Implemented X11 maximized state control
authorSam Lantinga <slouken@libsdl.org>
Thu, 19 Feb 2009 06:48:25 +0000
changeset 30779b58f26ede81
parent 3076 085e46423377
child 3078 81d15ace9129
Implemented X11 maximized state control
src/video/x11/SDL_x11sym.h
src/video/x11/SDL_x11window.c
     1.1 --- a/src/video/x11/SDL_x11sym.h	Thu Feb 19 04:41:09 2009 +0000
     1.2 +++ b/src/video/x11/SDL_x11sym.h	Thu Feb 19 06:48:25 2009 +0000
     1.3 @@ -70,6 +70,7 @@
     1.4  SDL_X11_SYM(XVisualInfo*,XGetVisualInfo,(Display* a,long b,XVisualInfo* c,int* d),(a,b,c,d),return)
     1.5  SDL_X11_SYM(XWMHints*,XGetWMHints,(Display* a,Window b),(a,b),return)
     1.6  SDL_X11_SYM(Status,XGetWindowAttributes,(Display* a,Window b,XWindowAttributes* c),(a,b,c),return)
     1.7 +SDL_X11_SYM(int,XGetWindowProperty,(Display* a,Window b,Atom c,long d,long e,Bool f,Atom g,Atom* h,int* i,unsigned long* j,unsigned long *k,unsigned char **l),(a,b,c,d,e,f,g,h,i,j,k,l),return)
     1.8  SDL_X11_SYM(int,XGrabKeyboard,(Display* a,Window b,Bool c,int d,int e,Time f),(a,b,c,d,e,f),return)
     1.9  SDL_X11_SYM(int,XGrabPointer,(Display* a,Window b,Bool c,unsigned int d,int e,int f,Window g,Cursor h,Time i),(a,b,c,d,e,f,g,h,i),return)
    1.10  SDL_X11_SYM(int,XGrabServer,(Display* a),(a),return)
     2.1 --- a/src/video/x11/SDL_x11window.c	Thu Feb 19 04:41:09 2009 +0000
     2.2 +++ b/src/video/x11/SDL_x11window.c	Thu Feb 19 06:48:25 2009 +0000
     2.3 @@ -31,6 +31,10 @@
     2.4  #include "SDL_x11gamma.h"
     2.5  #include "../Xext/extensions/StdCmap.h"
     2.6  
     2.7 +#define _NET_WM_STATE_REMOVE    0l
     2.8 +#define _NET_WM_STATE_ADD       1l
     2.9 +#define _NET_WM_STATE_TOGGLE    2l
    2.10 +
    2.11  static void
    2.12  X11_GetDisplaySize(_THIS, SDL_Window * window, int *w, int *h)
    2.13  {
    2.14 @@ -116,6 +120,40 @@
    2.15              window->flags &= ~SDL_WINDOW_SHOWN;
    2.16          }
    2.17      }
    2.18 +
    2.19 +    {
    2.20 +        Atom _NET_WM_STATE = XInternAtom(data->videodata->display, "_NET_WM_STATE", False);
    2.21 +        Atom _NET_WM_STATE_MAXIMIZED_VERT = XInternAtom(data->videodata->display, "_NET_WM_STATE_MAXIMIZED_VERT", False);
    2.22 +        Atom _NET_WM_STATE_MAXIMIZED_HORZ = XInternAtom(data->videodata->display, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
    2.23 +        Atom actualType;
    2.24 +        int actualFormat;
    2.25 +        unsigned long i, numItems, bytesAfter;
    2.26 +        unsigned char *propertyValue = NULL;
    2.27 +        long maxLength = 1024;
    2.28 +
    2.29 +        if (XGetWindowProperty(data->videodata->display, w, _NET_WM_STATE,
    2.30 +            0l, maxLength, False, XA_ATOM, &actualType, &actualFormat,
    2.31 +            &numItems, &bytesAfter, &propertyValue) == Success) {
    2.32 +            Atom *atoms = (Atom *)propertyValue;
    2.33 +            int maximized = 0;
    2.34 +
    2.35 +            for (i = 0; i < numItems; ++i) {
    2.36 +                if (atoms[i] == _NET_WM_STATE_MAXIMIZED_VERT) {
    2.37 +                    maximized |= 1;
    2.38 +                } else if (atoms[i] == _NET_WM_STATE_MAXIMIZED_HORZ) {
    2.39 +                    maximized |= 2;
    2.40 +                }
    2.41 +                /* Might also want to check the following properties:
    2.42 +                   _NET_WM_STATE_ABOVE, _NET_WM_STATE_FULLSCREEN
    2.43 +                */
    2.44 +            }
    2.45 +            if (maximized == 3) {
    2.46 +                window->flags |= SDL_WINDOW_MAXIMIZED;
    2.47 +            }
    2.48 +            XFree(propertyValue);
    2.49 +        }
    2.50 +    }
    2.51 +
    2.52      /* FIXME: How can I tell?
    2.53         {
    2.54         DWORD style = GetWindowLong(hwnd, GWL_STYLE);
    2.55 @@ -857,10 +895,36 @@
    2.56      XRaiseWindow(display, data->window);
    2.57  }
    2.58  
    2.59 +static void
    2.60 +X11_SetWindowMaximized(_THIS, SDL_Window * window, SDL_bool maximized)
    2.61 +{
    2.62 +    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    2.63 +    SDL_DisplayData *displaydata =
    2.64 +        (SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata;
    2.65 +    Display *display = data->videodata->display;
    2.66 +    Atom _NET_WM_STATE = XInternAtom(display, "_NET_WM_STATE", False);
    2.67 +    Atom _NET_WM_STATE_MAXIMIZED_VERT = XInternAtom(display, "_NET_WM_STATE_MAXIMIZED_VERT", False);
    2.68 +    Atom _NET_WM_STATE_MAXIMIZED_HORZ = XInternAtom(display, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
    2.69 +    XEvent e;
    2.70 +
    2.71 +    e.xany.type = ClientMessage;
    2.72 +    e.xany.window = data->window;
    2.73 +    e.xclient.message_type = _NET_WM_STATE;
    2.74 +    e.xclient.format = 32;
    2.75 +    e.xclient.data.l[0] = maximized ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
    2.76 +    e.xclient.data.l[1] = _NET_WM_STATE_MAXIMIZED_VERT;
    2.77 +    e.xclient.data.l[2] = _NET_WM_STATE_MAXIMIZED_HORZ;
    2.78 +    e.xclient.data.l[3] = 0l;
    2.79 +    e.xclient.data.l[4] = 0l;
    2.80 +
    2.81 +    XSendEvent(display, RootWindow(display, displaydata->screen), 0,
    2.82 +               SubstructureNotifyMask|SubstructureRedirectMask, &e);
    2.83 +}
    2.84 +
    2.85  void
    2.86  X11_MaximizeWindow(_THIS, SDL_Window * window)
    2.87  {
    2.88 -    /* FIXME: is this even possible? */
    2.89 +    X11_SetWindowMaximized(_this, window, SDL_TRUE);
    2.90  }
    2.91  
    2.92  void
    2.93 @@ -872,6 +936,7 @@
    2.94  void
    2.95  X11_RestoreWindow(_THIS, SDL_Window * window)
    2.96  {
    2.97 +    X11_SetWindowMaximized(_this, window, SDL_FALSE);
    2.98      X11_ShowWindow(_this, window);
    2.99  }
   2.100