summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--opentrack/keybinding-worker.cpp1
-rw-r--r--opentrack/win32-joystick.cpp25
-rw-r--r--opentrack/win32-joystick.hpp8
3 files changed, 10 insertions, 24 deletions
diff --git a/opentrack/keybinding-worker.cpp b/opentrack/keybinding-worker.cpp
index b0cef22d..39693a7c 100644
--- a/opentrack/keybinding-worker.cpp
+++ b/opentrack/keybinding-worker.cpp
@@ -164,6 +164,7 @@ KeybindingWorker::fun* KeybindingWorker::_add_receiver(fun& receiver)
receivers.push_back(std::unique_ptr<fun>(new fun(receiver)));
fun* f = receivers[receivers.size() - 1].get();
qDebug() << "add receiver" << (long) f;
+ joy_ctx.refresh();
return f;
}
diff --git a/opentrack/win32-joystick.cpp b/opentrack/win32-joystick.cpp
index 728e2f68..5e6f2011 100644
--- a/opentrack/win32-joystick.cpp
+++ b/opentrack/win32-joystick.cpp
@@ -6,7 +6,7 @@
void win32_joy_ctx::poll(fn f)
{
- refresh(false);
+ //refresh(false);
QMutexLocker l(&mtx);
@@ -94,7 +94,7 @@ win32_joy_ctx::win32_joy_ctx()
qDebug() << "setup DirectInput8 Creation failed!" << GetLastError();
assert(!"direct input handle can't be created");
}
- refresh(true);
+ refresh();
}
void win32_joy_ctx::release()
@@ -104,18 +104,12 @@ void win32_joy_ctx::release()
di = nullptr;
}
-void win32_joy_ctx::refresh(bool first)
+void win32_joy_ctx::refresh()
{
- if (!first)
- {
- // accessing struct Timer without a lock. worst can happen is seconds
- // and nanoseconds getting out of sync. no big deal.
- if (timer_joylist.elapsed_ms() < joylist_refresh_ms)
- return;
- timer_joylist.start();
- }
+ QMutexLocker l(&mtx);
- enum_state st(joys, mtx, fake_main_window, di);
+ qDebug() << "joy list refresh";
+ enum_state st(joys, fake_main_window, di);
}
QString win32_joy_ctx::guid_to_string(const GUID guid)
@@ -184,16 +178,12 @@ bool win32_joy_ctx::joy::poll(fn f)
}
win32_joy_ctx::enum_state::enum_state(std::unordered_map<QString, std::shared_ptr<joy>> &joys,
- QMutex& mtx,
QMainWindow &fake_main_window,
LPDIRECTINPUT8 di) :
fake_main_window(fake_main_window),
di(di)
{
- {
- QMutexLocker l(&mtx);
- this->joys = joys;
- }
+ this->joys = joys;
HRESULT hr;
@@ -216,7 +206,6 @@ win32_joy_ctx::enum_state::enum_state(std::unordered_map<QString, std::shared_pt
it++;
}
- QMutexLocker l(&mtx);
joys = this->joys;
}
diff --git a/opentrack/win32-joystick.hpp b/opentrack/win32-joystick.hpp
index 6d5e1074..9c888326 100644
--- a/opentrack/win32-joystick.hpp
+++ b/opentrack/win32-joystick.hpp
@@ -57,18 +57,14 @@ struct OPENTRACK_EXPORT win32_joy_ctx
win32_joy_ctx();
~win32_joy_ctx();
-
+ void refresh();
private:
- enum { joylist_refresh_ms = 100 };
-
QMutex mtx;
- Timer timer_joylist;
QMainWindow fake_main_window;
LPDIRECTINPUT8 di;
static QString guid_to_string(const GUID guid);
void release();
- void refresh(bool first);
struct joy
{
@@ -97,7 +93,7 @@ private:
static BOOL CALLBACK EnumJoysticksCallback(const DIDEVICEINSTANCE* pdidInstance, VOID* pContext);
static BOOL CALLBACK EnumObjectsCallback(const DIDEVICEOBJECTINSTANCE* pdidoi, VOID* ctx);
public:
- enum_state(std::unordered_map<QString, std::shared_ptr<joy>>& joys, QMutex &mtx, QMainWindow& fake_main_window, LPDIRECTINPUT8 di);
+ enum_state(std::unordered_map<QString, std::shared_ptr<joy>>& joys, QMainWindow& fake_main_window, LPDIRECTINPUT8 di);
};
};