src/video/x11/SDL_x11modes.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 27 Sep 2012 10:41:16 -0700
changeset 6468 6af2a8db95d0
parent 6331 5732e1a80bde
child 6472 d4623b7209db
permissions -rwxr-xr-x
Fixed bug where Xinerama was treated as being available even if it wasn't. Also added additional logging for X11 video modes
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
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
#include "SDL_x11video.h"
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
4519
62d693e01a24 Turned off debug spew
Sam Lantinga <slouken@libsdl.org>
parents: 4518
diff changeset
    27
/*#define X11MODES_DEBUG*/
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
static int
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    30
get_visualinfo(Display * display, int screen, XVisualInfo * vinfo)
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
{
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
    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
    33
    int depth;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    35
    /* Look for an exact visual, if requested */
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    36
    if (visual_id) {
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
        XVisualInfo *vi, template;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    38
        int nvis;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    39
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    40
        SDL_zero(template);
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    41
        template.visualid = SDL_strtol(visual_id, NULL, 0);
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    42
        vi = XGetVisualInfo(display, VisualIDMask, &template, &nvis);
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    43
        if (vi) {
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    44
            *vinfo = *vi;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    45
            XFree(vi);
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    46
            return 0;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    47
        }
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
    depth = DefaultDepth(display, screen);
5466
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5408
diff changeset
    51
    if ((X11_UseDirectColorVisuals() &&
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5408
diff changeset
    52
         XMatchVisualInfo(display, screen, depth, DirectColor, vinfo)) ||
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5408
diff changeset
    53
        XMatchVisualInfo(display, screen, depth, TrueColor, vinfo) ||
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    54
        XMatchVisualInfo(display, screen, depth, PseudoColor, vinfo) ||
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    55
        XMatchVisualInfo(display, screen, depth, StaticColor, vinfo)) {
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    56
        return 0;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    57
    }
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    58
    return -1;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    59
}
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    60
5182
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    61
int
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    62
X11_GetVisualInfoFromVisual(Display * display, Visual * visual, XVisualInfo * vinfo)
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    63
{
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    64
    XVisualInfo *vi;
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    65
    int nvis;
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    66
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    67
    vinfo->visualid = XVisualIDFromVisual(visual);
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    68
    vi = XGetVisualInfo(display, VisualIDMask, vinfo, &nvis);
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    69
    if (vi) {
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    70
        *vinfo = *vi;
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    71
        XFree(vi);
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    72
        return 0;
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    73
    }
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    74
    return -1;
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    75
}
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
Uint32
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
    78
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
    79
{
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
    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
    81
        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
    82
        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
    83
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
        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
    85
        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
    86
        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
    87
        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
    88
            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
    89
        } 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
    90
            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
    91
        }
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
        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
    94
        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
    95
            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
    96
            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
    97
            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
    98
                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
    99
                    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
   100
                        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
   101
                        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
   102
                    }
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
                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
   105
            }
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
        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
   109
    }
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
    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
   112
        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
   113
        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
   114
            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
   115
        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
   116
            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
   117
                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
   118
            } 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
   119
                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
   120
            }
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
            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
   122
        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
   123
            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
   124
                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
   125
            } 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
   126
                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
   127
            }
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
            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
   129
        }
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
    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
   133
}
6331
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   134
#if SDL_VIDEO_DRIVER_X11_XINERAMA
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   135
static SDL_bool CheckXinerama(Display * display, int *major, int *minor);
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   136
#endif
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
   137
3521
76f9b76ddf0f Don't add any renderers if you can't add any displays
Sam Lantinga <slouken@libsdl.org>
parents: 3500
diff changeset
   138
int
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   139
X11_InitModes(_THIS)
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   140
{
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   141
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
6331
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   142
    int screen, screencount;
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   143
6331
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   144
#if SDL_VIDEO_DRIVER_X11_XINERAMA
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   145
    int xinerama_major, xinerama_minor;
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   146
    XineramaScreenInfo * xinerama = NULL;
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   147
    /* Query Xinerama extention
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   148
     * NOTE: This works with Nvidia Twinview correctly, but you need version 302.17 (released on June 2012)
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   149
     *       or newer of the Nvidia binary drivers
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   150
     */
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   151
    if (CheckXinerama(data->display, &xinerama_major, &xinerama_minor)) {
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   152
        xinerama = XineramaQueryScreens(data->display, &screencount);
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   153
        if (!xinerama) screencount = ScreenCount(data->display);
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   154
    }
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   155
    else {
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   156
        screencount = ScreenCount(data->display);
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   157
    }
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   158
#else
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   159
    screencount = ScreenCount(data->display);
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   160
#endif
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   161
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   162
    for (screen = 0; screen < screencount; ++screen) {
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   163
        XVisualInfo vinfo;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   164
        SDL_VideoDisplay display;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   165
        SDL_DisplayData *displaydata;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   166
        SDL_DisplayMode mode;
2916
ffdd533f7add Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents: 2906
diff changeset
   167
        XPixmapFormatValues *pixmapFormats;
ffdd533f7add Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents: 2906
diff changeset
   168
        int i, n;
6331
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   169
#if SDL_VIDEO_DRIVER_X11_XINERAMA
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   170
        if (xinerama) {
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   171
            if (get_visualinfo(data->display, 0, &vinfo) < 0) {
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   172
                continue;
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   173
            }
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   174
        }
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   175
        else {
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   176
            if (get_visualinfo(data->display, screen, &vinfo) < 0) {
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   177
                continue;
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   178
            }
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   179
        }
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   180
#else
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   181
        if (get_visualinfo(data->display, screen, &vinfo) < 0) {
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   182
            continue;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   183
        }
6331
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   184
#endif
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   185
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
   186
        mode.format = X11_GetPixelFormatFromVisualInfo(data->display, &vinfo);
5149
be02be2ea897 Making the API simpler, removed support for palettized video modes and textures.
Sam Lantinga <slouken@libsdl.org>
parents: 4618
diff changeset
   187
        if (SDL_ISPIXELFORMAT_INDEXED(mode.format)) {
be02be2ea897 Making the API simpler, removed support for palettized video modes and textures.
Sam Lantinga <slouken@libsdl.org>
parents: 4618
diff changeset
   188
            /* We don't support palettized modes now */
be02be2ea897 Making the API simpler, removed support for palettized video modes and textures.
Sam Lantinga <slouken@libsdl.org>
parents: 4618
diff changeset
   189
            continue;
be02be2ea897 Making the API simpler, removed support for palettized video modes and textures.
Sam Lantinga <slouken@libsdl.org>
parents: 4618
diff changeset
   190
        }
6331
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   191
#if SDL_VIDEO_DRIVER_X11_XINERAMA
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   192
        if (xinerama) {
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   193
            mode.w = xinerama[screen].width;
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   194
            mode.h = xinerama[screen].height;
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   195
        }
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   196
        else {
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   197
            mode.w = DisplayWidth(data->display, screen);
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   198
            mode.h = DisplayHeight(data->display, screen);
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   199
        }
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   200
#else
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   201
        mode.w = DisplayWidth(data->display, screen);
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   202
        mode.h = DisplayHeight(data->display, screen);
6331
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   203
#endif
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   204
        mode.refresh_rate = 0;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   205
        mode.driverdata = NULL;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   206
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
   207
        displaydata = (SDL_DisplayData *) SDL_calloc(1, sizeof(*displaydata));
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   208
        if (!displaydata) {
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   209
            continue;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   210
        }
6331
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   211
#if SDL_VIDEO_DRIVER_X11_XINERAMA
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   212
        /* Most of SDL's calls to X11 are unwaware of Xinerama, and to X11 standard calls, when Xinerama is active,
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   213
         * there's only one screen available. So we force the screen number to zero and
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   214
         * let Xinerama specific code handle specific functionality using displaydata->xinerama_info
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   215
         */
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   216
        if (xinerama) {
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   217
            displaydata->screen = 0;
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   218
            displaydata->use_xinerama = xinerama_major * 100 + xinerama_minor;
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   219
            displaydata->xinerama_info = xinerama[screen];
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   220
        }
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   221
        else displaydata->screen = screen;
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   222
#else
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   223
        displaydata->screen = screen;
6331
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   224
#endif
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   225
        displaydata->visual = vinfo.visual;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents: 1950
diff changeset
   226
        displaydata->depth = vinfo.depth;
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   227
2920
Sam Lantinga <slouken@libsdl.org>
parents: 2916
diff changeset
   228
        displaydata->scanline_pad = SDL_BYTESPERPIXEL(mode.format) * 8;
2916
ffdd533f7add Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents: 2906
diff changeset
   229
        pixmapFormats = XListPixmapFormats(data->display, &n);
ffdd533f7add Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents: 2906
diff changeset
   230
        if (pixmapFormats) {
ffdd533f7add Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents: 2906
diff changeset
   231
            for (i = 0; i < n; ++i) {
ffdd533f7add Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents: 2906
diff changeset
   232
                if (pixmapFormats[i].depth == displaydata->depth) {
ffdd533f7add Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents: 2906
diff changeset
   233
                    displaydata->scanline_pad = pixmapFormats[i].scanline_pad;
ffdd533f7add Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents: 2906
diff changeset
   234
                    break;
ffdd533f7add Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents: 2906
diff changeset
   235
                }
ffdd533f7add Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents: 2906
diff changeset
   236
            }
ffdd533f7add Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents: 2906
diff changeset
   237
            XFree(pixmapFormats);
ffdd533f7add Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents: 2906
diff changeset
   238
        }
ffdd533f7add Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents: 2906
diff changeset
   239
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   240
        SDL_zero(display);
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   241
        display.desktop_mode = mode;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   242
        display.current_mode = mode;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   243
        display.driverdata = displaydata;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   244
        SDL_AddVideoDisplay(&display);
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   245
    }
6331
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   246
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   247
#if SDL_VIDEO_DRIVER_X11_XINERAMA
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   248
    if (xinerama) XFree(xinerama);
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   249
#endif
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   250
3521
76f9b76ddf0f Don't add any renderers if you can't add any displays
Sam Lantinga <slouken@libsdl.org>
parents: 3500
diff changeset
   251
    if (_this->num_displays == 0) {
76f9b76ddf0f Don't add any renderers if you can't add any displays
Sam Lantinga <slouken@libsdl.org>
parents: 3500
diff changeset
   252
        SDL_SetError("No available displays");
76f9b76ddf0f Don't add any renderers if you can't add any displays
Sam Lantinga <slouken@libsdl.org>
parents: 3500
diff changeset
   253
        return -1;
76f9b76ddf0f Don't add any renderers if you can't add any displays
Sam Lantinga <slouken@libsdl.org>
parents: 3500
diff changeset
   254
    }
76f9b76ddf0f Don't add any renderers if you can't add any displays
Sam Lantinga <slouken@libsdl.org>
parents: 3500
diff changeset
   255
    return 0;
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   256
}
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   257
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   258
/* Global for the error handler */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   259
int vm_event, vm_error = -1;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   260
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   261
#if SDL_VIDEO_DRIVER_X11_XINERAMA
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   262
static SDL_bool
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   263
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
   264
{
6027
56185b574d61 Use correct Xinerama APIs for querying version and availability.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   265
    int event_base = 0;
56185b574d61 Use correct Xinerama APIs for querying version and availability.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   266
    int error_base = 0;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   267
    const char *env;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   268
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   269
    /* Default the extension not available */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   270
    *major = *minor = 0;
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
    /* Allow environment override */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   273
    env = getenv("SDL_VIDEO_X11_XINERAMA");
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   274
    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
   275
#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
   276
        printf("Xinerama disabled due to environment variable\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
   277
#endif
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   278
        return SDL_FALSE;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   279
    }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   280
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   281
    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
   282
#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
   283
        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
   284
#endif
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   285
        return SDL_FALSE;
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   286
    }
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   287
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   288
    /* 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
   289
    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
   290
        !XineramaQueryVersion(display, major, minor) ||
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   291
        !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
   292
#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
   293
        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
   294
#endif
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   295
        return SDL_FALSE;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   296
    }
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
   297
#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
   298
    printf("Xinerama 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
   299
#endif
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   300
    return SDL_TRUE;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   301
}
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   302
#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   303
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   304
#if SDL_VIDEO_DRIVER_X11_XRANDR
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   305
static SDL_bool
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   306
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
   307
{
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   308
    const char *env;
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
    /* Default the extension not available */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   311
    *major = *minor = 0;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   312
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   313
    /* Allow environment override */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   314
    env = getenv("SDL_VIDEO_X11_XRANDR");
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   315
    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
   316
#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
   317
        printf("XRandR disabled due to environment variable\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
   318
#endif
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   319
        return SDL_FALSE;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   320
    }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   321
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   322
    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
   323
#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
   324
        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
   325
#endif
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   326
        return SDL_FALSE;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   327
    }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   328
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   329
    /* Query the extension version */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   330
    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
   331
#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
   332
        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
   333
#endif
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   334
        return SDL_FALSE;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   335
    }
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
   336
#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
   337
    printf("XRandR 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
   338
#endif
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   339
    return SDL_TRUE;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   340
}
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   341
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   342
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   343
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   344
static SDL_bool
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   345
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
   346
{
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   347
    const char *env;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   348
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   349
    /* Default the extension not available */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   350
    *major = *minor = 0;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   351
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   352
    /* Allow environment override */
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   353
    env = getenv("SDL_VIDEO_X11_XVIDMODE");
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   354
    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
   355
#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
   356
        printf("XVidMode disabled due to environment variable\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
   357
#endif
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   358
        return SDL_FALSE;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   359
    }
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   360
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   361
    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
   362
#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
   363
        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
   364
#endif
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   365
        return SDL_FALSE;
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   366
    }
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   367
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   368
    /* Query the extension version */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   369
    vm_error = -1;
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   370
    if (!XF86VidModeQueryExtension(display, &vm_event, &vm_error)
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   371
        || !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
   372
#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
   373
        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
   374
#endif
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   375
        return SDL_FALSE;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   376
    }
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
   377
#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
   378
    printf("XVidMode 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
   379
#endif
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   380
    return SDL_TRUE;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   381
}
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   382
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
   383
static
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   384
Bool XF86VidModeGetModeInfo(Display * dpy, int scr,
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   385
                                       XF86VidModeModeInfo* info)
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   386
{
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   387
    Bool retval;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   388
    int dotclock;
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   389
    XF86VidModeModeLine l;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   390
    SDL_zerop(info);
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   391
    SDL_zero(l);
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   392
    retval = XF86VidModeGetModeLine(dpy, scr, &dotclock, &l);
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   393
    info->dotclock = dotclock;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   394
    info->hdisplay = l.hdisplay;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   395
    info->hsyncstart = l.hsyncstart;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   396
    info->hsyncend = l.hsyncend;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   397
    info->htotal = l.htotal;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   398
    info->hskew = l.hskew;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   399
    info->vdisplay = l.vdisplay;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   400
    info->vsyncstart = l.vsyncstart;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   401
    info->vsyncend = l.vsyncend;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   402
    info->vtotal = l.vtotal;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   403
    info->flags = l.flags;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   404
    info->privsize = l.privsize;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   405
    info->private = l.private;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   406
    return retval;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   407
}
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   408
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   409
static int
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   410
calculate_rate(XF86VidModeModeInfo * info)
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   411
{
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   412
    return (info->htotal
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   413
            && info->vtotal) ? (1000 * info->dotclock / (info->htotal *
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   414
                                                         info->vtotal)) : 0;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   415
}
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   416
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   417
static void
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   418
save_mode(Display * display, SDL_DisplayData * data)
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   419
{
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   420
    XF86VidModeGetModeInfo(display, data->screen,
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   421
                                    &data->saved_mode);
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   422
    XF86VidModeGetViewPort(display, data->screen,
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   423
                                    &data->saved_view.x,
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   424
                                    &data->saved_view.y);
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   425
}
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   426
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
   427
/*
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   428
static void
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   429
restore_mode(Display * display, SDL_DisplayData * data)
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   430
{
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   431
    XF86VidModeModeInfo mode;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   432
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   433
    if (XF86VidModeGetModeInfo(display, data->screen, &mode)) {
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   434
        if (SDL_memcmp(&mode, &data->saved_mode, sizeof(mode)) != 0) {
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   435
            XF86VidModeSwitchToMode(display, data->screen, &data->saved_mode);
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   436
        }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   437
    }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   438
    if ((data->saved_view.x != 0) || (data->saved_view.y != 0)) {
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   439
        XF86VidModeSetViewPort(display, data->screen,
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   440
                                        data->saved_view.x,
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   441
                                        data->saved_view.y);
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   442
    }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   443
}
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
   444
*/
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   445
#endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   446
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   447
void
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 2963
diff changeset
   448
X11_GetDisplayModes(_THIS, SDL_VideoDisplay * sdl_display)
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   449
{
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
   450
    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
   451
    SDL_DisplayData *data = (SDL_DisplayData *) sdl_display->driverdata;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   452
#if SDL_VIDEO_DRIVER_X11_XRANDR
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   453
    int xrandr_major, xrandr_minor;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   454
    int nsizes, nrates;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   455
    XRRScreenSize *sizes;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   456
    short *rates;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   457
#endif
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   458
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   459
    int vm_major, vm_minor;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   460
    int nmodes;
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   461
    XF86VidModeModeInfo ** modes;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   462
#endif
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   463
    int screen_w;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   464
    int screen_h;
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   465
    SDL_DisplayMode mode;
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
   466
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   467
    /* 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
   468
     * 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
   469
     * 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
   470
     * 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
   471
     * (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
   472
     */
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 2963
diff changeset
   473
    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
   474
    mode.driverdata = NULL;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   475
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   476
    screen_w = DisplayWidth(display, data->screen);
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   477
    screen_h = DisplayHeight(display, data->screen);
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   478
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   479
#if SDL_VIDEO_DRIVER_X11_XINERAMA
6331
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   480
    if (data->use_xinerama) {
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   481
        /* 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
   482
        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
   483
           (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
   484
            mode.w = screen_w;
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   485
            mode.h = screen_h;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   486
            mode.refresh_rate = 0;
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 2963
diff changeset
   487
            SDL_AddDisplayMode(sdl_display, &mode);
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   488
        }
6331
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   489
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   490
        /* Add the head xinerama mode */
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   491
        mode.w = data->xinerama_info.width;
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   492
        mode.h = data->xinerama_info.height;
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   493
        mode.refresh_rate = 0;
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   494
        SDL_AddDisplayMode(sdl_display, &mode);
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   495
    }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   496
#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   497
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   498
#if SDL_VIDEO_DRIVER_X11_XRANDR
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   499
    /* XRandR */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   500
    /* require at least XRandR v1.0 (arbitrary) */
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   501
    if (CheckXRandR(display, &xrandr_major, &xrandr_minor)
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   502
        && xrandr_major >= 1) {
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   503
#ifdef X11MODES_DEBUG
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   504
        fprintf(stderr, "XRANDR: XRRQueryVersion: V%d.%d\n",
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   505
                xrandr_major, xrandr_minor);
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   506
#endif
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   507
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   508
        /* save the screen configuration since we must reference it
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   509
           each time we toggle modes.
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   510
         */
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   511
        data->screen_config =
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   512
            XRRGetScreenInfo(display, RootWindow(display, data->screen));
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   513
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   514
        /* retrieve the list of resolution */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   515
        sizes = XRRConfigSizes(data->screen_config, &nsizes);
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   516
        if (nsizes > 0) {
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   517
            int i, j;
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   518
            for (i = 0; i < nsizes; i++) {
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   519
                mode.w = sizes[i].width;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   520
                mode.h = sizes[i].height;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   521
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   522
                rates = XRRConfigRates(data->screen_config, i, &nrates);
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   523
                for (j = 0; j < nrates; ++j) {
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   524
                    mode.refresh_rate = rates[j];
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   525
#ifdef X11MODES_DEBUG
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   526
                    fprintf(stderr,
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   527
                            "XRANDR: mode = %4d[%d], w = %4d, h = %4d, rate = %4d\n",
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   528
                            i, j, mode.w, mode.h, mode.refresh_rate);
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   529
#endif
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 2963
diff changeset
   530
                    SDL_AddDisplayMode(sdl_display, &mode);
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   531
                }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   532
            }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   533
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   534
            data->use_xrandr = xrandr_major * 100 + xrandr_minor;
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   535
            data->saved_size =
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   536
                XRRConfigCurrentConfiguration(data->screen_config,
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   537
                                              &data->saved_rotation);
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   538
            data->saved_rate = XRRConfigCurrentRate(data->screen_config);
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   539
        }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   540
    }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   541
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   542
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   543
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   544
    /* XVidMode */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   545
    if (!data->use_xrandr &&
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   546
#if SDL_VIDEO_DRIVER_X11_XINERAMA
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   547
        (!data->use_xinerama || data->xinerama_info.screen_number == 0) &&
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   548
#endif
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   549
        CheckVidMode(display, &vm_major, &vm_minor) &&
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   550
        XF86VidModeGetAllModeLines(display, data->screen, &nmodes, &modes)) {
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   551
        int i;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   552
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   553
#ifdef X11MODES_DEBUG
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   554
        printf("VidMode modes: (unsorted)\n");
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   555
        for (i = 0; i < nmodes; ++i) {
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   556
            printf("Mode %d: %d x %d @ %d\n", i,
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   557
                   modes[i]->hdisplay, modes[i]->vdisplay,
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   558
                   calculate_rate(modes[i]));
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   559
        }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   560
#endif
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   561
        for (i = 0; i < nmodes; ++i) {
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   562
            mode.w = modes[i]->hdisplay;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   563
            mode.h = modes[i]->vdisplay;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   564
            mode.refresh_rate = calculate_rate(modes[i]);
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 2963
diff changeset
   565
            SDL_AddDisplayMode(sdl_display, &mode);
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   566
        }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   567
        XFree(modes);
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   568
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   569
        data->use_vidmode = vm_major * 100 + vm_minor;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   570
        save_mode(display, data);
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   571
    }
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   572
#endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   573
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   574
    if (!data->use_xrandr && !data->use_vidmode) {
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   575
        mode.w = screen_w;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   576
        mode.h = screen_h;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   577
        mode.refresh_rate = 0;
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 2963
diff changeset
   578
        SDL_AddDisplayMode(sdl_display, &mode);
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   579
    }
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   580
#ifdef X11MODES_DEBUG
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   581
    if (data->use_xinerama) {
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   582
        printf("Xinerama is enabled\n");
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   583
    }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   584
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   585
    if (data->use_xrandr) {
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   586
        printf("XRandR is enabled\n");
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   587
    }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   588
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   589
    if (data->use_vidmode) {
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   590
        printf("VidMode is enabled\n");
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   591
    }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   592
#endif /* X11MODES_DEBUG */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   593
}
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   594
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   595
static void
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   596
get_real_resolution(Display * display, SDL_DisplayData * data, int *w, int *h,
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   597
                    int *rate)
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   598
{
6331
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   599
#if SDL_VIDEO_DRIVER_X11_XINERAMA
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   600
    if (data->use_xinerama) {
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   601
        *w = data->xinerama_info.width;
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   602
        *h = data->xinerama_info.height;
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   603
        *rate = 0;
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   604
        return;
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   605
    }
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   606
#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   607
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   608
#if SDL_VIDEO_DRIVER_X11_XRANDR
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   609
    if (data->use_xrandr) {
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   610
        int nsizes;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   611
        XRRScreenSize *sizes;
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   612
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   613
        sizes = XRRConfigSizes(data->screen_config, &nsizes);
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   614
        if (nsizes > 0) {
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   615
            int cur_size;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   616
            Rotation cur_rotation;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   617
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   618
            cur_size =
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   619
                XRRConfigCurrentConfiguration(data->screen_config,
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   620
                                              &cur_rotation);
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   621
            *w = sizes[cur_size].width;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   622
            *h = sizes[cur_size].height;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   623
            *rate = XRRConfigCurrentRate(data->screen_config);
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   624
#ifdef X11MODES_DEBUG
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   625
            fprintf(stderr,
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   626
                    "XRANDR: get_real_resolution: w = %d, h = %d, rate = %d\n",
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   627
                    *w, *h, *rate);
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   628
#endif
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   629
            return;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   630
        }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   631
    }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   632
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   633
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   634
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   635
    if (data->use_vidmode) {
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   636
        XF86VidModeModeInfo mode;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   637
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   638
        if (XF86VidModeGetModeInfo(display, data->screen, &mode)) {
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   639
            *w = mode.hdisplay;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   640
            *h = mode.vdisplay;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   641
            *rate = calculate_rate(&mode);
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   642
            return;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   643
        }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   644
    }
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   645
#endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   646
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   647
    *w = DisplayWidth(display, data->screen);
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   648
    *h = DisplayHeight(display, data->screen);
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   649
    *rate = 0;
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
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   652
static void
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   653
set_best_resolution(Display * display, SDL_DisplayData * data, int w, int h,
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   654
                    int rate)
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   655
{
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   656
    int real_w, real_h, real_rate;
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
    /* check current mode so we can avoid uneccessary mode changes */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   659
    get_real_resolution(display, data, &real_w, &real_h, &real_rate);
6331
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   660
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   661
#if SDL_VIDEO_DRIVER_X11_XINERAMA
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   662
    if (w == real_w && h == real_h && (data->use_xinerama || !rate || rate == real_rate)) {
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   663
        return;
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   664
    }
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   665
#else
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   666
    if (w == real_w && h == real_h && (!rate || rate == real_rate)) {
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   667
        return;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   668
    }
6331
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   669
#endif
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   670
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   671
#if SDL_VIDEO_DRIVER_X11_XRANDR
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   672
    if (data->use_xrandr) {
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   673
#ifdef X11MODES_DEBUG
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   674
        fprintf(stderr, "XRANDR: set_best_resolution(): w = %d, h = %d\n",
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   675
                w, h);
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   676
#endif
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   677
        int i, nsizes, nrates;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   678
        int best;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   679
        int best_rate;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   680
        XRRScreenSize *sizes;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   681
        short *rates;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   682
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   683
        /* find the smallest resolution that is at least as big as the user requested */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   684
        best = -1;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   685
        sizes = XRRConfigSizes(data->screen_config, &nsizes);
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   686
        for (i = 0; i < nsizes; ++i) {
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   687
            if (sizes[i].width < w || sizes[i].height < h) {
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   688
                continue;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   689
            }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   690
            if (sizes[i].width == w && sizes[i].height == h) {
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   691
                best = i;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   692
                break;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   693
            }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   694
            if (best == -1 ||
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   695
                (sizes[i].width < sizes[best].width) ||
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   696
                (sizes[i].width == sizes[best].width
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   697
                 && sizes[i].height < sizes[best].height)) {
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   698
                best = i;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   699
            }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   700
        }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   701
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   702
        if (best >= 0) {
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   703
            best_rate = 0;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   704
            rates = XRRConfigRates(data->screen_config, best, &nrates);
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   705
            for (i = 0; i < nrates; ++i) {
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   706
                if (rates[i] == rate) {
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   707
                    best_rate = rate;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   708
                    break;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   709
                }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   710
                if (!rate) {
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   711
                    /* Higher is better, right? */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   712
                    if (rates[i] > best_rate) {
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   713
                        best_rate = rates[i];
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   714
                    }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   715
                } else {
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   716
                    if (SDL_abs(rates[i] - rate) < SDL_abs(best_rate - rate)) {
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   717
                        best_rate = rates[i];
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   718
                    }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   719
                }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   720
            }
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   721
            XRRSetScreenConfigAndRate(display, data->screen_config,
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   722
                                      RootWindow(display, data->screen), best,
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   723
                                      data->saved_rotation, best_rate,
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   724
                                      CurrentTime);
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   725
        }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   726
        return;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   727
    }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   728
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   729
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   730
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   731
    if (data->use_vidmode) {
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   732
        XF86VidModeModeInfo ** modes;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   733
        int i, nmodes;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   734
        int best;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   735
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   736
        if (XF86VidModeGetAllModeLines(display, data->screen, &nmodes, &modes)) {
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   737
            best = -1;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   738
            for (i = 0; i < nmodes; ++i) {
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   739
                if (modes[i]->hdisplay < w || modes[i]->vdisplay < h) {
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   740
                    continue;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   741
                }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   742
                if (best == -1 ||
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   743
                    (modes[i]->hdisplay < modes[best]->hdisplay) ||
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   744
                    (modes[i]->hdisplay == modes[best]->hdisplay
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   745
                     && modes[i]->vdisplay < modes[best]->vdisplay)) {
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   746
                    best = i;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   747
                    continue;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   748
                }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   749
                if ((modes[i]->hdisplay == modes[best]->hdisplay) &&
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   750
                    (modes[i]->vdisplay == modes[best]->vdisplay)) {
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   751
                    if (!rate) {
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   752
                        /* Higher is better, right? */
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   753
                        if (calculate_rate(modes[i]) >
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   754
                            calculate_rate(modes[best])) {
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   755
                            best = i;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   756
                        }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   757
                    } else {
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   758
                        if (SDL_abs(calculate_rate(modes[i]) - rate) <
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   759
                            SDL_abs(calculate_rate(modes[best]) - rate)) {
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   760
                            best = i;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   761
                        }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   762
                    }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   763
                }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   764
            }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   765
            if (best >= 0) {
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   766
#ifdef X11MODES_DEBUG
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   767
                printf("Best Mode %d: %d x %d @ %d\n", best,
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   768
                       modes[best]->hdisplay, modes[best]->vdisplay,
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   769
                       calculate_rate(modes[best]));
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   770
#endif
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   771
                XF86VidModeSwitchToMode(display, data->screen, modes[best]);
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   772
            }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   773
            XFree(modes);
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   774
        }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   775
        return;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   776
    }
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   777
#endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   778
}
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   779
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   780
int
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 2963
diff changeset
   781
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
   782
{
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   783
    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
   784
    SDL_DisplayData *data = (SDL_DisplayData *) sdl_display->driverdata;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   785
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   786
    set_best_resolution(display, data, mode->w, mode->h, mode->refresh_rate);
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   787
    return 0;
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   788
}
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   789
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   790
void
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   791
X11_QuitModes(_THIS)
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   792
{
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   793
}
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   794
6331
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   795
int
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   796
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
   797
{
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   798
    SDL_DisplayData *data = (SDL_DisplayData *) sdl_display->driverdata;
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   799
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   800
#if SDL_VIDEO_DRIVER_X11_XINERAMA
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   801
    if (data && data->use_xinerama) {
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   802
        rect->x = data->xinerama_info.x_org;
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   803
        rect->y = data->xinerama_info.y_org;
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   804
        rect->w = data->xinerama_info.width;
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   805
        rect->h = data->xinerama_info.height;
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   806
        return 0;
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   807
    }
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   808
#endif
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   809
    if (_this->windows) {
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   810
        rect->x = 0;
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   811
        rect->y = 0;
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   812
        rect->w = _this->windows->w;
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   813
        rect->h = _this->windows->h;
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   814
        return 0;
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   815
    }
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   816
    return -1;
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   817
}
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   818
5481
22dfc3958dc3 Fixed so code will compile with SDL_config_minimal.h
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
   819
#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
   820
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   821
/* vi: set ts=4 sw=4 expandtab: */