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

Commit

Permalink
Fixed setting fullscreen and maximized states for windows that haven'…
Browse files Browse the repository at this point in the history
…t been mapped yet.
  • Loading branch information
slouken committed Jul 14, 2010
1 parent e9381e4 commit 02700cb
Showing 1 changed file with 81 additions and 38 deletions.
119 changes: 81 additions & 38 deletions src/video/x11/SDL_x11window.c
Expand Up @@ -43,10 +43,9 @@
#define _NET_WM_STATE_TOGGLE 2l

static SDL_bool
X11_WindowIsOldstyleFullscreen(SDL_Window * window)
X11_IsWindowOldFullscreen(_THIS, SDL_Window * window)
{
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
SDL_VideoData *videodata = (SDL_VideoData *) data->videodata;
SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;

/* ICCCM2.0-compliant window managers can handle fullscreen windows */
if ((window->flags & SDL_WINDOW_FULLSCREEN) && !videodata->net_wm) {
Expand All @@ -56,6 +55,37 @@ X11_WindowIsOldstyleFullscreen(SDL_Window * window)
}
}

static SDL_bool
X11_IsWindowMapped(_THIS, SDL_Window * window)
{
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
XWindowAttributes attr;

XGetWindowAttributes(videodata->display, data->xwindow, &attr);
if (attr.map_state != IsUnmapped) {
return SDL_TRUE;
} else {
return SDL_FALSE;
}
}

static int
X11_GetWMStateProperty(_THIS, SDL_Window * window, Atom atoms[3])
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
int count = 0;

if (window->flags & SDL_WINDOW_FULLSCREEN) {
atoms[count++] = data->_NET_WM_STATE_FULLSCREEN;
}
if (window->flags & SDL_WINDOW_MAXIMIZED) {
atoms[count++] = data->_NET_WM_STATE_MAXIMIZED_VERT;
atoms[count++] = data->_NET_WM_STATE_MAXIMIZED_HORZ;
}
return count;
}

static void
X11_GetDisplaySize(_THIS, SDL_Window * window, int *w, int *h)
{
Expand Down Expand Up @@ -237,13 +267,11 @@ X11_CreateWindow(_THIS, SDL_Window * window)
SDL_bool oldstyle_fullscreen;
Atom _NET_WM_WINDOW_TYPE;
Atom _NET_WM_WINDOW_TYPE_NORMAL;
int wmstate_count;
Atom wmstate_atoms[3];

/* ICCCM2.0-compliant window managers can handle fullscreen windows */
if ((window->flags & SDL_WINDOW_FULLSCREEN) && !data->net_wm) {
oldstyle_fullscreen = SDL_TRUE;
} else {
oldstyle_fullscreen = SDL_FALSE;
}
oldstyle_fullscreen = X11_IsWindowOldFullscreen(_this, window);

#if SDL_VIDEO_DRIVER_X11_XINERAMA
/* FIXME
Expand Down Expand Up @@ -665,21 +693,14 @@ X11_CreateWindow(_THIS, SDL_Window * window)
XFree(classhints);
}

/* FIXME: Why doesn't this work? */
if (window->flags & SDL_WINDOW_FULLSCREEN) {
Atom _NET_WM_STATE = data->_NET_WM_STATE;
Atom _NET_WM_STATE_FULLSCREEN = data->_NET_WM_STATE_FULLSCREEN;
XEvent e;

e.xany.type = ClientMessage;
e.xclient.message_type = _NET_WM_STATE;
e.xclient.format = 32;
e.xclient.data.l[0] = _NET_WM_STATE_ADD;
e.xclient.data.l[1] = _NET_WM_STATE_FULLSCREEN;
e.xclient.data.l[2] = 0l;

XSendEvent(display, RootWindow(display, screen), 0,
SubstructureNotifyMask | SubstructureRedirectMask, &e);
/* Set the window manager state */
wmstate_count = X11_GetWMStateProperty(_this, window, wmstate_atoms);
if (wmstate_count > 0) {
XChangeProperty(display, w, data->_NET_WM_STATE, XA_ATOM, 32,
PropModeReplace,
(unsigned char *)wmstate_atoms, wmstate_count);
} else {
XDeleteProperty(display, w, data->_NET_WM_STATE);
}

/* Let the window manager know we're a "normal" window */
Expand Down Expand Up @@ -881,7 +902,7 @@ X11_SetWindowPosition(_THIS, SDL_Window * window)
int x, y;

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

if (oldstyle_fullscreen
|| window->x == SDL_WINDOWPOS_CENTERED) {
Expand Down Expand Up @@ -946,19 +967,41 @@ X11_SetWindowMaximized(_THIS, SDL_Window * window, SDL_bool maximized)
Atom _NET_WM_STATE = data->videodata->_NET_WM_STATE;
Atom _NET_WM_STATE_MAXIMIZED_VERT = data->videodata->_NET_WM_STATE_MAXIMIZED_VERT;
Atom _NET_WM_STATE_MAXIMIZED_HORZ = data->videodata->_NET_WM_STATE_MAXIMIZED_HORZ;
XEvent e;

e.xany.type = ClientMessage;
e.xclient.message_type = _NET_WM_STATE;
e.xclient.format = 32;
e.xclient.data.l[0] =
maximized ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
e.xclient.data.l[1] = _NET_WM_STATE_MAXIMIZED_VERT;
e.xclient.data.l[2] = _NET_WM_STATE_MAXIMIZED_HORZ;
e.xclient.data.l[3] = 0l;

XSendEvent(display, RootWindow(display, displaydata->screen), 0,
SubstructureNotifyMask | SubstructureRedirectMask, &e);
Atom _NET_WM_STATE_FULLSCREEN = data->videodata->_NET_WM_STATE_FULLSCREEN;

if (X11_IsWindowMapped(_this, window)) {
XEvent e;

e.xany.type = ClientMessage;
e.xclient.message_type = _NET_WM_STATE;
e.xclient.format = 32;
e.xclient.window = data->xwindow;
e.xclient.data.l[0] =
maximized ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
e.xclient.data.l[1] = _NET_WM_STATE_MAXIMIZED_VERT;
e.xclient.data.l[2] = _NET_WM_STATE_MAXIMIZED_HORZ;
e.xclient.data.l[3] = 0l;

XSendEvent(display, RootWindow(display, displaydata->screen), 0,
SubstructureNotifyMask | SubstructureRedirectMask, &e);
} else {
int count = 0;
Atom atoms[3];

if (window->flags & SDL_WINDOW_FULLSCREEN) {
atoms[count++] = _NET_WM_STATE_FULLSCREEN;
}
if (maximized) {
atoms[count++] = _NET_WM_STATE_MAXIMIZED_VERT;
atoms[count++] = _NET_WM_STATE_MAXIMIZED_HORZ;
}
if (count > 0) {
XChangeProperty(display, data->xwindow, _NET_WM_STATE, XA_ATOM, 32,
PropModeReplace, (unsigned char *)atoms, count);
} else {
XDeleteProperty(display, data->xwindow, _NET_WM_STATE);
}
}
}

void
Expand Down Expand Up @@ -993,7 +1036,7 @@ X11_SetWindowGrab(_THIS, SDL_Window * window)
SDL_bool oldstyle_fullscreen;

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

if (((window->flags & SDL_WINDOW_INPUT_GRABBED) || oldstyle_fullscreen)
&& (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
Expand Down

0 comments on commit 02700cb

Please sign in to comment.