Fixed bug 2534 - Mac: black bar at top of screen in SDL_WINDOW_FULLSCREEN mode Alex Szpakowski Patch to fix the y component of the position of fullscreen windows in OS X. In Mac OS X with the latest Mercurial code, when a window is in exclusive-fullscreen the y component of its position is offset by the same amount that is normally taken up by the menubar, resulting in a black bar at the top of the screen. The recent changes to the internal ConvertNSRect function make it treat the bottom of the menubar as 0 for the y component of window positions, even when the window is fullscreen and 'above' the menubar. I have attached a patch which fixes the issue by only making the window position relative to the menubar in windowed modes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m
index eca68a5..13bfb7b 100644
--- a/src/video/cocoa/SDL_cocoawindow.m
+++ b/src/video/cocoa/SDL_cocoawindow.m
@@ -49,6 +49,9 @@
#endif
+#define FULLSCREEN_MASK (SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN)
+
+
@interface SDLWindow : NSWindow
/* These are needed for borderless/fullscreen windows */
- (BOOL)canBecomeKeyWindow;
@@ -89,9 +92,9 @@
static Uint32 s_moveHack;
-static void ConvertNSRect(NSScreen *screen, NSRect *r)
+static void ConvertNSRect(NSScreen *screen, BOOL fullscreen, NSRect *r)
{
- NSRect visibleScreen = [screen visibleFrame];
+ NSRect visibleScreen = fullscreen ? [screen frame] : [screen visibleFrame];
r->origin.y = (visibleScreen.origin.y + visibleScreen.size.height) - r->origin.y - r->size.height;
}
@@ -412,8 +415,9 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
int x, y;
SDL_Window *window = _data->window;
NSWindow *nswindow = _data->nswindow;
+ BOOL fullscreen = window->flags & FULLSCREEN_MASK;
NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
- ConvertNSRect([nswindow screen], &rect);
+ ConvertNSRect([nswindow screen], fullscreen, &rect);
if (s_moveHack) {
SDL_bool blockMove = ((SDL_GetTicks() - s_moveHack) < 500);
@@ -424,7 +428,7 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
/* Cocoa is adjusting the window in response to a mode change */
rect.origin.x = window->x;
rect.origin.y = window->y;
- ConvertNSRect([nswindow screen], &rect);
+ ConvertNSRect([nswindow screen], fullscreen, &rect);
[nswindow setFrameOrigin:rect.origin];
return;
}
@@ -449,7 +453,7 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
NSWindow *nswindow = _data->nswindow;
int x, y, w, h;
NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
- ConvertNSRect([nswindow screen], &rect);
+ ConvertNSRect([nswindow screen], (window->flags & FULLSCREEN_MASK), &rect);
x = (int)rect.origin.x;
y = (int)rect.origin.y;
w = (int)rect.size.width;
@@ -934,7 +938,7 @@ SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created
/* Fill in the SDL window with the window data */
{
NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
- ConvertNSRect([nswindow screen], &rect);
+ ConvertNSRect([nswindow screen], (window->flags & FULLSCREEN_MASK), &rect);
window->x = (int)rect.origin.x;
window->y = (int)rect.origin.y;
window->w = (int)rect.size.width;
@@ -1010,7 +1014,7 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
rect.origin.y = window->y;
rect.size.width = window->w;
rect.size.height = window->h;
- ConvertNSRect([[NSScreen screens] objectAtIndex:0], &rect);
+ ConvertNSRect([[NSScreen screens] objectAtIndex:0], (window->flags & FULLSCREEN_MASK), &rect);
style = GetWindowStyle(window);
@@ -1138,7 +1142,7 @@ Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
rect.origin.y = window->y;
rect.size.width = window->w;
rect.size.height = window->h;
- ConvertNSRect([nswindow screen], &rect);
+ ConvertNSRect([nswindow screen], (window->flags & FULLSCREEN_MASK), &rect);
moveHack = s_moveHack;
s_moveHack = 0;
@@ -1338,7 +1342,7 @@ Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display
rect.origin.y = bounds.y;
rect.size.width = bounds.w;
rect.size.height = bounds.h;
- ConvertNSRect([nswindow screen], &rect);
+ ConvertNSRect([nswindow screen], fullscreen, &rect);
/* Hack to fix origin on Mac OS X 10.4 */
NSRect screenRect = [[nswindow screen] frame];
@@ -1356,7 +1360,7 @@ Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display
rect.origin.y = window->windowed.y;
rect.size.width = window->windowed.w;
rect.size.height = window->windowed.h;
- ConvertNSRect([nswindow screen], &rect);
+ ConvertNSRect([nswindow screen], fullscreen, &rect);
if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
[nswindow performSelector: @selector(setStyleMask:) withObject: (id)(uintptr_t)GetWindowStyle(window)];