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