Mercurial > sdl-ios-xcode
annotate src/video/x11/SDL_x11modes.c @ 5284:96a22141cf86 tip
Changed output directory of Universal libSDL.a for iOS to respect build configurations. Template generator was updated to reflect these changes as well.
author | Eric Wing <ewing . public |-at-| gmail . com> |
---|---|
date | Sat, 12 Feb 2011 21:52:30 -0800 |
parents | b530ef003506 |
children |
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 |
5267 | 3 Copyright (C) 1997-2011 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 |
4519 | 26 /*#define X11MODES_DEBUG*/ |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 static int |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 get_visualinfo(Display * display, int screen, XVisualInfo * vinfo) |
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 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
|
32 int depth; |
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 /* Look for an exact visual, if requested */ |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
35 if (visual_id) { |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
36 XVisualInfo *vi, template; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
37 int nvis; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
38 |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
39 SDL_zero(template); |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
40 template.visualid = SDL_strtol(visual_id, NULL, 0); |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
41 vi = XGetVisualInfo(display, VisualIDMask, &template, &nvis); |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
42 if (vi) { |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
43 *vinfo = *vi; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 XFree(vi); |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 return 0; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
46 } |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
47 } |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
48 |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
49 depth = DefaultDepth(display, screen); |
5248
3a8a452b49f0
Removed gamma support since it wasn't widely used and not well supported.
Sam Lantinga <slouken@libsdl.org>
parents:
5185
diff
changeset
|
50 if (XMatchVisualInfo(display, screen, depth, TrueColor, vinfo) || |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
51 XMatchVisualInfo(display, screen, depth, PseudoColor, vinfo) || |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
52 XMatchVisualInfo(display, screen, depth, StaticColor, vinfo)) { |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
53 return 0; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 } |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
55 return -1; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
56 } |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
57 |
5185
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
58 int |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
59 X11_GetVisualInfoFromVisual(Display * display, Visual * visual, XVisualInfo * vinfo) |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
60 { |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
61 XVisualInfo *vi; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
62 int nvis; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
63 |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
64 vinfo->visualid = XVisualIDFromVisual(visual); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
65 vi = XGetVisualInfo(display, VisualIDMask, vinfo, &nvis); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
66 if (vi) { |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
67 *vinfo = *vi; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
68 XFree(vi); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
69 return 0; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
70 } |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
71 return -1; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
72 } |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
73 |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
74 Uint32 |
2874 | 75 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
|
76 { |
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 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
|
78 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
|
79 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
|
80 |
b801df19835f
The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
81 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
|
82 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
|
83 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
|
84 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
|
85 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
|
86 } 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
|
87 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
|
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 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
|
91 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
|
92 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
|
93 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
|
94 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
|
95 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
|
96 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
|
97 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
|
98 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
|
99 } |
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 } |
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 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
|
102 } |
b801df19835f
The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
103 } |
b801df19835f
The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
104 |
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_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
|
106 } |
b801df19835f
The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
107 |
b801df19835f
The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
108 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
|
109 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
|
110 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
|
111 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
|
112 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
|
113 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
|
114 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
|
115 } 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
|
116 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
|
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 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
|
119 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
|
120 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
|
121 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
|
122 } 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
|
123 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
|
124 } |
b801df19835f
The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
125 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
|
126 } |
b801df19835f
The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
127 } |
b801df19835f
The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
128 |
b801df19835f
The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
129 return SDL_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
|
130 } |
b801df19835f
The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
131 |
3521
76f9b76ddf0f
Don't add any renderers if you can't add any displays
Sam Lantinga <slouken@libsdl.org>
parents:
3500
diff
changeset
|
132 int |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
133 X11_InitModes(_THIS) |
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 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
136 int screen; |
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 for (screen = 0; screen < ScreenCount(data->display); ++screen) { |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
139 XVisualInfo vinfo; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
140 SDL_VideoDisplay display; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
141 SDL_DisplayData *displaydata; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
142 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
|
143 XPixmapFormatValues *pixmapFormats; |
ffdd533f7add
Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents:
2906
diff
changeset
|
144 int i, n; |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
145 |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
146 if (get_visualinfo(data->display, screen, &vinfo) < 0) { |
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 |
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
|
150 mode.format = X11_GetPixelFormatFromVisualInfo(data->display, &vinfo); |
5152
be02be2ea897
Making the API simpler, removed support for palettized video modes and textures.
Sam Lantinga <slouken@libsdl.org>
parents:
4618
diff
changeset
|
151 if (SDL_ISPIXELFORMAT_INDEXED(mode.format)) { |
be02be2ea897
Making the API simpler, removed support for palettized video modes and textures.
Sam Lantinga <slouken@libsdl.org>
parents:
4618
diff
changeset
|
152 /* We don't support palettized modes now */ |
be02be2ea897
Making the API simpler, removed support for palettized video modes and textures.
Sam Lantinga <slouken@libsdl.org>
parents:
4618
diff
changeset
|
153 continue; |
be02be2ea897
Making the API simpler, removed support for palettized video modes and textures.
Sam Lantinga <slouken@libsdl.org>
parents:
4618
diff
changeset
|
154 } |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
155 mode.w = DisplayWidth(data->display, screen); |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
156 mode.h = DisplayHeight(data->display, screen); |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
157 mode.refresh_rate = 0; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
158 mode.driverdata = NULL; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
159 |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
160 displaydata = (SDL_DisplayData *) SDL_malloc(sizeof(*displaydata)); |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
161 if (!displaydata) { |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
162 continue; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
163 } |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
164 displaydata->screen = screen; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
165 displaydata->visual = vinfo.visual; |
1951
7177581dc9fa
Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
166 displaydata->depth = vinfo.depth; |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
167 |
2920 | 168 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
|
169 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
|
170 if (pixmapFormats) { |
ffdd533f7add
Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents:
2906
diff
changeset
|
171 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
|
172 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
|
173 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
|
174 break; |
ffdd533f7add
Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents:
2906
diff
changeset
|
175 } |
ffdd533f7add
Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents:
2906
diff
changeset
|
176 } |
ffdd533f7add
Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents:
2906
diff
changeset
|
177 XFree(pixmapFormats); |
ffdd533f7add
Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents:
2906
diff
changeset
|
178 } |
ffdd533f7add
Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents:
2906
diff
changeset
|
179 |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
180 SDL_zero(display); |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
181 display.desktop_mode = mode; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
182 display.current_mode = mode; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
183 display.driverdata = displaydata; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
184 SDL_AddVideoDisplay(&display); |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
185 } |
3521
76f9b76ddf0f
Don't add any renderers if you can't add any displays
Sam Lantinga <slouken@libsdl.org>
parents:
3500
diff
changeset
|
186 if (_this->num_displays == 0) { |
76f9b76ddf0f
Don't add any renderers if you can't add any displays
Sam Lantinga <slouken@libsdl.org>
parents:
3500
diff
changeset
|
187 SDL_SetError("No available displays"); |
76f9b76ddf0f
Don't add any renderers if you can't add any displays
Sam Lantinga <slouken@libsdl.org>
parents:
3500
diff
changeset
|
188 return -1; |
76f9b76ddf0f
Don't add any renderers if you can't add any displays
Sam Lantinga <slouken@libsdl.org>
parents:
3500
diff
changeset
|
189 } |
76f9b76ddf0f
Don't add any renderers if you can't add any displays
Sam Lantinga <slouken@libsdl.org>
parents:
3500
diff
changeset
|
190 return 0; |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
191 } |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
192 |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
193 /* Global for the error handler */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
194 int vm_event, vm_error = -1; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
195 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
196 #if SDL_VIDEO_DRIVER_X11_XINERAMA |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
197 static SDL_bool |
2874 | 198 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
|
199 { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
200 const char *env; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
201 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
202 /* Default the extension not available */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
203 *major = *minor = 0; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
204 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
205 /* Allow environment override */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
206 env = getenv("SDL_VIDEO_X11_XINERAMA"); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
207 if (env && !SDL_atoi(env)) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
208 return SDL_FALSE; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
209 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
210 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
211 /* Query the extension version */ |
2874 | 212 if (!SDL_NAME(XineramaQueryExtension) (display, major, minor) || |
213 !SDL_NAME(XineramaIsActive) (display)) { | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
214 return SDL_FALSE; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
215 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
216 return SDL_TRUE; |
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 #endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
219 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
220 #if SDL_VIDEO_DRIVER_X11_XRANDR |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
221 static SDL_bool |
2874 | 222 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
|
223 { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
224 const char *env; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
225 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
226 /* Default the extension not available */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
227 *major = *minor = 0; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
228 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
229 /* Allow environment override */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
230 env = getenv("SDL_VIDEO_X11_XRANDR"); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
231 if (env && !SDL_atoi(env)) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
232 return SDL_FALSE; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
233 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
234 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
235 if (!SDL_X11_HAVE_XRANDR) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
236 return SDL_FALSE; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
237 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
238 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
239 /* Query the extension version */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
240 if (!XRRQueryVersion(display, major, minor)) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
241 return SDL_FALSE; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
242 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
243 return SDL_TRUE; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
244 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
245 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
246 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
247 #if SDL_VIDEO_DRIVER_X11_VIDMODE |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
248 static SDL_bool |
2874 | 249 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
|
250 { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
251 const char *env; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
252 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
253 /* Default the extension not available */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
254 *major = *minor = 0; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
255 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
256 /* Allow environment override */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
257 env = getenv("SDL_VIDEO_X11_VIDMODE"); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
258 if (env && !SDL_atoi(env)) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
259 return SDL_FALSE; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
260 } |
2874 | 261 |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
262 /* Query the extension version */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
263 vm_error = -1; |
2874 | 264 if (!SDL_NAME(XF86VidModeQueryExtension) (display, &vm_event, &vm_error) |
265 || !SDL_NAME(XF86VidModeQueryVersion) (display, major, minor)) { | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
266 return SDL_FALSE; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
267 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
268 return SDL_TRUE; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
269 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
270 |
4518
a956a315fe67
Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
271 static |
2874 | 272 Bool SDL_NAME(XF86VidModeGetModeInfo) (Display * dpy, int scr, |
273 SDL_NAME(XF86VidModeModeInfo) * info) | |
2873
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 Bool retval; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
276 int dotclock; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
277 SDL_NAME(XF86VidModeModeLine) l; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
278 SDL_zerop(info); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
279 SDL_zero(l); |
2874 | 280 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
|
281 info->dotclock = dotclock; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
282 info->hdisplay = l.hdisplay; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
283 info->hsyncstart = l.hsyncstart; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
284 info->hsyncend = l.hsyncend; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
285 info->htotal = l.htotal; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
286 info->hskew = l.hskew; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
287 info->vdisplay = l.vdisplay; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
288 info->vsyncstart = l.vsyncstart; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
289 info->vsyncend = l.vsyncend; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
290 info->vtotal = l.vtotal; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
291 info->flags = l.flags; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
292 info->privsize = l.privsize; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
293 info->private = l.private; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
294 return retval; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
295 } |
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 static int |
2874 | 298 calculate_rate(SDL_NAME(XF86VidModeModeInfo) * info) |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
299 { |
2874 | 300 return (info->htotal |
301 && info->vtotal) ? (1000 * info->dotclock / (info->htotal * | |
302 info->vtotal)) : 0; | |
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 static void |
2874 | 306 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
|
307 { |
2874 | 308 SDL_NAME(XF86VidModeGetModeInfo) (display, data->screen, |
309 &data->saved_mode); | |
310 SDL_NAME(XF86VidModeGetViewPort) (display, data->screen, | |
311 &data->saved_view.x, | |
312 &data->saved_view.y); | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
313 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
314 |
4518
a956a315fe67
Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
315 /* |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
316 static void |
2874 | 317 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
|
318 { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
319 SDL_NAME(XF86VidModeModeInfo) mode; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
320 |
2874 | 321 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
|
322 if (SDL_memcmp(&mode, &data->saved_mode, sizeof(mode)) != 0) { |
2874 | 323 SDL_NAME(XF86VidModeSwitchToMode) (display, data->screen, |
324 &data->saved_mode); | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
325 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
326 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
327 if ((data->saved_view.x != 0) || (data->saved_view.y != 0)) { |
2874 | 328 SDL_NAME(XF86VidModeSetViewPort) (display, data->screen, |
329 data->saved_view.x, | |
330 data->saved_view.y); | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
331 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
332 } |
4518
a956a315fe67
Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
333 */ |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
334 #endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
335 |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
336 void |
3500
4b594623401b
Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents:
2963
diff
changeset
|
337 X11_GetDisplayModes(_THIS, SDL_VideoDisplay * sdl_display) |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
338 { |
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
|
339 Display *display = ((SDL_VideoData *) _this->driverdata)->display; |
3500
4b594623401b
Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents:
2963
diff
changeset
|
340 SDL_DisplayData *data = (SDL_DisplayData *) sdl_display->driverdata; |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
341 #if SDL_VIDEO_DRIVER_X11_XINERAMA |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
342 int xinerama_major, xinerama_minor; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
343 int screens; |
2874 | 344 SDL_NAME(XineramaScreenInfo) * xinerama; |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
345 #endif |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
346 #if SDL_VIDEO_DRIVER_X11_XRANDR |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
347 int xrandr_major, xrandr_minor; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
348 int nsizes, nrates; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
349 XRRScreenSize *sizes; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
350 short *rates; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
351 #endif |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
352 #if SDL_VIDEO_DRIVER_X11_VIDMODE |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
353 int vm_major, vm_minor; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
354 int nmodes; |
2874 | 355 SDL_NAME(XF86VidModeModeInfo) ** modes; |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
356 #endif |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
357 int screen_w; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
358 int screen_h; |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
359 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
|
360 |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
361 /* 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
|
362 * 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
|
363 * 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
|
364 * 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
|
365 * (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
|
366 */ |
3500
4b594623401b
Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents:
2963
diff
changeset
|
367 mode.format = sdl_display->current_mode.format; |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
368 mode.driverdata = NULL; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
369 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
370 data->use_xinerama = 0; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
371 data->use_xrandr = 0; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
372 data->use_vidmode = 0; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
373 screen_w = DisplayWidth(display, data->screen); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
374 screen_h = DisplayHeight(display, data->screen); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
375 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
376 #if SDL_VIDEO_DRIVER_X11_XINERAMA |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
377 /* Query Xinerama extention */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
378 if (CheckXinerama(display, &xinerama_major, &xinerama_minor)) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
379 #ifdef X11MODES_DEBUG |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
380 printf("X11 detected Xinerama:\n"); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
381 #endif |
2874 | 382 xinerama = SDL_NAME(XineramaQueryScreens) (display, &screens); |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
383 if (xinerama) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
384 int i; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
385 for (i = 0; i < screens; i++) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
386 #ifdef X11MODES_DEBUG |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
387 printf("xinerama %d: %dx%d+%d+%d\n", |
2874 | 388 xinerama[i].screen_number, |
389 xinerama[i].width, xinerama[i].height, | |
390 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
|
391 #endif |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
392 if (xinerama[i].screen_number == data->screen) { |
2874 | 393 data->use_xinerama = |
394 xinerama_major * 100 + xinerama_minor; | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
395 data->xinerama_info = xinerama[i]; |
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 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
398 XFree(xinerama); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
399 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
400 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
401 if (data->use_xinerama) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
402 /* Add the full xinerama mode */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
403 if (screen_w > data->xinerama_info.width || |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
404 screen_h > data->xinerama_info.height) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
405 mode.w = screen_w; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
406 mode.h = screen_h; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
407 mode.refresh_rate = 0; |
3500
4b594623401b
Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents:
2963
diff
changeset
|
408 SDL_AddDisplayMode(sdl_display, &mode); |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
409 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
410 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
411 /* Add the head xinerama mode */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
412 mode.w = data->xinerama_info.width; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
413 mode.h = data->xinerama_info.height; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
414 mode.refresh_rate = 0; |
3500
4b594623401b
Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents:
2963
diff
changeset
|
415 SDL_AddDisplayMode(sdl_display, &mode); |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
416 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
417 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
418 #endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
419 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
420 #if SDL_VIDEO_DRIVER_X11_XRANDR |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
421 /* XRandR */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
422 /* require at least XRandR v1.0 (arbitrary) */ |
2874 | 423 if (CheckXRandR(display, &xrandr_major, &xrandr_minor) |
424 && xrandr_major >= 1) { | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
425 #ifdef X11MODES_DEBUG |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
426 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
|
427 xrandr_major, xrandr_minor); |
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 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
430 /* 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
|
431 each time we toggle modes. |
2874 | 432 */ |
433 data->screen_config = | |
434 XRRGetScreenInfo(display, RootWindow(display, data->screen)); | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
435 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
436 /* retrieve the list of resolution */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
437 sizes = XRRConfigSizes(data->screen_config, &nsizes); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
438 if (nsizes > 0) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
439 int i, j; |
2874 | 440 for (i = 0; i < nsizes; i++) { |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
441 mode.w = sizes[i].width; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
442 mode.h = sizes[i].height; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
443 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
444 rates = XRRConfigRates(data->screen_config, i, &nrates); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
445 for (j = 0; j < nrates; ++j) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
446 mode.refresh_rate = rates[j]; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
447 #ifdef X11MODES_DEBUG |
2874 | 448 fprintf(stderr, |
449 "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
|
450 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
|
451 #endif |
3500
4b594623401b
Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents:
2963
diff
changeset
|
452 SDL_AddDisplayMode(sdl_display, &mode); |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
453 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
454 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
455 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
456 data->use_xrandr = xrandr_major * 100 + xrandr_minor; |
2874 | 457 data->saved_size = |
458 XRRConfigCurrentConfiguration(data->screen_config, | |
459 &data->saved_rotation); | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
460 data->saved_rate = XRRConfigCurrentRate(data->screen_config); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
461 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
462 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
463 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
464 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
465 #if SDL_VIDEO_DRIVER_X11_VIDMODE |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
466 /* XVidMode */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
467 if (!data->use_xrandr && |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
468 #if SDL_VIDEO_DRIVER_X11_XINERAMA |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
469 (!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
|
470 #endif |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
471 CheckVidMode(display, &vm_major, &vm_minor) && |
2874 | 472 SDL_NAME(XF86VidModeGetAllModeLines) (display, data->screen, &nmodes, |
473 &modes)) { | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
474 int i; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
475 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
476 #ifdef X11MODES_DEBUG |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
477 printf("VidMode modes: (unsorted)\n"); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
478 for (i = 0; i < nmodes; ++i) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
479 printf("Mode %d: %d x %d @ %d\n", i, |
2874 | 480 modes[i]->hdisplay, modes[i]->vdisplay, |
481 calculate_rate(modes[i])); | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
482 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
483 #endif |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
484 for (i = 0; i < nmodes; ++i) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
485 mode.w = modes[i]->hdisplay; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
486 mode.h = modes[i]->vdisplay; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
487 mode.refresh_rate = calculate_rate(modes[i]); |
3500
4b594623401b
Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents:
2963
diff
changeset
|
488 SDL_AddDisplayMode(sdl_display, &mode); |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
489 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
490 XFree(modes); |
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 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
|
493 save_mode(display, data); |
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 #endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
496 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
497 if (!data->use_xrandr && !data->use_vidmode) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
498 mode.w = screen_w; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
499 mode.h = screen_h; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
500 mode.refresh_rate = 0; |
3500
4b594623401b
Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents:
2963
diff
changeset
|
501 SDL_AddDisplayMode(sdl_display, &mode); |
2874 | 502 } |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
503 #ifdef X11MODES_DEBUG |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
504 if (data->use_xinerama) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
505 printf("Xinerama is enabled\n"); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
506 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
507 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
508 if (data->use_xrandr) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
509 printf("XRandR is enabled\n"); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
510 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
511 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
512 if (data->use_vidmode) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
513 printf("VidMode is enabled\n"); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
514 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
515 #endif /* X11MODES_DEBUG */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
516 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
517 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
518 static void |
2874 | 519 get_real_resolution(Display * display, SDL_DisplayData * data, int *w, int *h, |
520 int *rate) | |
2873
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 #if SDL_VIDEO_DRIVER_X11_XRANDR |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
523 if (data->use_xrandr) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
524 int nsizes; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
525 XRRScreenSize *sizes; |
2874 | 526 |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
527 sizes = XRRConfigSizes(data->screen_config, &nsizes); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
528 if (nsizes > 0) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
529 int cur_size; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
530 Rotation cur_rotation; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
531 |
2874 | 532 cur_size = |
533 XRRConfigCurrentConfiguration(data->screen_config, | |
534 &cur_rotation); | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
535 *w = sizes[cur_size].width; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
536 *h = sizes[cur_size].height; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
537 *rate = XRRConfigCurrentRate(data->screen_config); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
538 #ifdef X11MODES_DEBUG |
2874 | 539 fprintf(stderr, |
540 "XRANDR: get_real_resolution: w = %d, h = %d, rate = %d\n", | |
541 *w, *h, *rate); | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
542 #endif |
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 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
546 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
547 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
548 #if SDL_VIDEO_DRIVER_X11_VIDMODE |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
549 if (data->use_vidmode) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
550 SDL_NAME(XF86VidModeModeInfo) mode; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
551 |
2874 | 552 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
|
553 *w = mode.hdisplay; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
554 *h = mode.vdisplay; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
555 *rate = calculate_rate(&mode); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
556 return; |
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 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
559 #endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
560 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
561 #if SDL_VIDEO_DRIVER_X11_XINERAMA |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
562 if (data->use_xinerama) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
563 *w = data->xinerama_info.width; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
564 *h = data->xinerama_info.height; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
565 *rate = 0; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
566 return; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
567 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
568 #endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
569 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
570 *w = DisplayWidth(display, data->screen); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
571 *h = DisplayHeight(display, data->screen); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
572 *rate = 0; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
573 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
574 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
575 static void |
2874 | 576 set_best_resolution(Display * display, SDL_DisplayData * data, int w, int h, |
577 int rate) | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
578 { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
579 int real_w, real_h, real_rate; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
580 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
581 /* 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
|
582 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
|
583 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
|
584 return; |
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 SDL_VIDEO_DRIVER_X11_XRANDR |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
587 if (data->use_xrandr) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
588 #ifdef X11MODES_DEBUG |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
589 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
|
590 w, h); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
591 #endif |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
592 int i, nsizes, nrates; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
593 int best; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
594 int best_rate; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
595 XRRScreenSize *sizes; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
596 short *rates; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
597 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
598 /* 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
|
599 best = -1; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
600 sizes = XRRConfigSizes(data->screen_config, &nsizes); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
601 for (i = 0; i < nsizes; ++i) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
602 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
|
603 continue; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
604 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
605 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
|
606 best = i; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
607 break; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
608 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
609 if (best == -1 || |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
610 (sizes[i].width < sizes[best].width) || |
2874 | 611 (sizes[i].width == sizes[best].width |
612 && sizes[i].height < sizes[best].height)) { | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
613 best = i; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
614 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
615 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
616 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
617 if (best >= 0) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
618 best_rate = 0; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
619 rates = XRRConfigRates(data->screen_config, best, &nrates); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
620 for (i = 0; i < nrates; ++i) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
621 if (rates[i] == rate) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
622 best_rate = rate; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
623 break; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
624 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
625 if (!rate) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
626 /* Higher is better, right? */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
627 if (rates[i] > best_rate) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
628 best_rate = rates[i]; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
629 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
630 } else { |
2874 | 631 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
|
632 best_rate = rates[i]; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
633 } |
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 } |
2874 | 636 XRRSetScreenConfigAndRate(display, data->screen_config, |
637 RootWindow(display, data->screen), best, | |
638 data->saved_rotation, best_rate, | |
639 CurrentTime); | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
640 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
641 return; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
642 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
643 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */ |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
644 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
645 #if SDL_VIDEO_DRIVER_X11_VIDMODE |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
646 if (data->use_vidmode) { |
2874 | 647 SDL_NAME(XF86VidModeModeInfo) ** modes; |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
648 int i, nmodes; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
649 int best; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
650 |
2874 | 651 if (SDL_NAME(XF86VidModeGetAllModeLines) |
652 (display, data->screen, &nmodes, &modes)) { | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
653 best = -1; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
654 for (i = 0; i < nmodes; ++i) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
655 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
|
656 continue; |
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 == -1 || |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
659 (modes[i]->hdisplay < modes[best]->hdisplay) || |
2874 | 660 (modes[i]->hdisplay == modes[best]->hdisplay |
661 && modes[i]->vdisplay < modes[best]->vdisplay)) { | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
662 best = i; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
663 continue; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
664 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
665 if ((modes[i]->hdisplay == modes[best]->hdisplay) && |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
666 (modes[i]->vdisplay == modes[best]->vdisplay)) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
667 if (!rate) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
668 /* Higher is better, right? */ |
2874 | 669 if (calculate_rate(modes[i]) > |
670 calculate_rate(modes[best])) { | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
671 best = i; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
672 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
673 } else { |
2874 | 674 if (SDL_abs(calculate_rate(modes[i]) - rate) < |
675 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
|
676 best = i; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
677 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
678 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
679 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
680 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
681 if (best >= 0) { |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
682 #ifdef X11MODES_DEBUG |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
683 printf("Best Mode %d: %d x %d @ %d\n", best, |
2874 | 684 modes[best]->hdisplay, modes[best]->vdisplay, |
685 calculate_rate(modes[best])); | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
686 #endif |
2874 | 687 SDL_NAME(XF86VidModeSwitchToMode) (display, data->screen, |
688 modes[best]); | |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
689 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
690 XFree(modes); |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
691 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
692 return; |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
693 } |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
694 #endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */ |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
695 } |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
696 |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
697 int |
3500
4b594623401b
Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents:
2963
diff
changeset
|
698 X11_SetDisplayMode(_THIS, SDL_VideoDisplay * sdl_display, SDL_DisplayMode * mode) |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
699 { |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
700 Display *display = ((SDL_VideoData *) _this->driverdata)->display; |
3500
4b594623401b
Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents:
2963
diff
changeset
|
701 SDL_DisplayData *data = (SDL_DisplayData *) sdl_display->driverdata; |
2873
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
702 |
b33e38aaa027
Progress on fullscreen mode switching on X11
Sam Lantinga <slouken@libsdl.org>
parents:
2870
diff
changeset
|
703 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
|
704 return 0; |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
705 } |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
706 |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
707 void |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
708 X11_QuitModes(_THIS) |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
709 { |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
710 } |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
711 |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
712 /* vi: set ts=4 sw=4 expandtab: */ |