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