cocoa: Use cached viewport dimensions when querying the window pixel size
Recalculate the backing viewport dimensions in the resize handler, otherwise, this data can be out-of-sync with the logical window size if queried during transition animations.
This commit is contained in:
@@ -141,6 +141,7 @@ typedef enum
|
|||||||
@property(nonatomic) SDL_Window *window;
|
@property(nonatomic) SDL_Window *window;
|
||||||
@property(nonatomic) NSWindow *nswindow;
|
@property(nonatomic) NSWindow *nswindow;
|
||||||
@property(nonatomic) NSView *sdlContentView;
|
@property(nonatomic) NSView *sdlContentView;
|
||||||
|
@property(nonatomic) NSRect viewport;
|
||||||
@property(nonatomic) NSMutableArray *nscontexts;
|
@property(nonatomic) NSMutableArray *nscontexts;
|
||||||
@property(nonatomic) BOOL in_blocking_transition;
|
@property(nonatomic) BOOL in_blocking_transition;
|
||||||
@property(nonatomic) BOOL fullscreen_space_requested;
|
@property(nonatomic) BOOL fullscreen_space_requested;
|
||||||
|
|||||||
@@ -1242,6 +1242,12 @@ static NSCursor *Cocoa_GetDesiredCursor(void)
|
|||||||
w = (int)rect.size.width;
|
w = (int)rect.size.width;
|
||||||
h = (int)rect.size.height;
|
h = (int)rect.size.height;
|
||||||
|
|
||||||
|
_data.viewport = [_data.sdlContentView bounds];
|
||||||
|
if (window->flags & SDL_WINDOW_HIGH_PIXEL_DENSITY) {
|
||||||
|
// This gives us the correct viewport for a Retina-enabled view.
|
||||||
|
_data.viewport = [_data.sdlContentView convertRectToBacking:_data.viewport];
|
||||||
|
}
|
||||||
|
|
||||||
ScheduleContextUpdates(_data);
|
ScheduleContextUpdates(_data);
|
||||||
|
|
||||||
/* The OS can resize the window automatically if the display density
|
/* The OS can resize the window automatically if the display density
|
||||||
@@ -2274,6 +2280,12 @@ static bool SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, NSWindow
|
|||||||
data.nscontexts = [[NSMutableArray alloc] init];
|
data.nscontexts = [[NSMutableArray alloc] init];
|
||||||
data.sdlContentView = nsview;
|
data.sdlContentView = nsview;
|
||||||
|
|
||||||
|
data.viewport = [data.sdlContentView bounds];
|
||||||
|
if (window->flags & SDL_WINDOW_HIGH_PIXEL_DENSITY) {
|
||||||
|
// This gives us the correct viewport for a Retina-enabled view.
|
||||||
|
data.viewport = [data.sdlContentView convertRectToBacking:data.viewport];
|
||||||
|
}
|
||||||
|
|
||||||
// Create an event listener for the window
|
// Create an event listener for the window
|
||||||
data.listener = [[SDL3Cocoa_WindowListener alloc] init];
|
data.listener = [[SDL3Cocoa_WindowListener alloc] init];
|
||||||
|
|
||||||
@@ -2703,16 +2715,9 @@ void Cocoa_GetWindowSizeInPixels(SDL_VideoDevice *_this, SDL_Window *window, int
|
|||||||
{
|
{
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
SDL_CocoaWindowData *windata = (__bridge SDL_CocoaWindowData *)window->internal;
|
SDL_CocoaWindowData *windata = (__bridge SDL_CocoaWindowData *)window->internal;
|
||||||
NSView *contentView = windata.sdlContentView;
|
|
||||||
NSRect viewport = [contentView bounds];
|
|
||||||
|
|
||||||
if (window->flags & SDL_WINDOW_HIGH_PIXEL_DENSITY) {
|
*w = (int)windata.viewport.size.width;
|
||||||
// This gives us the correct viewport for a Retina-enabled view.
|
*h = (int)windata.viewport.size.height;
|
||||||
viewport = [contentView convertRectToBacking:viewport];
|
|
||||||
}
|
|
||||||
|
|
||||||
*w = (int)viewport.size.width;
|
|
||||||
*h = (int)viewport.size.height;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user