Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
806 lines (713 loc) · 24.9 KB

SDL_x11modes.c

File metadata and controls

806 lines (713 loc) · 24.9 KB
 
Jun 22, 2011
Jun 22, 2011
1
2
/*
Simple DirectMedia Layer
Dec 31, 2011
Dec 31, 2011
3
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
Jun 22, 2011
Jun 22, 2011
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_config.h"
#if SDL_VIDEO_DRIVER_X11
Sep 27, 2012
Sep 27, 2012
25
#include "SDL_hints.h"
Jun 22, 2011
Jun 22, 2011
26
27
#include "SDL_x11video.h"
Oct 4, 2012
Oct 4, 2012
28
29
30
31
32
33
34
35
36
37
38
#define X11MODES_DEBUG
/* I'm becoming more and more convinced that the application should never use XRandR,
* and it's the window manager's responsibility to track and manage display modes for
* fullscreen windows. Right now XRandR is completely broken with respect to window
* manager behavior on every window manager that I can find. For example, on Unity 3D
* if you show a fullscreen window while the resolution is changing (within ~250 ms)
* your window will retain the fullscreen state hint but be decorated and windowed.
*/
#define XRANDR_DISABLED_BY_DEFAULT
Jun 22, 2011
Jun 22, 2011
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
static int
get_visualinfo(Display * display, int screen, XVisualInfo * vinfo)
{
const char *visual_id = SDL_getenv("SDL_VIDEO_X11_VISUALID");
int depth;
/* Look for an exact visual, if requested */
if (visual_id) {
XVisualInfo *vi, template;
int nvis;
SDL_zero(template);
template.visualid = SDL_strtol(visual_id, NULL, 0);
vi = XGetVisualInfo(display, VisualIDMask, &template, &nvis);
if (vi) {
*vinfo = *vi;
XFree(vi);
return 0;
}
}
depth = DefaultDepth(display, screen);
if ((X11_UseDirectColorVisuals() &&
XMatchVisualInfo(display, screen, depth, DirectColor, vinfo)) ||
XMatchVisualInfo(display, screen, depth, TrueColor, vinfo) ||
XMatchVisualInfo(display, screen, depth, PseudoColor, vinfo) ||
XMatchVisualInfo(display, screen, depth, StaticColor, vinfo)) {
return 0;
}
return -1;
}
int
X11_GetVisualInfoFromVisual(Display * display, Visual * visual, XVisualInfo * vinfo)
{
XVisualInfo *vi;
int nvis;
vinfo->visualid = XVisualIDFromVisual(visual);
vi = XGetVisualInfo(display, VisualIDMask, vinfo, &nvis);
if (vi) {
*vinfo = *vi;
XFree(vi);
return 0;
}
return -1;
}
Uint32
X11_GetPixelFormatFromVisualInfo(Display * display, XVisualInfo * vinfo)
{
if (vinfo->class == DirectColor || vinfo->class == TrueColor) {
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
Rmask = vinfo->visual->red_mask;
Gmask = vinfo->visual->green_mask;
Bmask = vinfo->visual->blue_mask;
if (vinfo->depth == 32) {
Amask = (0xFFFFFFFF & ~(Rmask | Gmask | Bmask));
} else {
Amask = 0;
}
bpp = vinfo->depth;
if (bpp == 24) {
int i, n;
XPixmapFormatValues *p = XListPixmapFormats(display, &n);
if (p) {
for (i = 0; i < n; ++i) {
if (p[i].depth == 24) {
bpp = p[i].bits_per_pixel;
break;
}
}
XFree(p);
}
}
return SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask);
}
if (vinfo->class == PseudoColor || vinfo->class == StaticColor) {
switch (vinfo->depth) {
case 8:
return SDL_PIXELTYPE_INDEX8;
case 4:
if (BitmapBitOrder(display) == LSBFirst) {
return SDL_PIXELFORMAT_INDEX4LSB;
} else {
return SDL_PIXELFORMAT_INDEX4MSB;
}
break;
case 1:
if (BitmapBitOrder(display) == LSBFirst) {
return SDL_PIXELFORMAT_INDEX1LSB;
} else {
return SDL_PIXELFORMAT_INDEX1MSB;
}
break;
}
}
return SDL_PIXELFORMAT_UNKNOWN;
}
/* Global for the error handler */
int vm_event, vm_error = -1;
#if SDL_VIDEO_DRIVER_X11_XINERAMA
static SDL_bool
CheckXinerama(Display * display, int *major, int *minor)
{
Oct 24, 2011
Oct 24, 2011
153
154
int event_base = 0;
int error_base = 0;
Jun 22, 2011
Jun 22, 2011
155
156
157
158
159
160
const char *env;
/* Default the extension not available */
*major = *minor = 0;
/* Allow environment override */
Sep 27, 2012
Sep 27, 2012
161
env = SDL_GetHint(SDL_HINT_VIDEO_X11_XINERAMA);
Jun 22, 2011
Jun 22, 2011
162
if (env && !SDL_atoi(env)) {
Sep 27, 2012
Sep 27, 2012
163
#ifdef X11MODES_DEBUG
Sep 27, 2012
Sep 27, 2012
164
printf("Xinerama disabled due to hint\n");
Sep 27, 2012
Sep 27, 2012
165
#endif
Jun 22, 2011
Jun 22, 2011
166
167
168
169
return SDL_FALSE;
}
if (!SDL_X11_HAVE_XINERAMA) {
Sep 27, 2012
Sep 27, 2012
170
171
172
#ifdef X11MODES_DEBUG
printf("Xinerama support not available\n");
#endif
Jun 22, 2011
Jun 22, 2011
173
174
175
176
return SDL_FALSE;
}
/* Query the extension version */
Oct 24, 2011
Oct 24, 2011
177
178
if (!XineramaQueryExtension(display, &event_base, &error_base) ||
!XineramaQueryVersion(display, major, minor) ||
Jun 22, 2011
Jun 22, 2011
179
!XineramaIsActive(display)) {
Sep 27, 2012
Sep 27, 2012
180
181
182
#ifdef X11MODES_DEBUG
printf("Xinerama not active on the display\n");
#endif
Jun 22, 2011
Jun 22, 2011
183
184
return SDL_FALSE;
}
Sep 27, 2012
Sep 27, 2012
185
#ifdef X11MODES_DEBUG
Oct 4, 2012
Oct 4, 2012
186
printf("Xinerama available at version %d.%d!\n", *major, *minor);
Sep 27, 2012
Sep 27, 2012
187
#endif
Jun 22, 2011
Jun 22, 2011
188
189
190
191
192
193
194
195
196
197
198
199
200
201
return SDL_TRUE;
}
#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
#if SDL_VIDEO_DRIVER_X11_XRANDR
static SDL_bool
CheckXRandR(Display * display, int *major, int *minor)
{
const char *env;
/* Default the extension not available */
*major = *minor = 0;
/* Allow environment override */
Sep 27, 2012
Sep 27, 2012
202
env = SDL_GetHint(SDL_HINT_VIDEO_X11_XRANDR);
Oct 4, 2012
Oct 4, 2012
203
204
205
206
207
208
209
210
#ifdef XRANDR_DISABLED_BY_DEFAULT
if (!env || !SDL_atoi(env)) {
#ifdef X11MODES_DEBUG
printf("XRandR disabled by default due to window manager issues\n");
#endif
return SDL_FALSE;
}
#else
Jun 22, 2011
Jun 22, 2011
211
if (env && !SDL_atoi(env)) {
Sep 27, 2012
Sep 27, 2012
212
#ifdef X11MODES_DEBUG
Sep 27, 2012
Sep 27, 2012
213
printf("XRandR disabled due to hint\n");
Sep 27, 2012
Sep 27, 2012
214
#endif
Jun 22, 2011
Jun 22, 2011
215
216
return SDL_FALSE;
}
Oct 4, 2012
Oct 4, 2012
217
#endif /* XRANDR_ENABLED_BY_DEFAULT */
Jun 22, 2011
Jun 22, 2011
218
219
if (!SDL_X11_HAVE_XRANDR) {
Sep 27, 2012
Sep 27, 2012
220
221
222
#ifdef X11MODES_DEBUG
printf("XRandR support not available\n");
#endif
Jun 22, 2011
Jun 22, 2011
223
224
225
226
227
return SDL_FALSE;
}
/* Query the extension version */
if (!XRRQueryVersion(display, major, minor)) {
Sep 27, 2012
Sep 27, 2012
228
229
230
#ifdef X11MODES_DEBUG
printf("XRandR not active on the display\n");
#endif
Jun 22, 2011
Jun 22, 2011
231
232
return SDL_FALSE;
}
Sep 27, 2012
Sep 27, 2012
233
#ifdef X11MODES_DEBUG
Oct 4, 2012
Oct 4, 2012
234
printf("XRandR available at version %d.%d!\n", *major, *minor);
Sep 27, 2012
Sep 27, 2012
235
#endif
Jun 22, 2011
Jun 22, 2011
236
237
return SDL_TRUE;
}
Oct 3, 2012
Oct 3, 2012
238
239
240
241
#define XRANDR_ROTATION_LEFT (1 << 1)
#define XRANDR_ROTATION_RIGHT (1 << 3)
Oct 4, 2012
Oct 4, 2012
242
243
static int
CalculateXRandRRefreshRate(const XRRModeInfo *info)
Oct 3, 2012
Oct 3, 2012
244
{
Oct 4, 2012
Oct 4, 2012
245
return (info->hTotal
Oct 4, 2012
Oct 4, 2012
246
&& info->vTotal) ? (info->dotClock / (info->hTotal * info->vTotal)) : 0;
Oct 4, 2012
Oct 4, 2012
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
}
static SDL_bool
SetXRandRModeInfo(Display *display, XRRScreenResources *res, XRROutputInfo *output_info,
RRMode modeID, SDL_DisplayMode *mode)
{
int i;
for (i = 0; i < res->nmode; ++i) {
if (res->modes[i].id == modeID) {
XRRCrtcInfo *crtc;
Rotation rotation = 0;
const XRRModeInfo *info = &res->modes[i];
crtc = XRRGetCrtcInfo(display, res, output_info->crtc);
if (crtc) {
rotation = crtc->rotation;
XRRFreeCrtcInfo(crtc);
}
if (rotation & (XRANDR_ROTATION_LEFT|XRANDR_ROTATION_RIGHT)) {
mode->w = info->height;
mode->h = info->width;
} else {
mode->w = info->width;
mode->h = info->height;
}
mode->refresh_rate = CalculateXRandRRefreshRate(info);
((SDL_DisplayModeData*)mode->driverdata)->xrandr_mode = modeID;
#ifdef X11MODES_DEBUG
printf("XRandR mode %d: %dx%d@%dHz\n", modeID, mode->w, mode->h, mode->refresh_rate);
#endif
return SDL_TRUE;
}
Oct 3, 2012
Oct 3, 2012
280
}
Oct 4, 2012
Oct 4, 2012
281
return SDL_FALSE;
Oct 3, 2012
Oct 3, 2012
282
}
Jun 22, 2011
Jun 22, 2011
283
284
285
286
287
288
289
290
291
292
293
294
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
static SDL_bool
CheckVidMode(Display * display, int *major, int *minor)
{
const char *env;
/* Default the extension not available */
*major = *minor = 0;
/* Allow environment override */
Sep 27, 2012
Sep 27, 2012
295
env = SDL_GetHint(SDL_HINT_VIDEO_X11_XVIDMODE);
Jun 22, 2011
Jun 22, 2011
296
if (env && !SDL_atoi(env)) {
Sep 27, 2012
Sep 27, 2012
297
#ifdef X11MODES_DEBUG
Sep 27, 2012
Sep 27, 2012
298
printf("XVidMode disabled due to hint\n");
Sep 27, 2012
Sep 27, 2012
299
#endif
Jun 22, 2011
Jun 22, 2011
300
301
302
303
return SDL_FALSE;
}
if (!SDL_X11_HAVE_XVIDMODE) {
Sep 27, 2012
Sep 27, 2012
304
305
306
#ifdef X11MODES_DEBUG
printf("XVidMode support not available\n");
#endif
Jun 22, 2011
Jun 22, 2011
307
308
309
310
311
312
313
return SDL_FALSE;
}
/* Query the extension version */
vm_error = -1;
if (!XF86VidModeQueryExtension(display, &vm_event, &vm_error)
|| !XF86VidModeQueryVersion(display, major, minor)) {
Sep 27, 2012
Sep 27, 2012
314
315
316
#ifdef X11MODES_DEBUG
printf("XVidMode not active on the display\n");
#endif
Jun 22, 2011
Jun 22, 2011
317
318
return SDL_FALSE;
}
Sep 27, 2012
Sep 27, 2012
319
#ifdef X11MODES_DEBUG
Oct 4, 2012
Oct 4, 2012
320
printf("XVidMode available at version %d.%d!\n", *major, *minor);
Sep 27, 2012
Sep 27, 2012
321
#endif
Jun 22, 2011
Jun 22, 2011
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
return SDL_TRUE;
}
static
Bool XF86VidModeGetModeInfo(Display * dpy, int scr,
XF86VidModeModeInfo* info)
{
Bool retval;
int dotclock;
XF86VidModeModeLine l;
SDL_zerop(info);
SDL_zero(l);
retval = XF86VidModeGetModeLine(dpy, scr, &dotclock, &l);
info->dotclock = dotclock;
info->hdisplay = l.hdisplay;
info->hsyncstart = l.hsyncstart;
info->hsyncend = l.hsyncend;
info->htotal = l.htotal;
info->hskew = l.hskew;
info->vdisplay = l.vdisplay;
info->vsyncstart = l.vsyncstart;
info->vsyncend = l.vsyncend;
info->vtotal = l.vtotal;
info->flags = l.flags;
info->privsize = l.privsize;
info->private = l.private;
return retval;
}
static int
Oct 4, 2012
Oct 4, 2012
352
CalculateXVidModeRefreshRate(const XF86VidModeModeInfo * info)
Jun 22, 2011
Jun 22, 2011
353
354
355
356
357
358
{
return (info->htotal
&& info->vtotal) ? (1000 * info->dotclock / (info->htotal *
info->vtotal)) : 0;
}
Oct 4, 2012
Oct 4, 2012
359
360
SDL_bool
SetXVidModeModeInfo(const XF86VidModeModeInfo *info, SDL_DisplayMode *mode)
Jun 22, 2011
Jun 22, 2011
361
{
Oct 4, 2012
Oct 4, 2012
362
363
364
365
366
mode->w = info->hdisplay;
mode->h = info->vdisplay;
mode->refresh_rate = CalculateXVidModeRefreshRate(info);
((SDL_DisplayModeData*)mode->driverdata)->vm_mode = *info;
return SDL_TRUE;
Jun 22, 2011
Jun 22, 2011
367
}
Oct 4, 2012
Oct 4, 2012
368
#endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
Jun 22, 2011
Jun 22, 2011
369
Oct 4, 2012
Oct 4, 2012
370
371
int
X11_InitModes(_THIS)
Jun 22, 2011
Jun 22, 2011
372
{
Oct 4, 2012
Oct 4, 2012
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
int screen, screencount;
#if SDL_VIDEO_DRIVER_X11_XINERAMA
int xinerama_major, xinerama_minor;
int use_xinerama = 0;
XineramaScreenInfo *xinerama = NULL;
#endif
#if SDL_VIDEO_DRIVER_X11_XRANDR
int xrandr_major, xrandr_minor;
int use_xrandr = 0;
XRRScreenResources *res = NULL;
#endif
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
int vm_major, vm_minor;
int use_vidmode = 0;
#endif
Jun 22, 2011
Jun 22, 2011
389
Oct 4, 2012
Oct 4, 2012
390
391
392
393
394
395
396
397
398
#if SDL_VIDEO_DRIVER_X11_XINERAMA
/* Query Xinerama extention
* NOTE: This works with Nvidia Twinview correctly, but you need version 302.17 (released on June 2012)
* or newer of the Nvidia binary drivers
*/
if (CheckXinerama(data->display, &xinerama_major, &xinerama_minor)) {
xinerama = XineramaQueryScreens(data->display, &screencount);
if (xinerama) {
use_xinerama = xinerama_major * 100 + xinerama_minor;
Jun 22, 2011
Jun 22, 2011
399
400
}
}
Oct 4, 2012
Oct 4, 2012
401
402
if (!xinerama) {
screencount = ScreenCount(data->display);
Jun 22, 2011
Jun 22, 2011
403
}
Oct 4, 2012
Oct 4, 2012
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
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
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
#else
screencount = ScreenCount(data->display);
#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
#if SDL_VIDEO_DRIVER_X11_XRANDR
/* require at least XRandR v1.2 */
if (CheckXRandR(data->display, &xrandr_major, &xrandr_minor) &&
(xrandr_major >= 2 || (xrandr_major == 1 && xrandr_minor >= 2))) {
use_xrandr = xrandr_major * 100 + xrandr_minor;
}
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
if (CheckVidMode(data->display, &vm_major, &vm_minor)) {
use_vidmode = vm_major * 100 + vm_minor;
}
#endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
for (screen = 0; screen < screencount; ++screen) {
XVisualInfo vinfo;
SDL_VideoDisplay display;
SDL_DisplayData *displaydata;
SDL_DisplayMode mode;
SDL_DisplayModeData *modedata;
XPixmapFormatValues *pixmapFormats;
int i, n;
#if SDL_VIDEO_DRIVER_X11_XINERAMA
if (xinerama) {
if (get_visualinfo(data->display, 0, &vinfo) < 0) {
continue;
}
} else {
if (get_visualinfo(data->display, screen, &vinfo) < 0) {
continue;
}
}
#else
if (get_visualinfo(data->display, screen, &vinfo) < 0) {
continue;
}
#endif
displaydata = (SDL_DisplayData *) SDL_calloc(1, sizeof(*displaydata));
if (!displaydata) {
continue;
}
mode.format = X11_GetPixelFormatFromVisualInfo(data->display, &vinfo);
if (SDL_ISPIXELFORMAT_INDEXED(mode.format)) {
/* We don't support palettized modes now */
SDL_free(displaydata);
continue;
}
#if SDL_VIDEO_DRIVER_X11_XINERAMA
if (xinerama) {
mode.w = xinerama[screen].width;
mode.h = xinerama[screen].height;
} else {
mode.w = DisplayWidth(data->display, screen);
mode.h = DisplayHeight(data->display, screen);
}
#else
mode.w = DisplayWidth(data->display, screen);
mode.h = DisplayHeight(data->display, screen);
#endif
mode.refresh_rate = 0;
modedata = (SDL_DisplayModeData *) SDL_calloc(1, sizeof(SDL_DisplayModeData));
if (!modedata) {
SDL_free(displaydata);
continue;
}
mode.driverdata = modedata;
#if SDL_VIDEO_DRIVER_X11_XINERAMA
/* Most of SDL's calls to X11 are unwaware of Xinerama, and to X11 standard calls, when Xinerama is active,
* there's only one screen available. So we force the screen number to zero and
* let Xinerama specific code handle specific functionality using displaydata->xinerama_info
*/
if (use_xinerama) {
displaydata->screen = 0;
displaydata->use_xinerama = use_xinerama;
displaydata->xinerama_info = xinerama[screen];
displaydata->xinerama_screen = screen;
}
else displaydata->screen = screen;
#else
displaydata->screen = screen;
#endif
displaydata->visual = vinfo.visual;
displaydata->depth = vinfo.depth;
displaydata->scanline_pad = SDL_BYTESPERPIXEL(mode.format) * 8;
pixmapFormats = XListPixmapFormats(data->display, &n);
if (pixmapFormats) {
for (i = 0; i < n; ++i) {
if (pixmapFormats[i].depth == displaydata->depth) {
displaydata->scanline_pad = pixmapFormats[i].scanline_pad;
break;
}
}
XFree(pixmapFormats);
}
#if SDL_VIDEO_DRIVER_X11_XINERAMA
if (use_xinerama) {
displaydata->x = xinerama[screen].x_org;
displaydata->y = xinerama[screen].y_org;
}
else
#endif
{
displaydata->x = 0;
displaydata->y = 0;
}
#if SDL_VIDEO_DRIVER_X11_XRANDR
if (use_xrandr) {
res = XRRGetScreenResources(data->display, RootWindow(data->display, displaydata->screen));
}
if (res) {
XRROutputInfo *output_info;
XRRCrtcInfo *crtc;
int output;
for (output = 0; output < res->noutput; output++) {
output_info = XRRGetOutputInfo(data->display, res, res->outputs[output]);
Oct 4, 2012
Oct 4, 2012
532
533
if (!output_info || !output_info->crtc ||
output_info->connection == RR_Disconnected) {
Oct 4, 2012
Oct 4, 2012
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
XRRFreeOutputInfo(output_info);
continue;
}
/* Is this the output that corresponds to the current screen?
We're checking the crtc position, but that may not be a valid test
in all cases. Anybody want to give this some love?
*/
crtc = XRRGetCrtcInfo(data->display, res, output_info->crtc);
if (!crtc || crtc->x != displaydata->x || crtc->y != displaydata->y) {
XRRFreeOutputInfo(output_info);
XRRFreeCrtcInfo(crtc);
continue;
}
displaydata->use_xrandr = use_xrandr;
displaydata->xrandr_output = res->outputs[output];
SetXRandRModeInfo(data->display, res, output_info, crtc->mode, &mode);
XRRFreeOutputInfo(output_info);
XRRFreeCrtcInfo(crtc);
break;
}
#ifdef X11MODES_DEBUG
if (output == res->noutput) {
printf("Couldn't find XRandR CRTC at %d,%d\n", displaydata->x, displaydata->y);
}
#endif
XRRFreeScreenResources(res);
}
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
if (!displaydata->use_xrandr &&
#if SDL_VIDEO_DRIVER_X11_XINERAMA
(!displaydata->use_xinerama || displaydata->xinerama_info.screen_number == 0) &&
#endif
use_vidmode) {
displaydata->use_vidmode = use_vidmode;
XF86VidModeGetModeInfo(data->display, screen, &modedata->vm_mode);
}
Jun 22, 2011
Jun 22, 2011
575
576
#endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
Oct 4, 2012
Oct 4, 2012
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
SDL_zero(display);
display.desktop_mode = mode;
display.current_mode = mode;
display.driverdata = displaydata;
SDL_AddVideoDisplay(&display);
}
#if SDL_VIDEO_DRIVER_X11_XINERAMA
if (xinerama) XFree(xinerama);
#endif
if (_this->num_displays == 0) {
SDL_SetError("No available displays");
return -1;
}
return 0;
}
Jun 22, 2011
Jun 22, 2011
595
596
597
598
599
600
601
602
603
604
605
606
void
X11_GetDisplayModes(_THIS, SDL_VideoDisplay * sdl_display)
{
Display *display = ((SDL_VideoData *) _this->driverdata)->display;
SDL_DisplayData *data = (SDL_DisplayData *) sdl_display->driverdata;
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
int nmodes;
XF86VidModeModeInfo ** modes;
#endif
int screen_w;
int screen_h;
SDL_DisplayMode mode;
Oct 4, 2012
Oct 4, 2012
607
SDL_DisplayModeData *modedata;
Jun 22, 2011
Jun 22, 2011
608
609
610
611
612
613
614
615
616
617
618
619
620
621
/* Unfortunately X11 requires the window to be created with the correct
* visual and depth ahead of time, but the SDL API allows you to create
* a window before setting the fullscreen display mode. This means that
* we have to use the same format for all windows and all display modes.
* (or support recreating the window with a new visual behind the scenes)
*/
mode.format = sdl_display->current_mode.format;
mode.driverdata = NULL;
screen_w = DisplayWidth(display, data->screen);
screen_h = DisplayHeight(display, data->screen);
#if SDL_VIDEO_DRIVER_X11_XINERAMA
Jun 19, 2012
Jun 19, 2012
622
623
624
625
626
627
if (data->use_xinerama) {
/* Add the full (both screens combined) xinerama mode only on the display that starts at 0,0 */
if (!data->xinerama_info.x_org && !data->xinerama_info.y_org &&
(screen_w > data->xinerama_info.width || screen_h > data->xinerama_info.height)) {
mode.w = screen_w;
mode.h = screen_h;
Jun 22, 2011
Jun 22, 2011
628
mode.refresh_rate = 0;
Oct 4, 2012
Oct 4, 2012
629
630
631
632
633
modedata = (SDL_DisplayModeData *) SDL_calloc(1, sizeof(SDL_DisplayModeData));
if (modedata) {
*modedata = *(SDL_DisplayModeData *)sdl_display->desktop_mode.driverdata;
}
mode.driverdata = modedata;
Jun 22, 2011
Jun 22, 2011
634
635
636
637
638
639
SDL_AddDisplayMode(sdl_display, &mode);
}
}
#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
#if SDL_VIDEO_DRIVER_X11_XRANDR
Oct 4, 2012
Oct 4, 2012
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
if (data->use_xrandr) {
XRRScreenResources *res;
res = XRRGetScreenResources (display, RootWindow(display, data->screen));
if (res) {
SDL_DisplayModeData *modedata;
XRROutputInfo *output_info;
int i;
output_info = XRRGetOutputInfo(display, res, data->xrandr_output);
if (output_info && output_info->connection != RR_Disconnected) {
for (i = 0; i < output_info->nmode; ++i) {
modedata = (SDL_DisplayModeData *) SDL_calloc(1, sizeof(SDL_DisplayModeData));
if (!modedata) {
continue;
}
mode.driverdata = modedata;
Jun 22, 2011
Jun 22, 2011
657
Oct 4, 2012
Oct 4, 2012
658
659
660
661
662
if (SetXRandRModeInfo(display, res, output_info, output_info->modes[i], &mode)) {
SDL_AddDisplayMode(sdl_display, &mode);
} else {
SDL_free(modedata);
}
Jun 22, 2011
Jun 22, 2011
663
664
}
}
Oct 4, 2012
Oct 4, 2012
665
666
XRRFreeOutputInfo(output_info);
XRRFreeScreenResources(res);
Jun 22, 2011
Jun 22, 2011
667
}
Oct 4, 2012
Oct 4, 2012
668
return;
Jun 22, 2011
Jun 22, 2011
669
670
671
672
}
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
Oct 4, 2012
Oct 4, 2012
673
if (data->use_vidmode &&
Jun 22, 2011
Jun 22, 2011
674
675
676
677
678
679
680
681
XF86VidModeGetAllModeLines(display, data->screen, &nmodes, &modes)) {
int i;
#ifdef X11MODES_DEBUG
printf("VidMode modes: (unsorted)\n");
for (i = 0; i < nmodes; ++i) {
printf("Mode %d: %d x %d @ %d\n", i,
modes[i]->hdisplay, modes[i]->vdisplay,
Oct 4, 2012
Oct 4, 2012
682
CalculateXVidModeRefreshRate(modes[i]));
Jun 22, 2011
Jun 22, 2011
683
684
685
}
#endif
for (i = 0; i < nmodes; ++i) {
Oct 4, 2012
Oct 4, 2012
686
687
688
689
690
691
692
693
694
695
696
modedata = (SDL_DisplayModeData *) SDL_calloc(1, sizeof(SDL_DisplayModeData));
if (!modedata) {
continue;
}
mode.driverdata = modedata;
if (SetXVidModeModeInfo(modes[i], &mode)) {
SDL_AddDisplayMode(sdl_display, &mode);
} else {
SDL_free(modedata);
}
Jun 22, 2011
Jun 22, 2011
697
698
}
XFree(modes);
Oct 4, 2012
Oct 4, 2012
699
return;
Jun 22, 2011
Jun 22, 2011
700
701
702
703
}
#endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
if (!data->use_xrandr && !data->use_vidmode) {
Oct 4, 2012
Oct 4, 2012
704
705
706
707
708
709
710
/* Add the desktop mode */
mode = sdl_display->desktop_mode;
modedata = (SDL_DisplayModeData *) SDL_calloc(1, sizeof(SDL_DisplayModeData));
if (modedata) {
*modedata = *(SDL_DisplayModeData *)sdl_display->desktop_mode.driverdata;
}
mode.driverdata = modedata;
Jun 22, 2011
Jun 22, 2011
711
712
713
714
SDL_AddDisplayMode(sdl_display, &mode);
}
}
Oct 4, 2012
Oct 4, 2012
715
716
int
X11_SetDisplayMode(_THIS, SDL_VideoDisplay * sdl_display, SDL_DisplayMode * mode)
Jun 22, 2011
Jun 22, 2011
717
{
Oct 4, 2012
Oct 4, 2012
718
719
720
721
Display *display = ((SDL_VideoData *) _this->driverdata)->display;
SDL_DisplayData *data = (SDL_DisplayData *) sdl_display->driverdata;
SDL_DisplayModeData *modedata = (SDL_DisplayModeData *)mode->driverdata;
Jun 22, 2011
Jun 22, 2011
722
723
#if SDL_VIDEO_DRIVER_X11_XRANDR
if (data->use_xrandr) {
Oct 4, 2012
Oct 4, 2012
724
725
726
727
728
729
730
731
732
XRRScreenResources *res;
XRROutputInfo *output_info;
XRRCrtcInfo *crtc;
Status status;
res = XRRGetScreenResources (display, RootWindow(display, data->screen));
if (!res) {
SDL_SetError("Couldn't get XRandR screen resources");
return -1;
Jun 22, 2011
Jun 22, 2011
733
734
}
Oct 4, 2012
Oct 4, 2012
735
736
737
738
739
output_info = XRRGetOutputInfo(display, res, data->xrandr_output);
if (!output_info || output_info->connection == RR_Disconnected) {
SDL_SetError("Couldn't get XRandR output info");
XRRFreeScreenResources(res);
return -1;
Jun 22, 2011
Jun 22, 2011
740
741
}
Oct 4, 2012
Oct 4, 2012
742
743
744
745
746
747
crtc = XRRGetCrtcInfo(display, res, output_info->crtc);
if (!crtc) {
SDL_SetError("Couldn't get XRandR crtc info");
XRRFreeOutputInfo(output_info);
XRRFreeScreenResources(res);
return -1;
Sep 28, 2012
Sep 28, 2012
748
749
}
Oct 4, 2012
Oct 4, 2012
750
751
752
status = XRRSetCrtcConfig (display, res, output_info->crtc, CurrentTime,
crtc->x, crtc->y, modedata->xrandr_mode, crtc->rotation,
&data->xrandr_output, 1);
Oct 3, 2012
Oct 3, 2012
753
Oct 4, 2012
Oct 4, 2012
754
755
756
XRRFreeCrtcInfo(crtc);
XRRFreeOutputInfo(output_info);
XRRFreeScreenResources(res);
Oct 3, 2012
Oct 3, 2012
757
Oct 4, 2012
Oct 4, 2012
758
759
760
if (status != Success) {
SDL_SetError("XRRSetCrtcConfig failed");
return -1;
Jun 22, 2011
Jun 22, 2011
761
762
763
764
765
766
}
}
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
if (data->use_vidmode) {
Oct 4, 2012
Oct 4, 2012
767
XF86VidModeSwitchToMode(display, data->screen, &modedata->vm_mode);
Jun 22, 2011
Jun 22, 2011
768
769
770
771
772
773
774
775
776
777
778
}
#endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
return 0;
}
void
X11_QuitModes(_THIS)
{
}
Jun 19, 2012
Jun 19, 2012
779
780
781
int
X11_GetDisplayBounds(_THIS, SDL_VideoDisplay * sdl_display, SDL_Rect * rect)
{
Sep 28, 2012
Sep 28, 2012
782
Display *display = ((SDL_VideoData *) _this->driverdata)->display;
Jun 19, 2012
Jun 19, 2012
783
SDL_DisplayData *data = (SDL_DisplayData *) sdl_display->driverdata;
Sep 28, 2012
Sep 28, 2012
784
Oct 4, 2012
Oct 4, 2012
785
786
787
788
rect->x = data->x;
rect->y = data->y;
rect->w = sdl_display->current_mode.w;
rect->h = sdl_display->current_mode.h;
Jun 19, 2012
Jun 19, 2012
789
790
#if SDL_VIDEO_DRIVER_X11_XINERAMA
Oct 4, 2012
Oct 4, 2012
791
/* Get the real current bounds of the display */
Sep 28, 2012
Sep 28, 2012
792
if (data->use_xinerama) {
Oct 4, 2012
Oct 4, 2012
793
794
795
796
797
798
int screencount;
XineramaScreenInfo *xinerama = XineramaQueryScreens(display, &screencount);
if (xinerama) {
rect->x = xinerama[data->xinerama_screen].x_org;
rect->y = xinerama[data->xinerama_screen].y_org;
}
Jun 19, 2012
Jun 19, 2012
799
}
Oct 4, 2012
Oct 4, 2012
800
#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
Sep 27, 2012
Sep 27, 2012
801
return 0;
Jun 19, 2012
Jun 19, 2012
802
803
}
Jun 22, 2011
Jun 22, 2011
804
805
806
#endif /* SDL_VIDEO_DRIVER_X11 */
/* vi: set ts=4 sw=4 expandtab: */