From e4f24ff7ae795c3e36ee4922dd88ddadadb4c9c7 Mon Sep 17 00:00:00 2001 From: Dima Volynets Date: Wed, 8 Oct 2025 20:52:01 +0300 Subject: [PATCH] MacOS: Added hint to control update of the metal layer's drawable size (#14053) --- include/SDL3/SDL_hints.h | 16 ++++++++++++++++ src/video/cocoa/SDL_cocoametalview.m | 4 +++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/SDL3/SDL_hints.h b/include/SDL3/SDL_hints.h index aa5d13b286..e1b067c3b7 100644 --- a/include/SDL3/SDL_hints.h +++ b/include/SDL3/SDL_hints.h @@ -3615,6 +3615,22 @@ extern "C" { */ #define SDL_HINT_VIDEO_MAC_FULLSCREEN_MENU_VISIBILITY "SDL_VIDEO_MAC_FULLSCREEN_MENU_VISIBILITY" +/** + * A variable indicating whether the metal layer drawable size should be + * updated for the SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED event on macOS. + * + * The variable can be set to the following values: + * + * - "0": the metal layer drawable size will not be updated + * on the SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED event. + * - "1": the metal layer drawable size will be updated + * on the SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED event. (default) + * + * This hint should be set before SDL_Metal_CreateView called. + * + * \since This hint is available since SDL 3.4.0. */ +#define SDL_HINT_VIDEO_METAL_AUTO_RESIZE_DRAWABLE "SDL_VIDEO_METAL_AUTO_RESIZE_DRAWABLE" + /** * A variable controlling whether SDL will attempt to automatically set the * destination display to a mode most closely matching that of the previous diff --git a/src/video/cocoa/SDL_cocoametalview.m b/src/video/cocoa/SDL_cocoametalview.m index af84e93586..1cd1cc90ca 100644 --- a/src/video/cocoa/SDL_cocoametalview.m +++ b/src/video/cocoa/SDL_cocoametalview.m @@ -90,7 +90,9 @@ static bool SDLCALL SDL_MetalViewEventWatch(void *userdata, SDL_Event *event) self.layer.opaque = opaque; - SDL_AddWindowEventWatch(SDL_WINDOW_EVENT_WATCH_EARLY, SDL_MetalViewEventWatch, (__bridge void *)(self)); + if (SDL_GetHintBoolean(SDL_HINT_VIDEO_METAL_AUTO_RESIZE_DRAWABLE, true)) { + SDL_AddWindowEventWatch(SDL_WINDOW_EVENT_WATCH_EARLY, SDL_MetalViewEventWatch, (__bridge void *)(self)); + } [self updateDrawableSize]; }