Skip to content

Latest commit

 

History

History
1106 lines (979 loc) · 34.4 KB

SDL_x11modes.c

File metadata and controls

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