From 001fc52465143149995527fc887c94b62bf62dc6 Mon Sep 17 00:00:00 2001 From: dvolynets Date: Fri, 26 Sep 2025 16:41:09 +0300 Subject: [PATCH 1/3] added hint to control update of the metal layer's drawable size --- include/SDL3/SDL_hints.h | 16 ++++++++++++++++ src/video/cocoa/SDL_cocoametalview.m | 8 ++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/include/SDL3/SDL_hints.h b/include/SDL3/SDL_hints.h index 5b9f2f2fdbd69..07986b3d897db 100644 --- a/include/SDL3/SDL_hints.h +++ b/include/SDL3/SDL_hints.h @@ -3594,6 +3594,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": metal view event watcher is disabled, the drawable size of the metal view + * will not be updated for the SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED event. + * - "1": metal view event watcher is enabled, the drawable size of the metal view + * will be updated for 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_MAC_ENABLE_METAL_VIEW_WATCHER "SDL_VIDEO_MAC_ENABLE_METAL_VIEW_WATCHER" + /** * 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 af84e935864d5..fc586ddc2bdc5 100644 --- a/src/video/cocoa/SDL_cocoametalview.m +++ b/src/video/cocoa/SDL_cocoametalview.m @@ -90,7 +90,9 @@ - (instancetype)initWithFrame:(NSRect)frame self.layer.opaque = opaque; - SDL_AddWindowEventWatch(SDL_WINDOW_EVENT_WATCH_EARLY, SDL_MetalViewEventWatch, (__bridge void *)(self)); + if (SDL_GetHintBoolean(SDL_HINT_VIDEO_MAC_ENABLE_METAL_VIEW_WATCHER, true)) { + SDL_AddWindowEventWatch(SDL_WINDOW_EVENT_WATCH_EARLY, SDL_MetalViewEventWatch, (__bridge void *)(self)); + } [self updateDrawableSize]; } @@ -100,7 +102,9 @@ - (instancetype)initWithFrame:(NSRect)frame - (void)dealloc { - SDL_RemoveWindowEventWatch(SDL_WINDOW_EVENT_WATCH_EARLY, SDL_MetalViewEventWatch, (__bridge void *)(self)); + if (SDL_GetHintBoolean(SDL_HINT_VIDEO_MAC_ENABLE_METAL_VIEW_WATCHER, true)) { + SDL_RemoveWindowEventWatch(SDL_WINDOW_EVENT_WATCH_EARLY, SDL_MetalViewEventWatch, (__bridge void *)(self)); + } } - (NSInteger)tag From dc75ffbe7f3dbf65bbe21f14aab090adf6c148b2 Mon Sep 17 00:00:00 2001 From: dvolynets Date: Mon, 29 Sep 2025 12:08:51 +0300 Subject: [PATCH 2/3] renamed hint, fixed hint description --- include/SDL3/SDL_hints.h | 10 +++++----- src/video/cocoa/SDL_cocoametalview.m | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/SDL3/SDL_hints.h b/include/SDL3/SDL_hints.h index 07986b3d897db..7002aff24325a 100644 --- a/include/SDL3/SDL_hints.h +++ b/include/SDL3/SDL_hints.h @@ -3600,15 +3600,15 @@ extern "C" { * * The variable can be set to the following values: * - * - "0": metal view event watcher is disabled, the drawable size of the metal view - * will not be updated for the SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED event. - * - "1": metal view event watcher is enabled, the drawable size of the metal view - * will be updated for the SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED event. (default) + * - "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_MAC_ENABLE_METAL_VIEW_WATCHER "SDL_VIDEO_MAC_ENABLE_METAL_VIEW_WATCHER" +#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 diff --git a/src/video/cocoa/SDL_cocoametalview.m b/src/video/cocoa/SDL_cocoametalview.m index fc586ddc2bdc5..57def2c24c7c7 100644 --- a/src/video/cocoa/SDL_cocoametalview.m +++ b/src/video/cocoa/SDL_cocoametalview.m @@ -90,7 +90,7 @@ - (instancetype)initWithFrame:(NSRect)frame self.layer.opaque = opaque; - if (SDL_GetHintBoolean(SDL_HINT_VIDEO_MAC_ENABLE_METAL_VIEW_WATCHER, true)) { + if (SDL_GetHintBoolean(SDL_HINT_VIDEO_METAL_AUTO_RESIZE_DRAWABLE, true)) { SDL_AddWindowEventWatch(SDL_WINDOW_EVENT_WATCH_EARLY, SDL_MetalViewEventWatch, (__bridge void *)(self)); } @@ -102,7 +102,7 @@ - (instancetype)initWithFrame:(NSRect)frame - (void)dealloc { - if (SDL_GetHintBoolean(SDL_HINT_VIDEO_MAC_ENABLE_METAL_VIEW_WATCHER, true)) { + if (SDL_GetHintBoolean(SDL_HINT_VIDEO_METAL_AUTO_RESIZE_DRAWABLE, true)) { SDL_RemoveWindowEventWatch(SDL_WINDOW_EVENT_WATCH_EARLY, SDL_MetalViewEventWatch, (__bridge void *)(self)); } } From 4b776584faae03db183d99b0854d5bab5f4ba7ab Mon Sep 17 00:00:00 2001 From: dvolynets Date: Tue, 30 Sep 2025 18:24:45 +0300 Subject: [PATCH 3/3] removed redundant hint checking inside dealloc --- src/video/cocoa/SDL_cocoametalview.m | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/video/cocoa/SDL_cocoametalview.m b/src/video/cocoa/SDL_cocoametalview.m index 57def2c24c7c7..1cd1cc90ca234 100644 --- a/src/video/cocoa/SDL_cocoametalview.m +++ b/src/video/cocoa/SDL_cocoametalview.m @@ -102,9 +102,7 @@ - (instancetype)initWithFrame:(NSRect)frame - (void)dealloc { - if (SDL_GetHintBoolean(SDL_HINT_VIDEO_METAL_AUTO_RESIZE_DRAWABLE, true)) { - SDL_RemoveWindowEventWatch(SDL_WINDOW_EVENT_WATCH_EARLY, SDL_MetalViewEventWatch, (__bridge void *)(self)); - } + SDL_RemoveWindowEventWatch(SDL_WINDOW_EVENT_WATCH_EARLY, SDL_MetalViewEventWatch, (__bridge void *)(self)); } - (NSInteger)tag