diff options
Diffstat (limited to 'opentrack/shortcuts.h')
-rw-r--r-- | opentrack/shortcuts.h | 97 |
1 files changed, 38 insertions, 59 deletions
diff --git a/opentrack/shortcuts.h b/opentrack/shortcuts.h index 8fe1a39b..4d4b19d3 100644 --- a/opentrack/shortcuts.h +++ b/opentrack/shortcuts.h @@ -1,4 +1,5 @@ #pragma once +#include <QObject> #include <QWidget> #include <QElapsedTimer> #include <QThread> @@ -6,11 +7,12 @@ #include <QCheckBox> #include <QComboBox> #include <QSettings> +#include <QMutex> #include "qxt-mini/QxtGlobalShortcut" #include "opentrack/plugin-support.h" #include "opentrack/options.hpp" -#include "ui_ftnoir_keyboardshortcuts.h" +#include "opentrack/main-settings.hpp" using namespace options; @@ -40,112 +42,89 @@ struct Key { bool shift; bool ctrl; bool alt; - bool ever_pressed; QElapsedTimer timer; public: - Key() : keycode(0), shift(false), ctrl(false), alt(false), ever_pressed(false) + Key() : keycode(0), shift(false), ctrl(false), alt(false) { } + + bool should_process() + { + return !timer.isValid() ? (timer.start(), true) : timer.restart() > 100; + } }; #else typedef unsigned char BYTE; struct Key { int foo; }; #endif +struct Shortcuts; + struct KeybindingWorker : public QThread { - Q_OBJECT #ifdef _WIN32 private: + Shortcuts& sc; LPDIRECTINPUT8 din; LPDIRECTINPUTDEVICE8 dinkeyboard; Key kCenter; Key kToggle; + Key kZero; + QMutex mtx; public: volatile bool should_quit; ~KeybindingWorker(); - KeybindingWorker(Key keyCenter, Key keyToggle, WId handle); - void run(); + KeybindingWorker(Key keyCenter, Key keyToggle, Key keyZero, WId handle, Shortcuts& sc); + void run(); + void set_keys(Key kCenter, Key kToggle, Key kZero); #else public: - KeybindingWorker(Key, Key, WId) {} - void run() {} + KeybindingWorker(Key, Key, Key, WId) {} + void run() {} #endif -signals: - void center(); - void toggle(); }; +struct Shortcuts : public QObject { + Q_OBJECT -struct Shortcuts { +public: using K = #ifndef _WIN32 - ptr<QxtGlobalShortcut> + mem<QxtGlobalShortcut> #else Key #endif ; - + K keyCenter; K keyToggle; + K keyZero; WId handle; #ifdef _WIN32 - ptr<KeybindingWorker> keybindingWorker; + mem<KeybindingWorker> keybindingWorker; #endif - + struct settings { pbundle b; - key_opts center, toggle; + key_opts center, toggle, zero; + main_settings s_main; settings() : b(bundle("keyboard-shortcuts")), center(b, "center"), - toggle(b, "toggle") + toggle(b, "toggle"), + zero(b, "zero") {} } s; - Shortcuts(WId handle) : handle(handle) - { - reload(); - } + Shortcuts(WId handle) : handle(handle) { reload(); } - void reload() - { -#ifndef _WIN32 - if (keyCenter) - { - keyCenter->setShortcut(QKeySequence::UnknownKey); - keyCenter->setEnabled(false); - } - if (keyToggle) - { - keyToggle->setShortcut(QKeySequence::UnknownKey); - keyToggle->setEnabled(false); - } -#endif - bind_keyboard_shortcut(keyCenter, s.center); - bind_keyboard_shortcut(keyToggle, s.toggle); -#ifdef _WIN32 - keybindingWorker = nullptr; - keybindingWorker = std::make_shared<KeybindingWorker>(keyCenter, keyToggle, handle); - keybindingWorker->start(); -#endif - } + void reload(); private: void bind_keyboard_shortcut(K &key, key_opts& k); -}; - -class KeyboardShortcutDialog: public QWidget -{ - Q_OBJECT -public: - KeyboardShortcutDialog(); -private: - Ui::UICKeyboardShortcutDialog ui; - Shortcuts::settings s; - ptr<Shortcuts> sc; signals: - void reload(); -private slots: - void doOK(); - void doCancel(); + void center(); + void toggle(); + void zero(); }; + + |