lib/platform: Use std::function instead of IJob in MSWindowsDesks

This commit is contained in:
Povilas Kanapickas 2021-11-01 06:16:29 +02:00
parent 4486830fdb
commit 666460aced
5 changed files with 11 additions and 19 deletions

View File

@ -27,7 +27,6 @@
#include "arch/win32/ArchMiscWindows.h" #include "arch/win32/ArchMiscWindows.h"
#include "base/Log.h" #include "base/Log.h"
#include "base/IEventQueue.h" #include "base/IEventQueue.h"
#include "base/IJob.h"
#include "base/TMethodEventJob.h" #include "base/TMethodEventJob.h"
#include "base/TMethodJob.h" #include "base/TMethodJob.h"
#include "base/IEventQueue.h" #include "base/IEventQueue.h"
@ -97,10 +96,9 @@
// MSWindowsDesks // MSWindowsDesks
// //
MSWindowsDesks::MSWindowsDesks( MSWindowsDesks::MSWindowsDesks(bool isPrimary, bool noHooks,
bool isPrimary, bool noHooks,
const IScreenSaver* screensaver, IEventQueue* events, const IScreenSaver* screensaver, IEventQueue* events,
IJob* updateKeys, bool stopOnDeskSwitch) : const std::function<void()>& updateKeys, bool stopOnDeskSwitch) :
m_isPrimary(isPrimary), m_isPrimary(isPrimary),
m_noHooks(noHooks), m_noHooks(noHooks),
m_isOnScreen(m_isPrimary), m_isOnScreen(m_isPrimary),
@ -130,7 +128,6 @@ MSWindowsDesks::~MSWindowsDesks()
disable(); disable();
destroyClass(m_deskClass); destroyClass(m_deskClass);
destroyCursor(m_cursor); destroyCursor(m_cursor);
delete m_updateKeys;
} }
void void
@ -709,7 +706,7 @@ MSWindowsDesks::deskThread(void* vdesk)
} }
case BARRIER_MSG_SYNC_KEYS: case BARRIER_MSG_SYNC_KEYS:
m_updateKeys->run(); m_updateKeys();
break; break;
case BARRIER_MSG_SCREENSAVER: case BARRIER_MSG_SCREENSAVER:

View File

@ -26,15 +26,16 @@
#include "mt/CondVar.h" #include "mt/CondVar.h"
#include "mt/Mutex.h" #include "mt/Mutex.h"
#include "common/stdmap.h" #include "common/stdmap.h"
#include <functional>
#include <string> #include <string>
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <Windows.h> #include <Windows.h>
class Event; class Event;
class EventQueueTimer; class EventQueueTimer;
class Thread; class Thread;
class IJob;
class IScreenSaver; class IScreenSaver;
class IEventQueue; class IEventQueue;
@ -68,7 +69,7 @@ public:
MSWindowsDesks( MSWindowsDesks(
bool isPrimary, bool noHooks, bool isPrimary, bool noHooks,
const IScreenSaver* screensaver, IEventQueue* events, const IScreenSaver* screensaver, IEventQueue* events,
IJob* updateKeys, bool stopOnDeskSwitch); const std::function<void()>& updateKeys, bool stopOnDeskSwitch);
~MSWindowsDesks(); ~MSWindowsDesks();
//! @name manipulators //! @name manipulators
@ -284,7 +285,7 @@ private:
Desks m_desks; Desks m_desks;
// keyboard stuff // keyboard stuff
IJob* m_updateKeys; std::function<void()> m_updateKeys;
HKL m_keyLayout; HKL m_keyLayout;
// options // options

View File

@ -134,8 +134,7 @@ MSWindowsScreen::MSWindowsScreen(
m_noHooks, m_noHooks,
m_screensaver, m_screensaver,
m_events, m_events,
new TMethodJob<MSWindowsScreen>( [this]() { updateKeysCB(); },
this, &MSWindowsScreen::updateKeysCB),
stopOnDeskSwitch); stopOnDeskSwitch);
m_keyState = new MSWindowsKeyState(m_desks, getEventTarget(), m_events); m_keyState = new MSWindowsKeyState(m_desks, getEventTarget(), m_events);
@ -1713,7 +1712,7 @@ MSWindowsScreen::mapPressFromEvent(WPARAM msg, LPARAM) const
} }
void void
MSWindowsScreen::updateKeysCB(void*) MSWindowsScreen::updateKeysCB()
{ {
// record which keys we think are down // record which keys we think are down
bool down[IKeyState::kNumButtons]; bool down[IKeyState::kNumButtons];

View File

@ -199,7 +199,7 @@ private: // HACK
bool mapPressFromEvent(WPARAM msg, LPARAM button) const; bool mapPressFromEvent(WPARAM msg, LPARAM button) const;
// job to update the key state // job to update the key state
void updateKeysCB(void*); void updateKeysCB();
// determine whether the mouse is hidden by the system and force // determine whether the mouse is hidden by the system and force
// it to be displayed if user has entered this secondary screen. // it to be displayed if user has entered this secondary screen.

View File

@ -50,10 +50,7 @@ protected:
MSWindowsDesks* newDesks(IEventQueue* eventQueue) MSWindowsDesks* newDesks(IEventQueue* eventQueue)
{ {
return new MSWindowsDesks( return new MSWindowsDesks(true, false, m_screensaver, eventQueue, [](){}, false);
true, false, m_screensaver, eventQueue,
new TMethodJob<MSWindowsKeyStateTests>(
this, &MSWindowsKeyStateTests::updateKeysCB), false);
} }
void* getEventTarget() const void* getEventTarget() const
@ -62,9 +59,7 @@ protected:
} }
private: private:
void updateKeysCB(void*) { }
IScreenSaver* m_screensaver; IScreenSaver* m_screensaver;
MSWindowsHook m_hook;
}; };
TEST_F(MSWindowsKeyStateTests, disable_eventQueueNotUsed) TEST_F(MSWindowsKeyStateTests, disable_eventQueueNotUsed)