src/video/x11/SDL_x11window.c
changeset 6487 b18a011ecc45
parent 6486 e3264eea9607
child 6488 7b2f712bdf1a
     1.1 --- a/src/video/x11/SDL_x11window.c	Fri Sep 28 01:36:26 2012 -0700
     1.2 +++ b/src/video/x11/SDL_x11window.c	Fri Sep 28 01:51:51 2012 -0700
     1.3 @@ -114,15 +114,18 @@
     1.4      return ret;
     1.5  }
     1.6  
     1.7 -int
     1.8 -X11_GetWMStateProperty(_THIS, Uint32 flags, Atom atoms[5])
     1.9 +void
    1.10 +X11_SetNetWMState(_THIS, Window xwindow, Uint32 flags)
    1.11  {
    1.12      SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
    1.13 +    Display *display = videodata->display;
    1.14 +    Atom _NET_WM_STATE = videodata->_NET_WM_STATE;
    1.15      /*Atom _NET_WM_STATE_HIDDEN = videodata->_NET_WM_STATE_HIDDEN;*/
    1.16      Atom _NET_WM_STATE_FOCUSED = videodata->_NET_WM_STATE_FOCUSED;
    1.17      Atom _NET_WM_STATE_MAXIMIZED_VERT = videodata->_NET_WM_STATE_MAXIMIZED_VERT;
    1.18      Atom _NET_WM_STATE_MAXIMIZED_HORZ = videodata->_NET_WM_STATE_MAXIMIZED_HORZ;
    1.19      Atom _NET_WM_STATE_FULLSCREEN = videodata->_NET_WM_STATE_FULLSCREEN;
    1.20 +    Atom atoms[5];
    1.21      int count = 0;
    1.22  
    1.23      /* The window manager sets this property, we shouldn't set it.
    1.24 @@ -143,14 +146,19 @@
    1.25      if (flags & SDL_WINDOW_FULLSCREEN) {
    1.26          atoms[count++] = _NET_WM_STATE_FULLSCREEN;
    1.27      }
    1.28 -    return count;
    1.29 +    if (count > 0) {
    1.30 +        XChangeProperty(display, xwindow, _NET_WM_STATE, XA_ATOM, 32,
    1.31 +                        PropModeReplace, (unsigned char *)atoms, count);
    1.32 +    } else {
    1.33 +        XDeleteProperty(display, xwindow, _NET_WM_STATE);
    1.34 +    }
    1.35  }
    1.36  
    1.37  Uint32
    1.38 -X11_GetNetWMState(_THIS, SDL_Window * window)
    1.39 +X11_GetNetWMState(_THIS, Window xwindow)
    1.40  {
    1.41 -    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    1.42      SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
    1.43 +    Display *display = videodata->display;
    1.44      Atom _NET_WM_STATE = videodata->_NET_WM_STATE;
    1.45      Atom _NET_WM_STATE_HIDDEN = videodata->_NET_WM_STATE_HIDDEN;
    1.46      Atom _NET_WM_STATE_FOCUSED = videodata->_NET_WM_STATE_FOCUSED;
    1.47 @@ -164,7 +172,7 @@
    1.48      long maxLength = 1024;
    1.49      Uint32 flags = 0;
    1.50  
    1.51 -    if (XGetWindowProperty(videodata->display, data->xwindow, _NET_WM_STATE,
    1.52 +    if (XGetWindowProperty(display, xwindow, _NET_WM_STATE,
    1.53                             0l, maxLength, False, XA_ATOM, &actualType,
    1.54                             &actualFormat, &numItems, &bytesAfter,
    1.55                             &propertyValue) == Success) {
    1.56 @@ -214,8 +222,6 @@
    1.57          SDL_OutOfMemory();
    1.58          return -1;
    1.59      }
    1.60 -    window->driverdata = data;
    1.61 -
    1.62      data->window = window;
    1.63      data->xwindow = w;
    1.64  #ifdef X_HAVE_UTF8_STRING
    1.65 @@ -269,7 +275,7 @@
    1.66          data->colormap = attrib.colormap;
    1.67      }
    1.68  
    1.69 -    window->flags |= X11_GetNetWMState(_this, window);
    1.70 +    window->flags |= X11_GetNetWMState(_this, w);
    1.71  
    1.72      {
    1.73          Window FocalWindow;
    1.74 @@ -290,6 +296,7 @@
    1.75      }
    1.76  
    1.77      /* All done! */
    1.78 +    window->driverdata = data;
    1.79      return 0;
    1.80  }
    1.81  
    1.82 @@ -342,8 +349,6 @@
    1.83      Atom _NET_WM_WINDOW_TYPE;
    1.84      Atom _NET_WM_WINDOW_TYPE_NORMAL;
    1.85      Atom _NET_WM_PID;
    1.86 -    int wmstate_count;
    1.87 -    Atom wmstate_atoms[5];
    1.88      Uint32 fevent = 0;
    1.89  
    1.90  #if SDL_VIDEO_OPENGL_GLX || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
    1.91 @@ -528,14 +533,7 @@
    1.92      }
    1.93  
    1.94      /* Set the window manager state */
    1.95 -    wmstate_count = X11_GetWMStateProperty(_this, window->flags, wmstate_atoms);
    1.96 -    if (wmstate_count > 0) {
    1.97 -        XChangeProperty(display, w, data->_NET_WM_STATE, XA_ATOM, 32,
    1.98 -                        PropModeReplace,
    1.99 -                        (unsigned char *)wmstate_atoms, wmstate_count);
   1.100 -    } else {
   1.101 -        XDeleteProperty(display, w, data->_NET_WM_STATE);
   1.102 -    }
   1.103 +    X11_SetNetWMState(_this, w, window->flags);
   1.104  
   1.105      /* Let the window manager know we're a "normal" window */
   1.106      _NET_WM_WINDOW_TYPE = XInternAtom(display, "_NET_WM_WINDOW_TYPE", False);
   1.107 @@ -875,9 +873,7 @@
   1.108          XSendEvent(display, RootWindow(display, displaydata->screen), 0,
   1.109                     SubstructureNotifyMask | SubstructureRedirectMask, &e);
   1.110      } else {
   1.111 -        int count;
   1.112          Uint32 flags;
   1.113 -        Atom atoms[5];
   1.114  
   1.115          flags = window->flags;
   1.116          if (maximized) {
   1.117 @@ -885,13 +881,7 @@
   1.118          } else {
   1.119              flags &= ~SDL_WINDOW_MAXIMIZED;
   1.120          }
   1.121 -        count = X11_GetWMStateProperty(_this, flags, atoms);
   1.122 -        if (count > 0) {
   1.123 -            XChangeProperty(display, data->xwindow, _NET_WM_STATE, XA_ATOM, 32,
   1.124 -                            PropModeReplace, (unsigned char *)atoms, count);
   1.125 -        } else {
   1.126 -            XDeleteProperty(display, data->xwindow, _NET_WM_STATE);
   1.127 -        }
   1.128 +        X11_SetNetWMState(_this, data->xwindow, flags);
   1.129      }
   1.130      XFlush(display);
   1.131  }
   1.132 @@ -970,9 +960,7 @@
   1.133          XSendEvent(display, RootWindow(display, displaydata->screen), 0,
   1.134                     SubstructureNotifyMask | SubstructureRedirectMask, &e);
   1.135      } else {
   1.136 -        int count;
   1.137          Uint32 flags;
   1.138 -        Atom atoms[5];
   1.139  
   1.140          flags = window->flags;
   1.141          if (fullscreen) {
   1.142 @@ -980,13 +968,7 @@
   1.143          } else {
   1.144              flags &= ~SDL_WINDOW_FULLSCREEN;
   1.145          }
   1.146 -        count = X11_GetWMStateProperty(_this, flags, atoms);
   1.147 -        if (count > 0) {
   1.148 -            XChangeProperty(display, data->xwindow, _NET_WM_STATE, XA_ATOM, 32,
   1.149 -                            PropModeReplace, (unsigned char *)atoms, count);
   1.150 -        } else {
   1.151 -            XDeleteProperty(display, data->xwindow, _NET_WM_STATE);
   1.152 -        }
   1.153 +        X11_SetNetWMState(_this, data->xwindow, flags);
   1.154      }
   1.155      XFlush(display);
   1.156  }