1 /****************************************************************************
3 ** Copyright (C) Qxt Foundation. Some rights reserved.
5 ** This file is part of the QxtGui module of the Qt eXTension library
7 ** This library is free software; you can redistribute it and/or modify it
8 ** under the terms of th Common Public License, version 1.0, as published by
11 ** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
12 ** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
13 ** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
14 ** FITNESS FOR A PARTICULAR PURPOSE.
16 ** You should have received a copy of the CPL along with this file.
17 ** See the LICENSE file and the cpl1.0.txt file included with the source
18 ** distribution for more information. If you did not receive a copy of the
19 ** license, contact the Qxt Foundation.
21 ** <http://libqxt.sourceforge.net> <foundation@libqxt.org>
23 ****************************************************************************/
24 #include "qxtapplication.h"
25 #include "qxtapplication_p.h"
26 #include <QKeySequence>
30 QxtApplication::QxtApplication(Display* display, Qt::HANDLE visual, Qt::HANDLE colormap)
31 : QApplication(display, visual, colormap)
34 QxtApplication::QxtApplication(Display* display, int& argc, char** argv, Qt::HANDLE visual, Qt::HANDLE colormap)
35 : QApplication(display, argc, argv, visual, colormap)
38 bool QxtApplication::x11EventFilter(XEvent* event)
40 foreach (QxtNativeEventFilter* filter, qxt_d().nativeFilters)
42 if (filter && filter->x11EventFilter(event))
46 if (event->type == KeyPress)
48 XKeyEvent* key = (XKeyEvent*) event;
49 qxt_d().activateHotKey(key->state, key->keycode);
51 return QApplication::x11EventFilter(event);
54 uint QxtApplicationPrivate::nativeModifiers(Qt::KeyboardModifiers modifiers) const
56 // ShiftMask, LockMask, ControlMask, Mod1Mask, Mod2Mask, Mod3Mask, Mod4Mask, and Mod5Mask
58 if (modifiers & Qt::ShiftModifier)
60 if (modifiers & Qt::ControlModifier)
61 native |= ControlMask;
62 if (modifiers & Qt::AltModifier)
64 // TODO: resolve these?
65 //if (modifiers & Qt::MetaModifier)
66 //if (modifiers & Qt::KeypadModifier)
67 //if (modifiers & Qt::GroupSwitchModifier)
71 uint QxtApplicationPrivate::nativeKeycode(Qt::Key key) const
73 Display* display = QX11Info::display();
74 return XKeysymToKeycode(display, XStringToKeysym(QKeySequence(key).toString().toLatin1().data()));
77 bool QxtApplicationPrivate::registerHotKey(uint modifiers, uint keycode, QWidget* receiver)
80 Display* display = QX11Info::display();
81 Window window = QX11Info::appRootWindow();
83 int pointer = GrabModeAsync;
84 int keyboard = GrabModeAsync;
85 return XGrabKey(display, keycode, modifiers, window, owner, pointer, keyboard);
88 bool QxtApplicationPrivate::unregisterHotKey(uint modifiers, uint keycode, QWidget* receiver)
91 Display* display = QX11Info::display();
92 Window window = QX11Info::appRootWindow();
93 return XUngrabKey(display, keycode, modifiers, window);