src/video/x11/SDL_x11modes.c
author Gabriel Jacobo <gabomdq@gmail.com>
Wed, 15 Oct 2014 18:33:43 -0300
changeset 9167 3d2c0f659ad3
parent 8922 dfb6f8611ebe
permissions -rw-r--r--
[X11] Obey DISPLAY environment variable when selecting screen (Steaphan Greene) Discussed in bug #2192, tested with Xvfb in dual head configuration.
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
8149
681eb46b8ac4 Fixed bug 2374 - Update copyright for 2014...
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
     3
  Copyright (C) 1997-2014 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
*/
8093
b43765095a6f Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents: 7914
diff changeset
    21
#include "../../SDL_internal.h"
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
5481
22dfc3958dc3 Fixed so code will compile with SDL_config_minimal.h
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
    23
#if SDL_VIDEO_DRIVER_X11
22dfc3958dc3 Fixed so code will compile with SDL_config_minimal.h
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
    24
6472
d4623b7209db Turned the X11 mode extension environment variables into hints so they can be more easily set from applications.
Sam Lantinga <slouken@libsdl.org>
parents: 6468
diff changeset
    25
#include "SDL_hints.h"
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
#include "SDL_x11video.h"
6796
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
    27
#include "edid.h"
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
    29
/* #define X11MODES_DEBUG */
6558
90f231aa77b9 I'm becoming more and more convinced that the application should never use XRandR, and it's the window manager's responsibility to track and manage display modes for fullscreen windows.
Sam Lantinga <slouken@libsdl.org>
parents: 6553
diff changeset
    30
6559
1fc5f5116bd0 Turn off video mode debugging
Sam Lantinga <slouken@libsdl.org>
parents: 6558
diff changeset
    31
/* I'm becoming more and more convinced that the application should never
1fc5f5116bd0 Turn off video mode debugging
Sam Lantinga <slouken@libsdl.org>
parents: 6558
diff changeset
    32
 * use XRandR, and it's the window manager's responsibility to track and
1fc5f5116bd0 Turn off video mode debugging
Sam Lantinga <slouken@libsdl.org>
parents: 6558
diff changeset
    33
 * manage display modes for fullscreen windows.  Right now XRandR is completely
1fc5f5116bd0 Turn off video mode debugging
Sam Lantinga <slouken@libsdl.org>
parents: 6558
diff changeset
    34
 * broken with respect to window manager behavior on every window manager that
1fc5f5116bd0 Turn off video mode debugging
Sam Lantinga <slouken@libsdl.org>
parents: 6558
diff changeset
    35
 * I can find.  For example, on Unity 3D if you show a fullscreen window while
1fc5f5116bd0 Turn off video mode debugging
Sam Lantinga <slouken@libsdl.org>
parents: 6558
diff changeset
    36
 * the resolution is changing (within ~250 ms) your window will retain the
1fc5f5116bd0 Turn off video mode debugging
Sam Lantinga <slouken@libsdl.org>
parents: 6558
diff changeset
    37
 * fullscreen state hint but be decorated and windowed.
6796
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
    38
 *
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
    39
 * However, many people swear by it, so let them swear at it. :)
6558
90f231aa77b9 I'm becoming more and more convinced that the application should never use XRandR, and it's the window manager's responsibility to track and manage display modes for fullscreen windows.
Sam Lantinga <slouken@libsdl.org>
parents: 6553
diff changeset
    40
*/
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
    41
/* #define XRANDR_DISABLED_BY_DEFAULT */
6558
90f231aa77b9 I'm becoming more and more convinced that the application should never use XRandR, and it's the window manager's responsibility to track and manage display modes for fullscreen windows.
Sam Lantinga <slouken@libsdl.org>
parents: 6553
diff changeset
    42
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    43
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    44
static int
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    45
get_visualinfo(Display * display, int screen, XVisualInfo * vinfo)
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    46
{
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    47
    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
    48
    int depth;
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
    /* Look for an exact visual, if requested */
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    51
    if (visual_id) {
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    52
        XVisualInfo *vi, template;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    53
        int nvis;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    54
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    55
        SDL_zero(template);
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    56
        template.visualid = SDL_strtol(visual_id, NULL, 0);
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
    57
        vi = X11_XGetVisualInfo(display, VisualIDMask, &template, &nvis);
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    58
        if (vi) {
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    59
            *vinfo = *vi;
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
    60
            X11_XFree(vi);
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    61
            return 0;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    62
        }
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    63
    }
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    64
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    65
    depth = DefaultDepth(display, screen);
5466
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5408
diff changeset
    66
    if ((X11_UseDirectColorVisuals() &&
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
    67
         X11_XMatchVisualInfo(display, screen, depth, DirectColor, vinfo)) ||
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
    68
        X11_XMatchVisualInfo(display, screen, depth, TrueColor, vinfo) ||
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
    69
        X11_XMatchVisualInfo(display, screen, depth, PseudoColor, vinfo) ||
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
    70
        X11_XMatchVisualInfo(display, screen, depth, StaticColor, vinfo)) {
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    71
        return 0;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    72
    }
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    73
    return -1;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    74
}
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    75
5182
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    76
int
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    77
X11_GetVisualInfoFromVisual(Display * display, Visual * visual, XVisualInfo * vinfo)
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    78
{
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    79
    XVisualInfo *vi;
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    80
    int nvis;
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    81
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
    82
    vinfo->visualid = X11_XVisualIDFromVisual(visual);
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
    83
    vi = X11_XGetVisualInfo(display, VisualIDMask, vinfo, &nvis);
5182
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    84
    if (vi) {
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    85
        *vinfo = *vi;
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
    86
        X11_XFree(vi);
5182
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    87
        return 0;
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    88
    }
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    89
    return -1;
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    90
}
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    91
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    92
Uint32
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
    93
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
    94
{
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    95
    if (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
    96
        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
    97
        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
    98
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
        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
   100
        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
   101
        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
   102
        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
   103
            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
   104
        } 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
   105
            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
   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
        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
   109
        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
   110
            int i, n;
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   111
            XPixmapFormatValues *p = X11_XListPixmapFormats(display, &n);
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
   112
            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
   113
                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
   114
                    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
   115
                        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
   116
                        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
   117
                    }
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
                }
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   119
                X11_XFree(p);
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
   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
        }
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
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
        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
   124
    }
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
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
    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
   127
        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
   128
        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
   129
            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
   130
        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
   131
            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
   132
                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
   133
            } 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
   134
                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
   135
            }
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   136
            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
   137
        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
   138
            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
   139
                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
   140
            } 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
   141
                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
   142
            }
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   143
            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
   144
        }
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   145
    }
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   146
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   147
    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
   148
}
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   149
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   150
/* Global for the error handler */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   151
int vm_event, vm_error = -1;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   152
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   153
#if SDL_VIDEO_DRIVER_X11_XINERAMA
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   154
static SDL_bool
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   155
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
   156
{
6027
56185b574d61 Use correct Xinerama APIs for querying version and availability.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   157
    int event_base = 0;
56185b574d61 Use correct Xinerama APIs for querying version and availability.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   158
    int error_base = 0;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   159
    const char *env;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   160
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   161
    /* Default the extension not available */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   162
    *major = *minor = 0;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   163
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   164
    /* Allow environment override */
6472
d4623b7209db Turned the X11 mode extension environment variables into hints so they can be more easily set from applications.
Sam Lantinga <slouken@libsdl.org>
parents: 6468
diff changeset
   165
    env = SDL_GetHint(SDL_HINT_VIDEO_X11_XINERAMA);
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   166
    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
   167
#ifdef X11MODES_DEBUG
6472
d4623b7209db Turned the X11 mode extension environment variables into hints so they can be more easily set from applications.
Sam Lantinga <slouken@libsdl.org>
parents: 6468
diff changeset
   168
        printf("Xinerama disabled due to hint\n");
6468
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   169
#endif
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   170
        return SDL_FALSE;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   171
    }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   172
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   173
    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
   174
#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
   175
        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
   176
#endif
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   177
        return SDL_FALSE;
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   178
    }
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   179
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   180
    /* Query the extension version */
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   181
    if (!X11_XineramaQueryExtension(display, &event_base, &error_base) ||
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   182
        !X11_XineramaQueryVersion(display, major, minor) ||
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   183
        !X11_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
   184
#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
   185
        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
   186
#endif
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   187
        return SDL_FALSE;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   188
    }
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
   189
#ifdef X11MODES_DEBUG
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   190
    printf("Xinerama available at version %d.%d!\n", *major, *minor);
6468
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   191
#endif
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   192
    return SDL_TRUE;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   193
}
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   194
#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   195
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   196
#if SDL_VIDEO_DRIVER_X11_XRANDR
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   197
static SDL_bool
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   198
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
   199
{
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   200
    const char *env;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   201
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   202
    /* Default the extension not available */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   203
    *major = *minor = 0;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   204
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   205
    /* Allow environment override */
6472
d4623b7209db Turned the X11 mode extension environment variables into hints so they can be more easily set from applications.
Sam Lantinga <slouken@libsdl.org>
parents: 6468
diff changeset
   206
    env = SDL_GetHint(SDL_HINT_VIDEO_X11_XRANDR);
6558
90f231aa77b9 I'm becoming more and more convinced that the application should never use XRandR, and it's the window manager's responsibility to track and manage display modes for fullscreen windows.
Sam Lantinga <slouken@libsdl.org>
parents: 6553
diff changeset
   207
#ifdef XRANDR_DISABLED_BY_DEFAULT
90f231aa77b9 I'm becoming more and more convinced that the application should never use XRandR, and it's the window manager's responsibility to track and manage display modes for fullscreen windows.
Sam Lantinga <slouken@libsdl.org>
parents: 6553
diff changeset
   208
    if (!env || !SDL_atoi(env)) {
90f231aa77b9 I'm becoming more and more convinced that the application should never use XRandR, and it's the window manager's responsibility to track and manage display modes for fullscreen windows.
Sam Lantinga <slouken@libsdl.org>
parents: 6553
diff changeset
   209
#ifdef X11MODES_DEBUG
90f231aa77b9 I'm becoming more and more convinced that the application should never use XRandR, and it's the window manager's responsibility to track and manage display modes for fullscreen windows.
Sam Lantinga <slouken@libsdl.org>
parents: 6553
diff changeset
   210
        printf("XRandR disabled by default due to window manager issues\n");
90f231aa77b9 I'm becoming more and more convinced that the application should never use XRandR, and it's the window manager's responsibility to track and manage display modes for fullscreen windows.
Sam Lantinga <slouken@libsdl.org>
parents: 6553
diff changeset
   211
#endif
90f231aa77b9 I'm becoming more and more convinced that the application should never use XRandR, and it's the window manager's responsibility to track and manage display modes for fullscreen windows.
Sam Lantinga <slouken@libsdl.org>
parents: 6553
diff changeset
   212
        return SDL_FALSE;
90f231aa77b9 I'm becoming more and more convinced that the application should never use XRandR, and it's the window manager's responsibility to track and manage display modes for fullscreen windows.
Sam Lantinga <slouken@libsdl.org>
parents: 6553
diff changeset
   213
    }
90f231aa77b9 I'm becoming more and more convinced that the application should never use XRandR, and it's the window manager's responsibility to track and manage display modes for fullscreen windows.
Sam Lantinga <slouken@libsdl.org>
parents: 6553
diff changeset
   214
#else
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   215
    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
   216
#ifdef X11MODES_DEBUG
6472
d4623b7209db Turned the X11 mode extension environment variables into hints so they can be more easily set from applications.
Sam Lantinga <slouken@libsdl.org>
parents: 6468
diff changeset
   217
        printf("XRandR disabled due to hint\n");
6468
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   218
#endif
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   219
        return SDL_FALSE;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   220
    }
6558
90f231aa77b9 I'm becoming more and more convinced that the application should never use XRandR, and it's the window manager's responsibility to track and manage display modes for fullscreen windows.
Sam Lantinga <slouken@libsdl.org>
parents: 6553
diff changeset
   221
#endif /* XRANDR_ENABLED_BY_DEFAULT */
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   222
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   223
    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
   224
#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
   225
        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
   226
#endif
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   227
        return SDL_FALSE;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   228
    }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   229
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   230
    /* Query the extension version */
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   231
    if (!X11_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
   232
#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
   233
        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
   234
#endif
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   235
        return SDL_FALSE;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   236
    }
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
   237
#ifdef X11MODES_DEBUG
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   238
    printf("XRandR available at version %d.%d!\n", *major, *minor);
6468
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   239
#endif
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   240
    return SDL_TRUE;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   241
}
6537
85cf169db434 Fixed XRandR code to change resolution on the correct monitor in a multi-monitor setup.
Sam Lantinga <slouken@libsdl.org>
parents: 6506
diff changeset
   242
85cf169db434 Fixed XRandR code to change resolution on the correct monitor in a multi-monitor setup.
Sam Lantinga <slouken@libsdl.org>
parents: 6506
diff changeset
   243
#define XRANDR_ROTATION_LEFT    (1 << 1)
85cf169db434 Fixed XRandR code to change resolution on the correct monitor in a multi-monitor setup.
Sam Lantinga <slouken@libsdl.org>
parents: 6506
diff changeset
   244
#define XRANDR_ROTATION_RIGHT   (1 << 3)
85cf169db434 Fixed XRandR code to change resolution on the correct monitor in a multi-monitor setup.
Sam Lantinga <slouken@libsdl.org>
parents: 6506
diff changeset
   245
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   246
static int
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   247
CalculateXRandRRefreshRate(const XRRModeInfo *info)
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   248
{
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   249
    return (info->hTotal
6551
b0679a0d5751 Fixed refresh rate calculation
Sam Lantinga <slouken@libsdl.org>
parents: 6550
diff changeset
   250
            && info->vTotal) ? (info->dotClock / (info->hTotal * info->vTotal)) : 0;
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   251
}
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   252
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   253
static SDL_bool
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   254
SetXRandRModeInfo(Display *display, XRRScreenResources *res, XRROutputInfo *output_info,
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   255
                  RRMode modeID, SDL_DisplayMode *mode)
6537
85cf169db434 Fixed XRandR code to change resolution on the correct monitor in a multi-monitor setup.
Sam Lantinga <slouken@libsdl.org>
parents: 6506
diff changeset
   256
{
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   257
    int i;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   258
    for (i = 0; i < res->nmode; ++i) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   259
        if (res->modes[i].id == modeID) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   260
            XRRCrtcInfo *crtc;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   261
            Rotation rotation = 0;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   262
            const XRRModeInfo *info = &res->modes[i];
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   263
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   264
            crtc = X11_XRRGetCrtcInfo(display, res, output_info->crtc);
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   265
            if (crtc) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   266
                rotation = crtc->rotation;
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   267
                X11_XRRFreeCrtcInfo(crtc);
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   268
            }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   269
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   270
            if (rotation & (XRANDR_ROTATION_LEFT|XRANDR_ROTATION_RIGHT)) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   271
                mode->w = info->height;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   272
                mode->h = info->width;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   273
            } else {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   274
                mode->w = info->width;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   275
                mode->h = info->height;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   276
            }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   277
            mode->refresh_rate = CalculateXRandRRefreshRate(info);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   278
            ((SDL_DisplayModeData*)mode->driverdata)->xrandr_mode = modeID;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   279
#ifdef X11MODES_DEBUG
6560
3c48e9d0ce2e Fixed compiler warning in debug code.
Ryan C. Gordon <icculus@icculus.org>
parents: 6559
diff changeset
   280
            printf("XRandR mode %d: %dx%d@%dHz\n", (int) modeID, mode->w, mode->h, mode->refresh_rate);
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   281
#endif
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   282
            return SDL_TRUE;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   283
        }
6537
85cf169db434 Fixed XRandR code to change resolution on the correct monitor in a multi-monitor setup.
Sam Lantinga <slouken@libsdl.org>
parents: 6506
diff changeset
   284
    }
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   285
    return SDL_FALSE;
6537
85cf169db434 Fixed XRandR code to change resolution on the correct monitor in a multi-monitor setup.
Sam Lantinga <slouken@libsdl.org>
parents: 6506
diff changeset
   286
}
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   287
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   288
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   289
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   290
static SDL_bool
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   291
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
   292
{
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   293
    const char *env;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   294
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   295
    /* Default the extension not available */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   296
    *major = *minor = 0;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   297
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   298
    /* Allow environment override */
6472
d4623b7209db Turned the X11 mode extension environment variables into hints so they can be more easily set from applications.
Sam Lantinga <slouken@libsdl.org>
parents: 6468
diff changeset
   299
    env = SDL_GetHint(SDL_HINT_VIDEO_X11_XVIDMODE);
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   300
    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
   301
#ifdef X11MODES_DEBUG
6472
d4623b7209db Turned the X11 mode extension environment variables into hints so they can be more easily set from applications.
Sam Lantinga <slouken@libsdl.org>
parents: 6468
diff changeset
   302
        printf("XVidMode disabled due to hint\n");
6468
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   303
#endif
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   304
        return SDL_FALSE;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   305
    }
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   306
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   307
    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
   308
#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
   309
        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
   310
#endif
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   311
        return SDL_FALSE;
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   312
    }
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   313
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   314
    /* Query the extension version */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   315
    vm_error = -1;
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   316
    if (!X11_XF86VidModeQueryExtension(display, &vm_event, &vm_error)
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   317
        || !X11_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
   318
#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
   319
        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
   320
#endif
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   321
        return SDL_FALSE;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   322
    }
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
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   324
    printf("XVidMode available at version %d.%d!\n", *major, *minor);
6468
6af2a8db95d0 Fixed bug where Xinerama was treated as being available even if it wasn't.
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   325
#endif
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   326
    return SDL_TRUE;
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
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
   329
static
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   330
Bool XF86VidModeGetModeInfo(Display * dpy, int scr,
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   331
                                       XF86VidModeModeInfo* info)
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   332
{
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   333
    Bool retval;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   334
    int dotclock;
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   335
    XF86VidModeModeLine l;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   336
    SDL_zerop(info);
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   337
    SDL_zero(l);
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   338
    retval = X11_XF86VidModeGetModeLine(dpy, scr, &dotclock, &l);
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   339
    info->dotclock = dotclock;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   340
    info->hdisplay = l.hdisplay;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   341
    info->hsyncstart = l.hsyncstart;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   342
    info->hsyncend = l.hsyncend;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   343
    info->htotal = l.htotal;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   344
    info->hskew = l.hskew;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   345
    info->vdisplay = l.vdisplay;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   346
    info->vsyncstart = l.vsyncstart;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   347
    info->vsyncend = l.vsyncend;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   348
    info->vtotal = l.vtotal;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   349
    info->flags = l.flags;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   350
    info->privsize = l.privsize;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   351
    info->private = l.private;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   352
    return retval;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   353
}
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   354
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   355
static int
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   356
CalculateXVidModeRefreshRate(const XF86VidModeModeInfo * info)
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   357
{
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   358
    return (info->htotal
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   359
            && info->vtotal) ? (1000 * info->dotclock / (info->htotal *
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   360
                                                         info->vtotal)) : 0;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   361
}
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   362
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   363
SDL_bool
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   364
SetXVidModeModeInfo(const XF86VidModeModeInfo *info, SDL_DisplayMode *mode)
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   365
{
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   366
    mode->w = info->hdisplay;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   367
    mode->h = info->vdisplay;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   368
    mode->refresh_rate = CalculateXVidModeRefreshRate(info);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   369
    ((SDL_DisplayModeData*)mode->driverdata)->vm_mode = *info;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   370
    return SDL_TRUE;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   371
}
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   372
#endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   373
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   374
int
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   375
X11_InitModes(_THIS)
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   376
{
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   377
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
9167
3d2c0f659ad3 [X11] Obey DISPLAY environment variable when selecting screen (Steaphan Greene)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8922
diff changeset
   378
    int snum, screen, screencount;
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   379
#if SDL_VIDEO_DRIVER_X11_XINERAMA
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   380
    int xinerama_major, xinerama_minor;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   381
    int use_xinerama = 0;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   382
    XineramaScreenInfo *xinerama = NULL;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   383
#endif
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   384
#if SDL_VIDEO_DRIVER_X11_XRANDR
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   385
    int xrandr_major, xrandr_minor;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   386
    int use_xrandr = 0;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   387
    XRRScreenResources *res = NULL;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   388
#endif
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   389
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   390
    int vm_major, vm_minor;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   391
    int use_vidmode = 0;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   392
#endif
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   393
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   394
#if SDL_VIDEO_DRIVER_X11_XINERAMA
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   395
    /* Query Xinerama extention
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   396
     * NOTE: This works with Nvidia Twinview correctly, but you need version 302.17 (released on June 2012)
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   397
     *       or newer of the Nvidia binary drivers
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   398
     */
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   399
    if (CheckXinerama(data->display, &xinerama_major, &xinerama_minor)) {
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   400
        xinerama = X11_XineramaQueryScreens(data->display, &screencount);
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   401
        if (xinerama) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   402
            use_xinerama = xinerama_major * 100 + xinerama_minor;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   403
        }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   404
    }
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   405
    if (!xinerama) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   406
        screencount = ScreenCount(data->display);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   407
    }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   408
#else
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   409
    screencount = ScreenCount(data->display);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   410
#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   411
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   412
#if SDL_VIDEO_DRIVER_X11_XRANDR
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   413
    /* require at least XRandR v1.2 */
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   414
    if (CheckXRandR(data->display, &xrandr_major, &xrandr_minor) &&
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   415
        (xrandr_major >= 2 || (xrandr_major == 1 && xrandr_minor >= 2))) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   416
        use_xrandr = xrandr_major * 100 + xrandr_minor;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   417
    }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   418
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   419
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   420
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   421
    if (CheckVidMode(data->display, &vm_major, &vm_minor)) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   422
        use_vidmode = vm_major * 100 + vm_minor;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   423
    }
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   424
#endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   425
9167
3d2c0f659ad3 [X11] Obey DISPLAY environment variable when selecting screen (Steaphan Greene)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8922
diff changeset
   426
    for (snum = 0; snum < screencount; ++snum) {
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   427
        XVisualInfo vinfo;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   428
        SDL_VideoDisplay display;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   429
        SDL_DisplayData *displaydata;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   430
        SDL_DisplayMode mode;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   431
        SDL_DisplayModeData *modedata;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   432
        XPixmapFormatValues *pixmapFormats;
6796
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   433
        char display_name[128];
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   434
        int i, n;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   435
9167
3d2c0f659ad3 [X11] Obey DISPLAY environment variable when selecting screen (Steaphan Greene)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8922
diff changeset
   436
        /* Re-order screens to always put default screen first */
3d2c0f659ad3 [X11] Obey DISPLAY environment variable when selecting screen (Steaphan Greene)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8922
diff changeset
   437
        if (snum == 0) {
3d2c0f659ad3 [X11] Obey DISPLAY environment variable when selecting screen (Steaphan Greene)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8922
diff changeset
   438
            screen = DefaultScreen(data->display);
3d2c0f659ad3 [X11] Obey DISPLAY environment variable when selecting screen (Steaphan Greene)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8922
diff changeset
   439
        } else if (snum == DefaultScreen(data->display)) {
3d2c0f659ad3 [X11] Obey DISPLAY environment variable when selecting screen (Steaphan Greene)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8922
diff changeset
   440
            screen = 0;
3d2c0f659ad3 [X11] Obey DISPLAY environment variable when selecting screen (Steaphan Greene)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8922
diff changeset
   441
        } else {
3d2c0f659ad3 [X11] Obey DISPLAY environment variable when selecting screen (Steaphan Greene)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8922
diff changeset
   442
            screen = snum;
3d2c0f659ad3 [X11] Obey DISPLAY environment variable when selecting screen (Steaphan Greene)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8922
diff changeset
   443
        }
3d2c0f659ad3 [X11] Obey DISPLAY environment variable when selecting screen (Steaphan Greene)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8922
diff changeset
   444
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   445
#if SDL_VIDEO_DRIVER_X11_XINERAMA
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   446
        if (xinerama) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   447
            if (get_visualinfo(data->display, 0, &vinfo) < 0) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   448
                continue;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   449
            }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   450
        } else {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   451
            if (get_visualinfo(data->display, screen, &vinfo) < 0) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   452
                continue;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   453
            }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   454
        }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   455
#else
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   456
        if (get_visualinfo(data->display, screen, &vinfo) < 0) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   457
            continue;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   458
        }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   459
#endif
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   460
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   461
        displaydata = (SDL_DisplayData *) SDL_calloc(1, sizeof(*displaydata));
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   462
        if (!displaydata) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   463
            continue;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   464
        }
6796
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   465
        display_name[0] = '\0';
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   466
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   467
        mode.format = X11_GetPixelFormatFromVisualInfo(data->display, &vinfo);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   468
        if (SDL_ISPIXELFORMAT_INDEXED(mode.format)) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   469
            /* We don't support palettized modes now */
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   470
            SDL_free(displaydata);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   471
            continue;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   472
        }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   473
#if SDL_VIDEO_DRIVER_X11_XINERAMA
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   474
        if (xinerama) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   475
            mode.w = xinerama[screen].width;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   476
            mode.h = xinerama[screen].height;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   477
        } else {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   478
            mode.w = DisplayWidth(data->display, screen);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   479
            mode.h = DisplayHeight(data->display, screen);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   480
        }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   481
#else
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   482
        mode.w = DisplayWidth(data->display, screen);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   483
        mode.h = DisplayHeight(data->display, screen);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   484
#endif
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   485
        mode.refresh_rate = 0;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   486
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   487
        modedata = (SDL_DisplayModeData *) SDL_calloc(1, sizeof(SDL_DisplayModeData));
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   488
        if (!modedata) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   489
            SDL_free(displaydata);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   490
            continue;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   491
        }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   492
        mode.driverdata = modedata;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   493
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   494
#if SDL_VIDEO_DRIVER_X11_XINERAMA
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   495
        /* Most of SDL's calls to X11 are unwaware of Xinerama, and to X11 standard calls, when Xinerama is active,
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   496
         * there's only one screen available. So we force the screen number to zero and
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   497
         * let Xinerama specific code handle specific functionality using displaydata->xinerama_info
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   498
         */
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   499
        if (use_xinerama) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   500
            displaydata->screen = 0;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   501
            displaydata->use_xinerama = use_xinerama;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   502
            displaydata->xinerama_info = xinerama[screen];
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   503
            displaydata->xinerama_screen = screen;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   504
        }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   505
        else displaydata->screen = screen;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   506
#else
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   507
        displaydata->screen = screen;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   508
#endif
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   509
        displaydata->visual = vinfo.visual;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   510
        displaydata->depth = vinfo.depth;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   511
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   512
        displaydata->scanline_pad = SDL_BYTESPERPIXEL(mode.format) * 8;
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   513
        pixmapFormats = X11_XListPixmapFormats(data->display, &n);
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   514
        if (pixmapFormats) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   515
            for (i = 0; i < n; ++i) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   516
                if (pixmapFormats[i].depth == displaydata->depth) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   517
                    displaydata->scanline_pad = pixmapFormats[i].scanline_pad;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   518
                    break;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   519
                }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   520
            }
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   521
            X11_XFree(pixmapFormats);
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   522
        }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   523
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   524
#if SDL_VIDEO_DRIVER_X11_XINERAMA
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   525
        if (use_xinerama) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   526
            displaydata->x = xinerama[screen].x_org;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   527
            displaydata->y = xinerama[screen].y_org;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   528
        }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   529
        else
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   530
#endif
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   531
        {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   532
            displaydata->x = 0;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   533
            displaydata->y = 0;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   534
        }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   535
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   536
#if SDL_VIDEO_DRIVER_X11_XRANDR
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   537
        if (use_xrandr) {
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   538
            res = X11_XRRGetScreenResources(data->display, RootWindow(data->display, displaydata->screen));
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   539
        }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   540
        if (res) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   541
            XRROutputInfo *output_info;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   542
            XRRCrtcInfo *crtc;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   543
            int output;
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   544
            Atom EDID = X11_XInternAtom(data->display, "EDID", False);
6796
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   545
            Atom *props;
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   546
            int nprop;
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   547
            unsigned long width_mm;
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   548
            unsigned long height_mm;
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   549
            int inches = 0;
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   550
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   551
            for (output = 0; output < res->noutput; output++) {
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   552
                output_info = X11_XRRGetOutputInfo(data->display, res, res->outputs[output]);
6550
191f00a080ba Don't try to query outputs that are not hooked up to a crtc
Sam Lantinga <slouken@libsdl.org>
parents: 6549
diff changeset
   553
                if (!output_info || !output_info->crtc ||
191f00a080ba Don't try to query outputs that are not hooked up to a crtc
Sam Lantinga <slouken@libsdl.org>
parents: 6549
diff changeset
   554
                    output_info->connection == RR_Disconnected) {
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   555
                    X11_XRRFreeOutputInfo(output_info);
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   556
                    continue;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   557
                }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   558
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   559
                /* Is this the output that corresponds to the current screen?
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   560
                   We're checking the crtc position, but that may not be a valid test
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   561
                   in all cases.  Anybody want to give this some love?
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   562
                 */
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   563
                crtc = X11_XRRGetCrtcInfo(data->display, res, output_info->crtc);
7914
a391318fa60f Fixed spot where SDL was assuming that two displays having the same origin means they're the same display. Changed it to check for the same extents instead.
Sam Lantinga <slouken@libsdl.org>
parents: 7827
diff changeset
   564
                if (!crtc || crtc->x != displaydata->x || crtc->y != displaydata->y ||
a391318fa60f Fixed spot where SDL was assuming that two displays having the same origin means they're the same display. Changed it to check for the same extents instead.
Sam Lantinga <slouken@libsdl.org>
parents: 7827
diff changeset
   565
                    crtc->width != mode.w || crtc->height != mode.h) {
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   566
                    X11_XRRFreeOutputInfo(output_info);
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   567
                    X11_XRRFreeCrtcInfo(crtc);
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   568
                    continue;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   569
                }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   570
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   571
                displaydata->use_xrandr = use_xrandr;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   572
                displaydata->xrandr_output = res->outputs[output];
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   573
                SetXRandRModeInfo(data->display, res, output_info, crtc->mode, &mode);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   574
6796
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   575
                /* Get the name of this display */
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   576
                width_mm = output_info->mm_width;
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   577
                height_mm = output_info->mm_height;
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   578
                inches = (int)((sqrt(width_mm * width_mm +
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   579
                                     height_mm * height_mm) / 25.4f) + 0.5f);
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   580
                SDL_strlcpy(display_name, output_info->name, sizeof(display_name));
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   581
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   582
                /* See if we can get the EDID data for the real monitor name */
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   583
                props = X11_XRRListOutputProperties(data->display, res->outputs[output], &nprop);
6796
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   584
                for (i = 0; i < nprop; ++i) {
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   585
                    unsigned char *prop;
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   586
                    int actual_format;
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   587
                    unsigned long nitems, bytes_after;
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   588
                    Atom actual_type;
6940
142dcc136188 Fixed bug 1736 - Memory leak in X11_InitModes
Sam Lantinga <slouken@libsdl.org>
parents: 6906
diff changeset
   589
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   590
                    if (props[i] == EDID) {
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   591
                        if (X11_XRRGetOutputProperty(data->display,
6940
142dcc136188 Fixed bug 1736 - Memory leak in X11_InitModes
Sam Lantinga <slouken@libsdl.org>
parents: 6906
diff changeset
   592
                                                 res->outputs[output], props[i],
142dcc136188 Fixed bug 1736 - Memory leak in X11_InitModes
Sam Lantinga <slouken@libsdl.org>
parents: 6906
diff changeset
   593
                                                 0, 100, False, False,
142dcc136188 Fixed bug 1736 - Memory leak in X11_InitModes
Sam Lantinga <slouken@libsdl.org>
parents: 6906
diff changeset
   594
                                                 AnyPropertyType,
142dcc136188 Fixed bug 1736 - Memory leak in X11_InitModes
Sam Lantinga <slouken@libsdl.org>
parents: 6906
diff changeset
   595
                                                 &actual_type, &actual_format,
142dcc136188 Fixed bug 1736 - Memory leak in X11_InitModes
Sam Lantinga <slouken@libsdl.org>
parents: 6906
diff changeset
   596
                                                 &nitems, &bytes_after, &prop) == Success ) {
142dcc136188 Fixed bug 1736 - Memory leak in X11_InitModes
Sam Lantinga <slouken@libsdl.org>
parents: 6906
diff changeset
   597
                            MonitorInfo *info = decode_edid(prop);
142dcc136188 Fixed bug 1736 - Memory leak in X11_InitModes
Sam Lantinga <slouken@libsdl.org>
parents: 6906
diff changeset
   598
                            if (info) {
142dcc136188 Fixed bug 1736 - Memory leak in X11_InitModes
Sam Lantinga <slouken@libsdl.org>
parents: 6906
diff changeset
   599
    #ifdef X11MODES_DEBUG
142dcc136188 Fixed bug 1736 - Memory leak in X11_InitModes
Sam Lantinga <slouken@libsdl.org>
parents: 6906
diff changeset
   600
                                printf("Found EDID data for %s\n", output_info->name);
142dcc136188 Fixed bug 1736 - Memory leak in X11_InitModes
Sam Lantinga <slouken@libsdl.org>
parents: 6906
diff changeset
   601
                                dump_monitor_info(info);
142dcc136188 Fixed bug 1736 - Memory leak in X11_InitModes
Sam Lantinga <slouken@libsdl.org>
parents: 6906
diff changeset
   602
    #endif
142dcc136188 Fixed bug 1736 - Memory leak in X11_InitModes
Sam Lantinga <slouken@libsdl.org>
parents: 6906
diff changeset
   603
                                SDL_strlcpy(display_name, info->dsc_product_name, sizeof(display_name));
142dcc136188 Fixed bug 1736 - Memory leak in X11_InitModes
Sam Lantinga <slouken@libsdl.org>
parents: 6906
diff changeset
   604
                                free(info);
142dcc136188 Fixed bug 1736 - Memory leak in X11_InitModes
Sam Lantinga <slouken@libsdl.org>
parents: 6906
diff changeset
   605
                            }
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   606
                            X11_XFree(prop);
6796
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   607
                        }
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   608
                        break;
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   609
                    }
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   610
                }
6940
142dcc136188 Fixed bug 1736 - Memory leak in X11_InitModes
Sam Lantinga <slouken@libsdl.org>
parents: 6906
diff changeset
   611
                if (props) {
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   612
                    X11_XFree(props);
6940
142dcc136188 Fixed bug 1736 - Memory leak in X11_InitModes
Sam Lantinga <slouken@libsdl.org>
parents: 6906
diff changeset
   613
                }
6796
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   614
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   615
                if (*display_name && inches) {
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   616
                    size_t len = SDL_strlen(display_name);
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   617
                    SDL_snprintf(&display_name[len], sizeof(display_name)-len, " %d\"", inches);
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   618
                }
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   619
#ifdef X11MODES_DEBUG
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   620
                printf("Display name: %s\n", display_name);
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   621
#endif
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   622
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   623
                X11_XRRFreeOutputInfo(output_info);
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   624
                X11_XRRFreeCrtcInfo(crtc);
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   625
                break;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   626
            }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   627
#ifdef X11MODES_DEBUG
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   628
            if (output == res->noutput) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   629
                printf("Couldn't find XRandR CRTC at %d,%d\n", displaydata->x, displaydata->y);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   630
            }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   631
#endif
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   632
            X11_XRRFreeScreenResources(res);
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   633
        }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   634
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   635
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   636
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   637
        if (!displaydata->use_xrandr &&
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   638
#if SDL_VIDEO_DRIVER_X11_XINERAMA
6564
fa0c355cbcdd XVidMode only works on the screen at the origin
Sam Lantinga <slouken@libsdl.org>
parents: 6560
diff changeset
   639
            /* XVidMode only works on the screen at the origin */
fa0c355cbcdd XVidMode only works on the screen at the origin
Sam Lantinga <slouken@libsdl.org>
parents: 6560
diff changeset
   640
            (!displaydata->use_xinerama ||
fa0c355cbcdd XVidMode only works on the screen at the origin
Sam Lantinga <slouken@libsdl.org>
parents: 6560
diff changeset
   641
             (displaydata->x == 0 && displaydata->y == 0)) &&
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   642
#endif
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   643
            use_vidmode) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   644
            displaydata->use_vidmode = use_vidmode;
6565
1f3c0df426dc When using Xinerama, XVidMode always works on screen 0. Otherwise use the real X11 screen.
Sam Lantinga <slouken@libsdl.org>
parents: 6564
diff changeset
   645
            if (displaydata->use_xinerama) {
1f3c0df426dc When using Xinerama, XVidMode always works on screen 0. Otherwise use the real X11 screen.
Sam Lantinga <slouken@libsdl.org>
parents: 6564
diff changeset
   646
                displaydata->vidmode_screen = 0;
1f3c0df426dc When using Xinerama, XVidMode always works on screen 0. Otherwise use the real X11 screen.
Sam Lantinga <slouken@libsdl.org>
parents: 6564
diff changeset
   647
            } else {
1f3c0df426dc When using Xinerama, XVidMode always works on screen 0. Otherwise use the real X11 screen.
Sam Lantinga <slouken@libsdl.org>
parents: 6564
diff changeset
   648
                displaydata->vidmode_screen = screen;
1f3c0df426dc When using Xinerama, XVidMode always works on screen 0. Otherwise use the real X11 screen.
Sam Lantinga <slouken@libsdl.org>
parents: 6564
diff changeset
   649
            }
1f3c0df426dc When using Xinerama, XVidMode always works on screen 0. Otherwise use the real X11 screen.
Sam Lantinga <slouken@libsdl.org>
parents: 6564
diff changeset
   650
            XF86VidModeGetModeInfo(data->display, displaydata->vidmode_screen, &modedata->vm_mode);
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   651
        }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   652
#endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   653
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   654
        SDL_zero(display);
6796
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   655
        if (*display_name) {
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   656
            display.name = display_name;
424a12862805 Implemented SDL_GetDisplayName() for X11, which requires the XRandR extension.
Sam Lantinga <slouken@libsdl.org>
parents: 6566
diff changeset
   657
        }
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   658
        display.desktop_mode = mode;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   659
        display.current_mode = mode;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   660
        display.driverdata = displaydata;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   661
        SDL_AddVideoDisplay(&display);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   662
    }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   663
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   664
#if SDL_VIDEO_DRIVER_X11_XINERAMA
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   665
    if (xinerama) X11_XFree(xinerama);
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   666
#endif
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   667
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   668
    if (_this->num_displays == 0) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6941
diff changeset
   669
        return SDL_SetError("No available displays");
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   670
    }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   671
    return 0;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   672
}
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   673
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   674
void
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 2963
diff changeset
   675
X11_GetDisplayModes(_THIS, SDL_VideoDisplay * sdl_display)
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   676
{
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
   677
    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
   678
    SDL_DisplayData *data = (SDL_DisplayData *) sdl_display->driverdata;
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   679
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   680
    int nmodes;
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   681
    XF86VidModeModeInfo ** modes;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   682
#endif
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   683
    int screen_w;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   684
    int screen_h;
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   685
    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
   686
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   687
    /* 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
   688
     * 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
   689
     * 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
   690
     * 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
   691
     * (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
   692
     */
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 2963
diff changeset
   693
    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
   694
    mode.driverdata = NULL;
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   695
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   696
    screen_w = DisplayWidth(display, data->screen);
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   697
    screen_h = DisplayHeight(display, data->screen);
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   698
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   699
#if SDL_VIDEO_DRIVER_X11_XINERAMA
6331
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   700
    if (data->use_xinerama) {
7361
9b4430c49235 Remove full-desktop Xinerama mode when using XRandR
David Gow <david@ingeniumdigital.com>
parents: 7191
diff changeset
   701
        if (data->use_vidmode && !data->xinerama_info.x_org && !data->xinerama_info.y_org &&
6331
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   702
           (screen_w > data->xinerama_info.width || screen_h > data->xinerama_info.height)) {
8922
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   703
            SDL_DisplayModeData *modedata;
7361
9b4430c49235 Remove full-desktop Xinerama mode when using XRandR
David Gow <david@ingeniumdigital.com>
parents: 7191
diff changeset
   704
            /* Add the full (both screens combined) xinerama mode only on the display that starts at 0,0
9b4430c49235 Remove full-desktop Xinerama mode when using XRandR
David Gow <david@ingeniumdigital.com>
parents: 7191
diff changeset
   705
             * if we're using vidmode.
9b4430c49235 Remove full-desktop Xinerama mode when using XRandR
David Gow <david@ingeniumdigital.com>
parents: 7191
diff changeset
   706
             */
6331
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   707
            mode.w = screen_w;
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   708
            mode.h = screen_h;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   709
            mode.refresh_rate = 0;
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   710
            modedata = (SDL_DisplayModeData *) SDL_calloc(1, sizeof(SDL_DisplayModeData));
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   711
            if (modedata) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   712
                *modedata = *(SDL_DisplayModeData *)sdl_display->desktop_mode.driverdata;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   713
            }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   714
            mode.driverdata = modedata;
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 2963
diff changeset
   715
            SDL_AddDisplayMode(sdl_display, &mode);
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   716
        }
7431
0fc94f315dac Only get desktop modes from Xinerama if we can't use XRandR (fix #1956)
David Gow <david@ingeniumdigital.com>
parents: 7361
diff changeset
   717
        else if (!data->use_xrandr)
7361
9b4430c49235 Remove full-desktop Xinerama mode when using XRandR
David Gow <david@ingeniumdigital.com>
parents: 7191
diff changeset
   718
        {
8922
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   719
            SDL_DisplayModeData *modedata;
7431
0fc94f315dac Only get desktop modes from Xinerama if we can't use XRandR (fix #1956)
David Gow <david@ingeniumdigital.com>
parents: 7361
diff changeset
   720
            /* Add the current mode of each monitor otherwise if we can't get them from xrandr */
7361
9b4430c49235 Remove full-desktop Xinerama mode when using XRandR
David Gow <david@ingeniumdigital.com>
parents: 7191
diff changeset
   721
            mode.w = data->xinerama_info.width;
9b4430c49235 Remove full-desktop Xinerama mode when using XRandR
David Gow <david@ingeniumdigital.com>
parents: 7191
diff changeset
   722
            mode.h = data->xinerama_info.height;
9b4430c49235 Remove full-desktop Xinerama mode when using XRandR
David Gow <david@ingeniumdigital.com>
parents: 7191
diff changeset
   723
            mode.refresh_rate = 0;
9b4430c49235 Remove full-desktop Xinerama mode when using XRandR
David Gow <david@ingeniumdigital.com>
parents: 7191
diff changeset
   724
            modedata = (SDL_DisplayModeData *) SDL_calloc(1, sizeof(SDL_DisplayModeData));
9b4430c49235 Remove full-desktop Xinerama mode when using XRandR
David Gow <david@ingeniumdigital.com>
parents: 7191
diff changeset
   725
            if (modedata) {
9b4430c49235 Remove full-desktop Xinerama mode when using XRandR
David Gow <david@ingeniumdigital.com>
parents: 7191
diff changeset
   726
                *modedata = *(SDL_DisplayModeData *)sdl_display->desktop_mode.driverdata;
9b4430c49235 Remove full-desktop Xinerama mode when using XRandR
David Gow <david@ingeniumdigital.com>
parents: 7191
diff changeset
   727
            }
9b4430c49235 Remove full-desktop Xinerama mode when using XRandR
David Gow <david@ingeniumdigital.com>
parents: 7191
diff changeset
   728
            mode.driverdata = modedata;
9b4430c49235 Remove full-desktop Xinerama mode when using XRandR
David Gow <david@ingeniumdigital.com>
parents: 7191
diff changeset
   729
            SDL_AddDisplayMode(sdl_display, &mode);
9b4430c49235 Remove full-desktop Xinerama mode when using XRandR
David Gow <david@ingeniumdigital.com>
parents: 7191
diff changeset
   730
        }
9b4430c49235 Remove full-desktop Xinerama mode when using XRandR
David Gow <david@ingeniumdigital.com>
parents: 7191
diff changeset
   731
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   732
    }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   733
#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   734
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   735
#if SDL_VIDEO_DRIVER_X11_XRANDR
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   736
    if (data->use_xrandr) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   737
        XRRScreenResources *res;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   738
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   739
        res = X11_XRRGetScreenResources (display, RootWindow(display, data->screen));
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   740
        if (res) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   741
            SDL_DisplayModeData *modedata;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   742
            XRROutputInfo *output_info;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   743
            int i;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   744
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   745
            output_info = X11_XRRGetOutputInfo(display, res, data->xrandr_output);
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   746
            if (output_info && output_info->connection != RR_Disconnected) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   747
                for (i = 0; i < output_info->nmode; ++i) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   748
                    modedata = (SDL_DisplayModeData *) SDL_calloc(1, sizeof(SDL_DisplayModeData));
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   749
                    if (!modedata) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   750
                        continue;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   751
                    }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   752
                    mode.driverdata = modedata;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   753
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   754
                    if (SetXRandRModeInfo(display, res, output_info, output_info->modes[i], &mode)) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   755
                        SDL_AddDisplayMode(sdl_display, &mode);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   756
                    } else {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   757
                        SDL_free(modedata);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   758
                    }
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   759
                }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   760
            }
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   761
            X11_XRRFreeOutputInfo(output_info);
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   762
            X11_XRRFreeScreenResources(res);
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   763
        }
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   764
        return;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   765
    }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   766
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   767
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   768
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   769
    if (data->use_vidmode &&
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   770
        X11_XF86VidModeGetAllModeLines(display, data->vidmode_screen, &nmodes, &modes)) {
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   771
        int i;
8922
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   772
        SDL_DisplayModeData *modedata;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   773
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   774
#ifdef X11MODES_DEBUG
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   775
        printf("VidMode modes: (unsorted)\n");
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   776
        for (i = 0; i < nmodes; ++i) {
6566
dd7e57847ea9 Add flags to the vidmode debug output
Sam Lantinga <slouken@libsdl.org>
parents: 6565
diff changeset
   777
            printf("Mode %d: %d x %d @ %d, flags: 0x%x\n", i,
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   778
                   modes[i]->hdisplay, modes[i]->vdisplay,
6566
dd7e57847ea9 Add flags to the vidmode debug output
Sam Lantinga <slouken@libsdl.org>
parents: 6565
diff changeset
   779
                   CalculateXVidModeRefreshRate(modes[i]), modes[i]->flags);
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   780
        }
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   781
#endif
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   782
        for (i = 0; i < nmodes; ++i) {
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   783
            modedata = (SDL_DisplayModeData *) SDL_calloc(1, sizeof(SDL_DisplayModeData));
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   784
            if (!modedata) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   785
                continue;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   786
            }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   787
            mode.driverdata = modedata;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   788
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   789
            if (SetXVidModeModeInfo(modes[i], &mode)) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   790
                SDL_AddDisplayMode(sdl_display, &mode);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   791
            } else {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   792
                SDL_free(modedata);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   793
            }
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   794
        }
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   795
        X11_XFree(modes);
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   796
        return;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   797
    }
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   798
#endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   799
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   800
    if (!data->use_xrandr && !data->use_vidmode) {
8922
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   801
        SDL_DisplayModeData *modedata;
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   802
        /* Add the desktop mode */
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   803
        mode = sdl_display->desktop_mode;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   804
        modedata = (SDL_DisplayModeData *) SDL_calloc(1, sizeof(SDL_DisplayModeData));
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   805
        if (modedata) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   806
            *modedata = *(SDL_DisplayModeData *)sdl_display->desktop_mode.driverdata;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   807
        }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   808
        mode.driverdata = modedata;
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 2963
diff changeset
   809
        SDL_AddDisplayMode(sdl_display, &mode);
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2873
diff changeset
   810
    }
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   811
}
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   812
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   813
int
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 2963
diff changeset
   814
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
   815
{
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   816
    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
   817
    SDL_DisplayData *data = (SDL_DisplayData *) sdl_display->driverdata;
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   818
    SDL_DisplayModeData *modedata = (SDL_DisplayModeData *)mode->driverdata;
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   819
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   820
#if SDL_VIDEO_DRIVER_X11_XRANDR
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   821
    if (data->use_xrandr) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   822
        XRRScreenResources *res;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   823
        XRROutputInfo *output_info;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   824
        XRRCrtcInfo *crtc;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   825
        Status status;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   826
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   827
        res = X11_XRRGetScreenResources (display, RootWindow(display, data->screen));
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   828
        if (!res) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6941
diff changeset
   829
            return SDL_SetError("Couldn't get XRandR screen resources");
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   830
        }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   831
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   832
        output_info = X11_XRRGetOutputInfo(display, res, data->xrandr_output);
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   833
        if (!output_info || output_info->connection == RR_Disconnected) {
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   834
            X11_XRRFreeScreenResources(res);
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6941
diff changeset
   835
            return SDL_SetError("Couldn't get XRandR output info");
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   836
        }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   837
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   838
        crtc = X11_XRRGetCrtcInfo(display, res, output_info->crtc);
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   839
        if (!crtc) {
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   840
            X11_XRRFreeOutputInfo(output_info);
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   841
            X11_XRRFreeScreenResources(res);
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6941
diff changeset
   842
            return SDL_SetError("Couldn't get XRandR crtc info");
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   843
        }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   844
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   845
        status = X11_XRRSetCrtcConfig (display, res, output_info->crtc, CurrentTime,
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   846
          crtc->x, crtc->y, modedata->xrandr_mode, crtc->rotation,
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   847
          &data->xrandr_output, 1);
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   848
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   849
        X11_XRRFreeCrtcInfo(crtc);
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   850
        X11_XRRFreeOutputInfo(output_info);
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   851
        X11_XRRFreeScreenResources(res);
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   852
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   853
        if (status != Success) {
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   854
            return SDL_SetError("X11_XRRSetCrtcConfig failed");
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   855
        }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   856
    }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   857
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   858
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   859
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   860
    if (data->use_vidmode) {
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   861
        X11_XF86VidModeSwitchToMode(display, data->vidmode_screen, &modedata->vm_mode);
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   862
    }
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   863
#endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   864
2873
b33e38aaa027 Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
   865
    return 0;
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   866
}
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   867
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   868
void
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   869
X11_QuitModes(_THIS)
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   870
{
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   871
}
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   872
6331
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   873
int
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   874
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
   875
{
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   876
    SDL_DisplayData *data = (SDL_DisplayData *) sdl_display->driverdata;
6502
f41a82de351e Fixed detection of display bounds after a mode switch when Xinerama is enabled.
Sam Lantinga <slouken@libsdl.org>
parents: 6482
diff changeset
   877
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   878
    rect->x = data->x;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   879
    rect->y = data->y;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   880
    rect->w = sdl_display->current_mode.w;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   881
    rect->h = sdl_display->current_mode.h;
6331
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   882
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   883
#if SDL_VIDEO_DRIVER_X11_XINERAMA
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   884
    /* Get the real current bounds of the display */
6502
f41a82de351e Fixed detection of display bounds after a mode switch when Xinerama is enabled.
Sam Lantinga <slouken@libsdl.org>
parents: 6482
diff changeset
   885
    if (data->use_xinerama) {
7485
6ffa71faa50b Fixed another compiler warning.
Ryan C. Gordon <icculus@icculus.org>
parents: 7431
diff changeset
   886
        Display *display = ((SDL_VideoData *) _this->driverdata)->display;
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   887
        int screencount;
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   888
        XineramaScreenInfo *xinerama = X11_XineramaQueryScreens(display, &screencount);
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   889
        if (xinerama) {
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   890
            rect->x = xinerama[data->xinerama_screen].x_org;
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   891
            rect->y = xinerama[data->xinerama_screen].y_org;
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7678
diff changeset
   892
            X11_XFree(xinerama);
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   893
        }
6331
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   894
    }
6548
fc9e6be24ca9 Rewritten X11 video mode support to directly set requested modes and exactly restore the desktop mode at shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 6538
diff changeset
   895
#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
6475
71d39944810b Fixed fullscreen origin for multi-head displays
Sam Lantinga <slouken@libsdl.org>
parents: 6472
diff changeset
   896
    return 0;
6331
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   897
}
5732e1a80bde Fixes #1522, improved Xinerama / Twinview support
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6138
diff changeset
   898
5481
22dfc3958dc3 Fixed so code will compile with SDL_config_minimal.h
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
   899
#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
   900
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   901
/* vi: set ts=4 sw=4 expandtab: */