From cbfa6d2f741a5da472716f558c9116a0b1825157 Mon Sep 17 00:00:00 2001 From: Konstantin Isakov Date: Thu, 5 Feb 2009 16:56:57 +0000 Subject: [PATCH] Support for testing key modifiers under Windows added. The default modifier key in Windows build is Ctrl now. --- src/keyboardstate.cc | 21 +++++++++++++++++++++ src/keyboardstate.hh | 8 +++++++- src/scanpopup.cc | 15 ++++++++++----- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/keyboardstate.cc b/src/keyboardstate.cc index 3aca75e5..7e161bad 100644 --- a/src/keyboardstate.cc +++ b/src/keyboardstate.cc @@ -2,12 +2,32 @@ * Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */ #include "keyboardstate.hh" +#include // To get Qt Q_OS defines + +#ifdef Q_OS_WIN32 +#include +#else #include #include #include +#endif 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; XkbGetState( QX11Info::display(), XkbUseCoreKbd, &state ); @@ -17,5 +37,6 @@ bool KeyboardState::checkModifiersPressed( int mask ) ( mask & Ctrl && !( state.base_mods & ControlMask ) ) || ( mask & Shift && !( state.base_mods & ShiftMask ) ) || ( mask & Win && !( state.base_mods & Mod4Mask ) ) ); + #endif } diff --git a/src/keyboardstate.hh b/src/keyboardstate.hh index c9c90985..a59d81f5 100644 --- a/src/keyboardstate.hh +++ b/src/keyboardstate.hh @@ -16,7 +16,13 @@ public: Alt = 1, Ctrl = 2, 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; /// Returns true if all Modifiers present within the given mask are pressed diff --git a/src/scanpopup.cc b/src/scanpopup.cc index bc4396d3..57f4fc90 100644 --- a/src/scanpopup.cc +++ b/src/scanpopup.cc @@ -69,11 +69,6 @@ void ScanPopup::clipboardChanged( QClipboard::Mode m ) { printf( "clipboard changed\n" ); - // Check key modifiers - - if ( !checkModifiersPressed( Win ) ) - return; - QString subtype = "plain"; handleInputWord( QApplication::clipboard()->text( subtype, m ) ); @@ -86,6 +81,16 @@ void ScanPopup::mouseHovered( 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(); if ( !inputWord.size() )