Update qxt to qt5

This commit is contained in:
Chocobozzz 2015-04-11 22:45:27 +02:00
parent 11938e3d79
commit 39f120d405
11 changed files with 1019 additions and 1200 deletions

View File

@ -11,6 +11,7 @@ set(QXT-MOC-HEADERS
find_package(X11) find_package(X11)
include_directories(${X11_INCLUDE_DIR}) include_directories(${X11_INCLUDE_DIR})
include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS})
if(WIN32) if(WIN32)
set(QXT-SOURCES ${QXT-SOURCES} qxtglobalshortcut_win.cpp) set(QXT-SOURCES ${QXT-SOURCES} qxtglobalshortcut_win.cpp)
@ -20,9 +21,11 @@ else(WIN32)
set(QXT-SOURCES ${QXT-SOURCES} qxtglobalshortcut_x11.cpp) set(QXT-SOURCES ${QXT-SOURCES} qxtglobalshortcut_x11.cpp)
endif(WIN32) endif(WIN32)
QT4_WRAP_CPP(QXT-SOURCES-MOC ${QXT-MOC-HEADERS}) QT5_WRAP_CPP(QXT-SOURCES-MOC ${QXT-MOC-HEADERS})
ADD_LIBRARY(qxt STATIC ADD_LIBRARY(qxt STATIC
${QXT-SOURCES} ${QXT-SOURCES}
${QXT-SOURCES-MOC} ${QXT-SOURCES-MOC}
) )
QT5_USE_MODULES(qxt Core Widgets X11Extras)

View File

@ -1,432 +0,0 @@
diff -ru libqxt-old/src/gui/keymapper_x11.h libqxt/src/gui/keymapper_x11.h
--- libqxt-old/src/gui/keymapper_x11.h 2010-04-21 15:17:56.000000000 +0100
+++ libqxt/src/gui/keymapper_x11.h 2010-04-21 15:18:16.000000000 +0100
@@ -0,0 +1,364 @@
+#ifndef KEYMAPPER_X11_H
+#define KEYMAPPER_X11_H
+
+// (davidsansome) Nicked from qkeymapper_x11.cpp
+
+#include <Qt>
+
+#define XK_MISCELLANY
+#define XK_LATIN1
+#define XK_KOREAN
+#define XK_XKB_KEYS
+#include <X11/keysymdef.h>
+
+//
+// Keyboard event translation
+//
+
+#ifndef XK_ISO_Left_Tab
+#define XK_ISO_Left_Tab 0xFE20
+#endif
+
+#ifndef XK_dead_hook
+#define XK_dead_hook 0xFE61
+#endif
+
+#ifndef XK_dead_horn
+#define XK_dead_horn 0xFE62
+#endif
+
+#ifndef XK_Codeinput
+#define XK_Codeinput 0xFF37
+#endif
+
+#ifndef XK_Kanji_Bangou
+#define XK_Kanji_Bangou 0xFF37 /* same as codeinput */
+#endif
+
+// Fix old X libraries
+#ifndef XK_KP_Home
+#define XK_KP_Home 0xFF95
+#endif
+#ifndef XK_KP_Left
+#define XK_KP_Left 0xFF96
+#endif
+#ifndef XK_KP_Up
+#define XK_KP_Up 0xFF97
+#endif
+#ifndef XK_KP_Right
+#define XK_KP_Right 0xFF98
+#endif
+#ifndef XK_KP_Down
+#define XK_KP_Down 0xFF99
+#endif
+#ifndef XK_KP_Prior
+#define XK_KP_Prior 0xFF9A
+#endif
+#ifndef XK_KP_Next
+#define XK_KP_Next 0xFF9B
+#endif
+#ifndef XK_KP_End
+#define XK_KP_End 0xFF9C
+#endif
+#ifndef XK_KP_Insert
+#define XK_KP_Insert 0xFF9E
+#endif
+#ifndef XK_KP_Delete
+#define XK_KP_Delete 0xFF9F
+#endif
+
+// the next lines are taken from XFree > 4.0 (X11/XF86keysyms.h), defining some special
+// multimedia keys. They are included here as not every system has them.
+#define XF86XK_Standby 0x1008FF10
+#define XF86XK_AudioLowerVolume 0x1008FF11
+#define XF86XK_AudioMute 0x1008FF12
+#define XF86XK_AudioRaiseVolume 0x1008FF13
+#define XF86XK_AudioPlay 0x1008FF14
+#define XF86XK_AudioStop 0x1008FF15
+#define XF86XK_AudioPrev 0x1008FF16
+#define XF86XK_AudioNext 0x1008FF17
+#define XF86XK_HomePage 0x1008FF18
+#define XF86XK_Calculator 0x1008FF1D
+#define XF86XK_Mail 0x1008FF19
+#define XF86XK_Start 0x1008FF1A
+#define XF86XK_Search 0x1008FF1B
+#define XF86XK_AudioRecord 0x1008FF1C
+#define XF86XK_Back 0x1008FF26
+#define XF86XK_Forward 0x1008FF27
+#define XF86XK_Stop 0x1008FF28
+#define XF86XK_Refresh 0x1008FF29
+#define XF86XK_Favorites 0x1008FF30
+#define XF86XK_AudioPause 0x1008FF31
+#define XF86XK_AudioMedia 0x1008FF32
+#define XF86XK_MyComputer 0x1008FF33
+#define XF86XK_OpenURL 0x1008FF38
+#define XF86XK_Launch0 0x1008FF40
+#define XF86XK_Launch1 0x1008FF41
+#define XF86XK_Launch2 0x1008FF42
+#define XF86XK_Launch3 0x1008FF43
+#define XF86XK_Launch4 0x1008FF44
+#define XF86XK_Launch5 0x1008FF45
+#define XF86XK_Launch6 0x1008FF46
+#define XF86XK_Launch7 0x1008FF47
+#define XF86XK_Launch8 0x1008FF48
+#define XF86XK_Launch9 0x1008FF49
+#define XF86XK_LaunchA 0x1008FF4A
+#define XF86XK_LaunchB 0x1008FF4B
+#define XF86XK_LaunchC 0x1008FF4C
+#define XF86XK_LaunchD 0x1008FF4D
+#define XF86XK_LaunchE 0x1008FF4E
+#define XF86XK_LaunchF 0x1008FF4F
+// end of XF86keysyms.h
+
+// Special keys used by Qtopia, mapped into the X11 private keypad range.
+#define QTOPIAXK_Select 0x11000601
+#define QTOPIAXK_Yes 0x11000602
+#define QTOPIAXK_No 0x11000603
+#define QTOPIAXK_Cancel 0x11000604
+#define QTOPIAXK_Printer 0x11000605
+#define QTOPIAXK_Execute 0x11000606
+#define QTOPIAXK_Sleep 0x11000607
+#define QTOPIAXK_Play 0x11000608
+#define QTOPIAXK_Zoom 0x11000609
+#define QTOPIAXK_Context1 0x1100060A
+#define QTOPIAXK_Context2 0x1100060B
+#define QTOPIAXK_Context3 0x1100060C
+#define QTOPIAXK_Context4 0x1100060D
+#define QTOPIAXK_Call 0x1100060E
+#define QTOPIAXK_Hangup 0x1100060F
+#define QTOPIAXK_Flip 0x11000610
+
+// keyboard mapping table
+static const unsigned int KeyTbl[] = {
+
+ // misc keys
+
+ XK_Escape, Qt::Key_Escape,
+ XK_Tab, Qt::Key_Tab,
+ XK_ISO_Left_Tab, Qt::Key_Backtab,
+ XK_BackSpace, Qt::Key_Backspace,
+ XK_Return, Qt::Key_Return,
+ XK_Insert, Qt::Key_Insert,
+ XK_Delete, Qt::Key_Delete,
+ XK_Clear, Qt::Key_Delete,
+ XK_Pause, Qt::Key_Pause,
+ XK_Print, Qt::Key_Print,
+ 0x1005FF60, Qt::Key_SysReq, // hardcoded Sun SysReq
+ 0x1007ff00, Qt::Key_SysReq, // hardcoded X386 SysReq
+
+ // cursor movement
+
+ XK_Home, Qt::Key_Home,
+ XK_End, Qt::Key_End,
+ XK_Left, Qt::Key_Left,
+ XK_Up, Qt::Key_Up,
+ XK_Right, Qt::Key_Right,
+ XK_Down, Qt::Key_Down,
+ XK_Prior, Qt::Key_PageUp,
+ XK_Next, Qt::Key_PageDown,
+
+ // modifiers
+
+ XK_Shift_L, Qt::Key_Shift,
+ XK_Shift_R, Qt::Key_Shift,
+ XK_Shift_Lock, Qt::Key_Shift,
+ XK_Control_L, Qt::Key_Control,
+ XK_Control_R, Qt::Key_Control,
+ XK_Meta_L, Qt::Key_Meta,
+ XK_Meta_R, Qt::Key_Meta,
+ XK_Alt_L, Qt::Key_Alt,
+ XK_Alt_R, Qt::Key_Alt,
+ XK_Caps_Lock, Qt::Key_CapsLock,
+ XK_Num_Lock, Qt::Key_NumLock,
+ XK_Scroll_Lock, Qt::Key_ScrollLock,
+ XK_Super_L, Qt::Key_Super_L,
+ XK_Super_R, Qt::Key_Super_R,
+ XK_Menu, Qt::Key_Menu,
+ XK_Hyper_L, Qt::Key_Hyper_L,
+ XK_Hyper_R, Qt::Key_Hyper_R,
+ XK_Help, Qt::Key_Help,
+ 0x1000FF74, Qt::Key_Backtab, // hardcoded HP backtab
+ 0x1005FF10, Qt::Key_F11, // hardcoded Sun F36 (labeled F11)
+ 0x1005FF11, Qt::Key_F12, // hardcoded Sun F37 (labeled F12)
+
+ // numeric and function keypad keys
+
+ XK_KP_Space, Qt::Key_Space,
+ XK_KP_Tab, Qt::Key_Tab,
+ XK_KP_Enter, Qt::Key_Enter,
+ //XK_KP_F1, Qt::Key_F1,
+ //XK_KP_F2, Qt::Key_F2,
+ //XK_KP_F3, Qt::Key_F3,
+ //XK_KP_F4, Qt::Key_F4,
+ XK_KP_Home, Qt::Key_Home,
+ XK_KP_Left, Qt::Key_Left,
+ XK_KP_Up, Qt::Key_Up,
+ XK_KP_Right, Qt::Key_Right,
+ XK_KP_Down, Qt::Key_Down,
+ XK_KP_Prior, Qt::Key_PageUp,
+ XK_KP_Next, Qt::Key_PageDown,
+ XK_KP_End, Qt::Key_End,
+ XK_KP_Begin, Qt::Key_Clear,
+ XK_KP_Insert, Qt::Key_Insert,
+ XK_KP_Delete, Qt::Key_Delete,
+ XK_KP_Equal, Qt::Key_Equal,
+ XK_KP_Multiply, Qt::Key_Asterisk,
+ XK_KP_Add, Qt::Key_Plus,
+ XK_KP_Separator, Qt::Key_Comma,
+ XK_KP_Subtract, Qt::Key_Minus,
+ XK_KP_Decimal, Qt::Key_Period,
+ XK_KP_Divide, Qt::Key_Slash,
+
+ // International input method support keys
+
+ // International & multi-key character composition
+ XK_ISO_Level3_Shift, Qt::Key_AltGr,
+ XK_Multi_key, Qt::Key_Multi_key,
+ XK_Codeinput, Qt::Key_Codeinput,
+ XK_SingleCandidate, Qt::Key_SingleCandidate,
+ XK_MultipleCandidate, Qt::Key_MultipleCandidate,
+ XK_PreviousCandidate, Qt::Key_PreviousCandidate,
+
+ // Misc Functions
+ XK_Mode_switch, Qt::Key_Mode_switch,
+ XK_script_switch, Qt::Key_Mode_switch,
+
+ // Japanese keyboard support
+ XK_Kanji, Qt::Key_Kanji,
+ XK_Muhenkan, Qt::Key_Muhenkan,
+ //XK_Henkan_Mode, Qt::Key_Henkan_Mode,
+ XK_Henkan_Mode, Qt::Key_Henkan,
+ XK_Henkan, Qt::Key_Henkan,
+ XK_Romaji, Qt::Key_Romaji,
+ XK_Hiragana, Qt::Key_Hiragana,
+ XK_Katakana, Qt::Key_Katakana,
+ XK_Hiragana_Katakana, Qt::Key_Hiragana_Katakana,
+ XK_Zenkaku, Qt::Key_Zenkaku,
+ XK_Hankaku, Qt::Key_Hankaku,
+ XK_Zenkaku_Hankaku, Qt::Key_Zenkaku_Hankaku,
+ XK_Touroku, Qt::Key_Touroku,
+ XK_Massyo, Qt::Key_Massyo,
+ XK_Kana_Lock, Qt::Key_Kana_Lock,
+ XK_Kana_Shift, Qt::Key_Kana_Shift,
+ XK_Eisu_Shift, Qt::Key_Eisu_Shift,
+ XK_Eisu_toggle, Qt::Key_Eisu_toggle,
+ //XK_Kanji_Bangou, Qt::Key_Kanji_Bangou,
+ //XK_Zen_Koho, Qt::Key_Zen_Koho,
+ //XK_Mae_Koho, Qt::Key_Mae_Koho,
+ XK_Kanji_Bangou, Qt::Key_Codeinput,
+ XK_Zen_Koho, Qt::Key_MultipleCandidate,
+ XK_Mae_Koho, Qt::Key_PreviousCandidate,
+
+#ifdef XK_KOREAN
+ // Korean keyboard support
+ XK_Hangul, Qt::Key_Hangul,
+ XK_Hangul_Start, Qt::Key_Hangul_Start,
+ XK_Hangul_End, Qt::Key_Hangul_End,
+ XK_Hangul_Hanja, Qt::Key_Hangul_Hanja,
+ XK_Hangul_Jamo, Qt::Key_Hangul_Jamo,
+ XK_Hangul_Romaja, Qt::Key_Hangul_Romaja,
+ //XK_Hangul_Codeinput, Qt::Key_Hangul_Codeinput,
+ XK_Hangul_Codeinput, Qt::Key_Codeinput,
+ XK_Hangul_Jeonja, Qt::Key_Hangul_Jeonja,
+ XK_Hangul_Banja, Qt::Key_Hangul_Banja,
+ XK_Hangul_PreHanja, Qt::Key_Hangul_PreHanja,
+ XK_Hangul_PostHanja, Qt::Key_Hangul_PostHanja,
+ //XK_Hangul_SingleCandidate,Qt::Key_Hangul_SingleCandidate,
+ //XK_Hangul_MultipleCandidate,Qt::Key_Hangul_MultipleCandidate,
+ //XK_Hangul_PreviousCandidate,Qt::Key_Hangul_PreviousCandidate,
+ XK_Hangul_SingleCandidate, Qt::Key_SingleCandidate,
+ XK_Hangul_MultipleCandidate,Qt::Key_MultipleCandidate,
+ XK_Hangul_PreviousCandidate,Qt::Key_PreviousCandidate,
+ XK_Hangul_Special, Qt::Key_Hangul_Special,
+ //XK_Hangul_switch, Qt::Key_Hangul_switch,
+ XK_Hangul_switch, Qt::Key_Mode_switch,
+#endif // XK_KOREAN
+
+ // dead keys
+ XK_dead_grave, Qt::Key_Dead_Grave,
+ XK_dead_acute, Qt::Key_Dead_Acute,
+ XK_dead_circumflex, Qt::Key_Dead_Circumflex,
+ XK_dead_tilde, Qt::Key_Dead_Tilde,
+ XK_dead_macron, Qt::Key_Dead_Macron,
+ XK_dead_breve, Qt::Key_Dead_Breve,
+ XK_dead_abovedot, Qt::Key_Dead_Abovedot,
+ XK_dead_diaeresis, Qt::Key_Dead_Diaeresis,
+ XK_dead_abovering, Qt::Key_Dead_Abovering,
+ XK_dead_doubleacute, Qt::Key_Dead_Doubleacute,
+ XK_dead_caron, Qt::Key_Dead_Caron,
+ XK_dead_cedilla, Qt::Key_Dead_Cedilla,
+ XK_dead_ogonek, Qt::Key_Dead_Ogonek,
+ XK_dead_iota, Qt::Key_Dead_Iota,
+ XK_dead_voiced_sound, Qt::Key_Dead_Voiced_Sound,
+ XK_dead_semivoiced_sound, Qt::Key_Dead_Semivoiced_Sound,
+ XK_dead_belowdot, Qt::Key_Dead_Belowdot,
+ XK_dead_hook, Qt::Key_Dead_Hook,
+ XK_dead_horn, Qt::Key_Dead_Horn,
+
+ // Special multimedia keys
+ // currently only tested with MS internet keyboard
+
+ // browsing keys
+ XF86XK_Back, Qt::Key_Back,
+ XF86XK_Forward, Qt::Key_Forward,
+ XF86XK_Stop, Qt::Key_Stop,
+ XF86XK_Refresh, Qt::Key_Refresh,
+ XF86XK_Favorites, Qt::Key_Favorites,
+ XF86XK_AudioMedia, Qt::Key_LaunchMedia,
+ XF86XK_OpenURL, Qt::Key_OpenUrl,
+ XF86XK_HomePage, Qt::Key_HomePage,
+ XF86XK_Search, Qt::Key_Search,
+
+ // media keys
+ XF86XK_AudioLowerVolume, Qt::Key_VolumeDown,
+ XF86XK_AudioMute, Qt::Key_VolumeMute,
+ XF86XK_AudioRaiseVolume, Qt::Key_VolumeUp,
+ XF86XK_AudioPlay, Qt::Key_MediaPlay,
+ XF86XK_AudioStop, Qt::Key_MediaStop,
+ XF86XK_AudioPrev, Qt::Key_MediaPrevious,
+ XF86XK_AudioNext, Qt::Key_MediaNext,
+ XF86XK_AudioRecord, Qt::Key_MediaRecord,
+
+ // launch keys
+ XF86XK_Mail, Qt::Key_LaunchMail,
+ XF86XK_MyComputer, Qt::Key_Launch0,
+ XF86XK_Calculator, Qt::Key_Launch1,
+ XF86XK_Standby, Qt::Key_Standby,
+
+ XF86XK_Launch0, Qt::Key_Launch2,
+ XF86XK_Launch1, Qt::Key_Launch3,
+ XF86XK_Launch2, Qt::Key_Launch4,
+ XF86XK_Launch3, Qt::Key_Launch5,
+ XF86XK_Launch4, Qt::Key_Launch6,
+ XF86XK_Launch5, Qt::Key_Launch7,
+ XF86XK_Launch6, Qt::Key_Launch8,
+ XF86XK_Launch7, Qt::Key_Launch9,
+ XF86XK_Launch8, Qt::Key_LaunchA,
+ XF86XK_Launch9, Qt::Key_LaunchB,
+ XF86XK_LaunchA, Qt::Key_LaunchC,
+ XF86XK_LaunchB, Qt::Key_LaunchD,
+ XF86XK_LaunchC, Qt::Key_LaunchE,
+ XF86XK_LaunchD, Qt::Key_LaunchF,
+
+ // Qtopia keys
+ QTOPIAXK_Select, Qt::Key_Select,
+ QTOPIAXK_Yes, Qt::Key_Yes,
+ QTOPIAXK_No, Qt::Key_No,
+ QTOPIAXK_Cancel, Qt::Key_Cancel,
+ QTOPIAXK_Printer, Qt::Key_Printer,
+ QTOPIAXK_Execute, Qt::Key_Execute,
+ QTOPIAXK_Sleep, Qt::Key_Sleep,
+ QTOPIAXK_Play, Qt::Key_Play,
+ QTOPIAXK_Zoom, Qt::Key_Zoom,
+ QTOPIAXK_Context1, Qt::Key_Context1,
+ QTOPIAXK_Context2, Qt::Key_Context2,
+ QTOPIAXK_Context3, Qt::Key_Context3,
+ QTOPIAXK_Context4, Qt::Key_Context4,
+ QTOPIAXK_Call, Qt::Key_Call,
+ QTOPIAXK_Hangup, Qt::Key_Hangup,
+ QTOPIAXK_Flip, Qt::Key_Flip,
+
+ 0, 0
+};
+
+#endif // KEYMAPPER_X11_H
diff -ru libqxt-old/src/gui/qxtglobalshortcut_win.cpp libqxt/src/gui/qxtglobalshortcut_win.cpp
--- libqxt-old/src/gui/qxtglobalshortcut_win.cpp 2010-04-21 15:17:56.000000000 +0100
+++ libqxt/src/gui/qxtglobalshortcut_win.cpp 2010-04-21 15:18:16.000000000 +0100
@@ -156,6 +156,21 @@
case Qt::Key_Slash:
return VK_DIVIDE;
+ case Qt::Key_MediaNext:
+ return VK_MEDIA_NEXT_TRACK;
+ case Qt::Key_MediaPrevious:
+ return VK_MEDIA_PREV_TRACK;
+ case Qt::Key_MediaStop:
+ return VK_MEDIA_STOP;
+ case Qt::Key_MediaPlay:
+ return VK_MEDIA_PLAY_PAUSE;
+ case Qt::Key_VolumeDown:
+ return VK_VOLUME_DOWN;
+ case Qt::Key_VolumeUp:
+ return VK_VOLUME_UP;
+ case Qt::Key_VolumeMute:
+ return VK_VOLUME_MUTE;
+
// numbers
case Qt::Key_0:
case Qt::Key_1:
diff -ru libqxt-old/src/gui/qxtglobalshortcut_x11.cpp libqxt/src/gui/qxtglobalshortcut_x11.cpp
--- libqxt-old/src/gui/qxtglobalshortcut_x11.cpp 2010-04-21 15:17:56.000000000 +0100
+++ libqxt/src/gui/qxtglobalshortcut_x11.cpp 2010-04-21 15:18:16.000000000 +0100
@@ -26,6 +26,8 @@
#include <QX11Info>
#include <X11/Xlib.h>
+#include "keymapper_x11.h"
+
static int (*original_x_errhandler)(Display* display, XErrorEvent* event);
static int qxt_x_errhandler(Display* display, XErrorEvent *event)
@@ -81,8 +83,25 @@
quint32 QxtGlobalShortcutPrivate::nativeKeycode(Qt::Key key)
{
+ // (davidsansome) Try the table from QKeyMapper first - this seems to be
+ // the only way to get Keysyms for the media keys.
+ unsigned int keysym = 0;
+ int i = 0;
+ while (KeyTbl[i]) {
+ if (KeyTbl[i+1] == static_cast<uint>(key)) {
+ keysym = KeyTbl[i];
+ break;
+ }
+ i += 2;
+ }
+
+ // If that didn't work then fall back on XStringToKeysym
+ if (!keysym) {
+ keysym = XStringToKeysym(QKeySequence(key).toString().toLatin1().data());
+ }
+
Display* display = QX11Info::display();
- return XKeysymToKeycode(display, XStringToKeysym(QKeySequence(key).toString().toLatin1().data()));
+ return XKeysymToKeycode(display, keysym);
}
bool QxtGlobalShortcutPrivate::registerShortcut(quint32 nativeKey, quint32 nativeMods)

View File

@ -1,15 +0,0 @@
Index: qxtglobalshortcut_x11.cpp
===================================================================
--- qxtglobalshortcut_x11.cpp (revision 1208)
+++ qxtglobalshortcut_x11.cpp (working copy)
@@ -74,8 +74,9 @@
native |= ControlMask;
if (modifiers & Qt::AltModifier)
native |= Mod1Mask;
+ if (modifiers & Qt::MetaModifier)
+ native |= Mod4Mask;
// TODO: resolve these?
- //if (modifiers & Qt::MetaModifier)
//if (modifiers & Qt::KeypadModifier)
//if (modifiers & Qt::GroupSwitchModifier)
return native;

View File

@ -1,27 +1,33 @@
/**************************************************************************** /****************************************************************************
** ** Copyright (c) 2006 - 2011, the LibQxt project.
** Copyright (C) Qxt Foundation. Some rights reserved. ** See the Qxt AUTHORS file for a list of authors and copyright holders.
** ** All rights reserved.
** This file is part of the QxtCore module of the Qxt library. **
** ** Redistribution and use in source and binary forms, with or without
** This library is free software; you can redistribute it and/or modify it ** modification, are permitted provided that the following conditions are met:
** under the terms of the Common Public License, version 1.0, as published ** * Redistributions of source code must retain the above copyright
** by IBM, and/or under the terms of the GNU Lesser General Public License, ** notice, this list of conditions and the following disclaimer.
** version 2.1, as published by the Free Software Foundation. ** * Redistributions in binary form must reproduce the above copyright
** ** notice, this list of conditions and the following disclaimer in the
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY ** documentation and/or other materials provided with the distribution.
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY ** * Neither the name of the LibQxt project nor the
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR ** names of its contributors may be used to endorse or promote products
** FITNESS FOR A PARTICULAR PURPOSE. ** derived from this software without specific prior written permission.
** **
** You should have received a copy of the CPL and the LGPL along with this ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** included with the source distribution for more information. ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** If you did not receive a copy of the licenses, contact the Qxt Foundation. ** DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
** ** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** <http://libqxt.org> <foundation@libqxt.org> ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
****************************************************************************/ ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
** <http://libqxt.org> <foundation@libqxt.org>
*****************************************************************************/
#include "qxtglobal.h" #include "qxtglobal.h"
@ -74,7 +80,7 @@
\sa QXT_VERSION_STR \sa QXT_VERSION_STR
*/ */
const char* qxtVersion() const char * qxtVersion()
{ {
return QXT_VERSION_STR; return QXT_VERSION_STR;
} }
@ -170,13 +176,14 @@ void MyTestPrivate::doQuux() {
* \relates <QxtPimpl> * \relates <QxtPimpl>
* Declares that a public class has a related private class. * Declares that a public class has a related private class.
* *
* This shuold be put in the private section of the public class. The parameter is the name of the public class. * This shuold be put in the private section of the public class. The
* parameter \a PUB must be the name of the public class.
*/ */
/*! /*!
* \macro QXT_DECLARE_PUBLIC(PUB) * \macro QXT_DECLARE_PUBLIC(PUB)
* \relates <QxtPimpl> * \relates <QxtPimpl>
* Declares that a private class has a related public class. * Declares that a private class has a related public class named \a PUB.
* *
* This may be put anywhere in the declaration of the private class. The parameter is the name of the public class. * This may be put anywhere in the declaration of the private class. The parameter is the name of the public class.
*/ */
@ -187,23 +194,26 @@ void MyTestPrivate::doQuux() {
* Initializes resources owned by the private class. * Initializes resources owned by the private class.
* *
* This should be called from the public class's constructor, * This should be called from the public class's constructor,
* before qxt_d() is used for the first time. The parameter is the name of the public class. * before qxt_d() is used for the first time. The parameter \a PUB must be
* the name of the public class.
*/ */
/*! /*!
* \macro QXT_D(PUB) * \macro QXT_D(PUB)
* \relates <QxtPimpl> * \relates <QxtPimpl>
* Returns a reference in the current scope named "d" to the private class. * Returns a reference in the current scope named "d" to the private class
* associated with the public class \a PUB.
* *
* This function is only available in a class using \a QXT_DECLARE_PRIVATE. * This function is only available in a class using QXT_DECLARE_PRIVATE().
*/ */
/*! /*!
* \macro QXT_P(PUB) * \macro QXT_P(PUB)
* \relates <QxtPimpl> * \relates <QxtPimpl>
* Creates a reference in the current scope named "q" to the public class. * Creates a reference in the current scope named "q" to the public class
* named \a PUB.
* *
* This macro only works in a class using \a QXT_DECLARE_PUBLIC. * This macro only works in a class using QXT_DECLARE_PUBLIC().
*/ */
/*! /*!
@ -228,7 +238,7 @@ void MyTestPrivate::doQuux() {
* \relates <QxtPimpl> * \relates <QxtPimpl>
* Returns a reference to the public class. * Returns a reference to the public class.
* *
* This function is only available in a class using \a QXT_DECLARE_PUBLIC. * This function is only available in a class using QXT_DECLARE_PUBLIC().
*/ */
/*! /*!
@ -236,6 +246,6 @@ void MyTestPrivate::doQuux() {
* \relates <QxtPimpl> * \relates <QxtPimpl>
* Returns a const reference to the public class. * Returns a const reference to the public class.
* *
* This function is only available in a class using \a QXT_DECLARE_PUBLIC. * This function is only available in a class using QXT_DECLARE_PUBLIC().
* This overload will be automatically used in const functions. * This overload will be automatically used in const functions.
*/ */

View File

@ -1,47 +1,57 @@
/**************************************************************************** /****************************************************************************
** ** Copyright (c) 2006 - 2011, the LibQxt project.
** Copyright (C) Qxt Foundation. Some rights reserved. ** See the Qxt AUTHORS file for a list of authors and copyright holders.
** ** All rights reserved.
** This file is part of the QxtCore module of the Qxt library. **
** ** Redistribution and use in source and binary forms, with or without
** This library is free software; you can redistribute it and/or modify it ** modification, are permitted provided that the following conditions are met:
** under the terms of the Common Public License, version 1.0, as published ** * Redistributions of source code must retain the above copyright
** by IBM, and/or under the terms of the GNU Lesser General Public License, ** notice, this list of conditions and the following disclaimer.
** version 2.1, as published by the Free Software Foundation. ** * Redistributions in binary form must reproduce the above copyright
** ** notice, this list of conditions and the following disclaimer in the
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY ** documentation and/or other materials provided with the distribution.
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY ** * Neither the name of the LibQxt project nor the
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR ** names of its contributors may be used to endorse or promote products
** FITNESS FOR A PARTICULAR PURPOSE. ** derived from this software without specific prior written permission.
** **
** You should have received a copy of the CPL and the LGPL along with this ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** included with the source distribution for more information. ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** If you did not receive a copy of the licenses, contact the Qxt Foundation. ** DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
** ** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** <http://libqxt.org> <foundation@libqxt.org> ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
****************************************************************************/ ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
** <http://libqxt.org> <foundation@libqxt.org>
*****************************************************************************/
#ifndef QXTGLOBAL_H #ifndef QXTGLOBAL_H
#define QXTGLOBAL_H #define QXTGLOBAL_H
#include <QtGlobal> #include <QtGlobal>
#define QXT_VERSION 0x000600 #define QXT_VERSION 0x000700
#define QXT_VERSION_STR "0.6.0" #define QXT_VERSION_STR "0.7.0"
//--------------------------global macros------------------------------ //--------------------------global macros------------------------------
#ifndef QXT_NO_MACROS #ifndef QXT_NO_MACROS
#ifndef _countof
#define _countof(x) (sizeof(x)/sizeof(*x))
#endif
#endif // QXT_NO_MACROS #endif // QXT_NO_MACROS
//--------------------------export macros------------------------------ //--------------------------export macros------------------------------
#define QXT_DLLEXPORT DO_NOT_USE_THIS_ANYMORE #define QXT_DLLEXPORT DO_NOT_USE_THIS_ANYMORE
#if !defined(QXT_STATIC) #if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN)
# if defined(BUILD_QXT_CORE) # if defined(BUILD_QXT_CORE)
# define QXT_CORE_EXPORT Q_DECL_EXPORT # define QXT_CORE_EXPORT Q_DECL_EXPORT
# else # else
@ -51,7 +61,7 @@
# define QXT_CORE_EXPORT # define QXT_CORE_EXPORT
#endif // BUILD_QXT_CORE #endif // BUILD_QXT_CORE
#if !defined(QXT_STATIC) #if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN)
# if defined(BUILD_QXT_GUI) # if defined(BUILD_QXT_GUI)
# define QXT_GUI_EXPORT Q_DECL_EXPORT # define QXT_GUI_EXPORT Q_DECL_EXPORT
# else # else
@ -61,7 +71,7 @@
# define QXT_GUI_EXPORT # define QXT_GUI_EXPORT
#endif // BUILD_QXT_GUI #endif // BUILD_QXT_GUI
#if !defined(QXT_STATIC) #if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN)
# if defined(BUILD_QXT_NETWORK) # if defined(BUILD_QXT_NETWORK)
# define QXT_NETWORK_EXPORT Q_DECL_EXPORT # define QXT_NETWORK_EXPORT Q_DECL_EXPORT
# else # else
@ -71,7 +81,7 @@
# define QXT_NETWORK_EXPORT # define QXT_NETWORK_EXPORT
#endif // BUILD_QXT_NETWORK #endif // BUILD_QXT_NETWORK
#if !defined(QXT_STATIC) #if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN)
# if defined(BUILD_QXT_SQL) # if defined(BUILD_QXT_SQL)
# define QXT_SQL_EXPORT Q_DECL_EXPORT # define QXT_SQL_EXPORT Q_DECL_EXPORT
# else # else
@ -81,7 +91,7 @@
# define QXT_SQL_EXPORT # define QXT_SQL_EXPORT
#endif // BUILD_QXT_SQL #endif // BUILD_QXT_SQL
#if !defined(QXT_STATIC) #if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN)
# if defined(BUILD_QXT_WEB) # if defined(BUILD_QXT_WEB)
# define QXT_WEB_EXPORT Q_DECL_EXPORT # define QXT_WEB_EXPORT Q_DECL_EXPORT
# else # else
@ -91,7 +101,7 @@
# define QXT_WEB_EXPORT # define QXT_WEB_EXPORT
#endif // BUILD_QXT_WEB #endif // BUILD_QXT_WEB
#if !defined(QXT_STATIC) #if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN)
# if defined(BUILD_QXT_BERKELEY) # if defined(BUILD_QXT_BERKELEY)
# define QXT_BERKELEY_EXPORT Q_DECL_EXPORT # define QXT_BERKELEY_EXPORT Q_DECL_EXPORT
# else # else
@ -101,7 +111,7 @@
# define QXT_BERKELEY_EXPORT # define QXT_BERKELEY_EXPORT
#endif // BUILD_QXT_BERKELEY #endif // BUILD_QXT_BERKELEY
#if !defined(QXT_STATIC) #if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN)
# if defined(BUILD_QXT_ZEROCONF) # if defined(BUILD_QXT_ZEROCONF)
# define QXT_ZEROCONF_EXPORT Q_DECL_EXPORT # define QXT_ZEROCONF_EXPORT Q_DECL_EXPORT
# else # else
@ -111,7 +121,7 @@
# define QXT_ZEROCONF_EXPORT # define QXT_ZEROCONF_EXPORT
#endif // QXT_ZEROCONF_EXPORT #endif // QXT_ZEROCONF_EXPORT
#if defined BUILD_QXT_CORE || defined BUILD_QXT_GUI || defined BUILD_QXT_SQL || defined BUILD_QXT_NETWORK || defined BUILD_QXT_WEB || defined BUILD_QXT_BERKELEY || defined BUILD_QXT_ZEROCONF #if defined(BUILD_QXT_CORE) || defined(BUILD_QXT_GUI) || defined(BUILD_QXT_SQL) || defined(BUILD_QXT_NETWORK) || defined(BUILD_QXT_WEB) || defined(BUILD_QXT_BERKELEY) || defined(BUILD_QXT_ZEROCONF)
# define BUILD_QXT # define BUILD_QXT
#endif #endif
@ -167,6 +177,14 @@ protected:
{ {
return *qxt_p_ptr; return *qxt_p_ptr;
} }
inline PUB* qxt_ptr()
{
return qxt_p_ptr;
}
inline const PUB* qxt_ptr() const
{
return qxt_p_ptr;
}
private: private:
PUB* qxt_p_ptr; PUB* qxt_p_ptr;
@ -198,6 +216,14 @@ public:
{ {
return *static_cast<PVT*>(pvt); return *static_cast<PVT*>(pvt);
} }
inline PVT * operator->()
{
return static_cast<PVT*>(pvt);
}
inline const PVT * operator->() const
{
return static_cast<PVT*>(pvt);
}
private: private:
QxtPrivateInterface(const QxtPrivateInterface&) { } QxtPrivateInterface(const QxtPrivateInterface&) { }
QxtPrivateInterface& operator=(const QxtPrivateInterface&) { } QxtPrivateInterface& operator=(const QxtPrivateInterface&) { }

View File

@ -1,47 +1,69 @@
/****************************************************************************
**
** Copyright (C) Qxt Foundation. Some rights reserved.
**
** This file is part of the QxtGui module of the Qxt library.
**
** This library is free software; you can redistribute it and/or modify it
** under the terms of the Common Public License, version 1.0, as published
** by IBM, and/or under the terms of the GNU Lesser General Public License,
** version 2.1, as published by the Free Software Foundation.
**
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
** FITNESS FOR A PARTICULAR PURPOSE.
**
** You should have received a copy of the CPL and the LGPL along with this
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
** included with the source distribution for more information.
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
**
** <http://libqxt.org> <foundation@libqxt.org>
**
****************************************************************************/
#include "qxtglobalshortcut.h" #include "qxtglobalshortcut.h"
/****************************************************************************
** Copyright (c) 2006 - 2011, the LibQxt project.
** See the Qxt AUTHORS file for a list of authors and copyright holders.
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** * Neither the name of the LibQxt project nor the
** names of its contributors may be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
** <http://libqxt.org> <foundation@libqxt.org>
*****************************************************************************/
#include "qxtglobalshortcut_p.h" #include "qxtglobalshortcut_p.h"
#include <QAbstractEventDispatcher> #include <QAbstractEventDispatcher>
#include <QtDebug> #include <QtDebug>
bool QxtGlobalShortcutPrivate::error = false; bool QxtGlobalShortcutPrivate::error = false;
#ifndef Q_WS_MAC
int QxtGlobalShortcutPrivate::ref = 0; int QxtGlobalShortcutPrivate::ref = 0;
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
QAbstractEventDispatcher::EventFilter QxtGlobalShortcutPrivate::prevEventFilter = 0; QAbstractEventDispatcher::EventFilter QxtGlobalShortcutPrivate::prevEventFilter = 0;
#endif
#endif // Q_WS_MAC
QHash<QPair<quint32, quint32>, QxtGlobalShortcut*> QxtGlobalShortcutPrivate::shortcuts; QHash<QPair<quint32, quint32>, QxtGlobalShortcut*> QxtGlobalShortcutPrivate::shortcuts;
QxtGlobalShortcutPrivate::QxtGlobalShortcutPrivate() : enabled(true), key(Qt::Key(0)), mods(Qt::NoModifier) QxtGlobalShortcutPrivate::QxtGlobalShortcutPrivate() : enabled(true), key(Qt::Key(0)), mods(Qt::NoModifier)
{ {
#ifndef Q_WS_MAC
if (!ref++) if (!ref++)
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
prevEventFilter = QAbstractEventDispatcher::instance()->setEventFilter(eventFilter); prevEventFilter = QAbstractEventDispatcher::instance()->setEventFilter(eventFilter);
#else
QAbstractEventDispatcher::instance()->installNativeEventFilter(this);
#endif
#endif // Q_WS_MAC
} }
QxtGlobalShortcutPrivate::~QxtGlobalShortcutPrivate() QxtGlobalShortcutPrivate::~QxtGlobalShortcutPrivate()
{ {
#ifndef Q_WS_MAC
if (!--ref) if (!--ref)
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
QAbstractEventDispatcher::instance()->setEventFilter(prevEventFilter); QAbstractEventDispatcher::instance()->setEventFilter(prevEventFilter);
#else
QAbstractEventDispatcher::instance()->removeNativeEventFilter(this);
#endif
#endif // Q_WS_MAC
} }
bool QxtGlobalShortcutPrivate::setShortcut(const QKeySequence& shortcut) bool QxtGlobalShortcutPrivate::setShortcut(const QKeySequence& shortcut)
@ -52,19 +74,23 @@ bool QxtGlobalShortcutPrivate::setShortcut(const QKeySequence& shortcut)
const quint32 nativeKey = nativeKeycode(key); const quint32 nativeKey = nativeKeycode(key);
const quint32 nativeMods = nativeModifiers(mods); const quint32 nativeMods = nativeModifiers(mods);
const bool res = registerShortcut(nativeKey, nativeMods); const bool res = registerShortcut(nativeKey, nativeMods);
shortcuts.insert(qMakePair(nativeKey, nativeMods), &qxt_p()); if (res)
if (!res) shortcuts.insert(qMakePair(nativeKey, nativeMods), &qxt_p());
else
qWarning() << "QxtGlobalShortcut failed to register:" << QKeySequence(key + mods).toString(); qWarning() << "QxtGlobalShortcut failed to register:" << QKeySequence(key + mods).toString();
return res; return res;
} }
bool QxtGlobalShortcutPrivate::unsetShortcut() bool QxtGlobalShortcutPrivate::unsetShortcut()
{ {
bool res = false;
const quint32 nativeKey = nativeKeycode(key); const quint32 nativeKey = nativeKeycode(key);
const quint32 nativeMods = nativeModifiers(mods); const quint32 nativeMods = nativeModifiers(mods);
const bool res = unregisterShortcut(nativeKey, nativeMods); if (shortcuts.value(qMakePair(nativeKey, nativeMods)) == &qxt_p())
shortcuts.remove(qMakePair(nativeKey, nativeMods)); res = unregisterShortcut(nativeKey, nativeMods);
if (!res) if (res)
shortcuts.remove(qMakePair(nativeKey, nativeMods));
else
qWarning() << "QxtGlobalShortcut failed to unregister:" << QKeySequence(key + mods).toString(); qWarning() << "QxtGlobalShortcut failed to unregister:" << QKeySequence(key + mods).toString();
key = Qt::Key(0); key = Qt::Key(0);
mods = Qt::KeyboardModifiers(0); mods = Qt::KeyboardModifiers(0);
@ -80,7 +106,7 @@ void QxtGlobalShortcutPrivate::activateShortcut(quint32 nativeKey, quint32 nativ
/*! /*!
\class QxtGlobalShortcut \class QxtGlobalShortcut
\inmodule QxtGui \inmodule QxtWidgets
\brief The QxtGlobalShortcut class provides a global shortcut aka "hotkey". \brief The QxtGlobalShortcut class provides a global shortcut aka "hotkey".
A global shortcut triggers even if the application is not active. This A global shortcut triggers even if the application is not active. This
@ -189,3 +215,4 @@ void QxtGlobalShortcut::setDisabled(bool disabled)
{ {
qxt_d().enabled = !disabled; qxt_d().enabled = !disabled;
} }

View File

@ -1,28 +1,34 @@
/****************************************************************************
**
** Copyright (C) Qxt Foundation. Some rights reserved.
**
** This file is part of the QxtGui module of the Qxt library.
**
** This library is free software; you can redistribute it and/or modify it
** under the terms of the Common Public License, version 1.0, as published
** by IBM, and/or under the terms of the GNU Lesser General Public License,
** version 2.1, as published by the Free Software Foundation.
**
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
** FITNESS FOR A PARTICULAR PURPOSE.
**
** You should have received a copy of the CPL and the LGPL along with this
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
** included with the source distribution for more information.
** If you did not receive a copy of the licenses, contact the Qxt Foundation.
**
** <http://libqxt.org> <foundation@libqxt.org>
**
****************************************************************************/
#ifndef QXTGLOBALSHORTCUT_H #ifndef QXTGLOBALSHORTCUT_H
/****************************************************************************
** Copyright (c) 2006 - 2011, the LibQxt project.
** See the Qxt AUTHORS file for a list of authors and copyright holders.
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** * Neither the name of the LibQxt project nor the
** names of its contributors may be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
** <http://libqxt.org> <foundation@libqxt.org>
*****************************************************************************/
#define QXTGLOBALSHORTCUT_H #define QXTGLOBALSHORTCUT_H
#include "qxtglobal.h" #include "qxtglobal.h"
@ -56,3 +62,4 @@ Q_SIGNALS:
}; };
#endif // QXTGLOBALSHORTCUT_H #endif // QXTGLOBALSHORTCUT_H

View File

@ -1,207 +1,258 @@
#include <Carbon/Carbon.h>
/**************************************************************************** /****************************************************************************
** ** Copyright (c) 2006 - 2011, the LibQxt project.
** Copyright (C) Qxt Foundation. Some rights reserved. ** See the Qxt AUTHORS file for a list of authors and copyright holders.
** ** All rights reserved.
** This file is part of the QxtGui module of the Qxt library. **
** ** Redistribution and use in source and binary forms, with or without
** This library is free software; you can redistribute it and/or modify it ** modification, are permitted provided that the following conditions are met:
** under the terms of the Common Public License, version 1.0, as published ** * Redistributions of source code must retain the above copyright
** by IBM, and/or under the terms of the GNU Lesser General Public License, ** notice, this list of conditions and the following disclaimer.
** version 2.1, as published by the Free Software Foundation. ** * Redistributions in binary form must reproduce the above copyright
** ** notice, this list of conditions and the following disclaimer in the
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY ** documentation and/or other materials provided with the distribution.
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY ** * Neither the name of the LibQxt project nor the
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR ** names of its contributors may be used to endorse or promote products
** FITNESS FOR A PARTICULAR PURPOSE. ** derived from this software without specific prior written permission.
** **
** You should have received a copy of the CPL and the LGPL along with this ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** included with the source distribution for more information. ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** If you did not receive a copy of the licenses, contact the Qxt Foundation. ** DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
** ** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** <http://libqxt.org> <foundation@libqxt.org> ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
****************************************************************************/ ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
#include <Carbon/Carbon.h> ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
#include "qxtglobalshortcut_p.h" ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <QMap> **
#include <QHash> ** <http://libqxt.org> <foundation@libqxt.org>
#include <QtDebug> *****************************************************************************/
#include <QApplication>
typedef QPair<uint, uint> Identifier; #include "qxtglobalshortcut_p.h"
static QMap<quint32, EventHotKeyRef> keyRefs; #include <QMap>
static QHash<Identifier, quint32> keyIDs; #include <QHash>
static quint32 hotKeySerial = 0; #include <QtDebug>
static bool qxt_mac_handler_installed = false; #include <QApplication>
OSStatus qxt_mac_handle_hot_key(EventHandlerCallRef nextHandler, EventRef event, void* data) typedef QPair<uint, uint> Identifier;
{ static QMap<quint32, EventHotKeyRef> keyRefs;
// pass event to the app event filter static QHash<Identifier, quint32> keyIDs;
Q_UNUSED(data); static quint32 hotKeySerial = 0;
qApp->macEventFilter(nextHandler, event); static bool qxt_mac_handler_installed = false;
return noErr;
} OSStatus qxt_mac_handle_hot_key(EventHandlerCallRef nextHandler, EventRef event, void* data)
{
bool QxtGlobalShortcutPrivate::eventFilter(void* message) Q_UNUSED(nextHandler);
//bool QxtGlobalShortcutPrivate::macEventFilter(EventHandlerCallRef caller, EventRef event) Q_UNUSED(data);
{ if (GetEventClass(event) == kEventClassKeyboard && GetEventKind(event) == kEventHotKeyPressed)
EventRef event = (EventRef) message; {
if (GetEventClass(event) == kEventClassKeyboard && GetEventKind(event) == kEventHotKeyPressed) EventHotKeyID keyID;
{ GetEventParameter(event, kEventParamDirectObject, typeEventHotKeyID, NULL, sizeof(keyID), NULL, &keyID);
EventHotKeyID keyID; Identifier id = keyIDs.key(keyID.id);
GetEventParameter(event, kEventParamDirectObject, typeEventHotKeyID, NULL, sizeof(keyID), NULL, &keyID); QxtGlobalShortcutPrivate::activateShortcut(id.second, id.first);
Identifier id = keyIDs.key(keyID.id); }
activateShortcut(id.second, id.first); return noErr;
} }
return false;
} quint32 QxtGlobalShortcutPrivate::nativeModifiers(Qt::KeyboardModifiers modifiers)
{
quint32 QxtGlobalShortcutPrivate::nativeModifiers(Qt::KeyboardModifiers modifiers) quint32 native = 0;
{ if (modifiers & Qt::ShiftModifier)
quint32 native = 0; native |= shiftKey;
if (modifiers & Qt::ShiftModifier) if (modifiers & Qt::ControlModifier)
native |= shiftKeyBit; native |= cmdKey;
if (modifiers & Qt::ControlModifier) if (modifiers & Qt::AltModifier)
native |= cmdKey; native |= optionKey;
if (modifiers & Qt::AltModifier) if (modifiers & Qt::MetaModifier)
native |= optionKey; native |= controlKey;
if (modifiers & Qt::MetaModifier) if (modifiers & Qt::KeypadModifier)
native |= controlKey; native |= kEventKeyModifierNumLockMask;
if (modifiers & Qt::KeypadModifier) return native;
native |= kEventKeyModifierNumLockMask; }
return native;
} quint32 QxtGlobalShortcutPrivate::nativeKeycode(Qt::Key key)
{
quint32 QxtGlobalShortcutPrivate::nativeKeycode(Qt::Key key) UTF16Char ch;
{ // Constants found in NSEvent.h from AppKit.framework
UTF16Char ch; switch (key)
// Constants found in NSEvent.h from AppKit.framework {
if (key == Qt::Key_Up) ch = 0xF700; case Qt::Key_Return:
else if (key == Qt::Key_Down) ch = 0xF701; return kVK_Return;
else if (key == Qt::Key_Left) ch = 0xF702; case Qt::Key_Enter:
else if (key == Qt::Key_Right) ch = 0xF703; return kVK_ANSI_KeypadEnter;
else if (key >= Qt::Key_F1 && key <= Qt::Key_F35) case Qt::Key_Tab:
ch = key - Qt::Key_F1 + 0xF704; return kVK_Tab;
else if (key == Qt::Key_Insert) ch = 0xF727; case Qt::Key_Space:
else if (key == Qt::Key_Delete) ch = 0xF728; return kVK_Space;
else if (key == Qt::Key_Home) ch = 0xF729; case Qt::Key_Backspace:
else if (key == Qt::Key_End) ch = 0xF72B; return kVK_Delete;
else if (key == Qt::Key_PageUp) ch = 0xF72C; case Qt::Key_Control:
else if (key == Qt::Key_PageDown) ch = 0xF72D; return kVK_Command;
else if (key == Qt::Key_Print) ch = 0xF72E; case Qt::Key_Shift:
else if (key == Qt::Key_ScrollLock) ch = 0xF72F; return kVK_Shift;
else if (key == Qt::Key_Pause) ch = 0xF730; case Qt::Key_CapsLock:
else if (key == Qt::Key_SysReq) ch = 0xF731; return kVK_CapsLock;
else if (key == Qt::Key_Stop) ch = 0xF734; case Qt::Key_Option:
else if (key == Qt::Key_Menu) ch = 0xF735; return kVK_Option;
else if (key == Qt::Key_Select) ch = 0xF741; case Qt::Key_Meta:
else if (key == Qt::Key_Execute) ch = 0xF742; return kVK_Control;
else if (key == Qt::Key_Help) ch = 0xF746; case Qt::Key_F17:
else if (key == Qt::Key_Mode_switch) ch = 0xF747; return kVK_F17;
else if (key == Qt::Key_Escape) ch = 27; case Qt::Key_VolumeUp:
else if (key == Qt::Key_Return) ch = 13; return kVK_VolumeUp;
else if (key == Qt::Key_Enter) ch = 3; case Qt::Key_VolumeDown:
else if (key == Qt::Key_Tab) ch = 9; return kVK_VolumeDown;
else ch = key; case Qt::Key_F18:
return kVK_F18;
KeyboardLayoutRef layout; case Qt::Key_F19:
KeyboardLayoutKind layoutKind; return kVK_F19;
KLGetCurrentKeyboardLayout(&layout); case Qt::Key_F20:
KLGetKeyboardLayoutProperty(layout, kKLKind, const_cast<const void**>(reinterpret_cast<void**>(&layoutKind))); return kVK_F20;
case Qt::Key_F5:
if (layoutKind == kKLKCHRKind) return kVK_F5;
{ // no Unicode available case Qt::Key_F6:
if (ch > 255) return 0; return kVK_F6;
case Qt::Key_F7:
char* data; return kVK_F7;
KLGetKeyboardLayoutProperty(layout, kKLKCHRData, const_cast<const void**>(reinterpret_cast<void**>(&data))); case Qt::Key_F3:
int ct = *reinterpret_cast<short*>(data + 258); return kVK_F3;
for (int i = 0; i < ct; i++) case Qt::Key_F8:
{ return kVK_F8;
char* keyTable = data + 260 + 128 * i; case Qt::Key_F9:
for (int j = 0; j < 128; j++) return kVK_F9;
{ case Qt::Key_F11:
if (keyTable[j] == ch) return j; return kVK_F11;
} case Qt::Key_F13:
} return kVK_F13;
case Qt::Key_F16:
return 0; return kVK_F16;
} case Qt::Key_F14:
return kVK_F14;
char* data; case Qt::Key_F10:
KLGetKeyboardLayoutProperty(layout, kKLuchrData, const_cast<const void**>(reinterpret_cast<void**>(&data))); return kVK_F10;
UCKeyboardLayout* header = reinterpret_cast<UCKeyboardLayout*>(data); case Qt::Key_F12:
UCKeyboardTypeHeader* table = header->keyboardTypeList; return kVK_F12;
case Qt::Key_F15:
for (quint32 i=0; i < header->keyboardTypeCount; i++) return kVK_F15;
{ case Qt::Key_Help:
UCKeyStateRecordsIndex* stateRec = 0; return kVK_Help;
if (table[i].keyStateRecordsIndexOffset != 0) case Qt::Key_Home:
{ return kVK_Home;
stateRec = reinterpret_cast<UCKeyStateRecordsIndex*>(data + table[i].keyStateRecordsIndexOffset); case Qt::Key_PageUp:
if (stateRec->keyStateRecordsIndexFormat != kUCKeyStateRecordsIndexFormat) stateRec = 0; return kVK_PageUp;
} case Qt::Key_Delete:
return kVK_ForwardDelete;
UCKeyToCharTableIndex* charTable = reinterpret_cast<UCKeyToCharTableIndex*>(data + table[i].keyToCharTableIndexOffset); case Qt::Key_F4:
if (charTable->keyToCharTableIndexFormat != kUCKeyToCharTableIndexFormat) continue; return kVK_F4;
case Qt::Key_End:
for (quint32 j=0; j < charTable->keyToCharTableCount; j++) return kVK_End;
{ case Qt::Key_F2:
UCKeyOutput* keyToChar = reinterpret_cast<UCKeyOutput*>(data + charTable->keyToCharTableOffsets[j]); return kVK_F2;
for (quint32 k=0; k < charTable->keyToCharTableSize; k++) case Qt::Key_PageDown:
{ return kVK_PageDown;
if (keyToChar[k] & kUCKeyOutputTestForIndexMask) case Qt::Key_F1:
{ return kVK_F1;
long idx = keyToChar[k] & kUCKeyOutputGetIndexMask; case Qt::Key_Left:
if (stateRec && idx < stateRec->keyStateRecordCount) return kVK_LeftArrow;
{ case Qt::Key_Right:
UCKeyStateRecord* rec = reinterpret_cast<UCKeyStateRecord*>(data + stateRec->keyStateRecordOffsets[idx]); return kVK_RightArrow;
if (rec->stateZeroCharData == ch) return k; case Qt::Key_Down:
} return kVK_DownArrow;
} case Qt::Key_Up:
else if (!(keyToChar[k] & kUCKeyOutputSequenceIndexMask) && keyToChar[k] < 0xFFFE) return kVK_UpArrow;
{ default:
if (keyToChar[k] == ch) return k; ;
} }
} // for k
} // for j if (key == Qt::Key_Escape) ch = 27;
} // for i else if (key == Qt::Key_Return) ch = 13;
else if (key == Qt::Key_Enter) ch = 3;
return 0; else if (key == Qt::Key_Tab) ch = 9;
} else ch = key;
bool QxtGlobalShortcutPrivate::registerShortcut(quint32 nativeKey, quint32 nativeMods) CFDataRef currentLayoutData;
{ TISInputSourceRef currentKeyboard = TISCopyCurrentKeyboardInputSource();
if (!qxt_mac_handler_installed)
{ if (currentKeyboard == NULL)
EventTypeSpec t; return 0;
t.eventClass = kEventClassKeyboard;
t.eventKind = kEventHotKeyPressed; currentLayoutData = (CFDataRef)TISGetInputSourceProperty(currentKeyboard, kTISPropertyUnicodeKeyLayoutData);
InstallApplicationEventHandler(&qxt_mac_handle_hot_key, 1, &t, NULL, NULL); CFRelease(currentKeyboard);
} if (currentLayoutData == NULL)
return 0;
EventHotKeyID keyID;
keyID.signature = 'cute'; UCKeyboardLayout* header = (UCKeyboardLayout*)CFDataGetBytePtr(currentLayoutData);
keyID.id = ++hotKeySerial; UCKeyboardTypeHeader* table = header->keyboardTypeList;
EventHotKeyRef ref = 0; uint8_t *data = (uint8_t*)header;
bool rv = !RegisterEventHotKey(nativeKey, nativeMods, keyID, GetApplicationEventTarget(), 0, &ref); // God, would a little documentation for this shit kill you...
if (rv) for (quint32 i=0; i < header->keyboardTypeCount; i++)
{ {
keyIDs.insert(Identifier(nativeMods, nativeKey), keyID.id); UCKeyStateRecordsIndex* stateRec = 0;
keyRefs.insert(keyID.id, ref); if (table[i].keyStateRecordsIndexOffset != 0)
} {
qDebug() << ref; stateRec = reinterpret_cast<UCKeyStateRecordsIndex*>(data + table[i].keyStateRecordsIndexOffset);
return rv; if (stateRec->keyStateRecordsIndexFormat != kUCKeyStateRecordsIndexFormat) stateRec = 0;
} }
bool QxtGlobalShortcutPrivate::unregisterShortcut(quint32 nativeKey, quint32 nativeMods) UCKeyToCharTableIndex* charTable = reinterpret_cast<UCKeyToCharTableIndex*>(data + table[i].keyToCharTableIndexOffset);
{ if (charTable->keyToCharTableIndexFormat != kUCKeyToCharTableIndexFormat) continue;
Identifier id(nativeMods, nativeKey);
if (!keyIDs.contains(id)) return false; for (quint32 j=0; j < charTable->keyToCharTableCount; j++)
{
EventHotKeyRef ref = keyRefs.take(keyIDs[id]); UCKeyOutput* keyToChar = reinterpret_cast<UCKeyOutput*>(data + charTable->keyToCharTableOffsets[j]);
keyIDs.remove(id); for (quint32 k=0; k < charTable->keyToCharTableSize; k++)
return !UnregisterEventHotKey(ref); {
} if (keyToChar[k] & kUCKeyOutputTestForIndexMask)
{
long idx = keyToChar[k] & kUCKeyOutputGetIndexMask;
if (stateRec && idx < stateRec->keyStateRecordCount)
{
UCKeyStateRecord* rec = reinterpret_cast<UCKeyStateRecord*>(data + stateRec->keyStateRecordOffsets[idx]);
if (rec->stateZeroCharData == ch) return k;
}
}
else if (!(keyToChar[k] & kUCKeyOutputSequenceIndexMask) && keyToChar[k] < 0xFFFE)
{
if (keyToChar[k] == ch) return k;
}
} // for k
} // for j
} // for i
return 0;
}
bool QxtGlobalShortcutPrivate::registerShortcut(quint32 nativeKey, quint32 nativeMods)
{
if (!qxt_mac_handler_installed)
{
EventTypeSpec t;
t.eventClass = kEventClassKeyboard;
t.eventKind = kEventHotKeyPressed;
InstallApplicationEventHandler(&qxt_mac_handle_hot_key, 1, &t, NULL, NULL);
}
EventHotKeyID keyID;
keyID.signature = 'cute';
keyID.id = ++hotKeySerial;
EventHotKeyRef ref = 0;
bool rv = !RegisterEventHotKey(nativeKey, nativeMods, keyID, GetApplicationEventTarget(), 0, &ref);
if (rv)
{
keyIDs.insert(Identifier(nativeMods, nativeKey), keyID.id);
keyRefs.insert(keyID.id, ref);
}
return rv;
}
bool QxtGlobalShortcutPrivate::unregisterShortcut(quint32 nativeKey, quint32 nativeMods)
{
Identifier id(nativeMods, nativeKey);
if (!keyIDs.contains(id)) return false;
EventHotKeyRef ref = keyRefs.take(keyIDs[id]);
keyIDs.remove(id);
return !UnregisterEventHotKey(ref);
}

View File

@ -1,63 +1,84 @@
/**************************************************************************** #ifndef QXTGLOBALSHORTCUT_P_H
** /****************************************************************************
** Copyright (C) Qxt Foundation. Some rights reserved. ** Copyright (c) 2006 - 2011, the LibQxt project.
** ** See the Qxt AUTHORS file for a list of authors and copyright holders.
** This file is part of the QxtGui module of the Qxt library. ** All rights reserved.
** **
** This library is free software; you can redistribute it and/or modify it ** Redistribution and use in source and binary forms, with or without
** under the terms of the Common Public License, version 1.0, as published ** modification, are permitted provided that the following conditions are met:
** by IBM, and/or under the terms of the GNU Lesser General Public License, ** * Redistributions of source code must retain the above copyright
** version 2.1, as published by the Free Software Foundation. ** notice, this list of conditions and the following disclaimer.
** ** * Redistributions in binary form must reproduce the above copyright
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY ** notice, this list of conditions and the following disclaimer in the
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY ** documentation and/or other materials provided with the distribution.
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR ** * Neither the name of the LibQxt project nor the
** FITNESS FOR A PARTICULAR PURPOSE. ** names of its contributors may be used to endorse or promote products
** ** derived from this software without specific prior written permission.
** You should have received a copy of the CPL and the LGPL along with this **
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** included with the source distribution for more information. ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** If you did not receive a copy of the licenses, contact the Qxt Foundation. ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** ** DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
** <http://libqxt.org> <foundation@libqxt.org> ** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
****************************************************************************/ ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
#ifndef QXTGLOBALSHORTCUT_P_H ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
#define QXTGLOBALSHORTCUT_P_H ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "qxtglobalshortcut.h" **
#include <QAbstractEventDispatcher> ** <http://libqxt.org> <foundation@libqxt.org>
#include <QKeySequence> *****************************************************************************/
#include <QHash>
#define QXTGLOBALSHORTCUT_P_H
class QxtGlobalShortcutPrivate : public QxtPrivate<QxtGlobalShortcut>
{ #include "qxtglobalshortcut.h"
public: #include <QAbstractEventDispatcher>
QXT_DECLARE_PUBLIC(QxtGlobalShortcut) #include <QKeySequence>
QxtGlobalShortcutPrivate(); #include <QHash>
~QxtGlobalShortcutPrivate();
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
bool enabled; #include <QAbstractNativeEventFilter>
Qt::Key key; #endif
Qt::KeyboardModifiers mods;
bool setShortcut(const QKeySequence& shortcut); class QxtGlobalShortcutPrivate : public QxtPrivate<QxtGlobalShortcut>
bool unsetShortcut(); #if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
,public QAbstractNativeEventFilter
static bool error; #endif
static int ref; {
static QAbstractEventDispatcher::EventFilter prevEventFilter; public:
static bool eventFilter(void* message); QXT_DECLARE_PUBLIC(QxtGlobalShortcut)
QxtGlobalShortcutPrivate();
private: ~QxtGlobalShortcutPrivate();
static quint32 nativeKeycode(Qt::Key keycode);
static quint32 nativeModifiers(Qt::KeyboardModifiers modifiers); bool enabled;
Qt::Key key;
static bool registerShortcut(quint32 nativeKey, quint32 nativeMods); Qt::KeyboardModifiers mods;
static bool unregisterShortcut(quint32 nativeKey, quint32 nativeMods);
static void activateShortcut(quint32 nativeKey, quint32 nativeMods); bool setShortcut(const QKeySequence& shortcut);
bool unsetShortcut();
static QHash<QPair<quint32, quint32>, QxtGlobalShortcut*> shortcuts;
}; static bool error;
#ifndef Q_WS_MAC
#endif // QXTGLOBALSHORTCUT_P_H static int ref;
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
static QAbstractEventDispatcher::EventFilter prevEventFilter;
static bool eventFilter(void* message);
#else
virtual bool nativeEventFilter(const QByteArray & eventType, void * message, long * result);
#endif // QT_VERSION < QT_VERSION_CHECK(5,0,0)
#endif // Q_WS_MAC
static void activateShortcut(quint32 nativeKey, quint32 nativeMods);
private:
static quint32 nativeKeycode(Qt::Key keycode);
static quint32 nativeModifiers(Qt::KeyboardModifiers modifiers);
static bool registerShortcut(quint32 nativeKey, quint32 nativeMods);
static bool unregisterShortcut(quint32 nativeKey, quint32 nativeMods);
static QHash<QPair<quint32, quint32>, QxtGlobalShortcut*> shortcuts;
};
#endif // QXTGLOBALSHORTCUT_P_H

View File

@ -1,229 +1,247 @@
/**************************************************************************** #include "qxtglobalshortcut_p.h"
** /****************************************************************************
** Copyright (C) Qxt Foundation. Some rights reserved. ** Copyright (c) 2006 - 2011, the LibQxt project.
** ** See the Qxt AUTHORS file for a list of authors and copyright holders.
** This file is part of the QxtGui module of the Qxt library. ** All rights reserved.
** **
** This library is free software; you can redistribute it and/or modify it ** Redistribution and use in source and binary forms, with or without
** under the terms of the Common Public License, version 1.0, as published ** modification, are permitted provided that the following conditions are met:
** by IBM, and/or under the terms of the GNU Lesser General Public License, ** * Redistributions of source code must retain the above copyright
** version 2.1, as published by the Free Software Foundation. ** notice, this list of conditions and the following disclaimer.
** ** * Redistributions in binary form must reproduce the above copyright
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY ** notice, this list of conditions and the following disclaimer in the
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY ** documentation and/or other materials provided with the distribution.
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR ** * Neither the name of the LibQxt project nor the
** FITNESS FOR A PARTICULAR PURPOSE. ** names of its contributors may be used to endorse or promote products
** ** derived from this software without specific prior written permission.
** You should have received a copy of the CPL and the LGPL along with this **
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** included with the source distribution for more information. ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** If you did not receive a copy of the licenses, contact the Qxt Foundation. ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** ** DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
** <http://libqxt.org> <foundation@libqxt.org> ** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
****************************************************************************/ ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
#include "qxtglobalshortcut_p.h" ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
#include <qt_windows.h> ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
bool QxtGlobalShortcutPrivate::eventFilter(void* message) **
{ ** <http://libqxt.org> <foundation@libqxt.org>
MSG* msg = static_cast<MSG*>(message); *****************************************************************************/
if (msg->message == WM_HOTKEY)
{ #include <qt_windows.h>
const quint32 keycode = HIWORD(msg->lParam);
const quint32 modifiers = LOWORD(msg->lParam);
activateShortcut(keycode, modifiers); #if QT_VERSION < QT_VERSION_CHECK(5,0,0)
} bool QxtGlobalShortcutPrivate::eventFilter(void* message)
return false; {
} #else
bool QxtGlobalShortcutPrivate::nativeEventFilter(const QByteArray & eventType,
quint32 QxtGlobalShortcutPrivate::nativeModifiers(Qt::KeyboardModifiers modifiers) void * message, long * result)
{ {
// MOD_ALT, MOD_CONTROL, (MOD_KEYUP), MOD_SHIFT, MOD_WIN Q_UNUSED(eventType);
quint32 native = 0; Q_UNUSED(result);
if (modifiers & Qt::ShiftModifier) #endif
native |= MOD_SHIFT; MSG* msg = static_cast<MSG*>(message);
if (modifiers & Qt::ControlModifier) if (msg->message == WM_HOTKEY)
native |= MOD_CONTROL; {
if (modifiers & Qt::AltModifier) const quint32 keycode = HIWORD(msg->lParam);
native |= MOD_ALT; const quint32 modifiers = LOWORD(msg->lParam);
if (modifiers & Qt::MetaModifier) activateShortcut(keycode, modifiers);
native |= MOD_WIN; }
// TODO: resolve these? return false;
//if (modifiers & Qt::KeypadModifier) }
//if (modifiers & Qt::GroupSwitchModifier)
return native;
} quint32 QxtGlobalShortcutPrivate::nativeModifiers(Qt::KeyboardModifiers modifiers)
{
quint32 QxtGlobalShortcutPrivate::nativeKeycode(Qt::Key key) // MOD_ALT, MOD_CONTROL, (MOD_KEYUP), MOD_SHIFT, MOD_WIN
{ quint32 native = 0;
switch (key) if (modifiers & Qt::ShiftModifier)
{ native |= MOD_SHIFT;
case Qt::Key_Escape: if (modifiers & Qt::ControlModifier)
return VK_ESCAPE; native |= MOD_CONTROL;
case Qt::Key_Tab: if (modifiers & Qt::AltModifier)
case Qt::Key_Backtab: native |= MOD_ALT;
return VK_TAB; if (modifiers & Qt::MetaModifier)
case Qt::Key_Backspace: native |= MOD_WIN;
return VK_BACK; // TODO: resolve these?
case Qt::Key_Return: //if (modifiers & Qt::KeypadModifier)
case Qt::Key_Enter: //if (modifiers & Qt::GroupSwitchModifier)
return VK_RETURN; return native;
case Qt::Key_Insert: }
return VK_INSERT;
case Qt::Key_Delete: quint32 QxtGlobalShortcutPrivate::nativeKeycode(Qt::Key key)
return VK_DELETE; {
case Qt::Key_Pause: switch (key)
return VK_PAUSE; {
case Qt::Key_Print: case Qt::Key_Escape:
return VK_PRINT; return VK_ESCAPE;
case Qt::Key_Clear: case Qt::Key_Tab:
return VK_CLEAR; case Qt::Key_Backtab:
case Qt::Key_Home: return VK_TAB;
return VK_HOME; case Qt::Key_Backspace:
case Qt::Key_End: return VK_BACK;
return VK_END; case Qt::Key_Return:
case Qt::Key_Left: case Qt::Key_Enter:
return VK_LEFT; return VK_RETURN;
case Qt::Key_Up: case Qt::Key_Insert:
return VK_UP; return VK_INSERT;
case Qt::Key_Right: case Qt::Key_Delete:
return VK_RIGHT; return VK_DELETE;
case Qt::Key_Down: case Qt::Key_Pause:
return VK_DOWN; return VK_PAUSE;
case Qt::Key_PageUp: case Qt::Key_Print:
return VK_PRIOR; return VK_PRINT;
case Qt::Key_PageDown: case Qt::Key_Clear:
return VK_NEXT; return VK_CLEAR;
case Qt::Key_F1: case Qt::Key_Home:
return VK_F1; return VK_HOME;
case Qt::Key_F2: case Qt::Key_End:
return VK_F2; return VK_END;
case Qt::Key_F3: case Qt::Key_Left:
return VK_F3; return VK_LEFT;
case Qt::Key_F4: case Qt::Key_Up:
return VK_F4; return VK_UP;
case Qt::Key_F5: case Qt::Key_Right:
return VK_F5; return VK_RIGHT;
case Qt::Key_F6: case Qt::Key_Down:
return VK_F6; return VK_DOWN;
case Qt::Key_F7: case Qt::Key_PageUp:
return VK_F7; return VK_PRIOR;
case Qt::Key_F8: case Qt::Key_PageDown:
return VK_F8; return VK_NEXT;
case Qt::Key_F9: case Qt::Key_F1:
return VK_F9; return VK_F1;
case Qt::Key_F10: case Qt::Key_F2:
return VK_F10; return VK_F2;
case Qt::Key_F11: case Qt::Key_F3:
return VK_F11; return VK_F3;
case Qt::Key_F12: case Qt::Key_F4:
return VK_F12; return VK_F4;
case Qt::Key_F13: case Qt::Key_F5:
return VK_F13; return VK_F5;
case Qt::Key_F14: case Qt::Key_F6:
return VK_F14; return VK_F6;
case Qt::Key_F15: case Qt::Key_F7:
return VK_F15; return VK_F7;
case Qt::Key_F16: case Qt::Key_F8:
return VK_F16; return VK_F8;
case Qt::Key_F17: case Qt::Key_F9:
return VK_F17; return VK_F9;
case Qt::Key_F18: case Qt::Key_F10:
return VK_F18; return VK_F10;
case Qt::Key_F19: case Qt::Key_F11:
return VK_F19; return VK_F11;
case Qt::Key_F20: case Qt::Key_F12:
return VK_F20; return VK_F12;
case Qt::Key_F21: case Qt::Key_F13:
return VK_F21; return VK_F13;
case Qt::Key_F22: case Qt::Key_F14:
return VK_F22; return VK_F14;
case Qt::Key_F23: case Qt::Key_F15:
return VK_F23; return VK_F15;
case Qt::Key_F24: case Qt::Key_F16:
return VK_F24; return VK_F16;
case Qt::Key_Space: case Qt::Key_F17:
return VK_SPACE; return VK_F17;
case Qt::Key_Asterisk: case Qt::Key_F18:
return VK_MULTIPLY; return VK_F18;
case Qt::Key_Plus: case Qt::Key_F19:
return VK_ADD; return VK_F19;
case Qt::Key_Comma: case Qt::Key_F20:
return VK_SEPARATOR; return VK_F20;
case Qt::Key_Minus: case Qt::Key_F21:
return VK_SUBTRACT; return VK_F21;
case Qt::Key_Slash: case Qt::Key_F22:
return VK_DIVIDE; return VK_F22;
case Qt::Key_F23:
case Qt::Key_MediaNext: return VK_F23;
return VK_MEDIA_NEXT_TRACK; case Qt::Key_F24:
case Qt::Key_MediaPrevious: return VK_F24;
return VK_MEDIA_PREV_TRACK; case Qt::Key_Space:
case Qt::Key_MediaStop: return VK_SPACE;
return VK_MEDIA_STOP; case Qt::Key_Asterisk:
case Qt::Key_MediaPlay: return VK_MULTIPLY;
return VK_MEDIA_PLAY_PAUSE; case Qt::Key_Plus:
case Qt::Key_VolumeDown: return VK_ADD;
return VK_VOLUME_DOWN; case Qt::Key_Comma:
case Qt::Key_VolumeUp: return VK_SEPARATOR;
return VK_VOLUME_UP; case Qt::Key_Minus:
case Qt::Key_VolumeMute: return VK_SUBTRACT;
return VK_VOLUME_MUTE; case Qt::Key_Slash:
return VK_DIVIDE;
// numbers case Qt::Key_MediaNext:
case Qt::Key_0: return VK_MEDIA_NEXT_TRACK;
case Qt::Key_1: case Qt::Key_MediaPrevious:
case Qt::Key_2: return VK_MEDIA_PREV_TRACK;
case Qt::Key_3: case Qt::Key_MediaPlay:
case Qt::Key_4: return VK_MEDIA_PLAY_PAUSE;
case Qt::Key_5: case Qt::Key_MediaStop:
case Qt::Key_6: return VK_MEDIA_STOP;
case Qt::Key_7: // couldn't find those in VK_*
case Qt::Key_8: //case Qt::Key_MediaLast:
case Qt::Key_9: //case Qt::Key_MediaRecord:
return key; case Qt::Key_VolumeDown:
return VK_VOLUME_DOWN;
// letters case Qt::Key_VolumeUp:
case Qt::Key_A: return VK_VOLUME_UP;
case Qt::Key_B: case Qt::Key_VolumeMute:
case Qt::Key_C: return VK_VOLUME_MUTE;
case Qt::Key_D:
case Qt::Key_E: // numbers
case Qt::Key_F: case Qt::Key_0:
case Qt::Key_G: case Qt::Key_1:
case Qt::Key_H: case Qt::Key_2:
case Qt::Key_I: case Qt::Key_3:
case Qt::Key_J: case Qt::Key_4:
case Qt::Key_K: case Qt::Key_5:
case Qt::Key_L: case Qt::Key_6:
case Qt::Key_M: case Qt::Key_7:
case Qt::Key_N: case Qt::Key_8:
case Qt::Key_O: case Qt::Key_9:
case Qt::Key_P: return key;
case Qt::Key_Q:
case Qt::Key_R: // letters
case Qt::Key_S: case Qt::Key_A:
case Qt::Key_T: case Qt::Key_B:
case Qt::Key_U: case Qt::Key_C:
case Qt::Key_V: case Qt::Key_D:
case Qt::Key_W: case Qt::Key_E:
case Qt::Key_X: case Qt::Key_F:
case Qt::Key_Y: case Qt::Key_G:
case Qt::Key_Z: case Qt::Key_H:
return key; case Qt::Key_I:
case Qt::Key_J:
default: case Qt::Key_K:
return 0; case Qt::Key_L:
} case Qt::Key_M:
} case Qt::Key_N:
case Qt::Key_O:
bool QxtGlobalShortcutPrivate::registerShortcut(quint32 nativeKey, quint32 nativeMods) case Qt::Key_P:
{ case Qt::Key_Q:
return RegisterHotKey(0, nativeMods ^ nativeKey, nativeMods, nativeKey); case Qt::Key_R:
} case Qt::Key_S:
case Qt::Key_T:
bool QxtGlobalShortcutPrivate::unregisterShortcut(quint32 nativeKey, quint32 nativeMods) case Qt::Key_U:
{ case Qt::Key_V:
return UnregisterHotKey(0, nativeMods ^ nativeKey); case Qt::Key_W:
} case Qt::Key_X:
case Qt::Key_Y:
case Qt::Key_Z:
return key;
default:
return 0;
}
}
bool QxtGlobalShortcutPrivate::registerShortcut(quint32 nativeKey, quint32 nativeMods)
{
return RegisterHotKey(0, nativeMods ^ nativeKey, nativeMods, nativeKey);
}
bool QxtGlobalShortcutPrivate::unregisterShortcut(quint32 nativeKey, quint32 nativeMods)
{
return UnregisterHotKey(0, nativeMods ^ nativeKey);
}

View File

@ -1,135 +1,238 @@
/**************************************************************************** #include "qxtglobalshortcut_p.h"
** /****************************************************************************
** Copyright (C) Qxt Foundation. Some rights reserved. ** Copyright (c) 2006 - 2011, the LibQxt project.
** ** See the Qxt AUTHORS file for a list of authors and copyright holders.
** This file is part of the QxtGui module of the Qxt library. ** All rights reserved.
** **
** This library is free software; you can redistribute it and/or modify it ** Redistribution and use in source and binary forms, with or without
** under the terms of the Common Public License, version 1.0, as published ** modification, are permitted provided that the following conditions are met:
** by IBM, and/or under the terms of the GNU Lesser General Public License, ** * Redistributions of source code must retain the above copyright
** version 2.1, as published by the Free Software Foundation. ** notice, this list of conditions and the following disclaimer.
** ** * Redistributions in binary form must reproduce the above copyright
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY ** notice, this list of conditions and the following disclaimer in the
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY ** documentation and/or other materials provided with the distribution.
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR ** * Neither the name of the LibQxt project nor the
** FITNESS FOR A PARTICULAR PURPOSE. ** names of its contributors may be used to endorse or promote products
** ** derived from this software without specific prior written permission.
** You should have received a copy of the CPL and the LGPL along with this **
** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** included with the source distribution for more information. ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** If you did not receive a copy of the licenses, contact the Qxt Foundation. ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** ** DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
** <http://libqxt.org> <foundation@libqxt.org> ** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
****************************************************************************/ ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
#include "qxtglobalshortcut_p.h" ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
#include <QX11Info> ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
#include <X11/Xlib.h> ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
#include "keymapper_x11.h" ** <http://libqxt.org> <foundation@libqxt.org>
*****************************************************************************/
static int (*original_x_errhandler)(Display* display, XErrorEvent* event);
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
static int qxt_x_errhandler(Display* display, XErrorEvent *event) # include <QX11Info>
{ #else
Q_UNUSED(display); # include <QApplication>
switch (event->error_code) # include <qpa/qplatformnativeinterface.h>
{ # include <xcb/xcb.h>
case BadAccess: #endif
case BadValue: #include <QVector>
case BadWindow: #include <X11/Xlib.h>
if (event->request_code == 33 /* X_GrabKey */ ||
event->request_code == 34 /* X_UngrabKey */) namespace {
{
QxtGlobalShortcutPrivate::error = true; const QVector<quint32> maskModifiers = QVector<quint32>()
//TODO: << 0 << Mod2Mask << LockMask << (Mod2Mask | LockMask);
//char errstr[256];
//XGetErrorText(dpy, err->error_code, errstr, 256); typedef int (*X11ErrorHandler)(Display *display, XErrorEvent *event);
}
default: class QxtX11ErrorHandler {
return 0; public:
} static bool error;
}
static int qxtX11ErrorHandler(Display *display, XErrorEvent *event)
bool QxtGlobalShortcutPrivate::eventFilter(void* message) {
{ Q_UNUSED(display);
XEvent* event = static_cast<XEvent*>(message); switch (event->error_code)
if (event->type == KeyPress) {
{ case BadAccess:
XKeyEvent* key = (XKeyEvent*) event; case BadValue:
activateShortcut(key->keycode, case BadWindow:
// Mod1Mask == Alt, Mod4Mask == Meta if (event->request_code == 33 /* X_GrabKey */ ||
key->state & (ShiftMask | ControlMask | Mod1Mask | Mod4Mask)); event->request_code == 34 /* X_UngrabKey */)
} {
return false; error = true;
} //TODO:
//char errstr[256];
quint32 QxtGlobalShortcutPrivate::nativeModifiers(Qt::KeyboardModifiers modifiers) //XGetErrorText(dpy, err->error_code, errstr, 256);
{ }
// ShiftMask, LockMask, ControlMask, Mod1Mask, Mod2Mask, Mod3Mask, Mod4Mask, and Mod5Mask }
quint32 native = 0; return 0;
if (modifiers & Qt::ShiftModifier) }
native |= ShiftMask;
if (modifiers & Qt::ControlModifier) QxtX11ErrorHandler()
native |= ControlMask; {
if (modifiers & Qt::AltModifier) error = false;
native |= Mod1Mask; m_previousErrorHandler = XSetErrorHandler(qxtX11ErrorHandler);
if (modifiers & Qt::MetaModifier) }
native |= Mod4Mask;
// TODO: resolve these? ~QxtX11ErrorHandler()
//if (modifiers & Qt::KeypadModifier) {
//if (modifiers & Qt::GroupSwitchModifier) XSetErrorHandler(m_previousErrorHandler);
return native; }
}
private:
quint32 QxtGlobalShortcutPrivate::nativeKeycode(Qt::Key key) X11ErrorHandler m_previousErrorHandler;
{ };
// (davidsansome) Try the table from QKeyMapper first - this seems to be
// the only way to get Keysyms for the media keys. bool QxtX11ErrorHandler::error = false;
unsigned int keysym = 0;
int i = 0; class QxtX11Data {
while (KeyTbl[i]) { public:
if (KeyTbl[i+1] == static_cast<uint>(key)) { QxtX11Data()
keysym = KeyTbl[i]; {
break; #if QT_VERSION < QT_VERSION_CHECK(5,0,0)
} m_display = QX11Info::display();
i += 2; #else
} QPlatformNativeInterface *native = qApp->platformNativeInterface();
void *display = native->nativeResourceForScreen(QByteArray("display"),
// If that didn't work then fall back on XStringToKeysym QGuiApplication::primaryScreen());
if (!keysym) { m_display = reinterpret_cast<Display *>(display);
keysym = XStringToKeysym(QKeySequence(key).toString().toLatin1().data()); #endif
} }
Display* display = QX11Info::display(); bool isValid()
return XKeysymToKeycode(display, keysym); {
} return m_display != 0;
}
bool QxtGlobalShortcutPrivate::registerShortcut(quint32 nativeKey, quint32 nativeMods)
{ Display *display()
Display* display = QX11Info::display(); {
Window window = QX11Info::appRootWindow(); Q_ASSERT(isValid());
Bool owner = True; return m_display;
int pointer = GrabModeAsync; }
int keyboard = GrabModeAsync;
error = false; Window rootWindow()
original_x_errhandler = XSetErrorHandler(qxt_x_errhandler); {
XGrabKey(display, nativeKey, nativeMods, window, owner, pointer, keyboard); return DefaultRootWindow(display());
XGrabKey(display, nativeKey, nativeMods | Mod2Mask, window, owner, pointer, keyboard); // allow numlock }
XSync(display, False);
XSetErrorHandler(original_x_errhandler); bool grabKey(quint32 keycode, quint32 modifiers, Window window)
return !error; {
} QxtX11ErrorHandler errorHandler;
bool QxtGlobalShortcutPrivate::unregisterShortcut(quint32 nativeKey, quint32 nativeMods) for (int i = 0; !errorHandler.error && i < maskModifiers.size(); ++i) {
{ XGrabKey(display(), keycode, modifiers | maskModifiers[i], window, True,
Display* display = QX11Info::display(); GrabModeAsync, GrabModeAsync);
Window window = QX11Info::appRootWindow(); }
error = false;
original_x_errhandler = XSetErrorHandler(qxt_x_errhandler); if (errorHandler.error) {
XUngrabKey(display, nativeKey, nativeMods, window); ungrabKey(keycode, modifiers, window);
XUngrabKey(display, nativeKey, nativeMods | Mod2Mask, window); // allow numlock return false;
XSync(display, False); }
XSetErrorHandler(original_x_errhandler);
return !error; return true;
} }
bool ungrabKey(quint32 keycode, quint32 modifiers, Window window)
{
QxtX11ErrorHandler errorHandler;
foreach (quint32 maskMods, maskModifiers) {
XUngrabKey(display(), keycode, modifiers | maskMods, window);
}
return !errorHandler.error;
}
private:
Display *m_display;
};
} // namespace
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
bool QxtGlobalShortcutPrivate::eventFilter(void *message)
{
XEvent *event = static_cast<XEvent *>(message);
if (event->type == KeyPress)
{
XKeyEvent *key = reinterpret_cast<XKeyEvent *>(event);
unsigned int keycode = key->keycode;
unsigned int keystate = key->state;
#else
bool QxtGlobalShortcutPrivate::nativeEventFilter(const QByteArray & eventType,
void *message, long *result)
{
Q_UNUSED(result);
xcb_key_press_event_t *kev = 0;
if (eventType == "xcb_generic_event_t") {
xcb_generic_event_t *ev = static_cast<xcb_generic_event_t *>(message);
if ((ev->response_type & 127) == XCB_KEY_PRESS)
kev = static_cast<xcb_key_press_event_t *>(message);
}
if (kev != 0) {
unsigned int keycode = kev->detail;
unsigned int keystate = 0;
if(kev->state & XCB_MOD_MASK_1)
keystate |= Mod1Mask;
if(kev->state & XCB_MOD_MASK_CONTROL)
keystate |= ControlMask;
if(kev->state & XCB_MOD_MASK_4)
keystate |= Mod4Mask;
if(kev->state & XCB_MOD_MASK_SHIFT)
keystate |= ShiftMask;
#endif
activateShortcut(keycode,
// Mod1Mask == Alt, Mod4Mask == Meta
keystate & (ShiftMask | ControlMask | Mod1Mask | Mod4Mask));
}
return false;
}
quint32 QxtGlobalShortcutPrivate::nativeModifiers(Qt::KeyboardModifiers modifiers)
{
// ShiftMask, LockMask, ControlMask, Mod1Mask, Mod2Mask, Mod3Mask, Mod4Mask, and Mod5Mask
quint32 native = 0;
if (modifiers & Qt::ShiftModifier)
native |= ShiftMask;
if (modifiers & Qt::ControlModifier)
native |= ControlMask;
if (modifiers & Qt::AltModifier)
native |= Mod1Mask;
if (modifiers & Qt::MetaModifier)
native |= Mod4Mask;
// TODO: resolve these?
//if (modifiers & Qt::MetaModifier)
//if (modifiers & Qt::KeypadModifier)
//if (modifiers & Qt::GroupSwitchModifier)
return native;
}
quint32 QxtGlobalShortcutPrivate::nativeKeycode(Qt::Key key)
{
QxtX11Data x11;
if (!x11.isValid())
return 0;
KeySym keysym = XStringToKeysym(QKeySequence(key).toString().toLatin1().data());
if (keysym == NoSymbol)
keysym = static_cast<ushort>(key);
return XKeysymToKeycode(x11.display(), keysym);
}
bool QxtGlobalShortcutPrivate::registerShortcut(quint32 nativeKey, quint32 nativeMods)
{
QxtX11Data x11;
return x11.isValid() && x11.grabKey(nativeKey, nativeMods, x11.rootWindow());
}
bool QxtGlobalShortcutPrivate::unregisterShortcut(quint32 nativeKey, quint32 nativeMods)
{
QxtX11Data x11;
return x11.isValid() && x11.ungrabKey(nativeKey, nativeMods, x11.rootWindow());
}