From 666460aced4885c81457b2c1758f2a8ffd6e432a Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Mon, 1 Nov 2021 06:16:29 +0200 Subject: [PATCH] lib/platform: Use std::function instead of IJob in MSWindowsDesks --- src/lib/platform/MSWindowsDesks.cpp | 9 +++------ src/lib/platform/MSWindowsDesks.h | 7 ++++--- src/lib/platform/MSWindowsScreen.cpp | 5 ++--- src/lib/platform/MSWindowsScreen.h | 2 +- src/test/integtests/platform/MSWindowsKeyStateTests.cpp | 7 +------ 5 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/lib/platform/MSWindowsDesks.cpp b/src/lib/platform/MSWindowsDesks.cpp index 848ded78..c1298cb9 100644 --- a/src/lib/platform/MSWindowsDesks.cpp +++ b/src/lib/platform/MSWindowsDesks.cpp @@ -27,7 +27,6 @@ #include "arch/win32/ArchMiscWindows.h" #include "base/Log.h" #include "base/IEventQueue.h" -#include "base/IJob.h" #include "base/TMethodEventJob.h" #include "base/TMethodJob.h" #include "base/IEventQueue.h" @@ -97,10 +96,9 @@ // MSWindowsDesks // -MSWindowsDesks::MSWindowsDesks( - bool isPrimary, bool noHooks, +MSWindowsDesks::MSWindowsDesks(bool isPrimary, bool noHooks, const IScreenSaver* screensaver, IEventQueue* events, - IJob* updateKeys, bool stopOnDeskSwitch) : + const std::function& updateKeys, bool stopOnDeskSwitch) : m_isPrimary(isPrimary), m_noHooks(noHooks), m_isOnScreen(m_isPrimary), @@ -130,7 +128,6 @@ MSWindowsDesks::~MSWindowsDesks() disable(); destroyClass(m_deskClass); destroyCursor(m_cursor); - delete m_updateKeys; } void @@ -709,7 +706,7 @@ MSWindowsDesks::deskThread(void* vdesk) } case BARRIER_MSG_SYNC_KEYS: - m_updateKeys->run(); + m_updateKeys(); break; case BARRIER_MSG_SCREENSAVER: diff --git a/src/lib/platform/MSWindowsDesks.h b/src/lib/platform/MSWindowsDesks.h index 65d93ef5..8cd7bfbe 100644 --- a/src/lib/platform/MSWindowsDesks.h +++ b/src/lib/platform/MSWindowsDesks.h @@ -26,15 +26,16 @@ #include "mt/CondVar.h" #include "mt/Mutex.h" #include "common/stdmap.h" +#include #include #define WIN32_LEAN_AND_MEAN #include + class Event; class EventQueueTimer; class Thread; -class IJob; class IScreenSaver; class IEventQueue; @@ -68,7 +69,7 @@ public: MSWindowsDesks( bool isPrimary, bool noHooks, const IScreenSaver* screensaver, IEventQueue* events, - IJob* updateKeys, bool stopOnDeskSwitch); + const std::function& updateKeys, bool stopOnDeskSwitch); ~MSWindowsDesks(); //! @name manipulators @@ -284,7 +285,7 @@ private: Desks m_desks; // keyboard stuff - IJob* m_updateKeys; + std::function m_updateKeys; HKL m_keyLayout; // options diff --git a/src/lib/platform/MSWindowsScreen.cpp b/src/lib/platform/MSWindowsScreen.cpp index 2449ba7c..1714d45a 100644 --- a/src/lib/platform/MSWindowsScreen.cpp +++ b/src/lib/platform/MSWindowsScreen.cpp @@ -134,8 +134,7 @@ MSWindowsScreen::MSWindowsScreen( m_noHooks, m_screensaver, m_events, - new TMethodJob( - this, &MSWindowsScreen::updateKeysCB), + [this]() { updateKeysCB(); }, stopOnDeskSwitch); m_keyState = new MSWindowsKeyState(m_desks, getEventTarget(), m_events); @@ -1713,7 +1712,7 @@ MSWindowsScreen::mapPressFromEvent(WPARAM msg, LPARAM) const } void -MSWindowsScreen::updateKeysCB(void*) +MSWindowsScreen::updateKeysCB() { // record which keys we think are down bool down[IKeyState::kNumButtons]; diff --git a/src/lib/platform/MSWindowsScreen.h b/src/lib/platform/MSWindowsScreen.h index ae53f1ad..b89e8bae 100644 --- a/src/lib/platform/MSWindowsScreen.h +++ b/src/lib/platform/MSWindowsScreen.h @@ -199,7 +199,7 @@ private: // HACK bool mapPressFromEvent(WPARAM msg, LPARAM button) const; // job to update the key state - void updateKeysCB(void*); + void updateKeysCB(); // determine whether the mouse is hidden by the system and force // it to be displayed if user has entered this secondary screen. diff --git a/src/test/integtests/platform/MSWindowsKeyStateTests.cpp b/src/test/integtests/platform/MSWindowsKeyStateTests.cpp index 79935d89..5af3e89d 100644 --- a/src/test/integtests/platform/MSWindowsKeyStateTests.cpp +++ b/src/test/integtests/platform/MSWindowsKeyStateTests.cpp @@ -50,10 +50,7 @@ protected: MSWindowsDesks* newDesks(IEventQueue* eventQueue) { - return new MSWindowsDesks( - true, false, m_screensaver, eventQueue, - new TMethodJob( - this, &MSWindowsKeyStateTests::updateKeysCB), false); + return new MSWindowsDesks(true, false, m_screensaver, eventQueue, [](){}, false); } void* getEventTarget() const @@ -62,9 +59,7 @@ protected: } private: - void updateKeysCB(void*) { } IScreenSaver* m_screensaver; - MSWindowsHook m_hook; }; TEST_F(MSWindowsKeyStateTests, disable_eventQueueNotUsed)