/
SDL_x11modes.c
829 lines (741 loc) · 26.9 KB
1
2
/*
SDL - Simple DirectMedia Layer
3
Copyright (C) 1997-2006 Sam Lantinga
4
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
8
version 2.1 of the License, or (at your option) any later version.
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
13
Lesser General Public License for more details.
14
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
18
19
Sam Lantinga
20
slouken@libsdl.org
21
22
23
24
*/
/* Utilities for getting and setting the X display mode */
25
#include <stdio.h>
26
27
28
#include "SDL_timer.h"
#include "SDL_events.h"
29
#include "../../events/SDL_events_c.h"
30
31
32
#include "SDL_x11video.h"
#include "SDL_x11wm_c.h"
#include "SDL_x11modes_c.h"
33
#include "SDL_x11image_c.h"
34
35
36
#if SDL_VIDEO_DRIVER_X11_XINERAMA
#include "../Xext/extensions/Xinerama.h"
37
#endif
38
39
#define MAX(a, b) (a > b ? a : b)
40
41
#if SDL_VIDEO_DRIVER_X11_VIDMODE
42
Bool SDL_NAME(XF86VidModeGetModeInfo)(Display *dpy, int scr, SDL_NAME(XF86VidModeModeInfo) *info)
43
{
44
SDL_NAME(XF86VidModeModeLine) *l = (SDL_NAME(XF86VidModeModeLine)*)((char*)info + sizeof info->dotclock);
45
return SDL_NAME(XF86VidModeGetModeLine)(dpy, scr, (int*)&info->dotclock, l);
46
}
47
#endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */
48
49
#if SDL_VIDEO_DRIVER_X11_VIDMODE
50
51
static void save_mode(_THIS)
{
52
SDL_memset(&saved_mode, 0, sizeof(saved_mode));
53
54
SDL_NAME(XF86VidModeGetModeInfo)(SDL_Display,SDL_Screen,&saved_mode);
SDL_NAME(XF86VidModeGetViewPort)(SDL_Display,SDL_Screen,&saved_view.x,&saved_view.y);
55
56
57
}
#endif
58
#if SDL_VIDEO_DRIVER_X11_VIDMODE
59
60
static void restore_mode(_THIS)
{
61
SDL_NAME(XF86VidModeModeLine) mode;
62
63
int unused;
64
if ( SDL_NAME(XF86VidModeGetModeLine)(SDL_Display, SDL_Screen, &unused, &mode) ) {
65
66
if ( (saved_mode.hdisplay != mode.hdisplay) ||
(saved_mode.vdisplay != mode.vdisplay) ) {
67
SDL_NAME(XF86VidModeSwitchToMode)(SDL_Display, SDL_Screen, &saved_mode);
68
69
70
}
}
if ( (saved_view.x != 0) || (saved_view.y != 0) ) {
71
SDL_NAME(XF86VidModeSetViewPort)(SDL_Display, SDL_Screen, saved_view.x, saved_view.y);
72
73
74
75
}
}
#endif
76
#if SDL_VIDEO_DRIVER_X11_VIDMODE
77
78
static int cmpmodes(const void *va, const void *vb)
{
79
80
const SDL_NAME(XF86VidModeModeInfo) *a = *(const SDL_NAME(XF86VidModeModeInfo)**)va;
const SDL_NAME(XF86VidModeModeInfo) *b = *(const SDL_NAME(XF86VidModeModeInfo)**)vb;
81
82
83
84
if ( a->hdisplay == b->hdisplay )
return b->vdisplay - a->vdisplay;
else
return b->hdisplay - a->hdisplay;
85
86
87
}
#endif
88
89
static void get_real_resolution(_THIS, int* w, int* h);
90
91
static void set_best_resolution(_THIS, int width, int height)
{
92
#if SDL_VIDEO_DRIVER_X11_VIDMODE
93
if ( use_vidmode ) {
94
95
SDL_NAME(XF86VidModeModeLine) mode;
SDL_NAME(XF86VidModeModeInfo) **modes;
96
int i;
97
int best_width = 0, best_height = 0;
98
99
int nmodes;
100
if ( SDL_NAME(XF86VidModeGetModeLine)(SDL_Display, SDL_Screen, &i, &mode) &&
101
SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display,SDL_Screen,&nmodes,&modes)){
102
#ifdef XFREE86_DEBUG
103
printf("Available modes (unsorted):\n");
104
for ( i = 0; i < nmodes; ++i ) {
105
106
107
108
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) );
109
}
110
#endif
111
for ( i = 0; i < nmodes ; i++ ) {
112
if ( (modes[i]->hdisplay == width) &&
113
(modes[i]->vdisplay == height) )
114
115
goto match;
}
116
qsort(modes, nmodes, sizeof *modes, cmpmodes);
117
for ( i = nmodes-1; i > 0 ; i-- ) {
118
119
120
121
122
123
124
125
126
127
128
129
130
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;
}
}
131
}
132
match:
133
134
if ( (modes[i]->hdisplay != mode.hdisplay) ||
(modes[i]->vdisplay != mode.vdisplay) ) {
135
SDL_NAME(XF86VidModeSwitchToMode)(SDL_Display, SDL_Screen, modes[i]);
136
}
137
pXFree(modes);
138
139
}
}
140
#endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */
141
142
/* XiG */
143
#if SDL_VIDEO_DRIVER_X11_XME
144
145
#ifdef XIG_DEBUG
fprintf(stderr, "XME: set_best_resolution(): w = %d, h = %d\n",
146
width, height);
147
148
#endif
if ( SDL_modelist ) {
149
int i;
150
151
for ( i=0; SDL_modelist[i]; ++i ) {
152
if ( (SDL_modelist[i]->w >= width) &&
153
(SDL_modelist[i]->h >= height) ) {
154
155
break;
}
156
}
157
158
159
if ( SDL_modelist[i] ) { /* found one, lets try it */
int w, h;
160
161
/* check current mode so we can avoid uneccessary mode changes */
162
get_real_resolution(this, &w, &h);
163
164
if ( (SDL_modelist[i]->w != w) || (SDL_modelist[i]->h != h) ) {
165
# ifdef XIG_DEBUG
166
167
168
fprintf(stderr, "XME: set_best_resolution: "
"XiGMiscChangeResolution: %d %d\n",
SDL_modelist[s]->w, SDL_modelist[s]->h);
169
# endif
170
171
172
173
174
175
XiGMiscChangeResolution(SDL_Display,
SDL_Screen,
0, /* view */
SDL_modelist[i]->w,
SDL_modelist[i]->h,
0);
176
pXSync(SDL_Display, False);
177
178
179
}
}
}
180
#endif /* SDL_VIDEO_DRIVER_X11_XME */
181
182
183
184
185
}
static void get_real_resolution(_THIS, int* w, int* h)
{
186
#if SDL_VIDEO_DRIVER_X11_VIDMODE
187
if ( use_vidmode ) {
188
SDL_NAME(XF86VidModeModeLine) mode;
189
190
int unused;
191
if ( SDL_NAME(XF86VidModeGetModeLine)(SDL_Display, SDL_Screen, &unused, &mode) ) {
192
193
194
195
196
197
*w = mode.hdisplay;
*h = mode.vdisplay;
return;
}
}
#endif
198
199
#if SDL_VIDEO_DRIVER_X11_XME
200
201
202
203
204
if ( use_xme ) {
int ractive;
XiGMiscResolutionInfo *modelist;
XiGMiscQueryResolutions(SDL_Display, SDL_Screen,
205
206
0, /* view */
&ractive, &modelist);
207
208
209
210
211
212
213
214
215
216
*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;
}
#endif /* XIG_XME */
217
218
219
220
221
222
223
224
225
*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 {
226
pXMaskEvent(SDL_Display, StructureNotifyMask, &event);
227
228
229
230
231
232
233
234
} 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 {
235
pXMaskEvent(SDL_Display, StructureNotifyMask, &event);
236
237
238
239
240
} while ( (event.type != UnmapNotify) || (event.xunmap.event != win) );
}
static void move_cursor_to(_THIS, int x, int y)
{
241
pXWarpPointer(SDL_Display, None, SDL_Root, 0, 0, 0, 0, x, y);
242
243
244
245
246
}
static int add_visual(_THIS, int depth, int class)
{
XVisualInfo vi;
247
if(pXMatchVisualInfo(SDL_Display, SDL_Screen, depth, class, &vi)) {
248
249
250
251
int n = this->hidden->nvisuals;
this->hidden->visuals[n].depth = vi.depth;
this->hidden->visuals[n].visual = vi.visual;
this->hidden->nvisuals++;
252
253
254
255
256
257
258
259
260
}
return(this->hidden->nvisuals);
}
static int add_visual_byid(_THIS, const char *visual_id)
{
XVisualInfo *vi, template;
int nvis;
if ( visual_id ) {
261
262
SDL_memset(&template, 0, (sizeof template));
template.visualid = SDL_strtol(visual_id, NULL, 0);
263
vi = pXGetVisualInfo(SDL_Display, VisualIDMask, &template, &nvis);
264
if ( vi ) {
265
266
267
268
int n = this->hidden->nvisuals;
this->hidden->visuals[n].depth = vi->depth;
this->hidden->visuals[n].visual = vi->visual;
this->hidden->nvisuals++;
269
pXFree(vi);
270
271
272
273
274
275
276
277
278
279
}
}
return(this->hidden->nvisuals);
}
/* Global for the error handler */
int vm_event, vm_error = -1;
int X11_GetVideoModes(_THIS)
{
280
#if SDL_VIDEO_DRIVER_X11_VIDMODE
281
282
283
int buggy_X11;
int vm_major, vm_minor;
int nmodes;
284
SDL_NAME(XF86VidModeModeInfo) **modes;
285
#endif
286
#if SDL_VIDEO_DRIVER_X11_XME
287
288
289
int xme_major, xme_minor;
int ractive, nummodes;
XiGMiscResolutionInfo *modelist;
290
#endif
291
292
293
int i, n;
int screen_w;
int screen_h;
294
295
296
vm_error = -1;
use_vidmode = 0;
297
298
299
screen_w = DisplayWidth(SDL_Display, SDL_Screen);
screen_h = DisplayHeight(SDL_Display, SDL_Screen);
300
#if SDL_VIDEO_DRIVER_X11_VIDMODE
301
302
303
304
/* Metro-X 4.3.0 and earlier has a broken implementation of
XF86VidModeGetAllModeLines() - it hangs the client.
*/
buggy_X11 = 0;
305
if ( SDL_strcmp(ServerVendor(SDL_Display), "Metro Link Incorporated") == 0 ) {
306
307
308
309
310
311
312
313
314
315
316
317
318
319
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);
}
}
320
#if 0 /* Let's try this again... hopefully X servers have improved... */
321
322
#if defined(__alpha__) || defined(__sparc64__) || defined(__powerpc__)
/* The alpha, sparc64 and PPC XFree86 servers are also buggy */
323
buggy_X11 = 1;
324
#endif
325
326
327
#endif
/* Enumerate the available fullscreen modes */
if ( ! buggy_X11 ) {
328
329
if ( SDL_NAME(XF86VidModeQueryExtension)(SDL_Display, &vm_event, &vm_error) &&
SDL_NAME(XF86VidModeQueryVersion)(SDL_Display, &vm_major, &vm_minor) ) {
330
331
332
#ifdef BROKEN_XFREE86_4001
#ifdef X_XF86VidModeGetDotClocks /* Compiled under XFree86 4.0 */
/* Earlier X servers hang when doing vidmode */
333
if ( vm_major < 2 ) {
334
335
#ifdef XFREE86_DEBUG
printf("Compiled under XFree86 4.0, server is XFree86 3.X\n");
336
337
338
339
#endif
buggy_X11 = 1;
}
#else
340
/* XFree86 3.X code works with XFree86 4.0 servers */;
341
342
343
344
345
346
347
#endif /* XFree86 4.0 */
#endif /* XFree86 4.02 and newer are fixed wrt backwards compatibility */
} else {
buggy_X11 = 1;
}
}
if ( ! buggy_X11 &&
348
SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display, SDL_Screen,&nmodes,&modes) ) {
349
350
#ifdef XFREE86_DEBUG
351
printf("Available modes: (sorted)\n");
352
353
354
355
356
357
358
359
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
360
SDL_qsort(modes, nmodes, sizeof *modes, cmpmodes);
361
SDL_modelist = (SDL_Rect **)SDL_malloc((nmodes+2)*sizeof(SDL_Rect *));
362
if ( SDL_modelist ) {
363
n = 0;
364
for ( i=0; i<nmodes; ++i ) {
365
366
int w, h;
367
368
369
370
371
372
373
/* 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;
}
374
375
376
377
378
/* 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) ) {
379
SDL_modelist[n] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
380
381
382
383
384
385
386
387
388
389
390
391
392
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 */
393
SDL_modelist[n] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
394
if ( SDL_modelist[n] == NULL ) {
395
396
break;
}
397
398
399
400
401
SDL_modelist[n]->x = 0;
SDL_modelist[n]->y = 0;
SDL_modelist[n]->w = w;
SDL_modelist[n]->h = h;
++n;
402
}
403
SDL_modelist[n] = NULL;
404
}
405
pXFree(modes);
406
407
use_vidmode = vm_major * 100 + vm_minor;
408
409
save_mode(this);
}
410
#endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */
411
412
/* XiG */
413
#if SDL_VIDEO_DRIVER_X11_XME
414
415
416
/* 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
417
418
fprintf(stderr, "XME: XiGMiscQueryVersion: V%d.%d\n",
xme_major, xme_minor);
419
#endif
420
421
422
423
424
425
426
/* 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,
427
428
429
"XME: If you are using Xi Graphics CDE and a Summit server, you need to\n"
"XME: get the libXext update from our ftp site before fullscreen switching\n"
"XME: will work. Fullscreen switching is only supported on Summit Servers\n");
430
}
431
432
} else {
/* not there. Bummer. */
433
xme_major = xme_minor = 0;
434
435
436
437
}
modelist = NULL;
if (xme_major >= 2 && (nummodes = XiGMiscQueryResolutions(SDL_Display,
438
439
440
441
442
443
SDL_Screen,
0, /* view */
&ractive,
&modelist)) > 1)
{ /* then we actually have some */
int j;
444
445
#ifdef XIG_DEBUG
446
447
fprintf(stderr, "XME: nummodes = %d, active mode = %d\n",
nummodes, ractive);
448
449
#endif
450
SDL_modelist = (SDL_Rect **)SDL_malloc((nummodes+1)*sizeof(SDL_Rect *));
451
452
453
454
455
456
457
/* 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] =
458
(SDL_Rect *)SDL_malloc(sizeof(SDL_Rect))) == NULL)
459
break;
460
#ifdef XIG_DEBUG
461
462
fprintf(stderr, "XME: mode = %4d, w = %4d, h = %4d\n",
i, modelist[i].width, modelist[i].height);
463
#endif
464
465
466
467
468
469
470
SDL_modelist[i]->x = 0;
SDL_modelist[i]->y = 0;
SDL_modelist[i]->w = modelist[j].width;
SDL_modelist[i]->h = modelist[j].height;
}
471
SDL_modelist[i] = NULL; /* terminator */
472
473
474
}
use_xme = 1;
saved_res = modelist[ractive]; /* save the current resolution */
475
476
477
478
} else {
use_xme = 0;
}
if ( modelist ) {
479
pXFree(modelist);
480
}
481
#endif /* SDL_VIDEO_DRIVER_X11_XME */
482
483
{
484
485
486
487
488
489
490
static int depth_list[] = { 32, 24, 16, 15, 8 };
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 */
491
if ( SDL_getenv("SDL_VIDEO_X11_NODIRECTCOLOR") ) {
492
493
494
use_directcolor = 0;
}
this->hidden->nvisuals = 0;
495
if ( ! add_visual_byid(this, SDL_getenv("SDL_VIDEO_X11_VISUALID")) ) {
496
for ( i=0; i<SDL_arraysize(depth_list); ++i ) {
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
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 */
514
pf = pXListPixmapFormats(SDL_Display, &np);
515
516
517
518
519
520
521
522
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;
}
523
pXFree(pf);
524
525
526
}
if ( SDL_modelist == NULL ) {
527
SDL_modelist = (SDL_Rect **)SDL_malloc((1+1)*sizeof(SDL_Rect *));
528
if ( SDL_modelist ) {
529
n = 0;
530
SDL_modelist[n] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
531
532
533
534
535
536
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;
537
}
538
SDL_modelist[n] = NULL;
539
540
541
}
}
542
#if defined(XFREE86_DEBUG) || defined(XIG_DEBUG)
543
if ( use_vidmode ) {
544
printf("XFree86 VidMode is enabled\n");
545
}
546
547
#if SDL_VIDEO_DRIVER_X11_XME
548
549
550
551
552
553
if ( use_xme )
printf("Xi Graphics XME fullscreen is enabled\n");
else
printf("Xi Graphics XME fullscreen is not available\n");
#endif
554
if ( SDL_modelist ) {
555
printf("X11 video mode list:\n");
556
for ( i=0; SDL_modelist[i]; ++i ) {
557
printf("\t%dx%d\n", SDL_modelist[i]->w, SDL_modelist[i]->h);
558
559
}
}
560
#endif /* XFREE86_DEBUG || XIG_DEBUG */
561
562
563
564
565
/* The default X/Y fullscreen offset is 0/0 */
xinerama_x = 0;
xinerama_y = 0;
566
#if SDL_VIDEO_DRIVER_X11_XINERAMA
567
/* Query Xinerama extention */
568
569
if ( SDL_NAME(XineramaQueryExtension)(SDL_Display, &i, &i) &&
SDL_NAME(XineramaIsActive)(SDL_Display) ) {
570
571
/* Find out which screen is the desired one */
int desired = 0;
572
int screens;
573
SDL_NAME(XineramaScreenInfo) *xinerama;
574
575
576
#ifdef XINERAMA_DEBUG
printf("X11 detected Xinerama:\n");
577
578
#endif
#if 0 /* Apparently the vidmode extension doesn't work with Xinerama */
579
const char *variable = SDL_getenv("SDL_VIDEO_X11_XINERAMA_SCREEN");
580
581
582
if ( variable ) {
desired = atoi(variable);
}
583
#endif
584
xinerama = SDL_NAME(XineramaQueryScreens)(SDL_Display, &screens);
585
586
587
588
589
590
591
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
592
if ( xinerama[i].screen_number == desired ) {
593
594
595
596
xinerama_x = xinerama[i].x_org;
xinerama_y = xinerama[i].y_org;
}
}
597
pXFree(xinerama);
598
}
599
#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
600
601
602
603
604
605
606
607
return 0;
}
int X11_SupportedVisual(_THIS, SDL_PixelFormat *format)
{
int i;
for(i = 0; i < this->hidden->nvisuals; i++)
608
609
if(this->hidden->visuals[i].bpp == format->BitsPerPixel)
return 1;
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
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 ) {
632
SDL_free(SDL_modelist[i]);
633
}
634
SDL_free(SDL_modelist);
635
636
637
638
639
640
641
642
SDL_modelist = NULL;
}
}
int X11_ResizeFullScreen(_THIS)
{
int x, y;
int real_w, real_h;
643
644
645
646
647
int screen_w;
int screen_h;
screen_w = DisplayWidth(SDL_Display, SDL_Screen);
screen_h = DisplayHeight(SDL_Display, SDL_Screen);
648
649
650
x = xinerama_x;
y = xinerama_y;
651
652
if ( currently_fullscreen ) {
/* Switch resolution and cover it with the FSwindow */
653
move_cursor_to(this, x, y);
654
set_best_resolution(this, current_w, current_h);
655
move_cursor_to(this, x, y);
656
get_real_resolution(this, &real_w, &real_h);
657
658
659
660
661
662
if ( current_w > real_w ) {
real_w = MAX(real_w, screen_w);
}
if ( current_h > real_h ) {
real_h = MAX(real_h, screen_h);
}
663
pXMoveResizeWindow(SDL_Display, FSwindow, x, y, real_w, real_h);
664
665
666
667
668
move_cursor_to(this, real_w/2, real_h/2);
/* Center and reparent the drawing window */
x = (real_w - current_w)/2;
y = (real_h - current_h)/2;
669
pXReparentWindow(SDL_Display, SDL_Window, FSwindow, x, y);
670
/* FIXME: move the mouse to the old relative location */
671
pXSync(SDL_Display, True); /* Flush spurious mode change events */
672
673
674
675
676
677
678
679
680
}
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) */
681
pXSetInputFocus(SDL_Display, WMwindow, RevertToNone, CurrentTime);
682
683
684
685
686
687
688
689
690
691
#endif
}
int X11_EnterFullScreen(_THIS)
{
int okay;
#if 0
Window tmpwin, *windows;
int i, nwindows;
#endif
692
int real_w, real_h;
693
694
int screen_w;
int screen_h;
695
696
okay = 1;
697
698
699
if ( currently_fullscreen ) {
return(okay);
}
700
701
702
703
704
/* 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 */
705
706
screen_w = DisplayWidth(SDL_Display, SDL_Screen);
screen_h = DisplayHeight(SDL_Display, SDL_Screen);
707
get_real_resolution(this, &real_w, &real_h);
708
709
710
711
712
713
if ( current_w > real_w ) {
real_w = MAX(real_w, screen_w);
}
if ( current_h > real_h ) {
real_h = MAX(real_h, screen_h);
}
714
pXMoveResizeWindow(SDL_Display, FSwindow,
715
xinerama_x, xinerama_y, real_w, real_h);
716
pXMapRaised(SDL_Display, FSwindow);
717
X11_WaitMapped(this, FSwindow);
718
719
#if 0 /* This seems to break WindowMaker in focus-follows-mouse mode */
720
/* Make sure we got to the top of the window stack */
721
if ( pXQueryTree(SDL_Display, SDL_Root, &tmpwin, &tmpwin,
722
723
724
725
726
727
&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 ) {
728
SDL_memcpy(&windows[i], &windows[i+1],
729
730
(nwindows-i-1)*sizeof(windows[i]));
break;
731
732
}
}
733
windows[nwindows-1] = FSwindow;
734
735
pXRestackWindows(SDL_Display, windows, nwindows);
pXSync(SDL_Display, False);
736
}
737
pXFree(windows);
738
}
739
#else
740
pXRaiseWindow(SDL_Display, FSwindow);
741
742
#endif
743
#if SDL_VIDEO_DRIVER_X11_VIDMODE
744
745
/* Save the current video mode */
if ( use_vidmode ) {
746
SDL_NAME(XF86VidModeLockModeSwitch)(SDL_Display, SDL_Screen, True);
747
}
748
#endif
749
currently_fullscreen = 1;
750
751
752
753
754
755
756
757
/* Set the new resolution */
okay = X11_ResizeFullScreen(this);
if ( ! okay ) {
X11_LeaveFullScreen(this);
}
/* Set the colormap */
if ( SDL_XColorMap ) {
758
pXInstallColormap(SDL_Display, SDL_XColorMap);
759
}
760
761
762
763
764
765
766
767
768
769
770
771
772
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);
}
}
773
774
775
776
777
778
return(okay);
}
int X11_LeaveFullScreen(_THIS)
{
if ( currently_fullscreen ) {
779
pXReparentWindow(SDL_Display, SDL_Window, WMwindow, 0, 0);
780
#if SDL_VIDEO_DRIVER_X11_VIDMODE
781
782
if ( use_vidmode ) {
restore_mode(this);
783
SDL_NAME(XF86VidModeLockModeSwitch)(SDL_Display, SDL_Screen, False);
784
785
}
#endif
786
787
#if SDL_VIDEO_DRIVER_X11_XME
788
789
790
if ( use_xme ) {
int rw, rh;
791
/* check current mode so we can avoid uneccessary mode changes */
792
793
794
795
796
797
798
799
800
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);
801
pXSync(SDL_Display, False);
802
803
}
}
804
805
#endif
806
pXUnmapWindow(SDL_Display, FSwindow);
807
X11_WaitUnmapped(this, FSwindow);
808
pXSync(SDL_Display, True); /* Flush spurious mode change events */
809
810
811
812
813
814
815
816
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);
817
818
819
820
821
822
823
824
825
826
827
/* 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);
}
}
828
829
return(0);
}