summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--facetracknoir/keyboard.h33
-rw-r--r--facetracknoir/keyboard_listener.ui37
-rw-r--r--facetracknoir/options-dialog.cpp50
-rw-r--r--facetracknoir/options-dialog.hpp1
-rw-r--r--facetracknoir/settings.ui193
-rw-r--r--opentrack/global-shortcuts.cpp205
-rw-r--r--opentrack/global-shortcuts.h14
-rw-r--r--opentrack/shortcuts.cpp44
-rw-r--r--opentrack/shortcuts.h8
9 files changed, 310 insertions, 275 deletions
diff --git a/facetracknoir/keyboard.h b/facetracknoir/keyboard.h
new file mode 100644
index 00000000..65f5c58e
--- /dev/null
+++ b/facetracknoir/keyboard.h
@@ -0,0 +1,33 @@
+#pragma once
+#include "ui_keyboard_listener.h"
+#include <QLabel>
+#include <QKeyEvent>
+
+class KeyboardListener : public QLabel
+{
+ Q_OBJECT
+ Ui_keyboard_listener ui;
+public:
+ KeyboardListener(QWidget* parent = nullptr) : QLabel(parent)
+ {
+ ui.setupUi(this);
+ setFocusPolicy(Qt::StrongFocus);
+ }
+ void keyPressEvent(QKeyEvent* event) override
+ {
+ {
+ switch (event->key() | event->modifiers())
+ {
+ case 83886113: // ctrl
+ case 50331680: // shift
+ case 150994979: // alt
+ case 16777250: // meta
+ return;
+ default: break;
+ }
+ }
+ emit key_pressed(QKeySequence(event->key()));
+ }
+signals:
+ void key_pressed(QKeySequence k);
+};
diff --git a/facetracknoir/keyboard_listener.ui b/facetracknoir/keyboard_listener.ui
new file mode 100644
index 00000000..69ec530d
--- /dev/null
+++ b/facetracknoir/keyboard_listener.ui
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>keyboard_listener</class>
+ <widget class="QLabel" name="keyboard_listener">
+ <property name="windowModality">
+ <enum>Qt::ApplicationModal</enum>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>224</width>
+ <height>33</height>
+ </rect>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="windowTitle">
+ <string>Bind a shortcut</string>
+ </property>
+ <property name="text">
+ <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Press a key or close this window to cancel.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+ </property>
+ <property name="textFormat">
+ <enum>Qt::RichText</enum>
+ </property>
+ <property name="margin">
+ <number>10</number>
+ </property>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/facetracknoir/options-dialog.cpp b/facetracknoir/options-dialog.cpp
index ca4c6c3e..1d8e636a 100644
--- a/facetracknoir/options-dialog.cpp
+++ b/facetracknoir/options-dialog.cpp
@@ -7,6 +7,9 @@
*/
#include "options-dialog.hpp"
+#include "keyboard.h"
+#include <QPushButton>
+#include <QLayout>
OptionsDialog::OptionsDialog()
{
@@ -15,27 +18,6 @@ OptionsDialog::OptionsDialog()
connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK()));
connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel()));
- for ( int i = 0; i < global_key_sequences.size(); i++) {
- ui.cbxCenterKey->addItem(global_key_sequences.at(i));
- ui.cbxToggleKey->addItem(global_key_sequences.at(i));
- ui.cbxZeroKey->addItem(global_key_sequences.at(i));
- }
-
- tie_setting(s.center.key_index, ui.cbxCenterKey);
- tie_setting(s.center.alt, ui.chkCenterAlt);
- tie_setting(s.center.shift, ui.chkCenterShift);
- tie_setting(s.center.ctrl, ui.chkCenterCtrl);
-
- tie_setting(s.toggle.key_index, ui.cbxToggleKey);
- tie_setting(s.toggle.alt, ui.chkToggleAlt);
- tie_setting(s.toggle.shift, ui.chkToggleShift);
- tie_setting(s.toggle.ctrl, ui.chkToggleCtrl);
-
- tie_setting(s.zero.key_index, ui.cbxZeroKey);
- tie_setting(s.zero.alt, ui.chkZeroAlt);
- tie_setting(s.zero.shift, ui.chkZeroShift);
- tie_setting(s.zero.ctrl, ui.chkZeroCtrl);
-
tie_setting(s.s_main.tray_enabled, ui.trayp);
tie_setting(s.s_main.center_at_startup, ui.center_at_startup);
@@ -67,6 +49,32 @@ OptionsDialog::OptionsDialog()
tie_setting(s.s_main.camera_yaw, ui.camera_yaw);
tie_setting(s.s_main.camera_pitch, ui.camera_pitch);
tie_setting(s.s_main.camera_roll, ui.camera_roll);
+
+ connect(ui.bind_center, &QPushButton::pressed, [&]() -> void { bind_key(s.center.keycode, ui.center_text); });
+ connect(ui.bind_zero, &QPushButton::pressed, [&]() -> void { bind_key(s.zero.keycode, ui.zero_text); });
+ connect(ui.bind_toggle, &QPushButton::pressed, [&]() -> void { bind_key(s.toggle.keycode, ui.toggle_text); });
+
+ ui.center_text->setText(QKeySequence(s.center.keycode).toString());
+ ui.zero_text->setText(QKeySequence(s.zero.keycode).toString());
+ ui.toggle_text->setText(QKeySequence(s.toggle.keycode).toString());
+}
+
+void OptionsDialog::bind_key(value<int>& ret, QLabel* label)
+{
+ ret = 0;
+ QDialog d;
+ auto l = new QHBoxLayout;
+ l->setMargin(0);
+ auto k = new KeyboardListener;
+ l->addWidget(k);
+ d.setLayout(l);
+ d.setFixedSize(QSize(500, 500));
+ d.setWindowFlags(Qt::Dialog);
+ connect(k, &KeyboardListener::key_pressed, [&] (QKeySequence s) -> void { ret = static_cast<QVariant>(s).toInt(); d.close(); });
+ d.exec();
+ label->setText(QKeySequence(ret).toString());
+ delete k;
+ delete l;
}
void OptionsDialog::doOK() {
diff --git a/facetracknoir/options-dialog.hpp b/facetracknoir/options-dialog.hpp
index 71a3acda..0ab9849d 100644
--- a/facetracknoir/options-dialog.hpp
+++ b/facetracknoir/options-dialog.hpp
@@ -18,4 +18,5 @@ private:
private slots:
void doOK();
void doCancel();
+ void bind_key(value<int>& ret, QLabel* label);
};
diff --git a/facetracknoir/settings.ui b/facetracknoir/settings.ui
index 34b15b47..5eea9e57 100644
--- a/facetracknoir/settings.ui
+++ b/facetracknoir/settings.ui
@@ -62,82 +62,48 @@
<string notr="true">QGroupBox { border: 0; }</string>
</property>
<layout class="QGridLayout" name="gridLayout_8">
- <item row="3" column="0">
- <widget class="QLabel" name="textLabel2_5">
+ <item row="0" column="1">
+ <widget class="QLabel" name="center_text">
<property name="text">
- <string>Toggle</string>
- </property>
- <property name="wordWrap">
- <bool>false</bool>
+ <string/>
</property>
</widget>
</item>
- <item row="2" column="1">
- <widget class="QCheckBox" name="chkCenterShift">
- <property name="maximumSize">
- <size>
- <width>50</width>
- <height>16777215</height>
- </size>
- </property>
+ <item row="0" column="0">
+ <widget class="QLabel" name="textLabel2_3">
<property name="text">
- <string>Shift</string>
+ <string>Center</string>
+ </property>
+ <property name="wordWrap">
+ <bool>false</bool>
</property>
</widget>
</item>
- <item row="2" column="2">
- <widget class="QCheckBox" name="chkCenterCtrl">
- <property name="maximumSize">
- <size>
- <width>50</width>
- <height>16777215</height>
- </size>
- </property>
+ <item row="6" column="1">
+ <widget class="QLabel" name="zero_text">
<property name="text">
- <string>Ctrl</string>
+ <string/>
</property>
</widget>
</item>
- <item row="2" column="4">
- <widget class="QComboBox" name="cbxCenterKey">
- <property name="minimumSize">
- <size>
- <width>90</width>
- <height>0</height>
- </size>
- </property>
- <property name="toolTip">
- <string>Select Number</string>
- </property>
- <property name="insertPolicy">
- <enum>QComboBox::InsertAlphabetically</enum>
+ <item row="5" column="1">
+ <widget class="QLabel" name="toggle_text">
+ <property name="text">
+ <string/>
</property>
</widget>
</item>
- <item row="2" column="0">
- <widget class="QLabel" name="textLabel2_3">
+ <item row="5" column="0">
+ <widget class="QLabel" name="textLabel2_5">
<property name="text">
- <string>Center</string>
+ <string>Toggle</string>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
</widget>
</item>
- <item row="2" column="3">
- <widget class="QCheckBox" name="chkCenterAlt">
- <property name="maximumSize">
- <size>
- <width>50</width>
- <height>16777215</height>
- </size>
- </property>
- <property name="text">
- <string>Alt</string>
- </property>
- </widget>
- </item>
- <item row="4" column="0">
+ <item row="6" column="0">
<widget class="QLabel" name="textLabel2_6">
<property name="text">
<string>Zero</string>
@@ -147,113 +113,24 @@
</property>
</widget>
</item>
- <item row="4" column="3">
- <widget class="QCheckBox" name="chkZeroAlt">
- <property name="maximumSize">
- <size>
- <width>50</width>
- <height>16777215</height>
- </size>
- </property>
- <property name="text">
- <string>Alt</string>
- </property>
- </widget>
- </item>
- <item row="3" column="2">
- <widget class="QCheckBox" name="chkToggleCtrl">
- <property name="maximumSize">
- <size>
- <width>50</width>
- <height>16777215</height>
- </size>
- </property>
- <property name="text">
- <string>Ctrl</string>
- </property>
- </widget>
- </item>
- <item row="3" column="3">
- <widget class="QCheckBox" name="chkToggleAlt">
- <property name="maximumSize">
- <size>
- <width>50</width>
- <height>16777215</height>
- </size>
- </property>
- <property name="text">
- <string>Alt</string>
- </property>
- </widget>
- </item>
- <item row="4" column="2">
- <widget class="QCheckBox" name="chkZeroCtrl">
- <property name="maximumSize">
- <size>
- <width>50</width>
- <height>16777215</height>
- </size>
- </property>
+ <item row="0" column="2">
+ <widget class="QPushButton" name="bind_center">
<property name="text">
- <string>Ctrl</string>
+ <string>Bind</string>
</property>
</widget>
</item>
- <item row="4" column="1">
- <widget class="QCheckBox" name="chkZeroShift">
- <property name="maximumSize">
- <size>
- <width>50</width>
- <height>16777215</height>
- </size>
- </property>
+ <item row="5" column="2">
+ <widget class="QPushButton" name="bind_toggle">
<property name="text">
- <string>Shift</string>
+ <string>Bind</string>
</property>
</widget>
</item>
- <item row="4" column="4">
- <widget class="QComboBox" name="cbxZeroKey">
- <property name="minimumSize">
- <size>
- <width>90</width>
- <height>0</height>
- </size>
- </property>
- <property name="toolTip">
- <string>Select Number</string>
- </property>
- <property name="insertPolicy">
- <enum>QComboBox::InsertAlphabetically</enum>
- </property>
- </widget>
- </item>
- <item row="3" column="1">
- <widget class="QCheckBox" name="chkToggleShift">
- <property name="maximumSize">
- <size>
- <width>50</width>
- <height>16777215</height>
- </size>
- </property>
+ <item row="6" column="2">
+ <widget class="QPushButton" name="bind_zero">
<property name="text">
- <string>Shift</string>
- </property>
- </widget>
- </item>
- <item row="3" column="4">
- <widget class="QComboBox" name="cbxToggleKey">
- <property name="minimumSize">
- <size>
- <width>90</width>
- <height>0</height>
- </size>
- </property>
- <property name="toolTip">
- <string>Select Number</string>
- </property>
- <property name="insertPolicy">
- <enum>QComboBox::InsertAlphabetically</enum>
+ <string>Bind</string>
</property>
</widget>
</item>
@@ -1152,21 +1029,9 @@
</customwidget>
</customwidgets>
<tabstops>
- <tabstop>chkCenterShift</tabstop>
<tabstop>tabWidget</tabstop>
- <tabstop>chkCenterAlt</tabstop>
- <tabstop>cbxCenterKey</tabstop>
- <tabstop>chkToggleShift</tabstop>
- <tabstop>chkToggleCtrl</tabstop>
- <tabstop>chkToggleAlt</tabstop>
- <tabstop>cbxToggleKey</tabstop>
- <tabstop>chkZeroShift</tabstop>
- <tabstop>chkZeroCtrl</tabstop>
- <tabstop>chkZeroAlt</tabstop>
- <tabstop>cbxZeroKey</tabstop>
<tabstop>center_at_startup</tabstop>
<tabstop>trayp</tabstop>
- <tabstop>chkCenterCtrl</tabstop>
<tabstop>camera_yaw</tabstop>
<tabstop>camera_pitch</tabstop>
<tabstop>camera_roll</tabstop>
diff --git a/opentrack/global-shortcuts.cpp b/opentrack/global-shortcuts.cpp
index 7569fd9a..5c921a90 100644
--- a/opentrack/global-shortcuts.cpp
+++ b/opentrack/global-shortcuts.cpp
@@ -1,8 +1,8 @@
#include <QList>
-#include <QString>
-
-extern QList<QString> global_key_sequences;
-extern QList<int> global_windows_key_sequences;
+#include <QKeySequence>
+#include <QVariant>
+#include "global-shortcuts.h"
+#include <tuple>
#if defined(_WIN32)
# ifndef DIRECTINPUT_VERSION
@@ -11,58 +11,151 @@ extern QList<int> global_windows_key_sequences;
# include <windows.h>
# include <dinput.h>
-QList<int> global_windows_key_sequences =
- QList<int>()
- << 0
- << DIK_F1
- << DIK_F2
- << DIK_F3
- << DIK_F4
- << DIK_F5
- << DIK_F6
- << DIK_F7
- << DIK_F8
- << DIK_F9
- << DIK_F10
- << DIK_F11
- << DIK_F12
- << DIK_LEFT
- << DIK_RIGHT
- << DIK_UP
- << DIK_DOWN
- << DIK_PGUP
- << DIK_PGDN
- << DIK_HOME
- << DIK_END
- << DIK_BACK
- << DIK_DELETE
- << DIK_RETURN;
-#endif
+QList<win_key> windows_key_mods =
+ QList<win_key>({
+ win_key(DIK_LCONTROL, Qt::Key::Key_Control),
+ win_key(DIK_RCONTROL, Qt::Key::Key_Control),
+ win_key(DIK_LALT, Qt::Key::Key_Alt),
+ win_key(DIK_RALT, Qt::Key::Key_Alt),
+ win_key(DIK_LSHIFT, Qt::Key::Key_Shift),
+ win_key(DIK_RSHIFT, Qt::Key::Key_Shift),
+ win_key(DIK_LWIN, Qt::Key::Key_unknown),
+ win_key(DIK_RWIN, Qt::Key::Key_unknown)
+ });
+
+QList<win_key> windows_key_sequences =
+ QList<win_key>({
+ win_key(DIK_F1, Qt::Key::Key_F1 ),
+ win_key(DIK_F2, Qt::Key::Key_F2 ),
+ win_key(DIK_F3, Qt::Key::Key_F3 ),
+ win_key(DIK_F4, Qt::Key::Key_F4 ),
+ win_key(DIK_F5, Qt::Key::Key_F5 ),
+ win_key(DIK_F6, Qt::Key::Key_F6 ),
+ win_key(DIK_F7, Qt::Key::Key_F7 ),
+ win_key(DIK_F8, Qt::Key::Key_F8 ),
+ win_key(DIK_F9, Qt::Key::Key_F9 ),
+ win_key(DIK_F10, Qt::Key::Key_F10 ),
+ win_key(DIK_F11, Qt::Key::Key_F11 ),
+ win_key(DIK_F12, Qt::Key::Key_F12 ),
+ win_key(DIK_LEFT, Qt::Key::Key_Left ),
+ win_key(DIK_RIGHT, Qt::Key::Key_Right ),
+ win_key(DIK_UP, Qt::Key::Key_Up ),
+ win_key(DIK_DOWN, Qt::Key::Key_Down ),
+ win_key(DIK_PRIOR, Qt::Key::Key_PageUp ),
+ win_key(DIK_NEXT, Qt::Key::Key_PageDown ),
+ win_key(DIK_HOME, Qt::Key::Key_Home ),
+ win_key(DIK_END, Qt::Key::Key_End ),
+ win_key(DIK_BACK, Qt::Key::Key_Backspace ),
+ win_key(DIK_COMMA, Qt::Key::Key_Comma ),
+ win_key(DIK_PERIOD, Qt::Key::Key_Period ),
+ win_key(DIK_LBRACKET, Qt::Key::Key_BracketLeft ),
+ win_key(DIK_RBRACKET, Qt::Key::Key_BracketRight ),
+ win_key(DIK_SEMICOLON, Qt::Key::Key_Semicolon ),
+ win_key(DIK_SLASH, Qt::Key::Key_Slash ),
+ win_key(DIK_BACKSLASH, Qt::Key::Key_Backslash ),
+ win_key(DIK_BACKSPACE, Qt::Key::Key_Backspace ),
+ win_key(DIK_APOSTROPHE, Qt::Key::Key_Apostrophe ),
+ win_key(DIK_GRAVE, Qt::Key::Key_QuoteLeft ),
+ win_key(DIK_MINUS, Qt::Key::Key_Minus ),
+ win_key(DIK_EQUALS, Qt::Key::Key_Equal ),
+ win_key(DIK_PERIOD, Qt::Key::Key_Period ),
+ win_key(DIK_F1, Qt::Key::Key_F1 ),
+ win_key(DIK_F2, Qt::Key::Key_F2 ),
+ win_key(DIK_F3, Qt::Key::Key_F3 ),
+ win_key(DIK_F4, Qt::Key::Key_F4 ),
+ win_key(DIK_F5, Qt::Key::Key_F5 ),
+ win_key(DIK_F6, Qt::Key::Key_F6 ),
+ win_key(DIK_F7, Qt::Key::Key_F7 ),
+ win_key(DIK_F8, Qt::Key::Key_F8 ),
+ win_key(DIK_F9, Qt::Key::Key_F9 ),
+ win_key(DIK_F10, Qt::Key::Key_F10 ),
+ win_key(DIK_F11, Qt::Key::Key_F11 ),
+ win_key(DIK_F12, Qt::Key::Key_F12 ),
+ win_key(DIK_0, Qt::Key::Key_0 ),
+ win_key(DIK_1, Qt::Key::Key_1 ),
+ win_key(DIK_2, Qt::Key::Key_2 ),
+ win_key(DIK_3, Qt::Key::Key_3 ),
+ win_key(DIK_4, Qt::Key::Key_4 ),
+ win_key(DIK_5, Qt::Key::Key_5 ),
+ win_key(DIK_6, Qt::Key::Key_6 ),
+ win_key(DIK_7, Qt::Key::Key_7 ),
+ win_key(DIK_8, Qt::Key::Key_8 ),
+ win_key(DIK_9, Qt::Key::Key_9 ),
+ win_key(DIK_A, Qt::Key::Key_A ),
+ win_key(DIK_B, Qt::Key::Key_B ),
+ win_key(DIK_C, Qt::Key::Key_C ),
+ win_key(DIK_D, Qt::Key::Key_D ),
+ win_key(DIK_E, Qt::Key::Key_E ),
+ win_key(DIK_F, Qt::Key::Key_F ),
+ win_key(DIK_G, Qt::Key::Key_G ),
+ win_key(DIK_H, Qt::Key::Key_H ),
+ win_key(DIK_I, Qt::Key::Key_I ),
+ win_key(DIK_J, Qt::Key::Key_J ),
+ win_key(DIK_K, Qt::Key::Key_K ),
+ win_key(DIK_L, Qt::Key::Key_L ),
+ win_key(DIK_M, Qt::Key::Key_M ),
+ win_key(DIK_N, Qt::Key::Key_N ),
+ win_key(DIK_O, Qt::Key::Key_O ),
+ win_key(DIK_P, Qt::Key::Key_P ),
+ win_key(DIK_Q, Qt::Key::Key_Q ),
+ win_key(DIK_R, Qt::Key::Key_R ),
+ win_key(DIK_S, Qt::Key::Key_S ),
+ win_key(DIK_T, Qt::Key::Key_T ),
+ win_key(DIK_U, Qt::Key::Key_U ),
+ win_key(DIK_V, Qt::Key::Key_V ),
+ win_key(DIK_W, Qt::Key::Key_W ),
+ win_key(DIK_X, Qt::Key::Key_X ),
+ win_key(DIK_Y, Qt::Key::Key_Y ),
+ win_key(DIK_Z, Qt::Key::Key_Z ),
+ });
+
+bool win_key::from_qt(QKeySequence qt_, int& dik, Qt::KeyboardModifiers& mods)
+{
+ auto qt = static_cast<QVariant>(qt_).toInt();
+ const auto all_mods = Qt::KeyboardModifierMask;
+ auto our_mods = qt & all_mods;
+#ifdef _WIN32
+ const auto our_mods_ = our_mods;
+ our_mods |= Qt::ShiftModifier;
+ switch (qt)
+ {
+ case Qt::Key::Key_BraceLeft: qt = Qt::Key::Key_BracketLeft; break;
+ case Qt::Key::Key_BraceRight: qt = Qt::Key::Key_BracketRight; break;
+ case Qt::Key::Key_ParenLeft: qt = Qt::Key::Key_9; break;
+ case Qt::Key::Key_ParenRight: qt = Qt::Key::Key_0; break;
-QList<QString> global_key_sequences =
- QList<QString>()
- << ""
- << "F1"
- << "F2"
- << "F3"
- << "F4"
- << "F5"
- << "F6"
- << "F7"
- << "F8"
- << "F9"
- << "F10"
- << "F11"
- << "F12"
- << "Left"
- << "Right"
- << "Up"
- << "Down"
- << "PgUp"
- << "PgDown"
- << "Home"
- << "End"
- << "Del"
-;
+ case Qt::Key::Key_Exclam: qt = Qt::Key::Key_1; break;
+ case Qt::Key::Key_At: qt = Qt::Key::Key_2; break;
+ case Qt::Key::Key_NumberSign: qt = Qt::Key::Key_3; break;
+ case Qt::Key::Key_Dollar: qt = Qt::Key::Key_4; break;
+ case Qt::Key::Key_Percent: qt = Qt::Key::Key_5; break;
+ case Qt::Key::Key_AsciiCircum: qt = Qt::Key::Key_6; break;
+ case Qt::Key::Key_Ampersand: qt = Qt::Key::Key_7; break;
+ case Qt::Key::Key_Asterisk: qt = Qt::Key::Key_8; break;
+ case Qt::Key::Key_Underscore: qt = Qt::Key::Key_Minus; break;
+ case Qt::Key::Key_Plus: qt = Qt::Key::Key_Equal; break;
+ case Qt::Key::Key_Colon: qt = Qt::Key::Key_Semicolon; break;
+ case Qt::Key::Key_QuoteDbl: qt = Qt::Key::Key_Apostrophe; break;
+ case Qt::Key::Key_Less: qt = Qt::Key::Key_Comma; break;
+ case Qt::Key::Key_Question: qt = Qt::Key::Key_Slash; break;
+ case Qt::Key::Key_Bar: qt = Qt::Key::Key_Backslash; break;
+ default: our_mods = our_mods_; break;
+ }
+#endif
+
+ const auto key = qt & ~all_mods;
+ for (auto& wk : windows_key_sequences)
+ {
+ if (wk.qt == key)
+ {
+ dik = wk.win;
+ mods = static_cast<Qt::KeyboardModifiers>(our_mods);
+ return true;
+ }
+ }
+ return false;
+}
+
+#endif
diff --git a/opentrack/global-shortcuts.h b/opentrack/global-shortcuts.h
new file mode 100644
index 00000000..2b25321b
--- /dev/null
+++ b/opentrack/global-shortcuts.h
@@ -0,0 +1,14 @@
+#pragma once
+
+struct win_key;
+
+extern QList<win_key> windows_key_mods;
+extern QList<win_key> windows_key_sequences;
+
+struct win_key
+{
+ win_key(int win, Qt::Key qt) : win(win), qt(qt) {}
+ int win;
+ Qt::Key qt;
+ static bool from_qt(QKeySequence qt_, int& dik, Qt::KeyboardModifiers &mods);
+};
diff --git a/opentrack/shortcuts.cpp b/opentrack/shortcuts.cpp
index ed1701c7..190c4003 100644
--- a/opentrack/shortcuts.cpp
+++ b/opentrack/shortcuts.cpp
@@ -7,6 +7,7 @@
*/
#include "shortcuts.h"
+#include "global-shortcuts.h"
#include <QMutexLocker>
#if defined(_WIN32)
@@ -124,38 +125,25 @@ void KeybindingWorker::run() {
void Shortcuts::bind_keyboard_shortcut(K &key, key_opts& k)
{
#if !defined(_WIN32)
- const int idx = k.key_index;
- if (!key)
- key = std::make_shared<QxtGlobalShortcut>();
- else {
- key->setEnabled(false);
- key->setShortcut(QKeySequence::UnknownKey);
- }
- if (idx > 0)
+ key->setEnabled(false);
+ key->setShortcut(QKeySequence::UnknownKey);
+
+ if (k.keycode)
{
- QString seq(global_key_sequences.value(idx, ""));
- if (!seq.isEmpty())
- {
- if (k.shift)
- seq = "Shift+" + seq;
- if (k.alt)
- seq = "Alt+" + seq;
- if (k.ctrl)
- seq = "Ctrl+" + seq;
- key->setShortcut(QKeySequence::fromString(seq, QKeySequence::PortableText));
- key->setEnabled();
- }
+ key->setShortcut(Qt::KeySequence(k.keycode));
+ key->setEnabled();
}
+}
#else
key = K();
- int idx = k.key_index;
- key.keycode = 0;
- key.shift = key.alt = key.ctrl = 0;
- if (idx > 0 && idx < global_windows_key_sequences.size())
- key.keycode = global_windows_key_sequences[idx];
- key.shift = k.shift;
- key.alt = k.alt;
- key.ctrl = k.ctrl;
+ int idx = 0;
+ Qt::KeyboardModifiers mods = Qt::NoModifier;
+ if (k.keycode != Qt::Key_unknown)
+ win_key::from_qt(QKeySequence(k.keycode), idx, mods);
+ key.shift = !!(mods & Qt::ShiftModifier);
+ key.alt = !!(mods & Qt::AltModifier);
+ key.ctrl = !!(mods & Qt::ControlModifier);
+ key.keycode = idx;
#endif
}
diff --git a/opentrack/shortcuts.h b/opentrack/shortcuts.h
index 520042f0..6a9a6f77 100644
--- a/opentrack/shortcuts.h
+++ b/opentrack/shortcuts.h
@@ -27,14 +27,10 @@ using namespace options;
extern QList<QString> global_key_sequences;
struct key_opts {
- value<int> key_index;
- value<bool> ctrl, alt, shift;
+ value<int> keycode;
key_opts(pbundle b, const QString& name) :
- key_index(b, QString("key-index-%1").arg(name), 0),
- ctrl(b, QString("key-ctrl-%1").arg(name), 0),
- alt(b, QString("key-alt-%1").arg(name), 0),
- shift(b, QString("key-shift-%1").arg(name), 0)
+ keycode(b, QString("keycode-%1").arg(name), 0)
{}
};