mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-24 21:11:39 +00:00
Restore mouse position when entering GUI capture mode in Cocoa backend
This commit is contained in:
parent
60cb457c4c
commit
9292b23bb4
1 changed files with 21 additions and 4 deletions
|
@ -109,7 +109,7 @@ void CheckGUICapture()
|
|||
}
|
||||
}
|
||||
|
||||
void CenterCursor()
|
||||
void SetCursorPosition(const NSPoint position)
|
||||
{
|
||||
NSWindow* window = [NSApp keyWindow];
|
||||
if (nil == window)
|
||||
|
@ -118,15 +118,14 @@ void CenterCursor()
|
|||
}
|
||||
|
||||
const NSRect displayRect = [[window screen] frame];
|
||||
const NSRect windowRect = [window frame];
|
||||
const CGPoint centerPoint = CGPointMake(NSMidX(windowRect), displayRect.size.height - NSMidY(windowRect));
|
||||
const CGPoint eventPoint = CGPointMake(position.x, displayRect.size.height - position.y);
|
||||
|
||||
CGEventSourceRef eventSource = CGEventSourceCreate(kCGEventSourceStateCombinedSessionState);
|
||||
|
||||
if (NULL != eventSource)
|
||||
{
|
||||
CGEventRef mouseMoveEvent = CGEventCreateMouseEvent(eventSource,
|
||||
kCGEventMouseMoved, centerPoint, kCGMouseButtonLeft);
|
||||
kCGEventMouseMoved, eventPoint, kCGMouseButtonLeft);
|
||||
|
||||
if (NULL != mouseMoveEvent)
|
||||
{
|
||||
|
@ -141,6 +140,20 @@ void CenterCursor()
|
|||
s_skipMouseMoves = 2;
|
||||
}
|
||||
|
||||
void CenterCursor()
|
||||
{
|
||||
NSWindow* window = [NSApp keyWindow];
|
||||
if (nil == window)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const NSRect displayRect = [[window screen] frame];
|
||||
const NSRect windowRect = [window frame];
|
||||
const NSPoint centerPoint = { NSMidX(windowRect), NSMidY(windowRect) };
|
||||
|
||||
SetCursorPosition(centerPoint);
|
||||
}
|
||||
|
||||
bool IsInGame()
|
||||
{
|
||||
|
@ -227,6 +240,7 @@ void I_ReleaseMouseCapture()
|
|||
void I_SetNativeMouse(bool wantNative)
|
||||
{
|
||||
static bool nativeMouse = true;
|
||||
static NSPoint mouseLocation;
|
||||
|
||||
if (wantNative != nativeMouse)
|
||||
{
|
||||
|
@ -234,6 +248,7 @@ void I_SetNativeMouse(bool wantNative)
|
|||
|
||||
if (!wantNative)
|
||||
{
|
||||
mouseLocation = [NSEvent mouseLocation];
|
||||
CenterCursor();
|
||||
}
|
||||
|
||||
|
@ -241,6 +256,8 @@ void I_SetNativeMouse(bool wantNative)
|
|||
|
||||
if (wantNative)
|
||||
{
|
||||
SetCursorPosition(mouseLocation);
|
||||
|
||||
[NSCursor unhide];
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue