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