diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2015-11-11 13:44:45 +0100 | 
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2015-11-11 13:44:45 +0100 | 
| commit | 17849b12f232c89bdae16f7e179d3a92a32280ad (patch) | |
| tree | 5da1a08fd694971afe7a707069a38d1a1be2f92d /opentrack | |
| parent | c4c3e746f030e6c5e5a1f8b88762fae95d1b9225 (diff) | |
shortcuts: map joystick buttons on depress only
Some buttons like the X65 mode switch are held all the time. Prevent
them from hogging all the keybindings.
Issue: #118
Diffstat (limited to 'opentrack')
| -rw-r--r-- | opentrack/keybinding-worker.cpp | 5 | ||||
| -rw-r--r-- | opentrack/keybinding-worker.hpp | 3 | ||||
| -rw-r--r-- | opentrack/win32-joystick-shortcuts.hpp | 13 | 
3 files changed, 15 insertions, 6 deletions
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;          }  | 
