src/video/x11/SDL_x11modes.c
author Ryan C. Gordon <icculus@icculus.org>
Mon, 26 Jan 2015 17:46:39 -0500
changeset 9319 ad4f430cc9f5
parent 9167 3d2c0f659ad3
child 9619 b94b6d0bff0f
permissions -rw-r--r--
X11: Don't delay delivery of focus events unless we just changed vidmodes.

Normally there's a 200 millisecond delay on all focus events in case there
was a vidmode change, now we note the last vidmode change and only impose this
delay if a change happened extremely recently.

Thanks to Epic Games for reporting this issue.
slouken@1950
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@8149
     3
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
slouken@1950
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@1950
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@1950
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@1950
    20
*/
icculus@8093
    21
#include "../../SDL_internal.h"
slouken@1950
    22
slouken@5481
    23
#if SDL_VIDEO_DRIVER_X11
slouken@5481
    24
slouken@6472
    25
#include "SDL_hints.h"
slouken@1950
    26
#include "SDL_x11video.h"
icculus@9319
    27
#include "SDL_timer.h"
slouken@6796
    28
#include "edid.h"
slouken@1950
    29
gabomdq@7678
    30
/* #define X11MODES_DEBUG */
slouken@6558
    31
slouken@6559
    32
/* I'm becoming more and more convinced that the application should never
slouken@6559
    33
 * use XRandR, and it's the window manager's responsibility to track and
slouken@6559
    34
 * manage display modes for fullscreen windows.  Right now XRandR is completely
slouken@6559
    35
 * broken with respect to window manager behavior on every window manager that
slouken@6559
    36
 * I can find.  For example, on Unity 3D if you show a fullscreen window while
slouken@6559
    37
 * the resolution is changing (within ~250 ms) your window will retain the
slouken@6559
    38
 * fullscreen state hint but be decorated and windowed.
slouken@6796
    39
 *
slouken@6796
    40
 * However, many people swear by it, so let them swear at it. :)
slouken@6558
    41
*/
gabomdq@7678
    42
/* #define XRANDR_DISABLED_BY_DEFAULT */
slouken@6558
    43
slouken@1950
    44
slouken@1950
    45
static int
slouken@1950
    46
get_visualinfo(Display * display, int screen, XVisualInfo * vinfo)
slouken@1950
    47
{
slouken@1950
    48
    const char *visual_id = SDL_getenv("SDL_VIDEO_X11_VISUALID");
slouken@1950
    49
    int depth;
slouken@1950
    50
slouken@1950
    51
    /* Look for an exact visual, if requested */
slouken@1950
    52
    if (visual_id) {
slouken@3697
    53
        XVisualInfo *vi, template;
slouken@3697
    54
        int nvis;
slouken@1950
    55
slouken@1950
    56
        SDL_zero(template);
slouken@1950
    57
        template.visualid = SDL_strtol(visual_id, NULL, 0);
icculus@7827
    58
        vi = X11_XGetVisualInfo(display, VisualIDMask, &template, &nvis);
slouken@1950
    59
        if (vi) {
slouken@1950
    60
            *vinfo = *vi;
icculus@7827
    61
            X11_XFree(vi);
slouken@1950
    62
            return 0;
slouken@1950
    63
        }
slouken@1950
    64
    }
slouken@3697
    65
slouken@1950
    66
    depth = DefaultDepth(display, screen);
slouken@5466
    67
    if ((X11_UseDirectColorVisuals() &&
icculus@7827
    68
         X11_XMatchVisualInfo(display, screen, depth, DirectColor, vinfo)) ||
icculus@7827
    69
        X11_XMatchVisualInfo(display, screen, depth, TrueColor, vinfo) ||
icculus@7827
    70
        X11_XMatchVisualInfo(display, screen, depth, PseudoColor, vinfo) ||
icculus@7827
    71
        X11_XMatchVisualInfo(display, screen, depth, StaticColor, vinfo)) {
slouken@1950
    72
        return 0;
slouken@1950
    73
    }
slouken@1950
    74
    return -1;
slouken@1950
    75
}
slouken@1950
    76
slouken@5182
    77
int
slouken@5182
    78
X11_GetVisualInfoFromVisual(Display * display, Visual * visual, XVisualInfo * vinfo)
slouken@5182
    79
{
slouken@5182
    80
    XVisualInfo *vi;
slouken@5182
    81
    int nvis;
slouken@5182
    82
icculus@7827
    83
    vinfo->visualid = X11_XVisualIDFromVisual(visual);
icculus@7827
    84
    vi = X11_XGetVisualInfo(display, VisualIDMask, vinfo, &nvis);
slouken@5182
    85
    if (vi) {
slouken@5182
    86
        *vinfo = *vi;
icculus@7827
    87
        X11_XFree(vi);
slouken@5182
    88
        return 0;
slouken@5182
    89
    }
slouken@5182
    90
    return -1;
slouken@5182
    91
}
slouken@5182
    92
slouken@5182
    93
Uint32
slouken@2874
    94
X11_GetPixelFormatFromVisualInfo(Display * display, XVisualInfo * vinfo)
slouken@2870
    95
{
slouken@2870
    96
    if (vinfo->class == DirectColor || vinfo->class == TrueColor) {
slouken@2870
    97
        int bpp;
slouken@2870
    98
        Uint32 Rmask, Gmask, Bmask, Amask;
slouken@2870
    99
slouken@2870
   100
        Rmask = vinfo->visual->red_mask;
slouken@2870
   101
        Gmask = vinfo->visual->green_mask;
slouken@2870
   102
        Bmask = vinfo->visual->blue_mask;
slouken@2870
   103
        if (vinfo->depth == 32) {
slouken@2870
   104
            Amask = (0xFFFFFFFF & ~(Rmask | Gmask | Bmask));
slouken@2870
   105
        } else {
slouken@2870
   106
            Amask = 0;
slouken@2870
   107
        }
slouken@2870
   108
slouken@2870
   109
        bpp = vinfo->depth;
slouken@2870
   110
        if (bpp == 24) {
slouken@2870
   111
            int i, n;
icculus@7827
   112
            XPixmapFormatValues *p = X11_XListPixmapFormats(display, &n);
slouken@2870
   113
            if (p) {
slouken@2870
   114
                for (i = 0; i < n; ++i) {
slouken@2870
   115
                    if (p[i].depth == 24) {
slouken@2870
   116
                        bpp = p[i].bits_per_pixel;
slouken@2870
   117
                        break;
slouken@2870
   118
                    }
slouken@2870
   119
                }
icculus@7827
   120
                X11_XFree(p);
slouken@2870
   121
            }
slouken@2870
   122
        }
slouken@2870
   123
slouken@2870
   124
        return SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask);
slouken@2870
   125
    }
slouken@2870
   126
slouken@2870
   127
    if (vinfo->class == PseudoColor || vinfo->class == StaticColor) {
slouken@2870
   128
        switch (vinfo->depth) {
slouken@2870
   129
        case 8:
slouken@2870
   130
            return SDL_PIXELTYPE_INDEX8;
slouken@2870
   131
        case 4:
slouken@2870
   132
            if (BitmapBitOrder(display) == LSBFirst) {
slouken@2870
   133
                return SDL_PIXELFORMAT_INDEX4LSB;
slouken@2870
   134
            } else {
slouken@2870
   135
                return SDL_PIXELFORMAT_INDEX4MSB;
slouken@2870
   136
            }
slouken@2870
   137
            break;
slouken@2870
   138
        case 1:
slouken@2870
   139
            if (BitmapBitOrder(display) == LSBFirst) {
slouken@2870
   140
                return SDL_PIXELFORMAT_INDEX1LSB;
slouken@2870
   141
            } else {
slouken@2870
   142
                return SDL_PIXELFORMAT_INDEX1MSB;
slouken@2870
   143
            }
slouken@2870
   144
            break;
slouken@2870
   145
        }
slouken@2870
   146
    }
slouken@2870
   147
slouken@2870
   148
    return SDL_PIXELFORMAT_UNKNOWN;
slouken@2870
   149
}
slouken@1950
   150
slouken@2873
   151
/* Global for the error handler */
slouken@2873
   152
int vm_event, vm_error = -1;
slouken@2873
   153
slouken@2873
   154
#if SDL_VIDEO_DRIVER_X11_XINERAMA
slouken@2873
   155
static SDL_bool
slouken@2874
   156
CheckXinerama(Display * display, int *major, int *minor)
slouken@2873
   157
{
icculus@6027
   158
    int event_base = 0;
icculus@6027
   159
    int error_base = 0;
slouken@2873
   160
    const char *env;
slouken@2873
   161
slouken@2873
   162
    /* Default the extension not available */
slouken@2873
   163
    *major = *minor = 0;
slouken@2873
   164
slouken@2873
   165
    /* Allow environment override */
slouken@6472
   166
    env = SDL_GetHint(SDL_HINT_VIDEO_X11_XINERAMA);
slouken@2873
   167
    if (env && !SDL_atoi(env)) {
slouken@6468
   168
#ifdef X11MODES_DEBUG
slouken@6472
   169
        printf("Xinerama disabled due to hint\n");
slouken@6468
   170
#endif
slouken@2873
   171
        return SDL_FALSE;
slouken@2873
   172
    }
slouken@2873
   173
slouken@5408
   174
    if (!SDL_X11_HAVE_XINERAMA) {
slouken@6468
   175
#ifdef X11MODES_DEBUG
slouken@6468
   176
        printf("Xinerama support not available\n");
slouken@6468
   177
#endif
slouken@5408
   178
        return SDL_FALSE;
slouken@5408
   179
    }
slouken@5408
   180
slouken@2873
   181
    /* Query the extension version */
icculus@7827
   182
    if (!X11_XineramaQueryExtension(display, &event_base, &error_base) ||
icculus@7827
   183
        !X11_XineramaQueryVersion(display, major, minor) ||
icculus@7827
   184
        !X11_XineramaIsActive(display)) {
slouken@6468
   185
#ifdef X11MODES_DEBUG
slouken@6468
   186
        printf("Xinerama not active on the display\n");
slouken@6468
   187
#endif
slouken@2873
   188
        return SDL_FALSE;
slouken@2873
   189
    }
slouken@6468
   190
#ifdef X11MODES_DEBUG
slouken@6548
   191
    printf("Xinerama available at version %d.%d!\n", *major, *minor);
slouken@6468
   192
#endif
slouken@2873
   193
    return SDL_TRUE;
slouken@2873
   194
}
slouken@2873
   195
#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
slouken@2873
   196
slouken@2873
   197
#if SDL_VIDEO_DRIVER_X11_XRANDR
slouken@2873
   198
static SDL_bool
slouken@2874
   199
CheckXRandR(Display * display, int *major, int *minor)
slouken@2873
   200
{
slouken@2873
   201
    const char *env;
slouken@2873
   202
slouken@2873
   203
    /* Default the extension not available */
slouken@2873
   204
    *major = *minor = 0;
slouken@2873
   205
slouken@2873
   206
    /* Allow environment override */
slouken@6472
   207
    env = SDL_GetHint(SDL_HINT_VIDEO_X11_XRANDR);
slouken@6558
   208
#ifdef XRANDR_DISABLED_BY_DEFAULT
slouken@6558
   209
    if (!env || !SDL_atoi(env)) {
slouken@6558
   210
#ifdef X11MODES_DEBUG
slouken@6558
   211
        printf("XRandR disabled by default due to window manager issues\n");
slouken@6558
   212
#endif
slouken@6558
   213
        return SDL_FALSE;
slouken@6558
   214
    }
slouken@6558
   215
#else
slouken@2873
   216
    if (env && !SDL_atoi(env)) {
slouken@6468
   217
#ifdef X11MODES_DEBUG
slouken@6472
   218
        printf("XRandR disabled due to hint\n");
slouken@6468
   219
#endif
slouken@2873
   220
        return SDL_FALSE;
slouken@2873
   221
    }
slouken@6558
   222
#endif /* XRANDR_ENABLED_BY_DEFAULT */
slouken@2873
   223
slouken@2873
   224
    if (!SDL_X11_HAVE_XRANDR) {
slouken@6468
   225
#ifdef X11MODES_DEBUG
slouken@6468
   226
        printf("XRandR support not available\n");
slouken@6468
   227
#endif
slouken@2873
   228
        return SDL_FALSE;
slouken@2873
   229
    }
slouken@2873
   230
slouken@2873
   231
    /* Query the extension version */
icculus@7827
   232
    if (!X11_XRRQueryVersion(display, major, minor)) {
slouken@6468
   233
#ifdef X11MODES_DEBUG
slouken@6468
   234
        printf("XRandR not active on the display\n");
slouken@6468
   235
#endif
slouken@2873
   236
        return SDL_FALSE;
slouken@2873
   237
    }
slouken@6468
   238
#ifdef X11MODES_DEBUG
slouken@6548
   239
    printf("XRandR available at version %d.%d!\n", *major, *minor);
slouken@6468
   240
#endif
slouken@2873
   241
    return SDL_TRUE;
slouken@2873
   242
}
slouken@6537
   243
slouken@6537
   244
#define XRANDR_ROTATION_LEFT    (1 << 1)
slouken@6537
   245
#define XRANDR_ROTATION_RIGHT   (1 << 3)
slouken@6537
   246
slouken@6548
   247
static int
slouken@6548
   248
CalculateXRandRRefreshRate(const XRRModeInfo *info)
slouken@6537
   249
{
slouken@6548
   250
    return (info->hTotal
slouken@6551
   251
            && info->vTotal) ? (info->dotClock / (info->hTotal * info->vTotal)) : 0;
slouken@6548
   252
}
slouken@6548
   253
slouken@6548
   254
static SDL_bool
slouken@6548
   255
SetXRandRModeInfo(Display *display, XRRScreenResources *res, XRROutputInfo *output_info,
slouken@6548
   256
                  RRMode modeID, SDL_DisplayMode *mode)
slouken@6548
   257
{
slouken@6548
   258
    int i;
slouken@6548
   259
    for (i = 0; i < res->nmode; ++i) {
slouken@6548
   260
        if (res->modes[i].id == modeID) {
slouken@6548
   261
            XRRCrtcInfo *crtc;
slouken@6548
   262
            Rotation rotation = 0;
slouken@6548
   263
            const XRRModeInfo *info = &res->modes[i];
slouken@6548
   264
icculus@7827
   265
            crtc = X11_XRRGetCrtcInfo(display, res, output_info->crtc);
slouken@6548
   266
            if (crtc) {
slouken@6548
   267
                rotation = crtc->rotation;
icculus@7827
   268
                X11_XRRFreeCrtcInfo(crtc);
slouken@6548
   269
            }
slouken@6548
   270
slouken@6548
   271
            if (rotation & (XRANDR_ROTATION_LEFT|XRANDR_ROTATION_RIGHT)) {
slouken@6548
   272
                mode->w = info->height;
slouken@6548
   273
                mode->h = info->width;
slouken@6548
   274
            } else {
slouken@6548
   275
                mode->w = info->width;
slouken@6548
   276
                mode->h = info->height;
slouken@6548
   277
            }
slouken@6548
   278
            mode->refresh_rate = CalculateXRandRRefreshRate(info);
slouken@6548
   279
            ((SDL_DisplayModeData*)mode->driverdata)->xrandr_mode = modeID;
slouken@6548
   280
#ifdef X11MODES_DEBUG
icculus@6560
   281
            printf("XRandR mode %d: %dx%d@%dHz\n", (int) modeID, mode->w, mode->h, mode->refresh_rate);
slouken@6548
   282
#endif
slouken@6548
   283
            return SDL_TRUE;
slouken@6548
   284
        }
slouken@6537
   285
    }
slouken@6548
   286
    return SDL_FALSE;
slouken@6537
   287
}
slouken@2873
   288
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
slouken@2873
   289
slouken@5408
   290
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
slouken@2873
   291
static SDL_bool
slouken@2874
   292
CheckVidMode(Display * display, int *major, int *minor)
slouken@2873
   293
{
slouken@2873
   294
    const char *env;
slouken@2873
   295
slouken@2873
   296
    /* Default the extension not available */
slouken@2873
   297
    *major = *minor = 0;
slouken@2873
   298
slouken@2873
   299
    /* Allow environment override */
slouken@6472
   300
    env = SDL_GetHint(SDL_HINT_VIDEO_X11_XVIDMODE);
slouken@2873
   301
    if (env && !SDL_atoi(env)) {
slouken@6468
   302
#ifdef X11MODES_DEBUG
slouken@6472
   303
        printf("XVidMode disabled due to hint\n");
slouken@6468
   304
#endif
slouken@2873
   305
        return SDL_FALSE;
slouken@2873
   306
    }
slouken@2874
   307
slouken@5408
   308
    if (!SDL_X11_HAVE_XVIDMODE) {
slouken@6468
   309
#ifdef X11MODES_DEBUG
slouken@6468
   310
        printf("XVidMode support not available\n");
slouken@6468
   311
#endif
slouken@5408
   312
        return SDL_FALSE;
slouken@5408
   313
    }
slouken@5408
   314
slouken@2873
   315
    /* Query the extension version */
slouken@2873
   316
    vm_error = -1;
icculus@7827
   317
    if (!X11_XF86VidModeQueryExtension(display, &vm_event, &vm_error)
icculus@7827
   318
        || !X11_XF86VidModeQueryVersion(display, major, minor)) {
slouken@6468
   319
#ifdef X11MODES_DEBUG
slouken@6468
   320
        printf("XVidMode not active on the display\n");
slouken@6468
   321
#endif
slouken@2873
   322
        return SDL_FALSE;
slouken@2873
   323
    }
slouken@6468
   324
#ifdef X11MODES_DEBUG
slouken@6548
   325
    printf("XVidMode available at version %d.%d!\n", *major, *minor);
slouken@6468
   326
#endif
slouken@2873
   327
    return SDL_TRUE;
slouken@2873
   328
}
slouken@2873
   329
slouken@4518
   330
static
slouken@5408
   331
Bool XF86VidModeGetModeInfo(Display * dpy, int scr,
slouken@5408
   332
                                       XF86VidModeModeInfo* info)
slouken@2873
   333
{
slouken@2873
   334
    Bool retval;
slouken@2873
   335
    int dotclock;
slouken@5408
   336
    XF86VidModeModeLine l;
slouken@2873
   337
    SDL_zerop(info);
slouken@2873
   338
    SDL_zero(l);
icculus@7827
   339
    retval = X11_XF86VidModeGetModeLine(dpy, scr, &dotclock, &l);
slouken@2873
   340
    info->dotclock = dotclock;
slouken@2873
   341
    info->hdisplay = l.hdisplay;
slouken@2873
   342
    info->hsyncstart = l.hsyncstart;
slouken@2873
   343
    info->hsyncend = l.hsyncend;
slouken@2873
   344
    info->htotal = l.htotal;
slouken@2873
   345
    info->hskew = l.hskew;
slouken@2873
   346
    info->vdisplay = l.vdisplay;
slouken@2873
   347
    info->vsyncstart = l.vsyncstart;
slouken@2873
   348
    info->vsyncend = l.vsyncend;
slouken@2873
   349
    info->vtotal = l.vtotal;
slouken@2873
   350
    info->flags = l.flags;
slouken@2873
   351
    info->privsize = l.privsize;
slouken@2873
   352
    info->private = l.private;
slouken@2873
   353
    return retval;
slouken@2873
   354
}
slouken@2873
   355
slouken@2873
   356
static int
slouken@6548
   357
CalculateXVidModeRefreshRate(const XF86VidModeModeInfo * info)
slouken@2873
   358
{
slouken@2874
   359
    return (info->htotal
slouken@2874
   360
            && info->vtotal) ? (1000 * info->dotclock / (info->htotal *
slouken@2874
   361
                                                         info->vtotal)) : 0;
slouken@2873
   362
}
slouken@2873
   363
slouken@6548
   364
SDL_bool
slouken@6548
   365
SetXVidModeModeInfo(const XF86VidModeModeInfo *info, SDL_DisplayMode *mode)
slouken@2873
   366
{
slouken@6548
   367
    mode->w = info->hdisplay;
slouken@6548
   368
    mode->h = info->vdisplay;
slouken@6548
   369
    mode->refresh_rate = CalculateXVidModeRefreshRate(info);
slouken@6548
   370
    ((SDL_DisplayModeData*)mode->driverdata)->vm_mode = *info;
slouken@6548
   371
    return SDL_TRUE;
slouken@2873
   372
}
slouken@6548
   373
#endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
slouken@2873
   374
slouken@6548
   375
int
slouken@6548
   376
X11_InitModes(_THIS)
slouken@2873
   377
{
slouken@6548
   378
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
gabomdq@9167
   379
    int snum, screen, screencount;
slouken@6548
   380
#if SDL_VIDEO_DRIVER_X11_XINERAMA
slouken@6548
   381
    int xinerama_major, xinerama_minor;
slouken@6548
   382
    int use_xinerama = 0;
slouken@6548
   383
    XineramaScreenInfo *xinerama = NULL;
slouken@6548
   384
#endif
slouken@6548
   385
#if SDL_VIDEO_DRIVER_X11_XRANDR
slouken@6548
   386
    int xrandr_major, xrandr_minor;
slouken@6548
   387
    int use_xrandr = 0;
slouken@6548
   388
    XRRScreenResources *res = NULL;
slouken@6548
   389
#endif
slouken@6548
   390
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
slouken@6548
   391
    int vm_major, vm_minor;
slouken@6548
   392
    int use_vidmode = 0;
slouken@6548
   393
#endif
slouken@2873
   394
slouken@6548
   395
#if SDL_VIDEO_DRIVER_X11_XINERAMA
slouken@6548
   396
    /* Query Xinerama extention
slouken@6548
   397
     * NOTE: This works with Nvidia Twinview correctly, but you need version 302.17 (released on June 2012)
slouken@6548
   398
     *       or newer of the Nvidia binary drivers
slouken@6548
   399
     */
slouken@6548
   400
    if (CheckXinerama(data->display, &xinerama_major, &xinerama_minor)) {
icculus@7827
   401
        xinerama = X11_XineramaQueryScreens(data->display, &screencount);
slouken@6548
   402
        if (xinerama) {
slouken@6548
   403
            use_xinerama = xinerama_major * 100 + xinerama_minor;
slouken@2873
   404
        }
slouken@2873
   405
    }
slouken@6548
   406
    if (!xinerama) {
slouken@6548
   407
        screencount = ScreenCount(data->display);
slouken@2873
   408
    }
slouken@6548
   409
#else
slouken@6548
   410
    screencount = ScreenCount(data->display);
slouken@6548
   411
#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
slouken@6548
   412
slouken@6548
   413
#if SDL_VIDEO_DRIVER_X11_XRANDR
slouken@6548
   414
    /* require at least XRandR v1.2 */
slouken@6548
   415
    if (CheckXRandR(data->display, &xrandr_major, &xrandr_minor) &&
slouken@6548
   416
        (xrandr_major >= 2 || (xrandr_major == 1 && xrandr_minor >= 2))) {
slouken@6548
   417
        use_xrandr = xrandr_major * 100 + xrandr_minor;
slouken@6548
   418
    }
slouken@6548
   419
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
slouken@6548
   420
slouken@6548
   421
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
slouken@6548
   422
    if (CheckVidMode(data->display, &vm_major, &vm_minor)) {
slouken@6548
   423
        use_vidmode = vm_major * 100 + vm_minor;
slouken@6548
   424
    }
slouken@6548
   425
#endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
slouken@6548
   426
gabomdq@9167
   427
    for (snum = 0; snum < screencount; ++snum) {
slouken@6548
   428
        XVisualInfo vinfo;
slouken@6548
   429
        SDL_VideoDisplay display;
slouken@6548
   430
        SDL_DisplayData *displaydata;
slouken@6548
   431
        SDL_DisplayMode mode;
slouken@6548
   432
        SDL_DisplayModeData *modedata;
slouken@6548
   433
        XPixmapFormatValues *pixmapFormats;
slouken@6796
   434
        char display_name[128];
slouken@6548
   435
        int i, n;
slouken@6548
   436
gabomdq@9167
   437
        /* Re-order screens to always put default screen first */
gabomdq@9167
   438
        if (snum == 0) {
gabomdq@9167
   439
            screen = DefaultScreen(data->display);
gabomdq@9167
   440
        } else if (snum == DefaultScreen(data->display)) {
gabomdq@9167
   441
            screen = 0;
gabomdq@9167
   442
        } else {
gabomdq@9167
   443
            screen = snum;
gabomdq@9167
   444
        }
gabomdq@9167
   445
slouken@6548
   446
#if SDL_VIDEO_DRIVER_X11_XINERAMA
slouken@6548
   447
        if (xinerama) {
slouken@6548
   448
            if (get_visualinfo(data->display, 0, &vinfo) < 0) {
slouken@6548
   449
                continue;
slouken@6548
   450
            }
slouken@6548
   451
        } else {
slouken@6548
   452
            if (get_visualinfo(data->display, screen, &vinfo) < 0) {
slouken@6548
   453
                continue;
slouken@6548
   454
            }
slouken@6548
   455
        }
slouken@6548
   456
#else
slouken@6548
   457
        if (get_visualinfo(data->display, screen, &vinfo) < 0) {
slouken@6548
   458
            continue;
slouken@6548
   459
        }
slouken@6548
   460
#endif
slouken@6548
   461
slouken@6548
   462
        displaydata = (SDL_DisplayData *) SDL_calloc(1, sizeof(*displaydata));
slouken@6548
   463
        if (!displaydata) {
slouken@6548
   464
            continue;
slouken@6548
   465
        }
slouken@6796
   466
        display_name[0] = '\0';
slouken@6548
   467
slouken@6548
   468
        mode.format = X11_GetPixelFormatFromVisualInfo(data->display, &vinfo);
slouken@6548
   469
        if (SDL_ISPIXELFORMAT_INDEXED(mode.format)) {
slouken@6548
   470
            /* We don't support palettized modes now */
slouken@6548
   471
            SDL_free(displaydata);
slouken@6548
   472
            continue;
slouken@6548
   473
        }
slouken@6548
   474
#if SDL_VIDEO_DRIVER_X11_XINERAMA
slouken@6548
   475
        if (xinerama) {
slouken@6548
   476
            mode.w = xinerama[screen].width;
slouken@6548
   477
            mode.h = xinerama[screen].height;
slouken@6548
   478
        } else {
slouken@6548
   479
            mode.w = DisplayWidth(data->display, screen);
slouken@6548
   480
            mode.h = DisplayHeight(data->display, screen);
slouken@6548
   481
        }
slouken@6548
   482
#else
slouken@6548
   483
        mode.w = DisplayWidth(data->display, screen);
slouken@6548
   484
        mode.h = DisplayHeight(data->display, screen);
slouken@6548
   485
#endif
slouken@6548
   486
        mode.refresh_rate = 0;
slouken@6548
   487
slouken@6548
   488
        modedata = (SDL_DisplayModeData *) SDL_calloc(1, sizeof(SDL_DisplayModeData));
slouken@6548
   489
        if (!modedata) {
slouken@6548
   490
            SDL_free(displaydata);
slouken@6548
   491
            continue;
slouken@6548
   492
        }
slouken@6548
   493
        mode.driverdata = modedata;
slouken@6548
   494
slouken@6548
   495
#if SDL_VIDEO_DRIVER_X11_XINERAMA
slouken@6548
   496
        /* Most of SDL's calls to X11 are unwaware of Xinerama, and to X11 standard calls, when Xinerama is active,
slouken@6548
   497
         * there's only one screen available. So we force the screen number to zero and
slouken@6548
   498
         * let Xinerama specific code handle specific functionality using displaydata->xinerama_info
slouken@6548
   499
         */
slouken@6548
   500
        if (use_xinerama) {
slouken@6548
   501
            displaydata->screen = 0;
slouken@6548
   502
            displaydata->use_xinerama = use_xinerama;
slouken@6548
   503
            displaydata->xinerama_info = xinerama[screen];
slouken@6548
   504
            displaydata->xinerama_screen = screen;
slouken@6548
   505
        }
slouken@6548
   506
        else displaydata->screen = screen;
slouken@6548
   507
#else
slouken@6548
   508
        displaydata->screen = screen;
slouken@6548
   509
#endif
slouken@6548
   510
        displaydata->visual = vinfo.visual;
slouken@6548
   511
        displaydata->depth = vinfo.depth;
slouken@6548
   512
slouken@6548
   513
        displaydata->scanline_pad = SDL_BYTESPERPIXEL(mode.format) * 8;
icculus@7827
   514
        pixmapFormats = X11_XListPixmapFormats(data->display, &n);
slouken@6548
   515
        if (pixmapFormats) {
slouken@6548
   516
            for (i = 0; i < n; ++i) {
slouken@6548
   517
                if (pixmapFormats[i].depth == displaydata->depth) {
slouken@6548
   518
                    displaydata->scanline_pad = pixmapFormats[i].scanline_pad;
slouken@6548
   519
                    break;
slouken@6548
   520
                }
slouken@6548
   521
            }
icculus@7827
   522
            X11_XFree(pixmapFormats);
slouken@6548
   523
        }
slouken@6548
   524
slouken@6548
   525
#if SDL_VIDEO_DRIVER_X11_XINERAMA
slouken@6548
   526
        if (use_xinerama) {
slouken@6548
   527
            displaydata->x = xinerama[screen].x_org;
slouken@6548
   528
            displaydata->y = xinerama[screen].y_org;
slouken@6548
   529
        }
slouken@6548
   530
        else
slouken@6548
   531
#endif
slouken@6548
   532
        {
slouken@6548
   533
            displaydata->x = 0;
slouken@6548
   534
            displaydata->y = 0;
slouken@6548
   535
        }
slouken@6548
   536
slouken@6548
   537
#if SDL_VIDEO_DRIVER_X11_XRANDR
slouken@6548
   538
        if (use_xrandr) {
icculus@7827
   539
            res = X11_XRRGetScreenResources(data->display, RootWindow(data->display, displaydata->screen));
slouken@6548
   540
        }
slouken@6548
   541
        if (res) {
slouken@6548
   542
            XRROutputInfo *output_info;
slouken@6548
   543
            XRRCrtcInfo *crtc;
slouken@6548
   544
            int output;
icculus@7827
   545
            Atom EDID = X11_XInternAtom(data->display, "EDID", False);
slouken@6796
   546
            Atom *props;
slouken@6796
   547
            int nprop;
slouken@6796
   548
            unsigned long width_mm;
slouken@6796
   549
            unsigned long height_mm;
slouken@6796
   550
            int inches = 0;
slouken@6548
   551
slouken@6548
   552
            for (output = 0; output < res->noutput; output++) {
icculus@7827
   553
                output_info = X11_XRRGetOutputInfo(data->display, res, res->outputs[output]);
slouken@6550
   554
                if (!output_info || !output_info->crtc ||
slouken@6550
   555
                    output_info->connection == RR_Disconnected) {
icculus@7827
   556
                    X11_XRRFreeOutputInfo(output_info);
slouken@6548
   557
                    continue;
slouken@6548
   558
                }
slouken@6548
   559
slouken@6548
   560
                /* Is this the output that corresponds to the current screen?
slouken@6548
   561
                   We're checking the crtc position, but that may not be a valid test
slouken@6548
   562
                   in all cases.  Anybody want to give this some love?
slouken@6548
   563
                 */
icculus@7827
   564
                crtc = X11_XRRGetCrtcInfo(data->display, res, output_info->crtc);
slouken@7914
   565
                if (!crtc || crtc->x != displaydata->x || crtc->y != displaydata->y ||
slouken@7914
   566
                    crtc->width != mode.w || crtc->height != mode.h) {
icculus@7827
   567
                    X11_XRRFreeOutputInfo(output_info);
icculus@7827
   568
                    X11_XRRFreeCrtcInfo(crtc);
slouken@6548
   569
                    continue;
slouken@6548
   570
                }
slouken@6548
   571
slouken@6548
   572
                displaydata->use_xrandr = use_xrandr;
slouken@6548
   573
                displaydata->xrandr_output = res->outputs[output];
slouken@6548
   574
                SetXRandRModeInfo(data->display, res, output_info, crtc->mode, &mode);
slouken@6548
   575
slouken@6796
   576
                /* Get the name of this display */
slouken@6796
   577
                width_mm = output_info->mm_width;
slouken@6796
   578
                height_mm = output_info->mm_height;
slouken@6796
   579
                inches = (int)((sqrt(width_mm * width_mm +
slouken@6796
   580
                                     height_mm * height_mm) / 25.4f) + 0.5f);
slouken@6796
   581
                SDL_strlcpy(display_name, output_info->name, sizeof(display_name));
slouken@6796
   582
slouken@6796
   583
                /* See if we can get the EDID data for the real monitor name */
icculus@7827
   584
                props = X11_XRRListOutputProperties(data->display, res->outputs[output], &nprop);
slouken@6796
   585
                for (i = 0; i < nprop; ++i) {
slouken@6796
   586
                    unsigned char *prop;
slouken@6796
   587
                    int actual_format;
slouken@6796
   588
                    unsigned long nitems, bytes_after;
slouken@6796
   589
                    Atom actual_type;
slouken@6940
   590
slouken@7191
   591
                    if (props[i] == EDID) {
icculus@7827
   592
                        if (X11_XRRGetOutputProperty(data->display,
slouken@6940
   593
                                                 res->outputs[output], props[i],
slouken@6940
   594
                                                 0, 100, False, False,
slouken@6940
   595
                                                 AnyPropertyType,
slouken@6940
   596
                                                 &actual_type, &actual_format,
slouken@6940
   597
                                                 &nitems, &bytes_after, &prop) == Success ) {
slouken@6940
   598
                            MonitorInfo *info = decode_edid(prop);
slouken@6940
   599
                            if (info) {
slouken@6940
   600
    #ifdef X11MODES_DEBUG
slouken@6940
   601
                                printf("Found EDID data for %s\n", output_info->name);
slouken@6940
   602
                                dump_monitor_info(info);
slouken@6940
   603
    #endif
slouken@6940
   604
                                SDL_strlcpy(display_name, info->dsc_product_name, sizeof(display_name));
slouken@6940
   605
                                free(info);
slouken@6940
   606
                            }
icculus@7827
   607
                            X11_XFree(prop);
slouken@6796
   608
                        }
slouken@6796
   609
                        break;
slouken@6796
   610
                    }
slouken@6796
   611
                }
slouken@6940
   612
                if (props) {
icculus@7827
   613
                    X11_XFree(props);
slouken@6940
   614
                }
slouken@6796
   615
slouken@6796
   616
                if (*display_name && inches) {
slouken@6796
   617
                    size_t len = SDL_strlen(display_name);
slouken@6796
   618
                    SDL_snprintf(&display_name[len], sizeof(display_name)-len, " %d\"", inches);
slouken@6796
   619
                }
slouken@6796
   620
#ifdef X11MODES_DEBUG
slouken@6796
   621
                printf("Display name: %s\n", display_name);
slouken@6796
   622
#endif
slouken@6796
   623
icculus@7827
   624
                X11_XRRFreeOutputInfo(output_info);
icculus@7827
   625
                X11_XRRFreeCrtcInfo(crtc);
slouken@6548
   626
                break;
slouken@6548
   627
            }
slouken@6548
   628
#ifdef X11MODES_DEBUG
slouken@6548
   629
            if (output == res->noutput) {
slouken@6548
   630
                printf("Couldn't find XRandR CRTC at %d,%d\n", displaydata->x, displaydata->y);
slouken@6548
   631
            }
slouken@6548
   632
#endif
icculus@7827
   633
            X11_XRRFreeScreenResources(res);
slouken@6548
   634
        }
slouken@6548
   635
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
slouken@6548
   636
slouken@6548
   637
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
slouken@6548
   638
        if (!displaydata->use_xrandr &&
slouken@6548
   639
#if SDL_VIDEO_DRIVER_X11_XINERAMA
slouken@6564
   640
            /* XVidMode only works on the screen at the origin */
slouken@6564
   641
            (!displaydata->use_xinerama ||
slouken@6564
   642
             (displaydata->x == 0 && displaydata->y == 0)) &&
slouken@6548
   643
#endif
slouken@6548
   644
            use_vidmode) {
slouken@6548
   645
            displaydata->use_vidmode = use_vidmode;
slouken@6565
   646
            if (displaydata->use_xinerama) {
slouken@6565
   647
                displaydata->vidmode_screen = 0;
slouken@6565
   648
            } else {
slouken@6565
   649
                displaydata->vidmode_screen = screen;
slouken@6565
   650
            }
slouken@6565
   651
            XF86VidModeGetModeInfo(data->display, displaydata->vidmode_screen, &modedata->vm_mode);
slouken@6548
   652
        }
slouken@6548
   653
#endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
slouken@6548
   654
slouken@6548
   655
        SDL_zero(display);
slouken@6796
   656
        if (*display_name) {
slouken@6796
   657
            display.name = display_name;
slouken@6796
   658
        }
slouken@6548
   659
        display.desktop_mode = mode;
slouken@6548
   660
        display.current_mode = mode;
slouken@6548
   661
        display.driverdata = displaydata;
slouken@6548
   662
        SDL_AddVideoDisplay(&display);
slouken@6548
   663
    }
slouken@6548
   664
slouken@6548
   665
#if SDL_VIDEO_DRIVER_X11_XINERAMA
icculus@7827
   666
    if (xinerama) X11_XFree(xinerama);
slouken@6548
   667
#endif
slouken@6548
   668
slouken@6548
   669
    if (_this->num_displays == 0) {
icculus@7037
   670
        return SDL_SetError("No available displays");
slouken@6548
   671
    }
slouken@6548
   672
    return 0;
slouken@2873
   673
}
slouken@2873
   674
slouken@1950
   675
void
slouken@3500
   676
X11_GetDisplayModes(_THIS, SDL_VideoDisplay * sdl_display)
slouken@1950
   677
{
slouken@2870
   678
    Display *display = ((SDL_VideoData *) _this->driverdata)->display;
slouken@3500
   679
    SDL_DisplayData *data = (SDL_DisplayData *) sdl_display->driverdata;
slouken@5408
   680
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
slouken@2873
   681
    int nmodes;
slouken@5408
   682
    XF86VidModeModeInfo ** modes;
slouken@2873
   683
#endif
slouken@2873
   684
    int screen_w;
slouken@2873
   685
    int screen_h;
slouken@1950
   686
    SDL_DisplayMode mode;
slouken@2870
   687
slouken@2873
   688
    /* Unfortunately X11 requires the window to be created with the correct
slouken@2873
   689
     * visual and depth ahead of time, but the SDL API allows you to create
slouken@2873
   690
     * a window before setting the fullscreen display mode.  This means that
slouken@2873
   691
     * we have to use the same format for all windows and all display modes.
slouken@2873
   692
     * (or support recreating the window with a new visual behind the scenes)
slouken@2873
   693
     */
slouken@3500
   694
    mode.format = sdl_display->current_mode.format;
slouken@2873
   695
    mode.driverdata = NULL;
slouken@2873
   696
slouken@2873
   697
    screen_w = DisplayWidth(display, data->screen);
slouken@2873
   698
    screen_h = DisplayHeight(display, data->screen);
slouken@2873
   699
slouken@2873
   700
#if SDL_VIDEO_DRIVER_X11_XINERAMA
gabomdq@6331
   701
    if (data->use_xinerama) {
david@7361
   702
        if (data->use_vidmode && !data->xinerama_info.x_org && !data->xinerama_info.y_org &&
gabomdq@6331
   703
           (screen_w > data->xinerama_info.width || screen_h > data->xinerama_info.height)) {
slouken@8922
   704
            SDL_DisplayModeData *modedata;
david@7361
   705
            /* Add the full (both screens combined) xinerama mode only on the display that starts at 0,0
david@7361
   706
             * if we're using vidmode.
david@7361
   707
             */
gabomdq@6331
   708
            mode.w = screen_w;
gabomdq@6331
   709
            mode.h = screen_h;
slouken@2873
   710
            mode.refresh_rate = 0;
slouken@6548
   711
            modedata = (SDL_DisplayModeData *) SDL_calloc(1, sizeof(SDL_DisplayModeData));
slouken@6548
   712
            if (modedata) {
slouken@6548
   713
                *modedata = *(SDL_DisplayModeData *)sdl_display->desktop_mode.driverdata;
slouken@6548
   714
            }
slouken@6548
   715
            mode.driverdata = modedata;
slouken@3500
   716
            SDL_AddDisplayMode(sdl_display, &mode);
slouken@2873
   717
        }
david@7431
   718
        else if (!data->use_xrandr)
david@7361
   719
        {
slouken@8922
   720
            SDL_DisplayModeData *modedata;
david@7431
   721
            /* Add the current mode of each monitor otherwise if we can't get them from xrandr */
david@7361
   722
            mode.w = data->xinerama_info.width;
david@7361
   723
            mode.h = data->xinerama_info.height;
david@7361
   724
            mode.refresh_rate = 0;
david@7361
   725
            modedata = (SDL_DisplayModeData *) SDL_calloc(1, sizeof(SDL_DisplayModeData));
david@7361
   726
            if (modedata) {
david@7361
   727
                *modedata = *(SDL_DisplayModeData *)sdl_display->desktop_mode.driverdata;
david@7361
   728
            }
david@7361
   729
            mode.driverdata = modedata;
david@7361
   730
            SDL_AddDisplayMode(sdl_display, &mode);
david@7361
   731
        }
david@7361
   732
slouken@2873
   733
    }
slouken@2873
   734
#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
slouken@2873
   735
slouken@2873
   736
#if SDL_VIDEO_DRIVER_X11_XRANDR
slouken@6548
   737
    if (data->use_xrandr) {
slouken@6548
   738
        XRRScreenResources *res;
slouken@2873
   739
icculus@7827
   740
        res = X11_XRRGetScreenResources (display, RootWindow(display, data->screen));
slouken@6548
   741
        if (res) {
slouken@6548
   742
            SDL_DisplayModeData *modedata;
slouken@6548
   743
            XRROutputInfo *output_info;
slouken@6548
   744
            int i;
slouken@2873
   745
icculus@7827
   746
            output_info = X11_XRRGetOutputInfo(display, res, data->xrandr_output);
slouken@6548
   747
            if (output_info && output_info->connection != RR_Disconnected) {
slouken@6548
   748
                for (i = 0; i < output_info->nmode; ++i) {
slouken@6548
   749
                    modedata = (SDL_DisplayModeData *) SDL_calloc(1, sizeof(SDL_DisplayModeData));
slouken@6548
   750
                    if (!modedata) {
slouken@6548
   751
                        continue;
slouken@6548
   752
                    }
slouken@6548
   753
                    mode.driverdata = modedata;
slouken@2873
   754
slouken@6548
   755
                    if (SetXRandRModeInfo(display, res, output_info, output_info->modes[i], &mode)) {
slouken@6548
   756
                        SDL_AddDisplayMode(sdl_display, &mode);
slouken@6548
   757
                    } else {
slouken@6548
   758
                        SDL_free(modedata);
slouken@6548
   759
                    }
slouken@2873
   760
                }
slouken@2873
   761
            }
icculus@7827
   762
            X11_XRRFreeOutputInfo(output_info);
icculus@7827
   763
            X11_XRRFreeScreenResources(res);
slouken@2873
   764
        }
slouken@6548
   765
        return;
slouken@2873
   766
    }
slouken@2873
   767
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
slouken@2873
   768
slouken@5408
   769
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
slouken@6548
   770
    if (data->use_vidmode &&
icculus@7827
   771
        X11_XF86VidModeGetAllModeLines(display, data->vidmode_screen, &nmodes, &modes)) {
slouken@2873
   772
        int i;
slouken@8922
   773
        SDL_DisplayModeData *modedata;
slouken@2873
   774
slouken@2873
   775
#ifdef X11MODES_DEBUG
slouken@2873
   776
        printf("VidMode modes: (unsorted)\n");
slouken@2873
   777
        for (i = 0; i < nmodes; ++i) {
slouken@6566
   778
            printf("Mode %d: %d x %d @ %d, flags: 0x%x\n", i,
slouken@2874
   779
                   modes[i]->hdisplay, modes[i]->vdisplay,
slouken@6566
   780
                   CalculateXVidModeRefreshRate(modes[i]), modes[i]->flags);
slouken@2873
   781
        }
slouken@2873
   782
#endif
slouken@2873
   783
        for (i = 0; i < nmodes; ++i) {
slouken@6548
   784
            modedata = (SDL_DisplayModeData *) SDL_calloc(1, sizeof(SDL_DisplayModeData));
slouken@6548
   785
            if (!modedata) {
slouken@6548
   786
                continue;
slouken@6548
   787
            }
slouken@6548
   788
            mode.driverdata = modedata;
slouken@6548
   789
slouken@6548
   790
            if (SetXVidModeModeInfo(modes[i], &mode)) {
slouken@6548
   791
                SDL_AddDisplayMode(sdl_display, &mode);
slouken@6548
   792
            } else {
slouken@6548
   793
                SDL_free(modedata);
slouken@6548
   794
            }
slouken@2873
   795
        }
icculus@7827
   796
        X11_XFree(modes);
slouken@6548
   797
        return;
slouken@2873
   798
    }
slouken@5408
   799
#endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
slouken@2873
   800
slouken@2873
   801
    if (!data->use_xrandr && !data->use_vidmode) {
slouken@8922
   802
        SDL_DisplayModeData *modedata;
slouken@6548
   803
        /* Add the desktop mode */
slouken@6548
   804
        mode = sdl_display->desktop_mode;
slouken@6548
   805
        modedata = (SDL_DisplayModeData *) SDL_calloc(1, sizeof(SDL_DisplayModeData));
slouken@6548
   806
        if (modedata) {
slouken@6548
   807
            *modedata = *(SDL_DisplayModeData *)sdl_display->desktop_mode.driverdata;
slouken@6548
   808
        }
slouken@6548
   809
        mode.driverdata = modedata;
slouken@3500
   810
        SDL_AddDisplayMode(sdl_display, &mode);
slouken@2874
   811
    }
slouken@1950
   812
}
slouken@1950
   813
slouken@1950
   814
int
slouken@3500
   815
X11_SetDisplayMode(_THIS, SDL_VideoDisplay * sdl_display, SDL_DisplayMode * mode)
slouken@1950
   816
{
icculus@9319
   817
    SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata;
icculus@9319
   818
    Display *display = viddata->display;
slouken@3500
   819
    SDL_DisplayData *data = (SDL_DisplayData *) sdl_display->driverdata;
slouken@6548
   820
    SDL_DisplayModeData *modedata = (SDL_DisplayModeData *)mode->driverdata;
slouken@2873
   821
icculus@9319
   822
    viddata->last_mode_change_deadline = SDL_GetTicks() + (PENDING_FOCUS_TIME * 2);
icculus@9319
   823
slouken@6548
   824
#if SDL_VIDEO_DRIVER_X11_XRANDR
slouken@6548
   825
    if (data->use_xrandr) {
slouken@6548
   826
        XRRScreenResources *res;
slouken@6548
   827
        XRROutputInfo *output_info;
slouken@6548
   828
        XRRCrtcInfo *crtc;
slouken@6548
   829
        Status status;
slouken@6548
   830
icculus@7827
   831
        res = X11_XRRGetScreenResources (display, RootWindow(display, data->screen));
slouken@6548
   832
        if (!res) {
icculus@7037
   833
            return SDL_SetError("Couldn't get XRandR screen resources");
slouken@6548
   834
        }
slouken@6548
   835
icculus@7827
   836
        output_info = X11_XRRGetOutputInfo(display, res, data->xrandr_output);
slouken@6548
   837
        if (!output_info || output_info->connection == RR_Disconnected) {
icculus@7827
   838
            X11_XRRFreeScreenResources(res);
icculus@7037
   839
            return SDL_SetError("Couldn't get XRandR output info");
slouken@6548
   840
        }
slouken@6548
   841
icculus@7827
   842
        crtc = X11_XRRGetCrtcInfo(display, res, output_info->crtc);
slouken@6548
   843
        if (!crtc) {
icculus@7827
   844
            X11_XRRFreeOutputInfo(output_info);
icculus@7827
   845
            X11_XRRFreeScreenResources(res);
icculus@7037
   846
            return SDL_SetError("Couldn't get XRandR crtc info");
slouken@6548
   847
        }
slouken@6548
   848
icculus@7827
   849
        status = X11_XRRSetCrtcConfig (display, res, output_info->crtc, CurrentTime,
slouken@6548
   850
          crtc->x, crtc->y, modedata->xrandr_mode, crtc->rotation,
slouken@6548
   851
          &data->xrandr_output, 1);
slouken@6548
   852
icculus@7827
   853
        X11_XRRFreeCrtcInfo(crtc);
icculus@7827
   854
        X11_XRRFreeOutputInfo(output_info);
icculus@7827
   855
        X11_XRRFreeScreenResources(res);
slouken@6548
   856
slouken@6548
   857
        if (status != Success) {
icculus@7827
   858
            return SDL_SetError("X11_XRRSetCrtcConfig failed");
slouken@6548
   859
        }
slouken@6548
   860
    }
slouken@6548
   861
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
slouken@6548
   862
slouken@6548
   863
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
slouken@6548
   864
    if (data->use_vidmode) {
icculus@7827
   865
        X11_XF86VidModeSwitchToMode(display, data->vidmode_screen, &modedata->vm_mode);
slouken@6548
   866
    }
slouken@6548
   867
#endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
slouken@6548
   868
slouken@2873
   869
    return 0;
slouken@1950
   870
}
slouken@1950
   871
slouken@1950
   872
void
slouken@1950
   873
X11_QuitModes(_THIS)
slouken@1950
   874
{
slouken@1950
   875
}
slouken@1950
   876
gabomdq@6331
   877
int
gabomdq@6331
   878
X11_GetDisplayBounds(_THIS, SDL_VideoDisplay * sdl_display, SDL_Rect * rect)
gabomdq@6331
   879
{
gabomdq@6331
   880
    SDL_DisplayData *data = (SDL_DisplayData *) sdl_display->driverdata;
slouken@6502
   881
slouken@6548
   882
    rect->x = data->x;
slouken@6548
   883
    rect->y = data->y;
slouken@6548
   884
    rect->w = sdl_display->current_mode.w;
slouken@6548
   885
    rect->h = sdl_display->current_mode.h;
gabomdq@6331
   886
gabomdq@6331
   887
#if SDL_VIDEO_DRIVER_X11_XINERAMA
slouken@6548
   888
    /* Get the real current bounds of the display */
slouken@6502
   889
    if (data->use_xinerama) {
icculus@7485
   890
        Display *display = ((SDL_VideoData *) _this->driverdata)->display;
slouken@6548
   891
        int screencount;
icculus@7827
   892
        XineramaScreenInfo *xinerama = X11_XineramaQueryScreens(display, &screencount);
slouken@6548
   893
        if (xinerama) {
slouken@6548
   894
            rect->x = xinerama[data->xinerama_screen].x_org;
slouken@6548
   895
            rect->y = xinerama[data->xinerama_screen].y_org;
icculus@7827
   896
            X11_XFree(xinerama);
slouken@6548
   897
        }
gabomdq@6331
   898
    }
slouken@6548
   899
#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
slouken@6475
   900
    return 0;
gabomdq@6331
   901
}
gabomdq@6331
   902
slouken@5481
   903
#endif /* SDL_VIDEO_DRIVER_X11 */
slouken@5481
   904
slouken@1950
   905
/* vi: set ts=4 sw=4 expandtab: */