summaryrefslogtreecommitdiffhomepage
path: root/opentrack
diff options
context:
space:
mode:
Diffstat (limited to 'opentrack')
-rw-r--r--opentrack/keybinding-worker.cpp2
-rw-r--r--opentrack/keybinding-worker.hpp3
-rw-r--r--opentrack/shortcuts.cpp21
-rw-r--r--opentrack/shortcuts.h1
4 files changed, 21 insertions, 6 deletions
diff --git a/opentrack/keybinding-worker.cpp b/opentrack/keybinding-worker.cpp
index 2d133c2f..8bb99b8c 100644
--- a/opentrack/keybinding-worker.cpp
+++ b/opentrack/keybinding-worker.cpp
@@ -16,7 +16,7 @@
bool Key::should_process()
{
- if (keycode == 0 && guid == "")
+ if (!enabled || keycode == 0 && guid == "")
return false;
bool ret = timer.elapsed_ms() > 100;
timer.start();
diff --git a/opentrack/keybinding-worker.hpp b/opentrack/keybinding-worker.hpp
index fa50a974..19db0fa9 100644
--- a/opentrack/keybinding-worker.hpp
+++ b/opentrack/keybinding-worker.hpp
@@ -34,9 +34,10 @@ struct Key {
bool ctrl;
bool alt;
bool held;
+ bool enabled;
Timer timer;
public:
- Key() : keycode(0), shift(false), ctrl(false), alt(false), held(true) {}
+ Key() : keycode(0), shift(false), ctrl(false), alt(false), held(true), enabled(true) {}
bool should_process();
};
diff --git a/opentrack/shortcuts.cpp b/opentrack/shortcuts.cpp
index 2caa1790..e1087008 100644
--- a/opentrack/shortcuts.cpp
+++ b/opentrack/shortcuts.cpp
@@ -9,17 +9,30 @@
#include "shortcuts.h"
#include "win32-shortcuts.h"
-void Shortcuts::bind_keyboard_shortcut(K &key, const key_opts& k, unused(bool, held))
+void Shortcuts::free_binding(K& key)
{
-#if !defined(_WIN32)
- using sh = QxtGlobalShortcut;
+#ifndef _WIN32
if (key)
{
key->setEnabled(false);
key->setShortcut(QKeySequence::UnknownKey);
- std::shared_ptr<sh> tmp(nullptr);
+ std::shared_ptr<QxtGlobalShortcut> tmp(nullptr);
key.swap(tmp);
}
+#else
+ key.keycode = 0;
+ key.guid = "";
+#endif
+}
+
+void Shortcuts::bind_keyboard_shortcut(K &key, const key_opts& k, unused(bool, held))
+{
+#if !defined(_WIN32)
+ using sh = QxtGlobalShortcut;
+ if (key)
+ {
+ free_binding(key);
+ }
key = std::make_shared<sh>();
diff --git a/opentrack/shortcuts.h b/opentrack/shortcuts.h
index b4a6f586..e9935b01 100644
--- a/opentrack/shortcuts.h
+++ b/opentrack/shortcuts.h
@@ -61,6 +61,7 @@ public:
void reload(const std::vector<std::tuple<key_opts&, fun, bool>> &keys_);
private:
+ void free_binding(K& key);
void bind_keyboard_shortcut(K &key, const key_opts& k, bool held);
#ifdef _WIN32
void receiver(const Key& k);