Skip to content

Latest commit

 

History

History
987 lines (879 loc) · 32.3 KB

SDL_x11modes.c

File metadata and controls

987 lines (879 loc) · 32.3 KB
 
Apr 26, 2001
Apr 26, 2001
1
2
/*
SDL - Simple DirectMedia Layer
Feb 1, 2006
Feb 1, 2006
3
Copyright (C) 1997-2006 Sam Lantinga
Apr 26, 2001
Apr 26, 2001
4
5
This library is free software; you can redistribute it and/or
Feb 1, 2006
Feb 1, 2006
6
modify it under the terms of the GNU Lesser General Public
Apr 26, 2001
Apr 26, 2001
7
License as published by the Free Software Foundation; either
Feb 1, 2006
Feb 1, 2006
8
version 2.1 of the License, or (at your option) any later version.
Apr 26, 2001
Apr 26, 2001
9
10
11
12
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Feb 1, 2006
Feb 1, 2006
13
Lesser General Public License for more details.
Apr 26, 2001
Apr 26, 2001
14
Feb 1, 2006
Feb 1, 2006
15
16
17
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Apr 26, 2001
Apr 26, 2001
18
19
Sam Lantinga
Dec 14, 2001
Dec 14, 2001
20
slouken@libsdl.org
Apr 26, 2001
Apr 26, 2001
21
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
Apr 26, 2001
Apr 26, 2001
23
24
25
/* Utilities for getting and setting the X display mode */
Feb 7, 2006
Feb 7, 2006
26
#include <stdio.h>
Apr 26, 2001
Apr 26, 2001
27
28
29
#include "SDL_timer.h"
#include "SDL_events.h"
Feb 16, 2006
Feb 16, 2006
30
#include "../../events/SDL_events_c.h"
Apr 26, 2001
Apr 26, 2001
31
32
33
#include "SDL_x11video.h"
#include "SDL_x11wm_c.h"
#include "SDL_x11modes_c.h"
Jul 7, 2001
Jul 7, 2001
34
#include "SDL_x11image_c.h"
Apr 26, 2001
Apr 26, 2001
35
Feb 16, 2006
Feb 16, 2006
36
37
#if SDL_VIDEO_DRIVER_X11_XINERAMA
#include "../Xext/extensions/Xinerama.h"
Nov 3, 2001
Nov 3, 2001
38
#endif
Apr 26, 2001
Apr 26, 2001
39
Sep 30, 2002
Sep 30, 2002
40
#define MAX(a, b) (a > b ? a : b)
Nov 4, 2001
Nov 4, 2001
41
Feb 16, 2006
Feb 16, 2006
42
#if SDL_VIDEO_DRIVER_X11_VIDMODE
Mar 5, 2002
Mar 5, 2002
43
Bool SDL_NAME(XF86VidModeGetModeInfo)(Display *dpy, int scr, SDL_NAME(XF86VidModeModeInfo) *info)
Apr 26, 2001
Apr 26, 2001
44
{
Mar 5, 2002
Mar 5, 2002
45
SDL_NAME(XF86VidModeModeLine) *l = (SDL_NAME(XF86VidModeModeLine)*)((char*)info + sizeof info->dotclock);
Dec 8, 2005
Dec 8, 2005
46
return SDL_NAME(XF86VidModeGetModeLine)(dpy, scr, (int*)&info->dotclock, l);
Apr 26, 2001
Apr 26, 2001
47
}
Feb 16, 2006
Feb 16, 2006
48
#endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */
Apr 26, 2001
Apr 26, 2001
49
Feb 16, 2006
Feb 16, 2006
50
#if SDL_VIDEO_DRIVER_X11_VIDMODE
Apr 26, 2001
Apr 26, 2001
51
52
static void save_mode(_THIS)
{
Feb 7, 2006
Feb 7, 2006
53
SDL_memset(&saved_mode, 0, sizeof(saved_mode));
Mar 5, 2002
Mar 5, 2002
54
55
SDL_NAME(XF86VidModeGetModeInfo)(SDL_Display,SDL_Screen,&saved_mode);
SDL_NAME(XF86VidModeGetViewPort)(SDL_Display,SDL_Screen,&saved_view.x,&saved_view.y);
Apr 26, 2001
Apr 26, 2001
56
57
58
}
#endif
Feb 16, 2006
Feb 16, 2006
59
#if SDL_VIDEO_DRIVER_X11_VIDMODE
Apr 26, 2001
Apr 26, 2001
60
61
static void restore_mode(_THIS)
{
Mar 5, 2002
Mar 5, 2002
62
SDL_NAME(XF86VidModeModeLine) mode;
Apr 26, 2001
Apr 26, 2001
63
64
int unused;
Mar 5, 2002
Mar 5, 2002
65
if ( SDL_NAME(XF86VidModeGetModeLine)(SDL_Display, SDL_Screen, &unused, &mode) ) {
Apr 26, 2001
Apr 26, 2001
66
67
if ( (saved_mode.hdisplay != mode.hdisplay) ||
(saved_mode.vdisplay != mode.vdisplay) ) {
Mar 5, 2002
Mar 5, 2002
68
SDL_NAME(XF86VidModeSwitchToMode)(SDL_Display, SDL_Screen, &saved_mode);
Apr 26, 2001
Apr 26, 2001
69
70
71
}
}
if ( (saved_view.x != 0) || (saved_view.y != 0) ) {
Mar 5, 2002
Mar 5, 2002
72
SDL_NAME(XF86VidModeSetViewPort)(SDL_Display, SDL_Screen, saved_view.x, saved_view.y);
Apr 26, 2001
Apr 26, 2001
73
74
75
76
}
}
#endif
Feb 16, 2006
Feb 16, 2006
77
#if SDL_VIDEO_DRIVER_X11_VIDMODE
Apr 26, 2001
Apr 26, 2001
78
79
static int cmpmodes(const void *va, const void *vb)
{
Mar 5, 2002
Mar 5, 2002
80
81
const SDL_NAME(XF86VidModeModeInfo) *a = *(const SDL_NAME(XF86VidModeModeInfo)**)va;
const SDL_NAME(XF86VidModeModeInfo) *b = *(const SDL_NAME(XF86VidModeModeInfo)**)vb;
Nov 12, 2004
Nov 12, 2004
82
83
84
85
if ( a->hdisplay == b->hdisplay )
return b->vdisplay - a->vdisplay;
else
return b->hdisplay - a->hdisplay;
Apr 26, 2001
Apr 26, 2001
86
87
88
}
#endif
Mar 22, 2006
Mar 22, 2006
89
90
91
92
93
94
95
96
97
98
99
100
#if SDL_VIDEO_DRIVER_X11_XRANDR
static int cmpmodelist(const void *va, const void *vb)
{
const SDL_Rect *a = *(const SDL_Rect **)va;
const SDL_Rect *b = *(const SDL_Rect **)vb;
if ( a->w == b->w )
return b->h - a->h;
else
return b->w - a->w;
}
#endif
Nov 22, 2001
Nov 22, 2001
101
102
static void get_real_resolution(_THIS, int* w, int* h);
Apr 26, 2001
Apr 26, 2001
103
104
static void set_best_resolution(_THIS, int width, int height)
{
Feb 16, 2006
Feb 16, 2006
105
#if SDL_VIDEO_DRIVER_X11_VIDMODE
Apr 26, 2001
Apr 26, 2001
106
if ( use_vidmode ) {
Mar 5, 2002
Mar 5, 2002
107
108
SDL_NAME(XF86VidModeModeLine) mode;
SDL_NAME(XF86VidModeModeInfo) **modes;
Apr 26, 2001
Apr 26, 2001
109
int i;
Jun 28, 2003
Jun 28, 2003
110
int best_width = 0, best_height = 0;
Apr 26, 2001
Apr 26, 2001
111
112
int nmodes;
Mar 5, 2002
Mar 5, 2002
113
if ( SDL_NAME(XF86VidModeGetModeLine)(SDL_Display, SDL_Screen, &i, &mode) &&
Jun 28, 2003
Jun 28, 2003
114
SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display,SDL_Screen,&nmodes,&modes)){
Apr 26, 2001
Apr 26, 2001
115
#ifdef XFREE86_DEBUG
Jun 28, 2003
Jun 28, 2003
116
printf("Available modes (unsorted):\n");
Nov 3, 2001
Nov 3, 2001
117
for ( i = 0; i < nmodes; ++i ) {
Jun 28, 2003
Jun 28, 2003
118
119
120
121
printf("Mode %d: %d x %d @ %d\n", i,
modes[i]->hdisplay, modes[i]->vdisplay,
1000 * modes[i]->dotclock / (modes[i]->htotal *
modes[i]->vtotal) );
Nov 3, 2001
Nov 3, 2001
122
}
Apr 26, 2001
Apr 26, 2001
123
#endif
Jun 28, 2003
Jun 28, 2003
124
for ( i = 0; i < nmodes ; i++ ) {
Mar 6, 2003
Mar 6, 2003
125
if ( (modes[i]->hdisplay == width) &&
Jun 28, 2003
Jun 28, 2003
126
(modes[i]->vdisplay == height) )
Mar 6, 2003
Mar 6, 2003
127
128
goto match;
}
Jun 28, 2003
Jun 28, 2003
129
qsort(modes, nmodes, sizeof *modes, cmpmodes);
Sep 5, 2003
Sep 5, 2003
130
for ( i = nmodes-1; i > 0 ; i-- ) {
Jun 28, 2003
Jun 28, 2003
131
132
133
134
135
136
137
138
139
140
141
142
143
if ( ! best_width ) {
if ( (modes[i]->hdisplay >= width) &&
(modes[i]->vdisplay >= height) ) {
best_width = modes[i]->hdisplay;
best_height = modes[i]->vdisplay;
}
} else {
if ( (modes[i]->hdisplay != best_width) ||
(modes[i]->vdisplay != best_height) ) {
i++;
break;
}
}
Apr 26, 2001
Apr 26, 2001
144
}
Mar 6, 2003
Mar 6, 2003
145
match:
Apr 26, 2001
Apr 26, 2001
146
147
if ( (modes[i]->hdisplay != mode.hdisplay) ||
(modes[i]->vdisplay != mode.vdisplay) ) {
Mar 5, 2002
Mar 5, 2002
148
SDL_NAME(XF86VidModeSwitchToMode)(SDL_Display, SDL_Screen, modes[i]);
Apr 26, 2001
Apr 26, 2001
149
}
Mar 22, 2006
Mar 22, 2006
150
XFree(modes);
Apr 26, 2001
Apr 26, 2001
151
152
}
}
Feb 16, 2006
Feb 16, 2006
153
#endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */
Nov 22, 2001
Nov 22, 2001
154
Sep 30, 2002
Sep 30, 2002
155
/* XiG */
Feb 16, 2006
Feb 16, 2006
156
#if SDL_VIDEO_DRIVER_X11_XME
Nov 22, 2001
Nov 22, 2001
157
158
#ifdef XIG_DEBUG
fprintf(stderr, "XME: set_best_resolution(): w = %d, h = %d\n",
Sep 30, 2002
Sep 30, 2002
159
width, height);
Nov 22, 2001
Nov 22, 2001
160
161
#endif
if ( SDL_modelist ) {
Sep 30, 2002
Sep 30, 2002
162
int i;
Nov 22, 2001
Nov 22, 2001
163
164
for ( i=0; SDL_modelist[i]; ++i ) {
Sep 30, 2002
Sep 30, 2002
165
if ( (SDL_modelist[i]->w >= width) &&
Nov 22, 2001
Nov 22, 2001
166
(SDL_modelist[i]->h >= height) ) {
Sep 30, 2002
Sep 30, 2002
167
168
break;
}
Nov 22, 2001
Nov 22, 2001
169
}
Sep 30, 2002
Sep 30, 2002
170
171
172
if ( SDL_modelist[i] ) { /* found one, lets try it */
int w, h;
Nov 22, 2001
Nov 22, 2001
173
174
/* check current mode so we can avoid uneccessary mode changes */
Sep 30, 2002
Sep 30, 2002
175
get_real_resolution(this, &w, &h);
Nov 22, 2001
Nov 22, 2001
176
Sep 30, 2002
Sep 30, 2002
177
if ( (SDL_modelist[i]->w != w) || (SDL_modelist[i]->h != h) ) {
Nov 22, 2001
Nov 22, 2001
178
# ifdef XIG_DEBUG
Sep 30, 2002
Sep 30, 2002
179
180
181
fprintf(stderr, "XME: set_best_resolution: "
"XiGMiscChangeResolution: %d %d\n",
SDL_modelist[s]->w, SDL_modelist[s]->h);
Nov 22, 2001
Nov 22, 2001
182
# endif
Sep 30, 2002
Sep 30, 2002
183
184
185
186
187
188
XiGMiscChangeResolution(SDL_Display,
SDL_Screen,
0, /* view */
SDL_modelist[i]->w,
SDL_modelist[i]->h,
0);
Mar 22, 2006
Mar 22, 2006
189
XSync(SDL_Display, False);
Nov 22, 2001
Nov 22, 2001
190
191
192
}
}
}
Feb 16, 2006
Feb 16, 2006
193
#endif /* SDL_VIDEO_DRIVER_X11_XME */
Nov 22, 2001
Nov 22, 2001
194
Mar 22, 2006
Mar 22, 2006
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#if SDL_VIDEO_DRIVER_X11_XRANDR
if ( use_xrandr ) {
#ifdef XRANDR_DEBUG
fprintf(stderr, "XRANDR: set_best_resolution(): w = %d, h = %d\n",
width, height);
#endif
if ( SDL_modelist ) {
int i, nsizes;
XRRScreenSize *sizes;
/* find the smallest resolution that is at least as big as the user requested */
sizes = XRRConfigSizes(screen_config, &nsizes);
for ( i = (nsizes-1); i >= 0; i-- ) {
if ( (SDL_modelist[i]->w >= width) &&
(SDL_modelist[i]->h >= height) ) {
break;
}
}
if ( i >= 0 && SDL_modelist[i] ) { /* found one, lets try it */
int w, h;
/* check current mode so we can avoid uneccessary mode changes */
get_real_resolution(this, &w, &h);
if ( (SDL_modelist[i]->w != w) || (SDL_modelist[i]->h != h) ) {
int size_id;
#ifdef XRANDR_DEBUG
fprintf(stderr, "XRANDR: set_best_resolution: "
"XXRSetScreenConfig: %d %d\n",
SDL_modelist[i]->w, SDL_modelist[i]->h);
#endif
/* find the matching size entry index */
for ( size_id = 0; size_id < nsizes; ++size_id ) {
if ( (sizes[size_id].width == SDL_modelist[i]->w) &&
(sizes[size_id].height == SDL_modelist[i]->h) )
break;
}
XRRSetScreenConfig(SDL_Display, screen_config, SDL_Root,
size_id, saved_rotation, CurrentTime);
}
}
}
}
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
Apr 26, 2001
Apr 26, 2001
244
245
246
247
}
static void get_real_resolution(_THIS, int* w, int* h)
{
Feb 16, 2006
Feb 16, 2006
248
#if SDL_VIDEO_DRIVER_X11_VIDMODE
Apr 26, 2001
Apr 26, 2001
249
if ( use_vidmode ) {
Mar 5, 2002
Mar 5, 2002
250
SDL_NAME(XF86VidModeModeLine) mode;
Apr 26, 2001
Apr 26, 2001
251
252
int unused;
Mar 5, 2002
Mar 5, 2002
253
if ( SDL_NAME(XF86VidModeGetModeLine)(SDL_Display, SDL_Screen, &unused, &mode) ) {
Apr 26, 2001
Apr 26, 2001
254
255
256
257
258
*w = mode.hdisplay;
*h = mode.vdisplay;
return;
}
}
Mar 22, 2006
Mar 22, 2006
259
#endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */
Nov 22, 2001
Nov 22, 2001
260
Feb 16, 2006
Feb 16, 2006
261
#if SDL_VIDEO_DRIVER_X11_XME
Nov 22, 2001
Nov 22, 2001
262
263
264
265
266
if ( use_xme ) {
int ractive;
XiGMiscResolutionInfo *modelist;
XiGMiscQueryResolutions(SDL_Display, SDL_Screen,
Sep 30, 2002
Sep 30, 2002
267
268
0, /* view */
&ractive, &modelist);
Nov 22, 2001
Nov 22, 2001
269
270
271
272
273
274
275
276
*w = modelist[ractive].width;
*h = modelist[ractive].height;
#ifdef XIG_DEBUG
fprintf(stderr, "XME: get_real_resolution: w = %d h = %d\n", *w, *h);
#endif
XFree(modelist);
return;
}
Mar 22, 2006
Mar 22, 2006
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#endif /* SDL_VIDEO_DRIVER_X11_XME */
#if SDL_VIDEO_DRIVER_X11_XRANDR
if ( use_xrandr ) {
int nsizes;
XRRScreenSize* sizes;
sizes = XRRConfigSizes(screen_config, &nsizes);
if ( nsizes > 0 ) {
int cur_size;
Rotation cur_rotation;
cur_size = XRRConfigCurrentConfiguration(screen_config, &cur_rotation);
if ( cur_size >= 0 && cur_size < nsizes ) {
*w = sizes[cur_size].width;
*h = sizes[cur_size].height;
}
#ifdef XRANDR_DEBUG
fprintf(stderr, "XRANDR: get_real_resolution: w = %d h = %d\n", *w, *h);
#endif
return;
}
}
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
Nov 22, 2001
Nov 22, 2001
301
Apr 26, 2001
Apr 26, 2001
302
303
304
305
306
307
308
309
310
*w = DisplayWidth(SDL_Display, SDL_Screen);
*h = DisplayHeight(SDL_Display, SDL_Screen);
}
/* Called after mapping a window - waits until the window is mapped */
void X11_WaitMapped(_THIS, Window win)
{
XEvent event;
do {
Mar 22, 2006
Mar 22, 2006
311
XMaskEvent(SDL_Display, StructureNotifyMask, &event);
Apr 26, 2001
Apr 26, 2001
312
313
314
315
316
317
318
319
} while ( (event.type != MapNotify) || (event.xmap.event != win) );
}
/* Called after unmapping a window - waits until the window is unmapped */
void X11_WaitUnmapped(_THIS, Window win)
{
XEvent event;
do {
Mar 22, 2006
Mar 22, 2006
320
XMaskEvent(SDL_Display, StructureNotifyMask, &event);
Apr 26, 2001
Apr 26, 2001
321
322
323
324
325
} while ( (event.type != UnmapNotify) || (event.xunmap.event != win) );
}
static void move_cursor_to(_THIS, int x, int y)
{
Mar 22, 2006
Mar 22, 2006
326
XWarpPointer(SDL_Display, None, SDL_Root, 0, 0, 0, 0, x, y);
Apr 26, 2001
Apr 26, 2001
327
328
329
330
331
}
static int add_visual(_THIS, int depth, int class)
{
XVisualInfo vi;
Mar 22, 2006
Mar 22, 2006
332
if(XMatchVisualInfo(SDL_Display, SDL_Screen, depth, class, &vi)) {
Sep 30, 2002
Sep 30, 2002
333
334
335
336
int n = this->hidden->nvisuals;
this->hidden->visuals[n].depth = vi.depth;
this->hidden->visuals[n].visual = vi.visual;
this->hidden->nvisuals++;
Apr 26, 2001
Apr 26, 2001
337
338
339
340
341
342
343
344
345
}
return(this->hidden->nvisuals);
}
static int add_visual_byid(_THIS, const char *visual_id)
{
XVisualInfo *vi, template;
int nvis;
if ( visual_id ) {
Feb 7, 2006
Feb 7, 2006
346
347
SDL_memset(&template, 0, (sizeof template));
template.visualid = SDL_strtol(visual_id, NULL, 0);
Mar 22, 2006
Mar 22, 2006
348
vi = XGetVisualInfo(SDL_Display, VisualIDMask, &template, &nvis);
Apr 26, 2001
Apr 26, 2001
349
if ( vi ) {
Sep 30, 2002
Sep 30, 2002
350
351
352
353
int n = this->hidden->nvisuals;
this->hidden->visuals[n].depth = vi->depth;
this->hidden->visuals[n].visual = vi->visual;
this->hidden->nvisuals++;
Mar 22, 2006
Mar 22, 2006
354
XFree(vi);
Apr 26, 2001
Apr 26, 2001
355
356
357
358
359
360
361
362
363
364
}
}
return(this->hidden->nvisuals);
}
/* Global for the error handler */
int vm_event, vm_error = -1;
int X11_GetVideoModes(_THIS)
{
Feb 16, 2006
Feb 16, 2006
365
#if SDL_VIDEO_DRIVER_X11_VIDMODE
Apr 26, 2001
Apr 26, 2001
366
367
368
int buggy_X11;
int vm_major, vm_minor;
int nmodes;
Mar 5, 2002
Mar 5, 2002
369
SDL_NAME(XF86VidModeModeInfo) **modes;
Nov 22, 2001
Nov 22, 2001
370
#endif
Feb 16, 2006
Feb 16, 2006
371
#if SDL_VIDEO_DRIVER_X11_XME
Nov 22, 2001
Nov 22, 2001
372
373
374
int xme_major, xme_minor;
int ractive, nummodes;
XiGMiscResolutionInfo *modelist;
Mar 22, 2006
Mar 22, 2006
375
376
377
378
379
#endif
#if SDL_VIDEO_DRIVER_X11_XRANDR
int xrandr_major, xrandr_minor;
int nsizes;
XRRScreenSize *sizes;
Apr 26, 2001
Apr 26, 2001
380
#endif
Nov 4, 2001
Nov 4, 2001
381
382
383
int i, n;
int screen_w;
int screen_h;
Apr 26, 2001
Apr 26, 2001
384
385
386
vm_error = -1;
use_vidmode = 0;
Mar 22, 2006
Mar 22, 2006
387
use_xrandr = 0;
Nov 4, 2001
Nov 4, 2001
388
389
390
screen_w = DisplayWidth(SDL_Display, SDL_Screen);
screen_h = DisplayHeight(SDL_Display, SDL_Screen);
Mar 22, 2006
Mar 22, 2006
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
/* XRandR */
#if SDL_VIDEO_DRIVER_X11_XRANDR
/* require at least XRandR v1.0 (arbitrary) */
if ( ( SDL_X11_HAVE_XRANDR ) &&
( getenv("SDL_VIDEO_X11_NO_XRANDR") == NULL ) &&
( XRRQueryVersion(SDL_Display, &xrandr_major, &xrandr_minor) ) &&
( xrandr_major >= 1 ) ) {
#ifdef XRANDR_DEBUG
fprintf(stderr, "XRANDR: XRRQueryVersion: V%d.%d\n",
xrandr_major, xrandr_minor);
#endif
/* save the screen configuration since we must reference it
each time we toggle modes.
*/
screen_config = XRRGetScreenInfo(SDL_Display, SDL_Root);
/* retrieve the list of resolution */
sizes = XRRConfigSizes(screen_config, &nsizes);
if (nsizes > 0) {
SDL_modelist = (SDL_Rect **)malloc((nsizes+1)*sizeof(SDL_Rect *));
if (SDL_modelist) {
for ( i=0; i < nsizes; i++ ) {
if ((SDL_modelist[i] =
(SDL_Rect *)malloc(sizeof(SDL_Rect))) == NULL)
break;
#ifdef XRANDR_DEBUG
fprintf(stderr, "XRANDR: mode = %4d, w = %4d, h = %4d\n",
i, sizes[i].width, sizes[i].height);
#endif
SDL_modelist[i]->x = 0;
SDL_modelist[i]->y = 0;
SDL_modelist[i]->w = sizes[i].width;
SDL_modelist[i]->h = sizes[i].height;
}
/* sort the mode list descending as SDL expects */
qsort(SDL_modelist, nsizes, sizeof *SDL_modelist, cmpmodelist);
SDL_modelist[i] = NULL; /* terminator */
}
use_xrandr = xrandr_major * 100 + xrandr_minor;
saved_size_id = XRRConfigCurrentConfiguration(screen_config, &saved_rotation);
}
}
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
Feb 16, 2006
Feb 16, 2006
439
#if SDL_VIDEO_DRIVER_X11_VIDMODE
Apr 26, 2001
Apr 26, 2001
440
441
442
443
/* Metro-X 4.3.0 and earlier has a broken implementation of
XF86VidModeGetAllModeLines() - it hangs the client.
*/
buggy_X11 = 0;
Feb 7, 2006
Feb 7, 2006
444
if ( SDL_strcmp(ServerVendor(SDL_Display), "Metro Link Incorporated") == 0 ) {
Apr 26, 2001
Apr 26, 2001
445
446
447
448
449
450
451
452
453
454
455
456
457
458
FILE *metro_fp;
metro_fp = fopen("/usr/X11R6/lib/X11/Metro/.version", "r");
if ( metro_fp != NULL ) {
int major, minor, patch, version;
major = 0; minor = 0; patch = 0;
fscanf(metro_fp, "%d.%d.%d", &major, &minor, &patch);
version = major*100+minor*10+patch;
if ( version < 431 ) {
buggy_X11 = 1;
}
fclose(metro_fp);
}
}
Jan 25, 2006
Jan 25, 2006
459
#if 0 /* Let's try this again... hopefully X servers have improved... */
Mar 6, 2003
Mar 6, 2003
460
461
#if defined(__alpha__) || defined(__sparc64__) || defined(__powerpc__)
/* The alpha, sparc64 and PPC XFree86 servers are also buggy */
Apr 26, 2001
Apr 26, 2001
462
buggy_X11 = 1;
Jan 25, 2006
Jan 25, 2006
463
#endif
Apr 26, 2001
Apr 26, 2001
464
465
466
#endif
/* Enumerate the available fullscreen modes */
if ( ! buggy_X11 ) {
Mar 5, 2002
Mar 5, 2002
467
468
if ( SDL_NAME(XF86VidModeQueryExtension)(SDL_Display, &vm_event, &vm_error) &&
SDL_NAME(XF86VidModeQueryVersion)(SDL_Display, &vm_major, &vm_minor) ) {
Apr 26, 2001
Apr 26, 2001
469
470
471
#ifdef BROKEN_XFREE86_4001
#ifdef X_XF86VidModeGetDotClocks /* Compiled under XFree86 4.0 */
/* Earlier X servers hang when doing vidmode */
Sep 30, 2002
Sep 30, 2002
472
if ( vm_major < 2 ) {
Nov 3, 2001
Nov 3, 2001
473
474
#ifdef XFREE86_DEBUG
printf("Compiled under XFree86 4.0, server is XFree86 3.X\n");
Apr 26, 2001
Apr 26, 2001
475
476
477
478
#endif
buggy_X11 = 1;
}
#else
Sep 30, 2002
Sep 30, 2002
479
/* XFree86 3.X code works with XFree86 4.0 servers */;
Apr 26, 2001
Apr 26, 2001
480
481
482
483
484
485
#endif /* XFree86 4.0 */
#endif /* XFree86 4.02 and newer are fixed wrt backwards compatibility */
} else {
buggy_X11 = 1;
}
}
Mar 22, 2006
Mar 22, 2006
486
if ( ! buggy_X11 && ! use_xrandr &&
Jun 28, 2003
Jun 28, 2003
487
SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display, SDL_Screen,&nmodes,&modes) ) {
Apr 26, 2001
Apr 26, 2001
488
Jun 28, 2003
Jun 28, 2003
489
#ifdef XFREE86_DEBUG
Jun 28, 2003
Jun 28, 2003
490
printf("Available modes: (sorted)\n");
Jun 28, 2003
Jun 28, 2003
491
492
493
494
495
496
497
498
for ( i = 0; i < nmodes; ++i ) {
printf("Mode %d: %d x %d @ %d\n", i,
modes[i]->hdisplay, modes[i]->vdisplay,
1000 * modes[i]->dotclock / (modes[i]->htotal *
modes[i]->vtotal) );
}
#endif
Feb 7, 2006
Feb 7, 2006
499
SDL_qsort(modes, nmodes, sizeof *modes, cmpmodes);
Feb 7, 2006
Feb 7, 2006
500
SDL_modelist = (SDL_Rect **)SDL_malloc((nmodes+2)*sizeof(SDL_Rect *));
Apr 26, 2001
Apr 26, 2001
501
if ( SDL_modelist ) {
Nov 4, 2001
Nov 4, 2001
502
n = 0;
Apr 26, 2001
Apr 26, 2001
503
for ( i=0; i<nmodes; ++i ) {
Nov 4, 2001
Nov 4, 2001
504
505
int w, h;
Feb 1, 2006
Feb 1, 2006
506
507
508
509
510
511
512
/* Eliminate duplicate modes with different refresh rates */
if ( i > 0 &&
modes[i]->hdisplay == modes[i-1]->hdisplay &&
modes[i]->vdisplay == modes[i-1]->vdisplay ) {
continue;
}
Nov 4, 2001
Nov 4, 2001
513
514
515
516
517
/* Check to see if we should add the screen size (Xinerama) */
w = modes[i]->hdisplay;
h = modes[i]->vdisplay;
if ( (screen_w * screen_h) >= (w * h) ) {
if ( (screen_w != w) || (screen_h != h) ) {
Feb 7, 2006
Feb 7, 2006
518
SDL_modelist[n] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
Nov 4, 2001
Nov 4, 2001
519
520
521
522
523
524
525
526
527
528
529
530
531
if ( SDL_modelist[n] ) {
SDL_modelist[n]->x = 0;
SDL_modelist[n]->y = 0;
SDL_modelist[n]->w = screen_w;
SDL_modelist[n]->h = screen_h;
++n;
}
}
screen_w = 0;
screen_h = 0;
}
/* Add the size from the video mode list */
Feb 7, 2006
Feb 7, 2006
532
SDL_modelist[n] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
Nov 4, 2001
Nov 4, 2001
533
if ( SDL_modelist[n] == NULL ) {
Apr 26, 2001
Apr 26, 2001
534
535
break;
}
Nov 4, 2001
Nov 4, 2001
536
537
538
539
540
SDL_modelist[n]->x = 0;
SDL_modelist[n]->y = 0;
SDL_modelist[n]->w = w;
SDL_modelist[n]->h = h;
++n;
Apr 26, 2001
Apr 26, 2001
541
}
Nov 4, 2001
Nov 4, 2001
542
SDL_modelist[n] = NULL;
Apr 26, 2001
Apr 26, 2001
543
}
Mar 22, 2006
Mar 22, 2006
544
XFree(modes);
Apr 26, 2001
Apr 26, 2001
545
Jul 11, 2001
Jul 11, 2001
546
use_vidmode = vm_major * 100 + vm_minor;
Apr 26, 2001
Apr 26, 2001
547
548
save_mode(this);
}
Feb 16, 2006
Feb 16, 2006
549
#endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */
Apr 26, 2001
Apr 26, 2001
550
Sep 30, 2002
Sep 30, 2002
551
/* XiG */
Feb 16, 2006
Feb 16, 2006
552
#if SDL_VIDEO_DRIVER_X11_XME
Nov 22, 2001
Nov 22, 2001
553
554
555
/* first lets make sure we have the extension, and it's at least v2.0 */
if (XiGMiscQueryVersion(SDL_Display, &xme_major, &xme_minor)) {
#ifdef XIG_DEBUG
Sep 30, 2002
Sep 30, 2002
556
557
fprintf(stderr, "XME: XiGMiscQueryVersion: V%d.%d\n",
xme_major, xme_minor);
Nov 22, 2001
Nov 22, 2001
558
#endif
Sep 30, 2002
Sep 30, 2002
559
560
561
562
563
564
565
/* work around a XiGMisc bogosity in our version of libXext */
if (xme_major == 0 && xme_major == 0) {
/* Ideally libxme would spit this out, but the problem is that
the right Query func will never be called if using the bogus
libXext version.
*/
fprintf(stderr,
Nov 22, 2001
Nov 22, 2001
566
"XME: If you are using Xi Graphics CDE and a Summit server, you need to\n"
Mar 22, 2006
Mar 22, 2006
567
"XME: get the libXext update from Xi's ftp site before fullscreen switching\n"
Nov 22, 2001
Nov 22, 2001
568
"XME: will work. Fullscreen switching is only supported on Summit Servers\n");
Sep 30, 2002
Sep 30, 2002
569
}
Nov 22, 2001
Nov 22, 2001
570
571
} else {
/* not there. Bummer. */
Sep 30, 2002
Sep 30, 2002
572
xme_major = xme_minor = 0;
Nov 22, 2001
Nov 22, 2001
573
574
575
576
}
modelist = NULL;
if (xme_major >= 2 && (nummodes = XiGMiscQueryResolutions(SDL_Display,
Sep 30, 2002
Sep 30, 2002
577
578
579
580
581
582
SDL_Screen,
0, /* view */
&ractive,
&modelist)) > 1)
{ /* then we actually have some */
int j;
Nov 22, 2001
Nov 22, 2001
583
584
#ifdef XIG_DEBUG
Sep 30, 2002
Sep 30, 2002
585
586
fprintf(stderr, "XME: nummodes = %d, active mode = %d\n",
nummodes, ractive);
Nov 22, 2001
Nov 22, 2001
587
588
#endif
Feb 7, 2006
Feb 7, 2006
589
SDL_modelist = (SDL_Rect **)SDL_malloc((nummodes+1)*sizeof(SDL_Rect *));
Nov 22, 2001
Nov 22, 2001
590
Sep 30, 2002
Sep 30, 2002
591
592
593
594
595
596
/* we get the list already sorted in */
/* descending order. We'll copy it in */
/* reverse order so SDL is happy */
if (SDL_modelist) {
for ( i=0, j=nummodes-1; j>=0; i++, j-- ) {
if ((SDL_modelist[i] =
Feb 7, 2006
Feb 7, 2006
597
(SDL_Rect *)SDL_malloc(sizeof(SDL_Rect))) == NULL)
Sep 30, 2002
Sep 30, 2002
598
break;
Nov 22, 2001
Nov 22, 2001
599
#ifdef XIG_DEBUG
Sep 30, 2002
Sep 30, 2002
600
601
fprintf(stderr, "XME: mode = %4d, w = %4d, h = %4d\n",
i, modelist[i].width, modelist[i].height);
Nov 22, 2001
Nov 22, 2001
602
#endif
Sep 30, 2002
Sep 30, 2002
603
604
605
606
607
608
609
SDL_modelist[i]->x = 0;
SDL_modelist[i]->y = 0;
SDL_modelist[i]->w = modelist[j].width;
SDL_modelist[i]->h = modelist[j].height;
}
Nov 22, 2001
Nov 22, 2001
610
SDL_modelist[i] = NULL; /* terminator */
Sep 30, 2002
Sep 30, 2002
611
612
613
}
use_xme = 1;
saved_res = modelist[ractive]; /* save the current resolution */
Nov 22, 2001
Nov 22, 2001
614
615
616
617
} else {
use_xme = 0;
}
if ( modelist ) {
Mar 22, 2006
Mar 22, 2006
618
XFree(modelist);
Nov 22, 2001
Nov 22, 2001
619
}
Feb 16, 2006
Feb 16, 2006
620
#endif /* SDL_VIDEO_DRIVER_X11_XME */
Nov 22, 2001
Nov 22, 2001
621
Apr 26, 2001
Apr 26, 2001
622
{
Apr 17, 2006
Apr 17, 2006
623
624
/* It's interesting to note that if we allow 32 bit depths,
we get a visual with an alpha mask on composite servers.
Sep 30, 2002
Sep 30, 2002
625
static int depth_list[] = { 32, 24, 16, 15, 8 };
Apr 17, 2006
Apr 17, 2006
626
627
*/
static int depth_list[] = { 24, 16, 15, 8 };
Sep 30, 2002
Sep 30, 2002
628
629
630
631
632
633
int j, np;
int use_directcolor = 1;
XPixmapFormatValues *pf;
/* Search for the visuals in deepest-first order, so that the first
will be the richest one */
Feb 7, 2006
Feb 7, 2006
634
if ( SDL_getenv("SDL_VIDEO_X11_NODIRECTCOLOR") ) {
Sep 30, 2002
Sep 30, 2002
635
636
637
use_directcolor = 0;
}
this->hidden->nvisuals = 0;
Feb 7, 2006
Feb 7, 2006
638
if ( ! add_visual_byid(this, SDL_getenv("SDL_VIDEO_X11_VISUALID")) ) {
Feb 19, 2006
Feb 19, 2006
639
for ( i=0; i<SDL_arraysize(depth_list); ++i ) {
Sep 30, 2002
Sep 30, 2002
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
if ( depth_list[i] > 8 ) {
if ( use_directcolor ) {
add_visual(this, depth_list[i], DirectColor);
}
add_visual(this, depth_list[i], TrueColor);
} else {
add_visual(this, depth_list[i], PseudoColor);
add_visual(this, depth_list[i], StaticColor);
}
}
}
if ( this->hidden->nvisuals == 0 ) {
SDL_SetError("Found no sufficiently capable X11 visuals");
return -1;
}
/* look up the pixel quantum for each depth */
Mar 22, 2006
Mar 22, 2006
657
pf = XListPixmapFormats(SDL_Display, &np);
Sep 30, 2002
Sep 30, 2002
658
659
660
661
662
663
664
665
for(i = 0; i < this->hidden->nvisuals; i++) {
int d = this->hidden->visuals[i].depth;
for(j = 0; j < np; j++)
if(pf[j].depth == d)
break;
this->hidden->visuals[i].bpp = j < np ? pf[j].bits_per_pixel : d;
}
Mar 22, 2006
Mar 22, 2006
666
XFree(pf);
Apr 26, 2001
Apr 26, 2001
667
668
669
}
if ( SDL_modelist == NULL ) {
Feb 7, 2006
Feb 7, 2006
670
SDL_modelist = (SDL_Rect **)SDL_malloc((1+1)*sizeof(SDL_Rect *));
Apr 26, 2001
Apr 26, 2001
671
if ( SDL_modelist ) {
Nov 4, 2001
Nov 4, 2001
672
n = 0;
Feb 7, 2006
Feb 7, 2006
673
SDL_modelist[n] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
Nov 4, 2001
Nov 4, 2001
674
675
676
677
678
679
if ( SDL_modelist[n] ) {
SDL_modelist[n]->x = 0;
SDL_modelist[n]->y = 0;
SDL_modelist[n]->w = screen_w;
SDL_modelist[n]->h = screen_h;
++n;
Apr 26, 2001
Apr 26, 2001
680
}
Nov 4, 2001
Nov 4, 2001
681
SDL_modelist[n] = NULL;
Apr 26, 2001
Apr 26, 2001
682
683
684
}
}
Nov 22, 2001
Nov 22, 2001
685
#if defined(XFREE86_DEBUG) || defined(XIG_DEBUG)
Apr 26, 2001
Apr 26, 2001
686
if ( use_vidmode ) {
Nov 3, 2001
Nov 3, 2001
687
printf("XFree86 VidMode is enabled\n");
Apr 26, 2001
Apr 26, 2001
688
}
Nov 22, 2001
Nov 22, 2001
689
Feb 16, 2006
Feb 16, 2006
690
#if SDL_VIDEO_DRIVER_X11_XME
Nov 22, 2001
Nov 22, 2001
691
692
693
694
695
696
if ( use_xme )
printf("Xi Graphics XME fullscreen is enabled\n");
else
printf("Xi Graphics XME fullscreen is not available\n");
#endif
Apr 26, 2001
Apr 26, 2001
697
if ( SDL_modelist ) {
Nov 3, 2001
Nov 3, 2001
698
printf("X11 video mode list:\n");
Apr 26, 2001
Apr 26, 2001
699
for ( i=0; SDL_modelist[i]; ++i ) {
Nov 3, 2001
Nov 3, 2001
700
printf("\t%dx%d\n", SDL_modelist[i]->w, SDL_modelist[i]->h);
Apr 26, 2001
Apr 26, 2001
701
702
}
}
Nov 22, 2001
Nov 22, 2001
703
#endif /* XFREE86_DEBUG || XIG_DEBUG */
Nov 3, 2001
Nov 3, 2001
704
705
706
707
708
/* The default X/Y fullscreen offset is 0/0 */
xinerama_x = 0;
xinerama_y = 0;
Feb 16, 2006
Feb 16, 2006
709
#if SDL_VIDEO_DRIVER_X11_XINERAMA
Nov 3, 2001
Nov 3, 2001
710
/* Query Xinerama extention */
Mar 5, 2002
Mar 5, 2002
711
712
if ( SDL_NAME(XineramaQueryExtension)(SDL_Display, &i, &i) &&
SDL_NAME(XineramaIsActive)(SDL_Display) ) {
Sep 30, 2002
Sep 30, 2002
713
714
/* Find out which screen is the desired one */
int desired = 0;
Nov 3, 2001
Nov 3, 2001
715
int screens;
Mar 5, 2002
Mar 5, 2002
716
SDL_NAME(XineramaScreenInfo) *xinerama;
Nov 3, 2001
Nov 3, 2001
717
718
719
#ifdef XINERAMA_DEBUG
printf("X11 detected Xinerama:\n");
Sep 30, 2002
Sep 30, 2002
720
721
#endif
#if 0 /* Apparently the vidmode extension doesn't work with Xinerama */
Feb 7, 2006
Feb 7, 2006
722
const char *variable = SDL_getenv("SDL_VIDEO_X11_XINERAMA_SCREEN");
Sep 30, 2002
Sep 30, 2002
723
724
725
if ( variable ) {
desired = atoi(variable);
}
Nov 3, 2001
Nov 3, 2001
726
#endif
Mar 5, 2002
Mar 5, 2002
727
xinerama = SDL_NAME(XineramaQueryScreens)(SDL_Display, &screens);
Nov 3, 2001
Nov 3, 2001
728
729
730
731
732
733
734
for ( i = 0; i < screens; i++ ) {
#ifdef XINERAMA_DEBUG
printf("xinerama %d: %dx%d+%d+%d\n",
xinerama[i].screen_number,
xinerama[i].width, xinerama[i].height,
xinerama[i].x_org, xinerama[i].y_org);
#endif
Sep 30, 2002
Sep 30, 2002
735
if ( xinerama[i].screen_number == desired ) {
Nov 3, 2001
Nov 3, 2001
736
737
738
739
xinerama_x = xinerama[i].x_org;
xinerama_y = xinerama[i].y_org;
}
}
Mar 22, 2006
Mar 22, 2006
740
XFree(xinerama);
Nov 3, 2001
Nov 3, 2001
741
}
Feb 16, 2006
Feb 16, 2006
742
#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
Nov 3, 2001
Nov 3, 2001
743
Apr 26, 2001
Apr 26, 2001
744
745
746
747
748
749
750
return 0;
}
int X11_SupportedVisual(_THIS, SDL_PixelFormat *format)
{
int i;
for(i = 0; i < this->hidden->nvisuals; i++)
Sep 30, 2002
Sep 30, 2002
751
752
if(this->hidden->visuals[i].bpp == format->BitsPerPixel)
return 1;
Apr 26, 2001
Apr 26, 2001
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
return 0;
}
SDL_Rect **X11_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
{
if ( X11_SupportedVisual(this, format) ) {
if ( flags & SDL_FULLSCREEN ) {
return(SDL_modelist);
} else {
return((SDL_Rect **)-1);
}
} else {
return((SDL_Rect **)0);
}
}
void X11_FreeVideoModes(_THIS)
{
int i;
if ( SDL_modelist ) {
for ( i=0; SDL_modelist[i]; ++i ) {
Feb 7, 2006
Feb 7, 2006
775
SDL_free(SDL_modelist[i]);
Apr 26, 2001
Apr 26, 2001
776
}
Feb 7, 2006
Feb 7, 2006
777
SDL_free(SDL_modelist);
Apr 26, 2001
Apr 26, 2001
778
779
SDL_modelist = NULL;
}
Mar 22, 2006
Mar 22, 2006
780
781
782
783
784
785
786
787
#if SDL_VIDEO_DRIVER_X11_XRANDR
/* Free the Xrandr screen configuration */
if ( screen_config ) {
XRRFreeScreenConfigInfo(screen_config);
screen_config = NULL;
}
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
Apr 26, 2001
Apr 26, 2001
788
789
790
791
792
793
}
int X11_ResizeFullScreen(_THIS)
{
int x, y;
int real_w, real_h;
Nov 4, 2001
Nov 4, 2001
794
795
796
797
798
int screen_w;
int screen_h;
screen_w = DisplayWidth(SDL_Display, SDL_Screen);
screen_h = DisplayHeight(SDL_Display, SDL_Screen);
Apr 26, 2001
Apr 26, 2001
799
Nov 3, 2001
Nov 3, 2001
800
801
x = xinerama_x;
y = xinerama_y;
Apr 26, 2001
Apr 26, 2001
802
803
if ( currently_fullscreen ) {
/* Switch resolution and cover it with the FSwindow */
Nov 3, 2001
Nov 3, 2001
804
move_cursor_to(this, x, y);
Mar 15, 2006
Mar 15, 2006
805
set_best_resolution(this, window_w, window_h);
Nov 3, 2001
Nov 3, 2001
806
move_cursor_to(this, x, y);
Apr 26, 2001
Apr 26, 2001
807
get_real_resolution(this, &real_w, &real_h);
Mar 15, 2006
Mar 15, 2006
808
if ( window_w > real_w ) {
Nov 4, 2001
Nov 4, 2001
809
810
real_w = MAX(real_w, screen_w);
}
Mar 15, 2006
Mar 15, 2006
811
if ( window_h > real_h ) {
Nov 4, 2001
Nov 4, 2001
812
813
real_h = MAX(real_h, screen_h);
}
Mar 22, 2006
Mar 22, 2006
814
XMoveResizeWindow(SDL_Display, FSwindow, x, y, real_w, real_h);
Apr 26, 2001
Apr 26, 2001
815
816
817
move_cursor_to(this, real_w/2, real_h/2);
/* Center and reparent the drawing window */
Mar 15, 2006
Mar 15, 2006
818
819
x = (real_w - window_w)/2;
y = (real_h - window_h)/2;
Mar 22, 2006
Mar 22, 2006
820
XReparentWindow(SDL_Display, SDL_Window, FSwindow, x, y);
Apr 26, 2001
Apr 26, 2001
821
/* FIXME: move the mouse to the old relative location */
Mar 22, 2006
Mar 22, 2006
822
XSync(SDL_Display, True); /* Flush spurious mode change events */
Apr 26, 2001
Apr 26, 2001
823
824
825
826
827
828
829
830
831
}
return(1);
}
void X11_QueueEnterFullScreen(_THIS)
{
switch_waiting = 0x01 | SDL_FULLSCREEN;
switch_time = SDL_GetTicks() + 1500;
#if 0 /* This causes a BadMatch error if the window is iconified (not needed) */
Mar 22, 2006
Mar 22, 2006
832
XSetInputFocus(SDL_Display, WMwindow, RevertToNone, CurrentTime);
Apr 26, 2001
Apr 26, 2001
833
834
835
836
837
838
839
840
841
842
#endif
}
int X11_EnterFullScreen(_THIS)
{
int okay;
#if 0
Window tmpwin, *windows;
int i, nwindows;
#endif
Jul 9, 2001
Jul 9, 2001
843
int real_w, real_h;
Nov 4, 2001
Nov 4, 2001
844
845
int screen_w;
int screen_h;
Apr 26, 2001
Apr 26, 2001
846
847
okay = 1;
Jul 9, 2001
Jul 9, 2001
848
849
850
if ( currently_fullscreen ) {
return(okay);
}
Apr 26, 2001
Apr 26, 2001
851
Jul 9, 2001
Jul 9, 2001
852
853
854
855
/* Ungrab the input so that we can move the mouse around */
X11_GrabInputNoLock(this, SDL_GRAB_OFF);
/* Map the fullscreen window to blank the screen */
Nov 4, 2001
Nov 4, 2001
856
857
screen_w = DisplayWidth(SDL_Display, SDL_Screen);
screen_h = DisplayHeight(SDL_Display, SDL_Screen);
Jul 9, 2001
Jul 9, 2001
858
get_real_resolution(this, &real_w, &real_h);
Mar 15, 2006
Mar 15, 2006
859
if ( window_w > real_w ) {
Nov 4, 2001
Nov 4, 2001
860
861
real_w = MAX(real_w, screen_w);
}
Mar 15, 2006
Mar 15, 2006
862
if ( window_h > real_h ) {
Nov 4, 2001
Nov 4, 2001
863
864
real_h = MAX(real_h, screen_h);
}
Mar 22, 2006
Mar 22, 2006
865
XMoveResizeWindow(SDL_Display, FSwindow,
Sep 30, 2002
Sep 30, 2002
866
xinerama_x, xinerama_y, real_w, real_h);
Mar 22, 2006
Mar 22, 2006
867
XMapRaised(SDL_Display, FSwindow);
Jul 9, 2001
Jul 9, 2001
868
X11_WaitMapped(this, FSwindow);
Apr 26, 2001
Apr 26, 2001
869
870
#if 0 /* This seems to break WindowMaker in focus-follows-mouse mode */
Jul 9, 2001
Jul 9, 2001
871
/* Make sure we got to the top of the window stack */
Mar 22, 2006
Mar 22, 2006
872
if ( XQueryTree(SDL_Display, SDL_Root, &tmpwin, &tmpwin,
Jul 9, 2001
Jul 9, 2001
873
874
875
876
877
878
&windows, &nwindows) && windows ) {
/* If not, try to put us there - if fail... oh well */
if ( windows[nwindows-1] != FSwindow ) {
tmpwin = windows[nwindows-1];
for ( i=0; i<nwindows; ++i ) {
if ( windows[i] == FSwindow ) {
Feb 7, 2006
Feb 7, 2006
879
SDL_memcpy(&windows[i], &windows[i+1],
Jul 9, 2001
Jul 9, 2001
880
881
(nwindows-i-1)*sizeof(windows[i]));
break;
Apr 26, 2001
Apr 26, 2001
882
883
}
}
Jul 9, 2001
Jul 9, 2001
884
windows[nwindows-1] = FSwindow;
Mar 22, 2006
Mar 22, 2006
885
886
XRestackWindows(SDL_Display, windows, nwindows);
XSync(SDL_Display, False);
Apr 26, 2001
Apr 26, 2001
887
}
Mar 22, 2006
Mar 22, 2006
888
XFree(windows);
Jul 9, 2001
Jul 9, 2001
889
}
Apr 26, 2001
Apr 26, 2001
890
#else
Mar 22, 2006
Mar 22, 2006
891
XRaiseWindow(SDL_Display, FSwindow);
Apr 26, 2001
Apr 26, 2001
892
893
#endif
Feb 16, 2006
Feb 16, 2006
894
#if SDL_VIDEO_DRIVER_X11_VIDMODE
Jul 9, 2001
Jul 9, 2001
895
896
/* Save the current video mode */
if ( use_vidmode ) {
Mar 5, 2002
Mar 5, 2002
897
SDL_NAME(XF86VidModeLockModeSwitch)(SDL_Display, SDL_Screen, True);
Jul 9, 2001
Jul 9, 2001
898
}
Apr 26, 2001
Apr 26, 2001
899
#endif
Jul 9, 2001
Jul 9, 2001
900
currently_fullscreen = 1;
Apr 26, 2001
Apr 26, 2001
901
Jul 9, 2001
Jul 9, 2001
902
903
904
905
906
907
908
/* Set the new resolution */
okay = X11_ResizeFullScreen(this);
if ( ! okay ) {
X11_LeaveFullScreen(this);
}
/* Set the colormap */
if ( SDL_XColorMap ) {
Mar 22, 2006
Mar 22, 2006
909
XInstallColormap(SDL_Display, SDL_XColorMap);
Apr 26, 2001
Apr 26, 2001
910
}
Jul 7, 2001
Jul 7, 2001
911
912
913
914
915
916
917
918
919
920
921
922
923
if ( okay )
X11_GrabInputNoLock(this, this->input_grab | SDL_GRAB_FULLSCREEN);
/* We may need to refresh the screen at this point (no backing store)
We also don't get an event, which is why we explicitly refresh. */
if ( this->screen ) {
if ( this->screen->flags & SDL_OPENGL ) {
SDL_PrivateExpose();
} else {
X11_RefreshDisplay(this);
}
}
Apr 26, 2001
Apr 26, 2001
924
925
926
927
928
929
return(okay);
}
int X11_LeaveFullScreen(_THIS)
{
if ( currently_fullscreen ) {
Mar 22, 2006
Mar 22, 2006
930
XReparentWindow(SDL_Display, SDL_Window, WMwindow, 0, 0);
Feb 16, 2006
Feb 16, 2006
931
#if SDL_VIDEO_DRIVER_X11_VIDMODE
Apr 26, 2001
Apr 26, 2001
932
933
if ( use_vidmode ) {
restore_mode(this);
Mar 5, 2002
Mar 5, 2002
934
SDL_NAME(XF86VidModeLockModeSwitch)(SDL_Display, SDL_Screen, False);
Apr 26, 2001
Apr 26, 2001
935
936
}
#endif
Nov 22, 2001
Nov 22, 2001
937
Feb 16, 2006
Feb 16, 2006
938
#if SDL_VIDEO_DRIVER_X11_XME
Sep 30, 2002
Sep 30, 2002
939
940
941
if ( use_xme ) {
int rw, rh;
Nov 22, 2001
Nov 22, 2001
942
/* check current mode so we can avoid uneccessary mode changes */
Sep 30, 2002
Sep 30, 2002
943
944
945
946
947
948
949
950
951
get_real_resolution(this, &rw, &rh);
if (rw != saved_res.width || rh != saved_res.height) {
XiGMiscChangeResolution(SDL_Display,
SDL_Screen,
0, /* view */
saved_res.width,
saved_res.height,
0);
Mar 22, 2006
Mar 22, 2006
952
XSync(SDL_Display, False);
Sep 30, 2002
Sep 30, 2002
953
954
}
}
Nov 22, 2001
Nov 22, 2001
955
956
#endif
Mar 22, 2006
Mar 22, 2006
957
958
959
960
961
962
963
#if SDL_VIDEO_DRIVER_X11_XRANDR
if ( use_xrandr ) {
XRRSetScreenConfig(SDL_Display, screen_config, SDL_Root,
saved_size_id, saved_rotation, CurrentTime);
}
#endif
Mar 22, 2006
Mar 22, 2006
964
XUnmapWindow(SDL_Display, FSwindow);
Apr 26, 2001
Apr 26, 2001
965
X11_WaitUnmapped(this, FSwindow);
Mar 22, 2006
Mar 22, 2006
966
XSync(SDL_Display, True); /* Flush spurious mode change events */
Apr 26, 2001
Apr 26, 2001
967
968
969
970
971
972
973
974
currently_fullscreen = 0;
}
/* If we get popped out of fullscreen mode for some reason, input_grab
will still have the SDL_GRAB_FULLSCREEN flag set, since this is only
temporary. In this case, release the grab unless the input has been
explicitly grabbed.
*/
X11_GrabInputNoLock(this, this->input_grab & ~SDL_GRAB_FULLSCREEN);
Jul 7, 2001
Jul 7, 2001
975
976
977
978
979
980
981
982
983
984
985
/* We may need to refresh the screen at this point (no backing store)
We also don't get an event, which is why we explicitly refresh. */
if ( this->screen ) {
if ( this->screen->flags & SDL_OPENGL ) {
SDL_PrivateExpose();
} else {
X11_RefreshDisplay(this);
}
}
Apr 26, 2001
Apr 26, 2001
986
987
return(0);
}