comparison src/video/x11/SDL_x11modes.c @ 1168:045f186426e1

Dynamically load X11 libraries like we currently do for alsa, esd, etc. This allows you to run an SDL program on a system without Xlib, since it'll just report the x11 target unavailable at runtime.
author Ryan C. Gordon <icculus@icculus.org>
date Sat, 05 Nov 2005 19:53:37 +0000
parents f72cc0c7305f
children b81f54c3963f
comparison
equal deleted inserted replaced
1167:435c2e481299 1168:045f186426e1
139 match: 139 match:
140 if ( (modes[i]->hdisplay != mode.hdisplay) || 140 if ( (modes[i]->hdisplay != mode.hdisplay) ||
141 (modes[i]->vdisplay != mode.vdisplay) ) { 141 (modes[i]->vdisplay != mode.vdisplay) ) {
142 SDL_NAME(XF86VidModeSwitchToMode)(SDL_Display, SDL_Screen, modes[i]); 142 SDL_NAME(XF86VidModeSwitchToMode)(SDL_Display, SDL_Screen, modes[i]);
143 } 143 }
144 XFree(modes); 144 pXFree(modes);
145 } 145 }
146 } 146 }
147 #endif /* XFREE86_VM */ 147 #endif /* XFREE86_VM */
148 148
149 /* XiG */ 149 /* XiG */
178 SDL_Screen, 178 SDL_Screen,
179 0, /* view */ 179 0, /* view */
180 SDL_modelist[i]->w, 180 SDL_modelist[i]->w,
181 SDL_modelist[i]->h, 181 SDL_modelist[i]->h,
182 0); 182 0);
183 XSync(SDL_Display, False); 183 pXSync(SDL_Display, False);
184 } 184 }
185 } 185 }
186 } 186 }
187 #endif /* HAVE_XIGXME */ 187 #endif /* HAVE_XIGXME */
188 188
228 /* Called after mapping a window - waits until the window is mapped */ 228 /* Called after mapping a window - waits until the window is mapped */
229 void X11_WaitMapped(_THIS, Window win) 229 void X11_WaitMapped(_THIS, Window win)
230 { 230 {
231 XEvent event; 231 XEvent event;
232 do { 232 do {
233 XMaskEvent(SDL_Display, StructureNotifyMask, &event); 233 pXMaskEvent(SDL_Display, StructureNotifyMask, &event);
234 } while ( (event.type != MapNotify) || (event.xmap.event != win) ); 234 } while ( (event.type != MapNotify) || (event.xmap.event != win) );
235 } 235 }
236 236
237 /* Called after unmapping a window - waits until the window is unmapped */ 237 /* Called after unmapping a window - waits until the window is unmapped */
238 void X11_WaitUnmapped(_THIS, Window win) 238 void X11_WaitUnmapped(_THIS, Window win)
239 { 239 {
240 XEvent event; 240 XEvent event;
241 do { 241 do {
242 XMaskEvent(SDL_Display, StructureNotifyMask, &event); 242 pXMaskEvent(SDL_Display, StructureNotifyMask, &event);
243 } while ( (event.type != UnmapNotify) || (event.xunmap.event != win) ); 243 } while ( (event.type != UnmapNotify) || (event.xunmap.event != win) );
244 } 244 }
245 245
246 static void move_cursor_to(_THIS, int x, int y) 246 static void move_cursor_to(_THIS, int x, int y)
247 { 247 {
248 XWarpPointer(SDL_Display, None, SDL_Root, 0, 0, 0, 0, x, y); 248 pXWarpPointer(SDL_Display, None, SDL_Root, 0, 0, 0, 0, x, y);
249 } 249 }
250 250
251 static int add_visual(_THIS, int depth, int class) 251 static int add_visual(_THIS, int depth, int class)
252 { 252 {
253 XVisualInfo vi; 253 XVisualInfo vi;
254 if(XMatchVisualInfo(SDL_Display, SDL_Screen, depth, class, &vi)) { 254 if(pXMatchVisualInfo(SDL_Display, SDL_Screen, depth, class, &vi)) {
255 int n = this->hidden->nvisuals; 255 int n = this->hidden->nvisuals;
256 this->hidden->visuals[n].depth = vi.depth; 256 this->hidden->visuals[n].depth = vi.depth;
257 this->hidden->visuals[n].visual = vi.visual; 257 this->hidden->visuals[n].visual = vi.visual;
258 this->hidden->nvisuals++; 258 this->hidden->nvisuals++;
259 } 259 }
265 int nvis; 265 int nvis;
266 266
267 if ( visual_id ) { 267 if ( visual_id ) {
268 memset(&template, 0, (sizeof template)); 268 memset(&template, 0, (sizeof template));
269 template.visualid = strtol(visual_id, NULL, 0); 269 template.visualid = strtol(visual_id, NULL, 0);
270 vi = XGetVisualInfo(SDL_Display, VisualIDMask, &template, &nvis); 270 vi = pXGetVisualInfo(SDL_Display, VisualIDMask, &template, &nvis);
271 if ( vi ) { 271 if ( vi ) {
272 int n = this->hidden->nvisuals; 272 int n = this->hidden->nvisuals;
273 this->hidden->visuals[n].depth = vi->depth; 273 this->hidden->visuals[n].depth = vi->depth;
274 this->hidden->visuals[n].visual = vi->visual; 274 this->hidden->visuals[n].visual = vi->visual;
275 this->hidden->nvisuals++; 275 this->hidden->nvisuals++;
276 XFree(vi); 276 pXFree(vi);
277 } 277 }
278 } 278 }
279 return(this->hidden->nvisuals); 279 return(this->hidden->nvisuals);
280 } 280 }
281 281
398 SDL_modelist[n]->h = h; 398 SDL_modelist[n]->h = h;
399 ++n; 399 ++n;
400 } 400 }
401 SDL_modelist[n] = NULL; 401 SDL_modelist[n] = NULL;
402 } 402 }
403 XFree(modes); 403 pXFree(modes);
404 404
405 use_vidmode = vm_major * 100 + vm_minor; 405 use_vidmode = vm_major * 100 + vm_minor;
406 save_mode(this); 406 save_mode(this);
407 } 407 }
408 #endif /* XFREE86_VM */ 408 #endif /* XFREE86_VM */
472 saved_res = modelist[ractive]; /* save the current resolution */ 472 saved_res = modelist[ractive]; /* save the current resolution */
473 } else { 473 } else {
474 use_xme = 0; 474 use_xme = 0;
475 } 475 }
476 if ( modelist ) { 476 if ( modelist ) {
477 XFree(modelist); 477 pXFree(modelist);
478 } 478 }
479 #endif /* HAVE_XIGXME */ 479 #endif /* HAVE_XIGXME */
480 480
481 { 481 {
482 static int depth_list[] = { 32, 24, 16, 15, 8 }; 482 static int depth_list[] = { 32, 24, 16, 15, 8 };
507 SDL_SetError("Found no sufficiently capable X11 visuals"); 507 SDL_SetError("Found no sufficiently capable X11 visuals");
508 return -1; 508 return -1;
509 } 509 }
510 510
511 /* look up the pixel quantum for each depth */ 511 /* look up the pixel quantum for each depth */
512 pf = XListPixmapFormats(SDL_Display, &np); 512 pf = pXListPixmapFormats(SDL_Display, &np);
513 for(i = 0; i < this->hidden->nvisuals; i++) { 513 for(i = 0; i < this->hidden->nvisuals; i++) {
514 int d = this->hidden->visuals[i].depth; 514 int d = this->hidden->visuals[i].depth;
515 for(j = 0; j < np; j++) 515 for(j = 0; j < np; j++)
516 if(pf[j].depth == d) 516 if(pf[j].depth == d)
517 break; 517 break;
518 this->hidden->visuals[i].bpp = j < np ? pf[j].bits_per_pixel : d; 518 this->hidden->visuals[i].bpp = j < np ? pf[j].bits_per_pixel : d;
519 } 519 }
520 520
521 XFree(pf); 521 pXFree(pf);
522 } 522 }
523 523
524 if ( SDL_modelist == NULL ) { 524 if ( SDL_modelist == NULL ) {
525 SDL_modelist = (SDL_Rect **)malloc((1+1)*sizeof(SDL_Rect *)); 525 SDL_modelist = (SDL_Rect **)malloc((1+1)*sizeof(SDL_Rect *));
526 if ( SDL_modelist ) { 526 if ( SDL_modelist ) {
590 if ( xinerama[i].screen_number == desired ) { 590 if ( xinerama[i].screen_number == desired ) {
591 xinerama_x = xinerama[i].x_org; 591 xinerama_x = xinerama[i].x_org;
592 xinerama_y = xinerama[i].y_org; 592 xinerama_y = xinerama[i].y_org;
593 } 593 }
594 } 594 }
595 XFree(xinerama); 595 pXFree(xinerama);
596 } 596 }
597 #endif /* HAVE_XINERAMA */ 597 #endif /* HAVE_XINERAMA */
598 598
599 return 0; 599 return 0;
600 } 600 }
656 real_w = MAX(real_w, screen_w); 656 real_w = MAX(real_w, screen_w);
657 } 657 }
658 if ( current_h > real_h ) { 658 if ( current_h > real_h ) {
659 real_h = MAX(real_h, screen_h); 659 real_h = MAX(real_h, screen_h);
660 } 660 }
661 XMoveResizeWindow(SDL_Display, FSwindow, x, y, real_w, real_h); 661 pXMoveResizeWindow(SDL_Display, FSwindow, x, y, real_w, real_h);
662 move_cursor_to(this, real_w/2, real_h/2); 662 move_cursor_to(this, real_w/2, real_h/2);
663 663
664 /* Center and reparent the drawing window */ 664 /* Center and reparent the drawing window */
665 x = (real_w - current_w)/2; 665 x = (real_w - current_w)/2;
666 y = (real_h - current_h)/2; 666 y = (real_h - current_h)/2;
667 XReparentWindow(SDL_Display, SDL_Window, FSwindow, x, y); 667 pXReparentWindow(SDL_Display, SDL_Window, FSwindow, x, y);
668 /* FIXME: move the mouse to the old relative location */ 668 /* FIXME: move the mouse to the old relative location */
669 XSync(SDL_Display, True); /* Flush spurious mode change events */ 669 pXSync(SDL_Display, True); /* Flush spurious mode change events */
670 } 670 }
671 return(1); 671 return(1);
672 } 672 }
673 673
674 void X11_QueueEnterFullScreen(_THIS) 674 void X11_QueueEnterFullScreen(_THIS)
675 { 675 {
676 switch_waiting = 0x01 | SDL_FULLSCREEN; 676 switch_waiting = 0x01 | SDL_FULLSCREEN;
677 switch_time = SDL_GetTicks() + 1500; 677 switch_time = SDL_GetTicks() + 1500;
678 #if 0 /* This causes a BadMatch error if the window is iconified (not needed) */ 678 #if 0 /* This causes a BadMatch error if the window is iconified (not needed) */
679 XSetInputFocus(SDL_Display, WMwindow, RevertToNone, CurrentTime); 679 pXSetInputFocus(SDL_Display, WMwindow, RevertToNone, CurrentTime);
680 #endif 680 #endif
681 } 681 }
682 682
683 int X11_EnterFullScreen(_THIS) 683 int X11_EnterFullScreen(_THIS)
684 { 684 {
707 real_w = MAX(real_w, screen_w); 707 real_w = MAX(real_w, screen_w);
708 } 708 }
709 if ( current_h > real_h ) { 709 if ( current_h > real_h ) {
710 real_h = MAX(real_h, screen_h); 710 real_h = MAX(real_h, screen_h);
711 } 711 }
712 XMoveResizeWindow(SDL_Display, FSwindow, 712 pXMoveResizeWindow(SDL_Display, FSwindow,
713 xinerama_x, xinerama_y, real_w, real_h); 713 xinerama_x, xinerama_y, real_w, real_h);
714 XMapRaised(SDL_Display, FSwindow); 714 pXMapRaised(SDL_Display, FSwindow);
715 X11_WaitMapped(this, FSwindow); 715 X11_WaitMapped(this, FSwindow);
716 716
717 #if 0 /* This seems to break WindowMaker in focus-follows-mouse mode */ 717 #if 0 /* This seems to break WindowMaker in focus-follows-mouse mode */
718 /* Make sure we got to the top of the window stack */ 718 /* Make sure we got to the top of the window stack */
719 if ( XQueryTree(SDL_Display, SDL_Root, &tmpwin, &tmpwin, 719 if ( pXQueryTree(SDL_Display, SDL_Root, &tmpwin, &tmpwin,
720 &windows, &nwindows) && windows ) { 720 &windows, &nwindows) && windows ) {
721 /* If not, try to put us there - if fail... oh well */ 721 /* If not, try to put us there - if fail... oh well */
722 if ( windows[nwindows-1] != FSwindow ) { 722 if ( windows[nwindows-1] != FSwindow ) {
723 tmpwin = windows[nwindows-1]; 723 tmpwin = windows[nwindows-1];
724 for ( i=0; i<nwindows; ++i ) { 724 for ( i=0; i<nwindows; ++i ) {
727 (nwindows-i-1)*sizeof(windows[i])); 727 (nwindows-i-1)*sizeof(windows[i]));
728 break; 728 break;
729 } 729 }
730 } 730 }
731 windows[nwindows-1] = FSwindow; 731 windows[nwindows-1] = FSwindow;
732 XRestackWindows(SDL_Display, windows, nwindows); 732 pXRestackWindows(SDL_Display, windows, nwindows);
733 XSync(SDL_Display, False); 733 pXSync(SDL_Display, False);
734 } 734 }
735 XFree(windows); 735 pXFree(windows);
736 } 736 }
737 #else 737 #else
738 XRaiseWindow(SDL_Display, FSwindow); 738 pXRaiseWindow(SDL_Display, FSwindow);
739 #endif 739 #endif
740 740
741 #ifdef XFREE86_VM 741 #ifdef XFREE86_VM
742 /* Save the current video mode */ 742 /* Save the current video mode */
743 if ( use_vidmode ) { 743 if ( use_vidmode ) {
751 if ( ! okay ) { 751 if ( ! okay ) {
752 X11_LeaveFullScreen(this); 752 X11_LeaveFullScreen(this);
753 } 753 }
754 /* Set the colormap */ 754 /* Set the colormap */
755 if ( SDL_XColorMap ) { 755 if ( SDL_XColorMap ) {
756 XInstallColormap(SDL_Display, SDL_XColorMap); 756 pXInstallColormap(SDL_Display, SDL_XColorMap);
757 } 757 }
758 if ( okay ) 758 if ( okay )
759 X11_GrabInputNoLock(this, this->input_grab | SDL_GRAB_FULLSCREEN); 759 X11_GrabInputNoLock(this, this->input_grab | SDL_GRAB_FULLSCREEN);
760 760
761 /* We may need to refresh the screen at this point (no backing store) 761 /* We may need to refresh the screen at this point (no backing store)
772 } 772 }
773 773
774 int X11_LeaveFullScreen(_THIS) 774 int X11_LeaveFullScreen(_THIS)
775 { 775 {
776 if ( currently_fullscreen ) { 776 if ( currently_fullscreen ) {
777 XReparentWindow(SDL_Display, SDL_Window, WMwindow, 0, 0); 777 pXReparentWindow(SDL_Display, SDL_Window, WMwindow, 0, 0);
778 #ifdef XFREE86_VM 778 #ifdef XFREE86_VM
779 if ( use_vidmode ) { 779 if ( use_vidmode ) {
780 restore_mode(this); 780 restore_mode(this);
781 SDL_NAME(XF86VidModeLockModeSwitch)(SDL_Display, SDL_Screen, False); 781 SDL_NAME(XF86VidModeLockModeSwitch)(SDL_Display, SDL_Screen, False);
782 } 782 }
794 SDL_Screen, 794 SDL_Screen,
795 0, /* view */ 795 0, /* view */
796 saved_res.width, 796 saved_res.width,
797 saved_res.height, 797 saved_res.height,
798 0); 798 0);
799 XSync(SDL_Display, False); 799 pXSync(SDL_Display, False);
800 } 800 }
801 } 801 }
802 #endif 802 #endif
803 803
804 XUnmapWindow(SDL_Display, FSwindow); 804 pXUnmapWindow(SDL_Display, FSwindow);
805 X11_WaitUnmapped(this, FSwindow); 805 X11_WaitUnmapped(this, FSwindow);
806 XSync(SDL_Display, True); /* Flush spurious mode change events */ 806 pXSync(SDL_Display, True); /* Flush spurious mode change events */
807 currently_fullscreen = 0; 807 currently_fullscreen = 0;
808 } 808 }
809 /* If we get popped out of fullscreen mode for some reason, input_grab 809 /* If we get popped out of fullscreen mode for some reason, input_grab
810 will still have the SDL_GRAB_FULLSCREEN flag set, since this is only 810 will still have the SDL_GRAB_FULLSCREEN flag set, since this is only
811 temporary. In this case, release the grab unless the input has been 811 temporary. In this case, release the grab unless the input has been