mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 00:14:06 +00:00
fixed bug with global hotkeys in Windows
This commit is contained in:
parent
715e510866
commit
aca734932d
|
@ -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<QHotkeyApplication*>(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<QHotkeyApplication*>(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();
|
||||
|
||||
|
|
|
@ -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 );
|
||||
|
|
Loading…
Reference in a new issue