Implemented X11 fullscreen toggling with modern window managers
authorSam Lantinga <slouken@libsdl.org>
Tue, 15 Feb 2011 17:23:02 -0800
changeset 5302b1b9ec9874ba
parent 5301 248c5c7d6e29
child 5303 d4074e52e739
Implemented X11 fullscreen toggling with modern window managers
src/video/x11/SDL_x11video.c
src/video/x11/SDL_x11window.c
src/video/x11/SDL_x11window.h
     1.1 --- a/src/video/x11/SDL_x11video.c	Tue Feb 15 16:41:04 2011 -0800
     1.2 +++ b/src/video/x11/SDL_x11video.c	Tue Feb 15 17:23:02 2011 -0800
     1.3 @@ -201,6 +201,7 @@
     1.4      device->MaximizeWindow = X11_MaximizeWindow;
     1.5      device->MinimizeWindow = X11_MinimizeWindow;
     1.6      device->RestoreWindow = X11_RestoreWindow;
     1.7 +    device->SetWindowFullscreen = X11_SetWindowFullscreen;
     1.8      device->SetWindowGrab = X11_SetWindowGrab;
     1.9      device->DestroyWindow = X11_DestroyWindow;
    1.10      device->CreateWindowFramebuffer = X11_CreateWindowFramebuffer;
     2.1 --- a/src/video/x11/SDL_x11window.c	Tue Feb 15 16:41:04 2011 -0800
     2.2 +++ b/src/video/x11/SDL_x11window.c	Tue Feb 15 17:23:02 2011 -0800
     2.3 @@ -772,7 +772,7 @@
     2.4  }
     2.5  
     2.6  static void
     2.7 -X11_SetWindowMaximized(_THIS, SDL_Window * window, SDL_bool maximized)
     2.8 +SetWindowMaximized(_THIS, SDL_Window * window, SDL_bool maximized)
     2.9  {
    2.10      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    2.11      SDL_DisplayData *displaydata =
    2.12 @@ -823,7 +823,7 @@
    2.13  void
    2.14  X11_MaximizeWindow(_THIS, SDL_Window * window)
    2.15  {
    2.16 -    X11_SetWindowMaximized(_this, window, SDL_TRUE);
    2.17 +    SetWindowMaximized(_this, window, SDL_TRUE);
    2.18  }
    2.19  
    2.20  void
    2.21 @@ -841,10 +841,68 @@
    2.22  void
    2.23  X11_RestoreWindow(_THIS, SDL_Window * window)
    2.24  {
    2.25 -    X11_SetWindowMaximized(_this, window, SDL_FALSE);
    2.26 +    SetWindowMaximized(_this, window, SDL_FALSE);
    2.27      X11_ShowWindow(_this, window);
    2.28  }
    2.29  
    2.30 +static void
    2.31 +SetWindowFullscreen(_THIS, SDL_Window * window, SDL_bool fullscreen)
    2.32 +{
    2.33 +    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    2.34 +    SDL_DisplayData *displaydata =
    2.35 +        (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
    2.36 +    Display *display = data->videodata->display;
    2.37 +    Atom _NET_WM_STATE = data->videodata->_NET_WM_STATE;
    2.38 +    Atom _NET_WM_STATE_MAXIMIZED_VERT = data->videodata->_NET_WM_STATE_MAXIMIZED_VERT;
    2.39 +    Atom _NET_WM_STATE_MAXIMIZED_HORZ = data->videodata->_NET_WM_STATE_MAXIMIZED_HORZ;
    2.40 +    Atom _NET_WM_STATE_FULLSCREEN = data->videodata->_NET_WM_STATE_FULLSCREEN;
    2.41 +
    2.42 +    if (X11_IsWindowMapped(_this, window)) {
    2.43 +        XEvent e;
    2.44 +
    2.45 +        SDL_zero(e);
    2.46 +        e.xany.type = ClientMessage;
    2.47 +        e.xclient.message_type = _NET_WM_STATE;
    2.48 +        e.xclient.format = 32;
    2.49 +        e.xclient.window = data->xwindow;
    2.50 +        e.xclient.data.l[0] =
    2.51 +            fullscreen ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
    2.52 +        e.xclient.data.l[1] = _NET_WM_STATE_FULLSCREEN;
    2.53 +        e.xclient.data.l[3] = 0l;
    2.54 +
    2.55 +        XSendEvent(display, RootWindow(display, displaydata->screen), 0,
    2.56 +                   SubstructureNotifyMask | SubstructureRedirectMask, &e);
    2.57 +    } else {
    2.58 +        int count = 0;
    2.59 +        Atom atoms[3];
    2.60 +
    2.61 +        if (fullscreen) {
    2.62 +            atoms[count++] = _NET_WM_STATE_FULLSCREEN;
    2.63 +        }
    2.64 +        if (window->flags & SDL_WINDOW_MAXIMIZED) {
    2.65 +            atoms[count++] = _NET_WM_STATE_MAXIMIZED_VERT;
    2.66 +            atoms[count++] = _NET_WM_STATE_MAXIMIZED_HORZ;
    2.67 +        }
    2.68 +        if (count > 0) {
    2.69 +            XChangeProperty(display, data->xwindow, _NET_WM_STATE, XA_ATOM, 32,
    2.70 +                            PropModeReplace, (unsigned char *)atoms, count);
    2.71 +        } else {
    2.72 +            XDeleteProperty(display, data->xwindow, _NET_WM_STATE);
    2.73 +        }
    2.74 +    }
    2.75 +    XFlush(display);
    2.76 +}
    2.77 +
    2.78 +void
    2.79 +X11_SetWindowFullscreen(_THIS, SDL_Window * window)
    2.80 +{
    2.81 +    if (FULLSCREEN_VISIBLE(window)) {
    2.82 +        SetWindowFullscreen(_this, window, SDL_TRUE);
    2.83 +    } else {
    2.84 +        SetWindowFullscreen(_this, window, SDL_FALSE);
    2.85 +    }
    2.86 +}
    2.87 +
    2.88  void
    2.89  X11_SetWindowGrab(_THIS, SDL_Window * window)
    2.90  {
     3.1 --- a/src/video/x11/SDL_x11window.h	Tue Feb 15 16:41:04 2011 -0800
     3.2 +++ b/src/video/x11/SDL_x11window.h	Tue Feb 15 17:23:02 2011 -0800
     3.3 @@ -54,6 +54,7 @@
     3.4  extern void X11_MaximizeWindow(_THIS, SDL_Window * window);
     3.5  extern void X11_MinimizeWindow(_THIS, SDL_Window * window);
     3.6  extern void X11_RestoreWindow(_THIS, SDL_Window * window);
     3.7 +extern void X11_SetWindowFullscreen(_THIS, SDL_Window * window);
     3.8  extern void X11_SetWindowGrab(_THIS, SDL_Window * window);
     3.9  extern void X11_DestroyWindow(_THIS, SDL_Window * window);
    3.10  extern SDL_bool X11_GetWindowWMInfo(_THIS, SDL_Window * window,