summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gui/keyboard.h4
-rw-r--r--gui/options-dialog.cpp13
-rw-r--r--opentrack/keybinding-worker.cpp5
-rw-r--r--opentrack/keybinding-worker.hpp3
-rw-r--r--opentrack/win32-joystick-shortcuts.hpp13
5 files changed, 25 insertions, 13 deletions
diff --git a/gui/keyboard.h b/gui/keyboard.h
index aa4b4a24..b840bc78 100644
--- a/gui/keyboard.h
+++ b/gui/keyboard.h
@@ -22,7 +22,7 @@ public:
{
if(k.guid != "")
{
- joystick_button_pressed(k.guid, k.keycode);
+ joystick_button_pressed(k.guid, k.keycode, k.held);
}
else
{
@@ -54,5 +54,5 @@ public:
#endif
signals:
void key_pressed(QKeySequence k);
- void joystick_button_pressed(QString guid, int idx);
+ void joystick_button_pressed(QString guid, int idx, bool held);
};
diff --git a/gui/options-dialog.cpp b/gui/options-dialog.cpp
index c8bf668d..4cff6e77 100644
--- a/gui/options-dialog.cpp
+++ b/gui/options-dialog.cpp
@@ -90,11 +90,14 @@ void OptionsDialog::bind_key(Shortcuts::key_opts& kopts, QLabel* label)
kopts.button = -1;
d.close();
});
- connect(k, &KeyboardListener::joystick_button_pressed, [&](QString guid, int idx) -> void {
- kopts.guid = guid;
- kopts.keycode = "";
- kopts.button = idx;
- d.close();
+ connect(k, &KeyboardListener::joystick_button_pressed, [&](QString guid, int idx, bool held) -> void {
+ if (!held)
+ {
+ kopts.guid = guid;
+ kopts.keycode = "";
+ kopts.button = idx;
+ d.close();
+ }
});
d.exec();
label->setText(kopts_to_string(kopts));
diff --git a/opentrack/keybinding-worker.cpp b/opentrack/keybinding-worker.cpp
index e6c023ef..e9255801 100644
--- a/opentrack/keybinding-worker.cpp
+++ b/opentrack/keybinding-worker.cpp
@@ -73,12 +73,13 @@ void KeybindingWorker::run() {
while (!should_quit)
{
{
- using joy_fn = std::function<void(const QString& guid, int idx)>;
+ using joy_fn = std::function<void(const QString& guid, int idx, bool held)>;
- joy_fn f = [&](const QString& guid, int idx) -> void {
+ joy_fn f = [&](const QString& guid, int idx, bool held) -> void {
Key k;
k.keycode = idx;
k.guid = guid;
+ k.held = held;
receiver(k);
};
diff --git a/opentrack/keybinding-worker.hpp b/opentrack/keybinding-worker.hpp
index 8cf59d65..cb3e5f9f 100644
--- a/opentrack/keybinding-worker.hpp
+++ b/opentrack/keybinding-worker.hpp
@@ -32,9 +32,10 @@ struct Key {
bool shift;
bool ctrl;
bool alt;
+ bool held;
Timer timer;
public:
- Key() : keycode(0), shift(false), ctrl(false), alt(false)
+ Key() : keycode(0), shift(false), ctrl(false), alt(false), held(true)
{
}
diff --git a/opentrack/win32-joystick-shortcuts.hpp b/opentrack/win32-joystick-shortcuts.hpp
index 67465bce..3c839197 100644
--- a/opentrack/win32-joystick-shortcuts.hpp
+++ b/opentrack/win32-joystick-shortcuts.hpp
@@ -16,7 +16,7 @@
struct win32_joy_ctx
{
- using fn = std::function<void(const QString& guid, int btn)>;
+ using fn = std::function<void(const QString& guid, int btn, bool held)>;
void poll(fn f)
{
@@ -32,10 +32,13 @@ struct win32_joy_ctx
{
LPDIRECTINPUTDEVICE8 joy_handle;
QString guid;
+ bool pressed[128];
joy(LPDIRECTINPUTDEVICE8 handle, const QString& guid) : joy_handle(handle), guid(guid)
{
qDebug() << "got joy" << guid;
+ for (int i = 0; i < 128; i++)
+ pressed[i] = false;
}
~joy()
@@ -88,8 +91,12 @@ struct win32_joy_ctx
}
for (int i = 0; i < 128; i++)
- if (js.rgbButtons[i] & 0x80)
- f(guid, i);
+ {
+ const bool state = !!(js.rgbButtons[i] & 0x80);
+ if (state != pressed[i])
+ f(guid, i, state);
+ pressed[i] = state;
+ }
return true;
}