From aca734932d980cddbec0b7b7c6de112567176e97 Mon Sep 17 00:00:00 2001 From: ars_goldendict Date: Tue, 21 Apr 2009 21:07:15 +0000 Subject: [PATCH] fixed bug with global hotkeys in Windows --- src/hotkeywrapper.cc | 20 +++++++++++++------- src/hotkeywrapper.hh | 6 +++++- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/hotkeywrapper.cc b/src/hotkeywrapper.cc index a1ced2c4..d392a68b 100644 --- a/src/hotkeywrapper.cc +++ b/src/hotkeywrapper.cc @@ -25,11 +25,12 @@ void QHotkeyApplication::unregisterWrapper(HotkeyWrapper *wrapper) ////////////////////////////////////////////////////////////////////////// HotkeyStruct::HotkeyStruct( quint32 key_, quint32 key2_, quint32 modifier_, - int handle_ ): + int handle_, int id_ ): key( key_ ), key2( key2_ ), modifier( modifier_ ), - handle( handle_ ) + handle( handle_ ), + id( id_ ) { } @@ -43,6 +44,11 @@ HotkeyWrapper::HotkeyWrapper(QObject *parent) : QThread( parent ), (static_cast(qApp))->registerWrapper(this); } +HotkeyWrapper::~HotkeyWrapper() +{ + unregister(); +} + void HotkeyWrapper::waitKey2() { state2 = false; @@ -110,7 +116,7 @@ bool HotkeyWrapper::setGlobalKey( int key, int key2, quint32 vk = nativeKey( key ); quint32 vk2 = key2 ? nativeKey( key2 ) : 0; - hotkeys.append( HotkeyStruct( vk, vk2, mod, handle ) ); + hotkeys.append( HotkeyStruct( vk, vk2, mod, handle, id ) ); if (!RegisterHotKey(hwnd, id++, mod, vk)) return false; @@ -193,16 +199,16 @@ quint32 HotkeyWrapper::nativeKey(int key) return key; } -HotkeyWrapper::~HotkeyWrapper() +void HotkeyWrapper::unregister() { for (int i = 0; i < hotkeys.count(); i++) { HotkeyStruct const & hk = hotkeys.at( i ); - UnregisterHotKey( hwnd, hk.key ); + UnregisterHotKey( hwnd, hk.id ); if ( hk.key2 && hk.key2 != hk.key ) - UnregisterHotKey( hwnd, hk.key2 ); + UnregisterHotKey( hwnd, hk.id+1 ); } (static_cast(qApp))->unregisterWrapper(this); @@ -389,7 +395,7 @@ quint32 HotkeyWrapper::nativeKey(int key) return XKeysymToKeycode( display, XStringToKeysym( keySymName.toLatin1().data() ) ); } -HotkeyWrapper::~HotkeyWrapper() +void HotkeyWrapper::unregister() { Display * display = QX11Info::display(); diff --git a/src/hotkeywrapper.hh b/src/hotkeywrapper.hh index 43d1be11..4229fa97 100644 --- a/src/hotkeywrapper.hh +++ b/src/hotkeywrapper.hh @@ -18,11 +18,12 @@ struct HotkeyStruct { HotkeyStruct() {}; - HotkeyStruct( quint32 key, quint32 key2, quint32 modifier, int handle ); + HotkeyStruct( quint32 key, quint32 key2, quint32 modifier, int handle, int id ); quint32 key, key2; quint32 modifier; int handle; + int id; }; ////////////////////////////////////////////////////////////////////////// @@ -45,6 +46,9 @@ public: bool setGlobalKey( int key, int key2, Qt::KeyboardModifiers modifier, int handle ); + /// Unregisters everything + void unregister(); + signals: void hotkeyActivated( int );