Mercurial > sdl-ios-xcode
annotate src/video/x11/SDL_x11modes.c @ 227:24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 03 Nov 2001 17:03:16 +0000 |
parents | a1c973c35fef |
children | 275a934573a7 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga | |
4 | |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
20 slouken@devolution.com | |
21 */ | |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 /* Utilities for getting and setting the X display mode */ | |
29 | |
30 #include <stdlib.h> | |
31 #include <string.h> | |
32 | |
33 #include "SDL_timer.h" | |
34 #include "SDL_error.h" | |
35 #include "SDL_events.h" | |
36 #include "SDL_events_c.h" | |
37 #include "SDL_x11video.h" | |
38 #include "SDL_x11wm_c.h" | |
39 #include "SDL_x11modes_c.h" | |
88
71774090f286
Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
40 #include "SDL_x11image_c.h" |
0 | 41 |
227
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
42 #ifdef HAVE_XINERAMA |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
43 #include <X11/extensions/Xinerama.h> |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
44 #endif |
0 | 45 |
46 #ifdef XFREE86_VM | |
47 Bool XVidMode(GetModeInfo, (Display *dpy, int scr, XF86VidModeModeInfo *info)) | |
48 { | |
49 XF86VidModeModeLine *l = (XF86VidModeModeLine*)((char*)info + sizeof info->dotclock); | |
50 return XVidMode(GetModeLine, (dpy, scr, &info->dotclock, l)); | |
51 } | |
52 #endif /* XFREE86_VM */ | |
53 | |
54 #ifdef XFREE86_VM | |
55 static void save_mode(_THIS) | |
56 { | |
57 memset(&saved_mode, 0, sizeof(saved_mode)); | |
58 XVidMode(GetModeInfo, (SDL_Display,SDL_Screen,&saved_mode)); | |
59 XVidMode(GetViewPort, (SDL_Display,SDL_Screen,&saved_view.x,&saved_view.y)); | |
60 } | |
61 #endif | |
62 | |
63 #ifdef XFREE86_VM | |
64 static void restore_mode(_THIS) | |
65 { | |
66 XF86VidModeModeLine mode; | |
67 int unused; | |
68 | |
69 if ( XVidMode(GetModeLine, (SDL_Display, SDL_Screen, &unused, &mode)) ) { | |
70 if ( (saved_mode.hdisplay != mode.hdisplay) || | |
71 (saved_mode.vdisplay != mode.vdisplay) ) { | |
72 XVidMode(SwitchToMode, (SDL_Display, SDL_Screen, &saved_mode)); | |
73 } | |
74 } | |
75 if ( (saved_view.x != 0) || (saved_view.y != 0) ) { | |
76 XVidMode(SetViewPort, (SDL_Display, SDL_Screen, saved_view.x, saved_view.y)); | |
77 } | |
78 } | |
79 #endif | |
80 | |
81 #ifdef XFREE86_VM | |
82 static int cmpmodes(const void *va, const void *vb) | |
83 { | |
91
e85e03f195b4
From: "Markus F.X.J. Oberhumer"
Sam Lantinga <slouken@lokigames.com>
parents:
90
diff
changeset
|
84 const XF86VidModeModeInfo *a = *(const XF86VidModeModeInfo**)va; |
e85e03f195b4
From: "Markus F.X.J. Oberhumer"
Sam Lantinga <slouken@lokigames.com>
parents:
90
diff
changeset
|
85 const XF86VidModeModeInfo *b = *(const XF86VidModeModeInfo**)vb; |
0 | 86 if(a->hdisplay > b->hdisplay) |
87 return -1; | |
88 return b->vdisplay - a->vdisplay; | |
89 } | |
90 #endif | |
91 | |
92 static void set_best_resolution(_THIS, int width, int height) | |
93 { | |
94 #ifdef XFREE86_VM | |
95 if ( use_vidmode ) { | |
96 XF86VidModeModeLine mode; | |
97 XF86VidModeModeInfo **modes; | |
98 int i; | |
99 int nmodes; | |
100 | |
101 if ( XVidMode(GetModeLine, (SDL_Display, SDL_Screen, &i, &mode)) && | |
102 XVidMode(GetAllModeLines, (SDL_Display,SDL_Screen,&nmodes,&modes))){ | |
103 qsort(modes, nmodes, sizeof *modes, cmpmodes); | |
104 #ifdef XFREE86_DEBUG | |
227
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
105 printf("Available modes:\n"); |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
106 for ( i = 0; i < nmodes; ++i ) { |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
107 printf("Mode %d: %dx%d\n", i, |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
108 modes[i]->hdisplay, modes[i]->vdisplay); |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
109 } |
0 | 110 #endif |
111 for ( i = nmodes-1; i > 0 ; --i ) { | |
112 if ( (modes[i]->hdisplay >= width) && | |
113 (modes[i]->vdisplay >= height) ) | |
114 break; | |
115 } | |
116 if ( (modes[i]->hdisplay != mode.hdisplay) || | |
117 (modes[i]->vdisplay != mode.vdisplay) ) { | |
118 XVidMode(SwitchToMode, (SDL_Display, SDL_Screen, modes[i])); | |
119 } | |
120 XFree(modes); | |
121 } | |
122 } | |
123 #endif /* XFREE86_VM */ | |
124 } | |
125 | |
126 static void get_real_resolution(_THIS, int* w, int* h) | |
127 { | |
128 #ifdef XFREE86_VM | |
129 if ( use_vidmode ) { | |
130 XF86VidModeModeLine mode; | |
131 int unused; | |
132 | |
133 if ( XVidMode(GetModeLine, (SDL_Display, SDL_Screen, &unused, &mode)) ) { | |
134 *w = mode.hdisplay; | |
135 *h = mode.vdisplay; | |
136 return; | |
137 } | |
138 } | |
139 #endif | |
140 *w = DisplayWidth(SDL_Display, SDL_Screen); | |
141 *h = DisplayHeight(SDL_Display, SDL_Screen); | |
142 } | |
143 | |
144 /* Called after mapping a window - waits until the window is mapped */ | |
145 void X11_WaitMapped(_THIS, Window win) | |
146 { | |
147 XEvent event; | |
148 do { | |
149 XMaskEvent(SDL_Display, StructureNotifyMask, &event); | |
150 } while ( (event.type != MapNotify) || (event.xmap.event != win) ); | |
151 } | |
152 | |
153 /* Called after unmapping a window - waits until the window is unmapped */ | |
154 void X11_WaitUnmapped(_THIS, Window win) | |
155 { | |
156 XEvent event; | |
157 do { | |
158 XMaskEvent(SDL_Display, StructureNotifyMask, &event); | |
159 } while ( (event.type != UnmapNotify) || (event.xunmap.event != win) ); | |
160 } | |
161 | |
162 static void move_cursor_to(_THIS, int x, int y) | |
163 { | |
164 XWarpPointer(SDL_Display, None, SDL_Root, 0, 0, 0, 0, x, y); | |
165 } | |
166 | |
167 static int add_visual(_THIS, int depth, int class) | |
168 { | |
169 XVisualInfo vi; | |
170 if(XMatchVisualInfo(SDL_Display, SDL_Screen, depth, class, &vi)) { | |
171 int n = this->hidden->nvisuals; | |
172 this->hidden->visuals[n].depth = vi.depth; | |
173 this->hidden->visuals[n].visual = vi.visual; | |
174 this->hidden->nvisuals++; | |
175 } | |
176 return(this->hidden->nvisuals); | |
177 } | |
178 static int add_visual_byid(_THIS, const char *visual_id) | |
179 { | |
180 XVisualInfo *vi, template; | |
181 int nvis; | |
182 | |
183 if ( visual_id ) { | |
184 memset(&template, 0, (sizeof template)); | |
185 template.visualid = strtol(visual_id, NULL, 0); | |
186 vi = XGetVisualInfo(SDL_Display, VisualIDMask, &template, &nvis); | |
187 if ( vi ) { | |
188 int n = this->hidden->nvisuals; | |
189 this->hidden->visuals[n].depth = vi->depth; | |
190 this->hidden->visuals[n].visual = vi->visual; | |
191 this->hidden->nvisuals++; | |
192 XFree(vi); | |
193 } | |
194 } | |
195 return(this->hidden->nvisuals); | |
196 } | |
197 | |
198 /* Global for the error handler */ | |
199 int vm_event, vm_error = -1; | |
200 | |
201 int X11_GetVideoModes(_THIS) | |
202 { | |
203 #ifdef XFREE86_VM | |
204 int buggy_X11; | |
205 int vm_major, vm_minor; | |
206 int nmodes; | |
207 XF86VidModeModeInfo **modes; | |
208 #endif | |
209 int i; | |
210 | |
211 vm_error = -1; | |
212 use_vidmode = 0; | |
213 #ifdef XFREE86_VM | |
214 /* Metro-X 4.3.0 and earlier has a broken implementation of | |
215 XF86VidModeGetAllModeLines() - it hangs the client. | |
216 */ | |
217 buggy_X11 = 0; | |
218 if ( strcmp(ServerVendor(SDL_Display), "Metro Link Incorporated") == 0 ) { | |
219 FILE *metro_fp; | |
220 | |
221 metro_fp = fopen("/usr/X11R6/lib/X11/Metro/.version", "r"); | |
222 if ( metro_fp != NULL ) { | |
223 int major, minor, patch, version; | |
224 major = 0; minor = 0; patch = 0; | |
225 fscanf(metro_fp, "%d.%d.%d", &major, &minor, &patch); | |
226 version = major*100+minor*10+patch; | |
227 if ( version < 431 ) { | |
228 buggy_X11 = 1; | |
229 } | |
230 fclose(metro_fp); | |
231 } | |
232 } | |
233 #if defined(__alpha__) || defined(__powerpc__) | |
234 /* The alpha and PPC XFree86 servers are also buggy */ | |
235 buggy_X11 = 1; | |
236 #endif | |
237 /* Enumerate the available fullscreen modes */ | |
238 if ( ! buggy_X11 ) { | |
239 if ( XVidMode(QueryExtension, (SDL_Display, &vm_event, &vm_error)) && | |
240 XVidMode(QueryVersion, (SDL_Display, &vm_major, &vm_minor)) ) { | |
241 #ifdef BROKEN_XFREE86_4001 | |
242 #ifdef X_XF86VidModeGetDotClocks /* Compiled under XFree86 4.0 */ | |
243 /* Earlier X servers hang when doing vidmode */ | |
244 if ( vm_major < 2 ) { | |
227
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
245 #ifdef XFREE86_DEBUG |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
246 printf("Compiled under XFree86 4.0, server is XFree86 3.X\n"); |
0 | 247 #endif |
248 buggy_X11 = 1; | |
249 } | |
250 #else | |
251 /* XFree86 3.X code works with XFree86 4.0 servers */; | |
252 #endif /* XFree86 4.0 */ | |
253 #endif /* XFree86 4.02 and newer are fixed wrt backwards compatibility */ | |
254 } else { | |
255 buggy_X11 = 1; | |
256 } | |
257 } | |
258 if ( ! buggy_X11 && | |
259 XVidMode(GetAllModeLines, (SDL_Display, SDL_Screen,&nmodes,&modes)) ) { | |
260 | |
261 qsort(modes, nmodes, sizeof *modes, cmpmodes); | |
262 SDL_modelist = (SDL_Rect **)malloc((nmodes+1)*sizeof(SDL_Rect *)); | |
263 if ( SDL_modelist ) { | |
264 for ( i=0; i<nmodes; ++i ) { | |
265 SDL_modelist[i] = (SDL_Rect *)malloc(sizeof(SDL_Rect)); | |
266 if ( SDL_modelist[i] == NULL ) { | |
267 break; | |
268 } | |
269 SDL_modelist[i]->x = 0; | |
270 SDL_modelist[i]->y = 0; | |
271 SDL_modelist[i]->w = modes[i]->hdisplay; | |
272 SDL_modelist[i]->h = modes[i]->vdisplay; | |
273 } | |
274 SDL_modelist[i] = NULL; | |
275 } | |
276 XFree(modes); | |
277 | |
100
a1c973c35fef
Fixed using the video mode extension on older servers
Sam Lantinga <slouken@lokigames.com>
parents:
98
diff
changeset
|
278 use_vidmode = vm_major * 100 + vm_minor; |
0 | 279 save_mode(this); |
280 } | |
281 #endif /* XFREE86_VM */ | |
282 | |
283 { | |
284 static int depth_list[] = { 32, 24, 16, 15, 8 }; | |
285 int j, np; | |
286 int use_directcolor = 1; | |
287 XPixmapFormatValues *pf; | |
288 | |
289 /* Search for the visuals in deepest-first order, so that the first | |
290 will be the richest one */ | |
291 if ( getenv("SDL_VIDEO_X11_NODIRECTCOLOR") ) { | |
292 use_directcolor = 0; | |
293 } | |
294 this->hidden->nvisuals = 0; | |
295 if ( ! add_visual_byid(this, getenv("SDL_VIDEO_X11_VISUALID")) ) { | |
296 for ( i=0; i<SDL_TABLESIZE(depth_list); ++i ) { | |
297 if ( depth_list[i] > 8 ) { | |
298 if ( use_directcolor ) { | |
299 add_visual(this, depth_list[i], DirectColor); | |
300 } | |
301 add_visual(this, depth_list[i], TrueColor); | |
302 } else { | |
303 add_visual(this, depth_list[i], PseudoColor); | |
304 add_visual(this, depth_list[i], StaticColor); | |
305 } | |
306 } | |
307 } | |
308 if ( this->hidden->nvisuals == 0 ) { | |
309 SDL_SetError("Found no sufficiently capable X11 visuals"); | |
310 return -1; | |
311 } | |
312 | |
313 /* look up the pixel quantum for each depth */ | |
314 pf = XListPixmapFormats(SDL_Display, &np); | |
315 for(i = 0; i < this->hidden->nvisuals; i++) { | |
316 int d = this->hidden->visuals[i].depth; | |
317 for(j = 0; j < np; j++) | |
318 if(pf[j].depth == d) | |
319 break; | |
320 this->hidden->visuals[i].bpp = j < np ? pf[j].bits_per_pixel : d; | |
321 } | |
322 | |
323 XFree(pf); | |
324 } | |
325 | |
326 if ( SDL_modelist == NULL ) { | |
327 SDL_modelist = (SDL_Rect **)malloc((1+1)*sizeof(SDL_Rect *)); | |
328 i = 0; | |
329 if ( SDL_modelist ) { | |
330 SDL_modelist[i] = (SDL_Rect *)malloc(sizeof(SDL_Rect)); | |
331 if ( SDL_modelist[i] ) { | |
332 SDL_modelist[i]->x = 0; | |
333 SDL_modelist[i]->y = 0; | |
334 SDL_modelist[i]->w = DisplayWidth(SDL_Display, SDL_Screen); | |
335 SDL_modelist[i]->h = DisplayHeight(SDL_Display, SDL_Screen); | |
336 ++i; | |
337 } | |
338 SDL_modelist[i] = NULL; | |
339 } | |
340 } | |
341 | |
227
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
342 #ifdef XFREE86_DEBUG |
0 | 343 if ( use_vidmode ) { |
227
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
344 printf("XFree86 VidMode is enabled\n"); |
0 | 345 } |
346 if ( SDL_modelist ) { | |
227
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
347 printf("X11 video mode list:\n"); |
0 | 348 for ( i=0; SDL_modelist[i]; ++i ) { |
227
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
349 printf("\t%dx%d\n", SDL_modelist[i]->w, SDL_modelist[i]->h); |
0 | 350 } |
351 } | |
227
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
352 #endif /* XFREE86_DEBUG */ |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
353 |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
354 /* The default X/Y fullscreen offset is 0/0 */ |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
355 xinerama_x = 0; |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
356 xinerama_y = 0; |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
357 |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
358 #ifdef HAVE_XINERAMA |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
359 /* Query Xinerama extention */ |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
360 if ( XineramaQueryExtension(SDL_Display, &i, &i) && |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
361 XineramaIsActive(SDL_Display) ) { |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
362 /* Find out which screen is the zero'th one */ |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
363 int screens; |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
364 XineramaScreenInfo *xinerama; |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
365 |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
366 #ifdef XINERAMA_DEBUG |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
367 printf("X11 detected Xinerama:\n"); |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
368 #endif |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
369 xinerama = XineramaQueryScreens(SDL_Display, &screens); |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
370 for ( i = 0; i < screens; i++ ) { |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
371 #ifdef XINERAMA_DEBUG |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
372 printf("xinerama %d: %dx%d+%d+%d\n", |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
373 xinerama[i].screen_number, |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
374 xinerama[i].width, xinerama[i].height, |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
375 xinerama[i].x_org, xinerama[i].y_org); |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
376 #endif |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
377 if ( xinerama[i].screen_number == 0 ) { |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
378 xinerama_x = xinerama[i].x_org; |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
379 xinerama_y = xinerama[i].y_org; |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
380 } |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
381 } |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
382 XFree(xinerama); |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
383 } |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
384 #endif /* HAVE_XINERAMA */ |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
385 |
0 | 386 return 0; |
387 } | |
388 | |
389 int X11_SupportedVisual(_THIS, SDL_PixelFormat *format) | |
390 { | |
391 int i; | |
392 for(i = 0; i < this->hidden->nvisuals; i++) | |
393 if(this->hidden->visuals[i].bpp == format->BitsPerPixel) | |
394 return 1; | |
395 return 0; | |
396 } | |
397 | |
398 SDL_Rect **X11_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) | |
399 { | |
400 if ( X11_SupportedVisual(this, format) ) { | |
401 if ( flags & SDL_FULLSCREEN ) { | |
402 return(SDL_modelist); | |
403 } else { | |
404 return((SDL_Rect **)-1); | |
405 } | |
406 } else { | |
407 return((SDL_Rect **)0); | |
408 } | |
409 } | |
410 | |
411 void X11_FreeVideoModes(_THIS) | |
412 { | |
413 int i; | |
414 | |
415 if ( SDL_modelist ) { | |
416 for ( i=0; SDL_modelist[i]; ++i ) { | |
417 free(SDL_modelist[i]); | |
418 } | |
419 free(SDL_modelist); | |
420 SDL_modelist = NULL; | |
421 } | |
422 } | |
423 | |
424 int X11_ResizeFullScreen(_THIS) | |
425 { | |
426 int x, y; | |
427 int real_w, real_h; | |
428 | |
227
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
429 x = xinerama_x; |
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
430 y = xinerama_y; |
0 | 431 if ( currently_fullscreen ) { |
432 /* Switch resolution and cover it with the FSwindow */ | |
227
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
433 move_cursor_to(this, x, y); |
0 | 434 set_best_resolution(this, current_w, current_h); |
227
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
435 move_cursor_to(this, x, y); |
0 | 436 get_real_resolution(this, &real_w, &real_h); |
227
24878c14b391
Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents:
100
diff
changeset
|
437 XMoveResizeWindow(SDL_Display, FSwindow, x, y, real_w, real_h); |
0 | 438 move_cursor_to(this, real_w/2, real_h/2); |
439 | |
440 /* Center and reparent the drawing window */ | |
441 x = (real_w - current_w)/2; | |
442 y = (real_h - current_h)/2; | |
443 XReparentWindow(SDL_Display, SDL_Window, FSwindow, x, y); | |
444 /* FIXME: move the mouse to the old relative location */ | |
445 XSync(SDL_Display, True); /* Flush spurious mode change events */ | |
446 } | |
447 return(1); | |
448 } | |
449 | |
450 void X11_QueueEnterFullScreen(_THIS) | |
451 { | |
452 switch_waiting = 0x01 | SDL_FULLSCREEN; | |
453 switch_time = SDL_GetTicks() + 1500; | |
454 #if 0 /* This causes a BadMatch error if the window is iconified (not needed) */ | |
455 XSetInputFocus(SDL_Display, WMwindow, RevertToNone, CurrentTime); | |
456 #endif | |
457 } | |
458 | |
459 int X11_EnterFullScreen(_THIS) | |
460 { | |
461 int okay; | |
462 #if 0 | |
463 Window tmpwin, *windows; | |
464 int i, nwindows; | |
465 #endif | |
98
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
466 int real_w, real_h; |
0 | 467 |
468 okay = 1; | |
98
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
469 if ( currently_fullscreen ) { |
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
470 return(okay); |
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
471 } |
0 | 472 |
98
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
473 /* Ungrab the input so that we can move the mouse around */ |
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
474 X11_GrabInputNoLock(this, SDL_GRAB_OFF); |
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
475 |
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
476 /* Map the fullscreen window to blank the screen */ |
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
477 get_real_resolution(this, &real_w, &real_h); |
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
478 XMoveResizeWindow(SDL_Display, FSwindow, 0, 0, real_w, real_h); |
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
479 XMapRaised(SDL_Display, FSwindow); |
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
480 X11_WaitMapped(this, FSwindow); |
0 | 481 |
482 #if 0 /* This seems to break WindowMaker in focus-follows-mouse mode */ | |
98
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
483 /* Make sure we got to the top of the window stack */ |
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
484 if ( XQueryTree(SDL_Display, SDL_Root, &tmpwin, &tmpwin, |
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
485 &windows, &nwindows) && windows ) { |
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
486 /* If not, try to put us there - if fail... oh well */ |
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
487 if ( windows[nwindows-1] != FSwindow ) { |
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
488 tmpwin = windows[nwindows-1]; |
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
489 for ( i=0; i<nwindows; ++i ) { |
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
490 if ( windows[i] == FSwindow ) { |
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
491 memcpy(&windows[i], &windows[i+1], |
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
492 (nwindows-i-1)*sizeof(windows[i])); |
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
493 break; |
0 | 494 } |
495 } | |
98
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
496 windows[nwindows-1] = FSwindow; |
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
497 XRestackWindows(SDL_Display, windows, nwindows); |
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
498 XSync(SDL_Display, False); |
0 | 499 } |
98
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
500 XFree(windows); |
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
501 } |
0 | 502 #else |
98
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
503 XRaiseWindow(SDL_Display, FSwindow); |
0 | 504 #endif |
505 | |
506 #ifdef XFREE86_VM | |
98
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
507 /* Save the current video mode */ |
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
508 if ( use_vidmode ) { |
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
509 XVidMode(LockModeSwitch, (SDL_Display, SDL_Screen, True)); |
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
510 } |
0 | 511 #endif |
98
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
512 currently_fullscreen = 1; |
0 | 513 |
98
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
514 /* Set the new resolution */ |
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
515 okay = X11_ResizeFullScreen(this); |
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
516 if ( ! okay ) { |
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
517 X11_LeaveFullScreen(this); |
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
518 } |
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
519 /* Set the colormap */ |
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
520 if ( SDL_XColorMap ) { |
8a5aff5c1294
Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
521 XInstallColormap(SDL_Display, SDL_XColorMap); |
0 | 522 } |
88
71774090f286
Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
523 if ( okay ) |
71774090f286
Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
524 X11_GrabInputNoLock(this, this->input_grab | SDL_GRAB_FULLSCREEN); |
71774090f286
Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
525 |
71774090f286
Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
526 /* We may need to refresh the screen at this point (no backing store) |
71774090f286
Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
527 We also don't get an event, which is why we explicitly refresh. */ |
71774090f286
Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
528 if ( this->screen ) { |
71774090f286
Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
529 if ( this->screen->flags & SDL_OPENGL ) { |
71774090f286
Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
530 SDL_PrivateExpose(); |
71774090f286
Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
531 } else { |
71774090f286
Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
532 X11_RefreshDisplay(this); |
71774090f286
Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
533 } |
71774090f286
Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
534 } |
71774090f286
Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
535 |
0 | 536 return(okay); |
537 } | |
538 | |
539 int X11_LeaveFullScreen(_THIS) | |
540 { | |
541 if ( currently_fullscreen ) { | |
542 XReparentWindow(SDL_Display, SDL_Window, WMwindow, 0, 0); | |
543 #ifdef XFREE86_VM | |
544 if ( use_vidmode ) { | |
545 restore_mode(this); | |
546 XVidMode(LockModeSwitch, (SDL_Display, SDL_Screen, False)); | |
547 } | |
548 #endif | |
549 XUnmapWindow(SDL_Display, FSwindow); | |
550 X11_WaitUnmapped(this, FSwindow); | |
551 XSync(SDL_Display, True); /* Flush spurious mode change events */ | |
552 currently_fullscreen = 0; | |
553 } | |
554 /* If we get popped out of fullscreen mode for some reason, input_grab | |
555 will still have the SDL_GRAB_FULLSCREEN flag set, since this is only | |
556 temporary. In this case, release the grab unless the input has been | |
557 explicitly grabbed. | |
558 */ | |
559 X11_GrabInputNoLock(this, this->input_grab & ~SDL_GRAB_FULLSCREEN); | |
88
71774090f286
Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
560 |
71774090f286
Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
561 /* We may need to refresh the screen at this point (no backing store) |
71774090f286
Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
562 We also don't get an event, which is why we explicitly refresh. */ |
71774090f286
Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
563 if ( this->screen ) { |
71774090f286
Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
564 if ( this->screen->flags & SDL_OPENGL ) { |
71774090f286
Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
565 SDL_PrivateExpose(); |
71774090f286
Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
566 } else { |
71774090f286
Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
567 X11_RefreshDisplay(this); |
71774090f286
Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
568 } |
71774090f286
Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
569 } |
71774090f286
Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
570 |
0 | 571 return(0); |
572 } |