src/video/x11/SDL_x11window.c
author Sam Lantinga <slouken@libsdl.org>
Fri, 30 Jan 2009 06:38:44 +0000
changeset 3052 b7197d7e8566
parent 3044 b36579172f27
child 3057 089a77aebb7d
permissions -rw-r--r--
indent
slouken@1951
     1
/*
slouken@1951
     2
    SDL - Simple DirectMedia Layer
slouken@2859
     3
    Copyright (C) 1997-2009 Sam Lantinga
slouken@1951
     4
slouken@1951
     5
    This library is free software; you can redistribute it and/or
slouken@1951
     6
    modify it under the terms of the GNU Lesser General Public
slouken@1951
     7
    License as published by the Free Software Foundation; either
slouken@1951
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@1951
     9
slouken@1951
    10
    This library is distributed in the hope that it will be useful,
slouken@1951
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@1951
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1951
    13
    Lesser General Public License for more details.
slouken@1951
    14
slouken@1951
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1951
    16
    License along with this library; if not, write to the Free Software
slouken@1951
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@1951
    18
slouken@1951
    19
    Sam Lantinga
slouken@1951
    20
    slouken@libsdl.org
slouken@1951
    21
*/
slouken@1951
    22
#include "SDL_config.h"
slouken@1951
    23
slouken@1951
    24
#include "SDL_syswm.h"
slouken@1951
    25
#include "../SDL_sysvideo.h"
slouken@1951
    26
#include "../../events/SDL_keyboard_c.h"
slouken@2940
    27
#include "../../events/SDL_mouse_c.h"
slouken@1951
    28
slouken@1951
    29
#include "SDL_x11video.h"
slouken@2940
    30
#include "SDL_x11mouse.h"
bob@3009
    31
#include "SDL_x11gamma.h"
bob@2185
    32
#include "../Xext/extensions/StdCmap.h"
slouken@1951
    33
slouken@2931
    34
static void
slouken@2931
    35
X11_GetDisplaySize(_THIS, SDL_Window * window, int *w, int *h)
slouken@2931
    36
{
slouken@2931
    37
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
slouken@2931
    38
    SDL_DisplayData *displaydata =
slouken@2931
    39
        (SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata;
slouken@2931
    40
    XWindowAttributes attr;
slouken@2931
    41
slouken@2931
    42
    XGetWindowAttributes(data->display, RootWindow(data->display,
slouken@2931
    43
                                                   displaydata->screen),
slouken@2931
    44
                         &attr);
slouken@2931
    45
    if (w) {
slouken@2931
    46
        *w = attr.width;
slouken@2931
    47
    }
slouken@2931
    48
    if (h) {
slouken@2931
    49
        *h = attr.height;
slouken@2931
    50
    }
slouken@2931
    51
}
slouken@2931
    52
slouken@1951
    53
static int
slouken@1951
    54
SetupWindowData(_THIS, SDL_Window * window, Window w, BOOL created)
slouken@1951
    55
{
slouken@1951
    56
    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
slouken@1951
    57
    SDL_WindowData *data;
slouken@1951
    58
    int numwindows = videodata->numwindows;
bob@2324
    59
    int windowlistlength = videodata->windowlistlength;
slouken@1951
    60
    SDL_WindowData **windowlist = videodata->windowlist;
bob@2323
    61
    int index;
slouken@1951
    62
slouken@1951
    63
    /* Allocate the window data */
bob@2323
    64
    data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
slouken@1951
    65
    if (!data) {
slouken@1951
    66
        SDL_OutOfMemory();
slouken@1951
    67
        return -1;
slouken@1951
    68
    }
slouken@1951
    69
    data->windowID = window->id;
slouken@1951
    70
    data->window = w;
slouken@1951
    71
#ifdef X_HAVE_UTF8_STRING
slouken@1951
    72
    if (SDL_X11_HAVE_UTF8) {
slouken@1951
    73
        data->ic =
slouken@1951
    74
            pXCreateIC(videodata->im, XNClientWindow, w, XNFocusWindow, w,
slouken@1951
    75
                       XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
slouken@1951
    76
                       XNResourceName, videodata->classname, XNResourceClass,
slouken@1951
    77
                       videodata->classname, NULL);
slouken@1951
    78
    }
slouken@1951
    79
#endif
slouken@1951
    80
    data->created = created;
slouken@1951
    81
    data->videodata = videodata;
slouken@1951
    82
bob@2323
    83
    /* Associate the data with the window */
bob@2324
    84
bob@2324
    85
    if (numwindows < windowlistlength) {
bob@2324
    86
        windowlist[numwindows] = data;
bob@2324
    87
        videodata->numwindows++;
bob@2324
    88
    } else {
bob@2324
    89
        windowlist =
bob@2324
    90
            (SDL_WindowData **) SDL_realloc(windowlist,
bob@2324
    91
                                            (numwindows +
bob@2324
    92
                                             1) * sizeof(*windowlist));
bob@2324
    93
        if (!windowlist) {
bob@2324
    94
            SDL_OutOfMemory();
bob@2324
    95
            SDL_free(data);
bob@2324
    96
            return -1;
bob@2323
    97
        }
bob@2324
    98
        windowlist[numwindows] = data;
bob@2324
    99
        videodata->numwindows++;
bob@2324
   100
        videodata->windowlistlength++;
bob@2324
   101
        videodata->windowlist = windowlist;
bob@2323
   102
    }
bob@2323
   103
slouken@1951
   104
    /* Fill in the SDL window with the window data */
slouken@1951
   105
    {
slouken@1951
   106
        XWindowAttributes attrib;
slouken@1951
   107
slouken@1951
   108
        XGetWindowAttributes(data->videodata->display, w, &attrib);
slouken@1951
   109
        window->x = attrib.x;
slouken@1951
   110
        window->y = attrib.y;
slouken@1951
   111
        window->w = attrib.width;
slouken@1951
   112
        window->h = attrib.height;
slouken@1951
   113
        if (attrib.map_state != IsUnmapped) {
slouken@1951
   114
            window->flags |= SDL_WINDOW_SHOWN;
slouken@1951
   115
        } else {
slouken@1951
   116
            window->flags &= ~SDL_WINDOW_SHOWN;
slouken@1951
   117
        }
slouken@1951
   118
    }
slouken@1951
   119
    /* FIXME: How can I tell?
slouken@1951
   120
       {
slouken@1951
   121
       DWORD style = GetWindowLong(hwnd, GWL_STYLE);
slouken@1951
   122
       if (style & WS_VISIBLE) {
slouken@1951
   123
       if (style & (WS_BORDER | WS_THICKFRAME)) {
slouken@1951
   124
       window->flags &= ~SDL_WINDOW_BORDERLESS;
slouken@1951
   125
       } else {
slouken@1951
   126
       window->flags |= SDL_WINDOW_BORDERLESS;
slouken@1951
   127
       }
slouken@1951
   128
       if (style & WS_THICKFRAME) {
slouken@1951
   129
       window->flags |= SDL_WINDOW_RESIZABLE;
slouken@1951
   130
       } else {
slouken@1951
   131
       window->flags &= ~SDL_WINDOW_RESIZABLE;
slouken@1951
   132
       }
slouken@1951
   133
       if (style & WS_MAXIMIZE) {
slouken@1951
   134
       window->flags |= SDL_WINDOW_MAXIMIZED;
slouken@1951
   135
       } else {
slouken@1951
   136
       window->flags &= ~SDL_WINDOW_MAXIMIZED;
slouken@1951
   137
       }
slouken@1951
   138
       if (style & WS_MINIMIZE) {
slouken@1951
   139
       window->flags |= SDL_WINDOW_MINIMIZED;
slouken@1951
   140
       } else {
slouken@1951
   141
       window->flags &= ~SDL_WINDOW_MINIMIZED;
slouken@1951
   142
       }
slouken@1951
   143
       }
slouken@1951
   144
       if (GetFocus() == hwnd) {
slouken@1951
   145
       int index = data->videodata->keyboard;
slouken@1951
   146
       window->flags |= SDL_WINDOW_INPUT_FOCUS;
slouken@1951
   147
       SDL_SetKeyboardFocus(index, data->windowID);
slouken@1951
   148
slouken@1951
   149
       if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
slouken@1951
   150
       RECT rect;
slouken@1951
   151
       GetClientRect(hwnd, &rect);
slouken@1951
   152
       ClientToScreen(hwnd, (LPPOINT) & rect);
slouken@1951
   153
       ClientToScreen(hwnd, (LPPOINT) & rect + 1);
slouken@1951
   154
       ClipCursor(&rect);
slouken@1951
   155
       }
slouken@1951
   156
       }
slouken@1951
   157
     */
slouken@1951
   158
slouken@1951
   159
    /* All done! */
slouken@1951
   160
    window->driverdata = data;
slouken@1951
   161
    return 0;
slouken@1951
   162
}
slouken@1951
   163
slouken@1951
   164
int
slouken@1951
   165
X11_CreateWindow(_THIS, SDL_Window * window)
slouken@1951
   166
{
slouken@1951
   167
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
slouken@1951
   168
    SDL_DisplayData *displaydata =
slouken@1952
   169
        (SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata;
slouken@1951
   170
    Visual *visual;
slouken@1951
   171
    int depth;
slouken@1951
   172
    XSetWindowAttributes xattr;
slouken@1951
   173
    int x, y;
slouken@1951
   174
    Window w;
slouken@1951
   175
    XSizeHints *sizehints;
slouken@1951
   176
    XWMHints *wmhints;
slouken@1951
   177
    XClassHint *classhints;
slouken@1951
   178
slouken@1951
   179
#if SDL_VIDEO_DRIVER_X11_XINERAMA
slouken@1951
   180
/* FIXME
slouken@1951
   181
    if ( use_xinerama ) {
slouken@1951
   182
        x = xinerama_info.x_org;
slouken@1951
   183
        y = xinerama_info.y_org;
slouken@1951
   184
    }
slouken@1951
   185
*/
slouken@1951
   186
#endif
slouken@1952
   187
#ifdef SDL_VIDEO_OPENGL_GLX
slouken@1951
   188
    if (window->flags & SDL_WINDOW_OPENGL) {
slouken@1952
   189
        XVisualInfo *vinfo;
slouken@1952
   190
slouken@1952
   191
        if (X11_GL_Initialize(_this) < 0) {
slouken@1952
   192
            return -1;
slouken@1952
   193
        }
slouken@1952
   194
        vinfo = X11_GL_GetVisual(_this, data->display, displaydata->screen);
slouken@1952
   195
        if (!vinfo) {
slouken@1952
   196
            return -1;
slouken@1952
   197
        }
slouken@1952
   198
        visual = vinfo->visual;
slouken@1952
   199
        depth = vinfo->depth;
slouken@1952
   200
        XFree(vinfo);
slouken@1952
   201
    } else
slouken@1952
   202
#endif
slouken@1952
   203
    {
slouken@1951
   204
        visual = displaydata->visual;
slouken@1951
   205
        depth = displaydata->depth;
slouken@1951
   206
    }
slouken@1951
   207
slouken@1951
   208
    if (window->flags & SDL_WINDOW_FULLSCREEN) {
slouken@1951
   209
        xattr.override_redirect = True;
slouken@1951
   210
    } else {
slouken@1951
   211
        xattr.override_redirect = False;
slouken@1951
   212
    }
slouken@1951
   213
    xattr.background_pixel = 0;
slouken@1951
   214
    xattr.border_pixel = 0;
bob@2214
   215
slouken@2945
   216
    if (visual->class == PseudoColor) {
bob@3044
   217
        printf("asking for PseudoColor\n");
bob@3044
   218
bob@3044
   219
        Status status;
bob@2214
   220
        XStandardColormap cmap;
bob@2214
   221
        XColor *colorcells;
bob@2214
   222
        Colormap colormap;
slouken@3052
   223
        Sint32 pix;
bob@3044
   224
        Sint32 ncolors;
bob@3044
   225
        Sint32 nbits;
bob@3044
   226
        Sint32 rmax, gmax, bmax;
slouken@3052
   227
        Sint32 rwidth, gwidth, bwidth;
bob@3044
   228
        Sint32 rmask, gmask, bmask;
bob@3044
   229
        Sint32 rshift, gshift, bshift;
slouken@3052
   230
        Sint32 r, g, b;
bob@2185
   231
bob@3044
   232
        /* Is the colormap we need already registered in SDL? */
bob@2214
   233
        if (colormap =
bob@3044
   234
            X11_LookupColormap(data->display,
bob@3044
   235
                               displaydata->screen, visual->visualid)) {
bob@2214
   236
            xattr.colormap = colormap;
bob@3044
   237
/*             printf("found existing colormap\n"); */
bob@2214
   238
        } else {
bob@3044
   239
            /* The colormap is not known to SDL so we will create it */
bob@3044
   240
            colormap = XCreateColormap(data->display,
bob@3044
   241
                                       RootWindow(data->display,
bob@3044
   242
                                                  displaydata->screen),
bob@3044
   243
                                       visual, AllocAll);
bob@3044
   244
/*             printf("colormap = %x\n", colormap); */
bob@3044
   245
bob@3044
   246
            /* If we can't create a colormap, then we must die */
bob@3044
   247
            if (!colormap) {
bob@3044
   248
                SDL_SetError
bob@3044
   249
                    ("Couldn't create window: Could not create writable colormap");
bob@3044
   250
                return -1;
bob@2185
   251
            }
bob@2213
   252
bob@3044
   253
            /* OK, we got a colormap, now fill it in as best as we can */
bob@2214
   254
bob@2214
   255
            colorcells = SDL_malloc(visual->map_entries * sizeof(XColor));
bob@2214
   256
            if (NULL == colorcells) {
bob@2214
   257
                SDL_SetError("out of memory in X11_CreateWindow");
bob@2185
   258
                return -1;
bob@2185
   259
            }
bob@3044
   260
bob@2214
   261
            ncolors = visual->map_entries;
slouken@3052
   262
            nbits = visual->bits_per_rgb;
bob@2214
   263
bob@3044
   264
/* 	    printf("ncolors = %d nbits = %d\n", ncolors, nbits); */
bob@3044
   265
slouken@3052
   266
            /* what if ncolors != (1 << nbits)? That can happen on a
slouken@3052
   267
               true PseudoColor display.  I'm assuming that we will
slouken@3052
   268
               always have ncolors == (1 << nbits) */
bob@3044
   269
slouken@3052
   270
            /* I'm making a lot of assumptions here. */
bob@3044
   271
slouken@3052
   272
            /* Compute the width of each field. If there is one extra
slouken@3052
   273
               bit, give it to green. If there are two extra bits give
slouken@3052
   274
               them to red and greed.  We can get extra bits when the
slouken@3052
   275
               number of bits per pixel is not a multiple of 3. For
slouken@3052
   276
               example when we have 16 bits per pixel and need a 5/6/5
slouken@3052
   277
               layout for the RGB fields */
slouken@3052
   278
slouken@3052
   279
            rwidth = (nbits / 3) + (((nbits % 3) == 2) ? 1 : 0);
slouken@3052
   280
            gwidth = (nbits / 3) + (((nbits % 3) >= 1) ? 1 : 0);
slouken@3052
   281
            bwidth = (nbits / 3);
bob@3044
   282
bob@3044
   283
            rshift = gwidth + bwidth;
bob@3044
   284
            gshift = bwidth;
bob@3044
   285
            bshift = 0;
bob@3044
   286
bob@3044
   287
            rmax = 1 << rwidth;
bob@3044
   288
            gmax = 1 << gwidth;
bob@3044
   289
            bmax = 1 << bwidth;
bob@3044
   290
bob@3044
   291
            rmask = rmax - 1;
bob@3044
   292
            gmask = gmax - 1;
bob@3044
   293
            bmask = bmax - 1;
bob@3044
   294
bob@3044
   295
/*             printf("red   mask = %4x shift = %4d width = %d\n", rmask, rshift, rwidth); */
bob@3044
   296
/*             printf("green mask = %4x shift = %4d width = %d\n", gmask, gshift, gwidth); */
bob@3044
   297
/*             printf("blue  mask = %4x shift = %4d width = %d\n", bmask, bshift, bwidth); */
bob@2214
   298
bob@2214
   299
            /* build the color table pixel values */
slouken@3052
   300
            pix = 0;
slouken@3052
   301
            for (r = 0; r < rmax; r++) {
slouken@3052
   302
                for (g = 0; g < gmax; g++) {
slouken@3052
   303
                    for (b = 0; b < bmax; b++) {
slouken@3052
   304
                        colorcells[pix].pixel =
slouken@3052
   305
                            (r << rshift) | (g << gshift) | (b << bshift);
slouken@3052
   306
                        colorcells[pix].red = (0xffff * r) / rmask;
slouken@3052
   307
                        colorcells[pix].green = (0xffff * g) / gmask;
slouken@3052
   308
                        colorcells[pix].blue = (0xffff * b) / bmask;
bob@3044
   309
/* 		  printf("%4x:%4x [%4x %4x %4x]\n",  */
bob@3044
   310
/* 			 pix,  */
bob@3044
   311
/* 			 colorcells[pix].pixel, */
bob@3044
   312
/* 			 colorcells[pix].red, */
bob@3044
   313
/* 			 colorcells[pix].green, */
bob@3044
   314
/* 			 colorcells[pix].blue); */
slouken@3052
   315
                        pix++;
slouken@3052
   316
                    }
slouken@3052
   317
                }
slouken@3052
   318
            }
bob@2214
   319
bob@3044
   320
/*             status = */
bob@3044
   321
/*                 XStoreColors(data->display, colormap, colorcells, ncolors); */
bob@2214
   322
bob@2214
   323
            xattr.colormap = colormap;
bob@3044
   324
            X11_TrackColormap(data->display, displaydata->screen,
bob@3044
   325
                              colormap, visual, NULL);
bob@3044
   326
bob@3009
   327
            SDL_free(colorcells);
bob@2185
   328
        }
slouken@2945
   329
    } else if (visual->class == DirectColor) {
bob@3009
   330
        Status status;
bob@3009
   331
        XStandardColormap cmap;
bob@3009
   332
        XColor *colorcells;
bob@3009
   333
        Colormap colormap;
bob@3009
   334
        int i;
bob@3009
   335
        int ncolors;
bob@3009
   336
        int rmax, gmax, bmax;
bob@3009
   337
        int rmask, gmask, bmask;
bob@3009
   338
        int rshift, gshift, bshift;
bob@3009
   339
bob@3009
   340
        /* Is the colormap we need already registered in SDL? */
bob@3009
   341
        if (colormap =
bob@3009
   342
            X11_LookupColormap(data->display,
bob@3009
   343
                               displaydata->screen, visual->visualid)) {
bob@3009
   344
            xattr.colormap = colormap;
bob@3009
   345
/*             printf("found existing colormap\n"); */
bob@3009
   346
        } else {
bob@3009
   347
            /* The colormap is not known to SDL so we will create it */
bob@3009
   348
            colormap = XCreateColormap(data->display,
bob@3009
   349
                                       RootWindow(data->display,
bob@3009
   350
                                                  displaydata->screen),
bob@3009
   351
                                       visual, AllocAll);
bob@3009
   352
/*             printf("colormap = %x\n", colormap); */
bob@3009
   353
bob@3009
   354
            /* If we can't create a colormap, then we must die */
bob@3009
   355
            if (!colormap) {
bob@3009
   356
                SDL_SetError
bob@3044
   357
                    ("Couldn't create window: Could not create writable colormap");
bob@3009
   358
                return -1;
bob@3009
   359
            }
bob@3009
   360
bob@3009
   361
            /* OK, we got a colormap, now fill it in as best as we can */
bob@3009
   362
bob@3009
   363
            colorcells = SDL_malloc(visual->map_entries * sizeof(XColor));
bob@3009
   364
            if (NULL == colorcells) {
bob@3009
   365
                SDL_SetError("out of memory in X11_CreateWindow");
bob@3009
   366
                return -1;
bob@3009
   367
            }
bob@3009
   368
            ncolors = visual->map_entries;
bob@3009
   369
            rmax = 0xffff;
bob@3009
   370
            gmax = 0xffff;
bob@3009
   371
            bmax = 0xffff;
bob@3009
   372
bob@3009
   373
            rshift = 0;
bob@3009
   374
            rmask = visual->red_mask;
bob@3009
   375
            while (0 == (rmask & 1)) {
bob@3009
   376
                rshift++;
bob@3009
   377
                rmask >>= 1;
bob@3009
   378
            }
bob@3009
   379
bob@3009
   380
/*             printf("rmask = %4x rshift = %4d\n", rmask, rshift); */
bob@3009
   381
bob@3009
   382
            gshift = 0;
bob@3009
   383
            gmask = visual->green_mask;
bob@3009
   384
            while (0 == (gmask & 1)) {
bob@3009
   385
                gshift++;
bob@3009
   386
                gmask >>= 1;
bob@3009
   387
            }
bob@3009
   388
bob@3009
   389
/*             printf("gmask = %4x gshift = %4d\n", gmask, gshift); */
bob@3009
   390
bob@3009
   391
            bshift = 0;
bob@3009
   392
            bmask = visual->blue_mask;
bob@3009
   393
            while (0 == (bmask & 1)) {
bob@3009
   394
                bshift++;
bob@3009
   395
                bmask >>= 1;
bob@3009
   396
            }
bob@3009
   397
bob@3009
   398
/*             printf("bmask = %4x bshift = %4d\n", bmask, bshift); */
bob@3009
   399
bob@3009
   400
            /* build the color table pixel values */
bob@3009
   401
            for (i = 0; i < ncolors; i++) {
bob@3009
   402
                Uint32 red = (rmax * i) / (ncolors - 1);
bob@3009
   403
                Uint32 green = (gmax * i) / (ncolors - 1);
bob@3009
   404
                Uint32 blue = (bmax * i) / (ncolors - 1);
bob@3009
   405
bob@3009
   406
                Uint32 rbits = (rmask * i) / (ncolors - 1);
bob@3009
   407
                Uint32 gbits = (gmask * i) / (ncolors - 1);
bob@3009
   408
                Uint32 bbits = (bmask * i) / (ncolors - 1);
bob@3009
   409
bob@3009
   410
                Uint32 pix =
bob@3009
   411
                    (rbits << rshift) | (gbits << gshift) | (bbits << bshift);
bob@3009
   412
bob@3009
   413
                colorcells[i].pixel = pix;
bob@3009
   414
bob@3009
   415
                colorcells[i].red = red;
bob@3009
   416
                colorcells[i].green = green;
bob@3009
   417
                colorcells[i].blue = blue;
bob@3009
   418
bob@3009
   419
                colorcells[i].flags = DoRed | DoGreen | DoBlue;
bob@3009
   420
/* 		printf("%2d:%4x [%4x %4x %4x]\n", i, pix, red, green, blue); */
bob@3009
   421
            }
bob@3009
   422
bob@3009
   423
            status =
bob@3009
   424
                XStoreColors(data->display, colormap, colorcells, ncolors);
bob@3009
   425
bob@3009
   426
            xattr.colormap = colormap;
bob@3009
   427
            X11_TrackColormap(data->display, displaydata->screen,
bob@3009
   428
                              colormap, visual, colorcells);
bob@3009
   429
bob@3009
   430
            SDL_free(colorcells);
bob@3009
   431
        }
slouken@1951
   432
    } else {
slouken@1951
   433
        xattr.colormap =
slouken@1951
   434
            XCreateColormap(data->display,
slouken@1951
   435
                            RootWindow(data->display, displaydata->screen),
slouken@1951
   436
                            visual, AllocNone);
slouken@1951
   437
    }
slouken@1951
   438
slouken@2876
   439
    if ((window->flags & SDL_WINDOW_FULLSCREEN)
slouken@2876
   440
        || window->x == SDL_WINDOWPOS_CENTERED) {
slouken@2931
   441
        X11_GetDisplaySize(_this, window, &x, NULL);
slouken@2931
   442
        x = (x - window->w) / 2;
slouken@1951
   443
    } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
slouken@1951
   444
        x = 0;
slouken@1951
   445
    } else {
slouken@1951
   446
        x = window->x;
slouken@1951
   447
    }
slouken@2876
   448
    if ((window->flags & SDL_WINDOW_FULLSCREEN)
slouken@2876
   449
        || window->y == SDL_WINDOWPOS_CENTERED) {
slouken@2931
   450
        X11_GetDisplaySize(_this, window, NULL, &y);
slouken@2931
   451
        y = (y - window->h) / 2;
slouken@1951
   452
    } else if (window->y == SDL_WINDOWPOS_UNDEFINED) {
slouken@1951
   453
        y = 0;
slouken@1951
   454
    } else {
slouken@1951
   455
        y = window->y;
slouken@1951
   456
    }
slouken@1951
   457
slouken@1951
   458
    w = XCreateWindow(data->display,
slouken@1951
   459
                      RootWindow(data->display, displaydata->screen), x, y,
slouken@1951
   460
                      window->w, window->h, 0, depth, InputOutput, visual,
slouken@1951
   461
                      (CWOverrideRedirect | CWBackPixel | CWBorderPixel |
slouken@1951
   462
                       CWColormap), &xattr);
slouken@1952
   463
    if (!w) {
slouken@1952
   464
#ifdef SDL_VIDEO_OPENGL_GLX
slouken@1952
   465
        if (window->flags & SDL_WINDOW_OPENGL) {
slouken@1952
   466
            X11_GL_Shutdown(_this);
slouken@1952
   467
        }
slouken@1952
   468
#endif
slouken@1952
   469
        SDL_SetError("Couldn't create window");
slouken@1952
   470
        return -1;
slouken@1952
   471
    }
slouken@1951
   472
slouken@1951
   473
    sizehints = XAllocSizeHints();
slouken@1951
   474
    if (sizehints) {
slouken@2876
   475
        if ((window->flags & SDL_WINDOW_RESIZABLE)
slouken@2876
   476
            && !(window->flags & SDL_WINDOW_FULLSCREEN)) {
slouken@1951
   477
            sizehints->min_width = 32;
slouken@1951
   478
            sizehints->min_height = 32;
slouken@1951
   479
            sizehints->max_height = 4096;
slouken@1951
   480
            sizehints->max_width = 4096;
slouken@1951
   481
        } else {
slouken@1951
   482
            sizehints->min_width = sizehints->max_width = window->w;
slouken@1951
   483
            sizehints->min_height = sizehints->max_height = window->h;
slouken@1951
   484
        }
slouken@1951
   485
        sizehints->flags = PMaxSize | PMinSize;
slouken@1951
   486
        if (!(window->flags & SDL_WINDOW_FULLSCREEN)
slouken@1951
   487
            && window->x != SDL_WINDOWPOS_UNDEFINED
slouken@1951
   488
            && window->y != SDL_WINDOWPOS_UNDEFINED) {
slouken@1951
   489
            sizehints->x = x;
slouken@1951
   490
            sizehints->y = y;
slouken@1951
   491
            sizehints->flags |= USPosition;
slouken@1951
   492
        }
slouken@1951
   493
        XSetWMNormalHints(data->display, w, sizehints);
slouken@1951
   494
        XFree(sizehints);
slouken@1951
   495
    }
slouken@1951
   496
slouken@2876
   497
    if (window->flags & (SDL_WINDOW_BORDERLESS | SDL_WINDOW_FULLSCREEN)) {
slouken@1951
   498
        SDL_bool set;
slouken@1951
   499
        Atom WM_HINTS;
slouken@1951
   500
slouken@1951
   501
        /* We haven't modified the window manager hints yet */
slouken@1951
   502
        set = SDL_FALSE;
slouken@1951
   503
slouken@1951
   504
        /* First try to set MWM hints */
slouken@1951
   505
        WM_HINTS = XInternAtom(data->display, "_MOTIF_WM_HINTS", True);
slouken@1951
   506
        if (WM_HINTS != None) {
slouken@1951
   507
            /* Hints used by Motif compliant window managers */
slouken@1951
   508
            struct
slouken@1951
   509
            {
slouken@1951
   510
                unsigned long flags;
slouken@1951
   511
                unsigned long functions;
slouken@1951
   512
                unsigned long decorations;
slouken@1951
   513
                long input_mode;
slouken@1951
   514
                unsigned long status;
slouken@1951
   515
            } MWMHints = {
slouken@1951
   516
            (1L << 1), 0, 0, 0, 0};
slouken@1951
   517
slouken@1951
   518
            XChangeProperty(data->display, w, WM_HINTS, WM_HINTS, 32,
slouken@1951
   519
                            PropModeReplace, (unsigned char *) &MWMHints,
slouken@1951
   520
                            sizeof(MWMHints) / sizeof(long));
slouken@1951
   521
            set = SDL_TRUE;
slouken@1951
   522
        }
slouken@1951
   523
        /* Now try to set KWM hints */
slouken@1951
   524
        WM_HINTS = XInternAtom(data->display, "KWM_WIN_DECORATION", True);
slouken@1951
   525
        if (WM_HINTS != None) {
slouken@1951
   526
            long KWMHints = 0;
slouken@1951
   527
slouken@1951
   528
            XChangeProperty(data->display, w,
slouken@1951
   529
                            WM_HINTS, WM_HINTS, 32,
slouken@1951
   530
                            PropModeReplace,
slouken@1951
   531
                            (unsigned char *) &KWMHints,
slouken@1951
   532
                            sizeof(KWMHints) / sizeof(long));
slouken@1951
   533
            set = SDL_TRUE;
slouken@1951
   534
        }
slouken@1951
   535
        /* Now try to set GNOME hints */
slouken@1951
   536
        WM_HINTS = XInternAtom(data->display, "_WIN_HINTS", True);
slouken@1951
   537
        if (WM_HINTS != None) {
slouken@1951
   538
            long GNOMEHints = 0;
slouken@1951
   539
slouken@1951
   540
            XChangeProperty(data->display, w,
slouken@1951
   541
                            WM_HINTS, WM_HINTS, 32,
slouken@1951
   542
                            PropModeReplace,
slouken@1951
   543
                            (unsigned char *) &GNOMEHints,
slouken@1951
   544
                            sizeof(GNOMEHints) / sizeof(long));
slouken@1951
   545
            set = SDL_TRUE;
slouken@1951
   546
        }
slouken@1951
   547
        /* Finally set the transient hints if necessary */
slouken@1951
   548
        if (!set) {
slouken@1951
   549
            XSetTransientForHint(data->display, w,
slouken@1951
   550
                                 RootWindow(data->display,
slouken@1951
   551
                                            displaydata->screen));
slouken@1951
   552
        }
slouken@1951
   553
    } else {
slouken@1951
   554
        SDL_bool set;
slouken@1951
   555
        Atom WM_HINTS;
slouken@1951
   556
slouken@1951
   557
        /* We haven't modified the window manager hints yet */
slouken@1951
   558
        set = SDL_FALSE;
slouken@1951
   559
slouken@1951
   560
        /* First try to unset MWM hints */
slouken@1951
   561
        WM_HINTS = XInternAtom(data->display, "_MOTIF_WM_HINTS", True);
slouken@1951
   562
        if (WM_HINTS != None) {
slouken@1951
   563
            XDeleteProperty(data->display, w, WM_HINTS);
slouken@1951
   564
            set = SDL_TRUE;
slouken@1951
   565
        }
slouken@1951
   566
        /* Now try to unset KWM hints */
slouken@1951
   567
        WM_HINTS = XInternAtom(data->display, "KWM_WIN_DECORATION", True);
slouken@1951
   568
        if (WM_HINTS != None) {
slouken@1951
   569
            XDeleteProperty(data->display, w, WM_HINTS);
slouken@1951
   570
            set = SDL_TRUE;
slouken@1951
   571
        }
slouken@1951
   572
        /* Now try to unset GNOME hints */
slouken@1951
   573
        WM_HINTS = XInternAtom(data->display, "_WIN_HINTS", True);
slouken@1951
   574
        if (WM_HINTS != None) {
slouken@1951
   575
            XDeleteProperty(data->display, w, WM_HINTS);
slouken@1951
   576
            set = SDL_TRUE;
slouken@1951
   577
        }
slouken@1951
   578
        /* Finally unset the transient hints if necessary */
slouken@1951
   579
        if (!set) {
slouken@1951
   580
            /* NOTE: Does this work? */
slouken@1951
   581
            XSetTransientForHint(data->display, w, None);
slouken@1951
   582
        }
slouken@1951
   583
    }
slouken@1951
   584
slouken@1951
   585
    /* Tell KDE to keep fullscreen windows on top */
slouken@1951
   586
    if (window->flags & SDL_WINDOW_FULLSCREEN) {
slouken@1951
   587
        XEvent ev;
slouken@1951
   588
        long mask;
slouken@1951
   589
slouken@1951
   590
        SDL_zero(ev);
slouken@1951
   591
        ev.xclient.type = ClientMessage;
slouken@1951
   592
        ev.xclient.window = RootWindow(data->display, displaydata->screen);
slouken@1951
   593
        ev.xclient.message_type =
slouken@1951
   594
            XInternAtom(data->display, "KWM_KEEP_ON_TOP", False);
slouken@1951
   595
        ev.xclient.format = 32;
slouken@1951
   596
        ev.xclient.data.l[0] = w;
slouken@1951
   597
        ev.xclient.data.l[1] = CurrentTime;
slouken@1951
   598
        XSendEvent(data->display,
slouken@1951
   599
                   RootWindow(data->display, displaydata->screen), False,
slouken@1951
   600
                   SubstructureRedirectMask, &ev);
slouken@1951
   601
    }
slouken@1951
   602
slouken@1951
   603
    /* Set the input hints so we get keyboard input */
slouken@1951
   604
    wmhints = XAllocWMHints();
slouken@1951
   605
    if (wmhints) {
slouken@1951
   606
        wmhints->input = True;
slouken@1956
   607
        wmhints->flags = InputHint;
slouken@1951
   608
        XSetWMHints(data->display, w, wmhints);
slouken@1951
   609
        XFree(wmhints);
slouken@1951
   610
    }
slouken@1951
   611
slouken@1951
   612
    /* Set the class hints so we can get an icon (AfterStep) */
slouken@1951
   613
    classhints = XAllocClassHint();
slouken@1951
   614
    if (classhints != NULL) {
slouken@1951
   615
        classhints->res_name = data->classname;
slouken@1951
   616
        classhints->res_class = data->classname;
slouken@1951
   617
        XSetClassHint(data->display, w, classhints);
slouken@1951
   618
        XFree(classhints);
slouken@1951
   619
    }
slouken@1951
   620
slouken@1951
   621
    /* Allow the window to be deleted by the window manager */
slouken@1951
   622
    XSetWMProtocols(data->display, w, &data->WM_DELETE_WINDOW, 1);
slouken@1951
   623
slouken@1951
   624
    if (SetupWindowData(_this, window, w, SDL_TRUE) < 0) {
slouken@1952
   625
#ifdef SDL_VIDEO_OPENGL_GLX
slouken@1952
   626
        if (window->flags & SDL_WINDOW_OPENGL) {
slouken@1952
   627
            X11_GL_Shutdown(_this);
slouken@1952
   628
        }
slouken@1952
   629
#endif
slouken@1951
   630
        XDestroyWindow(data->display, w);
slouken@1951
   631
        return -1;
slouken@1951
   632
    }
bob@2325
   633
#ifdef X_HAVE_UTF8_STRING
bob@2325
   634
    {
bob@2325
   635
        Uint32 fevent = 0;
bob@2325
   636
        pXGetICValues(((SDL_WindowData *) window->driverdata)->ic,
bob@2325
   637
                      XNFilterEvents, &fevent, NULL);
bob@2325
   638
        XSelectInput(data->display, w,
bob@2325
   639
                     (FocusChangeMask | EnterWindowMask | LeaveWindowMask |
bob@2325
   640
                      ExposureMask | ButtonPressMask | ButtonReleaseMask |
bob@2325
   641
                      PointerMotionMask | KeyPressMask | KeyReleaseMask |
bob@2325
   642
                      PropertyChangeMask | StructureNotifyMask |
bob@2325
   643
                      KeymapStateMask | fevent));
bob@2325
   644
    }
bob@2325
   645
#else
kazeuser@2718
   646
    {
kazeuser@2718
   647
        XSelectInput(data->display, w,
slouken@2725
   648
                     (FocusChangeMask | EnterWindowMask | LeaveWindowMask |
slouken@2725
   649
                      ExposureMask | ButtonPressMask | ButtonReleaseMask |
slouken@2725
   650
                      PointerMotionMask | KeyPressMask | KeyReleaseMask |
slouken@2725
   651
                      PropertyChangeMask | StructureNotifyMask |
slouken@2725
   652
                      KeymapStateMask));
kazeuser@2718
   653
    }
bob@2325
   654
#endif
bob@2325
   655
slouken@2940
   656
#if SDL_VIDEO_DRIVER_X11_XINPUT
slouken@2710
   657
    /* we're informing the display what extension events we want to receive from it */
slouken@2940
   658
    {
slouken@2940
   659
        int i, j, n = 0;
slouken@2940
   660
        XEventClass xevents[256];
slouken@2940
   661
slouken@2940
   662
        for (i = 0; i < SDL_GetNumMice(); ++i) {
slouken@2940
   663
            SDL_Mouse *mouse;
slouken@2940
   664
            X11_MouseData *data;
slouken@2940
   665
slouken@2940
   666
            mouse = SDL_GetMouse(i);
slouken@2942
   667
            data = (X11_MouseData *) mouse->driverdata;
slouken@2940
   668
            if (!data) {
slouken@2940
   669
                continue;
slouken@2940
   670
            }
slouken@2940
   671
slouken@2940
   672
            for (j = 0; j < data->num_xevents; ++j) {
slouken@2940
   673
                xevents[n++] = data->xevents[j];
slouken@2940
   674
            }
slouken@2940
   675
        }
slouken@2940
   676
        if (n > 0) {
slouken@2940
   677
            XSelectExtensionEvent(data->display, w, xevents, n);
slouken@2940
   678
        }
slouken@2940
   679
    }
slouken@2940
   680
#endif
slouken@2710
   681
slouken@1951
   682
    return 0;
slouken@1951
   683
}
slouken@1951
   684
slouken@1951
   685
int
bob@2324
   686
X11_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
slouken@1951
   687
{
slouken@1951
   688
    Window w = (Window) data;
slouken@1951
   689
slouken@1951
   690
    /* FIXME: Query the title from the existing window */
slouken@1951
   691
slouken@1951
   692
    if (SetupWindowData(_this, window, w, SDL_FALSE) < 0) {
slouken@1951
   693
        return -1;
slouken@1951
   694
    }
slouken@1951
   695
    return 0;
slouken@1951
   696
}
slouken@1951
   697
slouken@1951
   698
void
slouken@1951
   699
X11_SetWindowTitle(_THIS, SDL_Window * window)
slouken@1951
   700
{
slouken@1951
   701
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
slouken@1951
   702
    Display *display = data->videodata->display;
slouken@1951
   703
    XTextProperty titleprop, iconprop;
slouken@1951
   704
    Status status;
slouken@1951
   705
    const char *title = window->title;
slouken@1951
   706
    const char *icon = NULL;
slouken@1951
   707
slouken@1951
   708
#ifdef X_HAVE_UTF8_STRING
slouken@1951
   709
    Atom _NET_WM_NAME = 0;
slouken@1951
   710
    Atom _NET_WM_ICON_NAME = 0;
slouken@1951
   711
slouken@1951
   712
    /* Look up some useful Atoms */
slouken@1951
   713
    if (SDL_X11_HAVE_UTF8) {
slouken@1951
   714
        _NET_WM_NAME = XInternAtom(display, "_NET_WM_NAME", False);
slouken@1951
   715
        _NET_WM_ICON_NAME = XInternAtom(display, "_NET_WM_ICON_NAME", False);
slouken@1951
   716
    }
slouken@1951
   717
#endif
slouken@1951
   718
slouken@1951
   719
    if (title != NULL) {
slouken@2143
   720
        char *title_locale = SDL_iconv_utf8_locale(title);
slouken@2143
   721
        if (!title_locale) {
slouken@1951
   722
            SDL_OutOfMemory();
slouken@1951
   723
            return;
slouken@1951
   724
        }
slouken@2143
   725
        status = XStringListToTextProperty(&title_locale, 1, &titleprop);
slouken@2143
   726
        SDL_free(title_locale);
slouken@1951
   727
        if (status) {
slouken@1951
   728
            XSetTextProperty(display, data->window, &titleprop, XA_WM_NAME);
slouken@1951
   729
            XFree(titleprop.value);
slouken@1951
   730
        }
slouken@1951
   731
#ifdef X_HAVE_UTF8_STRING
slouken@1951
   732
        if (SDL_X11_HAVE_UTF8) {
slouken@1951
   733
            status =
slouken@1951
   734
                Xutf8TextListToTextProperty(display, (char **) &title, 1,
slouken@1951
   735
                                            XUTF8StringStyle, &titleprop);
slouken@1951
   736
            if (status == Success) {
slouken@1951
   737
                XSetTextProperty(display, data->window, &titleprop,
slouken@1951
   738
                                 _NET_WM_NAME);
slouken@1951
   739
                XFree(titleprop.value);
slouken@1951
   740
            }
slouken@1951
   741
        }
slouken@1951
   742
#endif
slouken@1951
   743
    }
slouken@1951
   744
    if (icon != NULL) {
slouken@2143
   745
        char *icon_locale = SDL_iconv_utf8_locale(icon);
slouken@2143
   746
        if (!icon_locale) {
slouken@1951
   747
            SDL_OutOfMemory();
slouken@1951
   748
            return;
slouken@1951
   749
        }
slouken@2143
   750
        status = XStringListToTextProperty(&icon_locale, 1, &iconprop);
slouken@2143
   751
        SDL_free(icon_locale);
slouken@1951
   752
        if (status) {
slouken@1951
   753
            XSetTextProperty(display, data->window, &iconprop,
slouken@1951
   754
                             XA_WM_ICON_NAME);
slouken@1951
   755
            XFree(iconprop.value);
slouken@1951
   756
        }
slouken@1951
   757
#ifdef X_HAVE_UTF8_STRING
slouken@1951
   758
        if (SDL_X11_HAVE_UTF8) {
slouken@1951
   759
            status =
slouken@1951
   760
                Xutf8TextListToTextProperty(display, (char **) &icon, 1,
slouken@1951
   761
                                            XUTF8StringStyle, &iconprop);
slouken@1951
   762
            if (status == Success) {
slouken@1951
   763
                XSetTextProperty(display, data->window, &iconprop,
slouken@1951
   764
                                 _NET_WM_ICON_NAME);
slouken@1951
   765
                XFree(iconprop.value);
slouken@1951
   766
            }
slouken@1951
   767
        }
slouken@1951
   768
#endif
slouken@1951
   769
    }
slouken@1951
   770
}
slouken@1951
   771
slouken@1951
   772
void
slouken@2967
   773
X11_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
slouken@2967
   774
{
slouken@2967
   775
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
slouken@2967
   776
    Display *display = data->videodata->display;
slouken@2967
   777
    Atom _NET_WM_ICON = XInternAtom(display, "_NET_WM_ICON", False);
slouken@2967
   778
slouken@2967
   779
    if (icon) {
slouken@2967
   780
        SDL_PixelFormat format;
slouken@2967
   781
        SDL_Surface *surface;
slouken@2967
   782
        int propsize;
slouken@2967
   783
        Uint32 *propdata;
slouken@2967
   784
slouken@2967
   785
        /* Convert the icon to ARGB for modern window managers */
slouken@2990
   786
        SDL_InitFormat(&format, 32, 0x00FF0000, 0x0000FF00, 0x000000FF,
slouken@2990
   787
                       0xFF000000);
slouken@2967
   788
        surface = SDL_ConvertSurface(icon, &format, 0);
slouken@2967
   789
        if (!surface) {
slouken@2967
   790
            return;
slouken@2967
   791
        }
slouken@2967
   792
slouken@2967
   793
        /* Set the _NET_WM_ICON property */
slouken@2990
   794
        propsize = 2 + (icon->w * icon->h);
slouken@2967
   795
        propdata = SDL_malloc(propsize * sizeof(Uint32));
slouken@2967
   796
        if (propdata) {
slouken@2967
   797
            propdata[0] = icon->w;
slouken@2967
   798
            propdata[1] = icon->h;
slouken@2990
   799
            SDL_memcpy(&propdata[2], surface->pixels,
slouken@2990
   800
                       surface->h * surface->pitch);
slouken@2990
   801
            XChangeProperty(display, data->window, _NET_WM_ICON, XA_CARDINAL,
slouken@2990
   802
                            32, PropModeReplace, (unsigned char *) propdata,
slouken@2990
   803
                            propsize);
slouken@2967
   804
        }
slouken@2967
   805
        SDL_FreeSurface(surface);
slouken@2967
   806
    } else {
slouken@2967
   807
        XDeleteProperty(display, data->window, _NET_WM_ICON);
slouken@2967
   808
    }
slouken@2967
   809
}
slouken@2967
   810
slouken@2967
   811
void
slouken@1951
   812
X11_SetWindowPosition(_THIS, SDL_Window * window)
slouken@1951
   813
{
slouken@1951
   814
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
slouken@1951
   815
    SDL_DisplayData *displaydata =
slouken@1952
   816
        (SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata;
slouken@1951
   817
    Display *display = data->videodata->display;
slouken@2875
   818
    int x, y;
slouken@1951
   819
slouken@2876
   820
    if ((window->flags & SDL_WINDOW_FULLSCREEN)
slouken@2876
   821
        || window->x == SDL_WINDOWPOS_CENTERED) {
slouken@2931
   822
        X11_GetDisplaySize(_this, window, &x, NULL);
slouken@2931
   823
        x = (x - window->w) / 2;
slouken@2875
   824
    } else {
slouken@2875
   825
        x = window->x;
slouken@2875
   826
    }
slouken@2876
   827
    if ((window->flags & SDL_WINDOW_FULLSCREEN)
slouken@2876
   828
        || window->y == SDL_WINDOWPOS_CENTERED) {
slouken@2931
   829
        X11_GetDisplaySize(_this, window, NULL, &y);
slouken@2931
   830
        y = (y - window->h) / 2;
slouken@2875
   831
    } else {
slouken@2875
   832
        y = window->y;
slouken@2875
   833
    }
slouken@2875
   834
    XMoveWindow(display, data->window, x, y);
slouken@1951
   835
}
slouken@1951
   836
slouken@1951
   837
void
slouken@1951
   838
X11_SetWindowSize(_THIS, SDL_Window * window)
slouken@1951
   839
{
slouken@1951
   840
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
slouken@1951
   841
    Display *display = data->videodata->display;
slouken@1951
   842
slouken@2931
   843
    XResizeWindow(display, data->window, window->w, window->h);
slouken@1951
   844
}
slouken@1951
   845
slouken@1951
   846
void
slouken@1951
   847
X11_ShowWindow(_THIS, SDL_Window * window)
slouken@1951
   848
{
slouken@1951
   849
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
slouken@1951
   850
    Display *display = data->videodata->display;
slouken@1951
   851
slouken@1951
   852
    XMapRaised(display, data->window);
slouken@1951
   853
}
slouken@1951
   854
slouken@1951
   855
void
slouken@1951
   856
X11_HideWindow(_THIS, SDL_Window * window)
slouken@1951
   857
{
slouken@1951
   858
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
slouken@1951
   859
    Display *display = data->videodata->display;
slouken@1951
   860
slouken@1951
   861
    XUnmapWindow(display, data->window);
slouken@1951
   862
}
slouken@1951
   863
slouken@1951
   864
void
slouken@1951
   865
X11_RaiseWindow(_THIS, SDL_Window * window)
slouken@1951
   866
{
slouken@1951
   867
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
slouken@1951
   868
    Display *display = data->videodata->display;
slouken@1951
   869
slouken@1951
   870
    XRaiseWindow(display, data->window);
slouken@1951
   871
}
slouken@1951
   872
slouken@1951
   873
void
slouken@1951
   874
X11_MaximizeWindow(_THIS, SDL_Window * window)
slouken@1951
   875
{
slouken@1951
   876
    /* FIXME: is this even possible? */
slouken@1951
   877
}
slouken@1951
   878
slouken@1951
   879
void
slouken@1951
   880
X11_MinimizeWindow(_THIS, SDL_Window * window)
slouken@1951
   881
{
slouken@1951
   882
    X11_HideWindow(_this, window);
slouken@1951
   883
}
slouken@1951
   884
slouken@1951
   885
void
slouken@1951
   886
X11_RestoreWindow(_THIS, SDL_Window * window)
slouken@1951
   887
{
slouken@1951
   888
    X11_ShowWindow(_this, window);
slouken@1951
   889
}
slouken@1951
   890
slouken@1951
   891
void
slouken@1951
   892
X11_SetWindowGrab(_THIS, SDL_Window * window)
slouken@1951
   893
{
slouken@2875
   894
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
slouken@2875
   895
    Display *display = data->videodata->display;
slouken@2875
   896
slouken@2876
   897
    if ((window->flags & (SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_FULLSCREEN))
slouken@2876
   898
        && (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
slouken@2875
   899
        /* Try to grab the mouse */
slouken@2876
   900
        for (;;) {
slouken@2876
   901
            int result =
slouken@2876
   902
                XGrabPointer(display, data->window, True, 0, GrabModeAsync,
slouken@2876
   903
                             GrabModeAsync, data->window, None, CurrentTime);
slouken@2876
   904
            if (result == GrabSuccess) {
slouken@2875
   905
                break;
slouken@2875
   906
            }
slouken@2875
   907
            SDL_Delay(100);
slouken@2875
   908
        }
slouken@2875
   909
slouken@2875
   910
        /* Raise the window if we grab the mouse */
slouken@2875
   911
        XRaiseWindow(display, data->window);
slouken@2875
   912
slouken@2875
   913
        /* Now grab the keyboard */
slouken@2876
   914
        XGrabKeyboard(display, data->window, True, GrabModeAsync,
slouken@2876
   915
                      GrabModeAsync, CurrentTime);
slouken@2875
   916
    } else {
slouken@2875
   917
        XUngrabPointer(display, CurrentTime);
slouken@2875
   918
        XUngrabKeyboard(display, CurrentTime);
slouken@2875
   919
    }
slouken@1951
   920
}
slouken@1951
   921
slouken@1951
   922
void
slouken@1951
   923
X11_DestroyWindow(_THIS, SDL_Window * window)
slouken@1951
   924
{
slouken@1951
   925
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
bob@2323
   926
    window->driverdata = NULL;
slouken@1951
   927
slouken@1951
   928
    if (data) {
bob@2323
   929
        SDL_VideoData *videodata = (SDL_VideoData *) data->videodata;
bob@2323
   930
        Display *display = videodata->display;
bob@2323
   931
        int numwindows = videodata->numwindows;
bob@2323
   932
        SDL_WindowData **windowlist = videodata->windowlist;
bob@2323
   933
        int i;
bob@2323
   934
bob@2323
   935
        if (windowlist) {
bob@2324
   936
            for (i = 0; i < numwindows; ++i) {
bob@2324
   937
                if (windowlist[i] && (windowlist[i]->windowID == window->id)) {
bob@2324
   938
                    windowlist[i] = windowlist[numwindows - 1];
bob@2324
   939
                    windowlist[numwindows - 1] = NULL;
bob@2324
   940
                    videodata->numwindows--;
bob@2324
   941
                    break;
bob@2324
   942
                }
bob@2323
   943
            }
bob@2323
   944
        }
slouken@1952
   945
#ifdef SDL_VIDEO_OPENGL_GLX
slouken@1952
   946
        if (window->flags & SDL_WINDOW_OPENGL) {
slouken@1952
   947
            X11_GL_Shutdown(_this);
slouken@1952
   948
        }
slouken@1951
   949
#endif
slouken@1951
   950
#ifdef X_HAVE_UTF8_STRING
slouken@1951
   951
        if (data->ic) {
slouken@1951
   952
            XDestroyIC(data->ic);
slouken@1951
   953
        }
slouken@1951
   954
#endif
slouken@1951
   955
        if (data->created) {
slouken@1951
   956
            XDestroyWindow(display, data->window);
slouken@1951
   957
        }
slouken@1951
   958
        SDL_free(data);
slouken@1951
   959
    }
slouken@1951
   960
}
slouken@1951
   961
slouken@1951
   962
SDL_bool
slouken@1951
   963
X11_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
slouken@1951
   964
{
slouken@1951
   965
    if (info->version.major <= SDL_MAJOR_VERSION) {
slouken@1951
   966
        /* FIXME! */
slouken@1951
   967
        return SDL_TRUE;
slouken@1951
   968
    } else {
slouken@1951
   969
        SDL_SetError("Application not compiled with SDL %d.%d\n",
slouken@1951
   970
                     SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
slouken@1951
   971
        return SDL_FALSE;
slouken@1951
   972
    }
slouken@1951
   973
}
slouken@1951
   974
slouken@1951
   975
/* vi: set ts=4 sw=4 expandtab: */