src/video/x11/SDL_x11window.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 25 Aug 2008 06:33:00 +0000
changeset 2710 44e49d3fa6cf
parent 2325 c7bcf84ba1b9
child 2718 abacf2555bb4
permissions -rw-r--r--
Final merge of Google Summer of Code 2008 work...

Many-mouse and tablet support
by Szymon Wilczek, mentored by Ryan C. Gordon

Everything concerning the project is noted on the wiki:
http://wilku.ravenlord.ws/doku.php?id=start
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2006 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Lesser General Public
     7     License as published by the Free Software Foundation; either
     8     version 2.1 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Lesser General Public License for more details.
    14 
    15     You should have received a copy of the GNU Lesser General Public
    16     License along with this library; if not, write to the Free Software
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 #include "SDL_config.h"
    23 
    24 #include "SDL_syswm.h"
    25 #include "../SDL_sysvideo.h"
    26 #include "../../events/SDL_keyboard_c.h"
    27 
    28 #include "SDL_x11video.h"
    29 #include "../Xext/extensions/StdCmap.h"
    30 
    31 static int
    32 SetupWindowData(_THIS, SDL_Window * window, Window w, BOOL created)
    33 {
    34     SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
    35     SDL_WindowData *data;
    36     int numwindows = videodata->numwindows;
    37     int windowlistlength = videodata->windowlistlength;
    38     SDL_WindowData **windowlist = videodata->windowlist;
    39     int index;
    40 
    41     /* Allocate the window data */
    42     data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
    43     if (!data) {
    44         SDL_OutOfMemory();
    45         return -1;
    46     }
    47     data->windowID = window->id;
    48     data->window = w;
    49 #ifdef X_HAVE_UTF8_STRING
    50     if (SDL_X11_HAVE_UTF8) {
    51         data->ic =
    52             pXCreateIC(videodata->im, XNClientWindow, w, XNFocusWindow, w,
    53                        XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
    54                        XNResourceName, videodata->classname, XNResourceClass,
    55                        videodata->classname, NULL);
    56     }
    57 #endif
    58     data->created = created;
    59     data->videodata = videodata;
    60 
    61     /* Associate the data with the window */
    62 
    63     if (numwindows < windowlistlength) {
    64         windowlist[numwindows] = data;
    65         videodata->numwindows++;
    66     } else {
    67         windowlist =
    68             (SDL_WindowData **) SDL_realloc(windowlist,
    69                                             (numwindows +
    70                                              1) * sizeof(*windowlist));
    71         if (!windowlist) {
    72             SDL_OutOfMemory();
    73             SDL_free(data);
    74             return -1;
    75         }
    76         windowlist[numwindows] = data;
    77         videodata->numwindows++;
    78         videodata->windowlistlength++;
    79         videodata->windowlist = windowlist;
    80     }
    81 
    82     /* Fill in the SDL window with the window data */
    83     {
    84         XWindowAttributes attrib;
    85 
    86         XGetWindowAttributes(data->videodata->display, w, &attrib);
    87         window->x = attrib.x;
    88         window->y = attrib.y;
    89         window->w = attrib.width;
    90         window->h = attrib.height;
    91         if (attrib.map_state != IsUnmapped) {
    92             window->flags |= SDL_WINDOW_SHOWN;
    93         } else {
    94             window->flags &= ~SDL_WINDOW_SHOWN;
    95         }
    96     }
    97     /* FIXME: How can I tell?
    98        {
    99        DWORD style = GetWindowLong(hwnd, GWL_STYLE);
   100        if (style & WS_VISIBLE) {
   101        if (style & (WS_BORDER | WS_THICKFRAME)) {
   102        window->flags &= ~SDL_WINDOW_BORDERLESS;
   103        } else {
   104        window->flags |= SDL_WINDOW_BORDERLESS;
   105        }
   106        if (style & WS_THICKFRAME) {
   107        window->flags |= SDL_WINDOW_RESIZABLE;
   108        } else {
   109        window->flags &= ~SDL_WINDOW_RESIZABLE;
   110        }
   111        if (style & WS_MAXIMIZE) {
   112        window->flags |= SDL_WINDOW_MAXIMIZED;
   113        } else {
   114        window->flags &= ~SDL_WINDOW_MAXIMIZED;
   115        }
   116        if (style & WS_MINIMIZE) {
   117        window->flags |= SDL_WINDOW_MINIMIZED;
   118        } else {
   119        window->flags &= ~SDL_WINDOW_MINIMIZED;
   120        }
   121        }
   122        if (GetFocus() == hwnd) {
   123        int index = data->videodata->keyboard;
   124        window->flags |= SDL_WINDOW_INPUT_FOCUS;
   125        SDL_SetKeyboardFocus(index, data->windowID);
   126 
   127        if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
   128        RECT rect;
   129        GetClientRect(hwnd, &rect);
   130        ClientToScreen(hwnd, (LPPOINT) & rect);
   131        ClientToScreen(hwnd, (LPPOINT) & rect + 1);
   132        ClipCursor(&rect);
   133        }
   134        }
   135      */
   136 
   137     /* All done! */
   138     window->driverdata = data;
   139     return 0;
   140 }
   141 
   142 int
   143 X11_CreateWindow(_THIS, SDL_Window * window)
   144 {
   145     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
   146     SDL_DisplayData *displaydata =
   147         (SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata;
   148     Visual *visual;
   149     int depth;
   150     XSetWindowAttributes xattr;
   151     int x, y;
   152     Window w;
   153     XSizeHints *sizehints;
   154     XWMHints *wmhints;
   155     XClassHint *classhints;
   156     extern XEventClass SDL_XEvents[];
   157     extern int SDL_NumOfXEvents;
   158 
   159 #if SDL_VIDEO_DRIVER_X11_XINERAMA
   160 /* FIXME
   161     if ( use_xinerama ) {
   162         x = xinerama_info.x_org;
   163         y = xinerama_info.y_org;
   164     }
   165 */
   166 #endif
   167 #ifdef SDL_VIDEO_OPENGL_GLX
   168     if (window->flags & SDL_WINDOW_OPENGL) {
   169         XVisualInfo *vinfo;
   170 
   171         if (X11_GL_Initialize(_this) < 0) {
   172             return -1;
   173         }
   174         vinfo = X11_GL_GetVisual(_this, data->display, displaydata->screen);
   175         if (!vinfo) {
   176             return -1;
   177         }
   178         visual = vinfo->visual;
   179         depth = vinfo->depth;
   180         XFree(vinfo);
   181     } else
   182 #endif
   183     {
   184         visual = displaydata->visual;
   185         depth = displaydata->depth;
   186     }
   187 
   188     if (window->flags & SDL_WINDOW_FULLSCREEN) {
   189         xattr.override_redirect = True;
   190     } else {
   191         xattr.override_redirect = False;
   192     }
   193     xattr.background_pixel = 0;
   194     xattr.border_pixel = 0;
   195 
   196     if (visual->class == DirectColor || visual->class == PseudoColor) {
   197         int nmaps;
   198         XStandardColormap cmap;
   199         XStandardColormap *stdmaps;
   200         XColor *colorcells;
   201         Colormap colormap;
   202         Bool found = False;
   203         int i;
   204         int ncolors;
   205         int rmax, gmax, bmax;
   206         int rmul, gmul, bmul;
   207 
   208         if (colormap =
   209             X11_LookupColormap(data->display, displaydata->screen,
   210                                visual->visualid)) {
   211             xattr.colormap = colormap;
   212         } else {
   213             /* check to see if the colormap we need already exists */
   214             if (0 != XGetRGBColormaps(data->display,
   215                                       RootWindow(data->display,
   216                                                  displaydata->screen),
   217                                       &stdmaps, &nmaps, XA_RGB_BEST_MAP)) {
   218                 for (i = 0; i < nmaps; i++) {
   219                     if (stdmaps[i].visualid == visual->visualid) {
   220                         SDL_memcpy(&cmap, &stdmaps[i],
   221                                    sizeof(XStandardColormap));
   222                         found = True;
   223                         break;
   224                     }
   225                 }
   226                 XFree(stdmaps);
   227             }
   228 
   229             /* it doesn't exist, so create it */
   230             if (!found) {
   231                 int max = visual->map_entries - 1;
   232                 stdmaps =
   233                     XmuStandardColormap(data->display, displaydata->screen,
   234                                         visual->visualid, depth,
   235                                         XA_RGB_BEST_MAP, None, max, max, max);
   236                 if (NULL == stdmaps || stdmaps->visualid != visual->visualid) {
   237                     SDL_SetError
   238                         ("Couldn't create window:XA_RGB_BEST_MAP not found and could not be created");
   239                     return -1;
   240                 }
   241                 SDL_memcpy(&cmap, stdmaps, sizeof(XStandardColormap));
   242                 XFree(stdmaps);
   243             }
   244 
   245             /* OK, we have the best color map, now copy it for use by the
   246                program */
   247 
   248             colorcells = SDL_malloc(visual->map_entries * sizeof(XColor));
   249             if (NULL == colorcells) {
   250                 SDL_SetError("out of memory in X11_CreateWindow");
   251                 return -1;
   252             }
   253             ncolors = visual->map_entries;
   254             rmax = cmap.red_max + 1;
   255             gmax = cmap.blue_max + 1;
   256             bmax = cmap.green_max + 1;
   257 
   258             rmul = cmap.red_mult;
   259             gmul = cmap.blue_mult;
   260             bmul = cmap.green_mult;
   261 
   262             /* build the color table pixel values */
   263             for (i = 0; i < ncolors; i++) {
   264                 Uint32 red = (rmax * i) / ncolors;
   265                 Uint32 green = (gmax * i) / ncolors;
   266                 Uint32 blue = (bmax * i) / ncolors;
   267 
   268                 colorcells[i].pixel =
   269                     (red * rmul) | (green * gmul) | (blue * bmul);
   270             }
   271             XQueryColors(data->display, cmap.colormap, colorcells, ncolors);
   272             colormap = XCreateColormap(data->display,
   273                                        RootWindow(data->display,
   274                                                   displaydata->screen),
   275                                        visual, AllocAll);
   276             XStoreColors(data->display, colormap, colorcells, ncolors);
   277             SDL_free(colorcells);
   278 
   279             xattr.colormap = colormap;
   280             X11_TrackColormap(data->display, displaydata->screen, colormap,
   281                               &cmap, visual);
   282         }
   283     } else {
   284         xattr.colormap =
   285             XCreateColormap(data->display,
   286                             RootWindow(data->display, displaydata->screen),
   287                             visual, AllocNone);
   288     }
   289 
   290     if (window->x == SDL_WINDOWPOS_CENTERED) {
   291         x = (DisplayWidth(data->display, displaydata->screen) -
   292              window->w) / 2;
   293     } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
   294         x = 0;
   295     } else {
   296         x = window->x;
   297     }
   298     if (window->y == SDL_WINDOWPOS_CENTERED) {
   299         y = (DisplayHeight(data->display, displaydata->screen) -
   300              window->h) / 2;
   301     } else if (window->y == SDL_WINDOWPOS_UNDEFINED) {
   302         y = 0;
   303     } else {
   304         y = window->y;
   305     }
   306 
   307     w = XCreateWindow(data->display,
   308                       RootWindow(data->display, displaydata->screen), x, y,
   309                       window->w, window->h, 0, depth, InputOutput, visual,
   310                       (CWOverrideRedirect | CWBackPixel | CWBorderPixel |
   311                        CWColormap), &xattr);
   312     if (!w) {
   313 #ifdef SDL_VIDEO_OPENGL_GLX
   314         if (window->flags & SDL_WINDOW_OPENGL) {
   315             X11_GL_Shutdown(_this);
   316         }
   317 #endif
   318         SDL_SetError("Couldn't create window");
   319         return -1;
   320     }
   321 
   322     sizehints = XAllocSizeHints();
   323     if (sizehints) {
   324         if (window->flags & SDL_WINDOW_RESIZABLE) {
   325             sizehints->min_width = 32;
   326             sizehints->min_height = 32;
   327             sizehints->max_height = 4096;
   328             sizehints->max_width = 4096;
   329         } else {
   330             sizehints->min_width = sizehints->max_width = window->w;
   331             sizehints->min_height = sizehints->max_height = window->h;
   332         }
   333         sizehints->flags = PMaxSize | PMinSize;
   334         if (!(window->flags & SDL_WINDOW_FULLSCREEN)
   335             && window->x != SDL_WINDOWPOS_UNDEFINED
   336             && window->y != SDL_WINDOWPOS_UNDEFINED) {
   337             sizehints->x = x;
   338             sizehints->y = y;
   339             sizehints->flags |= USPosition;
   340         }
   341         XSetWMNormalHints(data->display, w, sizehints);
   342         XFree(sizehints);
   343     }
   344 
   345     if (window->flags & SDL_WINDOW_BORDERLESS) {
   346         SDL_bool set;
   347         Atom WM_HINTS;
   348 
   349         /* We haven't modified the window manager hints yet */
   350         set = SDL_FALSE;
   351 
   352         /* First try to set MWM hints */
   353         WM_HINTS = XInternAtom(data->display, "_MOTIF_WM_HINTS", True);
   354         if (WM_HINTS != None) {
   355             /* Hints used by Motif compliant window managers */
   356             struct
   357             {
   358                 unsigned long flags;
   359                 unsigned long functions;
   360                 unsigned long decorations;
   361                 long input_mode;
   362                 unsigned long status;
   363             } MWMHints = {
   364             (1L << 1), 0, 0, 0, 0};
   365 
   366             XChangeProperty(data->display, w, WM_HINTS, WM_HINTS, 32,
   367                             PropModeReplace, (unsigned char *) &MWMHints,
   368                             sizeof(MWMHints) / sizeof(long));
   369             set = SDL_TRUE;
   370         }
   371         /* Now try to set KWM hints */
   372         WM_HINTS = XInternAtom(data->display, "KWM_WIN_DECORATION", True);
   373         if (WM_HINTS != None) {
   374             long KWMHints = 0;
   375 
   376             XChangeProperty(data->display, w,
   377                             WM_HINTS, WM_HINTS, 32,
   378                             PropModeReplace,
   379                             (unsigned char *) &KWMHints,
   380                             sizeof(KWMHints) / sizeof(long));
   381             set = SDL_TRUE;
   382         }
   383         /* Now try to set GNOME hints */
   384         WM_HINTS = XInternAtom(data->display, "_WIN_HINTS", True);
   385         if (WM_HINTS != None) {
   386             long GNOMEHints = 0;
   387 
   388             XChangeProperty(data->display, w,
   389                             WM_HINTS, WM_HINTS, 32,
   390                             PropModeReplace,
   391                             (unsigned char *) &GNOMEHints,
   392                             sizeof(GNOMEHints) / sizeof(long));
   393             set = SDL_TRUE;
   394         }
   395         /* Finally set the transient hints if necessary */
   396         if (!set) {
   397             XSetTransientForHint(data->display, w,
   398                                  RootWindow(data->display,
   399                                             displaydata->screen));
   400         }
   401     } else {
   402         SDL_bool set;
   403         Atom WM_HINTS;
   404 
   405         /* We haven't modified the window manager hints yet */
   406         set = SDL_FALSE;
   407 
   408         /* First try to unset MWM hints */
   409         WM_HINTS = XInternAtom(data->display, "_MOTIF_WM_HINTS", True);
   410         if (WM_HINTS != None) {
   411             XDeleteProperty(data->display, w, WM_HINTS);
   412             set = SDL_TRUE;
   413         }
   414         /* Now try to unset KWM hints */
   415         WM_HINTS = XInternAtom(data->display, "KWM_WIN_DECORATION", True);
   416         if (WM_HINTS != None) {
   417             XDeleteProperty(data->display, w, WM_HINTS);
   418             set = SDL_TRUE;
   419         }
   420         /* Now try to unset GNOME hints */
   421         WM_HINTS = XInternAtom(data->display, "_WIN_HINTS", True);
   422         if (WM_HINTS != None) {
   423             XDeleteProperty(data->display, w, WM_HINTS);
   424             set = SDL_TRUE;
   425         }
   426         /* Finally unset the transient hints if necessary */
   427         if (!set) {
   428             /* NOTE: Does this work? */
   429             XSetTransientForHint(data->display, w, None);
   430         }
   431     }
   432 
   433     /* Tell KDE to keep fullscreen windows on top */
   434     if (window->flags & SDL_WINDOW_FULLSCREEN) {
   435         XEvent ev;
   436         long mask;
   437 
   438         SDL_zero(ev);
   439         ev.xclient.type = ClientMessage;
   440         ev.xclient.window = RootWindow(data->display, displaydata->screen);
   441         ev.xclient.message_type =
   442             XInternAtom(data->display, "KWM_KEEP_ON_TOP", False);
   443         ev.xclient.format = 32;
   444         ev.xclient.data.l[0] = w;
   445         ev.xclient.data.l[1] = CurrentTime;
   446         XSendEvent(data->display,
   447                    RootWindow(data->display, displaydata->screen), False,
   448                    SubstructureRedirectMask, &ev);
   449     }
   450 
   451     /* Set the input hints so we get keyboard input */
   452     wmhints = XAllocWMHints();
   453     if (wmhints) {
   454         wmhints->input = True;
   455         wmhints->flags = InputHint;
   456         XSetWMHints(data->display, w, wmhints);
   457         XFree(wmhints);
   458     }
   459 
   460     /* Set the class hints so we can get an icon (AfterStep) */
   461     classhints = XAllocClassHint();
   462     if (classhints != NULL) {
   463         classhints->res_name = data->classname;
   464         classhints->res_class = data->classname;
   465         XSetClassHint(data->display, w, classhints);
   466         XFree(classhints);
   467     }
   468 
   469     /* Allow the window to be deleted by the window manager */
   470     XSetWMProtocols(data->display, w, &data->WM_DELETE_WINDOW, 1);
   471 
   472     if (SetupWindowData(_this, window, w, SDL_TRUE) < 0) {
   473 #ifdef SDL_VIDEO_OPENGL_GLX
   474         if (window->flags & SDL_WINDOW_OPENGL) {
   475             X11_GL_Shutdown(_this);
   476         }
   477 #endif
   478         XDestroyWindow(data->display, w);
   479         return -1;
   480     }
   481 #ifdef X_HAVE_UTF8_STRING
   482     {
   483         Uint32 fevent = 0;
   484         pXGetICValues(((SDL_WindowData *) window->driverdata)->ic,
   485                       XNFilterEvents, &fevent, NULL);
   486         XMapWindow(data->display, w);
   487         XSelectInput(data->display, w,
   488                      (FocusChangeMask | EnterWindowMask | LeaveWindowMask |
   489                       ExposureMask | ButtonPressMask | ButtonReleaseMask |
   490                       PointerMotionMask | KeyPressMask | KeyReleaseMask |
   491                       PropertyChangeMask | StructureNotifyMask |
   492                       KeymapStateMask | fevent));
   493     }
   494 #else
   495     XMapWindow(data->display, w);
   496     XSelectInput(data->display, w,
   497                  (FocusChangeMask | EnterWindowMask | LeaveWindowMask |
   498                   ExposureMask | ButtonPressMask | ButtonReleaseMask |
   499                   PointerMotionMask | KeyPressMask | KeyReleaseMask |
   500                   PropertyChangeMask | StructureNotifyMask |
   501                   KeymapStateMask));
   502 #endif
   503 
   504     /* we're informing the display what extension events we want to receive from it */
   505     XSelectExtensionEvent(data->display, w, SDL_XEvents, SDL_NumOfXEvents);
   506 
   507     return 0;
   508 }
   509 
   510 int
   511 X11_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
   512 {
   513     Window w = (Window) data;
   514 
   515     /* FIXME: Query the title from the existing window */
   516 
   517     if (SetupWindowData(_this, window, w, SDL_FALSE) < 0) {
   518         return -1;
   519     }
   520     return 0;
   521 }
   522 
   523 void
   524 X11_SetWindowTitle(_THIS, SDL_Window * window)
   525 {
   526     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   527     Display *display = data->videodata->display;
   528     XTextProperty titleprop, iconprop;
   529     Status status;
   530     const char *title = window->title;
   531     const char *icon = NULL;
   532 
   533 #ifdef X_HAVE_UTF8_STRING
   534     Atom _NET_WM_NAME = 0;
   535     Atom _NET_WM_ICON_NAME = 0;
   536 
   537     /* Look up some useful Atoms */
   538     if (SDL_X11_HAVE_UTF8) {
   539         _NET_WM_NAME = XInternAtom(display, "_NET_WM_NAME", False);
   540         _NET_WM_ICON_NAME = XInternAtom(display, "_NET_WM_ICON_NAME", False);
   541     }
   542 #endif
   543 
   544     if (title != NULL) {
   545         char *title_locale = SDL_iconv_utf8_locale(title);
   546         if (!title_locale) {
   547             SDL_OutOfMemory();
   548             return;
   549         }
   550         status = XStringListToTextProperty(&title_locale, 1, &titleprop);
   551         SDL_free(title_locale);
   552         if (status) {
   553             XSetTextProperty(display, data->window, &titleprop, XA_WM_NAME);
   554             XFree(titleprop.value);
   555         }
   556 #ifdef X_HAVE_UTF8_STRING
   557         if (SDL_X11_HAVE_UTF8) {
   558             status =
   559                 Xutf8TextListToTextProperty(display, (char **) &title, 1,
   560                                             XUTF8StringStyle, &titleprop);
   561             if (status == Success) {
   562                 XSetTextProperty(display, data->window, &titleprop,
   563                                  _NET_WM_NAME);
   564                 XFree(titleprop.value);
   565             }
   566         }
   567 #endif
   568     }
   569     if (icon != NULL) {
   570         char *icon_locale = SDL_iconv_utf8_locale(icon);
   571         if (!icon_locale) {
   572             SDL_OutOfMemory();
   573             return;
   574         }
   575         status = XStringListToTextProperty(&icon_locale, 1, &iconprop);
   576         SDL_free(icon_locale);
   577         if (status) {
   578             XSetTextProperty(display, data->window, &iconprop,
   579                              XA_WM_ICON_NAME);
   580             XFree(iconprop.value);
   581         }
   582 #ifdef X_HAVE_UTF8_STRING
   583         if (SDL_X11_HAVE_UTF8) {
   584             status =
   585                 Xutf8TextListToTextProperty(display, (char **) &icon, 1,
   586                                             XUTF8StringStyle, &iconprop);
   587             if (status == Success) {
   588                 XSetTextProperty(display, data->window, &iconprop,
   589                                  _NET_WM_ICON_NAME);
   590                 XFree(iconprop.value);
   591             }
   592         }
   593 #endif
   594     }
   595 }
   596 
   597 void
   598 X11_SetWindowPosition(_THIS, SDL_Window * window)
   599 {
   600     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   601     SDL_DisplayData *displaydata =
   602         (SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata;
   603     Display *display = data->videodata->display;
   604 
   605     XMoveWindow(display, data->window, window->x, window->y);
   606 }
   607 
   608 void
   609 X11_SetWindowSize(_THIS, SDL_Window * window)
   610 {
   611     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   612     Display *display = data->videodata->display;
   613 
   614     XMoveWindow(display, data->window, window->w, window->h);
   615 }
   616 
   617 void
   618 X11_ShowWindow(_THIS, SDL_Window * window)
   619 {
   620     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   621     Display *display = data->videodata->display;
   622 
   623     XMapRaised(display, data->window);
   624 }
   625 
   626 void
   627 X11_HideWindow(_THIS, SDL_Window * window)
   628 {
   629     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   630     Display *display = data->videodata->display;
   631 
   632     XUnmapWindow(display, data->window);
   633 }
   634 
   635 void
   636 X11_RaiseWindow(_THIS, SDL_Window * window)
   637 {
   638     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   639     Display *display = data->videodata->display;
   640 
   641     XRaiseWindow(display, data->window);
   642 }
   643 
   644 void
   645 X11_MaximizeWindow(_THIS, SDL_Window * window)
   646 {
   647     /* FIXME: is this even possible? */
   648 }
   649 
   650 void
   651 X11_MinimizeWindow(_THIS, SDL_Window * window)
   652 {
   653     X11_HideWindow(_this, window);
   654 }
   655 
   656 void
   657 X11_RestoreWindow(_THIS, SDL_Window * window)
   658 {
   659     X11_ShowWindow(_this, window);
   660 }
   661 
   662 void
   663 X11_SetWindowGrab(_THIS, SDL_Window * window)
   664 {
   665     /* FIXME */
   666 }
   667 
   668 void
   669 X11_DestroyWindow(_THIS, SDL_Window * window)
   670 {
   671     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   672     window->driverdata = NULL;
   673 
   674     if (data) {
   675         SDL_VideoData *videodata = (SDL_VideoData *) data->videodata;
   676         Display *display = videodata->display;
   677         int numwindows = videodata->numwindows;
   678         SDL_WindowData **windowlist = videodata->windowlist;
   679         int i;
   680 
   681         if (windowlist) {
   682             for (i = 0; i < numwindows; ++i) {
   683                 if (windowlist[i] && (windowlist[i]->windowID == window->id)) {
   684                     windowlist[i] = windowlist[numwindows - 1];
   685                     windowlist[numwindows - 1] = NULL;
   686                     videodata->numwindows--;
   687                     break;
   688                 }
   689             }
   690         }
   691 #ifdef SDL_VIDEO_OPENGL_GLX
   692         if (window->flags & SDL_WINDOW_OPENGL) {
   693             X11_GL_Shutdown(_this);
   694         }
   695 #endif
   696 #ifdef X_HAVE_UTF8_STRING
   697         if (data->ic) {
   698             XDestroyIC(data->ic);
   699         }
   700 #endif
   701         if (data->created) {
   702             XDestroyWindow(display, data->window);
   703         }
   704         SDL_free(data);
   705     }
   706 }
   707 
   708 SDL_bool
   709 X11_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
   710 {
   711     if (info->version.major <= SDL_MAJOR_VERSION) {
   712         /* FIXME! */
   713         return SDL_TRUE;
   714     } else {
   715         SDL_SetError("Application not compiled with SDL %d.%d\n",
   716                      SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
   717         return SDL_FALSE;
   718     }
   719 }
   720 
   721 /* vi: set ts=4 sw=4 expandtab: */