Let the window manager know we're a "normal" window
authorSam Lantinga <slouken@libsdl.org>
Wed, 14 Jul 2010 00:28:15 -0700
changeset 452150125e8aab94
parent 4520 0c67c4328678
child 4522 a4da6b906abb
Let the window manager know we're a "normal" window
src/video/x11/SDL_x11window.c
     1.1 --- a/src/video/x11/SDL_x11window.c	Wed Jul 14 00:08:46 2010 -0700
     1.2 +++ b/src/video/x11/SDL_x11window.c	Wed Jul 14 00:28:15 2010 -0700
     1.3 @@ -224,6 +224,8 @@
     1.4      SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
     1.5      SDL_DisplayData *displaydata =
     1.6          (SDL_DisplayData *) window->display->driverdata;
     1.7 +    Display *display = data->display;
     1.8 +    int screen = displaydata->screen;
     1.9      Visual *visual;
    1.10      int depth;
    1.11      XSetWindowAttributes xattr;
    1.12 @@ -233,6 +235,8 @@
    1.13      XWMHints *wmhints;
    1.14      XClassHint *classhints;
    1.15      SDL_bool oldstyle_fullscreen;
    1.16 +    Atom _NET_WM_WINDOW_TYPE;
    1.17 +    Atom _NET_WM_WINDOW_TYPE_NORMAL;
    1.18  
    1.19      /* ICCCM2.0-compliant window managers can handle fullscreen windows */
    1.20      if ((window->flags & SDL_WINDOW_FULLSCREEN) && !data->net_wm) {
    1.21 @@ -253,7 +257,7 @@
    1.22      if (window->flags & SDL_WINDOW_OPENGL) {
    1.23          XVisualInfo *vinfo;
    1.24  
    1.25 -        vinfo = X11_GL_GetVisual(_this, data->display, displaydata->screen);
    1.26 +        vinfo = X11_GL_GetVisual(_this, display, screen);
    1.27          if (!vinfo) {
    1.28              return -1;
    1.29          }
    1.30 @@ -266,7 +270,7 @@
    1.31      if (window->flags & SDL_WINDOW_OPENGL) {
    1.32          XVisualInfo *vinfo;
    1.33  
    1.34 -        vinfo = X11_GLES_GetVisual(_this, data->display, displaydata->screen);
    1.35 +        vinfo = X11_GLES_GetVisual(_this, display, screen);
    1.36          if (!vinfo) {
    1.37              return -1;
    1.38          }
    1.39 @@ -305,15 +309,12 @@
    1.40  
    1.41          /* Is the colormap we need already registered in SDL? */
    1.42          if ((colormap =
    1.43 -            X11_LookupColormap(data->display,
    1.44 -                               displaydata->screen, visual->visualid))) {
    1.45 +            X11_LookupColormap(display, screen, visual->visualid))) {
    1.46              xattr.colormap = colormap;
    1.47  /*             printf("found existing colormap\n"); */
    1.48          } else {
    1.49              /* The colormap is not known to SDL so we will create it */
    1.50 -            colormap = XCreateColormap(data->display,
    1.51 -                                       RootWindow(data->display,
    1.52 -                                                  displaydata->screen),
    1.53 +            colormap = XCreateColormap(display, RootWindow(display, screen),
    1.54                                         visual, AllocAll);
    1.55  /*             printf("colormap = %x\n", colormap); */
    1.56  
    1.57 @@ -392,11 +393,10 @@
    1.58              }
    1.59  
    1.60  /*             status = */
    1.61 -/*                 XStoreColors(data->display, colormap, colorcells, ncolors); */
    1.62 +/*                 XStoreColors(display, colormap, colorcells, ncolors); */
    1.63  
    1.64              xattr.colormap = colormap;
    1.65 -            X11_TrackColormap(data->display, displaydata->screen,
    1.66 -                              colormap, visual, NULL);
    1.67 +            X11_TrackColormap(display, screen, colormap, visual, NULL);
    1.68  
    1.69              SDL_free(colorcells);
    1.70          }
    1.71 @@ -412,15 +412,12 @@
    1.72  
    1.73          /* Is the colormap we need already registered in SDL? */
    1.74          if ((colormap =
    1.75 -             X11_LookupColormap(data->display,
    1.76 -                                displaydata->screen, visual->visualid))) {
    1.77 +             X11_LookupColormap(display, screen, visual->visualid))) {
    1.78              xattr.colormap = colormap;
    1.79  /*             printf("found existing colormap\n"); */
    1.80          } else {
    1.81              /* The colormap is not known to SDL so we will create it */
    1.82 -            colormap = XCreateColormap(data->display,
    1.83 -                                       RootWindow(data->display,
    1.84 -                                                  displaydata->screen),
    1.85 +            colormap = XCreateColormap(display, RootWindow(display, screen),
    1.86                                         visual, AllocAll);
    1.87  /*             printf("colormap = %x\n", colormap); */
    1.88  
    1.89 @@ -493,18 +490,16 @@
    1.90              }
    1.91  
    1.92              status =
    1.93 -                XStoreColors(data->display, colormap, colorcells, ncolors);
    1.94 +                XStoreColors(display, colormap, colorcells, ncolors);
    1.95  
    1.96              xattr.colormap = colormap;
    1.97 -            X11_TrackColormap(data->display, displaydata->screen,
    1.98 -                              colormap, visual, colorcells);
    1.99 +            X11_TrackColormap(display, screen, colormap, visual, colorcells);
   1.100  
   1.101              SDL_free(colorcells);
   1.102          }
   1.103      } else {
   1.104          xattr.colormap =
   1.105 -            XCreateColormap(data->display,
   1.106 -                            RootWindow(data->display, displaydata->screen),
   1.107 +            XCreateColormap(display, RootWindow(display, screen),
   1.108                              visual, AllocNone);
   1.109      }
   1.110  
   1.111 @@ -527,8 +522,7 @@
   1.112          y = window->y;
   1.113      }
   1.114  
   1.115 -    w = XCreateWindow(data->display,
   1.116 -                      RootWindow(data->display, displaydata->screen), x, y,
   1.117 +    w = XCreateWindow(display, RootWindow(display, screen), x, y,
   1.118                        window->w, window->h, 0, depth, InputOutput, visual,
   1.119                        (CWOverrideRedirect | CWBackPixel | CWBorderPixel |
   1.120                         CWColormap), &xattr);
   1.121 @@ -565,7 +559,7 @@
   1.122              sizehints->y = y;
   1.123              sizehints->flags |= USPosition;
   1.124          }
   1.125 -        XSetWMNormalHints(data->display, w, sizehints);
   1.126 +        XSetWMNormalHints(display, w, sizehints);
   1.127          XFree(sizehints);
   1.128      }
   1.129  
   1.130 @@ -577,7 +571,7 @@
   1.131          set = SDL_FALSE;
   1.132  
   1.133          /* First try to set MWM hints */
   1.134 -        WM_HINTS = XInternAtom(data->display, "_MOTIF_WM_HINTS", True);
   1.135 +        WM_HINTS = XInternAtom(display, "_MOTIF_WM_HINTS", True);
   1.136          if (WM_HINTS != None) {
   1.137              /* Hints used by Motif compliant window managers */
   1.138              struct
   1.139 @@ -590,40 +584,36 @@
   1.140              } MWMHints = {
   1.141              (1L << 1), 0, 0, 0, 0};
   1.142  
   1.143 -            XChangeProperty(data->display, w, WM_HINTS, WM_HINTS, 32,
   1.144 +            XChangeProperty(display, w, WM_HINTS, WM_HINTS, 32,
   1.145                              PropModeReplace, (unsigned char *) &MWMHints,
   1.146 -                            sizeof(MWMHints) / sizeof(long));
   1.147 +                            sizeof(MWMHints) / 4);
   1.148              set = SDL_TRUE;
   1.149          }
   1.150          /* Now try to set KWM hints */
   1.151 -        WM_HINTS = XInternAtom(data->display, "KWM_WIN_DECORATION", True);
   1.152 +        WM_HINTS = XInternAtom(display, "KWM_WIN_DECORATION", True);
   1.153          if (WM_HINTS != None) {
   1.154              long KWMHints = 0;
   1.155  
   1.156 -            XChangeProperty(data->display, w,
   1.157 -                            WM_HINTS, WM_HINTS, 32,
   1.158 +            XChangeProperty(display, w, WM_HINTS, WM_HINTS, 32,
   1.159                              PropModeReplace,
   1.160                              (unsigned char *) &KWMHints,
   1.161 -                            sizeof(KWMHints) / sizeof(long));
   1.162 +                            sizeof(KWMHints) / 4);
   1.163              set = SDL_TRUE;
   1.164          }
   1.165          /* Now try to set GNOME hints */
   1.166 -        WM_HINTS = XInternAtom(data->display, "_WIN_HINTS", True);
   1.167 +        WM_HINTS = XInternAtom(display, "_WIN_HINTS", True);
   1.168          if (WM_HINTS != None) {
   1.169              long GNOMEHints = 0;
   1.170  
   1.171 -            XChangeProperty(data->display, w,
   1.172 -                            WM_HINTS, WM_HINTS, 32,
   1.173 +            XChangeProperty(display, w, WM_HINTS, WM_HINTS, 32,
   1.174                              PropModeReplace,
   1.175                              (unsigned char *) &GNOMEHints,
   1.176 -                            sizeof(GNOMEHints) / sizeof(long));
   1.177 +                            sizeof(GNOMEHints) / 4);
   1.178              set = SDL_TRUE;
   1.179          }
   1.180          /* Finally set the transient hints if necessary */
   1.181          if (!set) {
   1.182 -            XSetTransientForHint(data->display, w,
   1.183 -                                 RootWindow(data->display,
   1.184 -                                            displaydata->screen));
   1.185 +            XSetTransientForHint(display, w, RootWindow(display, screen));
   1.186          }
   1.187      } else {
   1.188          SDL_bool set;
   1.189 @@ -633,27 +623,27 @@
   1.190          set = SDL_FALSE;
   1.191  
   1.192          /* First try to unset MWM hints */
   1.193 -        WM_HINTS = XInternAtom(data->display, "_MOTIF_WM_HINTS", True);
   1.194 +        WM_HINTS = XInternAtom(display, "_MOTIF_WM_HINTS", True);
   1.195          if (WM_HINTS != None) {
   1.196 -            XDeleteProperty(data->display, w, WM_HINTS);
   1.197 +            XDeleteProperty(display, w, WM_HINTS);
   1.198              set = SDL_TRUE;
   1.199          }
   1.200          /* Now try to unset KWM hints */
   1.201 -        WM_HINTS = XInternAtom(data->display, "KWM_WIN_DECORATION", True);
   1.202 +        WM_HINTS = XInternAtom(display, "KWM_WIN_DECORATION", True);
   1.203          if (WM_HINTS != None) {
   1.204 -            XDeleteProperty(data->display, w, WM_HINTS);
   1.205 +            XDeleteProperty(display, w, WM_HINTS);
   1.206              set = SDL_TRUE;
   1.207          }
   1.208          /* Now try to unset GNOME hints */
   1.209 -        WM_HINTS = XInternAtom(data->display, "_WIN_HINTS", True);
   1.210 +        WM_HINTS = XInternAtom(display, "_WIN_HINTS", True);
   1.211          if (WM_HINTS != None) {
   1.212 -            XDeleteProperty(data->display, w, WM_HINTS);
   1.213 +            XDeleteProperty(display, w, WM_HINTS);
   1.214              set = SDL_TRUE;
   1.215          }
   1.216          /* Finally unset the transient hints if necessary */
   1.217          if (!set) {
   1.218              /* NOTE: Does this work? */
   1.219 -            XSetTransientForHint(data->display, w, None);
   1.220 +            XSetTransientForHint(display, w, None);
   1.221          }
   1.222      }
   1.223  
   1.224 @@ -662,7 +652,7 @@
   1.225      if (wmhints) {
   1.226          wmhints->input = True;
   1.227          wmhints->flags = InputHint;
   1.228 -        XSetWMHints(data->display, w, wmhints);
   1.229 +        XSetWMHints(display, w, wmhints);
   1.230          XFree(wmhints);
   1.231      }
   1.232  
   1.233 @@ -671,7 +661,7 @@
   1.234      if (classhints != NULL) {
   1.235          classhints->res_name = data->classname;
   1.236          classhints->res_class = data->classname;
   1.237 -        XSetClassHint(data->display, w, classhints);
   1.238 +        XSetClassHint(display, w, classhints);
   1.239          XFree(classhints);
   1.240      }
   1.241  
   1.242 @@ -688,16 +678,22 @@
   1.243          e.xclient.data.l[1] = _NET_WM_STATE_FULLSCREEN;
   1.244          e.xclient.data.l[2] = 0l;
   1.245  
   1.246 -        XSendEvent(data->display,
   1.247 -                   RootWindow(data->display, displaydata->screen), 0,
   1.248 +        XSendEvent(display, RootWindow(display, screen), 0,
   1.249                     SubstructureNotifyMask | SubstructureRedirectMask, &e);
   1.250      }
   1.251  
   1.252 +    /* Let the window manager know we're a "normal" window */
   1.253 +    _NET_WM_WINDOW_TYPE = XInternAtom(display, "_NET_WM_WINDOW_TYPE", False);
   1.254 +    _NET_WM_WINDOW_TYPE_NORMAL = XInternAtom(display, "_NET_WM_WINDOW_TYPE_NORMAL", False);
   1.255 +    XChangeProperty(display, w, _NET_WM_WINDOW_TYPE, XA_ATOM, 32,
   1.256 +                    PropModeReplace,
   1.257 +                    (unsigned char *)&_NET_WM_WINDOW_TYPE_NORMAL, 1);
   1.258 +
   1.259      /* Allow the window to be deleted by the window manager */
   1.260 -    XSetWMProtocols(data->display, w, &data->WM_DELETE_WINDOW, 1);
   1.261 +    XSetWMProtocols(display, w, &data->WM_DELETE_WINDOW, 1);
   1.262  
   1.263      if (SetupWindowData(_this, window, w, SDL_TRUE) < 0) {
   1.264 -        XDestroyWindow(data->display, w);
   1.265 +        XDestroyWindow(display, w);
   1.266          return -1;
   1.267      }
   1.268  #ifdef X_HAVE_UTF8_STRING
   1.269 @@ -705,7 +701,7 @@
   1.270          Uint32 fevent = 0;
   1.271          pXGetICValues(((SDL_WindowData *) window->driverdata)->ic,
   1.272                        XNFilterEvents, &fevent, NULL);
   1.273 -        XSelectInput(data->display, w,
   1.274 +        XSelectInput(display, w,
   1.275                       (FocusChangeMask | EnterWindowMask | LeaveWindowMask |
   1.276                        ExposureMask | ButtonPressMask | ButtonReleaseMask |
   1.277                        PointerMotionMask | KeyPressMask | KeyReleaseMask |
   1.278 @@ -714,7 +710,7 @@
   1.279      }
   1.280  #else
   1.281      {
   1.282 -        XSelectInput(data->display, w,
   1.283 +        XSelectInput(display, w,
   1.284                       (FocusChangeMask | EnterWindowMask | LeaveWindowMask |
   1.285                        ExposureMask | ButtonPressMask | ButtonReleaseMask |
   1.286                        PointerMotionMask | KeyPressMask | KeyReleaseMask |