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