Simplified the NetWM code a little bit, and it now operates on X11 Window
authorSam Lantinga <slouken@libsdl.org>
Fri, 28 Sep 2012 01:51:51 -0700
changeset 6487b18a011ecc45
parent 6486 e3264eea9607
child 6488 7b2f712bdf1a
Simplified the NetWM code a little bit, and it now operates on X11 Window
src/video/x11/SDL_x11events.c
src/video/x11/SDL_x11window.c
src/video/x11/SDL_x11window.h
     1.1 --- a/src/video/x11/SDL_x11events.c	Fri Sep 28 01:36:26 2012 -0700
     1.2 +++ b/src/video/x11/SDL_x11events.c	Fri Sep 28 01:51:51 2012 -0700
     1.3 @@ -485,7 +485,7 @@
     1.4                     without ever mapping / unmapping them, so we handle that here,
     1.5                     because they use the NETWM protocol to notify us of changes.
     1.6                   */
     1.7 -                Uint32 flags = X11_GetNetWMState(_this, data->window);
     1.8 +                Uint32 flags = X11_GetNetWMState(_this, xevent.xproperty.window);
     1.9                  if ((flags^data->window->flags) & SDL_WINDOW_HIDDEN) {
    1.10                      if (flags & SDL_WINDOW_HIDDEN) {
    1.11                          X11_DispatchUnmapNotify(data);
     2.1 --- a/src/video/x11/SDL_x11window.c	Fri Sep 28 01:36:26 2012 -0700
     2.2 +++ b/src/video/x11/SDL_x11window.c	Fri Sep 28 01:51:51 2012 -0700
     2.3 @@ -114,15 +114,18 @@
     2.4      return ret;
     2.5  }
     2.6  
     2.7 -int
     2.8 -X11_GetWMStateProperty(_THIS, Uint32 flags, Atom atoms[5])
     2.9 +void
    2.10 +X11_SetNetWMState(_THIS, Window xwindow, Uint32 flags)
    2.11  {
    2.12      SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
    2.13 +    Display *display = videodata->display;
    2.14 +    Atom _NET_WM_STATE = videodata->_NET_WM_STATE;
    2.15      /*Atom _NET_WM_STATE_HIDDEN = videodata->_NET_WM_STATE_HIDDEN;*/
    2.16      Atom _NET_WM_STATE_FOCUSED = videodata->_NET_WM_STATE_FOCUSED;
    2.17      Atom _NET_WM_STATE_MAXIMIZED_VERT = videodata->_NET_WM_STATE_MAXIMIZED_VERT;
    2.18      Atom _NET_WM_STATE_MAXIMIZED_HORZ = videodata->_NET_WM_STATE_MAXIMIZED_HORZ;
    2.19      Atom _NET_WM_STATE_FULLSCREEN = videodata->_NET_WM_STATE_FULLSCREEN;
    2.20 +    Atom atoms[5];
    2.21      int count = 0;
    2.22  
    2.23      /* The window manager sets this property, we shouldn't set it.
    2.24 @@ -143,14 +146,19 @@
    2.25      if (flags & SDL_WINDOW_FULLSCREEN) {
    2.26          atoms[count++] = _NET_WM_STATE_FULLSCREEN;
    2.27      }
    2.28 -    return count;
    2.29 +    if (count > 0) {
    2.30 +        XChangeProperty(display, xwindow, _NET_WM_STATE, XA_ATOM, 32,
    2.31 +                        PropModeReplace, (unsigned char *)atoms, count);
    2.32 +    } else {
    2.33 +        XDeleteProperty(display, xwindow, _NET_WM_STATE);
    2.34 +    }
    2.35  }
    2.36  
    2.37  Uint32
    2.38 -X11_GetNetWMState(_THIS, SDL_Window * window)
    2.39 +X11_GetNetWMState(_THIS, Window xwindow)
    2.40  {
    2.41 -    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    2.42      SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
    2.43 +    Display *display = videodata->display;
    2.44      Atom _NET_WM_STATE = videodata->_NET_WM_STATE;
    2.45      Atom _NET_WM_STATE_HIDDEN = videodata->_NET_WM_STATE_HIDDEN;
    2.46      Atom _NET_WM_STATE_FOCUSED = videodata->_NET_WM_STATE_FOCUSED;
    2.47 @@ -164,7 +172,7 @@
    2.48      long maxLength = 1024;
    2.49      Uint32 flags = 0;
    2.50  
    2.51 -    if (XGetWindowProperty(videodata->display, data->xwindow, _NET_WM_STATE,
    2.52 +    if (XGetWindowProperty(display, xwindow, _NET_WM_STATE,
    2.53                             0l, maxLength, False, XA_ATOM, &actualType,
    2.54                             &actualFormat, &numItems, &bytesAfter,
    2.55                             &propertyValue) == Success) {
    2.56 @@ -214,8 +222,6 @@
    2.57          SDL_OutOfMemory();
    2.58          return -1;
    2.59      }
    2.60 -    window->driverdata = data;
    2.61 -
    2.62      data->window = window;
    2.63      data->xwindow = w;
    2.64  #ifdef X_HAVE_UTF8_STRING
    2.65 @@ -269,7 +275,7 @@
    2.66          data->colormap = attrib.colormap;
    2.67      }
    2.68  
    2.69 -    window->flags |= X11_GetNetWMState(_this, window);
    2.70 +    window->flags |= X11_GetNetWMState(_this, w);
    2.71  
    2.72      {
    2.73          Window FocalWindow;
    2.74 @@ -290,6 +296,7 @@
    2.75      }
    2.76  
    2.77      /* All done! */
    2.78 +    window->driverdata = data;
    2.79      return 0;
    2.80  }
    2.81  
    2.82 @@ -342,8 +349,6 @@
    2.83      Atom _NET_WM_WINDOW_TYPE;
    2.84      Atom _NET_WM_WINDOW_TYPE_NORMAL;
    2.85      Atom _NET_WM_PID;
    2.86 -    int wmstate_count;
    2.87 -    Atom wmstate_atoms[5];
    2.88      Uint32 fevent = 0;
    2.89  
    2.90  #if SDL_VIDEO_OPENGL_GLX || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
    2.91 @@ -528,14 +533,7 @@
    2.92      }
    2.93  
    2.94      /* Set the window manager state */
    2.95 -    wmstate_count = X11_GetWMStateProperty(_this, window->flags, wmstate_atoms);
    2.96 -    if (wmstate_count > 0) {
    2.97 -        XChangeProperty(display, w, data->_NET_WM_STATE, XA_ATOM, 32,
    2.98 -                        PropModeReplace,
    2.99 -                        (unsigned char *)wmstate_atoms, wmstate_count);
   2.100 -    } else {
   2.101 -        XDeleteProperty(display, w, data->_NET_WM_STATE);
   2.102 -    }
   2.103 +    X11_SetNetWMState(_this, w, window->flags);
   2.104  
   2.105      /* Let the window manager know we're a "normal" window */
   2.106      _NET_WM_WINDOW_TYPE = XInternAtom(display, "_NET_WM_WINDOW_TYPE", False);
   2.107 @@ -875,9 +873,7 @@
   2.108          XSendEvent(display, RootWindow(display, displaydata->screen), 0,
   2.109                     SubstructureNotifyMask | SubstructureRedirectMask, &e);
   2.110      } else {
   2.111 -        int count;
   2.112          Uint32 flags;
   2.113 -        Atom atoms[5];
   2.114  
   2.115          flags = window->flags;
   2.116          if (maximized) {
   2.117 @@ -885,13 +881,7 @@
   2.118          } else {
   2.119              flags &= ~SDL_WINDOW_MAXIMIZED;
   2.120          }
   2.121 -        count = X11_GetWMStateProperty(_this, flags, atoms);
   2.122 -        if (count > 0) {
   2.123 -            XChangeProperty(display, data->xwindow, _NET_WM_STATE, XA_ATOM, 32,
   2.124 -                            PropModeReplace, (unsigned char *)atoms, count);
   2.125 -        } else {
   2.126 -            XDeleteProperty(display, data->xwindow, _NET_WM_STATE);
   2.127 -        }
   2.128 +        X11_SetNetWMState(_this, data->xwindow, flags);
   2.129      }
   2.130      XFlush(display);
   2.131  }
   2.132 @@ -970,9 +960,7 @@
   2.133          XSendEvent(display, RootWindow(display, displaydata->screen), 0,
   2.134                     SubstructureNotifyMask | SubstructureRedirectMask, &e);
   2.135      } else {
   2.136 -        int count;
   2.137          Uint32 flags;
   2.138 -        Atom atoms[5];
   2.139  
   2.140          flags = window->flags;
   2.141          if (fullscreen) {
   2.142 @@ -980,13 +968,7 @@
   2.143          } else {
   2.144              flags &= ~SDL_WINDOW_FULLSCREEN;
   2.145          }
   2.146 -        count = X11_GetWMStateProperty(_this, flags, atoms);
   2.147 -        if (count > 0) {
   2.148 -            XChangeProperty(display, data->xwindow, _NET_WM_STATE, XA_ATOM, 32,
   2.149 -                            PropModeReplace, (unsigned char *)atoms, count);
   2.150 -        } else {
   2.151 -            XDeleteProperty(display, data->xwindow, _NET_WM_STATE);
   2.152 -        }
   2.153 +        X11_SetNetWMState(_this, data->xwindow, flags);
   2.154      }
   2.155      XFlush(display);
   2.156  }
     3.1 --- a/src/video/x11/SDL_x11window.h	Fri Sep 28 01:36:26 2012 -0700
     3.2 +++ b/src/video/x11/SDL_x11window.h	Fri Sep 28 01:51:51 2012 -0700
     3.3 @@ -42,8 +42,8 @@
     3.4      struct SDL_VideoData *videodata;
     3.5  } SDL_WindowData;
     3.6  
     3.7 -extern int X11_GetWMStateProperty(_THIS, Uint32 flags, Atom atoms[5]);
     3.8 -extern Uint32 X11_GetNetWMState(_THIS, SDL_Window * window);
     3.9 +extern void X11_SetNetWMState(_THIS, Window xwindow, Uint32 flags);
    3.10 +extern Uint32 X11_GetNetWMState(_THIS, Window xwindow);
    3.11  
    3.12  extern int X11_CreateWindow(_THIS, SDL_Window * window);
    3.13  extern int X11_CreateWindowFrom(_THIS, SDL_Window * window, const void *data);