From 2a416d1f1dbdb671df01faa12bb592c701221a12 Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Sun, 1 Dec 2013 23:32:53 +0100 Subject: [PATCH] Make sure the remapping keycode is reset to NoSymbol. Previously the dtor of AutoTypePlatformX11 wasn't called. --- src/autotype/AutoType.cpp | 20 +++++++++++++++++++- src/autotype/AutoType.h | 1 + src/autotype/AutoTypePlatformPlugin.h | 1 + src/autotype/x11/AutoTypeX11.cpp | 25 ++++++++++++++++++------- src/autotype/x11/AutoTypeX11.h | 3 ++- 5 files changed, 41 insertions(+), 9 deletions(-) diff --git a/src/autotype/AutoType.cpp b/src/autotype/AutoType.cpp index dbf0dacc..80955a3b 100644 --- a/src/autotype/AutoType.cpp +++ b/src/autotype/AutoType.cpp @@ -57,11 +57,16 @@ AutoType::AutoType(QObject* parent, bool test) if (!pluginPath.isEmpty()) { loadPlugin(pluginPath); } + + connect(qApp, SIGNAL(aboutToQuit()), SLOT(unloadPlugin())); } AutoType::~AutoType() { - delete m_executor; + if (m_executor) { + delete m_executor; + m_executor = Q_NULLPTR; + } } void AutoType::loadPlugin(const QString& pluginPath) @@ -215,6 +220,19 @@ void AutoType::resetInAutoType() m_inAutoType = false; } +void AutoType::unloadPlugin() +{ + if (m_executor) { + delete m_executor; + m_executor = Q_NULLPTR; + } + + if (m_plugin) { + m_plugin->unload(); + m_plugin = Q_NULLPTR; + } +} + bool AutoType::registerGlobalShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers) { Q_ASSERT(key); diff --git a/src/autotype/AutoType.h b/src/autotype/AutoType.h index 0916698e..f3d626c8 100644 --- a/src/autotype/AutoType.h +++ b/src/autotype/AutoType.h @@ -59,6 +59,7 @@ Q_SIGNALS: private Q_SLOTS: void performAutoTypeFromGlobal(Entry* entry, const QString& sequence); void resetInAutoType(); + void unloadPlugin(); private: explicit AutoType(QObject* parent = Q_NULLPTR, bool test = false); diff --git a/src/autotype/AutoTypePlatformPlugin.h b/src/autotype/AutoTypePlatformPlugin.h index 03960fd3..1e78f0d2 100644 --- a/src/autotype/AutoTypePlatformPlugin.h +++ b/src/autotype/AutoTypePlatformPlugin.h @@ -33,6 +33,7 @@ public: virtual void unregisterGlobalShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers) = 0; virtual int platformEventFilter(void* event) = 0; virtual int initialTimeout() = 0; + virtual void unload() {} virtual AutoTypeExecutor* createExecutor() = 0; diff --git a/src/autotype/x11/AutoTypeX11.cpp b/src/autotype/x11/AutoTypeX11.cpp index 6aab0adc..e1462992 100644 --- a/src/autotype/x11/AutoTypeX11.cpp +++ b/src/autotype/x11/AutoTypeX11.cpp @@ -49,16 +49,26 @@ AutoTypePlatformX11::AutoTypePlatformX11() m_specialCharacterKeycode = 0; m_modifierMask = ControlMask | ShiftMask | Mod1Mask | Mod4Mask; + m_loaded = true; + updateKeymap(); } -/* - * Restore the KeyboardMapping to its original state. - */ -AutoTypePlatformX11::~AutoTypePlatformX11() { +void AutoTypePlatformX11::unload() +{ + // Restore the KeyboardMapping to its original state. AddKeysym(NoSymbol); -} + if (m_keysymTable) { + XFree(m_keysymTable); + } + + if (m_xkb) { + XkbFreeKeyboard(m_xkb, XkbAllComponentsMask, True); + } + + m_loaded = false; +} QStringList AutoTypePlatformX11::windowTitles() { @@ -168,13 +178,14 @@ int AutoTypePlatformX11::platformEventFilter(void* event) && m_currentGlobalKey && xevent->xkey.keycode == m_currentGlobalKeycode && (xevent->xkey.state & m_modifierMask) == m_currentGlobalNativeModifiers - && !QApplication::focusWidget()) { + && !QApplication::focusWidget() + && m_loaded) { if (xevent->type == KeyPress) { Q_EMIT globalShortcutTriggered(); } return 1; } - if (xevent->type == MappingNotify) { + if (xevent->type == MappingNotify && m_loaded) { XRefreshKeyboardMapping(reinterpret_cast(xevent)); updateKeymap(); } diff --git a/src/autotype/x11/AutoTypeX11.h b/src/autotype/x11/AutoTypeX11.h index c94897be..55456e84 100644 --- a/src/autotype/x11/AutoTypeX11.h +++ b/src/autotype/x11/AutoTypeX11.h @@ -42,7 +42,7 @@ class AutoTypePlatformX11 : public QObject, public AutoTypePlatformInterface public: AutoTypePlatformX11(); - ~AutoTypePlatformX11(); + void unload() Q_DECL_OVERRIDE; QStringList windowTitles(); WId activeWindow(); QString activeWindowTitle(); @@ -109,6 +109,7 @@ private: /* dedicated 'special character' keycode */ int m_specialCharacterKeycode; KeyCode m_modifier_keycode[N_MOD_INDICES]; + bool m_loaded; }; class AutoTypeExecturorX11 : public AutoTypeExecutor