mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
Support for testing key modifiers under Windows added. The default modifier key
in Windows build is Ctrl now.
This commit is contained in:
parent
4bae99aeb5
commit
cbfa6d2f74
|
@ -2,12 +2,32 @@
|
||||||
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
||||||
|
|
||||||
#include "keyboardstate.hh"
|
#include "keyboardstate.hh"
|
||||||
|
#include <QObject> // To get Qt Q_OS defines
|
||||||
|
|
||||||
|
#ifdef Q_OS_WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#else
|
||||||
#include <QX11Info>
|
#include <QX11Info>
|
||||||
#include <X11/X.h>
|
#include <X11/X.h>
|
||||||
#include <X11/XKBlib.h>
|
#include <X11/XKBlib.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
bool KeyboardState::checkModifiersPressed( int mask )
|
bool KeyboardState::checkModifiersPressed( int mask )
|
||||||
{
|
{
|
||||||
|
#ifdef Q_OS_WIN32
|
||||||
|
|
||||||
|
return !(
|
||||||
|
( mask & Alt && !( GetAsyncKeyState( VK_MENU ) & 0x8000 ) ) ||
|
||||||
|
( mask & Ctrl && !( GetAsyncKeyState( VK_CONTROL ) & 0x8000 ) ) ||
|
||||||
|
( mask & Shift && !( GetAsyncKeyState( VK_SHIFT ) & 0x8000 ) ) ||
|
||||||
|
( mask & LeftAlt && !( GetAsyncKeyState( VK_LMENU ) & 0x8000 ) ) ||
|
||||||
|
( mask & RightAlt && !( GetAsyncKeyState( VK_RMENU ) & 0x8000 ) ) ||
|
||||||
|
( mask & LeftCtrl && !( GetAsyncKeyState( VK_LCONTROL ) & 0x8000 ) ) ||
|
||||||
|
( mask & RightCtrl && !( GetAsyncKeyState( VK_RCONTROL ) & 0x8000 ) ) ||
|
||||||
|
( mask & LeftShift && !( GetAsyncKeyState( VK_LSHIFT ) & 0x8000 ) ) ||
|
||||||
|
( mask & RightShift && !( GetAsyncKeyState( VK_RSHIFT ) & 0x8000 ) ) );
|
||||||
|
|
||||||
|
#else
|
||||||
XkbStateRec state;
|
XkbStateRec state;
|
||||||
|
|
||||||
XkbGetState( QX11Info::display(), XkbUseCoreKbd, &state );
|
XkbGetState( QX11Info::display(), XkbUseCoreKbd, &state );
|
||||||
|
@ -17,5 +37,6 @@ bool KeyboardState::checkModifiersPressed( int mask )
|
||||||
( mask & Ctrl && !( state.base_mods & ControlMask ) ) ||
|
( mask & Ctrl && !( state.base_mods & ControlMask ) ) ||
|
||||||
( mask & Shift && !( state.base_mods & ShiftMask ) ) ||
|
( mask & Shift && !( state.base_mods & ShiftMask ) ) ||
|
||||||
( mask & Win && !( state.base_mods & Mod4Mask ) ) );
|
( mask & Win && !( state.base_mods & Mod4Mask ) ) );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,13 @@ public:
|
||||||
Alt = 1,
|
Alt = 1,
|
||||||
Ctrl = 2,
|
Ctrl = 2,
|
||||||
Shift = 4,
|
Shift = 4,
|
||||||
Win = 8
|
Win = 8, // Ironically, Linux only, since it's no use under Windows
|
||||||
|
LeftAlt = 16, // Those Left-Right are Windows-only, at least for now
|
||||||
|
RightAlt = 32,
|
||||||
|
LeftCtrl = 64,
|
||||||
|
RightCtrl = 128,
|
||||||
|
LeftShift = 256,
|
||||||
|
RightShift = 512
|
||||||
} Modifier;
|
} Modifier;
|
||||||
|
|
||||||
/// Returns true if all Modifiers present within the given mask are pressed
|
/// Returns true if all Modifiers present within the given mask are pressed
|
||||||
|
|
|
@ -69,11 +69,6 @@ void ScanPopup::clipboardChanged( QClipboard::Mode m )
|
||||||
{
|
{
|
||||||
printf( "clipboard changed\n" );
|
printf( "clipboard changed\n" );
|
||||||
|
|
||||||
// Check key modifiers
|
|
||||||
|
|
||||||
if ( !checkModifiersPressed( Win ) )
|
|
||||||
return;
|
|
||||||
|
|
||||||
QString subtype = "plain";
|
QString subtype = "plain";
|
||||||
|
|
||||||
handleInputWord( QApplication::clipboard()->text( subtype, m ) );
|
handleInputWord( QApplication::clipboard()->text( subtype, m ) );
|
||||||
|
@ -86,6 +81,16 @@ void ScanPopup::mouseHovered( QString const & str )
|
||||||
|
|
||||||
void ScanPopup::handleInputWord( QString const & str )
|
void ScanPopup::handleInputWord( QString const & str )
|
||||||
{
|
{
|
||||||
|
// Check key modifiers
|
||||||
|
|
||||||
|
#ifdef Q_OS_WIN32
|
||||||
|
if ( !checkModifiersPressed( Ctrl ) )
|
||||||
|
return;
|
||||||
|
#else
|
||||||
|
if ( !checkModifiersPressed( Win ) )
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
|
|
||||||
inputWord = str.trimmed();
|
inputWord = str.trimmed();
|
||||||
|
|
||||||
if ( !inputWord.size() )
|
if ( !inputWord.size() )
|
||||||
|
|
Loading…
Reference in a new issue