QuartzKeyboardAndMouse: Ensure windowNumber is fetched on the main thread

This commit is contained in:
OatmealDome 2021-07-06 04:46:27 -04:00
parent ffdc8538a1
commit 1bb72f00b5
2 changed files with 16 additions and 3 deletions

View File

@ -58,7 +58,7 @@ private:
public: public:
void UpdateInput() override; void UpdateInput() override;
explicit KeyboardAndMouse(void* window); explicit KeyboardAndMouse(void* view);
std::string GetName() const override; std::string GetName() const override;
std::string GetSource() const override; std::string GetSource() const override;

View File

@ -135,7 +135,7 @@ std::string KeyboardAndMouse::Key::GetName() const
return m_name; return m_name;
} }
KeyboardAndMouse::KeyboardAndMouse(void* window) KeyboardAndMouse::KeyboardAndMouse(void* view)
{ {
// All keycodes in <HIToolbox/Events.h> are 0x7e or lower. If you notice // All keycodes in <HIToolbox/Events.h> are 0x7e or lower. If you notice
// keys that aren't being recognized, bump this number up! // keys that aren't being recognized, bump this number up!
@ -147,7 +147,20 @@ KeyboardAndMouse::KeyboardAndMouse(void* window)
AddCombinedInput("Shift", {"Left Shift", "Right Shift"}); AddCombinedInput("Shift", {"Left Shift", "Right Shift"});
AddCombinedInput("Ctrl", {"Left Control", "Right Control"}); AddCombinedInput("Ctrl", {"Left Control", "Right Control"});
m_windowid = [[reinterpret_cast<NSView*>(window) window] windowNumber]; NSView* cocoa_view = reinterpret_cast<NSView*>(view);
// PopulateDevices may be called on the Emuthread, so we need to ensure that
// these UI APIs are only ever called on the main thread.
if ([NSThread isMainThread])
{
m_windowid = [[cocoa_view window] windowNumber];
}
else
{
dispatch_sync(dispatch_get_main_queue(), ^{
m_windowid = [[cocoa_view window] windowNumber];
});
}
// cursor, with a hax for-loop // cursor, with a hax for-loop
for (unsigned int i = 0; i < 4; ++i) for (unsigned int i = 0; i < 4; ++i)