From cc2c7b53cc5160d19019ac524420b9debc3c546d Mon Sep 17 00:00:00 2001 From: David Sansome Date: Thu, 25 Mar 2010 22:37:22 +0000 Subject: [PATCH] dos2unix all this stuff --- 3rdparty/qxt/qxtglobalshortcut.cpp | 382 ++++++++++----------- 3rdparty/qxt/qxtglobalshortcut.h | 116 +++---- 3rdparty/qxt/qxtglobalshortcut_mac.cpp | 414 +++++++++++----------- 3rdparty/qxt/qxtglobalshortcut_p.h | 126 +++---- 3rdparty/qxt/qxtglobalshortcut_win.cpp | 458 ++++++++++++------------- 3rdparty/qxt/qxtglobalshortcut_x11.cpp | 270 +++++++-------- 6 files changed, 883 insertions(+), 883 deletions(-) diff --git a/3rdparty/qxt/qxtglobalshortcut.cpp b/3rdparty/qxt/qxtglobalshortcut.cpp index 310e71b1f..ef378f965 100644 --- a/3rdparty/qxt/qxtglobalshortcut.cpp +++ b/3rdparty/qxt/qxtglobalshortcut.cpp @@ -1,191 +1,191 @@ -/**************************************************************************** - ** - ** 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. - ** - ** - ** - ****************************************************************************/ -#include "qxtglobalshortcut.h" -#include "qxtglobalshortcut_p.h" -#include -#include - -bool QxtGlobalShortcutPrivate::error = false; -int QxtGlobalShortcutPrivate::ref = 0; -QAbstractEventDispatcher::EventFilter QxtGlobalShortcutPrivate::prevEventFilter = 0; -QHash, QxtGlobalShortcut*> QxtGlobalShortcutPrivate::shortcuts; - -QxtGlobalShortcutPrivate::QxtGlobalShortcutPrivate() : enabled(true), key(Qt::Key(0)), mods(Qt::NoModifier) -{ - if (!ref++) - prevEventFilter = QAbstractEventDispatcher::instance()->setEventFilter(eventFilter); -} - -QxtGlobalShortcutPrivate::~QxtGlobalShortcutPrivate() -{ - if (!--ref) - QAbstractEventDispatcher::instance()->setEventFilter(prevEventFilter); -} - -bool QxtGlobalShortcutPrivate::setShortcut(const QKeySequence& shortcut) -{ - Qt::KeyboardModifiers allMods = Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier; - key = shortcut.isEmpty() ? Qt::Key(0) : Qt::Key((shortcut[0] ^ allMods) & shortcut[0]); - mods = shortcut.isEmpty() ? Qt::KeyboardModifiers(0) : Qt::KeyboardModifiers(shortcut[0] & allMods); - const quint32 nativeKey = nativeKeycode(key); - const quint32 nativeMods = nativeModifiers(mods); - const bool res = registerShortcut(nativeKey, nativeMods); - shortcuts.insert(qMakePair(nativeKey, nativeMods), &qxt_p()); - if (!res) - qWarning() << "QxtGlobalShortcut failed to register:" << QKeySequence(key + mods).toString(); - return res; -} - -bool QxtGlobalShortcutPrivate::unsetShortcut() -{ - const quint32 nativeKey = nativeKeycode(key); - const quint32 nativeMods = nativeModifiers(mods); - const bool res = unregisterShortcut(nativeKey, nativeMods); - shortcuts.remove(qMakePair(nativeKey, nativeMods)); - if (!res) - qWarning() << "QxtGlobalShortcut failed to unregister:" << QKeySequence(key + mods).toString(); - key = Qt::Key(0); - mods = Qt::KeyboardModifiers(0); - return res; -} - -void QxtGlobalShortcutPrivate::activateShortcut(quint32 nativeKey, quint32 nativeMods) -{ - QxtGlobalShortcut* shortcut = shortcuts.value(qMakePair(nativeKey, nativeMods)); - if (shortcut && shortcut->isEnabled()) - emit shortcut->activated(); -} - -/*! - \class QxtGlobalShortcut - \inmodule QxtGui - \brief The QxtGlobalShortcut class provides a global shortcut aka "hotkey". - - A global shortcut triggers even if the application is not active. This - makes it easy to implement applications that react to certain shortcuts - still if some other application is active or if the application is for - example minimized to the system tray. - - Example usage: - \code - QxtGlobalShortcut* shortcut = new QxtGlobalShortcut(window); - connect(shortcut, SIGNAL(activated()), window, SLOT(toggleVisibility())); - shortcut->setShortcut(QKeySequence("Ctrl+Shift+F12")); - \endcode - - \bold {Note:} Since Qxt 0.6 QxtGlobalShortcut no more requires QxtApplication. - */ - -/*! - \fn QxtGlobalShortcut::activated() - - This signal is emitted when the user types the shortcut's key sequence. - - \sa shortcut - */ - -/*! - Constructs a new QxtGlobalShortcut with \a parent. - */ -QxtGlobalShortcut::QxtGlobalShortcut(QObject* parent) - : QObject(parent) -{ - QXT_INIT_PRIVATE(QxtGlobalShortcut); -} - -/*! - Constructs a new QxtGlobalShortcut with \a shortcut and \a parent. - */ -QxtGlobalShortcut::QxtGlobalShortcut(const QKeySequence& shortcut, QObject* parent) - : QObject(parent) -{ - QXT_INIT_PRIVATE(QxtGlobalShortcut); - setShortcut(shortcut); -} - -/*! - Destructs the QxtGlobalShortcut. - */ -QxtGlobalShortcut::~QxtGlobalShortcut() -{ - if (qxt_d().key != 0) - qxt_d().unsetShortcut(); -} - -/*! - \property QxtGlobalShortcut::shortcut - \brief the shortcut key sequence - - \bold {Note:} Notice that corresponding key press and release events are not - delivered for registered global shortcuts even if they are disabled. - Also, comma separated key sequences are not supported. - Only the first part is used: - - \code - qxtShortcut->setShortcut(QKeySequence("Ctrl+Alt+A,Ctrl+Alt+B")); - Q_ASSERT(qxtShortcut->shortcut() == QKeySequence("Ctrl+Alt+A")); - \endcode - */ -QKeySequence QxtGlobalShortcut::shortcut() const -{ - return QKeySequence(qxt_d().key | qxt_d().mods); -} - -bool QxtGlobalShortcut::setShortcut(const QKeySequence& shortcut) -{ - if (qxt_d().key != 0) - qxt_d().unsetShortcut(); - return qxt_d().setShortcut(shortcut); -} - -/*! - \property QxtGlobalShortcut::enabled - \brief whether the shortcut is enabled - - A disabled shortcut does not get activated. - - The default value is \c true. - - \sa setDisabled() - */ -bool QxtGlobalShortcut::isEnabled() const -{ - return qxt_d().enabled; -} - -void QxtGlobalShortcut::setEnabled(bool enabled) -{ - qxt_d().enabled = enabled; -} - -/*! - Sets the shortcut \a disabled. - - \sa enabled - */ -void QxtGlobalShortcut::setDisabled(bool disabled) -{ - qxt_d().enabled = !disabled; -} +/**************************************************************************** + ** + ** 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. + ** + ** + ** + ****************************************************************************/ +#include "qxtglobalshortcut.h" +#include "qxtglobalshortcut_p.h" +#include +#include + +bool QxtGlobalShortcutPrivate::error = false; +int QxtGlobalShortcutPrivate::ref = 0; +QAbstractEventDispatcher::EventFilter QxtGlobalShortcutPrivate::prevEventFilter = 0; +QHash, QxtGlobalShortcut*> QxtGlobalShortcutPrivate::shortcuts; + +QxtGlobalShortcutPrivate::QxtGlobalShortcutPrivate() : enabled(true), key(Qt::Key(0)), mods(Qt::NoModifier) +{ + if (!ref++) + prevEventFilter = QAbstractEventDispatcher::instance()->setEventFilter(eventFilter); +} + +QxtGlobalShortcutPrivate::~QxtGlobalShortcutPrivate() +{ + if (!--ref) + QAbstractEventDispatcher::instance()->setEventFilter(prevEventFilter); +} + +bool QxtGlobalShortcutPrivate::setShortcut(const QKeySequence& shortcut) +{ + Qt::KeyboardModifiers allMods = Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier; + key = shortcut.isEmpty() ? Qt::Key(0) : Qt::Key((shortcut[0] ^ allMods) & shortcut[0]); + mods = shortcut.isEmpty() ? Qt::KeyboardModifiers(0) : Qt::KeyboardModifiers(shortcut[0] & allMods); + const quint32 nativeKey = nativeKeycode(key); + const quint32 nativeMods = nativeModifiers(mods); + const bool res = registerShortcut(nativeKey, nativeMods); + shortcuts.insert(qMakePair(nativeKey, nativeMods), &qxt_p()); + if (!res) + qWarning() << "QxtGlobalShortcut failed to register:" << QKeySequence(key + mods).toString(); + return res; +} + +bool QxtGlobalShortcutPrivate::unsetShortcut() +{ + const quint32 nativeKey = nativeKeycode(key); + const quint32 nativeMods = nativeModifiers(mods); + const bool res = unregisterShortcut(nativeKey, nativeMods); + shortcuts.remove(qMakePair(nativeKey, nativeMods)); + if (!res) + qWarning() << "QxtGlobalShortcut failed to unregister:" << QKeySequence(key + mods).toString(); + key = Qt::Key(0); + mods = Qt::KeyboardModifiers(0); + return res; +} + +void QxtGlobalShortcutPrivate::activateShortcut(quint32 nativeKey, quint32 nativeMods) +{ + QxtGlobalShortcut* shortcut = shortcuts.value(qMakePair(nativeKey, nativeMods)); + if (shortcut && shortcut->isEnabled()) + emit shortcut->activated(); +} + +/*! + \class QxtGlobalShortcut + \inmodule QxtGui + \brief The QxtGlobalShortcut class provides a global shortcut aka "hotkey". + + A global shortcut triggers even if the application is not active. This + makes it easy to implement applications that react to certain shortcuts + still if some other application is active or if the application is for + example minimized to the system tray. + + Example usage: + \code + QxtGlobalShortcut* shortcut = new QxtGlobalShortcut(window); + connect(shortcut, SIGNAL(activated()), window, SLOT(toggleVisibility())); + shortcut->setShortcut(QKeySequence("Ctrl+Shift+F12")); + \endcode + + \bold {Note:} Since Qxt 0.6 QxtGlobalShortcut no more requires QxtApplication. + */ + +/*! + \fn QxtGlobalShortcut::activated() + + This signal is emitted when the user types the shortcut's key sequence. + + \sa shortcut + */ + +/*! + Constructs a new QxtGlobalShortcut with \a parent. + */ +QxtGlobalShortcut::QxtGlobalShortcut(QObject* parent) + : QObject(parent) +{ + QXT_INIT_PRIVATE(QxtGlobalShortcut); +} + +/*! + Constructs a new QxtGlobalShortcut with \a shortcut and \a parent. + */ +QxtGlobalShortcut::QxtGlobalShortcut(const QKeySequence& shortcut, QObject* parent) + : QObject(parent) +{ + QXT_INIT_PRIVATE(QxtGlobalShortcut); + setShortcut(shortcut); +} + +/*! + Destructs the QxtGlobalShortcut. + */ +QxtGlobalShortcut::~QxtGlobalShortcut() +{ + if (qxt_d().key != 0) + qxt_d().unsetShortcut(); +} + +/*! + \property QxtGlobalShortcut::shortcut + \brief the shortcut key sequence + + \bold {Note:} Notice that corresponding key press and release events are not + delivered for registered global shortcuts even if they are disabled. + Also, comma separated key sequences are not supported. + Only the first part is used: + + \code + qxtShortcut->setShortcut(QKeySequence("Ctrl+Alt+A,Ctrl+Alt+B")); + Q_ASSERT(qxtShortcut->shortcut() == QKeySequence("Ctrl+Alt+A")); + \endcode + */ +QKeySequence QxtGlobalShortcut::shortcut() const +{ + return QKeySequence(qxt_d().key | qxt_d().mods); +} + +bool QxtGlobalShortcut::setShortcut(const QKeySequence& shortcut) +{ + if (qxt_d().key != 0) + qxt_d().unsetShortcut(); + return qxt_d().setShortcut(shortcut); +} + +/*! + \property QxtGlobalShortcut::enabled + \brief whether the shortcut is enabled + + A disabled shortcut does not get activated. + + The default value is \c true. + + \sa setDisabled() + */ +bool QxtGlobalShortcut::isEnabled() const +{ + return qxt_d().enabled; +} + +void QxtGlobalShortcut::setEnabled(bool enabled) +{ + qxt_d().enabled = enabled; +} + +/*! + Sets the shortcut \a disabled. + + \sa enabled + */ +void QxtGlobalShortcut::setDisabled(bool disabled) +{ + qxt_d().enabled = !disabled; +} diff --git a/3rdparty/qxt/qxtglobalshortcut.h b/3rdparty/qxt/qxtglobalshortcut.h index 65cdf8af7..2ca14da72 100644 --- a/3rdparty/qxt/qxtglobalshortcut.h +++ b/3rdparty/qxt/qxtglobalshortcut.h @@ -1,58 +1,58 @@ -/**************************************************************************** - ** - ** 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. - ** - ** - ** - ****************************************************************************/ -#ifndef QXTGLOBALSHORTCUT_H -#define QXTGLOBALSHORTCUT_H - -#include "qxtglobal.h" -#include -#include -class QxtGlobalShortcutPrivate; - -class QXT_GUI_EXPORT QxtGlobalShortcut : public QObject -{ - Q_OBJECT - QXT_DECLARE_PRIVATE(QxtGlobalShortcut) - Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled) - Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut) - -public: - QxtGlobalShortcut(QObject* parent = 0); - QxtGlobalShortcut(const QKeySequence& shortcut, QObject* parent = 0); - virtual ~QxtGlobalShortcut(); - - QKeySequence shortcut() const; - bool setShortcut(const QKeySequence& shortcut); - - bool isEnabled() const; - -public Q_SLOTS: - void setEnabled(bool enabled = true); - void setDisabled(bool disabled = true); - -Q_SIGNALS: - void activated(); -}; - -#endif // QXTGLOBALSHORTCUT_H +/**************************************************************************** + ** + ** 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. + ** + ** + ** + ****************************************************************************/ +#ifndef QXTGLOBALSHORTCUT_H +#define QXTGLOBALSHORTCUT_H + +#include "qxtglobal.h" +#include +#include +class QxtGlobalShortcutPrivate; + +class QXT_GUI_EXPORT QxtGlobalShortcut : public QObject +{ + Q_OBJECT + QXT_DECLARE_PRIVATE(QxtGlobalShortcut) + Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled) + Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut) + +public: + QxtGlobalShortcut(QObject* parent = 0); + QxtGlobalShortcut(const QKeySequence& shortcut, QObject* parent = 0); + virtual ~QxtGlobalShortcut(); + + QKeySequence shortcut() const; + bool setShortcut(const QKeySequence& shortcut); + + bool isEnabled() const; + +public Q_SLOTS: + void setEnabled(bool enabled = true); + void setDisabled(bool disabled = true); + +Q_SIGNALS: + void activated(); +}; + +#endif // QXTGLOBALSHORTCUT_H diff --git a/3rdparty/qxt/qxtglobalshortcut_mac.cpp b/3rdparty/qxt/qxtglobalshortcut_mac.cpp index 829cae232..0bcea7f36 100644 --- a/3rdparty/qxt/qxtglobalshortcut_mac.cpp +++ b/3rdparty/qxt/qxtglobalshortcut_mac.cpp @@ -1,207 +1,207 @@ -/**************************************************************************** - ** - ** 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. - ** - ** - ** - ****************************************************************************/ -#include -#include "qxtglobalshortcut_p.h" -#include -#include -#include -#include - -typedef QPair Identifier; -static QMap keyRefs; -static QHash keyIDs; -static quint32 hotKeySerial = 0; -static bool qxt_mac_handler_installed = false; - -OSStatus qxt_mac_handle_hot_key(EventHandlerCallRef nextHandler, EventRef event, void* data) -{ - // pass event to the app event filter - Q_UNUSED(data); - qApp->macEventFilter(nextHandler, event); - return noErr; -} - -bool QxtGlobalShortcutPrivate::eventFilter(void* message) -//bool QxtGlobalShortcutPrivate::macEventFilter(EventHandlerCallRef caller, EventRef event) -{ - EventRef event = (EventRef) message; - if (GetEventClass(event) == kEventClassKeyboard && GetEventKind(event) == kEventHotKeyPressed) - { - EventHotKeyID keyID; - GetEventParameter(event, kEventParamDirectObject, typeEventHotKeyID, NULL, sizeof(keyID), NULL, &keyID); - Identifier id = keyIDs.key(keyID.id); - activateShortcut(id.second, id.first); - } - return false; -} - -quint32 QxtGlobalShortcutPrivate::nativeModifiers(Qt::KeyboardModifiers modifiers) -{ - quint32 native = 0; - if (modifiers & Qt::ShiftModifier) - native |= shiftKeyBit; - if (modifiers & Qt::ControlModifier) - native |= cmdKey; - if (modifiers & Qt::AltModifier) - native |= optionKey; - if (modifiers & Qt::MetaModifier) - native |= controlKey; - if (modifiers & Qt::KeypadModifier) - native |= kEventKeyModifierNumLockMask; - return native; -} - -quint32 QxtGlobalShortcutPrivate::nativeKeycode(Qt::Key key) -{ - UTF16Char ch; - // Constants found in NSEvent.h from AppKit.framework - if (key == Qt::Key_Up) ch = 0xF700; - else if (key == Qt::Key_Down) ch = 0xF701; - else if (key == Qt::Key_Left) ch = 0xF702; - else if (key == Qt::Key_Right) ch = 0xF703; - else if (key >= Qt::Key_F1 && key <= Qt::Key_F35) - ch = key - Qt::Key_F1 + 0xF704; - else if (key == Qt::Key_Insert) ch = 0xF727; - else if (key == Qt::Key_Delete) ch = 0xF728; - else if (key == Qt::Key_Home) ch = 0xF729; - else if (key == Qt::Key_End) ch = 0xF72B; - else if (key == Qt::Key_PageUp) ch = 0xF72C; - else if (key == Qt::Key_PageDown) ch = 0xF72D; - else if (key == Qt::Key_Print) ch = 0xF72E; - else if (key == Qt::Key_ScrollLock) ch = 0xF72F; - else if (key == Qt::Key_Pause) ch = 0xF730; - else if (key == Qt::Key_SysReq) ch = 0xF731; - else if (key == Qt::Key_Stop) ch = 0xF734; - else if (key == Qt::Key_Menu) ch = 0xF735; - else if (key == Qt::Key_Select) ch = 0xF741; - else if (key == Qt::Key_Execute) ch = 0xF742; - else if (key == Qt::Key_Help) ch = 0xF746; - else if (key == Qt::Key_Mode_switch) ch = 0xF747; - else if (key == Qt::Key_Escape) ch = 27; - else if (key == Qt::Key_Return) ch = 13; - else if (key == Qt::Key_Enter) ch = 3; - else if (key == Qt::Key_Tab) ch = 9; - else ch = key; - - KeyboardLayoutRef layout; - KeyboardLayoutKind layoutKind; - KLGetCurrentKeyboardLayout(&layout); - KLGetKeyboardLayoutProperty(layout, kKLKind, const_cast(reinterpret_cast(&layoutKind))); - - if (layoutKind == kKLKCHRKind) - { // no Unicode available - if (ch > 255) return 0; - - char* data; - KLGetKeyboardLayoutProperty(layout, kKLKCHRData, const_cast(reinterpret_cast(&data))); - int ct = *reinterpret_cast(data + 258); - for (int i = 0; i < ct; i++) - { - char* keyTable = data + 260 + 128 * i; - for (int j = 0; j < 128; j++) - { - if (keyTable[j] == ch) return j; - } - } - - return 0; - } - - char* data; - KLGetKeyboardLayoutProperty(layout, kKLuchrData, const_cast(reinterpret_cast(&data))); - UCKeyboardLayout* header = reinterpret_cast(data); - UCKeyboardTypeHeader* table = header->keyboardTypeList; - - for (quint32 i=0; i < header->keyboardTypeCount; i++) - { - UCKeyStateRecordsIndex* stateRec = 0; - if (table[i].keyStateRecordsIndexOffset != 0) - { - stateRec = reinterpret_cast(data + table[i].keyStateRecordsIndexOffset); - if (stateRec->keyStateRecordsIndexFormat != kUCKeyStateRecordsIndexFormat) stateRec = 0; - } - - UCKeyToCharTableIndex* charTable = reinterpret_cast(data + table[i].keyToCharTableIndexOffset); - if (charTable->keyToCharTableIndexFormat != kUCKeyToCharTableIndexFormat) continue; - - for (quint32 j=0; j < charTable->keyToCharTableCount; j++) - { - UCKeyOutput* keyToChar = reinterpret_cast(data + charTable->keyToCharTableOffsets[j]); - for (quint32 k=0; k < charTable->keyToCharTableSize; k++) - { - if (keyToChar[k] & kUCKeyOutputTestForIndexMask) - { - long idx = keyToChar[k] & kUCKeyOutputGetIndexMask; - if (stateRec && idx < stateRec->keyStateRecordCount) - { - UCKeyStateRecord* rec = reinterpret_cast(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); - } - qDebug() << 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); -} +/**************************************************************************** + ** + ** 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. + ** + ** + ** + ****************************************************************************/ +#include +#include "qxtglobalshortcut_p.h" +#include +#include +#include +#include + +typedef QPair Identifier; +static QMap keyRefs; +static QHash keyIDs; +static quint32 hotKeySerial = 0; +static bool qxt_mac_handler_installed = false; + +OSStatus qxt_mac_handle_hot_key(EventHandlerCallRef nextHandler, EventRef event, void* data) +{ + // pass event to the app event filter + Q_UNUSED(data); + qApp->macEventFilter(nextHandler, event); + return noErr; +} + +bool QxtGlobalShortcutPrivate::eventFilter(void* message) +//bool QxtGlobalShortcutPrivate::macEventFilter(EventHandlerCallRef caller, EventRef event) +{ + EventRef event = (EventRef) message; + if (GetEventClass(event) == kEventClassKeyboard && GetEventKind(event) == kEventHotKeyPressed) + { + EventHotKeyID keyID; + GetEventParameter(event, kEventParamDirectObject, typeEventHotKeyID, NULL, sizeof(keyID), NULL, &keyID); + Identifier id = keyIDs.key(keyID.id); + activateShortcut(id.second, id.first); + } + return false; +} + +quint32 QxtGlobalShortcutPrivate::nativeModifiers(Qt::KeyboardModifiers modifiers) +{ + quint32 native = 0; + if (modifiers & Qt::ShiftModifier) + native |= shiftKeyBit; + if (modifiers & Qt::ControlModifier) + native |= cmdKey; + if (modifiers & Qt::AltModifier) + native |= optionKey; + if (modifiers & Qt::MetaModifier) + native |= controlKey; + if (modifiers & Qt::KeypadModifier) + native |= kEventKeyModifierNumLockMask; + return native; +} + +quint32 QxtGlobalShortcutPrivate::nativeKeycode(Qt::Key key) +{ + UTF16Char ch; + // Constants found in NSEvent.h from AppKit.framework + if (key == Qt::Key_Up) ch = 0xF700; + else if (key == Qt::Key_Down) ch = 0xF701; + else if (key == Qt::Key_Left) ch = 0xF702; + else if (key == Qt::Key_Right) ch = 0xF703; + else if (key >= Qt::Key_F1 && key <= Qt::Key_F35) + ch = key - Qt::Key_F1 + 0xF704; + else if (key == Qt::Key_Insert) ch = 0xF727; + else if (key == Qt::Key_Delete) ch = 0xF728; + else if (key == Qt::Key_Home) ch = 0xF729; + else if (key == Qt::Key_End) ch = 0xF72B; + else if (key == Qt::Key_PageUp) ch = 0xF72C; + else if (key == Qt::Key_PageDown) ch = 0xF72D; + else if (key == Qt::Key_Print) ch = 0xF72E; + else if (key == Qt::Key_ScrollLock) ch = 0xF72F; + else if (key == Qt::Key_Pause) ch = 0xF730; + else if (key == Qt::Key_SysReq) ch = 0xF731; + else if (key == Qt::Key_Stop) ch = 0xF734; + else if (key == Qt::Key_Menu) ch = 0xF735; + else if (key == Qt::Key_Select) ch = 0xF741; + else if (key == Qt::Key_Execute) ch = 0xF742; + else if (key == Qt::Key_Help) ch = 0xF746; + else if (key == Qt::Key_Mode_switch) ch = 0xF747; + else if (key == Qt::Key_Escape) ch = 27; + else if (key == Qt::Key_Return) ch = 13; + else if (key == Qt::Key_Enter) ch = 3; + else if (key == Qt::Key_Tab) ch = 9; + else ch = key; + + KeyboardLayoutRef layout; + KeyboardLayoutKind layoutKind; + KLGetCurrentKeyboardLayout(&layout); + KLGetKeyboardLayoutProperty(layout, kKLKind, const_cast(reinterpret_cast(&layoutKind))); + + if (layoutKind == kKLKCHRKind) + { // no Unicode available + if (ch > 255) return 0; + + char* data; + KLGetKeyboardLayoutProperty(layout, kKLKCHRData, const_cast(reinterpret_cast(&data))); + int ct = *reinterpret_cast(data + 258); + for (int i = 0; i < ct; i++) + { + char* keyTable = data + 260 + 128 * i; + for (int j = 0; j < 128; j++) + { + if (keyTable[j] == ch) return j; + } + } + + return 0; + } + + char* data; + KLGetKeyboardLayoutProperty(layout, kKLuchrData, const_cast(reinterpret_cast(&data))); + UCKeyboardLayout* header = reinterpret_cast(data); + UCKeyboardTypeHeader* table = header->keyboardTypeList; + + for (quint32 i=0; i < header->keyboardTypeCount; i++) + { + UCKeyStateRecordsIndex* stateRec = 0; + if (table[i].keyStateRecordsIndexOffset != 0) + { + stateRec = reinterpret_cast(data + table[i].keyStateRecordsIndexOffset); + if (stateRec->keyStateRecordsIndexFormat != kUCKeyStateRecordsIndexFormat) stateRec = 0; + } + + UCKeyToCharTableIndex* charTable = reinterpret_cast(data + table[i].keyToCharTableIndexOffset); + if (charTable->keyToCharTableIndexFormat != kUCKeyToCharTableIndexFormat) continue; + + for (quint32 j=0; j < charTable->keyToCharTableCount; j++) + { + UCKeyOutput* keyToChar = reinterpret_cast(data + charTable->keyToCharTableOffsets[j]); + for (quint32 k=0; k < charTable->keyToCharTableSize; k++) + { + if (keyToChar[k] & kUCKeyOutputTestForIndexMask) + { + long idx = keyToChar[k] & kUCKeyOutputGetIndexMask; + if (stateRec && idx < stateRec->keyStateRecordCount) + { + UCKeyStateRecord* rec = reinterpret_cast(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); + } + qDebug() << 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); +} diff --git a/3rdparty/qxt/qxtglobalshortcut_p.h b/3rdparty/qxt/qxtglobalshortcut_p.h index 4f627cc3f..4570396fe 100644 --- a/3rdparty/qxt/qxtglobalshortcut_p.h +++ b/3rdparty/qxt/qxtglobalshortcut_p.h @@ -1,63 +1,63 @@ -/**************************************************************************** - ** - ** 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. - ** - ** - ** - ****************************************************************************/ -#ifndef QXTGLOBALSHORTCUT_P_H -#define QXTGLOBALSHORTCUT_P_H - -#include "qxtglobalshortcut.h" -#include -#include -#include - -class QxtGlobalShortcutPrivate : public QxtPrivate -{ -public: - QXT_DECLARE_PUBLIC(QxtGlobalShortcut) - QxtGlobalShortcutPrivate(); - ~QxtGlobalShortcutPrivate(); - - bool enabled; - Qt::Key key; - Qt::KeyboardModifiers mods; - - bool setShortcut(const QKeySequence& shortcut); - bool unsetShortcut(); - - static bool error; - static int ref; - static QAbstractEventDispatcher::EventFilter prevEventFilter; - static bool eventFilter(void* message); - -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 void activateShortcut(quint32 nativeKey, quint32 nativeMods); - - static QHash, QxtGlobalShortcut*> shortcuts; -}; - -#endif // QXTGLOBALSHORTCUT_P_H +/**************************************************************************** + ** + ** 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. + ** + ** + ** + ****************************************************************************/ +#ifndef QXTGLOBALSHORTCUT_P_H +#define QXTGLOBALSHORTCUT_P_H + +#include "qxtglobalshortcut.h" +#include +#include +#include + +class QxtGlobalShortcutPrivate : public QxtPrivate +{ +public: + QXT_DECLARE_PUBLIC(QxtGlobalShortcut) + QxtGlobalShortcutPrivate(); + ~QxtGlobalShortcutPrivate(); + + bool enabled; + Qt::Key key; + Qt::KeyboardModifiers mods; + + bool setShortcut(const QKeySequence& shortcut); + bool unsetShortcut(); + + static bool error; + static int ref; + static QAbstractEventDispatcher::EventFilter prevEventFilter; + static bool eventFilter(void* message); + +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 void activateShortcut(quint32 nativeKey, quint32 nativeMods); + + static QHash, QxtGlobalShortcut*> shortcuts; +}; + +#endif // QXTGLOBALSHORTCUT_P_H diff --git a/3rdparty/qxt/qxtglobalshortcut_win.cpp b/3rdparty/qxt/qxtglobalshortcut_win.cpp index fc461441d..d81f1089d 100644 --- a/3rdparty/qxt/qxtglobalshortcut_win.cpp +++ b/3rdparty/qxt/qxtglobalshortcut_win.cpp @@ -1,229 +1,229 @@ -/**************************************************************************** - ** - ** 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. - ** - ** - ** - ****************************************************************************/ -#include "qxtglobalshortcut_p.h" -#include - -bool QxtGlobalShortcutPrivate::eventFilter(void* message) -{ - MSG* msg = static_cast(message); - if (msg->message == WM_HOTKEY) - { - const quint32 keycode = HIWORD(msg->lParam); - const quint32 modifiers = LOWORD(msg->lParam); - activateShortcut(keycode, modifiers); - } - return false; -} - -quint32 QxtGlobalShortcutPrivate::nativeModifiers(Qt::KeyboardModifiers modifiers) -{ - // MOD_ALT, MOD_CONTROL, (MOD_KEYUP), MOD_SHIFT, MOD_WIN - quint32 native = 0; - if (modifiers & Qt::ShiftModifier) - native |= MOD_SHIFT; - if (modifiers & Qt::ControlModifier) - native |= MOD_CONTROL; - if (modifiers & Qt::AltModifier) - native |= MOD_ALT; - if (modifiers & Qt::MetaModifier) - native |= MOD_WIN; - // TODO: resolve these? - //if (modifiers & Qt::KeypadModifier) - //if (modifiers & Qt::GroupSwitchModifier) - return native; -} - -quint32 QxtGlobalShortcutPrivate::nativeKeycode(Qt::Key key) -{ - switch (key) - { - case Qt::Key_Escape: - return VK_ESCAPE; - case Qt::Key_Tab: - case Qt::Key_Backtab: - return VK_TAB; - case Qt::Key_Backspace: - return VK_BACK; - case Qt::Key_Return: - case Qt::Key_Enter: - return VK_RETURN; - case Qt::Key_Insert: - return VK_INSERT; - case Qt::Key_Delete: - return VK_DELETE; - case Qt::Key_Pause: - return VK_PAUSE; - case Qt::Key_Print: - return VK_PRINT; - case Qt::Key_Clear: - return VK_CLEAR; - case Qt::Key_Home: - return VK_HOME; - case Qt::Key_End: - return VK_END; - case Qt::Key_Left: - return VK_LEFT; - case Qt::Key_Up: - return VK_UP; - case Qt::Key_Right: - return VK_RIGHT; - case Qt::Key_Down: - return VK_DOWN; - case Qt::Key_PageUp: - return VK_PRIOR; - case Qt::Key_PageDown: - return VK_NEXT; - case Qt::Key_F1: - return VK_F1; - case Qt::Key_F2: - return VK_F2; - case Qt::Key_F3: - return VK_F3; - case Qt::Key_F4: - return VK_F4; - case Qt::Key_F5: - return VK_F5; - case Qt::Key_F6: - return VK_F6; - case Qt::Key_F7: - return VK_F7; - case Qt::Key_F8: - return VK_F8; - case Qt::Key_F9: - return VK_F9; - case Qt::Key_F10: - return VK_F10; - case Qt::Key_F11: - return VK_F11; - case Qt::Key_F12: - return VK_F12; - case Qt::Key_F13: - return VK_F13; - case Qt::Key_F14: - return VK_F14; - case Qt::Key_F15: - return VK_F15; - case Qt::Key_F16: - return VK_F16; - case Qt::Key_F17: - return VK_F17; - case Qt::Key_F18: - return VK_F18; - case Qt::Key_F19: - return VK_F19; - case Qt::Key_F20: - return VK_F20; - case Qt::Key_F21: - return VK_F21; - case Qt::Key_F22: - return VK_F22; - case Qt::Key_F23: - return VK_F23; - case Qt::Key_F24: - return VK_F24; - case Qt::Key_Space: - return VK_SPACE; - case Qt::Key_Asterisk: - return VK_MULTIPLY; - case Qt::Key_Plus: - return VK_ADD; - case Qt::Key_Comma: - return VK_SEPARATOR; - case Qt::Key_Minus: - return VK_SUBTRACT; - 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: - case Qt::Key_2: - case Qt::Key_3: - case Qt::Key_4: - case Qt::Key_5: - case Qt::Key_6: - case Qt::Key_7: - case Qt::Key_8: - case Qt::Key_9: - return key; - - // letters - case Qt::Key_A: - case Qt::Key_B: - case Qt::Key_C: - case Qt::Key_D: - case Qt::Key_E: - case Qt::Key_F: - case Qt::Key_G: - case Qt::Key_H: - case Qt::Key_I: - case Qt::Key_J: - case Qt::Key_K: - case Qt::Key_L: - case Qt::Key_M: - case Qt::Key_N: - case Qt::Key_O: - case Qt::Key_P: - case Qt::Key_Q: - case Qt::Key_R: - case Qt::Key_S: - case Qt::Key_T: - case Qt::Key_U: - case Qt::Key_V: - 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); -} +/**************************************************************************** + ** + ** 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. + ** + ** + ** + ****************************************************************************/ +#include "qxtglobalshortcut_p.h" +#include + +bool QxtGlobalShortcutPrivate::eventFilter(void* message) +{ + MSG* msg = static_cast(message); + if (msg->message == WM_HOTKEY) + { + const quint32 keycode = HIWORD(msg->lParam); + const quint32 modifiers = LOWORD(msg->lParam); + activateShortcut(keycode, modifiers); + } + return false; +} + +quint32 QxtGlobalShortcutPrivate::nativeModifiers(Qt::KeyboardModifiers modifiers) +{ + // MOD_ALT, MOD_CONTROL, (MOD_KEYUP), MOD_SHIFT, MOD_WIN + quint32 native = 0; + if (modifiers & Qt::ShiftModifier) + native |= MOD_SHIFT; + if (modifiers & Qt::ControlModifier) + native |= MOD_CONTROL; + if (modifiers & Qt::AltModifier) + native |= MOD_ALT; + if (modifiers & Qt::MetaModifier) + native |= MOD_WIN; + // TODO: resolve these? + //if (modifiers & Qt::KeypadModifier) + //if (modifiers & Qt::GroupSwitchModifier) + return native; +} + +quint32 QxtGlobalShortcutPrivate::nativeKeycode(Qt::Key key) +{ + switch (key) + { + case Qt::Key_Escape: + return VK_ESCAPE; + case Qt::Key_Tab: + case Qt::Key_Backtab: + return VK_TAB; + case Qt::Key_Backspace: + return VK_BACK; + case Qt::Key_Return: + case Qt::Key_Enter: + return VK_RETURN; + case Qt::Key_Insert: + return VK_INSERT; + case Qt::Key_Delete: + return VK_DELETE; + case Qt::Key_Pause: + return VK_PAUSE; + case Qt::Key_Print: + return VK_PRINT; + case Qt::Key_Clear: + return VK_CLEAR; + case Qt::Key_Home: + return VK_HOME; + case Qt::Key_End: + return VK_END; + case Qt::Key_Left: + return VK_LEFT; + case Qt::Key_Up: + return VK_UP; + case Qt::Key_Right: + return VK_RIGHT; + case Qt::Key_Down: + return VK_DOWN; + case Qt::Key_PageUp: + return VK_PRIOR; + case Qt::Key_PageDown: + return VK_NEXT; + case Qt::Key_F1: + return VK_F1; + case Qt::Key_F2: + return VK_F2; + case Qt::Key_F3: + return VK_F3; + case Qt::Key_F4: + return VK_F4; + case Qt::Key_F5: + return VK_F5; + case Qt::Key_F6: + return VK_F6; + case Qt::Key_F7: + return VK_F7; + case Qt::Key_F8: + return VK_F8; + case Qt::Key_F9: + return VK_F9; + case Qt::Key_F10: + return VK_F10; + case Qt::Key_F11: + return VK_F11; + case Qt::Key_F12: + return VK_F12; + case Qt::Key_F13: + return VK_F13; + case Qt::Key_F14: + return VK_F14; + case Qt::Key_F15: + return VK_F15; + case Qt::Key_F16: + return VK_F16; + case Qt::Key_F17: + return VK_F17; + case Qt::Key_F18: + return VK_F18; + case Qt::Key_F19: + return VK_F19; + case Qt::Key_F20: + return VK_F20; + case Qt::Key_F21: + return VK_F21; + case Qt::Key_F22: + return VK_F22; + case Qt::Key_F23: + return VK_F23; + case Qt::Key_F24: + return VK_F24; + case Qt::Key_Space: + return VK_SPACE; + case Qt::Key_Asterisk: + return VK_MULTIPLY; + case Qt::Key_Plus: + return VK_ADD; + case Qt::Key_Comma: + return VK_SEPARATOR; + case Qt::Key_Minus: + return VK_SUBTRACT; + 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: + case Qt::Key_2: + case Qt::Key_3: + case Qt::Key_4: + case Qt::Key_5: + case Qt::Key_6: + case Qt::Key_7: + case Qt::Key_8: + case Qt::Key_9: + return key; + + // letters + case Qt::Key_A: + case Qt::Key_B: + case Qt::Key_C: + case Qt::Key_D: + case Qt::Key_E: + case Qt::Key_F: + case Qt::Key_G: + case Qt::Key_H: + case Qt::Key_I: + case Qt::Key_J: + case Qt::Key_K: + case Qt::Key_L: + case Qt::Key_M: + case Qt::Key_N: + case Qt::Key_O: + case Qt::Key_P: + case Qt::Key_Q: + case Qt::Key_R: + case Qt::Key_S: + case Qt::Key_T: + case Qt::Key_U: + case Qt::Key_V: + 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); +} diff --git a/3rdparty/qxt/qxtglobalshortcut_x11.cpp b/3rdparty/qxt/qxtglobalshortcut_x11.cpp index 24b4abad9..1a8549d8a 100644 --- a/3rdparty/qxt/qxtglobalshortcut_x11.cpp +++ b/3rdparty/qxt/qxtglobalshortcut_x11.cpp @@ -1,135 +1,135 @@ -/**************************************************************************** - ** - ** 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. - ** - ** - ** - ****************************************************************************/ -#include "qxtglobalshortcut_p.h" -#include -#include -#include - -#include "keymapper_x11.h" - -static int (*original_x_errhandler)(Display* display, XErrorEvent* event); - -static int qxt_x_errhandler(Display* display, XErrorEvent *event) -{ - Q_UNUSED(display); - switch (event->error_code) - { - case BadAccess: - case BadValue: - case BadWindow: - if (event->request_code == 33 /* X_GrabKey */ || - event->request_code == 34 /* X_UngrabKey */) - { - QxtGlobalShortcutPrivate::error = true; - //TODO: - //char errstr[256]; - //XGetErrorText(dpy, err->error_code, errstr, 256); - } - default: - return 0; - } -} - -bool QxtGlobalShortcutPrivate::eventFilter(void* message) -{ - XEvent* event = static_cast(message); - if (event->type == KeyPress) - { - XKeyEvent* key = (XKeyEvent*) event; - activateShortcut(key->keycode, - // Mod1Mask == Alt, Mod4Mask == Meta - key->state & (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; - // TODO: resolve these? - //if (modifiers & Qt::MetaModifier) - //if (modifiers & Qt::KeypadModifier) - //if (modifiers & Qt::GroupSwitchModifier) - return native; -} - -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(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, keysym); -} - -bool QxtGlobalShortcutPrivate::registerShortcut(quint32 nativeKey, quint32 nativeMods) -{ - Display* display = QX11Info::display(); - Window window = QX11Info::appRootWindow(); - Bool owner = True; - int pointer = GrabModeAsync; - int keyboard = GrabModeAsync; - error = false; - original_x_errhandler = XSetErrorHandler(qxt_x_errhandler); - XGrabKey(display, nativeKey, nativeMods, window, owner, pointer, keyboard); - XGrabKey(display, nativeKey, nativeMods | Mod2Mask, window, owner, pointer, keyboard); // allow numlock - XSync(display, False); - XSetErrorHandler(original_x_errhandler); - return !error; -} - -bool QxtGlobalShortcutPrivate::unregisterShortcut(quint32 nativeKey, quint32 nativeMods) -{ - Display* display = QX11Info::display(); - Window window = QX11Info::appRootWindow(); - error = false; - original_x_errhandler = XSetErrorHandler(qxt_x_errhandler); - XUngrabKey(display, nativeKey, nativeMods, window); - XUngrabKey(display, nativeKey, nativeMods | Mod2Mask, window); // allow numlock - XSync(display, False); - XSetErrorHandler(original_x_errhandler); - return !error; -} +/**************************************************************************** + ** + ** 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. + ** + ** + ** + ****************************************************************************/ +#include "qxtglobalshortcut_p.h" +#include +#include +#include + +#include "keymapper_x11.h" + +static int (*original_x_errhandler)(Display* display, XErrorEvent* event); + +static int qxt_x_errhandler(Display* display, XErrorEvent *event) +{ + Q_UNUSED(display); + switch (event->error_code) + { + case BadAccess: + case BadValue: + case BadWindow: + if (event->request_code == 33 /* X_GrabKey */ || + event->request_code == 34 /* X_UngrabKey */) + { + QxtGlobalShortcutPrivate::error = true; + //TODO: + //char errstr[256]; + //XGetErrorText(dpy, err->error_code, errstr, 256); + } + default: + return 0; + } +} + +bool QxtGlobalShortcutPrivate::eventFilter(void* message) +{ + XEvent* event = static_cast(message); + if (event->type == KeyPress) + { + XKeyEvent* key = (XKeyEvent*) event; + activateShortcut(key->keycode, + // Mod1Mask == Alt, Mod4Mask == Meta + key->state & (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; + // TODO: resolve these? + //if (modifiers & Qt::MetaModifier) + //if (modifiers & Qt::KeypadModifier) + //if (modifiers & Qt::GroupSwitchModifier) + return native; +} + +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(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, keysym); +} + +bool QxtGlobalShortcutPrivate::registerShortcut(quint32 nativeKey, quint32 nativeMods) +{ + Display* display = QX11Info::display(); + Window window = QX11Info::appRootWindow(); + Bool owner = True; + int pointer = GrabModeAsync; + int keyboard = GrabModeAsync; + error = false; + original_x_errhandler = XSetErrorHandler(qxt_x_errhandler); + XGrabKey(display, nativeKey, nativeMods, window, owner, pointer, keyboard); + XGrabKey(display, nativeKey, nativeMods | Mod2Mask, window, owner, pointer, keyboard); // allow numlock + XSync(display, False); + XSetErrorHandler(original_x_errhandler); + return !error; +} + +bool QxtGlobalShortcutPrivate::unregisterShortcut(quint32 nativeKey, quint32 nativeMods) +{ + Display* display = QX11Info::display(); + Window window = QX11Info::appRootWindow(); + error = false; + original_x_errhandler = XSetErrorHandler(qxt_x_errhandler); + XUngrabKey(display, nativeKey, nativeMods, window); + XUngrabKey(display, nativeKey, nativeMods | Mod2Mask, window); // allow numlock + XSync(display, False); + XSetErrorHandler(original_x_errhandler); + return !error; +}