diff options
| author | Léo Lam <leo@leolam.fr> | 2021-07-13 03:29:49 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-13 03:29:49 +0200 |
| commit | 162af2a7bbdc78a6cd49aad0eb17a5846f03e87e (patch) | |
| tree | f2009678340a2ac5b12c84897765d5ebf35ee2b5 /Source/Core/InputCommon/ControllerInterface | |
| parent | b09347c16040b4aebe224fc82753da92c49b2731 (diff) | |
| parent | 8c728945fba74caa62d7ee81b523074c16300719 (diff) | |
Merge pull request #9870 from OatmealDome/ui-thread
macOS: Move UI API calls to 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) |
