Replace NULL and 0 with nullptr
This commit is contained in:
2
3rdparty/qtsingleapplication/qtlocalpeer.cpp
vendored
2
3rdparty/qtsingleapplication/qtlocalpeer.cpp
vendored
@@ -157,7 +157,7 @@ bool QtLocalPeer::sendMessage(const QString &message, int timeout)
|
|||||||
Sleep(DWORD(ms));
|
Sleep(DWORD(ms));
|
||||||
#else
|
#else
|
||||||
struct timespec ts = { ms / 1000, (ms % 1000) * 1000 * 1000 };
|
struct timespec ts = { ms / 1000, (ms % 1000) * 1000 * 1000 };
|
||||||
nanosleep(&ts, NULL);
|
nanosleep(&ts, nullptr);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (!connOk)
|
if (!connOk)
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ Qt::HANDLE QtLockedFile::getMutexHandle(int idx, bool doCreate)
|
|||||||
|
|
||||||
Qt::HANDLE mutex;
|
Qt::HANDLE mutex;
|
||||||
if (doCreate) {
|
if (doCreate) {
|
||||||
mutex = CreateMutexW(NULL, FALSE, (WCHAR*)mname.utf16());
|
mutex = CreateMutexW(nullptr, FALSE, (WCHAR*)mname.utf16());
|
||||||
if (!mutex) {
|
if (!mutex) {
|
||||||
qErrnoWarning("QtLockedFile::lock(): CreateMutex failed");
|
qErrnoWarning("QtLockedFile::lock(): CreateMutex failed");
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
6
3rdparty/qxt/qxtglobalshortcut.h
vendored
6
3rdparty/qxt/qxtglobalshortcut.h
vendored
@@ -47,9 +47,9 @@ class QXT_GUI_EXPORT QxtGlobalShortcut : public QObject
|
|||||||
Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut)
|
Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit QxtGlobalShortcut(QObject* parent = 0);
|
explicit QxtGlobalShortcut(QObject* parent = nullptr);
|
||||||
explicit QxtGlobalShortcut(const QKeySequence& shortcut, QObject* parent = 0);
|
explicit QxtGlobalShortcut(const QKeySequence& shortcut, QObject* parent = nullptr);
|
||||||
virtual ~QxtGlobalShortcut();
|
~QxtGlobalShortcut();
|
||||||
|
|
||||||
QKeySequence shortcut() const;
|
QKeySequence shortcut() const;
|
||||||
bool setShortcut(const QKeySequence& shortcut);
|
bool setShortcut(const QKeySequence& shortcut);
|
||||||
|
|||||||
456
3rdparty/qxt/qxtglobalshortcut_mac.cpp
vendored
456
3rdparty/qxt/qxtglobalshortcut_mac.cpp
vendored
@@ -1,4 +1,4 @@
|
|||||||
#include <Carbon/Carbon.h>
|
#include <Carbon/Carbon.h>
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
** Copyright (c) 2006 - 2011, the LibQxt project.
|
** Copyright (c) 2006 - 2011, the LibQxt project.
|
||||||
** See the Qxt AUTHORS file for a list of authors and copyright holders.
|
** See the Qxt AUTHORS file for a list of authors and copyright holders.
|
||||||
@@ -29,230 +29,230 @@
|
|||||||
** <http://libqxt.org> <foundation@libqxt.org>
|
** <http://libqxt.org> <foundation@libqxt.org>
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
#include "qxtglobalshortcut_p.h"
|
#include "qxtglobalshortcut_p.h"
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
|
||||||
typedef QPair<uint, uint> Identifier;
|
typedef QPair<uint, uint> Identifier;
|
||||||
static QMap<quint32, EventHotKeyRef> keyRefs;
|
static QMap<quint32, EventHotKeyRef> keyRefs;
|
||||||
static QHash<Identifier, quint32> keyIDs;
|
static QHash<Identifier, quint32> keyIDs;
|
||||||
static quint32 hotKeySerial = 0;
|
static quint32 hotKeySerial = 0;
|
||||||
static bool qxt_mac_handler_installed = false;
|
static bool qxt_mac_handler_installed = false;
|
||||||
|
|
||||||
OSStatus qxt_mac_handle_hot_key(EventHandlerCallRef nextHandler, EventRef event, void* data)
|
OSStatus qxt_mac_handle_hot_key(EventHandlerCallRef nextHandler, EventRef event, void* data)
|
||||||
{
|
{
|
||||||
Q_UNUSED(nextHandler);
|
Q_UNUSED(nextHandler);
|
||||||
Q_UNUSED(data);
|
Q_UNUSED(data);
|
||||||
if (GetEventClass(event) == kEventClassKeyboard && GetEventKind(event) == kEventHotKeyPressed)
|
if (GetEventClass(event) == kEventClassKeyboard && GetEventKind(event) == kEventHotKeyPressed)
|
||||||
{
|
{
|
||||||
EventHotKeyID keyID;
|
EventHotKeyID keyID;
|
||||||
GetEventParameter(event, kEventParamDirectObject, typeEventHotKeyID, NULL, sizeof(keyID), NULL, &keyID);
|
GetEventParameter(event, kEventParamDirectObject, typeEventHotKeyID, nullptr, sizeof(keyID), nullptr, &keyID);
|
||||||
Identifier id = keyIDs.key(keyID.id);
|
Identifier id = keyIDs.key(keyID.id);
|
||||||
QxtGlobalShortcutPrivate::activateShortcut(id.second, id.first);
|
QxtGlobalShortcutPrivate::activateShortcut(id.second, id.first);
|
||||||
}
|
}
|
||||||
return noErr;
|
return noErr;
|
||||||
}
|
}
|
||||||
|
|
||||||
quint32 QxtGlobalShortcutPrivate::nativeModifiers(Qt::KeyboardModifiers modifiers)
|
quint32 QxtGlobalShortcutPrivate::nativeModifiers(Qt::KeyboardModifiers modifiers)
|
||||||
{
|
{
|
||||||
quint32 native = 0;
|
quint32 native = 0;
|
||||||
if (modifiers & Qt::ShiftModifier)
|
if (modifiers & Qt::ShiftModifier)
|
||||||
native |= shiftKey;
|
native |= shiftKey;
|
||||||
if (modifiers & Qt::ControlModifier)
|
if (modifiers & Qt::ControlModifier)
|
||||||
native |= cmdKey;
|
native |= cmdKey;
|
||||||
if (modifiers & Qt::AltModifier)
|
if (modifiers & Qt::AltModifier)
|
||||||
native |= optionKey;
|
native |= optionKey;
|
||||||
if (modifiers & Qt::MetaModifier)
|
if (modifiers & Qt::MetaModifier)
|
||||||
native |= controlKey;
|
native |= controlKey;
|
||||||
if (modifiers & Qt::KeypadModifier)
|
if (modifiers & Qt::KeypadModifier)
|
||||||
native |= kEventKeyModifierNumLockMask;
|
native |= kEventKeyModifierNumLockMask;
|
||||||
return native;
|
return native;
|
||||||
}
|
}
|
||||||
|
|
||||||
quint32 QxtGlobalShortcutPrivate::nativeKeycode(Qt::Key key)
|
quint32 QxtGlobalShortcutPrivate::nativeKeycode(Qt::Key key)
|
||||||
{
|
{
|
||||||
UTF16Char ch;
|
UTF16Char ch;
|
||||||
// Constants found in NSEvent.h from AppKit.framework
|
// Constants found in NSEvent.h from AppKit.framework
|
||||||
switch (key)
|
switch (key)
|
||||||
{
|
{
|
||||||
case Qt::Key_Return:
|
case Qt::Key_Return:
|
||||||
return kVK_Return;
|
return kVK_Return;
|
||||||
case Qt::Key_Enter:
|
case Qt::Key_Enter:
|
||||||
return kVK_ANSI_KeypadEnter;
|
return kVK_ANSI_KeypadEnter;
|
||||||
case Qt::Key_Tab:
|
case Qt::Key_Tab:
|
||||||
return kVK_Tab;
|
return kVK_Tab;
|
||||||
case Qt::Key_Space:
|
case Qt::Key_Space:
|
||||||
return kVK_Space;
|
return kVK_Space;
|
||||||
case Qt::Key_Backspace:
|
case Qt::Key_Backspace:
|
||||||
return kVK_Delete;
|
return kVK_Delete;
|
||||||
case Qt::Key_Control:
|
case Qt::Key_Control:
|
||||||
return kVK_Command;
|
return kVK_Command;
|
||||||
case Qt::Key_Shift:
|
case Qt::Key_Shift:
|
||||||
return kVK_Shift;
|
return kVK_Shift;
|
||||||
case Qt::Key_CapsLock:
|
case Qt::Key_CapsLock:
|
||||||
return kVK_CapsLock;
|
return kVK_CapsLock;
|
||||||
case Qt::Key_Option:
|
case Qt::Key_Option:
|
||||||
return kVK_Option;
|
return kVK_Option;
|
||||||
case Qt::Key_Meta:
|
case Qt::Key_Meta:
|
||||||
return kVK_Control;
|
return kVK_Control;
|
||||||
case Qt::Key_F17:
|
case Qt::Key_F17:
|
||||||
return kVK_F17;
|
return kVK_F17;
|
||||||
case Qt::Key_VolumeUp:
|
case Qt::Key_VolumeUp:
|
||||||
return kVK_VolumeUp;
|
return kVK_VolumeUp;
|
||||||
case Qt::Key_VolumeDown:
|
case Qt::Key_VolumeDown:
|
||||||
return kVK_VolumeDown;
|
return kVK_VolumeDown;
|
||||||
case Qt::Key_F18:
|
case Qt::Key_F18:
|
||||||
return kVK_F18;
|
return kVK_F18;
|
||||||
case Qt::Key_F19:
|
case Qt::Key_F19:
|
||||||
return kVK_F19;
|
return kVK_F19;
|
||||||
case Qt::Key_F20:
|
case Qt::Key_F20:
|
||||||
return kVK_F20;
|
return kVK_F20;
|
||||||
case Qt::Key_F5:
|
case Qt::Key_F5:
|
||||||
return kVK_F5;
|
return kVK_F5;
|
||||||
case Qt::Key_F6:
|
case Qt::Key_F6:
|
||||||
return kVK_F6;
|
return kVK_F6;
|
||||||
case Qt::Key_F7:
|
case Qt::Key_F7:
|
||||||
return kVK_F7;
|
return kVK_F7;
|
||||||
case Qt::Key_F3:
|
case Qt::Key_F3:
|
||||||
return kVK_F3;
|
return kVK_F3;
|
||||||
case Qt::Key_F8:
|
case Qt::Key_F8:
|
||||||
return kVK_F8;
|
return kVK_F8;
|
||||||
case Qt::Key_F9:
|
case Qt::Key_F9:
|
||||||
return kVK_F9;
|
return kVK_F9;
|
||||||
case Qt::Key_F11:
|
case Qt::Key_F11:
|
||||||
return kVK_F11;
|
return kVK_F11;
|
||||||
case Qt::Key_F13:
|
case Qt::Key_F13:
|
||||||
return kVK_F13;
|
return kVK_F13;
|
||||||
case Qt::Key_F16:
|
case Qt::Key_F16:
|
||||||
return kVK_F16;
|
return kVK_F16;
|
||||||
case Qt::Key_F14:
|
case Qt::Key_F14:
|
||||||
return kVK_F14;
|
return kVK_F14;
|
||||||
case Qt::Key_F10:
|
case Qt::Key_F10:
|
||||||
return kVK_F10;
|
return kVK_F10;
|
||||||
case Qt::Key_F12:
|
case Qt::Key_F12:
|
||||||
return kVK_F12;
|
return kVK_F12;
|
||||||
case Qt::Key_F15:
|
case Qt::Key_F15:
|
||||||
return kVK_F15;
|
return kVK_F15;
|
||||||
case Qt::Key_Help:
|
case Qt::Key_Help:
|
||||||
return kVK_Help;
|
return kVK_Help;
|
||||||
case Qt::Key_Home:
|
case Qt::Key_Home:
|
||||||
return kVK_Home;
|
return kVK_Home;
|
||||||
case Qt::Key_PageUp:
|
case Qt::Key_PageUp:
|
||||||
return kVK_PageUp;
|
return kVK_PageUp;
|
||||||
case Qt::Key_Delete:
|
case Qt::Key_Delete:
|
||||||
return kVK_ForwardDelete;
|
return kVK_ForwardDelete;
|
||||||
case Qt::Key_F4:
|
case Qt::Key_F4:
|
||||||
return kVK_F4;
|
return kVK_F4;
|
||||||
case Qt::Key_End:
|
case Qt::Key_End:
|
||||||
return kVK_End;
|
return kVK_End;
|
||||||
case Qt::Key_F2:
|
case Qt::Key_F2:
|
||||||
return kVK_F2;
|
return kVK_F2;
|
||||||
case Qt::Key_PageDown:
|
case Qt::Key_PageDown:
|
||||||
return kVK_PageDown;
|
return kVK_PageDown;
|
||||||
case Qt::Key_F1:
|
case Qt::Key_F1:
|
||||||
return kVK_F1;
|
return kVK_F1;
|
||||||
case Qt::Key_Left:
|
case Qt::Key_Left:
|
||||||
return kVK_LeftArrow;
|
return kVK_LeftArrow;
|
||||||
case Qt::Key_Right:
|
case Qt::Key_Right:
|
||||||
return kVK_RightArrow;
|
return kVK_RightArrow;
|
||||||
case Qt::Key_Down:
|
case Qt::Key_Down:
|
||||||
return kVK_DownArrow;
|
return kVK_DownArrow;
|
||||||
case Qt::Key_Up:
|
case Qt::Key_Up:
|
||||||
return kVK_UpArrow;
|
return kVK_UpArrow;
|
||||||
default:
|
default:
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key == Qt::Key_Escape) ch = 27;
|
if (key == Qt::Key_Escape) ch = 27;
|
||||||
else if (key == Qt::Key_Return) ch = 13;
|
else if (key == Qt::Key_Return) ch = 13;
|
||||||
else if (key == Qt::Key_Enter) ch = 3;
|
else if (key == Qt::Key_Enter) ch = 3;
|
||||||
else if (key == Qt::Key_Tab) ch = 9;
|
else if (key == Qt::Key_Tab) ch = 9;
|
||||||
else ch = key;
|
else ch = key;
|
||||||
|
|
||||||
CFDataRef currentLayoutData;
|
CFDataRef currentLayoutData;
|
||||||
TISInputSourceRef currentKeyboard = TISCopyCurrentKeyboardInputSource();
|
TISInputSourceRef currentKeyboard = TISCopyCurrentKeyboardInputSource();
|
||||||
|
|
||||||
if (currentKeyboard == NULL)
|
if (currentKeyboard == nullptr)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
currentLayoutData = (CFDataRef)TISGetInputSourceProperty(currentKeyboard, kTISPropertyUnicodeKeyLayoutData);
|
currentLayoutData = (CFDataRef)TISGetInputSourceProperty(currentKeyboard, kTISPropertyUnicodeKeyLayoutData);
|
||||||
CFRelease(currentKeyboard);
|
CFRelease(currentKeyboard);
|
||||||
if (currentLayoutData == NULL)
|
if (currentLayoutData == nullptr)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
UCKeyboardLayout* header = (UCKeyboardLayout*)CFDataGetBytePtr(currentLayoutData);
|
UCKeyboardLayout* header = (UCKeyboardLayout*)CFDataGetBytePtr(currentLayoutData);
|
||||||
UCKeyboardTypeHeader* table = header->keyboardTypeList;
|
UCKeyboardTypeHeader* table = header->keyboardTypeList;
|
||||||
|
|
||||||
uint8_t *data = (uint8_t*)header;
|
uint8_t *data = (uint8_t*)header;
|
||||||
// God, would a little documentation for this shit kill you...
|
// God, would a little documentation for this shit kill you...
|
||||||
for (quint32 i=0; i < header->keyboardTypeCount; i++)
|
for (quint32 i=0; i < header->keyboardTypeCount; i++)
|
||||||
{
|
{
|
||||||
UCKeyStateRecordsIndex* stateRec = 0;
|
UCKeyStateRecordsIndex* stateRec = 0;
|
||||||
if (table[i].keyStateRecordsIndexOffset != 0)
|
if (table[i].keyStateRecordsIndexOffset != 0)
|
||||||
{
|
{
|
||||||
stateRec = reinterpret_cast<UCKeyStateRecordsIndex*>(data + table[i].keyStateRecordsIndexOffset);
|
stateRec = reinterpret_cast<UCKeyStateRecordsIndex*>(data + table[i].keyStateRecordsIndexOffset);
|
||||||
if (stateRec->keyStateRecordsIndexFormat != kUCKeyStateRecordsIndexFormat) stateRec = 0;
|
if (stateRec->keyStateRecordsIndexFormat != kUCKeyStateRecordsIndexFormat) stateRec = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
UCKeyToCharTableIndex* charTable = reinterpret_cast<UCKeyToCharTableIndex*>(data + table[i].keyToCharTableIndexOffset);
|
UCKeyToCharTableIndex* charTable = reinterpret_cast<UCKeyToCharTableIndex*>(data + table[i].keyToCharTableIndexOffset);
|
||||||
if (charTable->keyToCharTableIndexFormat != kUCKeyToCharTableIndexFormat) continue;
|
if (charTable->keyToCharTableIndexFormat != kUCKeyToCharTableIndexFormat) continue;
|
||||||
|
|
||||||
for (quint32 j=0; j < charTable->keyToCharTableCount; j++)
|
for (quint32 j=0; j < charTable->keyToCharTableCount; j++)
|
||||||
{
|
{
|
||||||
UCKeyOutput* keyToChar = reinterpret_cast<UCKeyOutput*>(data + charTable->keyToCharTableOffsets[j]);
|
UCKeyOutput* keyToChar = reinterpret_cast<UCKeyOutput*>(data + charTable->keyToCharTableOffsets[j]);
|
||||||
for (quint32 k=0; k < charTable->keyToCharTableSize; k++)
|
for (quint32 k=0; k < charTable->keyToCharTableSize; k++)
|
||||||
{
|
{
|
||||||
if (keyToChar[k] & kUCKeyOutputTestForIndexMask)
|
if (keyToChar[k] & kUCKeyOutputTestForIndexMask)
|
||||||
{
|
{
|
||||||
long idx = keyToChar[k] & kUCKeyOutputGetIndexMask;
|
long idx = keyToChar[k] & kUCKeyOutputGetIndexMask;
|
||||||
if (stateRec && idx < stateRec->keyStateRecordCount)
|
if (stateRec && idx < stateRec->keyStateRecordCount)
|
||||||
{
|
{
|
||||||
UCKeyStateRecord* rec = reinterpret_cast<UCKeyStateRecord*>(data + stateRec->keyStateRecordOffsets[idx]);
|
UCKeyStateRecord* rec = reinterpret_cast<UCKeyStateRecord*>(data + stateRec->keyStateRecordOffsets[idx]);
|
||||||
if (rec->stateZeroCharData == ch) return k;
|
if (rec->stateZeroCharData == ch) return k;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!(keyToChar[k] & kUCKeyOutputSequenceIndexMask) && keyToChar[k] < 0xFFFE)
|
else if (!(keyToChar[k] & kUCKeyOutputSequenceIndexMask) && keyToChar[k] < 0xFFFE)
|
||||||
{
|
{
|
||||||
if (keyToChar[k] == ch) return k;
|
if (keyToChar[k] == ch) return k;
|
||||||
}
|
}
|
||||||
} // for k
|
} // for k
|
||||||
} // for j
|
} // for j
|
||||||
} // for i
|
} // for i
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QxtGlobalShortcutPrivate::registerShortcut(quint32 nativeKey, quint32 nativeMods)
|
bool QxtGlobalShortcutPrivate::registerShortcut(quint32 nativeKey, quint32 nativeMods)
|
||||||
{
|
{
|
||||||
if (!qxt_mac_handler_installed)
|
if (!qxt_mac_handler_installed)
|
||||||
{
|
{
|
||||||
EventTypeSpec t;
|
EventTypeSpec t;
|
||||||
t.eventClass = kEventClassKeyboard;
|
t.eventClass = kEventClassKeyboard;
|
||||||
t.eventKind = kEventHotKeyPressed;
|
t.eventKind = kEventHotKeyPressed;
|
||||||
InstallApplicationEventHandler(&qxt_mac_handle_hot_key, 1, &t, NULL, NULL);
|
InstallApplicationEventHandler(&qxt_mac_handle_hot_key, 1, &t, nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
EventHotKeyID keyID;
|
EventHotKeyID keyID;
|
||||||
keyID.signature = 'cute';
|
keyID.signature = 'cute';
|
||||||
keyID.id = ++hotKeySerial;
|
keyID.id = ++hotKeySerial;
|
||||||
|
|
||||||
EventHotKeyRef ref = 0;
|
EventHotKeyRef ref = 0;
|
||||||
bool rv = !RegisterEventHotKey(nativeKey, nativeMods, keyID, GetApplicationEventTarget(), 0, &ref);
|
bool rv = !RegisterEventHotKey(nativeKey, nativeMods, keyID, GetApplicationEventTarget(), 0, &ref);
|
||||||
if (rv)
|
if (rv)
|
||||||
{
|
{
|
||||||
keyIDs.insert(Identifier(nativeMods, nativeKey), keyID.id);
|
keyIDs.insert(Identifier(nativeMods, nativeKey), keyID.id);
|
||||||
keyRefs.insert(keyID.id, ref);
|
keyRefs.insert(keyID.id, ref);
|
||||||
}
|
}
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QxtGlobalShortcutPrivate::unregisterShortcut(quint32 nativeKey, quint32 nativeMods)
|
bool QxtGlobalShortcutPrivate::unregisterShortcut(quint32 nativeKey, quint32 nativeMods)
|
||||||
{
|
{
|
||||||
Identifier id(nativeMods, nativeKey);
|
Identifier id(nativeMods, nativeKey);
|
||||||
if (!keyIDs.contains(id)) return false;
|
if (!keyIDs.contains(id)) return false;
|
||||||
|
|
||||||
EventHotKeyRef ref = keyRefs.take(keyIDs[id]);
|
EventHotKeyRef ref = keyRefs.take(keyIDs[id]);
|
||||||
keyIDs.remove(id);
|
keyIDs.remove(id);
|
||||||
return !UnregisterEventHotKey(ref);
|
return !UnregisterEventHotKey(ref);
|
||||||
}
|
}
|
||||||
|
|||||||
168
3rdparty/qxt/qxtglobalshortcut_p.h
vendored
168
3rdparty/qxt/qxtglobalshortcut_p.h
vendored
@@ -1,84 +1,84 @@
|
|||||||
#ifndef QXTGLOBALSHORTCUT_P_H
|
#ifndef QXTGLOBALSHORTCUT_P_H
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
** Copyright (c) 2006 - 2011, the LibQxt project.
|
** Copyright (c) 2006 - 2011, the LibQxt project.
|
||||||
** See the Qxt AUTHORS file for a list of authors and copyright holders.
|
** See the Qxt AUTHORS file for a list of authors and copyright holders.
|
||||||
** All rights reserved.
|
** All rights reserved.
|
||||||
**
|
**
|
||||||
** Redistribution and use in source and binary forms, with or without
|
** Redistribution and use in source and binary forms, with or without
|
||||||
** modification, are permitted provided that the following conditions are met:
|
** modification, are permitted provided that the following conditions are met:
|
||||||
** * Redistributions of source code must retain the above copyright
|
** * Redistributions of source code must retain the above copyright
|
||||||
** notice, this list of conditions and the following disclaimer.
|
** notice, this list of conditions and the following disclaimer.
|
||||||
** * Redistributions in binary form must reproduce the above copyright
|
** * Redistributions in binary form must reproduce the above copyright
|
||||||
** notice, this list of conditions and the following disclaimer in the
|
** notice, this list of conditions and the following disclaimer in the
|
||||||
** documentation and/or other materials provided with the distribution.
|
** documentation and/or other materials provided with the distribution.
|
||||||
** * Neither the name of the LibQxt project nor the
|
** * Neither the name of the LibQxt project nor the
|
||||||
** names of its contributors may be used to endorse or promote products
|
** names of its contributors may be used to endorse or promote products
|
||||||
** derived from this software without specific prior written permission.
|
** derived from this software without specific prior written permission.
|
||||||
**
|
**
|
||||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
** 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
|
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
** DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
** DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||||
** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
** 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
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
**
|
**
|
||||||
** <http://libqxt.org> <foundation@libqxt.org>
|
** <http://libqxt.org> <foundation@libqxt.org>
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
#define QXTGLOBALSHORTCUT_P_H
|
#define QXTGLOBALSHORTCUT_P_H
|
||||||
|
|
||||||
#include "qxtglobalshortcut.h"
|
#include "qxtglobalshortcut.h"
|
||||||
#include <QAbstractEventDispatcher>
|
#include <QAbstractEventDispatcher>
|
||||||
#include <QKeySequence>
|
#include <QKeySequence>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
|
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
|
||||||
#include <QAbstractNativeEventFilter>
|
#include <QAbstractNativeEventFilter>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
class QxtGlobalShortcutPrivate : public QxtPrivate<QxtGlobalShortcut>
|
class QxtGlobalShortcutPrivate : public QxtPrivate<QxtGlobalShortcut>
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
|
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
|
||||||
,public QAbstractNativeEventFilter
|
,public QAbstractNativeEventFilter
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
QXT_DECLARE_PUBLIC(QxtGlobalShortcut)
|
QXT_DECLARE_PUBLIC(QxtGlobalShortcut)
|
||||||
QxtGlobalShortcutPrivate();
|
QxtGlobalShortcutPrivate();
|
||||||
~QxtGlobalShortcutPrivate();
|
~QxtGlobalShortcutPrivate();
|
||||||
|
|
||||||
bool enabled;
|
bool enabled;
|
||||||
Qt::Key key;
|
Qt::Key key;
|
||||||
Qt::KeyboardModifiers mods;
|
Qt::KeyboardModifiers mods;
|
||||||
|
|
||||||
bool setShortcut(const QKeySequence& shortcut);
|
bool setShortcut(const QKeySequence& shortcut);
|
||||||
bool unsetShortcut();
|
bool unsetShortcut();
|
||||||
|
|
||||||
static bool error;
|
static bool error;
|
||||||
#ifndef Q_OS_MAC
|
#ifndef Q_OS_MAC
|
||||||
static int ref;
|
static int ref;
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
||||||
static QAbstractEventDispatcher::EventFilter prevEventFilter;
|
static QAbstractEventDispatcher::EventFilter prevEventFilter;
|
||||||
static bool eventFilter(void* message);
|
static bool eventFilter(void* message);
|
||||||
#else
|
#else
|
||||||
virtual bool nativeEventFilter(const QByteArray & eventType, void * message, long * result);
|
virtual bool nativeEventFilter(const QByteArray & eventType, void * message, long * result);
|
||||||
#endif // QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
#endif // QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
||||||
#endif // Q_OS_MAC
|
#endif // Q_OS_MAC
|
||||||
|
|
||||||
static void activateShortcut(quint32 nativeKey, quint32 nativeMods);
|
static void activateShortcut(quint32 nativeKey, quint32 nativeMods);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static quint32 nativeKeycode(Qt::Key keycode);
|
static quint32 nativeKeycode(Qt::Key keycode);
|
||||||
static quint32 nativeModifiers(Qt::KeyboardModifiers modifiers);
|
static quint32 nativeModifiers(Qt::KeyboardModifiers modifiers);
|
||||||
|
|
||||||
static bool registerShortcut(quint32 nativeKey, quint32 nativeMods);
|
static bool registerShortcut(quint32 nativeKey, quint32 nativeMods);
|
||||||
static bool unregisterShortcut(quint32 nativeKey, quint32 nativeMods);
|
static bool unregisterShortcut(quint32 nativeKey, quint32 nativeMods);
|
||||||
|
|
||||||
static QHash<QPair<quint32, quint32>, QxtGlobalShortcut*> shortcuts;
|
static QHash<QPair<quint32, quint32>, QxtGlobalShortcut*> shortcuts;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QXTGLOBALSHORTCUT_P_H
|
#endif // QXTGLOBALSHORTCUT_P_H
|
||||||
|
|||||||
494
3rdparty/qxt/qxtglobalshortcut_win.cpp
vendored
494
3rdparty/qxt/qxtglobalshortcut_win.cpp
vendored
@@ -1,247 +1,247 @@
|
|||||||
#include "qxtglobalshortcut_p.h"
|
#include "qxtglobalshortcut_p.h"
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
** Copyright (c) 2006 - 2011, the LibQxt project.
|
** Copyright (c) 2006 - 2011, the LibQxt project.
|
||||||
** See the Qxt AUTHORS file for a list of authors and copyright holders.
|
** See the Qxt AUTHORS file for a list of authors and copyright holders.
|
||||||
** All rights reserved.
|
** All rights reserved.
|
||||||
**
|
**
|
||||||
** Redistribution and use in source and binary forms, with or without
|
** Redistribution and use in source and binary forms, with or without
|
||||||
** modification, are permitted provided that the following conditions are met:
|
** modification, are permitted provided that the following conditions are met:
|
||||||
** * Redistributions of source code must retain the above copyright
|
** * Redistributions of source code must retain the above copyright
|
||||||
** notice, this list of conditions and the following disclaimer.
|
** notice, this list of conditions and the following disclaimer.
|
||||||
** * Redistributions in binary form must reproduce the above copyright
|
** * Redistributions in binary form must reproduce the above copyright
|
||||||
** notice, this list of conditions and the following disclaimer in the
|
** notice, this list of conditions and the following disclaimer in the
|
||||||
** documentation and/or other materials provided with the distribution.
|
** documentation and/or other materials provided with the distribution.
|
||||||
** * Neither the name of the LibQxt project nor the
|
** * Neither the name of the LibQxt project nor the
|
||||||
** names of its contributors may be used to endorse or promote products
|
** names of its contributors may be used to endorse or promote products
|
||||||
** derived from this software without specific prior written permission.
|
** derived from this software without specific prior written permission.
|
||||||
**
|
**
|
||||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
** 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
|
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
** DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
** DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||||
** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
** 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
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
**
|
**
|
||||||
** <http://libqxt.org> <foundation@libqxt.org>
|
** <http://libqxt.org> <foundation@libqxt.org>
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
#include <qt_windows.h>
|
#include <qt_windows.h>
|
||||||
|
|
||||||
|
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
||||||
bool QxtGlobalShortcutPrivate::eventFilter(void* message)
|
bool QxtGlobalShortcutPrivate::eventFilter(void* message)
|
||||||
{
|
{
|
||||||
#else
|
#else
|
||||||
bool QxtGlobalShortcutPrivate::nativeEventFilter(const QByteArray & eventType,
|
bool QxtGlobalShortcutPrivate::nativeEventFilter(const QByteArray & eventType,
|
||||||
void * message, long * result)
|
void * message, long * result)
|
||||||
{
|
{
|
||||||
Q_UNUSED(eventType);
|
Q_UNUSED(eventType);
|
||||||
Q_UNUSED(result);
|
Q_UNUSED(result);
|
||||||
#endif
|
#endif
|
||||||
MSG* msg = static_cast<MSG*>(message);
|
MSG* msg = static_cast<MSG*>(message);
|
||||||
if (msg->message == WM_HOTKEY)
|
if (msg->message == WM_HOTKEY)
|
||||||
{
|
{
|
||||||
const quint32 keycode = HIWORD(msg->lParam);
|
const quint32 keycode = HIWORD(msg->lParam);
|
||||||
const quint32 modifiers = LOWORD(msg->lParam);
|
const quint32 modifiers = LOWORD(msg->lParam);
|
||||||
activateShortcut(keycode, modifiers);
|
activateShortcut(keycode, modifiers);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
quint32 QxtGlobalShortcutPrivate::nativeModifiers(Qt::KeyboardModifiers modifiers)
|
quint32 QxtGlobalShortcutPrivate::nativeModifiers(Qt::KeyboardModifiers modifiers)
|
||||||
{
|
{
|
||||||
// MOD_ALT, MOD_CONTROL, (MOD_KEYUP), MOD_SHIFT, MOD_WIN
|
// MOD_ALT, MOD_CONTROL, (MOD_KEYUP), MOD_SHIFT, MOD_WIN
|
||||||
quint32 native = 0;
|
quint32 native = 0;
|
||||||
if (modifiers & Qt::ShiftModifier)
|
if (modifiers & Qt::ShiftModifier)
|
||||||
native |= MOD_SHIFT;
|
native |= MOD_SHIFT;
|
||||||
if (modifiers & Qt::ControlModifier)
|
if (modifiers & Qt::ControlModifier)
|
||||||
native |= MOD_CONTROL;
|
native |= MOD_CONTROL;
|
||||||
if (modifiers & Qt::AltModifier)
|
if (modifiers & Qt::AltModifier)
|
||||||
native |= MOD_ALT;
|
native |= MOD_ALT;
|
||||||
if (modifiers & Qt::MetaModifier)
|
if (modifiers & Qt::MetaModifier)
|
||||||
native |= MOD_WIN;
|
native |= MOD_WIN;
|
||||||
// TODO: resolve these?
|
// TODO: resolve these?
|
||||||
//if (modifiers & Qt::KeypadModifier)
|
//if (modifiers & Qt::KeypadModifier)
|
||||||
//if (modifiers & Qt::GroupSwitchModifier)
|
//if (modifiers & Qt::GroupSwitchModifier)
|
||||||
return native;
|
return native;
|
||||||
}
|
}
|
||||||
|
|
||||||
quint32 QxtGlobalShortcutPrivate::nativeKeycode(Qt::Key key)
|
quint32 QxtGlobalShortcutPrivate::nativeKeycode(Qt::Key key)
|
||||||
{
|
{
|
||||||
switch (key)
|
switch (key)
|
||||||
{
|
{
|
||||||
case Qt::Key_Escape:
|
case Qt::Key_Escape:
|
||||||
return VK_ESCAPE;
|
return VK_ESCAPE;
|
||||||
case Qt::Key_Tab:
|
case Qt::Key_Tab:
|
||||||
case Qt::Key_Backtab:
|
case Qt::Key_Backtab:
|
||||||
return VK_TAB;
|
return VK_TAB;
|
||||||
case Qt::Key_Backspace:
|
case Qt::Key_Backspace:
|
||||||
return VK_BACK;
|
return VK_BACK;
|
||||||
case Qt::Key_Return:
|
case Qt::Key_Return:
|
||||||
case Qt::Key_Enter:
|
case Qt::Key_Enter:
|
||||||
return VK_RETURN;
|
return VK_RETURN;
|
||||||
case Qt::Key_Insert:
|
case Qt::Key_Insert:
|
||||||
return VK_INSERT;
|
return VK_INSERT;
|
||||||
case Qt::Key_Delete:
|
case Qt::Key_Delete:
|
||||||
return VK_DELETE;
|
return VK_DELETE;
|
||||||
case Qt::Key_Pause:
|
case Qt::Key_Pause:
|
||||||
return VK_PAUSE;
|
return VK_PAUSE;
|
||||||
case Qt::Key_Print:
|
case Qt::Key_Print:
|
||||||
return VK_PRINT;
|
return VK_PRINT;
|
||||||
case Qt::Key_Clear:
|
case Qt::Key_Clear:
|
||||||
return VK_CLEAR;
|
return VK_CLEAR;
|
||||||
case Qt::Key_Home:
|
case Qt::Key_Home:
|
||||||
return VK_HOME;
|
return VK_HOME;
|
||||||
case Qt::Key_End:
|
case Qt::Key_End:
|
||||||
return VK_END;
|
return VK_END;
|
||||||
case Qt::Key_Left:
|
case Qt::Key_Left:
|
||||||
return VK_LEFT;
|
return VK_LEFT;
|
||||||
case Qt::Key_Up:
|
case Qt::Key_Up:
|
||||||
return VK_UP;
|
return VK_UP;
|
||||||
case Qt::Key_Right:
|
case Qt::Key_Right:
|
||||||
return VK_RIGHT;
|
return VK_RIGHT;
|
||||||
case Qt::Key_Down:
|
case Qt::Key_Down:
|
||||||
return VK_DOWN;
|
return VK_DOWN;
|
||||||
case Qt::Key_PageUp:
|
case Qt::Key_PageUp:
|
||||||
return VK_PRIOR;
|
return VK_PRIOR;
|
||||||
case Qt::Key_PageDown:
|
case Qt::Key_PageDown:
|
||||||
return VK_NEXT;
|
return VK_NEXT;
|
||||||
case Qt::Key_F1:
|
case Qt::Key_F1:
|
||||||
return VK_F1;
|
return VK_F1;
|
||||||
case Qt::Key_F2:
|
case Qt::Key_F2:
|
||||||
return VK_F2;
|
return VK_F2;
|
||||||
case Qt::Key_F3:
|
case Qt::Key_F3:
|
||||||
return VK_F3;
|
return VK_F3;
|
||||||
case Qt::Key_F4:
|
case Qt::Key_F4:
|
||||||
return VK_F4;
|
return VK_F4;
|
||||||
case Qt::Key_F5:
|
case Qt::Key_F5:
|
||||||
return VK_F5;
|
return VK_F5;
|
||||||
case Qt::Key_F6:
|
case Qt::Key_F6:
|
||||||
return VK_F6;
|
return VK_F6;
|
||||||
case Qt::Key_F7:
|
case Qt::Key_F7:
|
||||||
return VK_F7;
|
return VK_F7;
|
||||||
case Qt::Key_F8:
|
case Qt::Key_F8:
|
||||||
return VK_F8;
|
return VK_F8;
|
||||||
case Qt::Key_F9:
|
case Qt::Key_F9:
|
||||||
return VK_F9;
|
return VK_F9;
|
||||||
case Qt::Key_F10:
|
case Qt::Key_F10:
|
||||||
return VK_F10;
|
return VK_F10;
|
||||||
case Qt::Key_F11:
|
case Qt::Key_F11:
|
||||||
return VK_F11;
|
return VK_F11;
|
||||||
case Qt::Key_F12:
|
case Qt::Key_F12:
|
||||||
return VK_F12;
|
return VK_F12;
|
||||||
case Qt::Key_F13:
|
case Qt::Key_F13:
|
||||||
return VK_F13;
|
return VK_F13;
|
||||||
case Qt::Key_F14:
|
case Qt::Key_F14:
|
||||||
return VK_F14;
|
return VK_F14;
|
||||||
case Qt::Key_F15:
|
case Qt::Key_F15:
|
||||||
return VK_F15;
|
return VK_F15;
|
||||||
case Qt::Key_F16:
|
case Qt::Key_F16:
|
||||||
return VK_F16;
|
return VK_F16;
|
||||||
case Qt::Key_F17:
|
case Qt::Key_F17:
|
||||||
return VK_F17;
|
return VK_F17;
|
||||||
case Qt::Key_F18:
|
case Qt::Key_F18:
|
||||||
return VK_F18;
|
return VK_F18;
|
||||||
case Qt::Key_F19:
|
case Qt::Key_F19:
|
||||||
return VK_F19;
|
return VK_F19;
|
||||||
case Qt::Key_F20:
|
case Qt::Key_F20:
|
||||||
return VK_F20;
|
return VK_F20;
|
||||||
case Qt::Key_F21:
|
case Qt::Key_F21:
|
||||||
return VK_F21;
|
return VK_F21;
|
||||||
case Qt::Key_F22:
|
case Qt::Key_F22:
|
||||||
return VK_F22;
|
return VK_F22;
|
||||||
case Qt::Key_F23:
|
case Qt::Key_F23:
|
||||||
return VK_F23;
|
return VK_F23;
|
||||||
case Qt::Key_F24:
|
case Qt::Key_F24:
|
||||||
return VK_F24;
|
return VK_F24;
|
||||||
case Qt::Key_Space:
|
case Qt::Key_Space:
|
||||||
return VK_SPACE;
|
return VK_SPACE;
|
||||||
case Qt::Key_Asterisk:
|
case Qt::Key_Asterisk:
|
||||||
return VK_MULTIPLY;
|
return VK_MULTIPLY;
|
||||||
case Qt::Key_Plus:
|
case Qt::Key_Plus:
|
||||||
return VK_ADD;
|
return VK_ADD;
|
||||||
case Qt::Key_Comma:
|
case Qt::Key_Comma:
|
||||||
return VK_SEPARATOR;
|
return VK_SEPARATOR;
|
||||||
case Qt::Key_Minus:
|
case Qt::Key_Minus:
|
||||||
return VK_SUBTRACT;
|
return VK_SUBTRACT;
|
||||||
case Qt::Key_Slash:
|
case Qt::Key_Slash:
|
||||||
return VK_DIVIDE;
|
return VK_DIVIDE;
|
||||||
case Qt::Key_MediaNext:
|
case Qt::Key_MediaNext:
|
||||||
return VK_MEDIA_NEXT_TRACK;
|
return VK_MEDIA_NEXT_TRACK;
|
||||||
case Qt::Key_MediaPrevious:
|
case Qt::Key_MediaPrevious:
|
||||||
return VK_MEDIA_PREV_TRACK;
|
return VK_MEDIA_PREV_TRACK;
|
||||||
case Qt::Key_MediaPlay:
|
case Qt::Key_MediaPlay:
|
||||||
return VK_MEDIA_PLAY_PAUSE;
|
return VK_MEDIA_PLAY_PAUSE;
|
||||||
case Qt::Key_MediaStop:
|
case Qt::Key_MediaStop:
|
||||||
return VK_MEDIA_STOP;
|
return VK_MEDIA_STOP;
|
||||||
// couldn't find those in VK_*
|
// couldn't find those in VK_*
|
||||||
//case Qt::Key_MediaLast:
|
//case Qt::Key_MediaLast:
|
||||||
//case Qt::Key_MediaRecord:
|
//case Qt::Key_MediaRecord:
|
||||||
case Qt::Key_VolumeDown:
|
case Qt::Key_VolumeDown:
|
||||||
return VK_VOLUME_DOWN;
|
return VK_VOLUME_DOWN;
|
||||||
case Qt::Key_VolumeUp:
|
case Qt::Key_VolumeUp:
|
||||||
return VK_VOLUME_UP;
|
return VK_VOLUME_UP;
|
||||||
case Qt::Key_VolumeMute:
|
case Qt::Key_VolumeMute:
|
||||||
return VK_VOLUME_MUTE;
|
return VK_VOLUME_MUTE;
|
||||||
|
|
||||||
// numbers
|
// numbers
|
||||||
case Qt::Key_0:
|
case Qt::Key_0:
|
||||||
case Qt::Key_1:
|
case Qt::Key_1:
|
||||||
case Qt::Key_2:
|
case Qt::Key_2:
|
||||||
case Qt::Key_3:
|
case Qt::Key_3:
|
||||||
case Qt::Key_4:
|
case Qt::Key_4:
|
||||||
case Qt::Key_5:
|
case Qt::Key_5:
|
||||||
case Qt::Key_6:
|
case Qt::Key_6:
|
||||||
case Qt::Key_7:
|
case Qt::Key_7:
|
||||||
case Qt::Key_8:
|
case Qt::Key_8:
|
||||||
case Qt::Key_9:
|
case Qt::Key_9:
|
||||||
return key;
|
return key;
|
||||||
|
|
||||||
// letters
|
// letters
|
||||||
case Qt::Key_A:
|
case Qt::Key_A:
|
||||||
case Qt::Key_B:
|
case Qt::Key_B:
|
||||||
case Qt::Key_C:
|
case Qt::Key_C:
|
||||||
case Qt::Key_D:
|
case Qt::Key_D:
|
||||||
case Qt::Key_E:
|
case Qt::Key_E:
|
||||||
case Qt::Key_F:
|
case Qt::Key_F:
|
||||||
case Qt::Key_G:
|
case Qt::Key_G:
|
||||||
case Qt::Key_H:
|
case Qt::Key_H:
|
||||||
case Qt::Key_I:
|
case Qt::Key_I:
|
||||||
case Qt::Key_J:
|
case Qt::Key_J:
|
||||||
case Qt::Key_K:
|
case Qt::Key_K:
|
||||||
case Qt::Key_L:
|
case Qt::Key_L:
|
||||||
case Qt::Key_M:
|
case Qt::Key_M:
|
||||||
case Qt::Key_N:
|
case Qt::Key_N:
|
||||||
case Qt::Key_O:
|
case Qt::Key_O:
|
||||||
case Qt::Key_P:
|
case Qt::Key_P:
|
||||||
case Qt::Key_Q:
|
case Qt::Key_Q:
|
||||||
case Qt::Key_R:
|
case Qt::Key_R:
|
||||||
case Qt::Key_S:
|
case Qt::Key_S:
|
||||||
case Qt::Key_T:
|
case Qt::Key_T:
|
||||||
case Qt::Key_U:
|
case Qt::Key_U:
|
||||||
case Qt::Key_V:
|
case Qt::Key_V:
|
||||||
case Qt::Key_W:
|
case Qt::Key_W:
|
||||||
case Qt::Key_X:
|
case Qt::Key_X:
|
||||||
case Qt::Key_Y:
|
case Qt::Key_Y:
|
||||||
case Qt::Key_Z:
|
case Qt::Key_Z:
|
||||||
return key;
|
return key;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QxtGlobalShortcutPrivate::registerShortcut(quint32 nativeKey, quint32 nativeMods)
|
bool QxtGlobalShortcutPrivate::registerShortcut(quint32 nativeKey, quint32 nativeMods)
|
||||||
{
|
{
|
||||||
return RegisterHotKey(0, nativeMods ^ nativeKey, nativeMods, nativeKey);
|
return RegisterHotKey(0, nativeMods ^ nativeKey, nativeMods, nativeKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QxtGlobalShortcutPrivate::unregisterShortcut(quint32 nativeKey, quint32 nativeMods)
|
bool QxtGlobalShortcutPrivate::unregisterShortcut(quint32 nativeKey, quint32 nativeMods)
|
||||||
{
|
{
|
||||||
return UnregisterHotKey(0, nativeMods ^ nativeKey);
|
return UnregisterHotKey(0, nativeMods ^ nativeKey);
|
||||||
}
|
}
|
||||||
|
|||||||
526
3rdparty/qxt/qxtglobalshortcut_x11.cpp
vendored
526
3rdparty/qxt/qxtglobalshortcut_x11.cpp
vendored
@@ -1,263 +1,263 @@
|
|||||||
#include "qxtglobalshortcut_p.h"
|
#include "qxtglobalshortcut_p.h"
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
** Copyright (c) 2006 - 2011, the LibQxt project.
|
** Copyright (c) 2006 - 2011, the LibQxt project.
|
||||||
** See the Qxt AUTHORS file for a list of authors and copyright holders.
|
** See the Qxt AUTHORS file for a list of authors and copyright holders.
|
||||||
** All rights reserved.
|
** All rights reserved.
|
||||||
**
|
**
|
||||||
** Redistribution and use in source and binary forms, with or without
|
** Redistribution and use in source and binary forms, with or without
|
||||||
** modification, are permitted provided that the following conditions are met:
|
** modification, are permitted provided that the following conditions are met:
|
||||||
** * Redistributions of source code must retain the above copyright
|
** * Redistributions of source code must retain the above copyright
|
||||||
** notice, this list of conditions and the following disclaimer.
|
** notice, this list of conditions and the following disclaimer.
|
||||||
** * Redistributions in binary form must reproduce the above copyright
|
** * Redistributions in binary form must reproduce the above copyright
|
||||||
** notice, this list of conditions and the following disclaimer in the
|
** notice, this list of conditions and the following disclaimer in the
|
||||||
** documentation and/or other materials provided with the distribution.
|
** documentation and/or other materials provided with the distribution.
|
||||||
** * Neither the name of the LibQxt project nor the
|
** * Neither the name of the LibQxt project nor the
|
||||||
** names of its contributors may be used to endorse or promote products
|
** names of its contributors may be used to endorse or promote products
|
||||||
** derived from this software without specific prior written permission.
|
** derived from this software without specific prior written permission.
|
||||||
**
|
**
|
||||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
** 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
|
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
** DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
** DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||||
** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
** 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
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
**
|
**
|
||||||
** <http://libqxt.org> <foundation@libqxt.org>
|
** <http://libqxt.org> <foundation@libqxt.org>
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
||||||
# include <QX11Info>
|
# include <QX11Info>
|
||||||
#else
|
#else
|
||||||
# include <qpa/qplatformnativeinterface.h>
|
# include <qpa/qplatformnativeinterface.h>
|
||||||
# include <xcb/xcb.h>
|
# include <xcb/xcb.h>
|
||||||
# include <QApplication>
|
# include <QApplication>
|
||||||
#endif
|
#endif
|
||||||
#include <X11/X.h>
|
#include <X11/X.h>
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <xcb/xproto.h>
|
#include <xcb/xproto.h>
|
||||||
|
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <QKeySequence>
|
#include <QKeySequence>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
#include "keymapper_x11.h"
|
#include "keymapper_x11.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
const QVector<quint32> maskModifiers = QVector<quint32>()
|
const QVector<quint32> maskModifiers = QVector<quint32>()
|
||||||
<< 0 << Mod2Mask << LockMask << (Mod2Mask | LockMask);
|
<< 0 << Mod2Mask << LockMask << (Mod2Mask | LockMask);
|
||||||
|
|
||||||
typedef int (*X11ErrorHandler)(Display *display, XErrorEvent *event);
|
typedef int (*X11ErrorHandler)(Display *display, XErrorEvent *event);
|
||||||
|
|
||||||
class QxtX11ErrorHandler {
|
class QxtX11ErrorHandler {
|
||||||
public:
|
public:
|
||||||
static bool error;
|
static bool error;
|
||||||
|
|
||||||
static int qxtX11ErrorHandler(Display *display, XErrorEvent *event)
|
static int qxtX11ErrorHandler(Display *display, XErrorEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(display);
|
Q_UNUSED(display);
|
||||||
switch (event->error_code)
|
switch (event->error_code)
|
||||||
{
|
{
|
||||||
case BadAccess:
|
case BadAccess:
|
||||||
case BadValue:
|
case BadValue:
|
||||||
case BadWindow:
|
case BadWindow:
|
||||||
if (event->request_code == 33 /* X_GrabKey */ ||
|
if (event->request_code == 33 /* X_GrabKey */ ||
|
||||||
event->request_code == 34 /* X_UngrabKey */)
|
event->request_code == 34 /* X_UngrabKey */)
|
||||||
{
|
{
|
||||||
error = true;
|
error = true;
|
||||||
//TODO:
|
//TODO:
|
||||||
//char errstr[256];
|
//char errstr[256];
|
||||||
//XGetErrorText(dpy, err->error_code, errstr, 256);
|
//XGetErrorText(dpy, err->error_code, errstr, 256);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QxtX11ErrorHandler()
|
QxtX11ErrorHandler()
|
||||||
{
|
{
|
||||||
error = false;
|
error = false;
|
||||||
m_previousErrorHandler = XSetErrorHandler(qxtX11ErrorHandler);
|
m_previousErrorHandler = XSetErrorHandler(qxtX11ErrorHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
~QxtX11ErrorHandler()
|
~QxtX11ErrorHandler()
|
||||||
{
|
{
|
||||||
XSetErrorHandler(m_previousErrorHandler);
|
XSetErrorHandler(m_previousErrorHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
X11ErrorHandler m_previousErrorHandler;
|
X11ErrorHandler m_previousErrorHandler;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool QxtX11ErrorHandler::error = false;
|
bool QxtX11ErrorHandler::error = false;
|
||||||
|
|
||||||
class QxtX11Data {
|
class QxtX11Data {
|
||||||
public:
|
public:
|
||||||
QxtX11Data()
|
QxtX11Data()
|
||||||
{
|
{
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
||||||
m_display = QX11Info::display();
|
m_display = QX11Info::display();
|
||||||
#else
|
#else
|
||||||
QPlatformNativeInterface *native = qApp->platformNativeInterface();
|
QPlatformNativeInterface *native = qApp->platformNativeInterface();
|
||||||
void *display = native->nativeResourceForScreen(QByteArray("display"),
|
void *display = native->nativeResourceForScreen(QByteArray("display"),
|
||||||
QGuiApplication::primaryScreen());
|
QGuiApplication::primaryScreen());
|
||||||
m_display = reinterpret_cast<Display *>(display);
|
m_display = reinterpret_cast<Display *>(display);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isValid()
|
bool isValid()
|
||||||
{
|
{
|
||||||
return m_display != 0;
|
return m_display != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Display *display()
|
Display *display()
|
||||||
{
|
{
|
||||||
Q_ASSERT(isValid());
|
Q_ASSERT(isValid());
|
||||||
return m_display;
|
return m_display;
|
||||||
}
|
}
|
||||||
|
|
||||||
Window rootWindow()
|
Window rootWindow()
|
||||||
{
|
{
|
||||||
return DefaultRootWindow(display());
|
return DefaultRootWindow(display());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool grabKey(quint32 keycode, quint32 modifiers, Window window)
|
bool grabKey(quint32 keycode, quint32 modifiers, Window window)
|
||||||
{
|
{
|
||||||
QxtX11ErrorHandler errorHandler;
|
QxtX11ErrorHandler errorHandler;
|
||||||
|
|
||||||
for (int i = 0; !errorHandler.error && i < maskModifiers.size(); ++i) {
|
for (int i = 0; !errorHandler.error && i < maskModifiers.size(); ++i) {
|
||||||
XGrabKey(display(), keycode, modifiers | maskModifiers[i], window, True,
|
XGrabKey(display(), keycode, modifiers | maskModifiers[i], window, True,
|
||||||
GrabModeAsync, GrabModeAsync);
|
GrabModeAsync, GrabModeAsync);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errorHandler.error) {
|
if (errorHandler.error) {
|
||||||
ungrabKey(keycode, modifiers, window);
|
ungrabKey(keycode, modifiers, window);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ungrabKey(quint32 keycode, quint32 modifiers, Window window)
|
bool ungrabKey(quint32 keycode, quint32 modifiers, Window window)
|
||||||
{
|
{
|
||||||
QxtX11ErrorHandler errorHandler;
|
QxtX11ErrorHandler errorHandler;
|
||||||
|
|
||||||
foreach (quint32 maskMods, maskModifiers) {
|
foreach (quint32 maskMods, maskModifiers) {
|
||||||
XUngrabKey(display(), keycode, modifiers | maskMods, window);
|
XUngrabKey(display(), keycode, modifiers | maskMods, window);
|
||||||
}
|
}
|
||||||
|
|
||||||
return !errorHandler.error;
|
return !errorHandler.error;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Display *m_display;
|
Display *m_display;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
||||||
bool QxtGlobalShortcutPrivate::eventFilter(void *message)
|
bool QxtGlobalShortcutPrivate::eventFilter(void *message)
|
||||||
{
|
{
|
||||||
XEvent *event = static_cast<XEvent *>(message);
|
XEvent *event = static_cast<XEvent *>(message);
|
||||||
if (event->type == KeyPress)
|
if (event->type == KeyPress)
|
||||||
{
|
{
|
||||||
XKeyEvent *key = reinterpret_cast<XKeyEvent *>(event);
|
XKeyEvent *key = reinterpret_cast<XKeyEvent *>(event);
|
||||||
unsigned int keycode = key->keycode;
|
unsigned int keycode = key->keycode;
|
||||||
unsigned int keystate = key->state;
|
unsigned int keystate = key->state;
|
||||||
#else
|
#else
|
||||||
bool QxtGlobalShortcutPrivate::nativeEventFilter(const QByteArray & eventType,
|
bool QxtGlobalShortcutPrivate::nativeEventFilter(const QByteArray & eventType,
|
||||||
void *message, long *result)
|
void *message, long *result)
|
||||||
{
|
{
|
||||||
Q_UNUSED(result);
|
Q_UNUSED(result);
|
||||||
|
|
||||||
xcb_key_press_event_t *kev = 0;
|
xcb_key_press_event_t *kev = nullptr;
|
||||||
if (eventType == "xcb_generic_event_t") {
|
if (eventType == "xcb_generic_event_t") {
|
||||||
xcb_generic_event_t *ev = static_cast<xcb_generic_event_t *>(message);
|
xcb_generic_event_t *ev = static_cast<xcb_generic_event_t *>(message);
|
||||||
if ((ev->response_type & 127) == XCB_KEY_PRESS)
|
if ((ev->response_type & 127) == XCB_KEY_PRESS)
|
||||||
kev = static_cast<xcb_key_press_event_t *>(message);
|
kev = static_cast<xcb_key_press_event_t *>(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kev != 0) {
|
if (kev != nullptr) {
|
||||||
unsigned int keycode = kev->detail;
|
unsigned int keycode = kev->detail;
|
||||||
unsigned int keystate = 0;
|
unsigned int keystate = 0;
|
||||||
if(kev->state & XCB_MOD_MASK_1)
|
if(kev->state & XCB_MOD_MASK_1)
|
||||||
keystate |= Mod1Mask;
|
keystate |= Mod1Mask;
|
||||||
if(kev->state & XCB_MOD_MASK_CONTROL)
|
if(kev->state & XCB_MOD_MASK_CONTROL)
|
||||||
keystate |= ControlMask;
|
keystate |= ControlMask;
|
||||||
if(kev->state & XCB_MOD_MASK_4)
|
if(kev->state & XCB_MOD_MASK_4)
|
||||||
keystate |= Mod4Mask;
|
keystate |= Mod4Mask;
|
||||||
if(kev->state & XCB_MOD_MASK_SHIFT)
|
if(kev->state & XCB_MOD_MASK_SHIFT)
|
||||||
keystate |= ShiftMask;
|
keystate |= ShiftMask;
|
||||||
#endif
|
#endif
|
||||||
activateShortcut(keycode,
|
activateShortcut(keycode,
|
||||||
// Mod1Mask == Alt, Mod4Mask == Meta
|
// Mod1Mask == Alt, Mod4Mask == Meta
|
||||||
keystate & (ShiftMask | ControlMask | Mod1Mask | Mod4Mask));
|
keystate & (ShiftMask | ControlMask | Mod1Mask | Mod4Mask));
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
quint32 QxtGlobalShortcutPrivate::nativeModifiers(Qt::KeyboardModifiers modifiers)
|
quint32 QxtGlobalShortcutPrivate::nativeModifiers(Qt::KeyboardModifiers modifiers)
|
||||||
{
|
{
|
||||||
// ShiftMask, LockMask, ControlMask, Mod1Mask, Mod2Mask, Mod3Mask, Mod4Mask, and Mod5Mask
|
// ShiftMask, LockMask, ControlMask, Mod1Mask, Mod2Mask, Mod3Mask, Mod4Mask, and Mod5Mask
|
||||||
quint32 native = 0;
|
quint32 native = 0;
|
||||||
if (modifiers & Qt::ShiftModifier)
|
if (modifiers & Qt::ShiftModifier)
|
||||||
native |= ShiftMask;
|
native |= ShiftMask;
|
||||||
if (modifiers & Qt::ControlModifier)
|
if (modifiers & Qt::ControlModifier)
|
||||||
native |= ControlMask;
|
native |= ControlMask;
|
||||||
if (modifiers & Qt::AltModifier)
|
if (modifiers & Qt::AltModifier)
|
||||||
native |= Mod1Mask;
|
native |= Mod1Mask;
|
||||||
if (modifiers & Qt::MetaModifier)
|
if (modifiers & Qt::MetaModifier)
|
||||||
native |= Mod4Mask;
|
native |= Mod4Mask;
|
||||||
|
|
||||||
// TODO: resolve these?
|
// TODO: resolve these?
|
||||||
//if (modifiers & Qt::MetaModifier)
|
//if (modifiers & Qt::MetaModifier)
|
||||||
//if (modifiers & Qt::KeypadModifier)
|
//if (modifiers & Qt::KeypadModifier)
|
||||||
//if (modifiers & Qt::GroupSwitchModifier)
|
//if (modifiers & Qt::GroupSwitchModifier)
|
||||||
return native;
|
return native;
|
||||||
}
|
}
|
||||||
|
|
||||||
quint32 QxtGlobalShortcutPrivate::nativeKeycode(Qt::Key key)
|
quint32 QxtGlobalShortcutPrivate::nativeKeycode(Qt::Key key)
|
||||||
{
|
{
|
||||||
// (davidsansome) Try the table from QKeyMapper first - this seems to be
|
// (davidsansome) Try the table from QKeyMapper first - this seems to be
|
||||||
// the only way to get Keysyms for the media keys.
|
// the only way to get Keysyms for the media keys.
|
||||||
unsigned int keysym = 0;
|
unsigned int keysym = 0;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (KeyTbl[i]) {
|
while (KeyTbl[i]) {
|
||||||
if (KeyTbl[i+1] == static_cast<uint>(key)) {
|
if (KeyTbl[i+1] == static_cast<uint>(key)) {
|
||||||
keysym = KeyTbl[i];
|
keysym = KeyTbl[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
i += 2;
|
i += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If that didn't work then fall back on XStringToKeysym
|
// If that didn't work then fall back on XStringToKeysym
|
||||||
if (!keysym) {
|
if (!keysym) {
|
||||||
keysym = XStringToKeysym(QKeySequence(key).toString().toLatin1().data());
|
keysym = XStringToKeysym(QKeySequence(key).toString().toLatin1().data());
|
||||||
if (keysym == NoSymbol)
|
if (keysym == NoSymbol)
|
||||||
keysym = static_cast<ushort>(key);
|
keysym = static_cast<ushort>(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
QxtX11Data x11;
|
QxtX11Data x11;
|
||||||
if (!x11.isValid())
|
if (!x11.isValid())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return XKeysymToKeycode(x11.display(), keysym);
|
return XKeysymToKeycode(x11.display(), keysym);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QxtGlobalShortcutPrivate::registerShortcut(quint32 nativeKey, quint32 nativeMods)
|
bool QxtGlobalShortcutPrivate::registerShortcut(quint32 nativeKey, quint32 nativeMods)
|
||||||
{
|
{
|
||||||
QxtX11Data x11;
|
QxtX11Data x11;
|
||||||
return x11.isValid() && x11.grabKey(nativeKey, nativeMods, x11.rootWindow());
|
return x11.isValid() && x11.grabKey(nativeKey, nativeMods, x11.rootWindow());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QxtGlobalShortcutPrivate::unregisterShortcut(quint32 nativeKey, quint32 nativeMods)
|
bool QxtGlobalShortcutPrivate::unregisterShortcut(quint32 nativeKey, quint32 nativeMods)
|
||||||
{
|
{
|
||||||
QxtX11Data x11;
|
QxtX11Data x11;
|
||||||
return x11.isValid() && x11.ungrabKey(nativeKey, nativeMods, x11.rootWindow());
|
return x11.isValid() && x11.ungrabKey(nativeKey, nativeMods, x11.rootWindow());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user