src/video/x11/SDL_x11window.c
changeset 3077 9b58f26ede81
parent 3057 089a77aebb7d
child 3078 81d15ace9129
     1.1 --- a/src/video/x11/SDL_x11window.c	Thu Feb 19 04:41:09 2009 +0000
     1.2 +++ b/src/video/x11/SDL_x11window.c	Thu Feb 19 06:48:25 2009 +0000
     1.3 @@ -31,6 +31,10 @@
     1.4  #include "SDL_x11gamma.h"
     1.5  #include "../Xext/extensions/StdCmap.h"
     1.6  
     1.7 +#define _NET_WM_STATE_REMOVE    0l
     1.8 +#define _NET_WM_STATE_ADD       1l
     1.9 +#define _NET_WM_STATE_TOGGLE    2l
    1.10 +
    1.11  static void
    1.12  X11_GetDisplaySize(_THIS, SDL_Window * window, int *w, int *h)
    1.13  {
    1.14 @@ -116,6 +120,40 @@
    1.15              window->flags &= ~SDL_WINDOW_SHOWN;
    1.16          }
    1.17      }
    1.18 +
    1.19 +    {
    1.20 +        Atom _NET_WM_STATE = XInternAtom(data->videodata->display, "_NET_WM_STATE", False);
    1.21 +        Atom _NET_WM_STATE_MAXIMIZED_VERT = XInternAtom(data->videodata->display, "_NET_WM_STATE_MAXIMIZED_VERT", False);
    1.22 +        Atom _NET_WM_STATE_MAXIMIZED_HORZ = XInternAtom(data->videodata->display, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
    1.23 +        Atom actualType;
    1.24 +        int actualFormat;
    1.25 +        unsigned long i, numItems, bytesAfter;
    1.26 +        unsigned char *propertyValue = NULL;
    1.27 +        long maxLength = 1024;
    1.28 +
    1.29 +        if (XGetWindowProperty(data->videodata->display, w, _NET_WM_STATE,
    1.30 +            0l, maxLength, False, XA_ATOM, &actualType, &actualFormat,
    1.31 +            &numItems, &bytesAfter, &propertyValue) == Success) {
    1.32 +            Atom *atoms = (Atom *)propertyValue;
    1.33 +            int maximized = 0;
    1.34 +
    1.35 +            for (i = 0; i < numItems; ++i) {
    1.36 +                if (atoms[i] == _NET_WM_STATE_MAXIMIZED_VERT) {
    1.37 +                    maximized |= 1;
    1.38 +                } else if (atoms[i] == _NET_WM_STATE_MAXIMIZED_HORZ) {
    1.39 +                    maximized |= 2;
    1.40 +                }
    1.41 +                /* Might also want to check the following properties:
    1.42 +                   _NET_WM_STATE_ABOVE, _NET_WM_STATE_FULLSCREEN
    1.43 +                */
    1.44 +            }
    1.45 +            if (maximized == 3) {
    1.46 +                window->flags |= SDL_WINDOW_MAXIMIZED;
    1.47 +            }
    1.48 +            XFree(propertyValue);
    1.49 +        }
    1.50 +    }
    1.51 +
    1.52      /* FIXME: How can I tell?
    1.53         {
    1.54         DWORD style = GetWindowLong(hwnd, GWL_STYLE);
    1.55 @@ -857,10 +895,36 @@
    1.56      XRaiseWindow(display, data->window);
    1.57  }
    1.58  
    1.59 +static void
    1.60 +X11_SetWindowMaximized(_THIS, SDL_Window * window, SDL_bool maximized)
    1.61 +{
    1.62 +    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    1.63 +    SDL_DisplayData *displaydata =
    1.64 +        (SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata;
    1.65 +    Display *display = data->videodata->display;
    1.66 +    Atom _NET_WM_STATE = XInternAtom(display, "_NET_WM_STATE", False);
    1.67 +    Atom _NET_WM_STATE_MAXIMIZED_VERT = XInternAtom(display, "_NET_WM_STATE_MAXIMIZED_VERT", False);
    1.68 +    Atom _NET_WM_STATE_MAXIMIZED_HORZ = XInternAtom(display, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
    1.69 +    XEvent e;
    1.70 +
    1.71 +    e.xany.type = ClientMessage;
    1.72 +    e.xany.window = data->window;
    1.73 +    e.xclient.message_type = _NET_WM_STATE;
    1.74 +    e.xclient.format = 32;
    1.75 +    e.xclient.data.l[0] = maximized ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
    1.76 +    e.xclient.data.l[1] = _NET_WM_STATE_MAXIMIZED_VERT;
    1.77 +    e.xclient.data.l[2] = _NET_WM_STATE_MAXIMIZED_HORZ;
    1.78 +    e.xclient.data.l[3] = 0l;
    1.79 +    e.xclient.data.l[4] = 0l;
    1.80 +
    1.81 +    XSendEvent(display, RootWindow(display, displaydata->screen), 0,
    1.82 +               SubstructureNotifyMask|SubstructureRedirectMask, &e);
    1.83 +}
    1.84 +
    1.85  void
    1.86  X11_MaximizeWindow(_THIS, SDL_Window * window)
    1.87  {
    1.88 -    /* FIXME: is this even possible? */
    1.89 +    X11_SetWindowMaximized(_this, window, SDL_TRUE);
    1.90  }
    1.91  
    1.92  void
    1.93 @@ -872,6 +936,7 @@
    1.94  void
    1.95  X11_RestoreWindow(_THIS, SDL_Window * window)
    1.96  {
    1.97 +    X11_SetWindowMaximized(_this, window, SDL_FALSE);
    1.98      X11_ShowWindow(_this, window);
    1.99  }
   1.100