@@ -323,6 +323,21 @@ static void Cocoa_GetHDRProperties(CGDirectDisplayID displayID, SDL_HDROutputPro
323323 }
324324}
325325
326+ static bool Cocoa_GetUsableBounds (CGDirectDisplayID displayID, SDL_Rect *rect)
327+ {
328+ NSScreen *screen = GetNSScreenForDisplayID (displayID);
329+
330+ if (screen == nil ) {
331+ return false ;
332+ }
333+
334+ const NSRect frame = [screen visibleFrame ];
335+ rect->x = (int )frame.origin .x ;
336+ rect->y = (int )(CGDisplayPixelsHigh (kCGDirectMainDisplay ) - frame.origin .y - frame.size .height );
337+ rect->w = (int )frame.size .width ;
338+ rect->h = (int )frame.size .height ;
339+ return true ;
340+ }
326341
327342bool Cocoa_AddDisplay (CGDirectDisplayID display, bool send_event)
328343{
@@ -331,7 +346,7 @@ bool Cocoa_AddDisplay(CGDirectDisplayID display, bool send_event)
331346 return false ;
332347 }
333348
334- SDL_DisplayData *displaydata = (SDL_DisplayData *)SDL_malloc ( sizeof (*displaydata));
349+ SDL_DisplayData *displaydata = (SDL_DisplayData *)SDL_calloc ( 1 , sizeof (*displaydata));
335350 if (!displaydata) {
336351 CGDisplayModeRelease (moderef);
337352 return false ;
@@ -359,6 +374,8 @@ bool Cocoa_AddDisplay(CGDirectDisplayID display, bool send_event)
359374
360375 Cocoa_GetHDRProperties (displaydata->display , &viddisplay.HDR );
361376
377+ Cocoa_GetUsableBounds (displaydata->display , &displaydata->usable_bounds );
378+
362379 viddisplay.desktop_mode = mode;
363380 viddisplay.internal = displaydata;
364381 const bool retval = SDL_AddVideoDisplay (&viddisplay, send_event);
@@ -538,6 +555,13 @@ void Cocoa_UpdateDisplays(SDL_VideoDevice *_this)
538555
539556 Cocoa_GetHDRProperties (displaydata->display , &HDR);
540557 SDL_SetDisplayHDRProperties (display, &HDR);
558+
559+ SDL_Rect rect;
560+ if (Cocoa_GetUsableBounds (displaydata->display , &rect) &&
561+ SDL_memcmp (&displaydata->usable_bounds , &rect, sizeof (rect)) != 0 ) {
562+ SDL_memcpy (&displaydata->usable_bounds , &rect, sizeof (rect));
563+ SDL_SendDisplayEvent (display, SDL_EVENT_DISPLAY_USABLE_BOUNDS_CHANGED, 0 , 0 );
564+ }
541565 }
542566}
543567
@@ -556,24 +580,10 @@ bool Cocoa_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, S
556580
557581bool Cocoa_GetDisplayUsableBounds (SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect)
558582{
559- @autoreleasepool {
560- SDL_DisplayData *displaydata = (SDL_DisplayData *)display->internal ;
561- NSScreen *screen = GetNSScreenForDisplayID (displaydata->display );
562-
563- if (screen == nil ) {
564- return SDL_SetError (" Couldn't get NSScreen for display" );
565- }
566-
567- {
568- const NSRect frame = [screen visibleFrame ];
569- rect->x = (int )frame.origin .x ;
570- rect->y = (int )(CGDisplayPixelsHigh (kCGDirectMainDisplay ) - frame.origin .y - frame.size .height );
571- rect->w = (int )frame.size .width ;
572- rect->h = (int )frame.size .height ;
573- }
583+ SDL_DisplayData *displaydata = (SDL_DisplayData *)display->internal ;
574584
575- return true ;
576- }
585+ SDL_memcpy (rect, &displaydata-> usable_bounds , sizeof (*rect)) ;
586+ return true ;
577587}
578588
579589bool Cocoa_GetDisplayModes (SDL_VideoDevice *_this, SDL_VideoDisplay *display)
0 commit comments