summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-04-29 09:21:10 +0200
committerStanislaw Halik <sthalik@misaki.pl>2016-04-29 09:21:23 +0200
commit3a7011ff73cce39ecacb4c5651c1a2dbda8eb10e (patch)
tree84d21d48998aaacbad9cb27b7e5edf29b0dd1396
parent69cc802722c8264c0fd8b138a298d4820c11f1d8 (diff)
api, main: implement new keybindings
The following keybindings are now implemented: - restart tracking. if not started, starts. - toggle (keep position) while key held - zero (keep zero) while key held The latter two options only work for Windows as libqxt doesn't support them. Closes #291
-rwxr-xr-x[-rw-r--r--]gui/options-dialog.cpp7
-rwxr-xr-x[-rw-r--r--]gui/settings.ui147
-rwxr-xr-xgui/ui.cpp13
-rwxr-xr-x[-rw-r--r--]gui/ui.h3
-rwxr-xr-x[-rw-r--r--]opentrack/keybinding-worker.cpp4
-rwxr-xr-x[-rw-r--r--]opentrack/main-settings.hpp8
-rwxr-xr-x[-rw-r--r--]opentrack/shortcuts.cpp19
-rwxr-xr-x[-rw-r--r--]opentrack/shortcuts.h14
-rwxr-xr-x[-rw-r--r--]opentrack/tracker.h2
-rwxr-xr-x[-rw-r--r--]opentrack/work.hpp16
10 files changed, 158 insertions, 75 deletions
diff --git a/gui/options-dialog.cpp b/gui/options-dialog.cpp
index e1324ccc..c99bc730 100644..100755
--- a/gui/options-dialog.cpp
+++ b/gui/options-dialog.cpp
@@ -78,17 +78,24 @@ OptionsDialog::OptionsDialog(main_settings& main,
connect(ui.bind_center, &QPushButton::pressed, [&]() -> void { bind_key(main.key_center, ui.center_text); });
connect(ui.bind_zero, &QPushButton::pressed, [&]() -> void { bind_key(main.key_zero, ui.zero_text); });
connect(ui.bind_toggle, &QPushButton::pressed, [&]() -> void { bind_key(main.key_toggle, ui.toggle_text); });
+ connect(ui.bind_toggle_held, &QPushButton::pressed, [&]() -> void { bind_key(main.key_toggle_press, ui.toggle_held_text); });
+ connect(ui.bind_zero_held, &QPushButton::pressed, [&]() -> void { bind_key(main.key_zero_press, ui.zero_held_text); });
+
connect(ui.bind_start, &QPushButton::pressed, [&]() -> void { bind_key(main.key_start_tracking, ui.start_tracking_text); });
connect(ui.bind_stop, &QPushButton::pressed, [&]() -> void { bind_key(main.key_stop_tracking, ui.stop_tracking_text); });
connect(ui.bind_toggle_tracking, &QPushButton::pressed, [&]() -> void { bind_key(main.key_toggle_tracking, ui.toggle_tracking_text); });
+ connect(ui.bind_restart_tracking, &QPushButton::pressed, [&]() -> void { bind_key(main.key_restart_tracking, ui.restart_tracking_text); });
ui.center_text->setText(kopts_to_string(main.key_center));
ui.toggle_text->setText(kopts_to_string(main.key_toggle));
+ ui.toggle_held_text->setText(kopts_to_string(main.key_toggle_press));
ui.zero_text->setText(kopts_to_string(main.key_zero));
+ ui.zero_held_text->setText(kopts_to_string(main.key_zero_press));
ui.start_tracking_text->setText(kopts_to_string(main.key_start_tracking));
ui.stop_tracking_text->setText(kopts_to_string(main.key_stop_tracking));
ui.toggle_tracking_text->setText(kopts_to_string(main.key_toggle_tracking));
+ ui.restart_tracking_text->setText(kopts_to_string(main.key_restart_tracking));
}
void OptionsDialog::bind_key(key_opts& kopts, QLabel* label)
diff --git a/gui/settings.ui b/gui/settings.ui
index 3a5de399..4c166a08 100644..100755
--- a/gui/settings.ui
+++ b/gui/settings.ui
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>381</width>
- <height>603</height>
+ <width>384</width>
+ <height>639</height>
</rect>
</property>
<property name="windowTitle">
@@ -62,14 +62,59 @@
<string notr="true">QGroupBox { border: 0; }</string>
</property>
<layout class="QGridLayout" name="gridLayout_8">
- <item row="8" column="2">
- <widget class="QPushButton" name="bind_stop">
+ <item row="11" column="2">
+ <widget class="QPushButton" name="bind_toggle_tracking">
<property name="text">
<string>Bind</string>
</property>
</widget>
</item>
- <item row="7" column="0">
+ <item row="11" column="0">
+ <widget class="QLabel" name="textLabel2_9">
+ <property name="text">
+ <string>Toggle tracking</string>
+ </property>
+ <property name="wordWrap">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="0">
+ <widget class="QLabel" name="label_27">
+ <property name="text">
+ <string>Toggle while held</string>
+ </property>
+ </widget>
+ </item>
+ <item row="9" column="1">
+ <widget class="QLabel" name="start_tracking_text">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="9" column="2">
+ <widget class="QPushButton" name="bind_start">
+ <property name="text">
+ <string>Bind</string>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="2">
+ <widget class="QPushButton" name="bind_toggle">
+ <property name="text">
+ <string>Bind</string>
+ </property>
+ </widget>
+ </item>
+ <item row="10" column="1">
+ <widget class="QLabel" name="stop_tracking_text">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="9" column="0">
<widget class="QLabel" name="textLabel2_7">
<property name="text">
<string>Start tracking</string>
@@ -79,7 +124,21 @@
</property>
</widget>
</item>
- <item row="8" column="0">
+ <item row="11" column="1">
+ <widget class="QLabel" name="toggle_tracking_text">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="10" column="2">
+ <widget class="QPushButton" name="bind_stop">
+ <property name="text">
+ <string>Bind</string>
+ </property>
+ </widget>
+ </item>
+ <item row="10" column="0">
<widget class="QLabel" name="textLabel2_8">
<property name="text">
<string>Stop tracking</string>
@@ -106,21 +165,21 @@
</property>
</widget>
</item>
- <item row="5" column="1">
- <widget class="QLabel" name="toggle_text">
+ <item row="7" column="1">
+ <widget class="QLabel" name="zero_text">
<property name="text">
<string/>
</property>
</widget>
</item>
- <item row="6" column="1">
- <widget class="QLabel" name="zero_text">
+ <item row="5" column="1">
+ <widget class="QLabel" name="toggle_text">
<property name="text">
<string/>
</property>
</widget>
</item>
- <item row="6" column="0">
+ <item row="7" column="0">
<widget class="QLabel" name="textLabel2_6">
<property name="text">
<string>Zero</string>
@@ -130,6 +189,13 @@
</property>
</widget>
</item>
+ <item row="8" column="0">
+ <widget class="QLabel" name="label_28">
+ <property name="text">
+ <string>Zero while held</string>
+ </property>
+ </widget>
+ </item>
<item row="0" column="2">
<widget class="QPushButton" name="bind_center">
<property name="text">
@@ -147,62 +213,62 @@
</property>
</widget>
</item>
- <item row="6" column="2">
+ <item row="7" column="2">
<widget class="QPushButton" name="bind_zero">
<property name="text">
<string>Bind</string>
</property>
</widget>
</item>
- <item row="5" column="2">
- <widget class="QPushButton" name="bind_toggle">
+ <item row="6" column="2">
+ <widget class="QPushButton" name="bind_toggle_held">
<property name="text">
<string>Bind</string>
</property>
</widget>
</item>
- <item row="7" column="2">
- <widget class="QPushButton" name="bind_start">
+ <item row="8" column="1">
+ <widget class="QLabel" name="zero_held_text">
<property name="text">
- <string>Bind</string>
+ <string/>
</property>
</widget>
</item>
- <item row="9" column="0">
- <widget class="QLabel" name="textLabel2_9">
+ <item row="8" column="2">
+ <widget class="QPushButton" name="bind_zero_held">
<property name="text">
- <string>Toggle tracking</string>
- </property>
- <property name="wordWrap">
- <bool>false</bool>
+ <string>Bind</string>
</property>
</widget>
</item>
- <item row="9" column="2">
- <widget class="QPushButton" name="bind_toggle_tracking">
+ <item row="6" column="1">
+ <widget class="QLabel" name="toggle_held_text">
<property name="text">
- <string>Bind</string>
+ <string/>
</property>
</widget>
</item>
- <item row="7" column="1">
- <widget class="QLabel" name="start_tracking_text">
+ <item row="12" column="0">
+ <widget class="QLabel" name="textLabel2_10">
<property name="text">
- <string/>
+ <string>Restart tracking</string>
+ </property>
+ <property name="wordWrap">
+ <bool>false</bool>
</property>
</widget>
</item>
- <item row="8" column="1">
- <widget class="QLabel" name="stop_tracking_text">
+ <item row="12" column="1">
+ <widget class="QLabel" name="restart_tracking_text">
<property name="text">
<string/>
</property>
</widget>
</item>
- <item row="9" column="1">
- <widget class="QLabel" name="toggle_tracking_text">
+ <item row="12" column="2">
+ <widget class="QPushButton" name="bind_restart_tracking">
<property name="text">
- <string/>
+ <string>Bind</string>
</property>
</widget>
</item>
@@ -266,19 +332,6 @@
</property>
</widget>
</item>
- <item>
- <spacer name="verticalSpacer">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>40</height>
- </size>
- </property>
- </spacer>
- </item>
</layout>
</widget>
<widget class="QWidget" name="tab_3">
diff --git a/gui/ui.cpp b/gui/ui.cpp
index a136f2aa..2832126b 100755
--- a/gui/ui.cpp
+++ b/gui/ui.cpp
@@ -119,6 +119,10 @@ MainWindow::MainWindow() :
connect(this, &MainWindow::emit_toggle_tracker,
this, [&]() -> void { if (keys_paused) return; qDebug() << "toggle tracker"; if (work) stopTracker(); else startTracker(); },
Qt::QueuedConnection);
+
+ connect(this, &MainWindow::emit_restart_tracker,
+ this, [&]() -> void { if (keys_paused) return; qDebug() << "retart tracker"; stopTracker(); startTracker(); },
+ Qt::QueuedConnection);
register_shortcuts();
@@ -129,12 +133,13 @@ MainWindow::MainWindow() :
void MainWindow::register_shortcuts()
{
- using t_shortcut = std::tuple<key_opts&, Shortcuts::fun>;
+ using t_shortcut = std::tuple<key_opts&, Shortcuts::fun, bool>;
std::vector<t_shortcut> keys {
- t_shortcut(s.key_start_tracking, [&]() -> void { emit_start_tracker(); }),
- t_shortcut(s.key_stop_tracking, [&]() -> void { emit_stop_tracker(); }),
- t_shortcut(s.key_toggle_tracking, [&]() -> void { emit_toggle_tracker(); }),
+ t_shortcut(s.key_start_tracking, [&](bool) -> void { emit_start_tracker(); }, true),
+ t_shortcut(s.key_stop_tracking, [&](bool) -> void { emit_stop_tracker(); }, true),
+ t_shortcut(s.key_toggle_tracking, [&](bool) -> void { emit_toggle_tracker(); }, true),
+ t_shortcut(s.key_restart_tracking, [&](bool) -> void { emit_restart_tracker(); }, true),
};
global_shortcuts.reload(keys);
diff --git a/gui/ui.h b/gui/ui.h
index 6dbcf962..9adb69a2 100644..100755
--- a/gui/ui.h
+++ b/gui/ui.h
@@ -111,7 +111,8 @@ signals:
void emit_start_tracker();
void emit_stop_tracker();
void emit_toggle_tracker();
-
+ void emit_restart_tracker();
+
void emit_minimized(bool);
public:
MainWindow();
diff --git a/opentrack/keybinding-worker.cpp b/opentrack/keybinding-worker.cpp
index 39693a7c..2d133c2f 100644..100755
--- a/opentrack/keybinding-worker.cpp
+++ b/opentrack/keybinding-worker.cpp
@@ -126,8 +126,9 @@ void KeybindingWorker::run() {
for (int i = 0; i < 256; i++)
{
Key k;
- if (old_keystate[i] != keystate[i] && keystate[i] & 0x80)
+ if (old_keystate[i] != keystate[i])
{
+ const bool held = keystate[i] & 0x80;
switch (i)
{
case DIK_LCONTROL:
@@ -142,6 +143,7 @@ void KeybindingWorker::run() {
k.alt = !!(keystate[DIK_LALT] & 0x80) || !!(keystate[DIK_RALT] & 0x80);
k.ctrl = !!(keystate[DIK_LCONTROL] & 0x80) || !!(keystate[DIK_RCONTROL] & 0x80);
k.keycode = i;
+ k.held = held;
for (auto& r : receivers)
r->operator()(k);
diff --git a/opentrack/main-settings.hpp b/opentrack/main-settings.hpp
index 793c52f7..7c04fd6d 100644..100755
--- a/opentrack/main-settings.hpp
+++ b/opentrack/main-settings.hpp
@@ -51,8 +51,9 @@ struct main_settings : opts {
value<int> camera_yaw, camera_pitch, camera_roll;
value<bool> center_at_startup;
value<int> center_method;
- key_opts key_start_tracking, key_stop_tracking, key_toggle_tracking;
+ key_opts key_start_tracking, key_stop_tracking, key_toggle_tracking, key_restart_tracking;
key_opts key_center, key_toggle, key_zero;
+ key_opts key_toggle_press, key_zero_press;
main_settings() :
opts("opentrack-ui"),
tracker_dll(b, "tracker-dll", ""),
@@ -75,9 +76,12 @@ struct main_settings : opts {
key_start_tracking(b, "start-tracking"),
key_stop_tracking(b, "stop-tracking"),
key_toggle_tracking(b, "toggle-tracking"),
+ key_restart_tracking(b, "restart-tracking"),
key_center(b, "center"),
key_toggle(b, "toggle"),
- key_zero(b, "zero")
+ key_zero(b, "zero"),
+ key_toggle_press(b, "toggle-press"),
+ key_zero_press(b, "zero-press")
{
}
};
diff --git a/opentrack/shortcuts.cpp b/opentrack/shortcuts.cpp
index bab1283a..aa1006c4 100644..100755
--- a/opentrack/shortcuts.cpp
+++ b/opentrack/shortcuts.cpp
@@ -9,7 +9,7 @@
#include "shortcuts.h"
#include "win32-shortcuts.h"
-void Shortcuts::bind_keyboard_shortcut(K &key, const key_opts& k)
+void Shortcuts::bind_keyboard_shortcut(K &key, const key_opts& k, unused(bool, held))
{
#if !defined(_WIN32)
using sh = QxtGlobalShortcut;
@@ -56,6 +56,7 @@ void Shortcuts::bind_keyboard_shortcut(K &key, const key_opts& k)
key.alt = !!(mods & Qt::AltModifier);
key.ctrl = !!(mods & Qt::ControlModifier);
key.keycode = idx;
+ key.held = held;
}
}
#endif
@@ -72,20 +73,19 @@ void Shortcuts::receiver(const Key& k)
continue;
if (k.keycode != k_.keycode)
continue;
- if (!k.held)
- continue;
- if (!k_.should_process())
- continue;
+ if (k_.held && !k.held) continue;
if (k_.alt && !k.alt) continue;
if (k_.ctrl && !k.ctrl) continue;
if (k_.shift && !k.shift) continue;
+ if (!k_.should_process())
+ continue;
- fun();
+ fun(k.held);
}
}
#endif
-void Shortcuts::reload(const std::vector<std::tuple<key_opts&, fun> > &keys_)
+void Shortcuts::reload(const std::vector<std::tuple<key_opts&, fun, bool>> &keys_)
{
const int sz = keys_.size();
keys = std::vector<tt>();
@@ -94,10 +94,11 @@ void Shortcuts::reload(const std::vector<std::tuple<key_opts&, fun> > &keys_)
{
const auto& kk = keys_[i];
const key_opts& opts = std::get<0>(kk);
+ const bool held = std::get<2>(kk);
auto& fun = std::get<1>(kk);
K k;
- bind_keyboard_shortcut(k, opts);
- keys.push_back(std::tuple<K, Shortcuts::fun>(k, fun));
+ bind_keyboard_shortcut(k, opts, held);
+ keys.push_back(tt(k, fun, held));
#ifndef _WIN32
connect(k.get(), &QxtGlobalShortcut::activated, fun);
#endif
diff --git a/opentrack/shortcuts.h b/opentrack/shortcuts.h
index 38037923..40d41957 100644..100755
--- a/opentrack/shortcuts.h
+++ b/opentrack/shortcuts.h
@@ -26,6 +26,12 @@
# include "keybinding-worker.hpp"
#endif
+#ifdef __GNUC__
+# define unused(t, i) t __attribute__((unused)) i
+#else
+# define unused(t, i) t i
+#endif
+
using namespace options;
struct OPENTRACK_EXPORT Shortcuts : public QObject {
@@ -40,8 +46,8 @@ public:
#endif
;
- using fun = std::function<void(void)>;
- using tt = std::tuple<K, fun>;
+ using fun = std::function<void(bool)>;
+ using tt = std::tuple<K, fun, bool>;
std::vector<tt> keys;
#ifdef _WIN32
KeybindingWorker::Token key_token;
@@ -53,9 +59,9 @@ public:
#endif
{}
- void reload(const std::vector<std::tuple<key_opts &, fun> > &keys);
+ void reload(const std::vector<std::tuple<key_opts &, fun, bool>> &keys);
private:
- void bind_keyboard_shortcut(K &key, const key_opts& k);
+ void bind_keyboard_shortcut(K &key, const key_opts& k, bool held);
#ifdef _WIN32
void receiver(const Key& k);
#endif
diff --git a/opentrack/tracker.h b/opentrack/tracker.h
index 36b5cad4..079ce473 100644..100755
--- a/opentrack/tracker.h
+++ b/opentrack/tracker.h
@@ -81,6 +81,8 @@ public:
void get_raw_and_mapped_poses(double* mapped, double* raw) const;
void start() { QThread::start(); }
void toggle_enabled() { qDebug() << "toggle enabled"; enabledp = !enabledp; }
+ void set_toggle(bool value) { qDebug() << "enabled" << value; enabledp = value; }
+ void set_zero(bool value) { qDebug() << "zero" << value; zero_ = value; }
void center() { qDebug() << "toggle center"; centerp = !centerp; }
void zero() { qDebug() << "toggle zero"; zero_ = !zero_; }
};
diff --git a/opentrack/work.hpp b/opentrack/work.hpp
index 4188b937..3b65ba52 100644..100755
--- a/opentrack/work.hpp
+++ b/opentrack/work.hpp
@@ -27,9 +27,9 @@ struct Work
mem<Tracker> tracker;
mem<Shortcuts> sc;
WId handle;
- using fn = std::function<void(void)>;
- using tt = std::tuple<key_opts&, fn>;
- std::vector<std::tuple<key_opts&, fn>> keys;
+ using fn = std::function<void(bool)>;
+ using tt = std::tuple<key_opts&, fn, bool>;
+ std::vector<tt> keys;
Work(main_settings& s, Mappings& m, SelectedLibraries& libs, WId handle) :
s(s), libs(libs),
@@ -37,13 +37,15 @@ struct Work
sc(std::make_shared<Shortcuts>()),
handle(handle),
keys {
- tt(s.key_center, [&]() -> void { tracker->center(); }),
- tt(s.key_toggle, [&]() -> void { tracker->toggle_enabled(); }),
- tt(s.key_zero, [&]() -> void { tracker->zero(); }),
+ tt(s.key_center, [&](bool) -> void { tracker->center(); }, true),
+ tt(s.key_toggle, [&](bool) -> void { tracker->toggle_enabled(); }, true),
+ tt(s.key_zero, [&](bool) -> void { tracker->zero(); }, true),
+ tt(s.key_toggle_press, [&](bool x) -> void { tracker->set_toggle(!x); }, false),
+ tt(s.key_zero_press, [&](bool x) -> void { tracker->set_zero(x); }, false),
}
{
reload_shortcuts();
- tracker->start();
+ tracker->start();
}
void reload_shortcuts()