comparison src/video/x11/SDL_x11modes.c @ 227:24878c14b391

Added X11 Xinerama support - fullscreen starts on screen 0
author Sam Lantinga <slouken@libsdl.org>
date Sat, 03 Nov 2001 17:03:16 +0000
parents a1c973c35fef
children 275a934573a7
comparison
equal deleted inserted replaced
226:bb72c418a1f9 227:24878c14b391
37 #include "SDL_x11video.h" 37 #include "SDL_x11video.h"
38 #include "SDL_x11wm_c.h" 38 #include "SDL_x11wm_c.h"
39 #include "SDL_x11modes_c.h" 39 #include "SDL_x11modes_c.h"
40 #include "SDL_x11image_c.h" 40 #include "SDL_x11image_c.h"
41 41
42 #ifdef HAVE_XINERAMA
43 #include <X11/extensions/Xinerama.h>
44 #endif
42 45
43 #ifdef XFREE86_VM 46 #ifdef XFREE86_VM
44 Bool XVidMode(GetModeInfo, (Display *dpy, int scr, XF86VidModeModeInfo *info)) 47 Bool XVidMode(GetModeInfo, (Display *dpy, int scr, XF86VidModeModeInfo *info))
45 { 48 {
46 XF86VidModeModeLine *l = (XF86VidModeModeLine*)((char*)info + sizeof info->dotclock); 49 XF86VidModeModeLine *l = (XF86VidModeModeLine*)((char*)info + sizeof info->dotclock);
97 100
98 if ( XVidMode(GetModeLine, (SDL_Display, SDL_Screen, &i, &mode)) && 101 if ( XVidMode(GetModeLine, (SDL_Display, SDL_Screen, &i, &mode)) &&
99 XVidMode(GetAllModeLines, (SDL_Display,SDL_Screen,&nmodes,&modes))){ 102 XVidMode(GetAllModeLines, (SDL_Display,SDL_Screen,&nmodes,&modes))){
100 qsort(modes, nmodes, sizeof *modes, cmpmodes); 103 qsort(modes, nmodes, sizeof *modes, cmpmodes);
101 #ifdef XFREE86_DEBUG 104 #ifdef XFREE86_DEBUG
102 printf("Available modes:\n"); 105 printf("Available modes:\n");
103 for ( i = 0; i < nmodes; ++i ) { 106 for ( i = 0; i < nmodes; ++i ) {
104 printf("Mode %d: %dx%d\n", i, modes[i]->hdisplay, modes[i]->vdisplay); 107 printf("Mode %d: %dx%d\n", i,
105 } 108 modes[i]->hdisplay, modes[i]->vdisplay);
109 }
106 #endif 110 #endif
107 for ( i = nmodes-1; i > 0 ; --i ) { 111 for ( i = nmodes-1; i > 0 ; --i ) {
108 if ( (modes[i]->hdisplay >= width) && 112 if ( (modes[i]->hdisplay >= width) &&
109 (modes[i]->vdisplay >= height) ) 113 (modes[i]->vdisplay >= height) )
110 break; 114 break;
236 XVidMode(QueryVersion, (SDL_Display, &vm_major, &vm_minor)) ) { 240 XVidMode(QueryVersion, (SDL_Display, &vm_major, &vm_minor)) ) {
237 #ifdef BROKEN_XFREE86_4001 241 #ifdef BROKEN_XFREE86_4001
238 #ifdef X_XF86VidModeGetDotClocks /* Compiled under XFree86 4.0 */ 242 #ifdef X_XF86VidModeGetDotClocks /* Compiled under XFree86 4.0 */
239 /* Earlier X servers hang when doing vidmode */ 243 /* Earlier X servers hang when doing vidmode */
240 if ( vm_major < 2 ) { 244 if ( vm_major < 2 ) {
241 #ifdef DEBUG_XF86 245 #ifdef XFREE86_DEBUG
242 printf("Compiled under XFree86 4.0, server is XFree86 3.X\n"); 246 printf("Compiled under XFree86 4.0, server is XFree86 3.X\n");
243 #endif 247 #endif
244 buggy_X11 = 1; 248 buggy_X11 = 1;
245 } 249 }
246 #else 250 #else
247 /* XFree86 3.X code works with XFree86 4.0 servers */; 251 /* XFree86 3.X code works with XFree86 4.0 servers */;
333 } 337 }
334 SDL_modelist[i] = NULL; 338 SDL_modelist[i] = NULL;
335 } 339 }
336 } 340 }
337 341
338 #ifdef DEBUG_XF86 342 #ifdef XFREE86_DEBUG
339 if ( use_vidmode ) { 343 if ( use_vidmode ) {
340 fprintf(stderr, "XFree86 VidMode is enabled\n"); 344 printf("XFree86 VidMode is enabled\n");
341 } 345 }
342 if ( SDL_modelist ) { 346 if ( SDL_modelist ) {
343 fprintf(stderr, "X11 video mode list:\n"); 347 printf("X11 video mode list:\n");
344 for ( i=0; SDL_modelist[i]; ++i ) { 348 for ( i=0; SDL_modelist[i]; ++i ) {
345 fprintf(stderr, "\t%dx%d\n", 349 printf("\t%dx%d\n", SDL_modelist[i]->w, SDL_modelist[i]->h);
346 SDL_modelist[i]->w, SDL_modelist[i]->h); 350 }
347 } 351 }
348 } 352 #endif /* XFREE86_DEBUG */
349 #endif /* DEBUG_XF86 */ 353
354 /* The default X/Y fullscreen offset is 0/0 */
355 xinerama_x = 0;
356 xinerama_y = 0;
357
358 #ifdef HAVE_XINERAMA
359 /* Query Xinerama extention */
360 if ( XineramaQueryExtension(SDL_Display, &i, &i) &&
361 XineramaIsActive(SDL_Display) ) {
362 /* Find out which screen is the zero'th one */
363 int screens;
364 XineramaScreenInfo *xinerama;
365
366 #ifdef XINERAMA_DEBUG
367 printf("X11 detected Xinerama:\n");
368 #endif
369 xinerama = XineramaQueryScreens(SDL_Display, &screens);
370 for ( i = 0; i < screens; i++ ) {
371 #ifdef XINERAMA_DEBUG
372 printf("xinerama %d: %dx%d+%d+%d\n",
373 xinerama[i].screen_number,
374 xinerama[i].width, xinerama[i].height,
375 xinerama[i].x_org, xinerama[i].y_org);
376 #endif
377 if ( xinerama[i].screen_number == 0 ) {
378 xinerama_x = xinerama[i].x_org;
379 xinerama_y = xinerama[i].y_org;
380 }
381 }
382 XFree(xinerama);
383 }
384 #endif /* HAVE_XINERAMA */
385
350 return 0; 386 return 0;
351 } 387 }
352 388
353 int X11_SupportedVisual(_THIS, SDL_PixelFormat *format) 389 int X11_SupportedVisual(_THIS, SDL_PixelFormat *format)
354 { 390 {
388 int X11_ResizeFullScreen(_THIS) 424 int X11_ResizeFullScreen(_THIS)
389 { 425 {
390 int x, y; 426 int x, y;
391 int real_w, real_h; 427 int real_w, real_h;
392 428
429 x = xinerama_x;
430 y = xinerama_y;
393 if ( currently_fullscreen ) { 431 if ( currently_fullscreen ) {
394 /* Switch resolution and cover it with the FSwindow */ 432 /* Switch resolution and cover it with the FSwindow */
395 move_cursor_to(this, 0, 0); 433 move_cursor_to(this, x, y);
396 set_best_resolution(this, current_w, current_h); 434 set_best_resolution(this, current_w, current_h);
397 move_cursor_to(this, 0, 0); 435 move_cursor_to(this, x, y);
398 get_real_resolution(this, &real_w, &real_h); 436 get_real_resolution(this, &real_w, &real_h);
399 XMoveResizeWindow(SDL_Display, FSwindow, 0, 0, real_w, real_h); 437 XMoveResizeWindow(SDL_Display, FSwindow, x, y, real_w, real_h);
400 move_cursor_to(this, real_w/2, real_h/2); 438 move_cursor_to(this, real_w/2, real_h/2);
401 439
402 /* Center and reparent the drawing window */ 440 /* Center and reparent the drawing window */
403 x = (real_w - current_w)/2; 441 x = (real_w - current_w)/2;
404 y = (real_h - current_h)/2; 442 y = (real_h - current_h)/2;