src/video/x11/SDL_x11modes.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 03 Oct 2012 19:25:08 -0700
changeset 6551 b0679a0d5751
parent 6550 191f00a080ba
child 6553 2f03111a2105
permissions -rw-r--r--
Fixed refresh rate calculation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
     2
  Simple DirectMedia Layer
6138
4c64952a58fb Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 6027
diff changeset
     3
  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
     7
  arising from the use of this software.
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    11
  freely, subject to the following restrictions:
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
#include "SDL_config.h"
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
5481
22dfc3958dc3 Fixed so code will compile with SDL_config_minimal.h
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
    23
#if SDL_VIDEO_DRIVER_X11
22dfc3958dc3 Fixed so code will compile with SDL_config_minimal.h
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
    24
6472
d4623b7209db Turned the X11 mode extension environment variables into hints so they can be more easily set from applications.
Sam Lantinga <slouken@libsdl.org>
parents: 6468
diff changeset
    25
#include "SDL_hints.h"
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
#include "SDL_x11video.h"
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
6538
05cf19d1eb53 Fixed compile error - had work in progress in there.
Sam Lantinga <slouken@libsdl.org>
parents: 6537
diff changeset
    28
/*#define X11MODES_DEBUG*/
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    30
static int
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
get_visualinfo(Display * display, int screen, XVisualInfo * vinfo)
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
{
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    33
    const char *visual_id = SDL_getenv("SDL_VIDEO_X11_VISUALID");
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
    int depth;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    35
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    36
    /* Look for an exact visual, if requested */
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
    if (visual_id) {
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    38
        XVisualInfo *vi, template;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    39
        int nvis;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    40
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    41
        SDL_zero(template);
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    42
        template.visualid = SDL_strtol(visual_id, NULL, 0);
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    43
        vi = XGetVisualInfo(display, VisualIDMask, &template, &nvis);
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    44
        if (vi) {
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    45
            *vinfo = *vi;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    46
            XFree(vi);
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    47
            return 0;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    48
        }
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    49
    }
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    50
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    51
    depth = DefaultDepth(display, screen);
5466
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5408
diff changeset
    52
    if ((X11_UseDirectColorVisuals() &&
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5408
diff changeset
    53
         XMatchVisualInfo(display, screen, depth, DirectColor, vinfo)) ||
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5408
diff changeset
    54
        XMatchVisualInfo(display, screen, depth, TrueColor, vinfo) ||
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    55
        XMatchVisualInfo(display, screen, depth, PseudoColor, vinfo) ||
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    56
        XMatchVisualInfo(display, screen, depth, StaticColor, vinfo)) {
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    57
        return 0;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    58
    }
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    59
    return -1;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    60
}
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    61
5182
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    62
int
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    63
X11_GetVisualInfoFromVisual(Display * display, Visual * visual, XVisualInfo * vinfo)
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    64
{
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    65
    XVisualInfo *vi;
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    66
    int nvis;
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    67
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    68
    vinfo->visualid = XVisualIDFromVisual(visual);
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    69
    vi = XGetVisualInfo(display, VisualIDMask, vinfo, &nvis);
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    70
    if (vi) {
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    71
        *vinfo = *vi;
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    72
        XFree(vi);
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    73
        return 0;
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    74
    }
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    75
    return -1;
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    76
}
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    77
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    78
Uint32
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
    79
X11_GetPixelFormatFromVisualInfo(Display * display, XVisualInfo * vinfo)
2870
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    80
{
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    81
    if (vinfo->class == DirectColor || vinfo->class == TrueColor) {
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    82
        int bpp;
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    83
        Uint32 Rmask, Gmask, Bmask, Amask;
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    84
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    85
        Rmask = vinfo->visual->red_mask;
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    86
        Gmask = vinfo->visual->green_mask;
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    87
        Bmask = vinfo->visual->blue_mask;
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    88
        if (vinfo->depth == 32) {
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    89
            Amask = (0xFFFFFFFF & ~(Rmask | Gmask | Bmask));
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    90
        } else {
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    91
            Amask = 0;
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    92
        }
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    93
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    94
        bpp = vinfo->depth;
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    95
        if (bpp == 24) {
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    96
            int i, n;
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    97
            XPixmapFormatValues *p = XListPixmapFormats(display, &n);
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    98
            if (p) {
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    99
                for (i = 0; i < n; ++i) {
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   100
                    if (p[i].depth == 24) {
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   101
                        bpp = p[i].bits_per_pixel;
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   102
                        break;
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   103
                    }
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   104
                }
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   105
                XFree(p);
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   106
            }
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   107
        }
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   108
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   109
        return SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask);
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   110
    }
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   111
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   112
    if (vinfo->class == PseudoColor || vinfo->class == StaticColor) {
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   113
        switch (vinfo->depth) {
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   114
        case 8:
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   115
            return SDL_PIXELTYPE_INDEX8;
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   116
        case 4:
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   117
            if (BitmapBitOrder(display) == LSBFirst) {
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   118
                return SDL_PIXELFORMAT_INDEX4LSB;
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   119
            } else {
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   120
                return SDL_PIXELFORMAT_INDEX4MSB;
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   121
            }
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   122
            break;
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   123
        case 1:
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   124
            if (BitmapBitOrder(display) == LSBFirst) {
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   125
                return SDL_PIXELFORMAT_INDEX1LSB;
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   126
            } else {
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   127
                return SDL_PIXELFORMAT_INDEX1MSB;
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   128
            }
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   129
            break;
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   130
        }
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   131
    }
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   132
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   133
    return SDL_PIXELFORMAT_UNKNOWN;
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   134
}
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   135
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   136
/* Global for the error handler */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   137
int vm_event, vm_error = -1;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   138
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   139
#if SDL_VIDEO_DRIVER_X11_XINERAMA
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   140
static SDL_bool
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   141
CheckXinerama(Display * display, int *major, int *minor)
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   142
{
6027
56185b574d61 Use correct Xinerama APIs for querying version and availability.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   143
    int event_base = 0;
56185b574d61 Use correct Xinerama APIs for querying version and availability.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   144
    int error_base = 0;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   145
    const char *env;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   146
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   147
    /* Default the extension not available */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   148
    *major = *minor = 0;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   149
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   150
    /* Allow environment override */
6472
d4623b7209db Turned the X11 mode extension environment variables into hints so they can be more easily set from applications.
Sam Lantinga <slouken@libsdl.org>
parents: 6468
diff changeset
   151
    env = SDL_GetHint(SDL_HINT_VIDEO_X11_XINERAMA);
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   152
    if (env && !SDL_atoi(env)) {
6468
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   153
#ifdef X11MODES_DEBUG
6472
d4623b7209db Turned the X11 mode extension environment variables into hints so they can be more easily set from applications.
Sam Lantinga <slouken@libsdl.org>
parents: 6468
diff changeset
   154
        printf("Xinerama disabled due to hint\n");
6468
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   155
#endif
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   156
        return SDL_FALSE;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   157
    }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   158
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   159
    if (!SDL_X11_HAVE_XINERAMA) {
6468
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   160
#ifdef X11MODES_DEBUG
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   161
        printf("Xinerama support not available\n");
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   162
#endif
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   163
        return SDL_FALSE;
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   164
    }
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   165
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   166
    /* Query the extension version */
6027
56185b574d61 Use correct Xinerama APIs for querying version and availability.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   167
    if (!XineramaQueryExtension(display, &event_base, &error_base) ||
56185b574d61 Use correct Xinerama APIs for querying version and availability.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   168
        !XineramaQueryVersion(display, major, minor) ||
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   169
        !XineramaIsActive(display)) {
6468
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   170
#ifdef X11MODES_DEBUG
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   171
        printf("Xinerama not active on the display\n");
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   172
#endif
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   173
        return SDL_FALSE;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   174
    }
6468
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   175
#ifdef X11MODES_DEBUG
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   176
    printf("Xinerama available at version %d.%d!\n", *major, *minor);
6468
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   177
#endif
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   178
    return SDL_TRUE;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   179
}
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   180
#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   181
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   182
#if SDL_VIDEO_DRIVER_X11_XRANDR
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   183
static SDL_bool
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   184
CheckXRandR(Display * display, int *major, int *minor)
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   185
{
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   186
    const char *env;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   187
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   188
    /* Default the extension not available */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   189
    *major = *minor = 0;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   190
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   191
    /* Allow environment override */
6472
d4623b7209db Turned the X11 mode extension environment variables into hints so they can be more easily set from applications.
Sam Lantinga <slouken@libsdl.org>
parents: 6468
diff changeset
   192
    env = SDL_GetHint(SDL_HINT_VIDEO_X11_XRANDR);
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   193
    if (env && !SDL_atoi(env)) {
6468
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   194
#ifdef X11MODES_DEBUG
6472
d4623b7209db Turned the X11 mode extension environment variables into hints so they can be more easily set from applications.
Sam Lantinga <slouken@libsdl.org>
parents: 6468
diff changeset
   195
        printf("XRandR disabled due to hint\n");
6468
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   196
#endif
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   197
        return SDL_FALSE;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   198
    }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   199
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   200
    if (!SDL_X11_HAVE_XRANDR) {
6468
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   201
#ifdef X11MODES_DEBUG
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   202
        printf("XRandR support not available\n");
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   203
#endif
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   204
        return SDL_FALSE;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   205
    }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   206
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   207
    /* Query the extension version */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   208
    if (!XRRQueryVersion(display, major, minor)) {
6468
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   209
#ifdef X11MODES_DEBUG
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   210
        printf("XRandR not active on the display\n");
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   211
#endif
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   212
        return SDL_FALSE;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   213
    }
6468
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   214
#ifdef X11MODES_DEBUG
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   215
    printf("XRandR available at version %d.%d!\n", *major, *minor);
6468
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   216
#endif
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   217
    return SDL_TRUE;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   218
}
6537
85cf169db434 Fixed XRandR code to change resolution on the correct monitor in a multi-monitor setup.
Sam Lantinga <slouken@libsdl.org>
parents: 6506
diff changeset
   219
85cf169db434 Fixed XRandR code to change resolution on the correct monitor in a multi-monitor setup.
Sam Lantinga <slouken@libsdl.org>
parents: 6506
diff changeset
   220
#define XRANDR_ROTATION_LEFT    (1 << 1)
85cf169db434 Fixed XRandR code to change resolution on the correct monitor in a multi-monitor setup.
Sam Lantinga <slouken@libsdl.org>
parents: 6506
diff changeset
   221
#define XRANDR_ROTATION_RIGHT   (1 << 3)
85cf169db434 Fixed XRandR code to change resolution on the correct monitor in a multi-monitor setup.
Sam Lantinga <slouken@libsdl.org>
parents: 6506
diff changeset
   222
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   223
static int
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   224
CalculateXRandRRefreshRate(const XRRModeInfo *info)
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   225
{
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   226
    return (info->hTotal
6551
b0679a0d5751 Fixed refresh rate calculation
Sam Lantinga <slouken@libsdl.org>
parents: 6550
diff changeset
   227
            && info->vTotal) ? (info->dotClock / (info->hTotal * info->vTotal)) : 0;
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   228
}
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   229
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   230
static SDL_bool
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   231
SetXRandRModeInfo(Display *display, XRRScreenResources *res, XRROutputInfo *output_info,
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   232
                  RRMode modeID, SDL_DisplayMode *mode)
6537
85cf169db434 Fixed XRandR code to change resolution on the correct monitor in a multi-monitor setup.
Sam Lantinga <slouken@libsdl.org>
parents: 6506
diff changeset
   233
{
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   234
    int i;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   235
    for (i = 0; i < res->nmode; ++i) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   236
        if (res->modes[i].id == modeID) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   237
            XRRCrtcInfo *crtc;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   238
            Rotation rotation = 0;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   239
            const XRRModeInfo *info = &res->modes[i];
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   240
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   241
            crtc = XRRGetCrtcInfo(display, res, output_info->crtc);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   242
            if (crtc) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   243
                rotation = crtc->rotation;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   244
                XRRFreeCrtcInfo(crtc);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   245
            }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   246
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   247
            if (rotation & (XRANDR_ROTATION_LEFT|XRANDR_ROTATION_RIGHT)) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   248
                mode->w = info->height;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   249
                mode->h = info->width;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   250
            } else {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   251
                mode->w = info->width;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   252
                mode->h = info->height;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   253
            }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   254
            mode->refresh_rate = CalculateXRandRRefreshRate(info);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   255
            ((SDL_DisplayModeData*)mode->driverdata)->xrandr_mode = modeID;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   256
#ifdef X11MODES_DEBUG
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   257
            printf("XRandR mode %d: %dx%d@%dHz\n", modeID, mode->w, mode->h, mode->refresh_rate);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   258
#endif
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   259
            return SDL_TRUE;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   260
        }
6537
85cf169db434 Fixed XRandR code to change resolution on the correct monitor in a multi-monitor setup.
Sam Lantinga <slouken@libsdl.org>
parents: 6506
diff changeset
   261
    }
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   262
    return SDL_FALSE;
6537
85cf169db434 Fixed XRandR code to change resolution on the correct monitor in a multi-monitor setup.
Sam Lantinga <slouken@libsdl.org>
parents: 6506
diff changeset
   263
}
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   264
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   265
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   266
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   267
static SDL_bool
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   268
CheckVidMode(Display * display, int *major, int *minor)
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   269
{
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   270
    const char *env;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   271
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   272
    /* Default the extension not available */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   273
    *major = *minor = 0;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   274
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   275
    /* Allow environment override */
6472
d4623b7209db Turned the X11 mode extension environment variables into hints so they can be more easily set from applications.
Sam Lantinga <slouken@libsdl.org>
parents: 6468
diff changeset
   276
    env = SDL_GetHint(SDL_HINT_VIDEO_X11_XVIDMODE);
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   277
    if (env && !SDL_atoi(env)) {
6468
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   278
#ifdef X11MODES_DEBUG
6472
d4623b7209db Turned the X11 mode extension environment variables into hints so they can be more easily set from applications.
Sam Lantinga <slouken@libsdl.org>
parents: 6468
diff changeset
   279
        printf("XVidMode disabled due to hint\n");
6468
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   280
#endif
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   281
        return SDL_FALSE;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   282
    }
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   283
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   284
    if (!SDL_X11_HAVE_XVIDMODE) {
6468
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   285
#ifdef X11MODES_DEBUG
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   286
        printf("XVidMode support not available\n");
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   287
#endif
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   288
        return SDL_FALSE;
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   289
    }
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   290
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   291
    /* Query the extension version */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   292
    vm_error = -1;
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   293
    if (!XF86VidModeQueryExtension(display, &vm_event, &vm_error)
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   294
        || !XF86VidModeQueryVersion(display, major, minor)) {
6468
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   295
#ifdef X11MODES_DEBUG
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   296
        printf("XVidMode not active on the display\n");
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   297
#endif
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   298
        return SDL_FALSE;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   299
    }
6468
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   300
#ifdef X11MODES_DEBUG
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   301
    printf("XVidMode available at version %d.%d!\n", *major, *minor);
6468
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   302
#endif
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   303
    return SDL_TRUE;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   304
}
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   305
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   306
static
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   307
Bool XF86VidModeGetModeInfo(Display * dpy, int scr,
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   308
                                       XF86VidModeModeInfo* info)
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   309
{
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   310
    Bool retval;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   311
    int dotclock;
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   312
    XF86VidModeModeLine l;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   313
    SDL_zerop(info);
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   314
    SDL_zero(l);
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   315
    retval = XF86VidModeGetModeLine(dpy, scr, &dotclock, &l);
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   316
    info->dotclock = dotclock;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   317
    info->hdisplay = l.hdisplay;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   318
    info->hsyncstart = l.hsyncstart;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   319
    info->hsyncend = l.hsyncend;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   320
    info->htotal = l.htotal;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   321
    info->hskew = l.hskew;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   322
    info->vdisplay = l.vdisplay;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   323
    info->vsyncstart = l.vsyncstart;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   324
    info->vsyncend = l.vsyncend;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   325
    info->vtotal = l.vtotal;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   326
    info->flags = l.flags;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   327
    info->privsize = l.privsize;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   328
    info->private = l.private;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   329
    return retval;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   330
}
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   331
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   332
static int
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   333
CalculateXVidModeRefreshRate(const XF86VidModeModeInfo * info)
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   334
{
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   335
    return (info->htotal
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   336
            && info->vtotal) ? (1000 * info->dotclock / (info->htotal *
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   337
                                                         info->vtotal)) : 0;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   338
}
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   339
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   340
SDL_bool
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   341
SetXVidModeModeInfo(const XF86VidModeModeInfo *info, SDL_DisplayMode *mode)
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   342
{
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   343
    mode->w = info->hdisplay;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   344
    mode->h = info->vdisplay;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   345
    mode->refresh_rate = CalculateXVidModeRefreshRate(info);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   346
    ((SDL_DisplayModeData*)mode->driverdata)->vm_mode = *info;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   347
    return SDL_TRUE;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   348
}
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   349
#endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   350
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   351
int
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   352
X11_InitModes(_THIS)
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   353
{
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   354
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   355
    int screen, screencount;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   356
#if SDL_VIDEO_DRIVER_X11_XINERAMA
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   357
    int xinerama_major, xinerama_minor;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   358
    int use_xinerama = 0;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   359
    XineramaScreenInfo *xinerama = NULL;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   360
#endif
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   361
#if SDL_VIDEO_DRIVER_X11_XRANDR
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   362
    int xrandr_major, xrandr_minor;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   363
    int use_xrandr = 0;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   364
    XRRScreenResources *res = NULL;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   365
#endif
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   366
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   367
    int vm_major, vm_minor;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   368
    int use_vidmode = 0;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   369
#endif
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   370
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   371
#if SDL_VIDEO_DRIVER_X11_XINERAMA
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   372
    /* Query Xinerama extention
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   373
     * NOTE: This works with Nvidia Twinview correctly, but you need version 302.17 (released on June 2012)
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   374
     *       or newer of the Nvidia binary drivers
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   375
     */
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   376
    if (CheckXinerama(data->display, &xinerama_major, &xinerama_minor)) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   377
        xinerama = XineramaQueryScreens(data->display, &screencount);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   378
        if (xinerama) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   379
            use_xinerama = xinerama_major * 100 + xinerama_minor;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   380
        }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   381
    }
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   382
    if (!xinerama) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   383
        screencount = ScreenCount(data->display);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   384
    }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   385
#else
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   386
    screencount = ScreenCount(data->display);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   387
#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   388
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   389
#if SDL_VIDEO_DRIVER_X11_XRANDR
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   390
    /* require at least XRandR v1.2 */
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   391
    if (CheckXRandR(data->display, &xrandr_major, &xrandr_minor) &&
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   392
        (xrandr_major >= 2 || (xrandr_major == 1 && xrandr_minor >= 2))) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   393
        use_xrandr = xrandr_major * 100 + xrandr_minor;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   394
    }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   395
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   396
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   397
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   398
    if (CheckVidMode(data->display, &vm_major, &vm_minor)) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   399
        use_vidmode = vm_major * 100 + vm_minor;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   400
    }
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   401
#endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   402
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   403
    for (screen = 0; screen < screencount; ++screen) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   404
        XVisualInfo vinfo;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   405
        SDL_VideoDisplay display;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   406
        SDL_DisplayData *displaydata;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   407
        SDL_DisplayMode mode;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   408
        SDL_DisplayModeData *modedata;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   409
        XPixmapFormatValues *pixmapFormats;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   410
        int i, n;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   411
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   412
#if SDL_VIDEO_DRIVER_X11_XINERAMA
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   413
        if (xinerama) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   414
            if (get_visualinfo(data->display, 0, &vinfo) < 0) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   415
                continue;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   416
            }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   417
        } else {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   418
            if (get_visualinfo(data->display, screen, &vinfo) < 0) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   419
                continue;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   420
            }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   421
        }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   422
#else
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   423
        if (get_visualinfo(data->display, screen, &vinfo) < 0) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   424
            continue;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   425
        }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   426
#endif
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   427
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   428
        displaydata = (SDL_DisplayData *) SDL_calloc(1, sizeof(*displaydata));
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   429
        if (!displaydata) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   430
            continue;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   431
        }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   432
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   433
        mode.format = X11_GetPixelFormatFromVisualInfo(data->display, &vinfo);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   434
        if (SDL_ISPIXELFORMAT_INDEXED(mode.format)) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   435
            /* We don't support palettized modes now */
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   436
            SDL_free(displaydata);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   437
            continue;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   438
        }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   439
#if SDL_VIDEO_DRIVER_X11_XINERAMA
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   440
        if (xinerama) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   441
            mode.w = xinerama[screen].width;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   442
            mode.h = xinerama[screen].height;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   443
        } else {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   444
            mode.w = DisplayWidth(data->display, screen);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   445
            mode.h = DisplayHeight(data->display, screen);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   446
        }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   447
#else
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   448
        mode.w = DisplayWidth(data->display, screen);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   449
        mode.h = DisplayHeight(data->display, screen);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   450
#endif
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   451
        mode.refresh_rate = 0;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   452
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   453
        modedata = (SDL_DisplayModeData *) SDL_calloc(1, sizeof(SDL_DisplayModeData));
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   454
        if (!modedata) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   455
            SDL_free(displaydata);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   456
            continue;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   457
        }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   458
        mode.driverdata = modedata;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   459
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   460
#if SDL_VIDEO_DRIVER_X11_XINERAMA
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   461
        /* Most of SDL's calls to X11 are unwaware of Xinerama, and to X11 standard calls, when Xinerama is active,
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   462
         * there's only one screen available. So we force the screen number to zero and
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   463
         * let Xinerama specific code handle specific functionality using displaydata->xinerama_info
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   464
         */
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   465
        if (use_xinerama) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   466
            displaydata->screen = 0;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   467
            displaydata->use_xinerama = use_xinerama;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   468
            displaydata->xinerama_info = xinerama[screen];
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   469
            displaydata->xinerama_screen = screen;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   470
        }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   471
        else displaydata->screen = screen;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   472
#else
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   473
        displaydata->screen = screen;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   474
#endif
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   475
        displaydata->visual = vinfo.visual;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   476
        displaydata->depth = vinfo.depth;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   477
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   478
        displaydata->scanline_pad = SDL_BYTESPERPIXEL(mode.format) * 8;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   479
        pixmapFormats = XListPixmapFormats(data->display, &n);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   480
        if (pixmapFormats) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   481
            for (i = 0; i < n; ++i) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   482
                if (pixmapFormats[i].depth == displaydata->depth) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   483
                    displaydata->scanline_pad = pixmapFormats[i].scanline_pad;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   484
                    break;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   485
                }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   486
            }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   487
            XFree(pixmapFormats);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   488
        }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   489
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   490
#if SDL_VIDEO_DRIVER_X11_XINERAMA
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   491
        if (use_xinerama) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   492
            displaydata->x = xinerama[screen].x_org;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   493
            displaydata->y = xinerama[screen].y_org;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   494
        }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   495
        else
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   496
#endif
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   497
        {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   498
            displaydata->x = 0;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   499
            displaydata->y = 0;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   500
        }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   501
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   502
#if SDL_VIDEO_DRIVER_X11_XRANDR
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   503
        if (use_xrandr) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   504
            res = XRRGetScreenResources(data->display, RootWindow(data->display, displaydata->screen));
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   505
        }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   506
        if (res) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   507
            XRROutputInfo *output_info;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   508
            XRRCrtcInfo *crtc;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   509
            int output;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   510
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   511
            for (output = 0; output < res->noutput; output++) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   512
                output_info = XRRGetOutputInfo(data->display, res, res->outputs[output]);
6550
191f00a080ba Don't try to query outputs that are not hooked up to a crtc
Sam Lantinga <slouken@libsdl.org>
parents: 6549
diff changeset
   513
                if (!output_info || !output_info->crtc ||
191f00a080ba Don't try to query outputs that are not hooked up to a crtc
Sam Lantinga <slouken@libsdl.org>
parents: 6549
diff changeset
   514
                    output_info->connection == RR_Disconnected) {
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   515
                    XRRFreeOutputInfo(output_info);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   516
                    continue;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   517
                }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   518
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   519
                /* Is this the output that corresponds to the current screen?
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   520
                   We're checking the crtc position, but that may not be a valid test
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   521
                   in all cases.  Anybody want to give this some love?
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   522
                 */
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   523
                crtc = XRRGetCrtcInfo(data->display, res, output_info->crtc);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   524
                if (!crtc || crtc->x != displaydata->x || crtc->y != displaydata->y) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   525
                    XRRFreeOutputInfo(output_info);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   526
                    XRRFreeCrtcInfo(crtc);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   527
                    continue;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   528
                }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   529
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   530
                displaydata->use_xrandr = use_xrandr;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   531
                displaydata->xrandr_output = res->outputs[output];
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   532
                SetXRandRModeInfo(data->display, res, output_info, crtc->mode, &mode);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   533
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   534
                XRRFreeOutputInfo(output_info);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   535
                XRRFreeCrtcInfo(crtc);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   536
                break;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   537
            }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   538
#ifdef X11MODES_DEBUG
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   539
            if (output == res->noutput) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   540
                printf("Couldn't find XRandR CRTC at %d,%d\n", displaydata->x, displaydata->y);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   541
            }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   542
#endif
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   543
            XRRFreeScreenResources(res);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   544
        }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   545
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   546
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   547
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   548
        if (!displaydata->use_xrandr &&
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   549
#if SDL_VIDEO_DRIVER_X11_XINERAMA
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   550
            (!displaydata->use_xinerama || displaydata->xinerama_info.screen_number == 0) &&
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   551
#endif
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   552
            use_vidmode) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   553
            displaydata->use_vidmode = use_vidmode;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   554
            XF86VidModeGetModeInfo(data->display, screen, &modedata->vm_mode);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   555
        }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   556
#endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   557
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   558
        SDL_zero(display);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   559
        display.desktop_mode = mode;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   560
        display.current_mode = mode;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   561
        display.driverdata = displaydata;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   562
        SDL_AddVideoDisplay(&display);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   563
    }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   564
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   565
#if SDL_VIDEO_DRIVER_X11_XINERAMA
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   566
    if (xinerama) XFree(xinerama);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   567
#endif
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   568
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   569
    if (_this->num_displays == 0) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   570
        SDL_SetError("No available displays");
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   571
        return -1;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   572
    }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   573
    return 0;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   574
}
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   575
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   576
void
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 2963
diff changeset
   577
X11_GetDisplayModes(_THIS, SDL_VideoDisplay * sdl_display)
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   578
{
2870
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   579
    Display *display = ((SDL_VideoData *) _this->driverdata)->display;
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 2963
diff changeset
   580
    SDL_DisplayData *data = (SDL_DisplayData *) sdl_display->driverdata;
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   581
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   582
    int nmodes;
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   583
    XF86VidModeModeInfo ** modes;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   584
#endif
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   585
    int screen_w;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   586
    int screen_h;
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   587
    SDL_DisplayMode mode;
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   588
    SDL_DisplayModeData *modedata;
2870
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   589
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   590
    /* Unfortunately X11 requires the window to be created with the correct
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   591
     * visual and depth ahead of time, but the SDL API allows you to create
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   592
     * a window before setting the fullscreen display mode.  This means that
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   593
     * we have to use the same format for all windows and all display modes.
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   594
     * (or support recreating the window with a new visual behind the scenes)
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   595
     */
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 2963
diff changeset
   596
    mode.format = sdl_display->current_mode.format;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   597
    mode.driverdata = NULL;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   598
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   599
    screen_w = DisplayWidth(display, data->screen);
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   600
    screen_h = DisplayHeight(display, data->screen);
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   601
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   602
#if SDL_VIDEO_DRIVER_X11_XINERAMA
6331
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   603
    if (data->use_xinerama) {
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   604
        /* Add the full (both screens combined) xinerama mode only on the display that starts at 0,0 */
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   605
        if (!data->xinerama_info.x_org && !data->xinerama_info.y_org &&
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   606
           (screen_w > data->xinerama_info.width || screen_h > data->xinerama_info.height)) {
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   607
            mode.w = screen_w;
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   608
            mode.h = screen_h;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   609
            mode.refresh_rate = 0;
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   610
            modedata = (SDL_DisplayModeData *) SDL_calloc(1, sizeof(SDL_DisplayModeData));
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   611
            if (modedata) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   612
                *modedata = *(SDL_DisplayModeData *)sdl_display->desktop_mode.driverdata;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   613
            }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   614
            mode.driverdata = modedata;
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 2963
diff changeset
   615
            SDL_AddDisplayMode(sdl_display, &mode);
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   616
        }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   617
    }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   618
#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   619
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   620
#if SDL_VIDEO_DRIVER_X11_XRANDR
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   621
    if (data->use_xrandr) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   622
        XRRScreenResources *res;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   623
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   624
        res = XRRGetScreenResources (display, RootWindow(display, data->screen));
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   625
        if (res) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   626
            SDL_DisplayModeData *modedata;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   627
            XRROutputInfo *output_info;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   628
            int i;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   629
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   630
            output_info = XRRGetOutputInfo(display, res, data->xrandr_output);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   631
            if (output_info && output_info->connection != RR_Disconnected) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   632
                for (i = 0; i < output_info->nmode; ++i) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   633
                    modedata = (SDL_DisplayModeData *) SDL_calloc(1, sizeof(SDL_DisplayModeData));
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   634
                    if (!modedata) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   635
                        continue;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   636
                    }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   637
                    mode.driverdata = modedata;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   638
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   639
                    if (SetXRandRModeInfo(display, res, output_info, output_info->modes[i], &mode)) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   640
                        SDL_AddDisplayMode(sdl_display, &mode);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   641
                    } else {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   642
                        SDL_free(modedata);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   643
                    }
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   644
                }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   645
            }
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   646
            XRRFreeOutputInfo(output_info);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   647
            XRRFreeScreenResources(res);
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   648
        }
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   649
        return;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   650
    }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   651
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   652
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   653
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   654
    if (data->use_vidmode &&
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   655
        XF86VidModeGetAllModeLines(display, data->screen, &nmodes, &modes)) {
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   656
        int i;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   657
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   658
#ifdef X11MODES_DEBUG
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   659
        printf("VidMode modes: (unsorted)\n");
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   660
        for (i = 0; i < nmodes; ++i) {
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   661
            printf("Mode %d: %d x %d @ %d\n", i,
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   662
                   modes[i]->hdisplay, modes[i]->vdisplay,
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   663
                   CalculateXVidModeRefreshRate(modes[i]));
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   664
        }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   665
#endif
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   666
        for (i = 0; i < nmodes; ++i) {
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   667
            modedata = (SDL_DisplayModeData *) SDL_calloc(1, sizeof(SDL_DisplayModeData));
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   668
            if (!modedata) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   669
                continue;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   670
            }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   671
            mode.driverdata = modedata;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   672
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   673
            if (SetXVidModeModeInfo(modes[i], &mode)) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   674
                SDL_AddDisplayMode(sdl_display, &mode);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   675
            } else {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   676
                SDL_free(modedata);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   677
            }
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   678
        }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   679
        XFree(modes);
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   680
        return;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   681
    }
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   682
#endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   683
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   684
    if (!data->use_xrandr && !data->use_vidmode) {
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   685
        /* Add the desktop mode */
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   686
        mode = sdl_display->desktop_mode;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   687
        modedata = (SDL_DisplayModeData *) SDL_calloc(1, sizeof(SDL_DisplayModeData));
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   688
        if (modedata) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   689
            *modedata = *(SDL_DisplayModeData *)sdl_display->desktop_mode.driverdata;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   690
        }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   691
        mode.driverdata = modedata;
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 2963
diff changeset
   692
        SDL_AddDisplayMode(sdl_display, &mode);
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   693
    }
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   694
}
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   695
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   696
int
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 2963
diff changeset
   697
X11_SetDisplayMode(_THIS, SDL_VideoDisplay * sdl_display, SDL_DisplayMode * mode)
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   698
{
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   699
    Display *display = ((SDL_VideoData *) _this->driverdata)->display;
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 2963
diff changeset
   700
    SDL_DisplayData *data = (SDL_DisplayData *) sdl_display->driverdata;
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   701
    SDL_DisplayModeData *modedata = (SDL_DisplayModeData *)mode->driverdata;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   702
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   703
#if SDL_VIDEO_DRIVER_X11_XRANDR
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   704
    if (data->use_xrandr) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   705
        XRRScreenResources *res;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   706
        XRROutputInfo *output_info;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   707
        XRRCrtcInfo *crtc;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   708
        Status status;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   709
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   710
        res = XRRGetScreenResources (display, RootWindow(display, data->screen));
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   711
        if (!res) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   712
            SDL_SetError("Couldn't get XRandR screen resources");
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   713
            return -1;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   714
        }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   715
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   716
        output_info = XRRGetOutputInfo(display, res, data->xrandr_output);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   717
        if (!output_info || output_info->connection == RR_Disconnected) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   718
            SDL_SetError("Couldn't get XRandR output info");
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   719
            XRRFreeScreenResources(res);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   720
            return -1;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   721
        }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   722
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   723
        crtc = XRRGetCrtcInfo(display, res, output_info->crtc);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   724
        if (!crtc) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   725
            SDL_SetError("Couldn't get XRandR crtc info");
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   726
            XRRFreeOutputInfo(output_info);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   727
            XRRFreeScreenResources(res);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   728
            return -1;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   729
        }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   730
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   731
        status = XRRSetCrtcConfig (display, res, output_info->crtc, CurrentTime,
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   732
          crtc->x, crtc->y, modedata->xrandr_mode, crtc->rotation,
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   733
          &data->xrandr_output, 1);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   734
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   735
        XRRFreeCrtcInfo(crtc);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   736
        XRRFreeOutputInfo(output_info);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   737
        XRRFreeScreenResources(res);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   738
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   739
        if (status != Success) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   740
            SDL_SetError("XRRSetCrtcConfig failed");
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   741
            return -1;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   742
        }
6549
db16b819e1d1 Added a delay hack to let the window manager adjust to the mode change. I'm not sure if this is a good idea, but at least it works sometimes now. :)
Sam Lantinga <slouken@libsdl.org>
parents: 6548
diff changeset
   743
db16b819e1d1 Added a delay hack to let the window manager adjust to the mode change. I'm not sure if this is a good idea, but at least it works sometimes now. :)
Sam Lantinga <slouken@libsdl.org>
parents: 6548
diff changeset
   744
        /* Hack to let the window manager adjust to the mode change */
db16b819e1d1 Added a delay hack to let the window manager adjust to the mode change. I'm not sure if this is a good idea, but at least it works sometimes now. :)
Sam Lantinga <slouken@libsdl.org>
parents: 6548
diff changeset
   745
        const int WINDOW_MANAGER_DELAY_HACK = 250;
db16b819e1d1 Added a delay hack to let the window manager adjust to the mode change. I'm not sure if this is a good idea, but at least it works sometimes now. :)
Sam Lantinga <slouken@libsdl.org>
parents: 6548
diff changeset
   746
        SDL_Delay(WINDOW_MANAGER_DELAY_HACK);
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   747
    }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   748
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   749
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   750
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   751
    if (data->use_vidmode) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   752
        XF86VidModeSwitchToMode(display, data->screen, &modedata->vm_mode);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   753
    }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   754
#endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   755
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   756
    return 0;
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   757
}
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   758
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   759
void
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   760
X11_QuitModes(_THIS)
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   761
{
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   762
}
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   763
6331
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   764
int
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   765
X11_GetDisplayBounds(_THIS, SDL_VideoDisplay * sdl_display, SDL_Rect * rect)
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   766
{
6502
f41a82de351e Fixed detection of display bounds after a mode switch when Xinerama is enabled.
Sam Lantinga <slouken@libsdl.org>
parents: 6482
diff changeset
   767
    Display *display = ((SDL_VideoData *) _this->driverdata)->display;
6331
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   768
    SDL_DisplayData *data = (SDL_DisplayData *) sdl_display->driverdata;
6502
f41a82de351e Fixed detection of display bounds after a mode switch when Xinerama is enabled.
Sam Lantinga <slouken@libsdl.org>
parents: 6482
diff changeset
   769
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   770
    rect->x = data->x;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   771
    rect->y = data->y;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   772
    rect->w = sdl_display->current_mode.w;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   773
    rect->h = sdl_display->current_mode.h;
6331
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   774
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   775
#if SDL_VIDEO_DRIVER_X11_XINERAMA
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   776
    /* Get the real current bounds of the display */
6502
f41a82de351e Fixed detection of display bounds after a mode switch when Xinerama is enabled.
Sam Lantinga <slouken@libsdl.org>
parents: 6482
diff changeset
   777
    if (data->use_xinerama) {
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   778
        int screencount;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   779
        XineramaScreenInfo *xinerama = XineramaQueryScreens(display, &screencount);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   780
        if (xinerama) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   781
            rect->x = xinerama[data->xinerama_screen].x_org;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   782
            rect->y = xinerama[data->xinerama_screen].y_org;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   783
        }
6331
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   784
    }
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   785
#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
6475
71d39944810b Fixed fullscreen origin for multi-head displays
Sam Lantinga <slouken@libsdl.org>
parents: 6472
diff changeset
   786
    return 0;
6331
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   787
}
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   788
5481
22dfc3958dc3 Fixed so code will compile with SDL_config_minimal.h
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
   789
#endif /* SDL_VIDEO_DRIVER_X11 */
22dfc3958dc3 Fixed so code will compile with SDL_config_minimal.h
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
   790
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   791
/* vi: set ts=4 sw=4 expandtab: */