Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Fixed bug 1167 (SDL_WINDOWPOS_CENTERED doesn't work if used right aft…
Browse files Browse the repository at this point in the history
…er fullscreen -> windowed switch)

The top level code handles SDL_WINDOWPOS_CENTERED now, and the Cocoa SetWindowPosition call will clear the moveHack before adjusting the window position.
  • Loading branch information
slouken committed Mar 12, 2011
1 parent 80077bb commit 600a0fe
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 65 deletions.
14 changes: 14 additions & 0 deletions src/video/SDL_video.c
Expand Up @@ -1413,6 +1413,20 @@ SDL_SetWindowPosition(SDL_Window * window, int x, int y)
if (!SDL_WINDOWPOS_ISUNDEFINED(y)) {
window->y = y;
}
if (SDL_WINDOWPOS_ISCENTERED(x) || SDL_WINDOWPOS_ISCENTERED(y)) {
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
int displayIndex;
SDL_Rect bounds;

displayIndex = SDL_GetIndexOfDisplay(display);
SDL_GetDisplayBounds(displayIndex, &bounds);
if (SDL_WINDOWPOS_ISCENTERED(x)) {
window->x = bounds.x + (bounds.w - window->w) / 2;
}
if (SDL_WINDOWPOS_ISCENTERED(y)) {
window->y = bounds.y + (bounds.h - window->h) / 2;
}
}
if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
if (_this->SetWindowPosition) {
_this->SetWindowPosition(_this, window);
Expand Down
22 changes: 8 additions & 14 deletions src/video/cocoa/SDL_cocoawindow.m
Expand Up @@ -670,26 +670,20 @@ - (void)rightMouseDown:(NSEvent *)theEvent
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
NSRect rect;
SDL_Rect bounds;
Uint32 moveHack;

Cocoa_GetDisplayBounds(_this, display, &bounds);
if (SDL_WINDOWPOS_ISCENTERED(window->x)) {
rect.origin.x = bounds.x + (bounds.w - window->w) / 2;
} else {
rect.origin.x = window->x;
}
if (SDL_WINDOWPOS_ISCENTERED(window->y)) {
rect.origin.y = bounds.y + (bounds.h - window->h) / 2;
} else {
rect.origin.y = window->y;
}
rect.origin.x = window->x;
rect.origin.y = window->y;
rect.size.width = window->w;
rect.size.height = window->h;
ConvertNSRect(&rect);
rect = [nswindow frameRectForContentRect:rect];

moveHack = s_moveHack;
s_moveHack = 0;
[nswindow setFrameOrigin:rect.origin];
s_moveHack = moveHack;

[pool release];
}

Expand Down
22 changes: 2 additions & 20 deletions src/video/directfb/SDL_DirectFB_window.c
Expand Up @@ -260,29 +260,11 @@ void
DirectFB_SetWindowPosition(_THIS, SDL_Window * window)
{
SDL_DFB_WINDOWDATA(window);
SDL_DFB_DISPLAYDATA(window);
int x, y;

if (SDL_WINDOWPOS_ISCENTERED(window->x)) {
x = (dispdata->cw - window->w) / 2;
} else if (SDL_WINDOWPOS_ISUNDEFINED(window->x)) {
x = 0;
} else {
x = window->x;
}

if (SDL_WINDOWPOS_ISCENTERED(window->y)) {
y = (dispdata->ch - window->h) / 2;
} else if (SDL_WINDOWPOS_ISUNDEFINED(window->y)) {
y = 0;
} else {
y = window->y;
}
x = window->x;
y = window->y;

if (window->flags & SDL_WINDOW_FULLSCREEN) {
x = 0;
y = 0;
}
DirectFB_WM_AdjustWindowLayout(window, window->flags, window->w, window->h);
SDL_DFB_CHECK(windata->dfbwin->MoveTo(windata->dfbwin, x, y));
}
Expand Down
14 changes: 2 additions & 12 deletions src/video/windows/SDL_windowswindow.c
Expand Up @@ -371,18 +371,8 @@ WIN_SetWindowPosition(_THIS, SDL_Window * window)
AdjustWindowRectEx(&rect, style, menu, 0);
w = (rect.right - rect.left);
h = (rect.bottom - rect.top);

WIN_GetDisplayBounds(_this, display, &bounds);
if (SDL_WINDOWPOS_ISCENTERED(window->x)) {
x = bounds.x + (bounds.w - w) / 2;
} else {
x = window->x + rect.left;
}
if (SDL_WINDOWPOS_ISCENTERED(window->y)) {
y = bounds.y + (bounds.h - h) / 2;
} else {
y = window->y + rect.top;
}
x = window->x + rect.left;
y = window->y + rect.top;

SetWindowPos(hwnd, top, x, y, 0, 0, (SWP_NOCOPYBITS | SWP_NOSIZE));
}
Expand Down
20 changes: 1 addition & 19 deletions src/video/x11/SDL_x11window.c
Expand Up @@ -756,27 +756,9 @@ X11_SetWindowPosition(_THIS, SDL_Window * window)
{
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
Display *display = data->videodata->display;
SDL_bool oldstyle_fullscreen;
int x, y;

/* ICCCM2.0-compliant window managers can handle fullscreen windows */
oldstyle_fullscreen = X11_IsWindowOldFullscreen(_this, window);

if (oldstyle_fullscreen
|| SDL_WINDOWPOS_ISCENTERED(window->x)) {
X11_GetDisplaySize(_this, window, &x, NULL);
x = (x - window->w) / 2;
} else {
x = window->x;
}
if (oldstyle_fullscreen
|| SDL_WINDOWPOS_ISCENTERED(window->y)) {
X11_GetDisplaySize(_this, window, NULL, &y);
y = (y - window->h) / 2;
} else {
y = window->y;
}
XMoveWindow(display, data->xwindow, x, y);
XMoveWindow(display, data->xwindow, window->x, window->y);
XFlush(display);
}

Expand Down

0 comments on commit 600a0fe

Please sign in to comment.