comparison src/video/x11/SDL_x11video.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 5c7859610bc4
children 9867f3d86e44
comparison
equal deleted inserted replaced
1167:435c2e481299 1168:045f186426e1
83 static int X11_SetColors(_THIS, int firstcolor, int ncolors, 83 static int X11_SetColors(_THIS, int firstcolor, int ncolors,
84 SDL_Color *colors); 84 SDL_Color *colors);
85 static int X11_SetGammaRamp(_THIS, Uint16 *ramp); 85 static int X11_SetGammaRamp(_THIS, Uint16 *ramp);
86 static void X11_VideoQuit(_THIS); 86 static void X11_VideoQuit(_THIS);
87 87
88
88 /* X11 driver bootstrap functions */ 89 /* X11 driver bootstrap functions */
89 90
90 static int X11_Available(void) 91 static int X11_Available(void)
91 { 92 {
92 Display *display; 93 Display *display = NULL;
93 94 if ( SDL_X11_LoadSymbols() ) {
94 display = XOpenDisplay(NULL); 95 display = pXOpenDisplay(NULL);
95 if ( display != NULL ) { 96 if ( display != NULL ) {
96 XCloseDisplay(display); 97 pXCloseDisplay(display);
98 }
99 SDL_X11_UnloadSymbols();
97 } 100 }
98 return(display != NULL); 101 return(display != NULL);
99 } 102 }
100 103
101 static void X11_DeleteDevice(SDL_VideoDevice *device) 104 static void X11_DeleteDevice(SDL_VideoDevice *device)
106 } 109 }
107 if ( device->gl_data ) { 110 if ( device->gl_data ) {
108 free(device->gl_data); 111 free(device->gl_data);
109 } 112 }
110 free(device); 113 free(device);
114 SDL_X11_UnloadSymbols();
111 } 115 }
112 } 116 }
113 117
114 static SDL_VideoDevice *X11_CreateDevice(int devindex) 118 static SDL_VideoDevice *X11_CreateDevice(int devindex)
115 { 119 {
116 SDL_VideoDevice *device; 120 SDL_VideoDevice *device = NULL;
117 121
118 /* Initialize all variables that we clean on shutdown */ 122 if ( SDL_X11_LoadSymbols() ) {
119 device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice)); 123 /* Initialize all variables that we clean on shutdown */
120 if ( device ) { 124 device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
121 memset(device, 0, (sizeof *device)); 125 if ( device ) {
122 device->hidden = (struct SDL_PrivateVideoData *) 126 memset(device, 0, (sizeof *device));
123 malloc((sizeof *device->hidden)); 127 device->hidden = (struct SDL_PrivateVideoData *)
124 device->gl_data = (struct SDL_PrivateGLData *) 128 malloc((sizeof *device->hidden));
125 malloc((sizeof *device->gl_data)); 129 device->gl_data = (struct SDL_PrivateGLData *)
126 } 130 malloc((sizeof *device->gl_data));
127 if ( (device == NULL) || (device->hidden == NULL) || 131 }
128 (device->gl_data == NULL) ) { 132 if ( (device == NULL) || (device->hidden == NULL) ||
129 SDL_OutOfMemory(); 133 (device->gl_data == NULL) ) {
130 X11_DeleteDevice(device); 134 SDL_OutOfMemory();
131 return(0); 135 X11_DeleteDevice(device); /* calls SDL_X11_UnloadSymbols(). */
132 } 136 return(0);
133 memset(device->hidden, 0, (sizeof *device->hidden)); 137 }
134 memset(device->gl_data, 0, (sizeof *device->gl_data)); 138 memset(device->hidden, 0, (sizeof *device->hidden));
135 139 memset(device->gl_data, 0, (sizeof *device->gl_data));
136 /* Set the driver flags */ 140
137 device->handles_any_size = 1; 141 /* Set the driver flags */
138 142 device->handles_any_size = 1;
139 /* Set the function pointers */ 143
140 device->VideoInit = X11_VideoInit; 144 /* Set the function pointers */
141 device->ListModes = X11_ListModes; 145 device->VideoInit = X11_VideoInit;
142 device->SetVideoMode = X11_SetVideoMode; 146 device->ListModes = X11_ListModes;
143 device->ToggleFullScreen = X11_ToggleFullScreen; 147 device->SetVideoMode = X11_SetVideoMode;
144 device->UpdateMouse = X11_UpdateMouse; 148 device->ToggleFullScreen = X11_ToggleFullScreen;
149 device->UpdateMouse = X11_UpdateMouse;
145 #ifdef XFREE86_XV 150 #ifdef XFREE86_XV
146 device->CreateYUVOverlay = X11_CreateYUVOverlay; 151 device->CreateYUVOverlay = X11_CreateYUVOverlay;
147 #endif 152 #endif
148 device->SetColors = X11_SetColors; 153 device->SetColors = X11_SetColors;
149 device->UpdateRects = NULL; 154 device->UpdateRects = NULL;
150 device->VideoQuit = X11_VideoQuit; 155 device->VideoQuit = X11_VideoQuit;
151 device->AllocHWSurface = X11_AllocHWSurface; 156 device->AllocHWSurface = X11_AllocHWSurface;
152 device->CheckHWBlit = NULL; 157 device->CheckHWBlit = NULL;
153 device->FillHWRect = NULL; 158 device->FillHWRect = NULL;
154 device->SetHWColorKey = NULL; 159 device->SetHWColorKey = NULL;
155 device->SetHWAlpha = NULL; 160 device->SetHWAlpha = NULL;
156 device->LockHWSurface = X11_LockHWSurface; 161 device->LockHWSurface = X11_LockHWSurface;
157 device->UnlockHWSurface = X11_UnlockHWSurface; 162 device->UnlockHWSurface = X11_UnlockHWSurface;
158 device->FlipHWSurface = X11_FlipHWSurface; 163 device->FlipHWSurface = X11_FlipHWSurface;
159 device->FreeHWSurface = X11_FreeHWSurface; 164 device->FreeHWSurface = X11_FreeHWSurface;
160 device->SetGamma = X11_SetVidModeGamma; 165 device->SetGamma = X11_SetVidModeGamma;
161 device->GetGamma = X11_GetVidModeGamma; 166 device->GetGamma = X11_GetVidModeGamma;
162 device->SetGammaRamp = X11_SetGammaRamp; 167 device->SetGammaRamp = X11_SetGammaRamp;
163 device->GetGammaRamp = NULL; 168 device->GetGammaRamp = NULL;
164 #ifdef HAVE_OPENGL 169 #ifdef HAVE_OPENGL
165 device->GL_LoadLibrary = X11_GL_LoadLibrary; 170 device->GL_LoadLibrary = X11_GL_LoadLibrary;
166 device->GL_GetProcAddress = X11_GL_GetProcAddress; 171 device->GL_GetProcAddress = X11_GL_GetProcAddress;
167 device->GL_GetAttribute = X11_GL_GetAttribute; 172 device->GL_GetAttribute = X11_GL_GetAttribute;
168 device->GL_MakeCurrent = X11_GL_MakeCurrent; 173 device->GL_MakeCurrent = X11_GL_MakeCurrent;
169 device->GL_SwapBuffers = X11_GL_SwapBuffers; 174 device->GL_SwapBuffers = X11_GL_SwapBuffers;
170 #endif 175 #endif
171 device->SetCaption = X11_SetCaption; 176 device->SetCaption = X11_SetCaption;
172 device->SetIcon = X11_SetIcon; 177 device->SetIcon = X11_SetIcon;
173 device->IconifyWindow = X11_IconifyWindow; 178 device->IconifyWindow = X11_IconifyWindow;
174 device->GrabInput = X11_GrabInput; 179 device->GrabInput = X11_GrabInput;
175 device->GetWMInfo = X11_GetWMInfo; 180 device->GetWMInfo = X11_GetWMInfo;
176 device->FreeWMCursor = X11_FreeWMCursor; 181 device->FreeWMCursor = X11_FreeWMCursor;
177 device->CreateWMCursor = X11_CreateWMCursor; 182 device->CreateWMCursor = X11_CreateWMCursor;
178 device->ShowWMCursor = X11_ShowWMCursor; 183 device->ShowWMCursor = X11_ShowWMCursor;
179 device->WarpWMCursor = X11_WarpWMCursor; 184 device->WarpWMCursor = X11_WarpWMCursor;
180 device->CheckMouseMode = X11_CheckMouseMode; 185 device->CheckMouseMode = X11_CheckMouseMode;
181 device->InitOSKeymap = X11_InitOSKeymap; 186 device->InitOSKeymap = X11_InitOSKeymap;
182 device->PumpEvents = X11_PumpEvents; 187 device->PumpEvents = X11_PumpEvents;
183 188
184 device->free = X11_DeleteDevice; 189 device->free = X11_DeleteDevice;
190 }
185 191
186 return device; 192 return device;
187 } 193 }
188 194
189 VideoBootStrap X11_bootstrap = { 195 VideoBootStrap X11_bootstrap = {
190 "x11", "X Window System", 196 "x11", "X Window System",
191 X11_Available, X11_CreateDevice 197 X11_Available, X11_CreateDevice
192 }; 198 };
193
194 /* Shared memory information */
195 extern int XShmQueryExtension(Display *dpy); /* Not in X11 headers */
196 199
197 /* Normal X11 error handler routine */ 200 /* Normal X11 error handler routine */
198 static int (*X_handler)(Display *, XErrorEvent *) = NULL; 201 static int (*X_handler)(Display *, XErrorEvent *) = NULL;
199 static int x_errhandler(Display *d, XErrorEvent *e) 202 static int x_errhandler(Display *d, XErrorEvent *e)
200 { 203 {
273 WMwindow = strtol(SDL_windowid, NULL, 0); 276 WMwindow = strtol(SDL_windowid, NULL, 0);
274 return; 277 return;
275 } 278 }
276 279
277 if(FSwindow) 280 if(FSwindow)
278 XDestroyWindow(SDL_Display, FSwindow); 281 pXDestroyWindow(SDL_Display, FSwindow);
279 282
280 xattr.override_redirect = True; 283 xattr.override_redirect = True;
281 xattr.background_pixel = def_vis ? BlackPixel(SDL_Display, SDL_Screen) : 0; 284 xattr.background_pixel = def_vis ? BlackPixel(SDL_Display, SDL_Screen) : 0;
282 xattr.border_pixel = 0; 285 xattr.border_pixel = 0;
283 xattr.colormap = SDL_XColorMap; 286 xattr.colormap = SDL_XColorMap;
284 287
285 FSwindow = XCreateWindow(SDL_Display, SDL_Root, 288 FSwindow = pXCreateWindow(SDL_Display, SDL_Root,
286 xinerama_x, xinerama_y, 32, 32, 0, 289 xinerama_x, xinerama_y, 32, 32, 0,
287 this->hidden->depth, InputOutput, SDL_Visual, 290 this->hidden->depth, InputOutput, SDL_Visual,
288 CWOverrideRedirect | CWBackPixel | CWBorderPixel 291 CWOverrideRedirect | CWBackPixel | CWBorderPixel
289 | CWColormap, 292 | CWColormap,
290 &xattr); 293 &xattr);
291 294
292 XSelectInput(SDL_Display, FSwindow, StructureNotifyMask); 295 pXSelectInput(SDL_Display, FSwindow, StructureNotifyMask);
293 296
294 /* Tell KDE to keep the fullscreen window on top */ 297 /* Tell KDE to keep the fullscreen window on top */
295 { 298 {
296 XEvent ev; 299 XEvent ev;
297 long mask; 300 long mask;
298 301
299 memset(&ev, 0, sizeof(ev)); 302 memset(&ev, 0, sizeof(ev));
300 ev.xclient.type = ClientMessage; 303 ev.xclient.type = ClientMessage;
301 ev.xclient.window = SDL_Root; 304 ev.xclient.window = SDL_Root;
302 ev.xclient.message_type = XInternAtom(SDL_Display, 305 ev.xclient.message_type = pXInternAtom(SDL_Display,
303 "KWM_KEEP_ON_TOP", False); 306 "KWM_KEEP_ON_TOP", False);
304 ev.xclient.format = 32; 307 ev.xclient.format = 32;
305 ev.xclient.data.l[0] = FSwindow; 308 ev.xclient.data.l[0] = FSwindow;
306 ev.xclient.data.l[1] = CurrentTime; 309 ev.xclient.data.l[1] = CurrentTime;
307 mask = SubstructureRedirectMask; 310 mask = SubstructureRedirectMask;
308 XSendEvent(SDL_Display, SDL_Root, False, mask, &ev); 311 pXSendEvent(SDL_Display, SDL_Root, False, mask, &ev);
309 } 312 }
310 313
311 hints = NULL; 314 hints = NULL;
312 titleprop.value = iconprop.value = NULL; 315 titleprop.value = iconprop.value = NULL;
313 if(WMwindow) { 316 if(WMwindow) {
314 /* All window attributes must survive the recreation */ 317 /* All window attributes must survive the recreation */
315 hints = XGetWMHints(SDL_Display, WMwindow); 318 hints = pXGetWMHints(SDL_Display, WMwindow);
316 XGetWMName(SDL_Display, WMwindow, &titleprop); 319 pXGetWMName(SDL_Display, WMwindow, &titleprop);
317 XGetWMIconName(SDL_Display, WMwindow, &iconprop); 320 pXGetWMIconName(SDL_Display, WMwindow, &iconprop);
318 XDestroyWindow(SDL_Display, WMwindow); 321 pXDestroyWindow(SDL_Display, WMwindow);
319 } 322 }
320 323
321 /* Create the window for windowed management */ 324 /* Create the window for windowed management */
322 /* (reusing the xattr structure above) */ 325 /* (reusing the xattr structure above) */
323 WMwindow = XCreateWindow(SDL_Display, SDL_Root, 0, 0, 32, 32, 0, 326 WMwindow = pXCreateWindow(SDL_Display, SDL_Root, 0, 0, 32, 32, 0,
324 this->hidden->depth, InputOutput, SDL_Visual, 327 this->hidden->depth, InputOutput, SDL_Visual,
325 CWBackPixel | CWBorderPixel | CWColormap, 328 CWBackPixel | CWBorderPixel | CWColormap,
326 &xattr); 329 &xattr);
327 330
328 /* Set the input hints so we get keyboard input */ 331 /* Set the input hints so we get keyboard input */
329 if(!hints) { 332 if(!hints) {
330 hints = XAllocWMHints(); 333 hints = pXAllocWMHints();
331 hints->input = True; 334 hints->input = True;
332 hints->flags = InputHint; 335 hints->flags = InputHint;
333 } 336 }
334 XSetWMHints(SDL_Display, WMwindow, hints); 337 pXSetWMHints(SDL_Display, WMwindow, hints);
335 XFree(hints); 338 pXFree(hints);
336 if(titleprop.value) { 339 if(titleprop.value) {
337 XSetWMName(SDL_Display, WMwindow, &titleprop); 340 pXSetWMName(SDL_Display, WMwindow, &titleprop);
338 XFree(titleprop.value); 341 pXFree(titleprop.value);
339 } 342 }
340 if(iconprop.value) { 343 if(iconprop.value) {
341 XSetWMIconName(SDL_Display, WMwindow, &iconprop); 344 pXSetWMIconName(SDL_Display, WMwindow, &iconprop);
342 XFree(iconprop.value); 345 pXFree(iconprop.value);
343 } 346 }
344 347
345 XSelectInput(SDL_Display, WMwindow, 348 pXSelectInput(SDL_Display, WMwindow,
346 FocusChangeMask | KeyPressMask | KeyReleaseMask 349 FocusChangeMask | KeyPressMask | KeyReleaseMask
347 | PropertyChangeMask | StructureNotifyMask | KeymapStateMask); 350 | PropertyChangeMask | StructureNotifyMask | KeymapStateMask);
348 351
349 /* Set the class hints so we can get an icon (AfterStep) */ 352 /* Set the class hints so we can get an icon (AfterStep) */
350 { 353 {
351 XClassHint *classhints; 354 XClassHint *classhints;
352 classhints = XAllocClassHint(); 355 classhints = pXAllocClassHint();
353 if(classhints != NULL) { 356 if(classhints != NULL) {
354 char *classname = getenv("SDL_VIDEO_X11_WMCLASS"); 357 char *classname = getenv("SDL_VIDEO_X11_WMCLASS");
355 if ( ! classname ) { 358 if ( ! classname ) {
356 classname = "SDL_App"; 359 classname = "SDL_App";
357 } 360 }
358 classhints->res_name = classname; 361 classhints->res_name = classname;
359 classhints->res_class = classname; 362 classhints->res_class = classname;
360 XSetClassHint(SDL_Display, WMwindow, classhints); 363 pXSetClassHint(SDL_Display, WMwindow, classhints);
361 XFree(classhints); 364 pXFree(classhints);
362 } 365 }
363 } 366 }
364 367
365 /* Allow the window to be deleted by the window manager */ 368 /* Allow the window to be deleted by the window manager */
366 WM_DELETE_WINDOW = XInternAtom(SDL_Display, "WM_DELETE_WINDOW", False); 369 WM_DELETE_WINDOW = pXInternAtom(SDL_Display, "WM_DELETE_WINDOW", False);
367 XSetWMProtocols(SDL_Display, WMwindow, &WM_DELETE_WINDOW, 1); 370 pXSetWMProtocols(SDL_Display, WMwindow, &WM_DELETE_WINDOW, 1);
368 } 371 }
369 372
370 static int X11_VideoInit(_THIS, SDL_PixelFormat *vformat) 373 static int X11_VideoInit(_THIS, SDL_PixelFormat *vformat)
371 { 374 {
372 char *display; 375 char *display;
373 int i; 376 int i;
374 377
375 /* Open the X11 display */ 378 /* Open the X11 display */
376 display = NULL; /* Get it from DISPLAY environment variable */ 379 display = NULL; /* Get it from DISPLAY environment variable */
377 380
378 if ( (strncmp(XDisplayName(display), ":", 1) == 0) || 381 if ( (strncmp(pXDisplayName(display), ":", 1) == 0) ||
379 (strncmp(XDisplayName(display), "unix:", 5) == 0) ) { 382 (strncmp(pXDisplayName(display), "unix:", 5) == 0) ) {
380 local_X11 = 1; 383 local_X11 = 1;
381 } else { 384 } else {
382 local_X11 = 0; 385 local_X11 = 0;
383 } 386 }
384 SDL_Display = XOpenDisplay(display); 387 SDL_Display = pXOpenDisplay(display);
385 if ( SDL_Display == NULL ) { 388 if ( SDL_Display == NULL ) {
386 SDL_SetError("Couldn't open X11 display"); 389 SDL_SetError("Couldn't open X11 display");
387 return(-1); 390 return(-1);
388 } 391 }
389 #ifdef X11_DEBUG 392 #ifdef X11_DEBUG
390 XSynchronize(SDL_Display, True); 393 pXSynchronize(SDL_Display, True);
391 #endif 394 #endif
392 395
393 /* Create an alternate X display for graphics updates -- allows us 396 /* Create an alternate X display for graphics updates -- allows us
394 to do graphics updates in a separate thread from event handling. 397 to do graphics updates in a separate thread from event handling.
395 Thread-safe X11 doesn't seem to exist. 398 Thread-safe X11 doesn't seem to exist.
396 */ 399 */
397 GFX_Display = XOpenDisplay(display); 400 GFX_Display = pXOpenDisplay(display);
398 if ( GFX_Display == NULL ) { 401 if ( GFX_Display == NULL ) {
399 SDL_SetError("Couldn't open X11 display"); 402 SDL_SetError("Couldn't open X11 display");
400 return(-1); 403 return(-1);
401 } 404 }
402 405
403 /* Set the normal X error handler */ 406 /* Set the normal X error handler */
404 X_handler = XSetErrorHandler(x_errhandler); 407 X_handler = pXSetErrorHandler(x_errhandler);
405 408
406 /* Set the error handler if we lose the X display */ 409 /* Set the error handler if we lose the X display */
407 XIO_handler = XSetIOErrorHandler(xio_errhandler); 410 XIO_handler = pXSetIOErrorHandler(xio_errhandler);
408 411
409 /* use default screen (from $DISPLAY) */ 412 /* use default screen (from $DISPLAY) */
410 SDL_Screen = DefaultScreen(SDL_Display); 413 SDL_Screen = DefaultScreen(SDL_Display);
411 414
412 #ifndef NO_SHARED_MEMORY 415 #ifndef NO_SHARED_MEMORY
413 /* Check for MIT shared memory extension */ 416 /* Check for MIT shared memory extension */
414 use_mitshm = 0; 417 use_mitshm = 0;
415 if ( local_X11 ) { 418 if ( local_X11 ) {
416 use_mitshm = XShmQueryExtension(SDL_Display); 419 use_mitshm = pXShmQueryExtension(SDL_Display);
417 } 420 }
418 #endif /* NO_SHARED_MEMORY */ 421 #endif /* NO_SHARED_MEMORY */
419 422
420 /* Get the available video modes */ 423 /* Get the available video modes */
421 if(X11_GetVideoModes(this) < 0) 424 if(X11_GetVideoModes(this) < 0)
434 } 437 }
435 SDL_Visual = this->hidden->visuals[i].visual; 438 SDL_Visual = this->hidden->visuals[i].visual;
436 if ( SDL_Visual == DefaultVisual(SDL_Display, SDL_Screen) ) { 439 if ( SDL_Visual == DefaultVisual(SDL_Display, SDL_Screen) ) {
437 SDL_XColorMap = SDL_DisplayColormap; 440 SDL_XColorMap = SDL_DisplayColormap;
438 } else { 441 } else {
439 SDL_XColorMap = XCreateColormap(SDL_Display, SDL_Root, 442 SDL_XColorMap = pXCreateColormap(SDL_Display, SDL_Root,
440 SDL_Visual, AllocNone); 443 SDL_Visual, AllocNone);
441 } 444 }
442 this->hidden->depth = this->hidden->visuals[i].depth; 445 this->hidden->depth = this->hidden->visuals[i].depth;
443 vformat->BitsPerPixel = this->hidden->visuals[i].bpp; 446 vformat->BitsPerPixel = this->hidden->visuals[i].bpp;
444 if ( vformat->BitsPerPixel > 8 ) { 447 if ( vformat->BitsPerPixel > 8 ) {
461 464
462 /* Fill in some window manager capabilities */ 465 /* Fill in some window manager capabilities */
463 this->info.wm_available = 1; 466 this->info.wm_available = 1;
464 467
465 /* We're done! */ 468 /* We're done! */
466 XFlush(SDL_Display); 469 pXFlush(SDL_Display);
467 return(0); 470 return(0);
468 } 471 }
469 472
470 static void X11_DestroyWindow(_THIS, SDL_Surface *screen) 473 static void X11_DestroyWindow(_THIS, SDL_Surface *screen)
471 { 474 {
476 X11_GL_Shutdown(this); 479 X11_GL_Shutdown(this);
477 480
478 if ( ! SDL_windowid ) { 481 if ( ! SDL_windowid ) {
479 /* Hide the managed window */ 482 /* Hide the managed window */
480 if ( WMwindow ) { 483 if ( WMwindow ) {
481 XUnmapWindow(SDL_Display, WMwindow); 484 pXUnmapWindow(SDL_Display, WMwindow);
482 } 485 }
483 if ( screen && (screen->flags & SDL_FULLSCREEN) ) { 486 if ( screen && (screen->flags & SDL_FULLSCREEN) ) {
484 screen->flags &= ~SDL_FULLSCREEN; 487 screen->flags &= ~SDL_FULLSCREEN;
485 X11_LeaveFullScreen(this); 488 X11_LeaveFullScreen(this);
486 } 489 }
487 490
488 /* Destroy the output window */ 491 /* Destroy the output window */
489 if ( SDL_Window ) { 492 if ( SDL_Window ) {
490 XDestroyWindow(SDL_Display, SDL_Window); 493 pXDestroyWindow(SDL_Display, SDL_Window);
491 } 494 }
492 495
493 /* Free the colormap entries */ 496 /* Free the colormap entries */
494 if ( SDL_XPixels ) { 497 if ( SDL_XPixels ) {
495 int numcolors; 498 int numcolors;
496 unsigned long pixel; 499 unsigned long pixel;
497 numcolors = SDL_Visual->map_entries; 500 numcolors = SDL_Visual->map_entries;
498 for ( pixel=0; pixel<numcolors; ++pixel ) { 501 for ( pixel=0; pixel<numcolors; ++pixel ) {
499 while ( SDL_XPixels[pixel] > 0 ) { 502 while ( SDL_XPixels[pixel] > 0 ) {
500 XFreeColors(GFX_Display, 503 pXFreeColors(GFX_Display,
501 SDL_DisplayColormap,&pixel,1,0); 504 SDL_DisplayColormap,&pixel,1,0);
502 --SDL_XPixels[pixel]; 505 --SDL_XPixels[pixel];
503 } 506 }
504 } 507 }
505 free(SDL_XPixels); 508 free(SDL_XPixels);
506 SDL_XPixels = NULL; 509 SDL_XPixels = NULL;
507 } 510 }
508 511
509 /* Free the graphics context */ 512 /* Free the graphics context */
510 if ( SDL_GC ) { 513 if ( SDL_GC ) {
511 XFreeGC(SDL_Display, SDL_GC); 514 pXFreeGC(SDL_Display, SDL_GC);
512 SDL_GC = 0; 515 SDL_GC = 0;
513 } 516 }
514 } 517 }
515 } 518 }
516 519
536 539
537 static void X11_SetSizeHints(_THIS, int w, int h, Uint32 flags) 540 static void X11_SetSizeHints(_THIS, int w, int h, Uint32 flags)
538 { 541 {
539 XSizeHints *hints; 542 XSizeHints *hints;
540 543
541 hints = XAllocSizeHints(); 544 hints = pXAllocSizeHints();
542 if ( hints ) { 545 if ( hints ) {
543 if ( flags & SDL_RESIZABLE ) { 546 if ( flags & SDL_RESIZABLE ) {
544 hints->min_width = 32; 547 hints->min_width = 32;
545 hints->min_height = 32; 548 hints->min_height = 32;
546 hints->max_height = 4096; 549 hints->max_height = 4096;
556 hints->flags |= USPosition; 559 hints->flags |= USPosition;
557 } else 560 } else
558 /* Center it, if desired */ 561 /* Center it, if desired */
559 if ( X11_WindowPosition(this, &hints->x, &hints->y, w, h) ) { 562 if ( X11_WindowPosition(this, &hints->x, &hints->y, w, h) ) {
560 hints->flags |= USPosition; 563 hints->flags |= USPosition;
561 XMoveWindow(SDL_Display, WMwindow, hints->x, hints->y); 564 pXMoveWindow(SDL_Display, WMwindow, hints->x, hints->y);
562 565
563 /* Flush the resize event so we don't catch it later */ 566 /* Flush the resize event so we don't catch it later */
564 XSync(SDL_Display, True); 567 pXSync(SDL_Display, True);
565 } 568 }
566 XSetWMNormalHints(SDL_Display, WMwindow, hints); 569 pXSetWMNormalHints(SDL_Display, WMwindow, hints);
567 XFree(hints); 570 pXFree(hints);
568 } 571 }
569 572
570 /* Respect the window caption style */ 573 /* Respect the window caption style */
571 if ( flags & SDL_NOFRAME ) { 574 if ( flags & SDL_NOFRAME ) {
572 SDL_bool set; 575 SDL_bool set;
574 577
575 /* We haven't modified the window manager hints yet */ 578 /* We haven't modified the window manager hints yet */
576 set = SDL_FALSE; 579 set = SDL_FALSE;
577 580
578 /* First try to set MWM hints */ 581 /* First try to set MWM hints */
579 WM_HINTS = XInternAtom(SDL_Display, "_MOTIF_WM_HINTS", True); 582 WM_HINTS = pXInternAtom(SDL_Display, "_MOTIF_WM_HINTS", True);
580 if ( WM_HINTS != None ) { 583 if ( WM_HINTS != None ) {
581 /* Hints used by Motif compliant window managers */ 584 /* Hints used by Motif compliant window managers */
582 struct { 585 struct {
583 unsigned long flags; 586 unsigned long flags;
584 unsigned long functions; 587 unsigned long functions;
585 unsigned long decorations; 588 unsigned long decorations;
586 long input_mode; 589 long input_mode;
587 unsigned long status; 590 unsigned long status;
588 } MWMHints = { (1L << 1), 0, 0, 0, 0 }; 591 } MWMHints = { (1L << 1), 0, 0, 0, 0 };
589 592
590 XChangeProperty(SDL_Display, WMwindow, 593 pXChangeProperty(SDL_Display, WMwindow,
591 WM_HINTS, WM_HINTS, 32, 594 WM_HINTS, WM_HINTS, 32,
592 PropModeReplace, 595 PropModeReplace,
593 (unsigned char *)&MWMHints, 596 (unsigned char *)&MWMHints,
594 sizeof(MWMHints)/sizeof(long)); 597 sizeof(MWMHints)/sizeof(long));
595 set = SDL_TRUE; 598 set = SDL_TRUE;
596 } 599 }
597 /* Now try to set KWM hints */ 600 /* Now try to set KWM hints */
598 WM_HINTS = XInternAtom(SDL_Display, "KWM_WIN_DECORATION", True); 601 WM_HINTS = pXInternAtom(SDL_Display, "KWM_WIN_DECORATION", True);
599 if ( WM_HINTS != None ) { 602 if ( WM_HINTS != None ) {
600 long KWMHints = 0; 603 long KWMHints = 0;
601 604
602 XChangeProperty(SDL_Display, WMwindow, 605 pXChangeProperty(SDL_Display, WMwindow,
603 WM_HINTS, WM_HINTS, 32, 606 WM_HINTS, WM_HINTS, 32,
604 PropModeReplace, 607 PropModeReplace,
605 (unsigned char *)&KWMHints, 608 (unsigned char *)&KWMHints,
606 sizeof(KWMHints)/sizeof(long)); 609 sizeof(KWMHints)/sizeof(long));
607 set = SDL_TRUE; 610 set = SDL_TRUE;
608 } 611 }
609 /* Now try to set GNOME hints */ 612 /* Now try to set GNOME hints */
610 WM_HINTS = XInternAtom(SDL_Display, "_WIN_HINTS", True); 613 WM_HINTS = pXInternAtom(SDL_Display, "_WIN_HINTS", True);
611 if ( WM_HINTS != None ) { 614 if ( WM_HINTS != None ) {
612 long GNOMEHints = 0; 615 long GNOMEHints = 0;
613 616
614 XChangeProperty(SDL_Display, WMwindow, 617 pXChangeProperty(SDL_Display, WMwindow,
615 WM_HINTS, WM_HINTS, 32, 618 WM_HINTS, WM_HINTS, 32,
616 PropModeReplace, 619 PropModeReplace,
617 (unsigned char *)&GNOMEHints, 620 (unsigned char *)&GNOMEHints,
618 sizeof(GNOMEHints)/sizeof(long)); 621 sizeof(GNOMEHints)/sizeof(long));
619 set = SDL_TRUE; 622 set = SDL_TRUE;
620 } 623 }
621 /* Finally set the transient hints if necessary */ 624 /* Finally set the transient hints if necessary */
622 if ( ! set ) { 625 if ( ! set ) {
623 XSetTransientForHint(SDL_Display, WMwindow, SDL_Root); 626 pXSetTransientForHint(SDL_Display, WMwindow, SDL_Root);
624 } 627 }
625 } else { 628 } else {
626 SDL_bool set; 629 SDL_bool set;
627 Atom WM_HINTS; 630 Atom WM_HINTS;
628 631
629 /* We haven't modified the window manager hints yet */ 632 /* We haven't modified the window manager hints yet */
630 set = SDL_FALSE; 633 set = SDL_FALSE;
631 634
632 /* First try to unset MWM hints */ 635 /* First try to unset MWM hints */
633 WM_HINTS = XInternAtom(SDL_Display, "_MOTIF_WM_HINTS", True); 636 WM_HINTS = pXInternAtom(SDL_Display, "_MOTIF_WM_HINTS", True);
634 if ( WM_HINTS != None ) { 637 if ( WM_HINTS != None ) {
635 XDeleteProperty(SDL_Display, WMwindow, WM_HINTS); 638 pXDeleteProperty(SDL_Display, WMwindow, WM_HINTS);
636 set = SDL_TRUE; 639 set = SDL_TRUE;
637 } 640 }
638 /* Now try to unset KWM hints */ 641 /* Now try to unset KWM hints */
639 WM_HINTS = XInternAtom(SDL_Display, "KWM_WIN_DECORATION", True); 642 WM_HINTS = pXInternAtom(SDL_Display, "KWM_WIN_DECORATION", True);
640 if ( WM_HINTS != None ) { 643 if ( WM_HINTS != None ) {
641 XDeleteProperty(SDL_Display, WMwindow, WM_HINTS); 644 pXDeleteProperty(SDL_Display, WMwindow, WM_HINTS);
642 set = SDL_TRUE; 645 set = SDL_TRUE;
643 } 646 }
644 /* Now try to unset GNOME hints */ 647 /* Now try to unset GNOME hints */
645 WM_HINTS = XInternAtom(SDL_Display, "_WIN_HINTS", True); 648 WM_HINTS = pXInternAtom(SDL_Display, "_WIN_HINTS", True);
646 if ( WM_HINTS != None ) { 649 if ( WM_HINTS != None ) {
647 XDeleteProperty(SDL_Display, WMwindow, WM_HINTS); 650 pXDeleteProperty(SDL_Display, WMwindow, WM_HINTS);
648 set = SDL_TRUE; 651 set = SDL_TRUE;
649 } 652 }
650 /* Finally unset the transient hints if necessary */ 653 /* Finally unset the transient hints if necessary */
651 if ( ! set ) { 654 if ( ! set ) {
652 /* NOTE: Does this work? */ 655 /* NOTE: Does this work? */
653 XSetTransientForHint(SDL_Display, WMwindow, None); 656 pXSetTransientForHint(SDL_Display, WMwindow, None);
654 } 657 }
655 } 658 }
656 } 659 }
657 660
658 static int X11_CreateWindow(_THIS, SDL_Surface *screen, 661 static int X11_CreateWindow(_THIS, SDL_Surface *screen,
686 vis = vi->visual; 689 vis = vi->visual;
687 depth = vi->depth; 690 depth = vi->depth;
688 } else if ( SDL_windowid ) { 691 } else if ( SDL_windowid ) {
689 XWindowAttributes a; 692 XWindowAttributes a;
690 693
691 XGetWindowAttributes(SDL_Display, SDL_Window, &a); 694 pXGetWindowAttributes(SDL_Display, SDL_Window, &a);
692 vis = a.visual; 695 vis = a.visual;
693 depth = a.depth; 696 depth = a.depth;
694 } else { 697 } else {
695 for ( i = 0; i < this->hidden->nvisuals; i++ ) { 698 for ( i = 0; i < this->hidden->nvisuals; i++ ) {
696 if ( this->hidden->visuals[i].bpp == bpp ) 699 if ( this->hidden->visuals[i].bpp == bpp )
715 vis->red_mask, vis->green_mask, vis->blue_mask, 0) ) 718 vis->red_mask, vis->green_mask, vis->blue_mask, 0) )
716 return -1; 719 return -1;
717 720
718 /* Create the appropriate colormap */ 721 /* Create the appropriate colormap */
719 if ( SDL_XColorMap != SDL_DisplayColormap ) { 722 if ( SDL_XColorMap != SDL_DisplayColormap ) {
720 XFreeColormap(SDL_Display, SDL_XColorMap); 723 pXFreeColormap(SDL_Display, SDL_XColorMap);
721 } 724 }
722 if ( SDL_Visual->class == PseudoColor ) { 725 if ( SDL_Visual->class == PseudoColor ) {
723 int ncolors; 726 int ncolors;
724 727
725 /* Allocate the pixel flags */ 728 /* Allocate the pixel flags */
735 if ( SDL_Visual != DefaultVisual(SDL_Display, SDL_Screen) ) { 738 if ( SDL_Visual != DefaultVisual(SDL_Display, SDL_Screen) ) {
736 flags |= SDL_HWPALETTE; 739 flags |= SDL_HWPALETTE;
737 } 740 }
738 if ( flags & SDL_HWPALETTE ) { 741 if ( flags & SDL_HWPALETTE ) {
739 screen->flags |= SDL_HWPALETTE; 742 screen->flags |= SDL_HWPALETTE;
740 SDL_XColorMap = XCreateColormap(SDL_Display, SDL_Root, 743 SDL_XColorMap = pXCreateColormap(SDL_Display, SDL_Root,
741 SDL_Visual, AllocAll); 744 SDL_Visual, AllocAll);
742 } else { 745 } else {
743 SDL_XColorMap = SDL_DisplayColormap; 746 SDL_XColorMap = SDL_DisplayColormap;
744 } 747 }
745 } else if ( SDL_Visual->class == DirectColor ) { 748 } else if ( SDL_Visual->class == DirectColor ) {
746 749
747 /* Create a colormap which we can manipulate for gamma */ 750 /* Create a colormap which we can manipulate for gamma */
748 SDL_XColorMap = XCreateColormap(SDL_Display, SDL_Root, 751 SDL_XColorMap = pXCreateColormap(SDL_Display, SDL_Root,
749 SDL_Visual, AllocAll); 752 SDL_Visual, AllocAll);
750 XSync(SDL_Display, False); 753 pXSync(SDL_Display, False);
751 754
752 /* Initialize the colormap to the identity mapping */ 755 /* Initialize the colormap to the identity mapping */
753 SDL_GetGammaRamp(0, 0, 0); 756 SDL_GetGammaRamp(0, 0, 0);
754 this->screen = screen; 757 this->screen = screen;
755 X11_SetGammaRamp(this, this->gamma); 758 X11_SetGammaRamp(this, this->gamma);
756 this->screen = NULL; 759 this->screen = NULL;
757 } else { 760 } else {
758 /* Create a read-only colormap for our window */ 761 /* Create a read-only colormap for our window */
759 SDL_XColorMap = XCreateColormap(SDL_Display, SDL_Root, 762 SDL_XColorMap = pXCreateColormap(SDL_Display, SDL_Root,
760 SDL_Visual, AllocNone); 763 SDL_Visual, AllocNone);
761 } 764 }
762 765
763 /* Recreate the auxiliary windows, if needed (required for GL) */ 766 /* Recreate the auxiliary windows, if needed (required for GL) */
764 if ( vis_change ) 767 if ( vis_change )
767 if(screen->flags & SDL_HWPALETTE) { 770 if(screen->flags & SDL_HWPALETTE) {
768 /* Since the full-screen window might have got a nonzero background 771 /* Since the full-screen window might have got a nonzero background
769 colour (0 is white on some displays), we should reset the 772 colour (0 is white on some displays), we should reset the
770 background to 0 here since that is what the user expects 773 background to 0 here since that is what the user expects
771 with a private colormap */ 774 with a private colormap */
772 XSetWindowBackground(SDL_Display, FSwindow, 0); 775 pXSetWindowBackground(SDL_Display, FSwindow, 0);
773 XClearWindow(SDL_Display, FSwindow); 776 pXClearWindow(SDL_Display, FSwindow);
774 } 777 }
775 778
776 /* resize the (possibly new) window manager window */ 779 /* resize the (possibly new) window manager window */
777 if( !SDL_windowid ) { 780 if( !SDL_windowid ) {
778 X11_SetSizeHints(this, w, h, flags); 781 X11_SetSizeHints(this, w, h, flags);
779 current_w = w; 782 current_w = w;
780 current_h = h; 783 current_h = h;
781 XResizeWindow(SDL_Display, WMwindow, w, h); 784 pXResizeWindow(SDL_Display, WMwindow, w, h);
782 } 785 }
783 786
784 /* Create (or use) the X11 display window */ 787 /* Create (or use) the X11 display window */
785 if ( !SDL_windowid ) { 788 if ( !SDL_windowid ) {
786 if ( flags & SDL_OPENGL ) { 789 if ( flags & SDL_OPENGL ) {
791 XSetWindowAttributes swa; 794 XSetWindowAttributes swa;
792 795
793 swa.background_pixel = 0; 796 swa.background_pixel = 0;
794 swa.border_pixel = 0; 797 swa.border_pixel = 0;
795 swa.colormap = SDL_XColorMap; 798 swa.colormap = SDL_XColorMap;
796 SDL_Window = XCreateWindow(SDL_Display, WMwindow, 799 SDL_Window = pXCreateWindow(SDL_Display, WMwindow,
797 0, 0, w, h, 0, depth, 800 0, 0, w, h, 0, depth,
798 InputOutput, SDL_Visual, 801 InputOutput, SDL_Visual,
799 CWBackPixel | CWBorderPixel 802 CWBackPixel | CWBorderPixel
800 | CWColormap, &swa); 803 | CWColormap, &swa);
801 } 804 }
802 /* Only manage our input if we own the window */ 805 /* Only manage our input if we own the window */
803 XSelectInput(SDL_Display, SDL_Window, 806 pXSelectInput(SDL_Display, SDL_Window,
804 ( EnterWindowMask | LeaveWindowMask 807 ( EnterWindowMask | LeaveWindowMask
805 | ButtonPressMask | ButtonReleaseMask 808 | ButtonPressMask | ButtonReleaseMask
806 | PointerMotionMask | ExposureMask )); 809 | PointerMotionMask | ExposureMask ));
807 } 810 }
808 811
815 } 818 }
816 } else { 819 } else {
817 XGCValues gcv; 820 XGCValues gcv;
818 821
819 gcv.graphics_exposures = False; 822 gcv.graphics_exposures = False;
820 SDL_GC = XCreateGC(SDL_Display, SDL_Window, 823 SDL_GC = pXCreateGC(SDL_Display, SDL_Window,
821 GCGraphicsExposures, &gcv); 824 GCGraphicsExposures, &gcv);
822 if ( ! SDL_GC ) { 825 if ( ! SDL_GC ) {
823 SDL_SetError("Couldn't create graphics context"); 826 SDL_SetError("Couldn't create graphics context");
824 return(-1); 827 return(-1);
825 } 828 }
826 } 829 }
827 830
828 /* Set our colormaps when not setting a GL mode */ 831 /* Set our colormaps when not setting a GL mode */
829 if ( ! (flags & SDL_OPENGL) ) { 832 if ( ! (flags & SDL_OPENGL) ) {
830 XSetWindowColormap(SDL_Display, SDL_Window, SDL_XColorMap); 833 pXSetWindowColormap(SDL_Display, SDL_Window, SDL_XColorMap);
831 if( !SDL_windowid ) { 834 if( !SDL_windowid ) {
832 XSetWindowColormap(SDL_Display, FSwindow, SDL_XColorMap); 835 pXSetWindowColormap(SDL_Display, FSwindow, SDL_XColorMap);
833 XSetWindowColormap(SDL_Display, WMwindow, SDL_XColorMap); 836 pXSetWindowColormap(SDL_Display, WMwindow, SDL_XColorMap);
834 } 837 }
835 } 838 }
836 839
837 #if 0 /* This is an experiment - are the graphics faster now? - nope. */ 840 #if 0 /* This is an experiment - are the graphics faster now? - nope. */
838 if ( getenv("SDL_VIDEO_X11_BACKINGSTORE") ) 841 if ( getenv("SDL_VIDEO_X11_BACKINGSTORE") )
843 XSetWindowAttributes a; 846 XSetWindowAttributes a;
844 847
845 xscreen = ScreenOfDisplay(SDL_Display, SDL_Screen); 848 xscreen = ScreenOfDisplay(SDL_Display, SDL_Screen);
846 a.backing_store = DoesBackingStore(xscreen); 849 a.backing_store = DoesBackingStore(xscreen);
847 if ( a.backing_store != NotUseful ) { 850 if ( a.backing_store != NotUseful ) {
848 XChangeWindowAttributes(SDL_Display, SDL_Window, 851 pXChangeWindowAttributes(SDL_Display, SDL_Window,
849 CWBackingStore, &a); 852 CWBackingStore, &a);
850 } 853 }
851 } 854 }
852 855
853 /* Update the internal keyboard state */ 856 /* Update the internal keyboard state */
877 } 880 }
878 } 881 }
879 882
880 /* Map them both and go fullscreen, if requested */ 883 /* Map them both and go fullscreen, if requested */
881 if ( ! SDL_windowid ) { 884 if ( ! SDL_windowid ) {
882 XMapWindow(SDL_Display, SDL_Window); 885 pXMapWindow(SDL_Display, SDL_Window);
883 XMapWindow(SDL_Display, WMwindow); 886 pXMapWindow(SDL_Display, WMwindow);
884 X11_WaitMapped(this, WMwindow); 887 X11_WaitMapped(this, WMwindow);
885 if ( flags & SDL_FULLSCREEN ) { 888 if ( flags & SDL_FULLSCREEN ) {
886 screen->flags |= SDL_FULLSCREEN; 889 screen->flags |= SDL_FULLSCREEN;
887 X11_EnterFullScreen(this); 890 X11_EnterFullScreen(this);
888 } else { 891 } else {
898 if ( ! SDL_windowid ) { 901 if ( ! SDL_windowid ) {
899 /* Resize the window manager window */ 902 /* Resize the window manager window */
900 X11_SetSizeHints(this, w, h, flags); 903 X11_SetSizeHints(this, w, h, flags);
901 current_w = w; 904 current_w = w;
902 current_h = h; 905 current_h = h;
903 XResizeWindow(SDL_Display, WMwindow, w, h); 906 pXResizeWindow(SDL_Display, WMwindow, w, h);
904 907
905 /* Resize the fullscreen and display windows */ 908 /* Resize the fullscreen and display windows */
906 if ( flags & SDL_FULLSCREEN ) { 909 if ( flags & SDL_FULLSCREEN ) {
907 if ( screen->flags & SDL_FULLSCREEN ) { 910 if ( screen->flags & SDL_FULLSCREEN ) {
908 X11_ResizeFullScreen(this); 911 X11_ResizeFullScreen(this);
914 if ( screen->flags & SDL_FULLSCREEN ) { 917 if ( screen->flags & SDL_FULLSCREEN ) {
915 screen->flags &= ~SDL_FULLSCREEN; 918 screen->flags &= ~SDL_FULLSCREEN;
916 X11_LeaveFullScreen(this); 919 X11_LeaveFullScreen(this);
917 } 920 }
918 } 921 }
919 XResizeWindow(SDL_Display, SDL_Window, w, h); 922 pXResizeWindow(SDL_Display, SDL_Window, w, h);
920 } 923 }
921 return(0); 924 return(0);
922 } 925 }
923 926
924 SDL_Surface *X11_SetVideoMode(_THIS, SDL_Surface *current, 927 SDL_Surface *X11_SetVideoMode(_THIS, SDL_Surface *current,
936 flags &= ~SDL_FULLSCREEN; 939 flags &= ~SDL_FULLSCREEN;
937 } 940 }
938 } 941 }
939 942
940 /* Flush any delayed updates */ 943 /* Flush any delayed updates */
941 XSync(GFX_Display, False); 944 pXSync(GFX_Display, False);
942 945
943 /* Set up the X11 window */ 946 /* Set up the X11 window */
944 saved_flags = current->flags; 947 saved_flags = current->flags;
945 if ( (SDL_Window) && ((saved_flags&SDL_OPENGL) == (flags&SDL_OPENGL)) 948 if ( (SDL_Window) && ((saved_flags&SDL_OPENGL) == (flags&SDL_OPENGL))
946 && (bpp == current->format->BitsPerPixel) 949 && (bpp == current->format->BitsPerPixel)
966 } 969 }
967 current->flags |= (flags&(SDL_RESIZABLE|SDL_NOFRAME)); 970 current->flags |= (flags&(SDL_RESIZABLE|SDL_NOFRAME));
968 971
969 done: 972 done:
970 /* Release the event thread */ 973 /* Release the event thread */
971 XSync(SDL_Display, False); 974 pXSync(SDL_Display, False);
972 SDL_Unlock_EventThread(); 975 SDL_Unlock_EventThread();
973 976
974 /* We're done! */ 977 /* We're done! */
975 return(current); 978 return(current);
976 } 979 }
1015 int x, y; 1018 int x, y;
1016 unsigned int mask; 1019 unsigned int mask;
1017 1020
1018 /* Lock the event thread, in multi-threading environments */ 1021 /* Lock the event thread, in multi-threading environments */
1019 SDL_Lock_EventThread(); 1022 SDL_Lock_EventThread();
1020 if ( XQueryPointer(SDL_Display, SDL_Window, &u1, &current_win, 1023 if ( pXQueryPointer(SDL_Display, SDL_Window, &u1, &current_win,
1021 &u2, &u2, &x, &y, &mask) ) { 1024 &u2, &u2, &x, &y, &mask) ) {
1022 if ( (x >= 0) && (x < SDL_VideoSurface->w) && 1025 if ( (x >= 0) && (x < SDL_VideoSurface->w) &&
1023 (y >= 0) && (y < SDL_VideoSurface->h) ) { 1026 (y >= 0) && (y < SDL_VideoSurface->h) ) {
1024 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); 1027 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
1025 SDL_PrivateMouseMotion(0, 0, x, y); 1028 SDL_PrivateMouseMotion(0, 0, x, y);
1052 all[i].pixel = i; 1055 all[i].pixel = i;
1053 /* 1056 /*
1054 * XQueryColors sets the flags in the XColor struct, so we use 1057 * XQueryColors sets the flags in the XColor struct, so we use
1055 * that to keep track of which colours are available 1058 * that to keep track of which colours are available
1056 */ 1059 */
1057 XQueryColors(GFX_Display, SDL_XColorMap, all, 256); 1060 pXQueryColors(GFX_Display, SDL_XColorMap, all, 256);
1058 1061
1059 for(i = 0; i < nwant; i++) { 1062 for(i = 0; i < nwant; i++) {
1060 XColor *c; 1063 XColor *c;
1061 int j; 1064 int j;
1062 int best = 0; 1065 int best = 0;
1078 } 1081 }
1079 } 1082 }
1080 if(SDL_XPixels[best]) 1083 if(SDL_XPixels[best])
1081 continue; /* already allocated, waste no more time */ 1084 continue; /* already allocated, waste no more time */
1082 c = all + best; 1085 c = all + best;
1083 if(XAllocColor(GFX_Display, SDL_XColorMap, c)) { 1086 if(pXAllocColor(GFX_Display, SDL_XColorMap, c)) {
1084 /* got it */ 1087 /* got it */
1085 colors[c->pixel].r = c->red >> 8; 1088 colors[c->pixel].r = c->red >> 8;
1086 colors[c->pixel].g = c->green >> 8; 1089 colors[c->pixel].g = c->green >> 8;
1087 colors[c->pixel].b = c->blue >> 8; 1090 colors[c->pixel].b = c->blue >> 8;
1088 ++SDL_XPixels[c->pixel]; 1091 ++SDL_XPixels[c->pixel];
1120 xcmap[i].red = (colors[i].r<<8)|colors[i].r; 1123 xcmap[i].red = (colors[i].r<<8)|colors[i].r;
1121 xcmap[i].green = (colors[i].g<<8)|colors[i].g; 1124 xcmap[i].green = (colors[i].g<<8)|colors[i].g;
1122 xcmap[i].blue = (colors[i].b<<8)|colors[i].b; 1125 xcmap[i].blue = (colors[i].b<<8)|colors[i].b;
1123 xcmap[i].flags = (DoRed|DoGreen|DoBlue); 1126 xcmap[i].flags = (DoRed|DoGreen|DoBlue);
1124 } 1127 }
1125 XStoreColors(GFX_Display, SDL_XColorMap, xcmap, ncolors); 1128 pXStoreColors(GFX_Display, SDL_XColorMap, xcmap, ncolors);
1126 XSync(GFX_Display, False); 1129 pXSync(GFX_Display, False);
1127 FREEA(xcmap); 1130 FREEA(xcmap);
1128 } else { 1131 } else {
1129 /* 1132 /*
1130 * Shared colormap: We only allocate read-only cells, which 1133 * Shared colormap: We only allocate read-only cells, which
1131 * increases the likelyhood of colour sharing with other 1134 * increases the likelyhood of colour sharing with other
1149 while(SDL_XPixels[pixel]) { 1152 while(SDL_XPixels[pixel]) {
1150 freelist[nfree++] = pixel; 1153 freelist[nfree++] = pixel;
1151 --SDL_XPixels[pixel]; 1154 --SDL_XPixels[pixel];
1152 } 1155 }
1153 } 1156 }
1154 XFreeColors(GFX_Display, SDL_XColorMap, freelist, nfree, 0); 1157 pXFreeColors(GFX_Display, SDL_XColorMap, freelist, nfree, 0);
1155 FREEA(freelist); 1158 FREEA(freelist);
1156 1159
1157 want = ALLOCA(ncolors * sizeof(SDL_Color)); 1160 want = ALLOCA(ncolors * sizeof(SDL_Color));
1158 reject = ALLOCA(ncolors * sizeof(SDL_Color)); 1161 reject = ALLOCA(ncolors * sizeof(SDL_Color));
1159 memcpy(want, colors + firstcolor, ncolors * sizeof(SDL_Color)); 1162 memcpy(want, colors + firstcolor, ncolors * sizeof(SDL_Color));
1166 XColor col; 1169 XColor col;
1167 col.red = want[i].r << 8; 1170 col.red = want[i].r << 8;
1168 col.green = want[i].g << 8; 1171 col.green = want[i].g << 8;
1169 col.blue = want[i].b << 8; 1172 col.blue = want[i].b << 8;
1170 col.flags = DoRed | DoGreen | DoBlue; 1173 col.flags = DoRed | DoGreen | DoBlue;
1171 if(XAllocColor(GFX_Display, SDL_XColorMap, &col)) { 1174 if(pXAllocColor(GFX_Display, SDL_XColorMap, &col)) {
1172 /* We got the colour, or at least the nearest 1175 /* We got the colour, or at least the nearest
1173 the hardware could get. */ 1176 the hardware could get. */
1174 colors[col.pixel].r = col.red >> 8; 1177 colors[col.pixel].r = col.red >> 8;
1175 colors[col.pixel].g = col.green >> 8; 1178 colors[col.pixel].g = col.green >> 8;
1176 colors[col.pixel].b = col.blue >> 8; 1179 colors[col.pixel].b = col.blue >> 8;
1210 xcmap[i].red = ramp[0*256+c]; 1213 xcmap[i].red = ramp[0*256+c];
1211 xcmap[i].green = ramp[1*256+c]; 1214 xcmap[i].green = ramp[1*256+c];
1212 xcmap[i].blue = ramp[2*256+c]; 1215 xcmap[i].blue = ramp[2*256+c];
1213 xcmap[i].flags = (DoRed|DoGreen|DoBlue); 1216 xcmap[i].flags = (DoRed|DoGreen|DoBlue);
1214 } 1217 }
1215 XStoreColors(GFX_Display, SDL_XColorMap, xcmap, ncolors); 1218 pXStoreColors(GFX_Display, SDL_XColorMap, xcmap, ncolors);
1216 XSync(GFX_Display, False); 1219 pXSync(GFX_Display, False);
1217 return(0); 1220 return(0);
1218 } 1221 }
1219 1222
1220 /* Note: If we are terminated, this could be called in the middle of 1223 /* Note: If we are terminated, this could be called in the middle of
1221 another SDL video routine -- notably UpdateRects. 1224 another SDL video routine -- notably UpdateRects.
1224 { 1227 {
1225 /* Shutdown everything that's still up */ 1228 /* Shutdown everything that's still up */
1226 /* The event thread should be done, so we can touch SDL_Display */ 1229 /* The event thread should be done, so we can touch SDL_Display */
1227 if ( SDL_Display != NULL ) { 1230 if ( SDL_Display != NULL ) {
1228 /* Flush any delayed updates */ 1231 /* Flush any delayed updates */
1229 XSync(GFX_Display, False); 1232 pXSync(GFX_Display, False);
1230 1233
1231 /* Start shutting down the windows */ 1234 /* Start shutting down the windows */
1232 X11_DestroyImage(this, this->screen); 1235 X11_DestroyImage(this, this->screen);
1233 X11_DestroyWindow(this, this->screen); 1236 X11_DestroyWindow(this, this->screen);
1234 X11_FreeVideoModes(this); 1237 X11_FreeVideoModes(this);
1235 if ( SDL_XColorMap != SDL_DisplayColormap ) { 1238 if ( SDL_XColorMap != SDL_DisplayColormap ) {
1236 XFreeColormap(SDL_Display, SDL_XColorMap); 1239 pXFreeColormap(SDL_Display, SDL_XColorMap);
1237 } 1240 }
1238 if ( SDL_iconcolors ) { 1241 if ( SDL_iconcolors ) {
1239 unsigned long pixel; 1242 unsigned long pixel;
1240 Colormap dcmap = DefaultColormap(SDL_Display, 1243 Colormap dcmap = DefaultColormap(SDL_Display,
1241 SDL_Screen); 1244 SDL_Screen);
1242 for(pixel = 0; pixel < 256; ++pixel) { 1245 for(pixel = 0; pixel < 256; ++pixel) {
1243 while(SDL_iconcolors[pixel] > 0) { 1246 while(SDL_iconcolors[pixel] > 0) {
1244 XFreeColors(GFX_Display, 1247 pXFreeColors(GFX_Display,
1245 dcmap, &pixel, 1, 0); 1248 dcmap, &pixel, 1, 0);
1246 --SDL_iconcolors[pixel]; 1249 --SDL_iconcolors[pixel];
1247 } 1250 }
1248 } 1251 }
1249 free(SDL_iconcolors); 1252 free(SDL_iconcolors);
1260 SDL_BlankCursor = NULL; 1263 SDL_BlankCursor = NULL;
1261 } 1264 }
1262 1265
1263 /* Close the X11 graphics connection */ 1266 /* Close the X11 graphics connection */
1264 if ( GFX_Display != NULL ) { 1267 if ( GFX_Display != NULL ) {
1265 XCloseDisplay(GFX_Display); 1268 pXCloseDisplay(GFX_Display);
1266 GFX_Display = NULL; 1269 GFX_Display = NULL;
1267 } 1270 }
1268 1271
1269 /* Close the X11 display connection */ 1272 /* Close the X11 display connection */
1270 XCloseDisplay(SDL_Display); 1273 pXCloseDisplay(SDL_Display);
1271 SDL_Display = NULL; 1274 SDL_Display = NULL;
1272 1275
1273 /* Reset the X11 error handlers */ 1276 /* Reset the X11 error handlers */
1274 if ( XIO_handler ) { 1277 if ( XIO_handler ) {
1275 XSetIOErrorHandler(XIO_handler); 1278 pXSetIOErrorHandler(XIO_handler);
1276 } 1279 }
1277 if ( X_handler ) { 1280 if ( X_handler ) {
1278 XSetErrorHandler(X_handler); 1281 pXSetErrorHandler(X_handler);
1279 } 1282 }
1280 1283
1281 /* Unload GL library after X11 shuts down */ 1284 /* Unload GL library after X11 shuts down */
1282 X11_GL_UnloadLibrary(this); 1285 X11_GL_UnloadLibrary(this);
1283 } 1286 }