2012-02-20 21:47:14 +00:00
|
|
|
/* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org>
|
2009-02-01 00:08:08 +00:00
|
|
|
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
|
|
|
|
|
|
|
#include "keyboardstate.hh"
|
2009-02-05 16:56:57 +00:00
|
|
|
#include <QObject> // To get Qt Q_OS defines
|
|
|
|
|
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
#include <windows.h>
|
2013-05-31 05:28:36 +00:00
|
|
|
#elif defined( HAVE_X11 )
|
2022-02-27 14:42:40 +00:00
|
|
|
#if ( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) )
|
2022-05-28 01:38:10 +00:00
|
|
|
#include <QGuiApplication>
|
2022-02-27 14:42:40 +00:00
|
|
|
#else
|
2009-02-01 00:08:08 +00:00
|
|
|
#include <QX11Info>
|
2022-02-27 14:42:40 +00:00
|
|
|
#endif
|
2009-02-01 00:08:08 +00:00
|
|
|
#include <X11/X.h>
|
|
|
|
#include <X11/XKBlib.h>
|
2014-05-12 13:53:13 +00:00
|
|
|
#elif defined Q_OS_MAC
|
2013-04-10 13:31:44 +00:00
|
|
|
#define __SECURITYHI__
|
|
|
|
#include <Carbon/Carbon.h>
|
2009-02-05 16:56:57 +00:00
|
|
|
#endif
|
2009-02-01 00:08:08 +00:00
|
|
|
|
|
|
|
bool KeyboardState::checkModifiersPressed( int mask )
|
|
|
|
{
|
2024-06-24 08:05:41 +00:00
|
|
|
#if defined( Q_OS_WIN32 )
|
2023-07-20 08:02:22 +00:00
|
|
|
|
2009-02-05 16:56:57 +00:00
|
|
|
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 ) ) );
|
|
|
|
|
2014-05-12 13:53:13 +00:00
|
|
|
#elif defined Q_OS_MAC
|
2013-04-10 13:31:44 +00:00
|
|
|
UInt32 keys = GetCurrentKeyModifiers();
|
|
|
|
return !( ( mask & Alt && !( keys & ( 1 << optionKeyBit ) ) ) || ( mask & Ctrl && !( keys & ( 1 << cmdKeyBit ) ) )
|
|
|
|
|| ( mask & Shift && !( keys & ( 1 << shiftKeyBit ) ) )
|
|
|
|
|| ( mask & Win && !( keys & ( 1 << controlKeyBit ) ) ) );
|
2022-05-28 01:38:10 +00:00
|
|
|
#else
|
2023-07-20 08:02:22 +00:00
|
|
|
|
2022-05-28 01:38:10 +00:00
|
|
|
#if QT_VERSION < 0x060000
|
|
|
|
Display * displayID = QX11Info::display();
|
2023-07-20 08:02:22 +00:00
|
|
|
#else
|
2022-05-28 01:38:10 +00:00
|
|
|
QNativeInterface::QX11Application * x11AppInfo = qApp->nativeInterface< QNativeInterface::QX11Application >();
|
|
|
|
Display * displayID = x11AppInfo->display();
|
|
|
|
#endif
|
|
|
|
|
2009-02-01 00:08:08 +00:00
|
|
|
XkbStateRec state;
|
|
|
|
|
2022-05-28 01:38:10 +00:00
|
|
|
XkbGetState( displayID, XkbUseCoreKbd, &state );
|
2009-02-01 00:08:08 +00:00
|
|
|
|
|
|
|
return !( ( mask & Alt && !( state.base_mods & Mod1Mask ) ) || ( mask & Ctrl && !( state.base_mods & ControlMask ) )
|
|
|
|
|| ( mask & Shift && !( state.base_mods & ShiftMask ) )
|
|
|
|
|| ( mask & Win && !( state.base_mods & Mod4Mask ) ) );
|
2009-02-05 16:56:57 +00:00
|
|
|
#endif
|
2009-02-01 00:08:08 +00:00
|
|
|
}
|