fixed bug with global hotkeys in Windows

This commit is contained in:
ars_goldendict 2009-04-21 21:07:15 +00:00
parent 715e510866
commit aca734932d
2 changed files with 18 additions and 8 deletions

View file

@ -25,11 +25,12 @@ void QHotkeyApplication::unregisterWrapper(HotkeyWrapper *wrapper)
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
HotkeyStruct::HotkeyStruct( quint32 key_, quint32 key2_, quint32 modifier_, HotkeyStruct::HotkeyStruct( quint32 key_, quint32 key2_, quint32 modifier_,
int handle_ ): int handle_, int id_ ):
key( key_ ), key( key_ ),
key2( key2_ ), key2( key2_ ),
modifier( modifier_ ), modifier( modifier_ ),
handle( handle_ ) handle( handle_ ),
id( id_ )
{ {
} }
@ -43,6 +44,11 @@ HotkeyWrapper::HotkeyWrapper(QObject *parent) : QThread( parent ),
(static_cast<QHotkeyApplication*>(qApp))->registerWrapper(this); (static_cast<QHotkeyApplication*>(qApp))->registerWrapper(this);
} }
HotkeyWrapper::~HotkeyWrapper()
{
unregister();
}
void HotkeyWrapper::waitKey2() void HotkeyWrapper::waitKey2()
{ {
state2 = false; state2 = false;
@ -110,7 +116,7 @@ bool HotkeyWrapper::setGlobalKey( int key, int key2,
quint32 vk = nativeKey( key ); quint32 vk = nativeKey( key );
quint32 vk2 = key2 ? nativeKey( key2 ) : 0; 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)) if (!RegisterHotKey(hwnd, id++, mod, vk))
return false; return false;
@ -193,16 +199,16 @@ quint32 HotkeyWrapper::nativeKey(int key)
return key; return key;
} }
HotkeyWrapper::~HotkeyWrapper() void HotkeyWrapper::unregister()
{ {
for (int i = 0; i < hotkeys.count(); i++) for (int i = 0; i < hotkeys.count(); i++)
{ {
HotkeyStruct const & hk = hotkeys.at( i ); HotkeyStruct const & hk = hotkeys.at( i );
UnregisterHotKey( hwnd, hk.key ); UnregisterHotKey( hwnd, hk.id );
if ( hk.key2 && hk.key2 != hk.key ) if ( hk.key2 && hk.key2 != hk.key )
UnregisterHotKey( hwnd, hk.key2 ); UnregisterHotKey( hwnd, hk.id+1 );
} }
(static_cast<QHotkeyApplication*>(qApp))->unregisterWrapper(this); (static_cast<QHotkeyApplication*>(qApp))->unregisterWrapper(this);
@ -389,7 +395,7 @@ quint32 HotkeyWrapper::nativeKey(int key)
return XKeysymToKeycode( display, XStringToKeysym( keySymName.toLatin1().data() ) ); return XKeysymToKeycode( display, XStringToKeysym( keySymName.toLatin1().data() ) );
} }
HotkeyWrapper::~HotkeyWrapper() void HotkeyWrapper::unregister()
{ {
Display * display = QX11Info::display(); Display * display = QX11Info::display();

View file

@ -18,11 +18,12 @@
struct HotkeyStruct struct HotkeyStruct
{ {
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 key, key2;
quint32 modifier; quint32 modifier;
int handle; int handle;
int id;
}; };
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
@ -45,6 +46,9 @@ public:
bool setGlobalKey( int key, int key2, Qt::KeyboardModifiers modifier, bool setGlobalKey( int key, int key2, Qt::KeyboardModifiers modifier,
int handle ); int handle );
/// Unregisters everything
void unregister();
signals: signals:
void hotkeyActivated( int ); void hotkeyActivated( int );