Mercurial > sdl-ios-xcode
annotate src/video/x11/SDL_x11modes.c @ 3052:b7197d7e8566
indent
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 30 Jan 2009 06:38:44 +0000 |
parents | ee331407574f |
children | 4b594623401b |
rev | line source |
---|---|
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 /* |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
2859 | 3 Copyright (C) 1997-2009 Sam Lantinga |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
13 Lesser General Public License for more details. |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 Sam Lantinga |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 slouken@libsdl.org |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 */ |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 #include "SDL_config.h" |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 #include "SDL_x11video.h" |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
26 //#define X11MODES_DEBUG |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
27 #undef SDL_VIDEO_DRIVER_X11_XINERAMA |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
28 #undef SDL_VIDEO_DRIVER_X11_XRANDR |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
29 #undef SDL_VIDEO_DRIVER_X11_VIDMODE |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
30 |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
31 static int |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
32 get_visualinfo(Display * display, int screen, XVisualInfo * vinfo) |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 { |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
34 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
|
35 int depth; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
36 |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
37 /* Look for an exact visual, if requested */ |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
38 if (visual_id) { |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
39 XVisualInfo *vi, template; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
40 int nvis; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
41 |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
42 SDL_zero(template); |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
43 template.visualid = SDL_strtol(visual_id, NULL, 0); |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 vi = XGetVisualInfo(display, VisualIDMask, &template, &nvis); |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 if (vi) { |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
46 *vinfo = *vi; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
47 XFree(vi); |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
48 return 0; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
49 } |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
50 } |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
51 |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
52 depth = DefaultDepth(display, screen); |
2963
ee331407574f
Don't use DirectColor visuals until we implement DirectColor colormap support
Sam Lantinga <slouken@libsdl.org>
parents:
2954
diff
changeset
|
53 if ((X11_UseDirectColorVisuals() && |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 XMatchVisualInfo(display, screen, depth, DirectColor, vinfo)) || |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
55 XMatchVisualInfo(display, screen, depth, TrueColor, vinfo) || |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
56 XMatchVisualInfo(display, screen, depth, PseudoColor, vinfo) || |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
57 XMatchVisualInfo(display, screen, depth, StaticColor, vinfo)) { |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
58 return 0; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 } |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
60 return -1; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
61 } |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 |
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
|
63 static Uint32 |
2874 | 64 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
|
65 { |
b801df19835f
The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
66 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
|
67 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
|
68 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
|
69 |
b801df19835f
The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
70 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
|
71 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
|
72 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
|
73 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
|
74 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
|
75 } 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
|
76 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
|
77 } |
b801df19835f
The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
78 |
b801df19835f
The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
79 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
|
80 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
|
81 int i, n; |
b801df19835f
The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
82 XPixmapFormatValues *p = XListPixmapFormats(display, &n); |
b801df19835f
The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
83 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
|
84 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
|
85 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
|
86 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
|
87 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
|
88 } |
b801df19835f
The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
89 } |
b801df19835f
The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
90 XFree(p); |
b801df19835f
The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
91 } |
b801df19835f
The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
92 } |
b801df19835f
The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
93 |
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 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
|
95 } |
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 |
b801df19835f
The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
97 if (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
|
98 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
|
99 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
|
100 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
|
101 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
|
102 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
|
103 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
|
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 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
|
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 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
|
108 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
|
109 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
|
110 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
|
111 } 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
|
112 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
|
113 } |
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 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
|
115 } |
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 } |
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 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
|
119 } |
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 |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
121 void |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
122 X11_InitModes(_THIS) |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
123 { |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
124 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
125 int screen; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
126 |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
127 for (screen = 0; screen < ScreenCount(data->display); ++screen) { |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
128 XVisualInfo vinfo; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
129 SDL_VideoDisplay display; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
130 SDL_DisplayData *displaydata; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
131 SDL_DisplayMode mode; |
2916
ffdd533f7add
Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents:
2906
diff
changeset
|
132 XPixmapFormatValues *pixmapFormats; |
ffdd533f7add
Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents:
2906
diff
changeset
|
133 int i, n; |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
134 |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
135 if (get_visualinfo(data->display, screen, &vinfo) < 0) { |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
136 continue; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
137 } |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
138 |
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
|
139 mode.format = X11_GetPixelFormatFromVisualInfo(data->display, &vinfo); |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
140 mode.w = DisplayWidth(data->display, screen); |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
141 mode.h = DisplayHeight(data->display, screen); |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
142 mode.refresh_rate = 0; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
143 mode.driverdata = NULL; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
144 |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
145 displaydata = (SDL_DisplayData *) SDL_malloc(sizeof(*displaydata)); |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
146 if (!displaydata) { |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
147 continue; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
148 } |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
149 displaydata->screen = screen; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
150 displaydata->visual = vinfo.visual; |
1951
7177581dc9fa
Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
151 displaydata->depth = vinfo.depth; |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 |
2920 | 153 displaydata->scanline_pad = SDL_BYTESPERPIXEL(mode.format) * 8; |
2916
ffdd533f7add
Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents:
2906
diff
changeset
|
154 pixmapFormats = XListPixmapFormats(data->display, &n); |
ffdd533f7add
Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents:
2906
diff
changeset
|
155 if (pixmapFormats) { |
ffdd533f7add
Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents:
2906
diff
changeset
|
156 for (i = 0; i < n; ++i) { |
ffdd533f7add
Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents:
2906
diff
changeset
|
157 if (pixmapFormats[i].depth == displaydata->depth) { |
ffdd533f7add
Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents:
2906
diff
changeset
|
158 displaydata->scanline_pad = pixmapFormats[i].scanline_pad; |
ffdd533f7add
Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents:
2906
diff
changeset
|
159 break; |
ffdd533f7add
Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents:
2906
diff
changeset
|
160 } |
ffdd533f7add
Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents:
2906
diff
changeset
|
161 } |
ffdd533f7add
Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents:
2906
diff
changeset
|
162 XFree(pixmapFormats); |
ffdd533f7add
Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents:
2906
diff
changeset
|
163 } |
ffdd533f7add
Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents:
2906
diff
changeset
|
164 |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
165 SDL_zero(display); |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
166 display.desktop_mode = mode; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
167 display.current_mode = mode; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
168 display.driverdata = displaydata; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
169 SDL_AddVideoDisplay(&display); |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
170 } |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
171 } |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
172 |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
173 /* Global for the error handler */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
174 int vm_event, vm_error = -1; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
175 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
176 #if SDL_VIDEO_DRIVER_X11_XINERAMA |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
177 static SDL_bool |
2874 | 178 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
|
179 { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
180 const char *env; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
181 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
182 /* Default the extension not available */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
183 *major = *minor = 0; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
184 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
185 /* Allow environment override */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
186 env = getenv("SDL_VIDEO_X11_XINERAMA"); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
187 if (env && !SDL_atoi(env)) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
188 return SDL_FALSE; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
189 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
190 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
191 /* Query the extension version */ |
2874 | 192 if (!SDL_NAME(XineramaQueryExtension) (display, major, minor) || |
193 !SDL_NAME(XineramaIsActive) (display)) { | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
194 return SDL_FALSE; |
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 return SDL_TRUE; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
197 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
198 #endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
199 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
200 #if SDL_VIDEO_DRIVER_X11_XRANDR |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
201 static SDL_bool |
2874 | 202 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
|
203 { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
204 const char *env; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
205 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
206 /* Default the extension not available */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
207 *major = *minor = 0; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
208 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
209 /* Allow environment override */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
210 env = getenv("SDL_VIDEO_X11_XRANDR"); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
211 if (env && !SDL_atoi(env)) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
212 return SDL_FALSE; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
213 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
214 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
215 if (!SDL_X11_HAVE_XRANDR) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
216 return SDL_FALSE; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
217 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
218 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
219 /* Query the extension version */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
220 if (!XRRQueryVersion(display, major, minor)) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
221 return SDL_FALSE; |
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 return SDL_TRUE; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
224 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
225 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
226 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
227 #if SDL_VIDEO_DRIVER_X11_VIDMODE |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
228 static SDL_bool |
2874 | 229 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
|
230 { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
231 const char *env; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
232 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
233 /* Default the extension not available */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
234 *major = *minor = 0; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
235 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
236 /* Allow environment override */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
237 env = getenv("SDL_VIDEO_X11_VIDMODE"); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
238 if (env && !SDL_atoi(env)) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
239 return SDL_FALSE; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
240 } |
2874 | 241 |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
242 /* Query the extension version */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
243 vm_error = -1; |
2874 | 244 if (!SDL_NAME(XF86VidModeQueryExtension) (display, &vm_event, &vm_error) |
245 || !SDL_NAME(XF86VidModeQueryVersion) (display, major, minor)) { | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
246 return SDL_FALSE; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
247 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
248 return SDL_TRUE; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
249 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
250 |
2874 | 251 Bool SDL_NAME(XF86VidModeGetModeInfo) (Display * dpy, int scr, |
252 SDL_NAME(XF86VidModeModeInfo) * info) | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
253 { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
254 Bool retval; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
255 int dotclock; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
256 SDL_NAME(XF86VidModeModeLine) l; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
257 SDL_zerop(info); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
258 SDL_zero(l); |
2874 | 259 retval = SDL_NAME(XF86VidModeGetModeLine) (dpy, scr, &dotclock, &l); |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
260 info->dotclock = dotclock; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
261 info->hdisplay = l.hdisplay; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
262 info->hsyncstart = l.hsyncstart; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
263 info->hsyncend = l.hsyncend; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
264 info->htotal = l.htotal; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
265 info->hskew = l.hskew; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
266 info->vdisplay = l.vdisplay; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
267 info->vsyncstart = l.vsyncstart; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
268 info->vsyncend = l.vsyncend; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
269 info->vtotal = l.vtotal; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
270 info->flags = l.flags; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
271 info->privsize = l.privsize; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
272 info->private = l.private; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
273 return retval; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
274 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
275 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
276 static int |
2874 | 277 calculate_rate(SDL_NAME(XF86VidModeModeInfo) * info) |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
278 { |
2874 | 279 return (info->htotal |
280 && info->vtotal) ? (1000 * info->dotclock / (info->htotal * | |
281 info->vtotal)) : 0; | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
282 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
283 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
284 static void |
2874 | 285 save_mode(Display * display, SDL_DisplayData * data) |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
286 { |
2874 | 287 SDL_NAME(XF86VidModeGetModeInfo) (display, data->screen, |
288 &data->saved_mode); | |
289 SDL_NAME(XF86VidModeGetViewPort) (display, data->screen, | |
290 &data->saved_view.x, | |
291 &data->saved_view.y); | |
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 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
294 static void |
2874 | 295 restore_mode(Display * display, SDL_DisplayData * data) |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
296 { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
297 SDL_NAME(XF86VidModeModeInfo) mode; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
298 |
2874 | 299 if (SDL_NAME(XF86VidModeGetModeInfo) (display, data->screen, &mode)) { |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
300 if (SDL_memcmp(&mode, &data->saved_mode, sizeof(mode)) != 0) { |
2874 | 301 SDL_NAME(XF86VidModeSwitchToMode) (display, data->screen, |
302 &data->saved_mode); | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
303 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
304 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
305 if ((data->saved_view.x != 0) || (data->saved_view.y != 0)) { |
2874 | 306 SDL_NAME(XF86VidModeSetViewPort) (display, data->screen, |
307 data->saved_view.x, | |
308 data->saved_view.y); | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
309 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
310 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
311 #endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
312 |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
313 void |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
314 X11_GetDisplayModes(_THIS) |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
315 { |
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
|
316 Display *display = ((SDL_VideoData *) _this->driverdata)->display; |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
317 SDL_DisplayData *data = (SDL_DisplayData *) SDL_CurrentDisplay.driverdata; |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
318 #if SDL_VIDEO_DRIVER_X11_XINERAMA |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
319 int xinerama_major, xinerama_minor; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
320 int screens; |
2874 | 321 SDL_NAME(XineramaScreenInfo) * xinerama; |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
322 #endif |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
323 #if SDL_VIDEO_DRIVER_X11_XRANDR |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
324 int xrandr_major, xrandr_minor; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
325 int nsizes, nrates; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
326 XRRScreenSize *sizes; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
327 short *rates; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
328 #endif |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
329 #if SDL_VIDEO_DRIVER_X11_VIDMODE |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
330 int vm_major, vm_minor; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
331 int nmodes; |
2874 | 332 SDL_NAME(XF86VidModeModeInfo) ** modes; |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
333 #endif |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
334 int screen_w; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
335 int screen_h; |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
336 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
|
337 |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
338 /* 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
|
339 * 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
|
340 * 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
|
341 * 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
|
342 * (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
|
343 */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
344 mode.format = SDL_CurrentDisplay.current_mode.format; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
345 mode.driverdata = NULL; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
346 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
347 data->use_xinerama = 0; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
348 data->use_xrandr = 0; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
349 data->use_vidmode = 0; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
350 screen_w = DisplayWidth(display, data->screen); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
351 screen_h = DisplayHeight(display, data->screen); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
352 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
353 #if SDL_VIDEO_DRIVER_X11_XINERAMA |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
354 /* Query Xinerama extention */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
355 if (CheckXinerama(display, &xinerama_major, &xinerama_minor)) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
356 #ifdef X11MODES_DEBUG |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
357 printf("X11 detected Xinerama:\n"); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
358 #endif |
2874 | 359 xinerama = SDL_NAME(XineramaQueryScreens) (display, &screens); |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
360 if (xinerama) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
361 int i; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
362 for (i = 0; i < screens; i++) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
363 #ifdef X11MODES_DEBUG |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
364 printf("xinerama %d: %dx%d+%d+%d\n", |
2874 | 365 xinerama[i].screen_number, |
366 xinerama[i].width, xinerama[i].height, | |
367 xinerama[i].x_org, xinerama[i].y_org); | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
368 #endif |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
369 if (xinerama[i].screen_number == data->screen) { |
2874 | 370 data->use_xinerama = |
371 xinerama_major * 100 + xinerama_minor; | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
372 data->xinerama_info = xinerama[i]; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
373 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
374 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
375 XFree(xinerama); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
376 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
377 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
378 if (data->use_xinerama) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
379 /* Add the full xinerama mode */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
380 if (screen_w > data->xinerama_info.width || |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
381 screen_h > data->xinerama_info.height) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
382 mode.w = screen_w; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
383 mode.h = screen_h; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
384 mode.refresh_rate = 0; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
385 SDL_AddDisplayMode(_this->current_display, &mode); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
386 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
387 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
388 /* Add the head xinerama mode */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
389 mode.w = data->xinerama_info.width; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
390 mode.h = data->xinerama_info.height; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
391 mode.refresh_rate = 0; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
392 SDL_AddDisplayMode(_this->current_display, &mode); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
393 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
394 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
395 #endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
396 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
397 #if SDL_VIDEO_DRIVER_X11_XRANDR |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
398 /* XRandR */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
399 /* require at least XRandR v1.0 (arbitrary) */ |
2874 | 400 if (CheckXRandR(display, &xrandr_major, &xrandr_minor) |
401 && xrandr_major >= 1) { | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
402 #ifdef X11MODES_DEBUG |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
403 fprintf(stderr, "XRANDR: XRRQueryVersion: V%d.%d\n", |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
404 xrandr_major, xrandr_minor); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
405 #endif |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
406 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
407 /* save the screen configuration since we must reference it |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
408 each time we toggle modes. |
2874 | 409 */ |
410 data->screen_config = | |
411 XRRGetScreenInfo(display, RootWindow(display, data->screen)); | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
412 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
413 /* retrieve the list of resolution */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
414 sizes = XRRConfigSizes(data->screen_config, &nsizes); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
415 if (nsizes > 0) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
416 int i, j; |
2874 | 417 for (i = 0; i < nsizes; i++) { |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
418 mode.w = sizes[i].width; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
419 mode.h = sizes[i].height; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
420 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
421 rates = XRRConfigRates(data->screen_config, i, &nrates); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
422 for (j = 0; j < nrates; ++j) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
423 mode.refresh_rate = rates[j]; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
424 #ifdef X11MODES_DEBUG |
2874 | 425 fprintf(stderr, |
426 "XRANDR: mode = %4d[%d], w = %4d, h = %4d, rate = %4d\n", | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
427 i, j, mode.w, mode.h, mode.refresh_rate); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
428 #endif |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
429 SDL_AddDisplayMode(_this->current_display, &mode); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
430 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
431 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
432 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
433 data->use_xrandr = xrandr_major * 100 + xrandr_minor; |
2874 | 434 data->saved_size = |
435 XRRConfigCurrentConfiguration(data->screen_config, | |
436 &data->saved_rotation); | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
437 data->saved_rate = XRRConfigCurrentRate(data->screen_config); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
438 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
439 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
440 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
441 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
442 #if SDL_VIDEO_DRIVER_X11_VIDMODE |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
443 /* XVidMode */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
444 if (!data->use_xrandr && |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
445 #if SDL_VIDEO_DRIVER_X11_XINERAMA |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
446 (!data->use_xinerama || data->xinerama_info.screen_number == 0) && |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
447 #endif |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
448 CheckVidMode(display, &vm_major, &vm_minor) && |
2874 | 449 SDL_NAME(XF86VidModeGetAllModeLines) (display, data->screen, &nmodes, |
450 &modes)) { | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
451 int i; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
452 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
453 #ifdef X11MODES_DEBUG |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
454 printf("VidMode modes: (unsorted)\n"); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
455 for (i = 0; i < nmodes; ++i) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
456 printf("Mode %d: %d x %d @ %d\n", i, |
2874 | 457 modes[i]->hdisplay, modes[i]->vdisplay, |
458 calculate_rate(modes[i])); | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
459 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
460 #endif |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
461 for (i = 0; i < nmodes; ++i) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
462 mode.w = modes[i]->hdisplay; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
463 mode.h = modes[i]->vdisplay; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
464 mode.refresh_rate = calculate_rate(modes[i]); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
465 SDL_AddDisplayMode(_this->current_display, &mode); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
466 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
467 XFree(modes); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
468 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
469 data->use_vidmode = vm_major * 100 + vm_minor; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
470 save_mode(display, data); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
471 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
472 #endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
473 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
474 if (!data->use_xrandr && !data->use_vidmode) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
475 mode.w = screen_w; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
476 mode.h = screen_h; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
477 mode.refresh_rate = 0; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
478 SDL_AddDisplayMode(_this->current_display, &mode); |
2874 | 479 } |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
480 #ifdef X11MODES_DEBUG |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
481 if (data->use_xinerama) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
482 printf("Xinerama is enabled\n"); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
483 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
484 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
485 if (data->use_xrandr) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
486 printf("XRandR is enabled\n"); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
487 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
488 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
489 if (data->use_vidmode) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
490 printf("VidMode is enabled\n"); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
491 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
492 #endif /* X11MODES_DEBUG */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
493 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
494 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
495 static void |
2874 | 496 get_real_resolution(Display * display, SDL_DisplayData * data, int *w, int *h, |
497 int *rate) | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
498 { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
499 #if SDL_VIDEO_DRIVER_X11_XRANDR |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
500 if (data->use_xrandr) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
501 int nsizes; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
502 XRRScreenSize *sizes; |
2874 | 503 |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
504 sizes = XRRConfigSizes(data->screen_config, &nsizes); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
505 if (nsizes > 0) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
506 int cur_size; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
507 Rotation cur_rotation; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
508 |
2874 | 509 cur_size = |
510 XRRConfigCurrentConfiguration(data->screen_config, | |
511 &cur_rotation); | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
512 *w = sizes[cur_size].width; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
513 *h = sizes[cur_size].height; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
514 *rate = XRRConfigCurrentRate(data->screen_config); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
515 #ifdef X11MODES_DEBUG |
2874 | 516 fprintf(stderr, |
517 "XRANDR: get_real_resolution: w = %d, h = %d, rate = %d\n", | |
518 *w, *h, *rate); | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
519 #endif |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
520 return; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
521 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
522 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
523 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
524 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
525 #if SDL_VIDEO_DRIVER_X11_VIDMODE |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
526 if (data->use_vidmode) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
527 SDL_NAME(XF86VidModeModeInfo) mode; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
528 |
2874 | 529 if (SDL_NAME(XF86VidModeGetModeInfo) (display, data->screen, &mode)) { |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
530 *w = mode.hdisplay; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
531 *h = mode.vdisplay; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
532 *rate = calculate_rate(&mode); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
533 return; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
534 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
535 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
536 #endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
537 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
538 #if SDL_VIDEO_DRIVER_X11_XINERAMA |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
539 if (data->use_xinerama) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
540 *w = data->xinerama_info.width; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
541 *h = data->xinerama_info.height; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
542 *rate = 0; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
543 return; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
544 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
545 #endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
546 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
547 *w = DisplayWidth(display, data->screen); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
548 *h = DisplayHeight(display, data->screen); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
549 *rate = 0; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
550 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
551 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
552 static void |
2874 | 553 set_best_resolution(Display * display, SDL_DisplayData * data, int w, int h, |
554 int rate) | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
555 { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
556 int real_w, real_h, real_rate; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
557 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
558 /* check current mode so we can avoid uneccessary mode changes */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
559 get_real_resolution(display, data, &real_w, &real_h, &real_rate); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
560 if (w == real_w && h == real_h && (!rate || rate == real_rate)) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
561 return; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
562 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
563 #if SDL_VIDEO_DRIVER_X11_XRANDR |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
564 if (data->use_xrandr) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
565 #ifdef X11MODES_DEBUG |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
566 fprintf(stderr, "XRANDR: set_best_resolution(): w = %d, h = %d\n", |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
567 w, h); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
568 #endif |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
569 int i, nsizes, nrates; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
570 int best; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
571 int best_rate; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
572 XRRScreenSize *sizes; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
573 short *rates; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
574 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
575 /* find the smallest resolution that is at least as big as the user requested */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
576 best = -1; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
577 sizes = XRRConfigSizes(data->screen_config, &nsizes); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
578 for (i = 0; i < nsizes; ++i) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
579 if (sizes[i].width < w || sizes[i].height < h) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
580 continue; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
581 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
582 if (sizes[i].width == w && sizes[i].height == h) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
583 best = i; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
584 break; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
585 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
586 if (best == -1 || |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
587 (sizes[i].width < sizes[best].width) || |
2874 | 588 (sizes[i].width == sizes[best].width |
589 && sizes[i].height < sizes[best].height)) { | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
590 best = i; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
591 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
592 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
593 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
594 if (best >= 0) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
595 best_rate = 0; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
596 rates = XRRConfigRates(data->screen_config, best, &nrates); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
597 for (i = 0; i < nrates; ++i) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
598 if (rates[i] == rate) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
599 best_rate = rate; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
600 break; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
601 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
602 if (!rate) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
603 /* Higher is better, right? */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
604 if (rates[i] > best_rate) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
605 best_rate = rates[i]; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
606 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
607 } else { |
2874 | 608 if (SDL_abs(rates[i] - rate) < SDL_abs(best_rate - rate)) { |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
609 best_rate = rates[i]; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
610 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
611 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
612 } |
2874 | 613 XRRSetScreenConfigAndRate(display, data->screen_config, |
614 RootWindow(display, data->screen), best, | |
615 data->saved_rotation, best_rate, | |
616 CurrentTime); | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
617 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
618 return; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
619 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
620 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
621 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
622 #if SDL_VIDEO_DRIVER_X11_VIDMODE |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
623 if (data->use_vidmode) { |
2874 | 624 SDL_NAME(XF86VidModeModeInfo) ** modes; |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
625 int i, nmodes; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
626 int best; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
627 |
2874 | 628 if (SDL_NAME(XF86VidModeGetAllModeLines) |
629 (display, data->screen, &nmodes, &modes)) { | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
630 best = -1; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
631 for (i = 0; i < nmodes; ++i) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
632 if (modes[i]->hdisplay < w || modes[i]->vdisplay < h) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
633 continue; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
634 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
635 if (best == -1 || |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
636 (modes[i]->hdisplay < modes[best]->hdisplay) || |
2874 | 637 (modes[i]->hdisplay == modes[best]->hdisplay |
638 && modes[i]->vdisplay < modes[best]->vdisplay)) { | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
639 best = i; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
640 continue; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
641 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
642 if ((modes[i]->hdisplay == modes[best]->hdisplay) && |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
643 (modes[i]->vdisplay == modes[best]->vdisplay)) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
644 if (!rate) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
645 /* Higher is better, right? */ |
2874 | 646 if (calculate_rate(modes[i]) > |
647 calculate_rate(modes[best])) { | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
648 best = i; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
649 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
650 } else { |
2874 | 651 if (SDL_abs(calculate_rate(modes[i]) - rate) < |
652 SDL_abs(calculate_rate(modes[best]) - rate)) { | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
653 best = i; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
654 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
655 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
656 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
657 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
658 if (best >= 0) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
659 #ifdef X11MODES_DEBUG |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
660 printf("Best Mode %d: %d x %d @ %d\n", best, |
2874 | 661 modes[best]->hdisplay, modes[best]->vdisplay, |
662 calculate_rate(modes[best])); | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
663 #endif |
2874 | 664 SDL_NAME(XF86VidModeSwitchToMode) (display, data->screen, |
665 modes[best]); | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
666 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
667 XFree(modes); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
668 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
669 return; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
670 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
671 #endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */ |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
672 } |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
673 |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
674 int |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
675 X11_SetDisplayMode(_THIS, SDL_DisplayMode * mode) |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
676 { |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
677 Display *display = ((SDL_VideoData *) _this->driverdata)->display; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
678 SDL_DisplayData *data = (SDL_DisplayData *) SDL_CurrentDisplay.driverdata; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
679 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
680 set_best_resolution(display, data, mode->w, mode->h, mode->refresh_rate); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
681 return 0; |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
682 } |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
683 |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
684 void |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
685 X11_QuitModes(_THIS) |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
686 { |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
687 } |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
688 |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
689 /* vi: set ts=4 sw=4 expandtab: */ |