cocoa: removed relative mode handling on focus change

This is now being done at a higher level, so we don't want to duplicate it here.

Fixes the mouse cursor staying hidden if you enable relative mode, alt-tab away and then alt-tab back.
This commit is contained in:
Sam Lantinga 2024-08-08 13:24:43 -07:00
parent d2bdfd7792
commit 74504e0965
2 changed files with 11 additions and 28 deletions

View File

@ -316,11 +316,19 @@ static int Cocoa_WarpMouse(SDL_Window *window, float x, float y)
static int Cocoa_SetRelativeMouseMode(SDL_bool enabled) static int Cocoa_SetRelativeMouseMode(SDL_bool enabled)
{ {
SDL_Window *window = SDL_GetKeyboardFocus();
CGError result; CGError result;
SDL_CocoaWindowData *data;
if (enabled) { if (enabled) {
SDL_Window *window = SDL_GetKeyboardFocus();
if (window) { if (window) {
/* We will re-apply the relative mode when the window finishes being moved,
* if it is being moved right now.
*/
SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->internal;
if ([data.listener isMovingOrFocusClickPending]) {
return 0;
}
/* make sure the mouse isn't at the corner of the window, as this can confuse things if macOS thinks a window resize is happening on the first click. */ /* make sure the mouse isn't at the corner of the window, as this can confuse things if macOS thinks a window resize is happening on the first click. */
const CGPoint point = CGPointMake((float)(window->x + (window->w / 2)), (float)(window->y + (window->h / 2))); const CGPoint point = CGPointMake((float)(window->x + (window->w / 2)), (float)(window->y + (window->h / 2)));
Cocoa_HandleMouseWarp(point.x, point.y); Cocoa_HandleMouseWarp(point.x, point.y);
@ -336,21 +344,6 @@ static int Cocoa_SetRelativeMouseMode(SDL_bool enabled)
return SDL_SetError("CGAssociateMouseAndMouseCursorPosition() failed"); return SDL_SetError("CGAssociateMouseAndMouseCursorPosition() failed");
} }
/* We will re-apply the non-relative mode when the window gets focus, if it
* doesn't have focus right now.
*/
if (!window) {
return 0;
}
/* We will re-apply the non-relative mode when the window finishes being moved,
* if it is being moved right now.
*/
data = (__bridge SDL_CocoaWindowData *)window->internal;
if ([data.listener isMovingOrFocusClickPending]) {
return 0;
}
/* The hide/unhide calls are redundant most of the time, but they fix /* The hide/unhide calls are redundant most of the time, but they fix
* https://bugzilla.libsdl.org/show_bug.cgi?id=2550 * https://bugzilla.libsdl.org/show_bug.cgi?id=2550
*/ */

View File

@ -1166,18 +1166,13 @@ static NSCursor *Cocoa_GetDesiredCursor(void)
- (void)windowDidBecomeKey:(NSNotification *)aNotification - (void)windowDidBecomeKey:(NSNotification *)aNotification
{ {
SDL_Window *window = _data.window; SDL_Window *window = _data.window;
SDL_Mouse *mouse = SDL_GetMouse();
/* We're going to get keyboard events, since we're key. */ /* We're going to get keyboard events, since we're key. */
/* This needs to be done before restoring the relative mouse mode. */ /* This needs to be done before restoring the relative mouse mode. */
Cocoa_SetKeyboardFocus(_data.keyboard_focus ? _data.keyboard_focus : window); Cocoa_SetKeyboardFocus(_data.keyboard_focus ? _data.keyboard_focus : window);
if (mouse->relative_mode && !mouse->relative_mode_warp && ![self isMovingOrFocusClickPending]) {
mouse->SetRelativeMouseMode(SDL_TRUE);
}
/* If we just gained focus we need the updated mouse position */ /* If we just gained focus we need the updated mouse position */
if (!mouse->relative_mode) { if (!(window->flags & SDL_WINDOW_MOUSE_RELATIVE_MODE)) {
NSPoint point; NSPoint point;
float x, y; float x, y;
@ -1205,11 +1200,6 @@ static NSCursor *Cocoa_GetDesiredCursor(void)
- (void)windowDidResignKey:(NSNotification *)aNotification - (void)windowDidResignKey:(NSNotification *)aNotification
{ {
SDL_Mouse *mouse = SDL_GetMouse();
if (mouse->relative_mode && !mouse->relative_mode_warp) {
mouse->SetRelativeMouseMode(SDL_FALSE);
}
/* Some other window will get mouse events, since we're not key. */ /* Some other window will get mouse events, since we're not key. */
if (SDL_GetMouseFocus() == _data.window) { if (SDL_GetMouseFocus() == _data.window) {
SDL_SetMouseFocus(NULL); SDL_SetMouseFocus(NULL);