Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F133263
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
7 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/hotkeymap.h b/hotkeymap.h
index 2993efe..868c7b7 100644
--- a/hotkeymap.h
+++ b/hotkeymap.h
@@ -1,148 +1,149 @@
#include <QtCore>
#if defined(Q_OS_WIN)
inline size_t QtKeyToWin(size_t key) {
// TODO: other maping or full keys list
if (key >= 0x01000030 && key <= 0x01000047) {
return VK_F1 + (key - Qt::Key_F1);
}
return key;
}
#elif defined(Q_OS_LINUX)
#include "ukeysequence.h"
#include "xcb/xcb.h"
#include "xcb/xcb_keysyms.h"
#include "X11/keysym.h"
struct UKeyData {
int key;
int mods;
};
inline UKeyData QtKeyToLinux(const UKeySequence &keySeq)
{
UKeyData data = {0, 0};
auto key = keySeq.GetSimpleKeys();
if (key.size() > 0)
data.key = key[0];
else
throw UException("Invalid hotkey");
// Key conversion
// Qt's F keys need conversion
if (data.key >= Qt::Key_F1 && data.key <= Qt::Key_F35) {
const size_t DIFF = Qt::Key_F1 - XK_F1;
data.key -= DIFF;
} else if (data.key >= Qt::Key_Space && data.key <= Qt::Key_QuoteLeft) {
// conversion is not necessary, if the value in the range Qt::Key_Space - Qt::Key_QuoteLeft
} else {
throw UException("Invalid hotkey: key conversion is not defined");
}
// Modifiers conversion
auto mods = keySeq.GetModifiers();
for (auto i : mods) {
if (i == Qt::Key_Shift)
data.mods |= XCB_MOD_MASK_SHIFT;
else if (i == Qt::Key_Control)
data.mods |= XCB_MOD_MASK_CONTROL;
else if (i == Qt::Key_Alt)
data.mods |= XCB_MOD_MASK_1;
else if (i == Qt::Key_Meta)
data.mods |= XCB_MOD_MASK_4; // !
}
return data;
}
#elif defined(Q_OS_MAC)
#include "ukeysequence.h"
#include <Carbon/Carbon.h>
#include <unordered_map>
struct UKeyData {
uint32_t key;
uint32_t mods;
};
static std::unordered_map<uint32_t, uint32_t> KEY_MAP = {
{Qt::Key_A, kVK_ANSI_A},
{Qt::Key_B, kVK_ANSI_B},
{Qt::Key_C, kVK_ANSI_C},
{Qt::Key_D, kVK_ANSI_D},
{Qt::Key_E, kVK_ANSI_E},
{Qt::Key_F, kVK_ANSI_F},
{Qt::Key_G, kVK_ANSI_G},
{Qt::Key_H, kVK_ANSI_H},
{Qt::Key_I, kVK_ANSI_I},
{Qt::Key_J, kVK_ANSI_J},
{Qt::Key_K, kVK_ANSI_K},
{Qt::Key_L, kVK_ANSI_L},
{Qt::Key_M, kVK_ANSI_M},
{Qt::Key_N, kVK_ANSI_N},
{Qt::Key_O, kVK_ANSI_O},
{Qt::Key_P, kVK_ANSI_P},
{Qt::Key_Q, kVK_ANSI_Q},
{Qt::Key_R, kVK_ANSI_R},
{Qt::Key_S, kVK_ANSI_S},
{Qt::Key_T, kVK_ANSI_T},
{Qt::Key_U, kVK_ANSI_U},
{Qt::Key_V, kVK_ANSI_V},
{Qt::Key_W, kVK_ANSI_W},
{Qt::Key_X, kVK_ANSI_X},
{Qt::Key_Y, kVK_ANSI_Y},
{Qt::Key_Z, kVK_ANSI_Z},
{Qt::Key_0, kVK_ANSI_0},
{Qt::Key_1, kVK_ANSI_1},
{Qt::Key_2, kVK_ANSI_2},
{Qt::Key_3, kVK_ANSI_3},
{Qt::Key_4, kVK_ANSI_4},
{Qt::Key_5, kVK_ANSI_5},
{Qt::Key_6, kVK_ANSI_6},
{Qt::Key_7, kVK_ANSI_7},
{Qt::Key_8, kVK_ANSI_8},
{Qt::Key_9, kVK_ANSI_9},
{Qt::Key_F1, kVK_F1},
{Qt::Key_F2, kVK_F2},
{Qt::Key_F3, kVK_F3},
{Qt::Key_F4, kVK_F4},
{Qt::Key_F5, kVK_F5},
{Qt::Key_F6, kVK_F6},
{Qt::Key_F7, kVK_F7},
{Qt::Key_F8, kVK_F8},
{Qt::Key_F9, kVK_F9},
{Qt::Key_F10, kVK_F10},
{Qt::Key_F11, kVK_F11},
{Qt::Key_F12, kVK_F12},
{Qt::Key_F13, kVK_F13},
{Qt::Key_F14, kVK_F14},
};
static std::unordered_map<uint32_t, uint32_t> MOD_MAP = {
{Qt::Key_Shift, shiftKey},
{Qt::Key_Alt, optionKey},
{Qt::Key_Control, controlKey},
{Qt::Key_Option, optionKey},
+ {Qt::Key_Meta, cmdKey},
};
inline UKeyData QtKeyToMac(const UKeySequence &keySeq) {
UKeyData data = {0, 0};
auto key = keySeq.GetSimpleKeys();
auto mods = keySeq.GetModifiers();
if (key.size() == 1 && KEY_MAP.find(key[0]) != KEY_MAP.end())
data.key = KEY_MAP[key[0]];
else
throw UException("Invalid hotkey");
for (auto&& mod: mods) {
if (MOD_MAP.find(mod) == MOD_MAP.end())
throw UException("Invalid hotkey");
data.mods += MOD_MAP[mod];
}
return data;
}
#endif
diff --git a/ukeysequence.cpp b/ukeysequence.cpp
index c44c6d8..321df1f 100644
--- a/ukeysequence.cpp
+++ b/ukeysequence.cpp
@@ -1,140 +1,144 @@
#include "ukeysequence.h"
#include <QDebug>
UKeySequence::UKeySequence(QObject *parent)
: QObject(parent)
{
}
UKeySequence::UKeySequence(const QString& str, QObject *parent)
: QObject(parent)
{
FromString(str);
}
bool IsModifier(int key) {
return (key == Qt::Key_Shift ||
key == Qt::Key_Control ||
- key == Qt::Key_Alt);
+ key == Qt::Key_Alt ||
+ key == Qt::Key_Meta);
}
static QString KeyToStr(int key) {
if (key == Qt::Key_Shift) {
return "Shift";
}
if (key == Qt::Key_Control) {
return "Ctrl";
}
if (key == Qt::Key_Alt) {
return "Alt";
}
+ if (key == Qt::Key_Meta) {
+ return "Meta";
+ }
QKeySequence seq(key);
return seq.toString();
}
void UKeySequence::FromString(const QString& str) {
QStringList keys = str.split('+');
for (int i = 0; i < keys.size(); i++) {
AddKey(keys[i]);
}
}
QString UKeySequence::ToString() {
QVector<int> simpleKeys = GetSimpleKeys();
QVector<int> modifiers = GetModifiers();
QStringList result;
for (int i = 0; i < modifiers.size(); i++) {
result.push_back(KeyToStr(modifiers[i]));
}
for (int i = 0; i < simpleKeys.size(); i++) {
result.push_back(KeyToStr(simpleKeys[i]));
}
return result.join('+');
}
QVector<int> UKeySequence::GetSimpleKeys() const {
QVector<int> result;
for (int i = 0; i < Keys.size(); i++) {
if (!IsModifier(Keys[i])) {
result.push_back(Keys[i]);
}
}
return result;
}
QVector<int> UKeySequence::GetModifiers() const {
QVector<int> result;
for (int i = 0; i < Keys.size(); i++) {
if (IsModifier(Keys[i])) {
result.push_back(Keys[i]);
}
}
return result;
}
void UKeySequence::AddModifiers(Qt::KeyboardModifiers mod) {
if (mod == Qt::NoModifier) {
return;
}
if (mod & Qt::ShiftModifier) {
AddKey(Qt::Key_Shift);
}
if (mod & Qt::ControlModifier) {
AddKey(Qt::Key_Control);
}
if (mod & Qt::AltModifier) {
AddKey(Qt::Key_Alt);
}
if (mod & Qt::MetaModifier) {
AddKey(Qt::Key_Meta);
}
}
void UKeySequence::AddKey(const QString& key) {
if (key.contains("+") || key.contains(",")) {
throw UException("Wrong key");
}
QString mod = key.toLower();
qDebug() << "mod: " << mod;
if (mod == "alt") {
AddKey(Qt::Key_Alt);
return;
}
if (mod == "shift" || mod == "shft") {
AddKey(Qt::Key_Shift);
return;
}
if (mod == "control" || mod == "ctrl") {
AddKey(Qt::Key_Control);
return;
}
if (mod == "win" || mod == "meta") {
AddKey(Qt::Key_Meta);
return;
}
QKeySequence seq(key);
if (seq.count() != 1) {
throw UException("Wrong key");
}
AddKey(seq[0]);
}
void UKeySequence::AddKey(int key) {
if (key <= 0) {
return;
}
for (int i = 0; i < Keys.size(); i++) {
if (Keys[i] == key) {
return;
}
}
qDebug() << "Key added: " << key;
Keys.push_back(key);
}
void UKeySequence::AddKey(const QKeyEvent* event) {
AddKey(event->key());
AddModifiers(event->modifiers());
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Tue, Jun 16, 1:29 AM (2 w, 19 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
71896
Default Alt Text
(7 KB)
Attached To
Mode
R65 cKaiser's UGlobalHotKey
Attached
Detach File
Event Timeline