add numpad support for x11
This commit is contained in:
parent
861322355e
commit
cf34488842
|
@ -74,10 +74,10 @@ QxtGlobalShortcutPrivate::~QxtGlobalShortcutPrivate()
|
|||
|
||||
bool QxtGlobalShortcutPrivate::setShortcut(const QKeySequence& shortcut)
|
||||
{
|
||||
Qt::KeyboardModifiers allMods = Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier;
|
||||
Qt::KeyboardModifiers allMods = Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier | Qt::KeypadModifier;
|
||||
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 nativeKey = nativeKeycode(key, mods);
|
||||
const quint32 nativeMods = nativeModifiers(mods);
|
||||
const bool res = registerShortcut(nativeKey, nativeMods);
|
||||
if (res)
|
||||
|
@ -90,7 +90,7 @@ bool QxtGlobalShortcutPrivate::setShortcut(const QKeySequence& shortcut)
|
|||
bool QxtGlobalShortcutPrivate::unsetShortcut()
|
||||
{
|
||||
bool res = false;
|
||||
const quint32 nativeKey = nativeKeycode(key);
|
||||
const quint32 nativeKey = nativeKeycode(key, mods);
|
||||
const quint32 nativeMods = nativeModifiers(mods);
|
||||
if (shortcuts.value(qMakePair(nativeKey, nativeMods)) == &qxt_p())
|
||||
res = unregisterShortcut(nativeKey, nativeMods);
|
||||
|
|
|
@ -72,7 +72,7 @@ public:
|
|||
static void activateShortcut(quint32 nativeKey, quint32 nativeMods);
|
||||
|
||||
private:
|
||||
static quint32 nativeKeycode(Qt::Key keycode);
|
||||
static quint32 nativeKeycode(Qt::Key keycode, Qt::KeyboardModifiers modifiers);
|
||||
static quint32 nativeModifiers(Qt::KeyboardModifiers modifiers);
|
||||
|
||||
static bool registerShortcut(quint32 nativeKey, quint32 nativeMods);
|
||||
|
|
|
@ -34,6 +34,9 @@
|
|||
#include <X11/Xlib.h>
|
||||
#include <QX11Info>
|
||||
#include <xcb/xcb.h>
|
||||
#include <X11/Xutil.h>
|
||||
|
||||
#include <Log.h>
|
||||
|
||||
namespace {
|
||||
|
||||
|
@ -205,12 +208,55 @@ quint32 QxtGlobalShortcutPrivate::nativeModifiers(Qt::KeyboardModifiers modifier
|
|||
return native;
|
||||
}
|
||||
|
||||
quint32 QxtGlobalShortcutPrivate::nativeKeycode(Qt::Key key)
|
||||
|
||||
static quint32 getNumpadKeyCode(Display* d, Qt::Key key) {
|
||||
quint32 keysm = XK_VoidSymbol;
|
||||
|
||||
if(key >= Qt::Key_0 && key <= Qt::Key_9) {
|
||||
keysm = XK_KP_0 + (key - Qt::Key_0);
|
||||
} else {
|
||||
switch(key) {
|
||||
case Qt::Key_Comma:
|
||||
keysm = XK_KP_Separator;
|
||||
break;
|
||||
case Qt::Key_Minus:
|
||||
keysm = XK_KP_Subtract;
|
||||
break;
|
||||
case Qt::Key_Plus:
|
||||
keysm = XK_KP_Add;
|
||||
break;
|
||||
case Qt::Key_Enter:
|
||||
keysm = XK_KP_Enter;
|
||||
break;
|
||||
case Qt::Key_multiply:
|
||||
keysm = XK_KP_Multiply;
|
||||
break;
|
||||
case Qt::Key_division:
|
||||
keysm = XK_KP_Divide;
|
||||
break;
|
||||
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return (keysm != XK_VoidSymbol) ? XKeysymToKeycode(d, keysm) : 0;
|
||||
}
|
||||
|
||||
quint32 QxtGlobalShortcutPrivate::nativeKeycode(Qt::Key key, Qt::KeyboardModifiers modifiers)
|
||||
{
|
||||
QxtX11Data x11;
|
||||
if (!x11.isValid())
|
||||
return 0;
|
||||
|
||||
if(modifiers & Qt::KeypadModifier) {
|
||||
Log::info << "resolveing keypad code: " << QKeySequence(key).toString().toStdString();
|
||||
quint32 code = getNumpadKeyCode(x11.display(), key);
|
||||
if(code != 0) {
|
||||
Log::info << "resolved keypad code: " << code;
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
KeySym keysym = XStringToKeysym(QKeySequence(key).toString().toLatin1().data());
|
||||
if (keysym == NoSymbol)
|
||||
keysym = static_cast<ushort>(key);
|
||||
|
|
Loading…
Reference in New Issue