Skip to content

Latest commit

 

History

History
824 lines (737 loc) · 26.3 KB

SDL_x11modes.c

File metadata and controls

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