diff options
| author | Admiral H. Curtiss <pikachu025@gmail.com> | 2022-07-26 12:52:33 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-26 12:52:33 +0200 |
| commit | 9d15a1c5a1e6183a0e98165ac093e74ca8e4894e (patch) | |
| tree | bb9806ee563adf38a74e55506f1e387e0bd08b72 /Source/Core/InputCommon/ControllerInterface/Quartz | |
| parent | c7752f80e4803362c58c03e0510680e95f4061c6 (diff) | |
| parent | d14bd10cd74ecfb9777e19dde842fe64d7681605 (diff) | |
Merge pull request #10858 from AdmiralCurtiss/mouse-center-hotkey
Add hotkey for centering mouse in render window.
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface/Quartz')
| -rw-r--r-- | Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm b/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm index 6b1790149b..b8ae0219be 100644 --- a/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm +++ b/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm @@ -8,6 +8,8 @@ #include <Carbon/Carbon.h> #include <Cocoa/Cocoa.h> +#include "Core/Host.h" + #include "InputCommon/ControllerInterface/ControllerInterface.h" namespace ciface::Quartz @@ -192,16 +194,36 @@ void KeyboardAndMouse::UpdateInput() CFRelease(windowDescriptions); CFRelease(windowArray); - CGEventRef event = CGEventCreate(nil); - CGPoint loc = CGEventGetLocation(event); - CFRelease(event); + const double window_width = std::max(bounds.size.width, 1.0); + const double window_height = std::max(bounds.size.height, 1.0); + + if (g_controller_interface.IsMouseCenteringRequested() && Host_RendererHasFocus()) + { + m_cursor.x = 0; + m_cursor.y = 0; - const auto window_scale = g_controller_interface.GetWindowInputScale(); + const CGPoint window_center_global_coordinates = + CGPointMake(bounds.origin.x + window_width / 2.0, bounds.origin.y + window_height / 2.0); + CGWarpMouseCursorPosition(window_center_global_coordinates); + // Without this line there is a short but obvious delay after centering the cursor before it can + // be moved again + CGAssociateMouseAndMouseCursorPosition(true); - loc.x -= bounds.origin.x; - loc.y -= bounds.origin.y; - m_cursor.x = (loc.x / std::max(bounds.size.width, 1.0) * 2 - 1.0) * window_scale.x; - m_cursor.y = (loc.y / std::max(bounds.size.height, 1.0) * 2 - 1.0) * window_scale.y; + g_controller_interface.SetMouseCenteringRequested(false); + } + else + { + CGEventRef event = CGEventCreate(nil); + CGPoint loc = CGEventGetLocation(event); + CFRelease(event); + + const auto window_scale = g_controller_interface.GetWindowInputScale(); + + loc.x -= bounds.origin.x; + loc.y -= bounds.origin.y; + m_cursor.x = (loc.x / window_width * 2 - 1.0) * window_scale.x; + m_cursor.y = (loc.y / window_height * 2 - 1.0) * window_scale.y; + } } std::string KeyboardAndMouse::GetName() const |
