summaryrefslogtreecommitdiffhomepage
path: root/opentrack
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2014-10-20 09:33:56 +0200
committerStanislaw Halik <sthalik@misaki.pl>2014-10-20 09:33:56 +0200
commitba0cd4a1fd743a7d0d025ca76c211c8f466e6879 (patch)
tree2bbd5f1939a7413e76cbe782e3da7b7c844cea8c /opentrack
parent7f0d0d1b9ef7711a4f1835b0120f014799b71e90 (diff)
refactor 2/n
Diffstat (limited to 'opentrack')
-rw-r--r--opentrack/shortcuts.cpp17
-rw-r--r--opentrack/shortcuts.h36
-rw-r--r--opentrack/work.hpp9
3 files changed, 30 insertions, 32 deletions
diff --git a/opentrack/shortcuts.cpp b/opentrack/shortcuts.cpp
index 18a3a312..0a3d7e0d 100644
--- a/opentrack/shortcuts.cpp
+++ b/opentrack/shortcuts.cpp
@@ -37,7 +37,7 @@ void KeyboardShortcutDialog::doCancel() {
#if defined(_WIN32)
#include <windows.h>
-KeybindingWorkerImpl::~KeybindingWorkerImpl() {
+KeybindingWorker::~KeybindingWorker() {
should_quit = true;
wait();
if (dinkeyboard) {
@@ -48,8 +48,8 @@ KeybindingWorkerImpl::~KeybindingWorkerImpl() {
din->Release();
}
-KeybindingWorkerImpl::KeybindingWorkerImpl(Key keyCenter, Key keyToggle)
-: din(0), dinkeyboard(0), kCenter(keyCenter), kToggle(keyToggle), window(w), should_quit(true)
+KeybindingWorker::KeybindingWorker(Key keyCenter, Key keyToggle, WId handle) :
+ din(0), dinkeyboard(0), kCenter(keyCenter), kToggle(keyToggle), should_quit(true)
{
if (DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&din, NULL) != DI_OK) {
qDebug() << "setup DirectInput8 Creation failed!" << GetLastError();
@@ -69,8 +69,7 @@ KeybindingWorkerImpl::KeybindingWorkerImpl(Key keyCenter, Key keyToggle)
din = 0;
return;
}
-
- if (dinkeyboard->SetCooperativeLevel((HWND) window.winId(), DISCL_NONEXCLUSIVE | DISCL_BACKGROUND) != DI_OK) {
+ if (dinkeyboard->SetCooperativeLevel((HWND) handle, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND) != DI_OK) {
dinkeyboard->Release();
din->Release();
din = 0;
@@ -111,9 +110,9 @@ static bool isKeyPressed( const Key *key, const BYTE *keystate ) {
#define PROCESS_KEY(k, s) \
if (isKeyPressed(&k, keystate) && (!k.ever_pressed ? (k.timer.start(), k.ever_pressed = true) : k.timer.restart() > 100)) \
- window.s();
+ emit s;
-void KeybindingWorkerImpl::run() {
+void KeybindingWorker::run() {
BYTE keystate[256];
while (!should_quit)
{
@@ -123,8 +122,8 @@ void KeybindingWorkerImpl::run() {
continue;
}
- PROCESS_KEY(kCenter, shortcutRecentered);
- PROCESS_KEY(kToggle, shortcutToggled);
+ PROCESS_KEY(kCenter, center());
+ PROCESS_KEY(kToggle, toggle());
Sleep(25);
}
diff --git a/opentrack/shortcuts.h b/opentrack/shortcuts.h
index 2962f4fd..54305a52 100644
--- a/opentrack/shortcuts.h
+++ b/opentrack/shortcuts.h
@@ -51,8 +51,9 @@ typedef unsigned char BYTE;
struct Key { int foo; };
#endif
-#if defined(_WIN32)
-class KeybindingWorkerImpl {
+struct KeybindingWorker : public QThread {
+ Q_OBJECT
+#ifdef _WIN32
private:
LPDIRECTINPUT8 din;
LPDIRECTINPUTDEVICE8 dinkeyboard;
@@ -60,26 +61,17 @@ private:
Key kToggle;
public:
volatile bool should_quit;
- ~KeybindingWorkerImpl();
- KeybindingWorkerImpl(Key keyCenter, Key keyToggle);
+ ~KeybindingWorker();
+ KeybindingWorker(Key keyCenter, Key keyToggle, WId handle);
void run();
-};
#else
-class KeybindingWorkerImpl {
public:
- KeybindingWorkerImpl(Key keyCenter, Key keyToggle);
+ KeybindingWorker(Key, Key, WId) {}
void run() {}
-};
#endif
-
-template<typename t_self>
-struct KeybindingWorker : public QThread, public KeybindingWorkerImpl {
- KeybindingWorker(Key keyCenter, Key keyToggle) : KeybindingWorkerImpl(keyCenter, keyToggle)
- {
- }
- void run() {
- KeybindingWorkerImpl::run();
- }
+signals:
+ void center();
+ void toggle();
};
@@ -108,14 +100,18 @@ struct Shortcuts {
{}
} s;
- Shortcuts()
+#ifdef _WIN32
+ Shortcuts(WId handle)
+#else
+ Shortcuts(WId)
+#endif
{
bind_keyboard_shortcut(keyCenter, s.center);
bind_keyboard_shortcut(keyToggle, s.toggle);
#ifdef _WIN32
keybindingWorker = nullptr;
- keybindingWorker = std::make_shared<KeybindingWorker>(*this, keyCenter, keyToggle);
- keybindingWorker.start();
+ keybindingWorker = std::make_shared<KeybindingWorker>(keyCenter, keyToggle, handle);
+ keybindingWorker->start();
#endif
}
private:
diff --git a/opentrack/work.hpp b/opentrack/work.hpp
index bd69f7ba..c0962b9a 100644
--- a/opentrack/work.hpp
+++ b/opentrack/work.hpp
@@ -16,14 +16,17 @@ struct Work
ptr<Tracker> tracker;
ptr<Shortcuts> sc;
- Work(main_settings& s, Mappings& m, SelectedLibraries& libs, QObject* recv) :
+ Work(main_settings& s, Mappings& m, SelectedLibraries& libs, QObject* recv, WId handle) :
s(s), libs(libs),
tracker(std::make_shared<Tracker>(s, m, libs)),
- sc(std::make_shared<Shortcuts>())
+ sc(std::make_shared<Shortcuts>(handle))
{
#ifndef _WIN32
QObject::connect(&sc->keyCenter, SIGNAL(activated()), recv, SLOT(shortcutRecentered()));
QObject::connect(&sc->keyToggle, 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()));
#endif
tracker->start();
}
@@ -34,4 +37,4 @@ struct Work
tracker = nullptr;
libs = SelectedLibraries();
}
-}; \ No newline at end of file
+};