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 "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<void()>& 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:

View File

@ -26,15 +26,16 @@
#include "mt/CondVar.h"
#include "mt/Mutex.h"
#include "common/stdmap.h"
#include <functional>
#include <string>
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
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<void()>& updateKeys, bool stopOnDeskSwitch);
~MSWindowsDesks();
//! @name manipulators
@ -284,7 +285,7 @@ private:
Desks m_desks;
// keyboard stuff
IJob* m_updateKeys;
std::function<void()> m_updateKeys;
HKL m_keyLayout;
// options

View File

@ -134,8 +134,7 @@ MSWindowsScreen::MSWindowsScreen(
m_noHooks,
m_screensaver,
m_events,
new TMethodJob<MSWindowsScreen>(
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];

View File

@ -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.

View File

@ -50,10 +50,7 @@ protected:
MSWindowsDesks* newDesks(IEventQueue* eventQueue)
{
return new MSWindowsDesks(
true, false, m_screensaver, eventQueue,
new TMethodJob<MSWindowsKeyStateTests>(
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)