From 5637cd009aeab9d05c8869861f7a85f9c1d09e88 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 29 Jul 2024 09:15:55 -0700 Subject: [PATCH] Don't assert or change window draggable state if SDL isn't managing hit testing Fixes an assert if the application has set up its own hit testing on macOS --- src/video/cocoa/SDL_cocoawindow.m | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index 7dc8ae50fc..cbd01c9082 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -1526,8 +1526,6 @@ static NSCursor *Cocoa_GetDesiredCursor(void) { SDL_Window *window = _data.window; - SDL_assert(isDragAreaRunning == [_data.nswindow isMovableByWindowBackground]); - if (window->hit_test) { /* if no hit-test, skip this. */ const NSPoint location = [theEvent locationInWindow]; const SDL_Point point = { (int)location.x, window->h - (((int)location.y) - 1) }; @@ -1538,15 +1536,15 @@ static NSCursor *Cocoa_GetDesiredCursor(void) [_data.nswindow setMovableByWindowBackground:YES]; } return YES; /* dragging! */ + } else { + if (isDragAreaRunning) { + isDragAreaRunning = NO; + [_data.nswindow setMovableByWindowBackground:NO]; + return YES; /* was dragging, drop event. */ + } } } - if (isDragAreaRunning) { - isDragAreaRunning = NO; - [_data.nswindow setMovableByWindowBackground:NO]; - return YES; /* was dragging, drop event. */ - } - return NO; /* not a special area, carry on. */ } @@ -2381,16 +2379,16 @@ void Cocoa_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window) /* isZoomed always returns true if the window is not resizable */ if (!(window->flags & SDL_WINDOW_RESIZABLE) || !Cocoa_IsZoomed(window)) { if (!(window->flags & SDL_WINDOW_FULLSCREEN)) { - int x, y; - NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]]; + int x, y; + NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]]; /* Cocoa will resize the window from the bottom-left rather than the * top-left when -[nswindow setContentSize:] is used, so we must set the * entire frame based on the new size, in order to preserve the position. */ SDL_RelativeToGlobalForWindow(window, window->floating.x, window->floating.y, &x, &y); - rect.origin.x = x; - rect.origin.y = y; + rect.origin.x = x; + rect.origin.y = y; rect.size.width = window->floating.w; rect.size.height = window->floating.h; ConvertNSRect(&rect);