diff options
| author | OatmealDome <julian@oatmealdome.me> | 2021-07-06 04:46:27 -0400 |
|---|---|---|
| committer | OatmealDome <julian@oatmealdome.me> | 2021-07-06 04:46:27 -0400 |
| commit | 1bb72f00b5216869c7346a4fda61047d4abb244c (patch) | |
| tree | d2aecd72b76ac1e715c844f2f146854ab3fd7b9c /Source/Core/InputCommon/ControllerInterface | |
| parent | ffdc8538a162b1ca56e3943c5a78c02358053b2a (diff) | |
QuartzKeyboardAndMouse: Ensure windowNumber is fetched on the main thread
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface')
| -rw-r--r-- | Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.h | 2 | ||||
| -rw-r--r-- | Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm | 17 |
2 files changed, 16 insertions, 3 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.h b/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.h index aee721f9d9..dfcf216e45 100644 --- a/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.h +++ b/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.h @@ -58,7 +58,7 @@ private: public: void UpdateInput() override; - explicit KeyboardAndMouse(void* window); + explicit KeyboardAndMouse(void* view); std::string GetName() const override; std::string GetSource() const override; diff --git a/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm b/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm index 1d55b07795..7aae59bf95 100644 --- a/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm +++ b/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm @@ -135,7 +135,7 @@ std::string KeyboardAndMouse::Key::GetName() const return m_name; } -KeyboardAndMouse::KeyboardAndMouse(void* window) +KeyboardAndMouse::KeyboardAndMouse(void* view) { // All keycodes in <HIToolbox/Events.h> are 0x7e or lower. If you notice // 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("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 for (unsigned int i = 0; i < 4; ++i) |
