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 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(window) window] windowNumber]; + NSView* cocoa_view = reinterpret_cast(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)