Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions include/SDL3/SDL_hints.h
Original file line number Diff line number Diff line change
Expand Up @@ -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": 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
Expand Down
8 changes: 6 additions & 2 deletions src/video/cocoa/SDL_cocoametalview.m
Original file line number Diff line number Diff line change
Expand Up @@ -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_METAL_AUTO_RESIZE_DRAWABLE, true)) {
SDL_AddWindowEventWatch(SDL_WINDOW_EVENT_WATCH_EARLY, SDL_MetalViewEventWatch, (__bridge void *)(self));
}

[self updateDrawableSize];
}
Expand All @@ -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_METAL_AUTO_RESIZE_DRAWABLE, true)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't check the hint here, we should either remember that we added the watcher or just call SDL_RemoveWindowEventWatch() unconditionally, in case someone changes the hint at runtime.

SDL_RemoveWindowEventWatch(SDL_WINDOW_EVENT_WATCH_EARLY, SDL_MetalViewEventWatch, (__bridge void *)(self));
}
}

- (NSInteger)tag
Expand Down