summaryrefslogtreecommitdiffhomepage
path: root/opentrack
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2014-10-21 10:10:56 +0200
committerStanislaw Halik <sthalik@misaki.pl>2014-10-21 10:29:17 +0200
commitf6d8fbbf3f4bc6984020de776285a38ad45c3631 (patch)
tree8d9b297e09de1053878a01ee1bf198803daa7967 /opentrack
parenta1ce590fb13ce34a3051f619f0d9cdbc1d2dffa5 (diff)
workaround qxt-mini "shortcut failed to unregister"
Diffstat (limited to 'opentrack')
-rw-r--r--opentrack/shortcuts.cpp16
-rw-r--r--opentrack/shortcuts.h38
-rw-r--r--opentrack/work.hpp6
3 files changed, 38 insertions, 22 deletions
diff --git a/opentrack/shortcuts.cpp b/opentrack/shortcuts.cpp
index 0a3d7e0d..d1cfa503 100644
--- a/opentrack/shortcuts.cpp
+++ b/opentrack/shortcuts.cpp
@@ -128,16 +128,18 @@ void KeybindingWorker::run() {
Sleep(25);
}
}
-
-#else
#endif
void Shortcuts::bind_keyboard_shortcut(K &key, key_opts& k)
{
#if !defined(_WIN32)
- key.setShortcut(QKeySequence::fromString(""));
- key.setDisabled();
const int idx = k.key_index;
+ if (!key)
+ key = std::make_shared<QxtGlobalShortcut>();
+ else {
+ key->setEnabled(false);
+ key->setShortcut(QKeySequence::UnknownKey);
+ }
if (idx > 0)
{
QString seq(global_key_sequences.value(idx, ""));
@@ -149,10 +151,8 @@ void Shortcuts::bind_keyboard_shortcut(K &key, key_opts& k)
seq = "Alt+" + seq;
if (k.ctrl)
seq = "Ctrl+" + seq;
- key.setShortcut(QKeySequence::fromString(seq, QKeySequence::PortableText));
- key.setEnabled();
- } else {
- key.setDisabled();
+ key->setShortcut(QKeySequence::fromString(seq, QKeySequence::PortableText));
+ key->setEnabled();
}
}
#else
diff --git a/opentrack/shortcuts.h b/opentrack/shortcuts.h
index 54305a52..8fe1a39b 100644
--- a/opentrack/shortcuts.h
+++ b/opentrack/shortcuts.h
@@ -19,6 +19,7 @@ extern QList<QString> global_key_sequences;
struct key_opts {
value<int> key_index;
value<bool> ctrl, alt, shift;
+
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),
@@ -78,7 +79,7 @@ signals:
struct Shortcuts {
using K =
#ifndef _WIN32
- QxtGlobalShortcut
+ ptr<QxtGlobalShortcut>
#else
Key
#endif
@@ -86,6 +87,8 @@ struct Shortcuts {
K keyCenter;
K keyToggle;
+
+ WId handle;
#ifdef _WIN32
ptr<KeybindingWorker> keybindingWorker;
#endif
@@ -99,23 +102,36 @@ struct Shortcuts {
toggle(b, "toggle")
{}
} s;
-
-#ifdef _WIN32
- Shortcuts(WId handle)
-#else
- Shortcuts(WId)
-#endif
+
+ 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
+#endif
}
private:
- void bind_keyboard_shortcut(K& key, key_opts& k);
+ void bind_keyboard_shortcut(K &key, key_opts& k);
};
class KeyboardShortcutDialog: public QWidget
@@ -124,7 +140,7 @@ class KeyboardShortcutDialog: public QWidget
public:
KeyboardShortcutDialog();
private:
- Ui::UICKeyboardShortcutDialog ui;
+ Ui::UICKeyboardShortcutDialog ui;
Shortcuts::settings s;
ptr<Shortcuts> sc;
signals:
@@ -132,4 +148,4 @@ signals:
private slots:
void doOK();
void doCancel();
-}; \ No newline at end of file
+};
diff --git a/opentrack/work.hpp b/opentrack/work.hpp
index 73ba691b..d0130018 100644
--- a/opentrack/work.hpp
+++ b/opentrack/work.hpp
@@ -24,8 +24,8 @@ struct Work
handle(handle)
{
#ifndef _WIN32
- QObject::connect(&sc->keyCenter, SIGNAL(activated()), recv, SLOT(shortcutRecentered()));
- QObject::connect(&sc->keyToggle, SIGNAL(activated()), recv, SLOT(shortcutToggled()));
+ QObject::connect(sc->keyCenter.get(), SIGNAL(activated()), recv, SLOT(shortcutRecentered()));
+ QObject::connect(sc->keyToggle.get(), SIGNAL(activated()), recv, SLOT(shortcutToggled()));
#else
QObject::connect(sc->keybindingWorker.get(), SIGNAL(center()), recv, SLOT(shortcutRecentered()));
QObject::connect(sc->keybindingWorker.get(), SIGNAL(toggle()), recv, SLOT(shortcutToggled()));
@@ -35,7 +35,7 @@ struct Work
void reload_shortcuts()
{
- sc = std::make_shared<Shortcuts>(handle);
+ sc->reload();
}
~Work()