comparison src/video/x11/SDL_x11video.c @ 1575:3ba88cb7eb1b

Updated dynamic X11 code. See details in Bugzilla #170.
author Ryan C. Gordon <icculus@icculus.org>
date Wed, 22 Mar 2006 05:00:59 +0000
parents b46bb79cc197
children c3b5d17277d4
comparison
equal deleted inserted replaced
1574:0fd72308659e 1575:3ba88cb7eb1b
69 69
70 static int X11_Available(void) 70 static int X11_Available(void)
71 { 71 {
72 Display *display = NULL; 72 Display *display = NULL;
73 if ( SDL_X11_LoadSymbols() ) { 73 if ( SDL_X11_LoadSymbols() ) {
74 display = pXOpenDisplay(NULL); 74 display = XOpenDisplay(NULL);
75 if ( display != NULL ) { 75 if ( display != NULL ) {
76 pXCloseDisplay(display); 76 XCloseDisplay(display);
77 } 77 }
78 SDL_X11_UnloadSymbols(); 78 SDL_X11_UnloadSymbols();
79 } 79 }
80 return(display != NULL); 80 return(display != NULL);
81 } 81 }
197 (((e->error_code == BadRequest)&&(e->request_code == vm_error)) || 197 (((e->error_code == BadRequest)&&(e->request_code == vm_error)) ||
198 ((e->error_code > vm_error) && 198 ((e->error_code > vm_error) &&
199 (e->error_code <= (vm_error+XF86VidModeNumberErrors)))) ) { 199 (e->error_code <= (vm_error+XF86VidModeNumberErrors)))) ) {
200 #ifdef XFREE86_DEBUG 200 #ifdef XFREE86_DEBUG
201 { char errmsg[1024]; 201 { char errmsg[1024];
202 pXGetErrorText(d, e->error_code, errmsg, sizeof(errmsg)); 202 XGetErrorText(d, e->error_code, errmsg, sizeof(errmsg));
203 printf("VidMode error: %s\n", errmsg); 203 printf("VidMode error: %s\n", errmsg);
204 } 204 }
205 #endif 205 #endif
206 return(0); 206 return(0);
207 } 207 }
212 if ( (dga_error >= 0) && 212 if ( (dga_error >= 0) &&
213 ((e->error_code > dga_error) && 213 ((e->error_code > dga_error) &&
214 (e->error_code <= (dga_error+XF86DGANumberErrors))) ) { 214 (e->error_code <= (dga_error+XF86DGANumberErrors))) ) {
215 #ifdef XFREE86_DEBUG 215 #ifdef XFREE86_DEBUG
216 { char errmsg[1024]; 216 { char errmsg[1024];
217 pXGetErrorText(d, e->error_code, errmsg, sizeof(errmsg)); 217 XGetErrorText(d, e->error_code, errmsg, sizeof(errmsg));
218 printf("DGA error: %s\n", errmsg); 218 printf("DGA error: %s\n", errmsg);
219 } 219 }
220 #endif 220 #endif
221 return(0); 221 return(0);
222 } 222 }
245 static int xext_errhandler(Display *d, char *ext_name, char *reason) 245 static int xext_errhandler(Display *d, char *ext_name, char *reason)
246 { 246 {
247 #ifdef XFREE86_DEBUG 247 #ifdef XFREE86_DEBUG
248 printf("Xext error inside SDL (may be harmless):\n"); 248 printf("Xext error inside SDL (may be harmless):\n");
249 printf(" Extension \"%s\" %s on display \"%s\".\n", 249 printf(" Extension \"%s\" %s on display \"%s\".\n",
250 ext_name, reason, pXDisplayString(d)); 250 ext_name, reason, XDisplayString(d));
251 #endif 251 #endif
252 252
253 if (SDL_strcmp(reason, "missing") == 0) { 253 if (SDL_strcmp(reason, "missing") == 0) {
254 /* 254 /*
255 * Since the query itself, elsewhere, can handle a missing extension 255 * Since the query itself, elsewhere, can handle a missing extension
317 XWMHints *hints; 317 XWMHints *hints;
318 XTextProperty titleprop, titlepropUTF8, iconprop, iconpropUTF8; 318 XTextProperty titleprop, titlepropUTF8, iconprop, iconpropUTF8;
319 int def_vis = (SDL_Visual == DefaultVisual(SDL_Display, SDL_Screen)); 319 int def_vis = (SDL_Visual == DefaultVisual(SDL_Display, SDL_Screen));
320 320
321 /* Look up some useful Atoms */ 321 /* Look up some useful Atoms */
322 WM_DELETE_WINDOW = pXInternAtom(SDL_Display, "WM_DELETE_WINDOW", False); 322 WM_DELETE_WINDOW = XInternAtom(SDL_Display, "WM_DELETE_WINDOW", False);
323 _NET_WM_NAME = pXInternAtom(SDL_Display, "_NET_WM_NAME", False); 323 _NET_WM_NAME = XInternAtom(SDL_Display, "_NET_WM_NAME", False);
324 _NET_WM_ICON_NAME = pXInternAtom(SDL_Display, "_NET_WM_ICON_NAME", False); 324 _NET_WM_ICON_NAME = XInternAtom(SDL_Display, "_NET_WM_ICON_NAME", False);
325 325
326 /* Don't create any extra windows if we are being managed */ 326 /* Don't create any extra windows if we are being managed */
327 if ( SDL_windowid ) { 327 if ( SDL_windowid ) {
328 FSwindow = 0; 328 FSwindow = 0;
329 WMwindow = SDL_strtol(SDL_windowid, NULL, 0); 329 WMwindow = SDL_strtol(SDL_windowid, NULL, 0);
330 return; 330 return;
331 } 331 }
332 332
333 if(FSwindow) 333 if(FSwindow)
334 pXDestroyWindow(SDL_Display, FSwindow); 334 XDestroyWindow(SDL_Display, FSwindow);
335 335
336 xattr.override_redirect = True; 336 xattr.override_redirect = True;
337 xattr.background_pixel = def_vis ? BlackPixel(SDL_Display, SDL_Screen) : 0; 337 xattr.background_pixel = def_vis ? BlackPixel(SDL_Display, SDL_Screen) : 0;
338 xattr.border_pixel = 0; 338 xattr.border_pixel = 0;
339 xattr.colormap = SDL_XColorMap; 339 xattr.colormap = SDL_XColorMap;
340 340
341 FSwindow = pXCreateWindow(SDL_Display, SDL_Root, 341 FSwindow = XCreateWindow(SDL_Display, SDL_Root,
342 xinerama_x, xinerama_y, 32, 32, 0, 342 xinerama_x, xinerama_y, 32, 32, 0,
343 this->hidden->depth, InputOutput, SDL_Visual, 343 this->hidden->depth, InputOutput, SDL_Visual,
344 CWOverrideRedirect | CWBackPixel | CWBorderPixel 344 CWOverrideRedirect | CWBackPixel | CWBorderPixel
345 | CWColormap, 345 | CWColormap,
346 &xattr); 346 &xattr);
347 347
348 pXSelectInput(SDL_Display, FSwindow, StructureNotifyMask); 348 XSelectInput(SDL_Display, FSwindow, StructureNotifyMask);
349 349
350 /* Tell KDE to keep the fullscreen window on top */ 350 /* Tell KDE to keep the fullscreen window on top */
351 { 351 {
352 XEvent ev; 352 XEvent ev;
353 long mask; 353 long mask;
354 354
355 SDL_memset(&ev, 0, sizeof(ev)); 355 SDL_memset(&ev, 0, sizeof(ev));
356 ev.xclient.type = ClientMessage; 356 ev.xclient.type = ClientMessage;
357 ev.xclient.window = SDL_Root; 357 ev.xclient.window = SDL_Root;
358 ev.xclient.message_type = pXInternAtom(SDL_Display, 358 ev.xclient.message_type = XInternAtom(SDL_Display,
359 "KWM_KEEP_ON_TOP", False); 359 "KWM_KEEP_ON_TOP", False);
360 ev.xclient.format = 32; 360 ev.xclient.format = 32;
361 ev.xclient.data.l[0] = FSwindow; 361 ev.xclient.data.l[0] = FSwindow;
362 ev.xclient.data.l[1] = CurrentTime; 362 ev.xclient.data.l[1] = CurrentTime;
363 mask = SubstructureRedirectMask; 363 mask = SubstructureRedirectMask;
364 pXSendEvent(SDL_Display, SDL_Root, False, mask, &ev); 364 XSendEvent(SDL_Display, SDL_Root, False, mask, &ev);
365 } 365 }
366 366
367 hints = NULL; 367 hints = NULL;
368 titleprop.value = titlepropUTF8.value = NULL; 368 titleprop.value = titlepropUTF8.value = NULL;
369 iconprop.value = iconpropUTF8.value = NULL; 369 iconprop.value = iconpropUTF8.value = NULL;
370 if(WMwindow) { 370 if(WMwindow) {
371 /* All window attributes must survive the recreation */ 371 /* All window attributes must survive the recreation */
372 hints = pXGetWMHints(SDL_Display, WMwindow); 372 hints = XGetWMHints(SDL_Display, WMwindow);
373 pXGetTextProperty(SDL_Display, WMwindow, &titleprop, XA_WM_NAME); 373 XGetTextProperty(SDL_Display, WMwindow, &titleprop, XA_WM_NAME);
374 pXGetTextProperty(SDL_Display, WMwindow, &titlepropUTF8, _NET_WM_NAME); 374 XGetTextProperty(SDL_Display, WMwindow, &titlepropUTF8, _NET_WM_NAME);
375 pXGetTextProperty(SDL_Display, WMwindow, &iconprop, XA_WM_ICON_NAME); 375 XGetTextProperty(SDL_Display, WMwindow, &iconprop, XA_WM_ICON_NAME);
376 pXGetTextProperty(SDL_Display, WMwindow, &iconpropUTF8, _NET_WM_ICON_NAME); 376 XGetTextProperty(SDL_Display, WMwindow, &iconpropUTF8, _NET_WM_ICON_NAME);
377 pXDestroyWindow(SDL_Display, WMwindow); 377 XDestroyWindow(SDL_Display, WMwindow);
378 } 378 }
379 379
380 /* Create the window for windowed management */ 380 /* Create the window for windowed management */
381 /* (reusing the xattr structure above) */ 381 /* (reusing the xattr structure above) */
382 WMwindow = pXCreateWindow(SDL_Display, SDL_Root, 0, 0, 32, 32, 0, 382 WMwindow = XCreateWindow(SDL_Display, SDL_Root, 0, 0, 32, 32, 0,
383 this->hidden->depth, InputOutput, SDL_Visual, 383 this->hidden->depth, InputOutput, SDL_Visual,
384 CWBackPixel | CWBorderPixel | CWColormap, 384 CWBackPixel | CWBorderPixel | CWColormap,
385 &xattr); 385 &xattr);
386 386
387 /* Set the input hints so we get keyboard input */ 387 /* Set the input hints so we get keyboard input */
388 if(!hints) { 388 if(!hints) {
389 hints = pXAllocWMHints(); 389 hints = XAllocWMHints();
390 hints->input = True; 390 hints->input = True;
391 hints->flags = InputHint; 391 hints->flags = InputHint;
392 } 392 }
393 pXSetWMHints(SDL_Display, WMwindow, hints); 393 XSetWMHints(SDL_Display, WMwindow, hints);
394 pXFree(hints); 394 XFree(hints);
395 if(titleprop.value) { 395 if(titleprop.value) {
396 pXSetTextProperty(SDL_Display, WMwindow, &titleprop, XA_WM_NAME); 396 XSetTextProperty(SDL_Display, WMwindow, &titleprop, XA_WM_NAME);
397 pXFree(titleprop.value); 397 XFree(titleprop.value);
398 } 398 }
399 if(titlepropUTF8.value) { 399 if(titlepropUTF8.value) {
400 pXSetTextProperty(SDL_Display, WMwindow, &titlepropUTF8, _NET_WM_NAME); 400 XSetTextProperty(SDL_Display, WMwindow, &titlepropUTF8, _NET_WM_NAME);
401 pXFree(titlepropUTF8.value); 401 XFree(titlepropUTF8.value);
402 } 402 }
403 if(iconprop.value) { 403 if(iconprop.value) {
404 pXSetTextProperty(SDL_Display, WMwindow, &iconprop, XA_WM_ICON_NAME); 404 XSetTextProperty(SDL_Display, WMwindow, &iconprop, XA_WM_ICON_NAME);
405 pXFree(iconprop.value); 405 XFree(iconprop.value);
406 } 406 }
407 if(iconpropUTF8.value) { 407 if(iconpropUTF8.value) {
408 pXSetTextProperty(SDL_Display, WMwindow, &iconpropUTF8, _NET_WM_ICON_NAME); 408 XSetTextProperty(SDL_Display, WMwindow, &iconpropUTF8, _NET_WM_ICON_NAME);
409 pXFree(iconpropUTF8.value); 409 XFree(iconpropUTF8.value);
410 } 410 }
411 411
412 pXSelectInput(SDL_Display, WMwindow, 412 XSelectInput(SDL_Display, WMwindow,
413 FocusChangeMask | KeyPressMask | KeyReleaseMask 413 FocusChangeMask | KeyPressMask | KeyReleaseMask
414 | PropertyChangeMask | StructureNotifyMask | KeymapStateMask); 414 | PropertyChangeMask | StructureNotifyMask | KeymapStateMask);
415 415
416 /* Set the class hints so we can get an icon (AfterStep) */ 416 /* Set the class hints so we can get an icon (AfterStep) */
417 get_classname(classname, sizeof(classname)); 417 get_classname(classname, sizeof(classname));
418 { 418 {
419 XClassHint *classhints; 419 XClassHint *classhints;
420 classhints = pXAllocClassHint(); 420 classhints = XAllocClassHint();
421 if(classhints != NULL) { 421 if(classhints != NULL) {
422 classhints->res_name = classname; 422 classhints->res_name = classname;
423 classhints->res_class = classname; 423 classhints->res_class = classname;
424 pXSetClassHint(SDL_Display, WMwindow, classhints); 424 XSetClassHint(SDL_Display, WMwindow, classhints);
425 pXFree(classhints); 425 XFree(classhints);
426 } 426 }
427 } 427 }
428 428
429 /* Setup the communication with the IM server */ 429 /* Setup the communication with the IM server */
430 SDL_IM = NULL; 430 SDL_IM = NULL;
431 SDL_IC = NULL; 431 SDL_IC = NULL;
432 432
433 #ifdef X_HAVE_UTF8_STRING 433 #ifdef X_HAVE_UTF8_STRING
434 SDL_IM = pXOpenIM(SDL_Display, NULL, classname, classname); 434 if (SDL_X11_HAVE_UTF8) {
435 if (SDL_IM == NULL) { 435 SDL_IM = XOpenIM(SDL_Display, NULL, classname, classname);
436 SDL_SetError("no input method could be opened"); 436 if (SDL_IM == NULL) {
437 } else { 437 SDL_SetError("no input method could be opened");
438 SDL_IC = pXCreateIC(SDL_IM, 438 } else {
439 XNClientWindow, WMwindow, 439 SDL_IC = pXCreateIC(SDL_IM,
440 XNFocusWindow, WMwindow, 440 XNClientWindow, WMwindow,
441 XNInputStyle, XIMPreeditNothing | XIMStatusNothing, 441 XNFocusWindow, WMwindow,
442 XNResourceName, classname, 442 XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
443 XNResourceClass, classname, 443 XNResourceName, classname,
444 NULL); 444 XNResourceClass, classname,
445 if (SDL_IC == NULL) { 445 NULL);
446 SDL_SetError("no input context could be created"); 446
447 pXCloseIM(SDL_IM); 447 if (SDL_IC == NULL) {
448 SDL_IM = NULL; 448 SDL_SetError("no input context could be created");
449 } 449 XCloseIM(SDL_IM);
450 } 450 SDL_IM = NULL;
451 #endif 451 }
452 452 }
453 /* Allow the window to be deleted by the window manager */ 453 }
454 pXSetWMProtocols(SDL_Display, WMwindow, &WM_DELETE_WINDOW, 1); 454 #endif
455
456 /* Allow the window to be deleted by the window manager */
457 XSetWMProtocols(SDL_Display, WMwindow, &WM_DELETE_WINDOW, 1);
455 } 458 }
456 459
457 static int X11_VideoInit(_THIS, SDL_PixelFormat *vformat) 460 static int X11_VideoInit(_THIS, SDL_PixelFormat *vformat)
458 { 461 {
459 char *display; 462 char *display;
460 int i; 463 int i;
461 464
462 /* Open the X11 display */ 465 /* Open the X11 display */
463 display = NULL; /* Get it from DISPLAY environment variable */ 466 display = NULL; /* Get it from DISPLAY environment variable */
464 467
465 if ( (SDL_strncmp(pXDisplayName(display), ":", 1) == 0) || 468 if ( (SDL_strncmp(XDisplayName(display), ":", 1) == 0) ||
466 (SDL_strncmp(pXDisplayName(display), "unix:", 5) == 0) ) { 469 (SDL_strncmp(XDisplayName(display), "unix:", 5) == 0) ) {
467 local_X11 = 1; 470 local_X11 = 1;
468 } else { 471 } else {
469 local_X11 = 0; 472 local_X11 = 0;
470 } 473 }
471 SDL_Display = pXOpenDisplay(display); 474 SDL_Display = XOpenDisplay(display);
472 #if defined(__osf__) && defined(SDL_VIDEO_DRIVER_X11_DYNAMIC) 475 #if defined(__osf__) && defined(SDL_VIDEO_DRIVER_X11_DYNAMIC)
473 /* On Tru64 if linking without -lX11, it fails and you get following message. 476 /* On Tru64 if linking without -lX11, it fails and you get following message.
474 * Xlib: connection to ":0.0" refused by server 477 * Xlib: connection to ":0.0" refused by server
475 * Xlib: XDM authorization key matches an existing client! 478 * Xlib: XDM authorization key matches an existing client!
476 * 479 *
478 * or if running xhost +localhost on shell. 481 * or if running xhost +localhost on shell.
479 * 482 *
480 */ 483 */
481 if ( SDL_Display == NULL ) { 484 if ( SDL_Display == NULL ) {
482 SDL_Delay(1000); 485 SDL_Delay(1000);
483 SDL_Display = pXOpenDisplay(display); 486 SDL_Display = XOpenDisplay(display);
484 } 487 }
485 #endif 488 #endif
486 if ( SDL_Display == NULL ) { 489 if ( SDL_Display == NULL ) {
487 SDL_SetError("Couldn't open X11 display"); 490 SDL_SetError("Couldn't open X11 display");
488 return(-1); 491 return(-1);
489 } 492 }
490 #ifdef X11_DEBUG 493 #ifdef X11_DEBUG
491 pXSynchronize(SDL_Display, True); 494 XSynchronize(SDL_Display, True);
492 #endif 495 #endif
493 496
494 /* Create an alternate X display for graphics updates -- allows us 497 /* Create an alternate X display for graphics updates -- allows us
495 to do graphics updates in a separate thread from event handling. 498 to do graphics updates in a separate thread from event handling.
496 Thread-safe X11 doesn't seem to exist. 499 Thread-safe X11 doesn't seem to exist.
497 */ 500 */
498 GFX_Display = pXOpenDisplay(display); 501 GFX_Display = XOpenDisplay(display);
499 if ( GFX_Display == NULL ) { 502 if ( GFX_Display == NULL ) {
500 SDL_SetError("Couldn't open X11 display"); 503 SDL_SetError("Couldn't open X11 display");
501 return(-1); 504 return(-1);
502 } 505 }
503 506
504 /* Set the normal X error handler */ 507 /* Set the normal X error handler */
505 X_handler = pXSetErrorHandler(x_errhandler); 508 X_handler = XSetErrorHandler(x_errhandler);
506 509
507 /* Set the error handler if we lose the X display */ 510 /* Set the error handler if we lose the X display */
508 XIO_handler = pXSetIOErrorHandler(xio_errhandler); 511 XIO_handler = XSetIOErrorHandler(xio_errhandler);
509 512
510 /* Set the X extension error handler */ 513 /* Set the X extension error handler */
511 Xext_handler = pXSetExtensionErrorHandler(xext_errhandler); 514 Xext_handler = XSetExtensionErrorHandler(xext_errhandler);
512 515
513 /* use default screen (from $DISPLAY) */ 516 /* use default screen (from $DISPLAY) */
514 SDL_Screen = DefaultScreen(SDL_Display); 517 SDL_Screen = DefaultScreen(SDL_Display);
515 518
516 #ifndef NO_SHARED_MEMORY 519 #ifndef NO_SHARED_MEMORY
517 /* Check for MIT shared memory extension */ 520 /* Check for MIT shared memory extension */
518 use_mitshm = 0; 521 use_mitshm = 0;
519 if ( local_X11 ) { 522 if ( local_X11 ) {
520 use_mitshm = pXShmQueryExtension(SDL_Display); 523 use_mitshm = XShmQueryExtension(SDL_Display);
521 } 524 }
522 #endif /* NO_SHARED_MEMORY */ 525 #endif /* NO_SHARED_MEMORY */
523 526
524 /* Get the available video modes */ 527 /* Get the available video modes */
525 if(X11_GetVideoModes(this) < 0) 528 if(X11_GetVideoModes(this) < 0)
542 } 545 }
543 SDL_Visual = this->hidden->visuals[i].visual; 546 SDL_Visual = this->hidden->visuals[i].visual;
544 if ( SDL_Visual == DefaultVisual(SDL_Display, SDL_Screen) ) { 547 if ( SDL_Visual == DefaultVisual(SDL_Display, SDL_Screen) ) {
545 SDL_XColorMap = SDL_DisplayColormap; 548 SDL_XColorMap = SDL_DisplayColormap;
546 } else { 549 } else {
547 SDL_XColorMap = pXCreateColormap(SDL_Display, SDL_Root, 550 SDL_XColorMap = XCreateColormap(SDL_Display, SDL_Root,
548 SDL_Visual, AllocNone); 551 SDL_Visual, AllocNone);
549 } 552 }
550 this->hidden->depth = this->hidden->visuals[i].depth; 553 this->hidden->depth = this->hidden->visuals[i].depth;
551 vformat->BitsPerPixel = this->hidden->visuals[i].bpp; 554 vformat->BitsPerPixel = this->hidden->visuals[i].bpp;
552 if ( vformat->BitsPerPixel > 8 ) { 555 if ( vformat->BitsPerPixel > 8 ) {
569 572
570 /* Fill in some window manager capabilities */ 573 /* Fill in some window manager capabilities */
571 this->info.wm_available = 1; 574 this->info.wm_available = 1;
572 575
573 /* We're done! */ 576 /* We're done! */
574 pXFlush(SDL_Display); 577 XFlush(SDL_Display);
575 return(0); 578 return(0);
576 } 579 }
577 580
578 static void X11_DestroyWindow(_THIS, SDL_Surface *screen) 581 static void X11_DestroyWindow(_THIS, SDL_Surface *screen)
579 { 582 {
584 X11_GL_Shutdown(this); 587 X11_GL_Shutdown(this);
585 588
586 if ( ! SDL_windowid ) { 589 if ( ! SDL_windowid ) {
587 /* Hide the managed window */ 590 /* Hide the managed window */
588 if ( WMwindow ) { 591 if ( WMwindow ) {
589 pXUnmapWindow(SDL_Display, WMwindow); 592 XUnmapWindow(SDL_Display, WMwindow);
590 } 593 }
591 if ( screen && (screen->flags & SDL_FULLSCREEN) ) { 594 if ( screen && (screen->flags & SDL_FULLSCREEN) ) {
592 screen->flags &= ~SDL_FULLSCREEN; 595 screen->flags &= ~SDL_FULLSCREEN;
593 X11_LeaveFullScreen(this); 596 X11_LeaveFullScreen(this);
594 } 597 }
595 598
596 /* Destroy the output window */ 599 /* Destroy the output window */
597 if ( SDL_Window ) { 600 if ( SDL_Window ) {
598 pXDestroyWindow(SDL_Display, SDL_Window); 601 XDestroyWindow(SDL_Display, SDL_Window);
599 } 602 }
600 603
601 /* Free the colormap entries */ 604 /* Free the colormap entries */
602 if ( SDL_XPixels ) { 605 if ( SDL_XPixels ) {
603 int numcolors; 606 int numcolors;
604 unsigned long pixel; 607 unsigned long pixel;
605 numcolors = SDL_Visual->map_entries; 608 numcolors = SDL_Visual->map_entries;
606 for ( pixel=0; pixel<numcolors; ++pixel ) { 609 for ( pixel=0; pixel<numcolors; ++pixel ) {
607 while ( SDL_XPixels[pixel] > 0 ) { 610 while ( SDL_XPixels[pixel] > 0 ) {
608 pXFreeColors(GFX_Display, 611 XFreeColors(GFX_Display,
609 SDL_DisplayColormap,&pixel,1,0); 612 SDL_DisplayColormap,&pixel,1,0);
610 --SDL_XPixels[pixel]; 613 --SDL_XPixels[pixel];
611 } 614 }
612 } 615 }
613 SDL_free(SDL_XPixels); 616 SDL_free(SDL_XPixels);
614 SDL_XPixels = NULL; 617 SDL_XPixels = NULL;
615 } 618 }
616 619
617 /* Free the graphics context */ 620 /* Free the graphics context */
618 if ( SDL_GC ) { 621 if ( SDL_GC ) {
619 pXFreeGC(SDL_Display, SDL_GC); 622 XFreeGC(SDL_Display, SDL_GC);
620 SDL_GC = 0; 623 SDL_GC = 0;
621 } 624 }
622 } 625 }
623 } 626 }
624 627
644 647
645 static void X11_SetSizeHints(_THIS, int w, int h, Uint32 flags) 648 static void X11_SetSizeHints(_THIS, int w, int h, Uint32 flags)
646 { 649 {
647 XSizeHints *hints; 650 XSizeHints *hints;
648 651
649 hints = pXAllocSizeHints(); 652 hints = XAllocSizeHints();
650 if ( hints ) { 653 if ( hints ) {
651 if ( flags & SDL_RESIZABLE ) { 654 if ( flags & SDL_RESIZABLE ) {
652 hints->min_width = 32; 655 hints->min_width = 32;
653 hints->min_height = 32; 656 hints->min_height = 32;
654 hints->max_height = 4096; 657 hints->max_height = 4096;
664 hints->flags |= USPosition; 667 hints->flags |= USPosition;
665 } else 668 } else
666 /* Center it, if desired */ 669 /* Center it, if desired */
667 if ( X11_WindowPosition(this, &hints->x, &hints->y, w, h) ) { 670 if ( X11_WindowPosition(this, &hints->x, &hints->y, w, h) ) {
668 hints->flags |= USPosition; 671 hints->flags |= USPosition;
669 pXMoveWindow(SDL_Display, WMwindow, hints->x, hints->y); 672 XMoveWindow(SDL_Display, WMwindow, hints->x, hints->y);
670 673
671 /* Flush the resize event so we don't catch it later */ 674 /* Flush the resize event so we don't catch it later */
672 pXSync(SDL_Display, True); 675 XSync(SDL_Display, True);
673 } 676 }
674 pXSetWMNormalHints(SDL_Display, WMwindow, hints); 677 XSetWMNormalHints(SDL_Display, WMwindow, hints);
675 pXFree(hints); 678 XFree(hints);
676 } 679 }
677 680
678 /* Respect the window caption style */ 681 /* Respect the window caption style */
679 if ( flags & SDL_NOFRAME ) { 682 if ( flags & SDL_NOFRAME ) {
680 SDL_bool set; 683 SDL_bool set;
682 685
683 /* We haven't modified the window manager hints yet */ 686 /* We haven't modified the window manager hints yet */
684 set = SDL_FALSE; 687 set = SDL_FALSE;
685 688
686 /* First try to set MWM hints */ 689 /* First try to set MWM hints */
687 WM_HINTS = pXInternAtom(SDL_Display, "_MOTIF_WM_HINTS", True); 690 WM_HINTS = XInternAtom(SDL_Display, "_MOTIF_WM_HINTS", True);
688 if ( WM_HINTS != None ) { 691 if ( WM_HINTS != None ) {
689 /* Hints used by Motif compliant window managers */ 692 /* Hints used by Motif compliant window managers */
690 struct { 693 struct {
691 unsigned long flags; 694 unsigned long flags;
692 unsigned long functions; 695 unsigned long functions;
693 unsigned long decorations; 696 unsigned long decorations;
694 long input_mode; 697 long input_mode;
695 unsigned long status; 698 unsigned long status;
696 } MWMHints = { (1L << 1), 0, 0, 0, 0 }; 699 } MWMHints = { (1L << 1), 0, 0, 0, 0 };
697 700
698 pXChangeProperty(SDL_Display, WMwindow, 701 XChangeProperty(SDL_Display, WMwindow,
699 WM_HINTS, WM_HINTS, 32, 702 WM_HINTS, WM_HINTS, 32,
700 PropModeReplace, 703 PropModeReplace,
701 (unsigned char *)&MWMHints, 704 (unsigned char *)&MWMHints,
702 sizeof(MWMHints)/sizeof(long)); 705 sizeof(MWMHints)/sizeof(long));
703 set = SDL_TRUE; 706 set = SDL_TRUE;
704 } 707 }
705 /* Now try to set KWM hints */ 708 /* Now try to set KWM hints */
706 WM_HINTS = pXInternAtom(SDL_Display, "KWM_WIN_DECORATION", True); 709 WM_HINTS = XInternAtom(SDL_Display, "KWM_WIN_DECORATION", True);
707 if ( WM_HINTS != None ) { 710 if ( WM_HINTS != None ) {
708 long KWMHints = 0; 711 long KWMHints = 0;
709 712
710 pXChangeProperty(SDL_Display, WMwindow, 713 XChangeProperty(SDL_Display, WMwindow,
711 WM_HINTS, WM_HINTS, 32, 714 WM_HINTS, WM_HINTS, 32,
712 PropModeReplace, 715 PropModeReplace,
713 (unsigned char *)&KWMHints, 716 (unsigned char *)&KWMHints,
714 sizeof(KWMHints)/sizeof(long)); 717 sizeof(KWMHints)/sizeof(long));
715 set = SDL_TRUE; 718 set = SDL_TRUE;
716 } 719 }
717 /* Now try to set GNOME hints */ 720 /* Now try to set GNOME hints */
718 WM_HINTS = pXInternAtom(SDL_Display, "_WIN_HINTS", True); 721 WM_HINTS = XInternAtom(SDL_Display, "_WIN_HINTS", True);
719 if ( WM_HINTS != None ) { 722 if ( WM_HINTS != None ) {
720 long GNOMEHints = 0; 723 long GNOMEHints = 0;
721 724
722 pXChangeProperty(SDL_Display, WMwindow, 725 XChangeProperty(SDL_Display, WMwindow,
723 WM_HINTS, WM_HINTS, 32, 726 WM_HINTS, WM_HINTS, 32,
724 PropModeReplace, 727 PropModeReplace,
725 (unsigned char *)&GNOMEHints, 728 (unsigned char *)&GNOMEHints,
726 sizeof(GNOMEHints)/sizeof(long)); 729 sizeof(GNOMEHints)/sizeof(long));
727 set = SDL_TRUE; 730 set = SDL_TRUE;
728 } 731 }
729 /* Finally set the transient hints if necessary */ 732 /* Finally set the transient hints if necessary */
730 if ( ! set ) { 733 if ( ! set ) {
731 pXSetTransientForHint(SDL_Display, WMwindow, SDL_Root); 734 XSetTransientForHint(SDL_Display, WMwindow, SDL_Root);
732 } 735 }
733 } else { 736 } else {
734 SDL_bool set; 737 SDL_bool set;
735 Atom WM_HINTS; 738 Atom WM_HINTS;
736 739
737 /* We haven't modified the window manager hints yet */ 740 /* We haven't modified the window manager hints yet */
738 set = SDL_FALSE; 741 set = SDL_FALSE;
739 742
740 /* First try to unset MWM hints */ 743 /* First try to unset MWM hints */
741 WM_HINTS = pXInternAtom(SDL_Display, "_MOTIF_WM_HINTS", True); 744 WM_HINTS = XInternAtom(SDL_Display, "_MOTIF_WM_HINTS", True);
742 if ( WM_HINTS != None ) { 745 if ( WM_HINTS != None ) {
743 pXDeleteProperty(SDL_Display, WMwindow, WM_HINTS); 746 XDeleteProperty(SDL_Display, WMwindow, WM_HINTS);
744 set = SDL_TRUE; 747 set = SDL_TRUE;
745 } 748 }
746 /* Now try to unset KWM hints */ 749 /* Now try to unset KWM hints */
747 WM_HINTS = pXInternAtom(SDL_Display, "KWM_WIN_DECORATION", True); 750 WM_HINTS = XInternAtom(SDL_Display, "KWM_WIN_DECORATION", True);
748 if ( WM_HINTS != None ) { 751 if ( WM_HINTS != None ) {
749 pXDeleteProperty(SDL_Display, WMwindow, WM_HINTS); 752 XDeleteProperty(SDL_Display, WMwindow, WM_HINTS);
750 set = SDL_TRUE; 753 set = SDL_TRUE;
751 } 754 }
752 /* Now try to unset GNOME hints */ 755 /* Now try to unset GNOME hints */
753 WM_HINTS = pXInternAtom(SDL_Display, "_WIN_HINTS", True); 756 WM_HINTS = XInternAtom(SDL_Display, "_WIN_HINTS", True);
754 if ( WM_HINTS != None ) { 757 if ( WM_HINTS != None ) {
755 pXDeleteProperty(SDL_Display, WMwindow, WM_HINTS); 758 XDeleteProperty(SDL_Display, WMwindow, WM_HINTS);
756 set = SDL_TRUE; 759 set = SDL_TRUE;
757 } 760 }
758 /* Finally unset the transient hints if necessary */ 761 /* Finally unset the transient hints if necessary */
759 if ( ! set ) { 762 if ( ! set ) {
760 /* NOTE: Does this work? */ 763 /* NOTE: Does this work? */
761 pXSetTransientForHint(SDL_Display, WMwindow, None); 764 XSetTransientForHint(SDL_Display, WMwindow, None);
762 } 765 }
763 } 766 }
764 } 767 }
765 768
766 static int X11_CreateWindow(_THIS, SDL_Surface *screen, 769 static int X11_CreateWindow(_THIS, SDL_Surface *screen,
794 vis = vi->visual; 797 vis = vi->visual;
795 depth = vi->depth; 798 depth = vi->depth;
796 } else if ( SDL_windowid ) { 799 } else if ( SDL_windowid ) {
797 XWindowAttributes a; 800 XWindowAttributes a;
798 801
799 pXGetWindowAttributes(SDL_Display, SDL_Window, &a); 802 XGetWindowAttributes(SDL_Display, SDL_Window, &a);
800 vis = a.visual; 803 vis = a.visual;
801 depth = a.depth; 804 depth = a.depth;
802 } else { 805 } else {
803 for ( i = 0; i < this->hidden->nvisuals; i++ ) { 806 for ( i = 0; i < this->hidden->nvisuals; i++ ) {
804 if ( this->hidden->visuals[i].bpp == bpp ) 807 if ( this->hidden->visuals[i].bpp == bpp )
823 vis->red_mask, vis->green_mask, vis->blue_mask, 0) ) 826 vis->red_mask, vis->green_mask, vis->blue_mask, 0) )
824 return -1; 827 return -1;
825 828
826 /* Create the appropriate colormap */ 829 /* Create the appropriate colormap */
827 if ( SDL_XColorMap != SDL_DisplayColormap ) { 830 if ( SDL_XColorMap != SDL_DisplayColormap ) {
828 pXFreeColormap(SDL_Display, SDL_XColorMap); 831 XFreeColormap(SDL_Display, SDL_XColorMap);
829 } 832 }
830 if ( SDL_Visual->class == PseudoColor ) { 833 if ( SDL_Visual->class == PseudoColor ) {
831 int ncolors; 834 int ncolors;
832 835
833 /* Allocate the pixel flags */ 836 /* Allocate the pixel flags */
843 if ( SDL_Visual != DefaultVisual(SDL_Display, SDL_Screen) ) { 846 if ( SDL_Visual != DefaultVisual(SDL_Display, SDL_Screen) ) {
844 flags |= SDL_HWPALETTE; 847 flags |= SDL_HWPALETTE;
845 } 848 }
846 if ( flags & SDL_HWPALETTE ) { 849 if ( flags & SDL_HWPALETTE ) {
847 screen->flags |= SDL_HWPALETTE; 850 screen->flags |= SDL_HWPALETTE;
848 SDL_XColorMap = pXCreateColormap(SDL_Display, SDL_Root, 851 SDL_XColorMap = XCreateColormap(SDL_Display, SDL_Root,
849 SDL_Visual, AllocAll); 852 SDL_Visual, AllocAll);
850 } else { 853 } else {
851 SDL_XColorMap = SDL_DisplayColormap; 854 SDL_XColorMap = SDL_DisplayColormap;
852 } 855 }
853 } else if ( SDL_Visual->class == DirectColor ) { 856 } else if ( SDL_Visual->class == DirectColor ) {
854 857
855 /* Create a colormap which we can manipulate for gamma */ 858 /* Create a colormap which we can manipulate for gamma */
856 SDL_XColorMap = pXCreateColormap(SDL_Display, SDL_Root, 859 SDL_XColorMap = XCreateColormap(SDL_Display, SDL_Root,
857 SDL_Visual, AllocAll); 860 SDL_Visual, AllocAll);
858 pXSync(SDL_Display, False); 861 XSync(SDL_Display, False);
859 862
860 /* Initialize the colormap to the identity mapping */ 863 /* Initialize the colormap to the identity mapping */
861 SDL_GetGammaRamp(0, 0, 0); 864 SDL_GetGammaRamp(0, 0, 0);
862 this->screen = screen; 865 this->screen = screen;
863 X11_SetGammaRamp(this, this->gamma); 866 X11_SetGammaRamp(this, this->gamma);
864 this->screen = NULL; 867 this->screen = NULL;
865 } else { 868 } else {
866 /* Create a read-only colormap for our window */ 869 /* Create a read-only colormap for our window */
867 SDL_XColorMap = pXCreateColormap(SDL_Display, SDL_Root, 870 SDL_XColorMap = XCreateColormap(SDL_Display, SDL_Root,
868 SDL_Visual, AllocNone); 871 SDL_Visual, AllocNone);
869 } 872 }
870 873
871 /* Recreate the auxiliary windows, if needed (required for GL) */ 874 /* Recreate the auxiliary windows, if needed (required for GL) */
872 if ( vis_change ) 875 if ( vis_change )
875 if(screen->flags & SDL_HWPALETTE) { 878 if(screen->flags & SDL_HWPALETTE) {
876 /* Since the full-screen window might have got a nonzero background 879 /* Since the full-screen window might have got a nonzero background
877 colour (0 is white on some displays), we should reset the 880 colour (0 is white on some displays), we should reset the
878 background to 0 here since that is what the user expects 881 background to 0 here since that is what the user expects
879 with a private colormap */ 882 with a private colormap */
880 pXSetWindowBackground(SDL_Display, FSwindow, 0); 883 XSetWindowBackground(SDL_Display, FSwindow, 0);
881 pXClearWindow(SDL_Display, FSwindow); 884 XClearWindow(SDL_Display, FSwindow);
882 } 885 }
883 886
884 /* resize the (possibly new) window manager window */ 887 /* resize the (possibly new) window manager window */
885 if( !SDL_windowid ) { 888 if( !SDL_windowid ) {
886 X11_SetSizeHints(this, w, h, flags); 889 X11_SetSizeHints(this, w, h, flags);
887 window_w = w; 890 window_w = w;
888 window_h = h; 891 window_h = h;
889 pXResizeWindow(SDL_Display, WMwindow, w, h); 892 XResizeWindow(SDL_Display, WMwindow, w, h);
890 } 893 }
891 894
892 /* Create (or use) the X11 display window */ 895 /* Create (or use) the X11 display window */
893 if ( !SDL_windowid ) { 896 if ( !SDL_windowid ) {
894 if ( flags & SDL_OPENGL ) { 897 if ( flags & SDL_OPENGL ) {
899 XSetWindowAttributes swa; 902 XSetWindowAttributes swa;
900 903
901 swa.background_pixel = 0; 904 swa.background_pixel = 0;
902 swa.border_pixel = 0; 905 swa.border_pixel = 0;
903 swa.colormap = SDL_XColorMap; 906 swa.colormap = SDL_XColorMap;
904 SDL_Window = pXCreateWindow(SDL_Display, WMwindow, 907 SDL_Window = XCreateWindow(SDL_Display, WMwindow,
905 0, 0, w, h, 0, depth, 908 0, 0, w, h, 0, depth,
906 InputOutput, SDL_Visual, 909 InputOutput, SDL_Visual,
907 CWBackPixel | CWBorderPixel 910 CWBackPixel | CWBorderPixel
908 | CWColormap, &swa); 911 | CWColormap, &swa);
909 } 912 }
910 /* Only manage our input if we own the window */ 913 /* Only manage our input if we own the window */
911 pXSelectInput(SDL_Display, SDL_Window, 914 XSelectInput(SDL_Display, SDL_Window,
912 ( EnterWindowMask | LeaveWindowMask 915 ( EnterWindowMask | LeaveWindowMask
913 | ButtonPressMask | ButtonReleaseMask 916 | ButtonPressMask | ButtonReleaseMask
914 | PointerMotionMask | ExposureMask )); 917 | PointerMotionMask | ExposureMask ));
915 } 918 }
916 /* Create the graphics context here, once we have a window */ 919 /* Create the graphics context here, once we have a window */
922 } 925 }
923 } else { 926 } else {
924 XGCValues gcv; 927 XGCValues gcv;
925 928
926 gcv.graphics_exposures = False; 929 gcv.graphics_exposures = False;
927 SDL_GC = pXCreateGC(SDL_Display, SDL_Window, 930 SDL_GC = XCreateGC(SDL_Display, SDL_Window,
928 GCGraphicsExposures, &gcv); 931 GCGraphicsExposures, &gcv);
929 if ( ! SDL_GC ) { 932 if ( ! SDL_GC ) {
930 SDL_SetError("Couldn't create graphics context"); 933 SDL_SetError("Couldn't create graphics context");
931 return(-1); 934 return(-1);
932 } 935 }
933 } 936 }
934 937
935 /* Set our colormaps when not setting a GL mode */ 938 /* Set our colormaps when not setting a GL mode */
936 if ( ! (flags & SDL_OPENGL) ) { 939 if ( ! (flags & SDL_OPENGL) ) {
937 pXSetWindowColormap(SDL_Display, SDL_Window, SDL_XColorMap); 940 XSetWindowColormap(SDL_Display, SDL_Window, SDL_XColorMap);
938 if( !SDL_windowid ) { 941 if( !SDL_windowid ) {
939 pXSetWindowColormap(SDL_Display, FSwindow, SDL_XColorMap); 942 XSetWindowColormap(SDL_Display, FSwindow, SDL_XColorMap);
940 pXSetWindowColormap(SDL_Display, WMwindow, SDL_XColorMap); 943 XSetWindowColormap(SDL_Display, WMwindow, SDL_XColorMap);
941 } 944 }
942 } 945 }
943 946
944 #if 0 /* This is an experiment - are the graphics faster now? - nope. */ 947 #if 0 /* This is an experiment - are the graphics faster now? - nope. */
945 if ( SDL_getenv("SDL_VIDEO_X11_BACKINGSTORE") ) 948 if ( SDL_getenv("SDL_VIDEO_X11_BACKINGSTORE") )
950 XSetWindowAttributes a; 953 XSetWindowAttributes a;
951 954
952 xscreen = ScreenOfDisplay(SDL_Display, SDL_Screen); 955 xscreen = ScreenOfDisplay(SDL_Display, SDL_Screen);
953 a.backing_store = DoesBackingStore(xscreen); 956 a.backing_store = DoesBackingStore(xscreen);
954 if ( a.backing_store != NotUseful ) { 957 if ( a.backing_store != NotUseful ) {
955 pXChangeWindowAttributes(SDL_Display, SDL_Window, 958 XChangeWindowAttributes(SDL_Display, SDL_Window,
956 CWBackingStore, &a); 959 CWBackingStore, &a);
957 } 960 }
958 } 961 }
959 962
960 /* Update the internal keyboard state */ 963 /* Update the internal keyboard state */
984 } 987 }
985 } 988 }
986 989
987 /* Map them both and go fullscreen, if requested */ 990 /* Map them both and go fullscreen, if requested */
988 if ( ! SDL_windowid ) { 991 if ( ! SDL_windowid ) {
989 pXMapWindow(SDL_Display, SDL_Window); 992 XMapWindow(SDL_Display, SDL_Window);
990 pXMapWindow(SDL_Display, WMwindow); 993 XMapWindow(SDL_Display, WMwindow);
991 X11_WaitMapped(this, WMwindow); 994 X11_WaitMapped(this, WMwindow);
992 if ( flags & SDL_FULLSCREEN ) { 995 if ( flags & SDL_FULLSCREEN ) {
993 screen->flags |= SDL_FULLSCREEN; 996 screen->flags |= SDL_FULLSCREEN;
994 X11_EnterFullScreen(this); 997 X11_EnterFullScreen(this);
995 } else { 998 } else {
1006 if ( ! SDL_windowid ) { 1009 if ( ! SDL_windowid ) {
1007 /* Resize the window manager window */ 1010 /* Resize the window manager window */
1008 X11_SetSizeHints(this, w, h, flags); 1011 X11_SetSizeHints(this, w, h, flags);
1009 window_w = w; 1012 window_w = w;
1010 window_h = h; 1013 window_h = h;
1011 pXResizeWindow(SDL_Display, WMwindow, w, h); 1014 XResizeWindow(SDL_Display, WMwindow, w, h);
1012 1015
1013 /* Resize the fullscreen and display windows */ 1016 /* Resize the fullscreen and display windows */
1014 if ( flags & SDL_FULLSCREEN ) { 1017 if ( flags & SDL_FULLSCREEN ) {
1015 if ( screen->flags & SDL_FULLSCREEN ) { 1018 if ( screen->flags & SDL_FULLSCREEN ) {
1016 X11_ResizeFullScreen(this); 1019 X11_ResizeFullScreen(this);
1022 if ( screen->flags & SDL_FULLSCREEN ) { 1025 if ( screen->flags & SDL_FULLSCREEN ) {
1023 screen->flags &= ~SDL_FULLSCREEN; 1026 screen->flags &= ~SDL_FULLSCREEN;
1024 X11_LeaveFullScreen(this); 1027 X11_LeaveFullScreen(this);
1025 } 1028 }
1026 } 1029 }
1027 pXResizeWindow(SDL_Display, SDL_Window, w, h); 1030 XResizeWindow(SDL_Display, SDL_Window, w, h);
1028 } 1031 }
1029 return(0); 1032 return(0);
1030 } 1033 }
1031 1034
1032 SDL_Surface *X11_SetVideoMode(_THIS, SDL_Surface *current, 1035 SDL_Surface *X11_SetVideoMode(_THIS, SDL_Surface *current,
1044 flags &= ~SDL_FULLSCREEN; 1047 flags &= ~SDL_FULLSCREEN;
1045 } 1048 }
1046 } 1049 }
1047 1050
1048 /* Flush any delayed updates */ 1051 /* Flush any delayed updates */
1049 pXSync(GFX_Display, False); 1052 XSync(GFX_Display, False);
1050 1053
1051 /* Set up the X11 window */ 1054 /* Set up the X11 window */
1052 saved_flags = current->flags; 1055 saved_flags = current->flags;
1053 if ( (SDL_Window) && ((saved_flags&SDL_OPENGL) == (flags&SDL_OPENGL)) 1056 if ( (SDL_Window) && ((saved_flags&SDL_OPENGL) == (flags&SDL_OPENGL))
1054 && (bpp == current->format->BitsPerPixel) 1057 && (bpp == current->format->BitsPerPixel)
1074 } 1077 }
1075 current->flags |= (flags&(SDL_RESIZABLE|SDL_NOFRAME)); 1078 current->flags |= (flags&(SDL_RESIZABLE|SDL_NOFRAME));
1076 1079
1077 done: 1080 done:
1078 /* Release the event thread */ 1081 /* Release the event thread */
1079 pXSync(SDL_Display, False); 1082 XSync(SDL_Display, False);
1080 SDL_Unlock_EventThread(); 1083 SDL_Unlock_EventThread();
1081 1084
1082 /* We're done! */ 1085 /* We're done! */
1083 return(current); 1086 return(current);
1084 } 1087 }
1123 int x, y; 1126 int x, y;
1124 unsigned int mask; 1127 unsigned int mask;
1125 1128
1126 /* Lock the event thread, in multi-threading environments */ 1129 /* Lock the event thread, in multi-threading environments */
1127 SDL_Lock_EventThread(); 1130 SDL_Lock_EventThread();
1128 if ( pXQueryPointer(SDL_Display, SDL_Window, &u1, &current_win, 1131 if ( XQueryPointer(SDL_Display, SDL_Window, &u1, &current_win,
1129 &u2, &u2, &x, &y, &mask) ) { 1132 &u2, &u2, &x, &y, &mask) ) {
1130 if ( (x >= 0) && (x < SDL_VideoSurface->w) && 1133 if ( (x >= 0) && (x < SDL_VideoSurface->w) &&
1131 (y >= 0) && (y < SDL_VideoSurface->h) ) { 1134 (y >= 0) && (y < SDL_VideoSurface->h) ) {
1132 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); 1135 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
1133 SDL_PrivateMouseMotion(0, 0, x, y); 1136 SDL_PrivateMouseMotion(0, 0, x, y);
1160 all[i].pixel = i; 1163 all[i].pixel = i;
1161 /* 1164 /*
1162 * XQueryColors sets the flags in the XColor struct, so we use 1165 * XQueryColors sets the flags in the XColor struct, so we use
1163 * that to keep track of which colours are available 1166 * that to keep track of which colours are available
1164 */ 1167 */
1165 pXQueryColors(GFX_Display, SDL_XColorMap, all, 256); 1168 XQueryColors(GFX_Display, SDL_XColorMap, all, 256);
1166 1169
1167 for(i = 0; i < nwant; i++) { 1170 for(i = 0; i < nwant; i++) {
1168 XColor *c; 1171 XColor *c;
1169 int j; 1172 int j;
1170 int best = 0; 1173 int best = 0;
1186 } 1189 }
1187 } 1190 }
1188 if(SDL_XPixels[best]) 1191 if(SDL_XPixels[best])
1189 continue; /* already allocated, waste no more time */ 1192 continue; /* already allocated, waste no more time */
1190 c = all + best; 1193 c = all + best;
1191 if(pXAllocColor(GFX_Display, SDL_XColorMap, c)) { 1194 if(XAllocColor(GFX_Display, SDL_XColorMap, c)) {
1192 /* got it */ 1195 /* got it */
1193 colors[c->pixel].r = c->red >> 8; 1196 colors[c->pixel].r = c->red >> 8;
1194 colors[c->pixel].g = c->green >> 8; 1197 colors[c->pixel].g = c->green >> 8;
1195 colors[c->pixel].b = c->blue >> 8; 1198 colors[c->pixel].b = c->blue >> 8;
1196 ++SDL_XPixels[c->pixel]; 1199 ++SDL_XPixels[c->pixel];
1228 xcmap[i].red = (colors[i].r<<8)|colors[i].r; 1231 xcmap[i].red = (colors[i].r<<8)|colors[i].r;
1229 xcmap[i].green = (colors[i].g<<8)|colors[i].g; 1232 xcmap[i].green = (colors[i].g<<8)|colors[i].g;
1230 xcmap[i].blue = (colors[i].b<<8)|colors[i].b; 1233 xcmap[i].blue = (colors[i].b<<8)|colors[i].b;
1231 xcmap[i].flags = (DoRed|DoGreen|DoBlue); 1234 xcmap[i].flags = (DoRed|DoGreen|DoBlue);
1232 } 1235 }
1233 pXStoreColors(GFX_Display, SDL_XColorMap, xcmap, ncolors); 1236 XStoreColors(GFX_Display, SDL_XColorMap, xcmap, ncolors);
1234 pXSync(GFX_Display, False); 1237 XSync(GFX_Display, False);
1235 SDL_stack_free(xcmap); 1238 SDL_stack_free(xcmap);
1236 } else { 1239 } else {
1237 /* 1240 /*
1238 * Shared colormap: We only allocate read-only cells, which 1241 * Shared colormap: We only allocate read-only cells, which
1239 * increases the likelyhood of colour sharing with other 1242 * increases the likelyhood of colour sharing with other
1257 while(SDL_XPixels[pixel]) { 1260 while(SDL_XPixels[pixel]) {
1258 freelist[nfree++] = pixel; 1261 freelist[nfree++] = pixel;
1259 --SDL_XPixels[pixel]; 1262 --SDL_XPixels[pixel];
1260 } 1263 }
1261 } 1264 }
1262 pXFreeColors(GFX_Display, SDL_XColorMap, freelist, nfree, 0); 1265 XFreeColors(GFX_Display, SDL_XColorMap, freelist, nfree, 0);
1263 SDL_stack_free(freelist); 1266 SDL_stack_free(freelist);
1264 1267
1265 want = SDL_stack_alloc(SDL_Color, ncolors); 1268 want = SDL_stack_alloc(SDL_Color, ncolors);
1266 reject = SDL_stack_alloc(SDL_Color, ncolors); 1269 reject = SDL_stack_alloc(SDL_Color, ncolors);
1267 SDL_memcpy(want, colors + firstcolor, ncolors * sizeof(SDL_Color)); 1270 SDL_memcpy(want, colors + firstcolor, ncolors * sizeof(SDL_Color));
1274 XColor col; 1277 XColor col;
1275 col.red = want[i].r << 8; 1278 col.red = want[i].r << 8;
1276 col.green = want[i].g << 8; 1279 col.green = want[i].g << 8;
1277 col.blue = want[i].b << 8; 1280 col.blue = want[i].b << 8;
1278 col.flags = DoRed | DoGreen | DoBlue; 1281 col.flags = DoRed | DoGreen | DoBlue;
1279 if(pXAllocColor(GFX_Display, SDL_XColorMap, &col)) { 1282 if(XAllocColor(GFX_Display, SDL_XColorMap, &col)) {
1280 /* We got the colour, or at least the nearest 1283 /* We got the colour, or at least the nearest
1281 the hardware could get. */ 1284 the hardware could get. */
1282 colors[col.pixel].r = col.red >> 8; 1285 colors[col.pixel].r = col.red >> 8;
1283 colors[col.pixel].g = col.green >> 8; 1286 colors[col.pixel].g = col.green >> 8;
1284 colors[col.pixel].b = col.blue >> 8; 1287 colors[col.pixel].b = col.blue >> 8;
1318 xcmap[i].red = ramp[0*256+c]; 1321 xcmap[i].red = ramp[0*256+c];
1319 xcmap[i].green = ramp[1*256+c]; 1322 xcmap[i].green = ramp[1*256+c];
1320 xcmap[i].blue = ramp[2*256+c]; 1323 xcmap[i].blue = ramp[2*256+c];
1321 xcmap[i].flags = (DoRed|DoGreen|DoBlue); 1324 xcmap[i].flags = (DoRed|DoGreen|DoBlue);
1322 } 1325 }
1323 pXStoreColors(GFX_Display, SDL_XColorMap, xcmap, ncolors); 1326 XStoreColors(GFX_Display, SDL_XColorMap, xcmap, ncolors);
1324 pXSync(GFX_Display, False); 1327 XSync(GFX_Display, False);
1325 return(0); 1328 return(0);
1326 } 1329 }
1327 1330
1328 /* Note: If we are terminated, this could be called in the middle of 1331 /* Note: If we are terminated, this could be called in the middle of
1329 another SDL video routine -- notably UpdateRects. 1332 another SDL video routine -- notably UpdateRects.
1332 { 1335 {
1333 /* Shutdown everything that's still up */ 1336 /* Shutdown everything that's still up */
1334 /* The event thread should be done, so we can touch SDL_Display */ 1337 /* The event thread should be done, so we can touch SDL_Display */
1335 if ( SDL_Display != NULL ) { 1338 if ( SDL_Display != NULL ) {
1336 /* Flush any delayed updates */ 1339 /* Flush any delayed updates */
1337 pXSync(GFX_Display, False); 1340 XSync(GFX_Display, False);
1338 1341
1339 /* Close the connection with the IM server */ 1342 /* Close the connection with the IM server */
1340 #ifdef X_HAVE_UTF8_STRING 1343 #ifdef X_HAVE_UTF8_STRING
1341 if (SDL_IC != NULL) { 1344 if (SDL_IC != NULL) {
1342 pXDestroyIC(SDL_IC); 1345 XDestroyIC(SDL_IC);
1343 SDL_IC = NULL; 1346 SDL_IC = NULL;
1344 } 1347 }
1345 if (SDL_IM != NULL) { 1348 if (SDL_IM != NULL) {
1346 pXCloseIM(SDL_IM); 1349 XCloseIM(SDL_IM);
1347 SDL_IM = NULL; 1350 SDL_IM = NULL;
1348 } 1351 }
1349 #endif 1352 #endif
1350 1353
1351 /* Start shutting down the windows */ 1354 /* Start shutting down the windows */
1352 X11_DestroyImage(this, this->screen); 1355 X11_DestroyImage(this, this->screen);
1353 X11_DestroyWindow(this, this->screen); 1356 X11_DestroyWindow(this, this->screen);
1354 X11_FreeVideoModes(this); 1357 X11_FreeVideoModes(this);
1355 if ( SDL_XColorMap != SDL_DisplayColormap ) { 1358 if ( SDL_XColorMap != SDL_DisplayColormap ) {
1356 pXFreeColormap(SDL_Display, SDL_XColorMap); 1359 XFreeColormap(SDL_Display, SDL_XColorMap);
1357 } 1360 }
1358 if ( SDL_iconcolors ) { 1361 if ( SDL_iconcolors ) {
1359 unsigned long pixel; 1362 unsigned long pixel;
1360 Colormap dcmap = DefaultColormap(SDL_Display, 1363 Colormap dcmap = DefaultColormap(SDL_Display,
1361 SDL_Screen); 1364 SDL_Screen);
1362 for(pixel = 0; pixel < 256; ++pixel) { 1365 for(pixel = 0; pixel < 256; ++pixel) {
1363 while(SDL_iconcolors[pixel] > 0) { 1366 while(SDL_iconcolors[pixel] > 0) {
1364 pXFreeColors(GFX_Display, 1367 XFreeColors(GFX_Display,
1365 dcmap, &pixel, 1, 0); 1368 dcmap, &pixel, 1, 0);
1366 --SDL_iconcolors[pixel]; 1369 --SDL_iconcolors[pixel];
1367 } 1370 }
1368 } 1371 }
1369 SDL_free(SDL_iconcolors); 1372 SDL_free(SDL_iconcolors);
1380 SDL_BlankCursor = NULL; 1383 SDL_BlankCursor = NULL;
1381 } 1384 }
1382 1385
1383 /* Close the X11 graphics connection */ 1386 /* Close the X11 graphics connection */
1384 if ( GFX_Display != NULL ) { 1387 if ( GFX_Display != NULL ) {
1385 pXCloseDisplay(GFX_Display); 1388 XCloseDisplay(GFX_Display);
1386 GFX_Display = NULL; 1389 GFX_Display = NULL;
1387 } 1390 }
1388 1391
1389 /* Close the X11 display connection */ 1392 /* Close the X11 display connection */
1390 pXCloseDisplay(SDL_Display); 1393 XCloseDisplay(SDL_Display);
1391 SDL_Display = NULL; 1394 SDL_Display = NULL;
1392 1395
1393 /* Reset the X11 error handlers */ 1396 /* Reset the X11 error handlers */
1394 if ( XIO_handler ) { 1397 if ( XIO_handler ) {
1395 pXSetIOErrorHandler(XIO_handler); 1398 XSetIOErrorHandler(XIO_handler);
1396 } 1399 }
1397 if ( X_handler ) { 1400 if ( X_handler ) {
1398 pXSetErrorHandler(X_handler); 1401 XSetErrorHandler(X_handler);
1399 } 1402 }
1400 1403
1401 /* Unload GL library after X11 shuts down */ 1404 /* Unload GL library after X11 shuts down */
1402 X11_GL_UnloadLibrary(this); 1405 X11_GL_UnloadLibrary(this);
1403 } 1406 }