mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 06:39:46 -06:00
Quartz: Handle mouse centering hotkey.
Co-authored-by: Dentomologist <dentomologist@gmail.com>
This commit is contained in:
@ -8,6 +8,8 @@
|
|||||||
#include <Carbon/Carbon.h>
|
#include <Carbon/Carbon.h>
|
||||||
#include <Cocoa/Cocoa.h>
|
#include <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
#include "Core/Host.h"
|
||||||
|
|
||||||
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
||||||
|
|
||||||
namespace ciface::Quartz
|
namespace ciface::Quartz
|
||||||
@ -192,16 +194,36 @@ void KeyboardAndMouse::UpdateInput()
|
|||||||
CFRelease(windowDescriptions);
|
CFRelease(windowDescriptions);
|
||||||
CFRelease(windowArray);
|
CFRelease(windowArray);
|
||||||
|
|
||||||
CGEventRef event = CGEventCreate(nil);
|
const double window_width = std::max(bounds.size.width, 1.0);
|
||||||
CGPoint loc = CGEventGetLocation(event);
|
const double window_height = std::max(bounds.size.height, 1.0);
|
||||||
CFRelease(event);
|
|
||||||
|
|
||||||
const auto window_scale = g_controller_interface.GetWindowInputScale();
|
if (g_controller_interface.IsMouseCenteringRequested() && Host_RendererHasFocus())
|
||||||
|
{
|
||||||
|
m_cursor.x = 0;
|
||||||
|
m_cursor.y = 0;
|
||||||
|
|
||||||
loc.x -= bounds.origin.x;
|
const CGPoint window_center_global_coordinates =
|
||||||
loc.y -= bounds.origin.y;
|
CGPointMake(bounds.origin.x + window_width / 2.0, bounds.origin.y + window_height / 2.0);
|
||||||
m_cursor.x = (loc.x / std::max(bounds.size.width, 1.0) * 2 - 1.0) * window_scale.x;
|
CGWarpMouseCursorPosition(window_center_global_coordinates);
|
||||||
m_cursor.y = (loc.y / std::max(bounds.size.height, 1.0) * 2 - 1.0) * window_scale.y;
|
// Without this line there is a short but obvious delay after centering the cursor before it can
|
||||||
|
// be moved again
|
||||||
|
CGAssociateMouseAndMouseCursorPosition(true);
|
||||||
|
|
||||||
|
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
|
std::string KeyboardAndMouse::GetName() const
|
||||||
|
Reference in New Issue
Block a user