summaryrefslogtreecommitdiffhomepage
path: root/opentrack
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2015-11-22 18:05:04 +0100
committerStanislaw Halik <sthalik@misaki.pl>2015-11-22 18:05:04 +0100
commite2ea45a81d5f30fdbd42e0b03a192afa81e877dc (patch)
treefc5334a9ecf3fcba8671ea2e8330460fcc2c82c8 /opentrack
parent5d4a9c78fbbbd59d366e91bfe4c4263d12833abe (diff)
api/shortcuts: don't provide guard/stubs for non-win32
The worker class is win32-only. Don't guard there, consumers are expected only to include it on _WIN32. For the same reason don't provide a stub for the keybinding worker.
Diffstat (limited to 'opentrack')
-rw-r--r--opentrack/keybinding-worker.cpp29
-rw-r--r--opentrack/keybinding-worker.hpp20
2 files changed, 19 insertions, 30 deletions
diff --git a/opentrack/keybinding-worker.cpp b/opentrack/keybinding-worker.cpp
index 3659a768..dcf5c1b6 100644
--- a/opentrack/keybinding-worker.cpp
+++ b/opentrack/keybinding-worker.cpp
@@ -6,10 +6,9 @@
* notice appear in all copies.
*/
-#include "keybinding-worker.hpp"
-
-#if defined(_WIN32)
+#ifdef _WIN32
+#include "keybinding-worker.hpp"
#include <functional>
#include <windows.h>
#include <QDebug>
@@ -29,7 +28,7 @@ KeybindingWorker::~KeybindingWorker() {
KeybindingWorker::KeybindingWorker() :
#ifdef _WIN32
- joy_ctx(win32_joy_ctx::make()),
+ joy_ctx(win32_joy_ctx::make()),
#endif
should_quit(true)
{
@@ -85,23 +84,23 @@ void KeybindingWorker::run() {
{
{
QMutexLocker l(&mtx);
-
+
if (receivers.size())
{
{
const HRESULT hr = dinkeyboard->GetDeviceState(256, (LPVOID)keystate);
-
+
if (hr != DI_OK) {
qDebug() << "Tracker::run GetDeviceState function failed!" << GetLastError();
Sleep(25);
continue;
}
}
-
+
#ifdef _WIN32
{
using joy_fn = std::function<void(const QString& guid, int idx, bool held)>;
-
+
joy_fn f = [&](const QString& guid, int idx, bool held) -> void {
Key k;
k.keycode = idx;
@@ -110,15 +109,15 @@ void KeybindingWorker::run() {
k.ctrl = !!(keystate[DIK_LCONTROL] & 0x80 || keystate[DIK_RCONTROL] & 0x80);
k.guid = guid;
k.held = held;
-
+
for (auto& r : receivers)
r(k);
};
-
+
joy_ctx.poll(f);
}
#endif
-
+
for (int i = 0; i < 256; i++)
{
Key k;
@@ -138,7 +137,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;
-
+
for (auto& r : receivers)
r(k);
break;
@@ -147,7 +146,7 @@ void KeybindingWorker::run() {
}
}
}
-
+
// keypresses get dropped with high values
Sleep(4);
}
@@ -165,7 +164,7 @@ void KeybindingWorker::remove_receiver(KeybindingWorker::fun* pos)
{
QMutexLocker l(&mtx);
bool ok = false;
-
+
for (int i = receivers.size() - 1; i >= 0; i--)
{
if (&receivers[i] == pos)
@@ -181,4 +180,4 @@ void KeybindingWorker::remove_receiver(KeybindingWorker::fun* pos)
}
}
-#endif \ No newline at end of file
+#endif
diff --git a/opentrack/keybinding-worker.hpp b/opentrack/keybinding-worker.hpp
index 83ffadf1..e3967682 100644
--- a/opentrack/keybinding-worker.hpp
+++ b/opentrack/keybinding-worker.hpp
@@ -15,20 +15,17 @@
#endif
#include "opentrack-compat/timer.hpp"
-#ifdef _WIN32
-# include "opentrack/win32-joystick.hpp"
-#endif
+#include "opentrack/win32-joystick.hpp"
#include <QThread>
#include <QMutex>
#include <QWidget>
#include <functional>
#include <vector>
-#ifdef _WIN32
-# undef DIRECTINPUT_VERSION
-# define DIRECTINPUT_VERSION 0x0800
-# include <windows.h>
-# include <dinput.h>
+#undef DIRECTINPUT_VERSION
+#define DIRECTINPUT_VERSION 0x0800
+#include <windows.h>
+#include <dinput.h>
struct Key {
BYTE keycode;
QString guid;
@@ -51,15 +48,10 @@ public:
return ret;
}
};
-#else
-typedef unsigned char BYTE;
-struct Key { int foo; };
-#endif
struct OPENTRACK_EXPORT KeybindingWorker : private QThread
{
private:
-#ifdef _WIN32
LPDIRECTINPUT8 din;
LPDIRECTINPUTDEVICE8 dinkeyboard;
win32_joy_ctx& joy_ctx;
@@ -99,7 +91,5 @@ public:
{
return Token(receiver);
}
-#else
void run() override {}
-#endif
};