Mercurial > sdl-ios-xcode
comparison src/video/x11/SDL_x11video.c @ 1668:4da1ee79c9af SDL-1.3
more tweaking indent options
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 29 May 2006 04:04:35 +0000 |
parents | 782fd950bd46 |
children | 43ba677b4f62 |
comparison
equal
deleted
inserted
replaced
1667:1fddae038bc8 | 1668:4da1ee79c9af |
---|---|
53 #include "SDL_x11gl_c.h" | 53 #include "SDL_x11gl_c.h" |
54 #include "SDL_x11gamma_c.h" | 54 #include "SDL_x11gamma_c.h" |
55 #include "../blank_cursor.h" | 55 #include "../blank_cursor.h" |
56 | 56 |
57 /* Initialization/Query functions */ | 57 /* Initialization/Query functions */ |
58 static int X11_VideoInit (_THIS); | 58 static int X11_VideoInit(_THIS); |
59 static SDL_Surface *X11_SetVideoMode (_THIS, SDL_Surface * current, | 59 static SDL_Surface *X11_SetVideoMode(_THIS, SDL_Surface * current, |
60 const SDL_DisplayMode * mode, | 60 const SDL_DisplayMode * mode, |
61 Uint32 flags); | 61 Uint32 flags); |
62 static int X11_ToggleFullScreen (_THIS, int on); | 62 static int X11_ToggleFullScreen(_THIS, int on); |
63 static void X11_UpdateMouse (_THIS); | 63 static void X11_UpdateMouse(_THIS); |
64 static int X11_SetColors (_THIS, int firstcolor, int ncolors, | 64 static int X11_SetColors(_THIS, int firstcolor, int ncolors, |
65 SDL_Color * colors); | 65 SDL_Color * colors); |
66 static int X11_SetGammaRamp (_THIS, Uint16 * ramp); | 66 static int X11_SetGammaRamp(_THIS, Uint16 * ramp); |
67 static void X11_VideoQuit (_THIS); | 67 static void X11_VideoQuit(_THIS); |
68 | 68 |
69 | 69 |
70 /* X11 driver bootstrap functions */ | 70 /* X11 driver bootstrap functions */ |
71 | 71 |
72 static int | 72 static int |
73 X11_Available (void) | 73 X11_Available(void) |
74 { | 74 { |
75 Display *display = NULL; | 75 Display *display = NULL; |
76 if (SDL_X11_LoadSymbols ()) { | 76 if (SDL_X11_LoadSymbols()) { |
77 display = XOpenDisplay (NULL); | 77 display = XOpenDisplay(NULL); |
78 if (display != NULL) { | 78 if (display != NULL) { |
79 XCloseDisplay (display); | 79 XCloseDisplay(display); |
80 } | 80 } |
81 SDL_X11_UnloadSymbols (); | 81 SDL_X11_UnloadSymbols(); |
82 } | 82 } |
83 return (display != NULL); | 83 return (display != NULL); |
84 } | 84 } |
85 | 85 |
86 static void | 86 static void |
87 X11_DeleteDevice (SDL_VideoDevice * device) | 87 X11_DeleteDevice(SDL_VideoDevice * device) |
88 { | 88 { |
89 if (device) { | 89 if (device) { |
90 if (device->hidden) { | 90 if (device->hidden) { |
91 SDL_free (device->hidden); | 91 SDL_free(device->hidden); |
92 } | 92 } |
93 if (device->gl_data) { | 93 if (device->gl_data) { |
94 SDL_free (device->gl_data); | 94 SDL_free(device->gl_data); |
95 } | 95 } |
96 SDL_free (device); | 96 SDL_free(device); |
97 SDL_X11_UnloadSymbols (); | 97 SDL_X11_UnloadSymbols(); |
98 } | 98 } |
99 } | 99 } |
100 | 100 |
101 static SDL_VideoDevice * | 101 static SDL_VideoDevice * |
102 X11_CreateDevice (int devindex) | 102 X11_CreateDevice(int devindex) |
103 { | 103 { |
104 SDL_VideoDevice *device = NULL; | 104 SDL_VideoDevice *device = NULL; |
105 | 105 |
106 if (SDL_X11_LoadSymbols ()) { | 106 if (SDL_X11_LoadSymbols()) { |
107 /* Initialize all variables that we clean on shutdown */ | 107 /* Initialize all variables that we clean on shutdown */ |
108 device = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice)); | 108 device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice)); |
109 if (device) { | 109 if (device) { |
110 SDL_memset (device, 0, (sizeof *device)); | 110 SDL_memset(device, 0, (sizeof *device)); |
111 device->hidden = (struct SDL_PrivateVideoData *) | 111 device->hidden = (struct SDL_PrivateVideoData *) |
112 SDL_malloc ((sizeof *device->hidden)); | 112 SDL_malloc((sizeof *device->hidden)); |
113 device->gl_data = (struct SDL_PrivateGLData *) | 113 device->gl_data = (struct SDL_PrivateGLData *) |
114 SDL_malloc ((sizeof *device->gl_data)); | 114 SDL_malloc((sizeof *device->gl_data)); |
115 } | 115 } |
116 if ((device == NULL) || (device->hidden == NULL) || | 116 if ((device == NULL) || (device->hidden == NULL) || |
117 (device->gl_data == NULL)) { | 117 (device->gl_data == NULL)) { |
118 SDL_OutOfMemory (); | 118 SDL_OutOfMemory(); |
119 X11_DeleteDevice (device); /* calls SDL_X11_UnloadSymbols(). */ | 119 X11_DeleteDevice(device); /* calls SDL_X11_UnloadSymbols(). */ |
120 return (0); | 120 return (0); |
121 } | 121 } |
122 SDL_memset (device->hidden, 0, (sizeof *device->hidden)); | 122 SDL_memset(device->hidden, 0, (sizeof *device->hidden)); |
123 SDL_memset (device->gl_data, 0, (sizeof *device->gl_data)); | 123 SDL_memset(device->gl_data, 0, (sizeof *device->gl_data)); |
124 | 124 |
125 /* Set the driver flags */ | 125 /* Set the driver flags */ |
126 device->handles_any_size = 1; | 126 device->handles_any_size = 1; |
127 | 127 |
128 /* Set the function pointers */ | 128 /* Set the function pointers */ |
181 }; | 181 }; |
182 | 182 |
183 /* Normal X11 error handler routine */ | 183 /* Normal X11 error handler routine */ |
184 static int (*X_handler) (Display *, XErrorEvent *) = NULL; | 184 static int (*X_handler) (Display *, XErrorEvent *) = NULL; |
185 static int | 185 static int |
186 x_errhandler (Display * d, XErrorEvent * e) | 186 x_errhandler(Display * d, XErrorEvent * e) |
187 { | 187 { |
188 #if SDL_VIDEO_DRIVER_X11_VIDMODE | 188 #if SDL_VIDEO_DRIVER_X11_VIDMODE |
189 extern int vm_error; | 189 extern int vm_error; |
190 #endif | 190 #endif |
191 #if SDL_VIDEO_DRIVER_X11_DGAMOUSE | 191 #if SDL_VIDEO_DRIVER_X11_DGAMOUSE |
203 ((e->error_code > vm_error) && | 203 ((e->error_code > vm_error) && |
204 (e->error_code <= (vm_error + XF86VidModeNumberErrors))))) { | 204 (e->error_code <= (vm_error + XF86VidModeNumberErrors))))) { |
205 #ifdef X11_DEBUG | 205 #ifdef X11_DEBUG |
206 { | 206 { |
207 char errmsg[1024]; | 207 char errmsg[1024]; |
208 XGetErrorText (d, e->error_code, errmsg, sizeof (errmsg)); | 208 XGetErrorText(d, e->error_code, errmsg, sizeof(errmsg)); |
209 printf ("VidMode error: %s\n", errmsg); | 209 printf("VidMode error: %s\n", errmsg); |
210 } | 210 } |
211 #endif | 211 #endif |
212 return (0); | 212 return (0); |
213 } | 213 } |
214 #endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */ | 214 #endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */ |
219 ((e->error_code > dga_error) && | 219 ((e->error_code > dga_error) && |
220 (e->error_code <= (dga_error + XF86DGANumberErrors)))) { | 220 (e->error_code <= (dga_error + XF86DGANumberErrors)))) { |
221 #ifdef X11_DEBUG | 221 #ifdef X11_DEBUG |
222 { | 222 { |
223 char errmsg[1024]; | 223 char errmsg[1024]; |
224 XGetErrorText (d, e->error_code, errmsg, sizeof (errmsg)); | 224 XGetErrorText(d, e->error_code, errmsg, sizeof(errmsg)); |
225 printf ("DGA error: %s\n", errmsg); | 225 printf("DGA error: %s\n", errmsg); |
226 } | 226 } |
227 #endif | 227 #endif |
228 return (0); | 228 return (0); |
229 } | 229 } |
230 #endif /* SDL_VIDEO_DRIVER_X11_DGAMOUSE */ | 230 #endif /* SDL_VIDEO_DRIVER_X11_DGAMOUSE */ |
231 | 231 |
232 return (X_handler (d, e)); | 232 return (X_handler(d, e)); |
233 } | 233 } |
234 | 234 |
235 /* X11 I/O error handler routine */ | 235 /* X11 I/O error handler routine */ |
236 static int (*XIO_handler) (Display *) = NULL; | 236 static int (*XIO_handler) (Display *) = NULL; |
237 static int | 237 static int |
238 xio_errhandler (Display * d) | 238 xio_errhandler(Display * d) |
239 { | 239 { |
240 /* Ack! Lost X11 connection! */ | 240 /* Ack! Lost X11 connection! */ |
241 | 241 |
242 /* We will crash if we try to clean up our display */ | 242 /* We will crash if we try to clean up our display */ |
243 if (current_video->hidden->Ximage) { | 243 if (current_video->hidden->Ximage) { |
244 SDL_VideoSurface->pixels = NULL; | 244 SDL_VideoSurface->pixels = NULL; |
245 } | 245 } |
246 current_video->hidden->X11_Display = NULL; | 246 current_video->hidden->X11_Display = NULL; |
247 | 247 |
248 /* Continue with the standard X11 error handler */ | 248 /* Continue with the standard X11 error handler */ |
249 return (XIO_handler (d)); | 249 return (XIO_handler(d)); |
250 } | 250 } |
251 | 251 |
252 static int (*Xext_handler) (Display *, _Xconst char *, _Xconst char *) = NULL; | 252 static int (*Xext_handler) (Display *, _Xconst char *, _Xconst char *) = NULL; |
253 static int | 253 static int |
254 xext_errhandler (Display * d, _Xconst char *ext, _Xconst char *reason) | 254 xext_errhandler(Display * d, _Xconst char *ext, _Xconst char *reason) |
255 { | 255 { |
256 #ifdef X11_DEBUG | 256 #ifdef X11_DEBUG |
257 printf ("Xext error inside SDL (may be harmless):\n"); | 257 printf("Xext error inside SDL (may be harmless):\n"); |
258 printf (" Extension \"%s\" %s on display \"%s\".\n", | 258 printf(" Extension \"%s\" %s on display \"%s\".\n", |
259 ext, reason, XDisplayString (d)); | 259 ext, reason, XDisplayString(d)); |
260 #endif | 260 #endif |
261 | 261 |
262 if (SDL_strcmp (reason, "missing") == 0) { | 262 if (SDL_strcmp(reason, "missing") == 0) { |
263 /* | 263 /* |
264 * Since the query itself, elsewhere, can handle a missing extension | 264 * Since the query itself, elsewhere, can handle a missing extension |
265 * and the default behaviour in Xlib is to write to stderr, which | 265 * and the default behaviour in Xlib is to write to stderr, which |
266 * generates unnecessary bug reports, we just ignore these. | 266 * generates unnecessary bug reports, we just ignore these. |
267 */ | 267 */ |
268 return 0; | 268 return 0; |
269 } | 269 } |
270 | 270 |
271 /* Everything else goes to the default handler... */ | 271 /* Everything else goes to the default handler... */ |
272 return Xext_handler (d, ext, reason); | 272 return Xext_handler(d, ext, reason); |
273 } | 273 } |
274 | 274 |
275 /* Find out what class name we should use */ | 275 /* Find out what class name we should use */ |
276 static char * | 276 static char * |
277 get_classname (char *classname, int maxlen) | 277 get_classname(char *classname, int maxlen) |
278 { | 278 { |
279 char *spot; | 279 char *spot; |
280 #if defined(__LINUX__) || defined(__FREEBSD__) | 280 #if defined(__LINUX__) || defined(__FREEBSD__) |
281 char procfile[1024]; | 281 char procfile[1024]; |
282 char linkfile[1024]; | 282 char linkfile[1024]; |
283 int linksize; | 283 int linksize; |
284 #endif | 284 #endif |
285 | 285 |
286 /* First allow environment variable override */ | 286 /* First allow environment variable override */ |
287 spot = SDL_getenv ("SDL_VIDEO_X11_WMCLASS"); | 287 spot = SDL_getenv("SDL_VIDEO_X11_WMCLASS"); |
288 if (spot) { | 288 if (spot) { |
289 SDL_strlcpy (classname, spot, maxlen); | 289 SDL_strlcpy(classname, spot, maxlen); |
290 return classname; | 290 return classname; |
291 } | 291 } |
292 | 292 |
293 /* Next look at the application's executable name */ | 293 /* Next look at the application's executable name */ |
294 #if defined(__LINUX__) || defined(__FREEBSD__) | 294 #if defined(__LINUX__) || defined(__FREEBSD__) |
295 #if defined(__LINUX__) | 295 #if defined(__LINUX__) |
296 SDL_snprintf (procfile, SDL_arraysize (procfile), "/proc/%d/exe", | 296 SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/exe", getpid()); |
297 getpid ()); | |
298 #elif defined(__FREEBSD__) | 297 #elif defined(__FREEBSD__) |
299 SDL_snprintf (procfile, SDL_arraysize (procfile), "/proc/%d/file", | 298 SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/file", |
300 getpid ()); | 299 getpid()); |
301 #else | 300 #else |
302 #error Where can we find the executable name? | 301 #error Where can we find the executable name? |
303 #endif | 302 #endif |
304 linksize = readlink (procfile, linkfile, sizeof (linkfile) - 1); | 303 linksize = readlink(procfile, linkfile, sizeof(linkfile) - 1); |
305 if (linksize > 0) { | 304 if (linksize > 0) { |
306 linkfile[linksize] = '\0'; | 305 linkfile[linksize] = '\0'; |
307 spot = SDL_strrchr (linkfile, '/'); | 306 spot = SDL_strrchr(linkfile, '/'); |
308 if (spot) { | 307 if (spot) { |
309 SDL_strlcpy (classname, spot + 1, maxlen); | 308 SDL_strlcpy(classname, spot + 1, maxlen); |
310 } else { | 309 } else { |
311 SDL_strlcpy (classname, linkfile, maxlen); | 310 SDL_strlcpy(classname, linkfile, maxlen); |
312 } | 311 } |
313 return classname; | 312 return classname; |
314 } | 313 } |
315 #endif /* __LINUX__ */ | 314 #endif /* __LINUX__ */ |
316 | 315 |
317 /* Finally use the default we've used forever */ | 316 /* Finally use the default we've used forever */ |
318 SDL_strlcpy (classname, "SDL_App", maxlen); | 317 SDL_strlcpy(classname, "SDL_App", maxlen); |
319 return classname; | 318 return classname; |
320 } | 319 } |
321 | 320 |
322 /* Create auxiliary (toplevel) windows with the current visual */ | 321 /* Create auxiliary (toplevel) windows with the current visual */ |
323 static void | 322 static void |
324 create_aux_windows (_THIS) | 323 create_aux_windows(_THIS) |
325 { | 324 { |
326 int x = 0, y = 0; | 325 int x = 0, y = 0; |
327 char classname[1024]; | 326 char classname[1024]; |
328 XSetWindowAttributes xattr; | 327 XSetWindowAttributes xattr; |
329 XWMHints *hints; | 328 XWMHints *hints; |
330 int def_vis = (SDL_Visual == DefaultVisual (SDL_Display, SDL_Screen)); | 329 int def_vis = (SDL_Visual == DefaultVisual(SDL_Display, SDL_Screen)); |
331 | 330 |
332 /* Look up some useful Atoms */ | 331 /* Look up some useful Atoms */ |
333 WM_DELETE_WINDOW = XInternAtom (SDL_Display, "WM_DELETE_WINDOW", False); | 332 WM_DELETE_WINDOW = XInternAtom(SDL_Display, "WM_DELETE_WINDOW", False); |
334 | 333 |
335 /* Don't create any extra windows if we are being managed */ | 334 /* Don't create any extra windows if we are being managed */ |
336 if (SDL_windowid) { | 335 if (SDL_windowid) { |
337 FSwindow = 0; | 336 FSwindow = 0; |
338 WMwindow = SDL_strtol (SDL_windowid, NULL, 0); | 337 WMwindow = SDL_strtol(SDL_windowid, NULL, 0); |
339 return; | 338 return; |
340 } | 339 } |
341 | 340 |
342 if (FSwindow) | 341 if (FSwindow) |
343 XDestroyWindow (SDL_Display, FSwindow); | 342 XDestroyWindow(SDL_Display, FSwindow); |
344 | 343 |
345 #if SDL_VIDEO_DRIVER_X11_VIDMODE | 344 #if SDL_VIDEO_DRIVER_X11_VIDMODE |
346 if (use_xinerama) { | 345 if (use_xinerama) { |
347 x = xinerama[this->current_display].x_org; | 346 x = xinerama[this->current_display].x_org; |
348 y = xinerama[this->current_display].y_org; | 347 y = xinerama[this->current_display].y_org; |
349 } | 348 } |
350 #endif | 349 #endif |
351 xattr.override_redirect = True; | 350 xattr.override_redirect = True; |
352 xattr.background_pixel = | 351 xattr.background_pixel = |
353 def_vis ? BlackPixel (SDL_Display, SDL_Screen) : 0; | 352 def_vis ? BlackPixel(SDL_Display, SDL_Screen) : 0; |
354 xattr.border_pixel = 0; | 353 xattr.border_pixel = 0; |
355 xattr.colormap = SDL_XColorMap; | 354 xattr.colormap = SDL_XColorMap; |
356 | 355 |
357 FSwindow = XCreateWindow (SDL_Display, SDL_Root, | 356 FSwindow = XCreateWindow(SDL_Display, SDL_Root, |
358 x, y, 32, 32, 0, | 357 x, y, 32, 32, 0, |
359 this->hidden->depth, InputOutput, SDL_Visual, | 358 this->hidden->depth, InputOutput, SDL_Visual, |
360 CWOverrideRedirect | CWBackPixel | CWBorderPixel | 359 CWOverrideRedirect | CWBackPixel | CWBorderPixel |
361 | CWColormap, &xattr); | 360 | CWColormap, &xattr); |
362 | 361 |
363 XSelectInput (SDL_Display, FSwindow, StructureNotifyMask); | 362 XSelectInput(SDL_Display, FSwindow, StructureNotifyMask); |
364 | 363 |
365 /* Tell KDE to keep the fullscreen window on top */ | 364 /* Tell KDE to keep the fullscreen window on top */ |
366 { | 365 { |
367 XEvent ev; | 366 XEvent ev; |
368 long mask; | 367 long mask; |
369 | 368 |
370 SDL_memset (&ev, 0, sizeof (ev)); | 369 SDL_memset(&ev, 0, sizeof(ev)); |
371 ev.xclient.type = ClientMessage; | 370 ev.xclient.type = ClientMessage; |
372 ev.xclient.window = SDL_Root; | 371 ev.xclient.window = SDL_Root; |
373 ev.xclient.message_type = XInternAtom (SDL_Display, | 372 ev.xclient.message_type = XInternAtom(SDL_Display, |
374 "KWM_KEEP_ON_TOP", False); | 373 "KWM_KEEP_ON_TOP", False); |
375 ev.xclient.format = 32; | 374 ev.xclient.format = 32; |
376 ev.xclient.data.l[0] = FSwindow; | 375 ev.xclient.data.l[0] = FSwindow; |
377 ev.xclient.data.l[1] = CurrentTime; | 376 ev.xclient.data.l[1] = CurrentTime; |
378 mask = SubstructureRedirectMask; | 377 mask = SubstructureRedirectMask; |
379 XSendEvent (SDL_Display, SDL_Root, False, mask, &ev); | 378 XSendEvent(SDL_Display, SDL_Root, False, mask, &ev); |
380 } | 379 } |
381 | 380 |
382 hints = NULL; | 381 hints = NULL; |
383 if (WMwindow) { | 382 if (WMwindow) { |
384 /* All window attributes must survive the recreation */ | 383 /* All window attributes must survive the recreation */ |
385 hints = XGetWMHints (SDL_Display, WMwindow); | 384 hints = XGetWMHints(SDL_Display, WMwindow); |
386 XDestroyWindow (SDL_Display, WMwindow); | 385 XDestroyWindow(SDL_Display, WMwindow); |
387 } | 386 } |
388 | 387 |
389 /* Create the window for windowed management */ | 388 /* Create the window for windowed management */ |
390 /* (reusing the xattr structure above) */ | 389 /* (reusing the xattr structure above) */ |
391 WMwindow = XCreateWindow (SDL_Display, SDL_Root, | 390 WMwindow = XCreateWindow(SDL_Display, SDL_Root, |
392 x, y, 32, 32, 0, | 391 x, y, 32, 32, 0, |
393 this->hidden->depth, InputOutput, SDL_Visual, | 392 this->hidden->depth, InputOutput, SDL_Visual, |
394 CWBackPixel | CWBorderPixel | CWColormap, | 393 CWBackPixel | CWBorderPixel | CWColormap, |
395 &xattr); | 394 &xattr); |
396 | 395 |
397 /* Set the input hints so we get keyboard input */ | 396 /* Set the input hints so we get keyboard input */ |
398 if (!hints) { | 397 if (!hints) { |
399 hints = XAllocWMHints (); | 398 hints = XAllocWMHints(); |
400 hints->input = True; | 399 hints->input = True; |
401 hints->flags = InputHint; | 400 hints->flags = InputHint; |
402 } | 401 } |
403 XSetWMHints (SDL_Display, WMwindow, hints); | 402 XSetWMHints(SDL_Display, WMwindow, hints); |
404 XFree (hints); | 403 XFree(hints); |
405 X11_SetCaptionNoLock (this, SDL_CurrentWindow.wm_title, | 404 X11_SetCaptionNoLock(this, SDL_CurrentWindow.wm_title, |
406 SDL_CurrentWindow.wm_icon); | 405 SDL_CurrentWindow.wm_icon); |
407 | 406 |
408 XSelectInput (SDL_Display, WMwindow, | 407 XSelectInput(SDL_Display, WMwindow, |
409 FocusChangeMask | KeyPressMask | KeyReleaseMask | 408 FocusChangeMask | KeyPressMask | KeyReleaseMask |
410 | PropertyChangeMask | StructureNotifyMask | | 409 | PropertyChangeMask | StructureNotifyMask | |
411 KeymapStateMask); | 410 KeymapStateMask); |
412 | 411 |
413 /* Set the class hints so we can get an icon (AfterStep) */ | 412 /* Set the class hints so we can get an icon (AfterStep) */ |
414 get_classname (classname, sizeof (classname)); | 413 get_classname(classname, sizeof(classname)); |
415 { | 414 { |
416 XClassHint *classhints; | 415 XClassHint *classhints; |
417 classhints = XAllocClassHint (); | 416 classhints = XAllocClassHint(); |
418 if (classhints != NULL) { | 417 if (classhints != NULL) { |
419 classhints->res_name = classname; | 418 classhints->res_name = classname; |
420 classhints->res_class = classname; | 419 classhints->res_class = classname; |
421 XSetClassHint (SDL_Display, WMwindow, classhints); | 420 XSetClassHint(SDL_Display, WMwindow, classhints); |
422 XFree (classhints); | 421 XFree(classhints); |
423 } | 422 } |
424 } | 423 } |
425 | 424 |
426 /* Setup the communication with the IM server */ | 425 /* Setup the communication with the IM server */ |
427 SDL_IM = NULL; | 426 SDL_IM = NULL; |
428 SDL_IC = NULL; | 427 SDL_IC = NULL; |
429 | 428 |
430 #ifdef X_HAVE_UTF8_STRING | 429 #ifdef X_HAVE_UTF8_STRING |
431 if (SDL_X11_HAVE_UTF8) { | 430 if (SDL_X11_HAVE_UTF8) { |
432 SDL_IM = XOpenIM (SDL_Display, NULL, classname, classname); | 431 SDL_IM = XOpenIM(SDL_Display, NULL, classname, classname); |
433 if (SDL_IM == NULL) { | 432 if (SDL_IM == NULL) { |
434 SDL_SetError ("no input method could be opened"); | 433 SDL_SetError("no input method could be opened"); |
435 } else { | 434 } else { |
436 SDL_IC = pXCreateIC (SDL_IM, | 435 SDL_IC = pXCreateIC(SDL_IM, |
437 XNClientWindow, WMwindow, | 436 XNClientWindow, WMwindow, |
438 XNFocusWindow, WMwindow, | 437 XNFocusWindow, WMwindow, |
439 XNInputStyle, | 438 XNInputStyle, |
440 XIMPreeditNothing | XIMStatusNothing, | 439 XIMPreeditNothing | XIMStatusNothing, |
441 XNResourceName, classname, | 440 XNResourceName, classname, |
442 XNResourceClass, classname, NULL); | 441 XNResourceClass, classname, NULL); |
443 | 442 |
444 if (SDL_IC == NULL) { | 443 if (SDL_IC == NULL) { |
445 SDL_SetError ("no input context could be created"); | 444 SDL_SetError("no input context could be created"); |
446 XCloseIM (SDL_IM); | 445 XCloseIM(SDL_IM); |
447 SDL_IM = NULL; | 446 SDL_IM = NULL; |
448 } | 447 } |
449 } | 448 } |
450 } | 449 } |
451 #endif | 450 #endif |
452 | 451 |
453 /* Allow the window to be deleted by the window manager */ | 452 /* Allow the window to be deleted by the window manager */ |
454 XSetWMProtocols (SDL_Display, WMwindow, &WM_DELETE_WINDOW, 1); | 453 XSetWMProtocols(SDL_Display, WMwindow, &WM_DELETE_WINDOW, 1); |
455 } | 454 } |
456 | 455 |
457 static int | 456 static int |
458 X11_VideoInit (_THIS) | 457 X11_VideoInit(_THIS) |
459 { | 458 { |
460 char *display; | 459 char *display; |
461 int i; | 460 int i; |
462 SDL_DisplayMode desktop_mode; | 461 SDL_DisplayMode desktop_mode; |
463 | 462 |
464 /* Open the X11 display */ | 463 /* Open the X11 display */ |
465 display = NULL; /* Get it from DISPLAY environment variable */ | 464 display = NULL; /* Get it from DISPLAY environment variable */ |
466 | 465 |
467 if ((SDL_strncmp (XDisplayName (display), ":", 1) == 0) || | 466 if ((SDL_strncmp(XDisplayName(display), ":", 1) == 0) || |
468 (SDL_strncmp (XDisplayName (display), "unix:", 5) == 0)) { | 467 (SDL_strncmp(XDisplayName(display), "unix:", 5) == 0)) { |
469 local_X11 = 1; | 468 local_X11 = 1; |
470 } else { | 469 } else { |
471 local_X11 = 0; | 470 local_X11 = 0; |
472 } | 471 } |
473 SDL_Display = XOpenDisplay (display); | 472 SDL_Display = XOpenDisplay(display); |
474 #if defined(__osf__) && defined(SDL_VIDEO_DRIVER_X11_DYNAMIC) | 473 #if defined(__osf__) && defined(SDL_VIDEO_DRIVER_X11_DYNAMIC) |
475 /* On Tru64 if linking without -lX11, it fails and you get following message. | 474 /* On Tru64 if linking without -lX11, it fails and you get following message. |
476 * Xlib: connection to ":0.0" refused by server | 475 * Xlib: connection to ":0.0" refused by server |
477 * Xlib: XDM authorization key matches an existing client! | 476 * Xlib: XDM authorization key matches an existing client! |
478 * | 477 * |
479 * It succeeds if retrying 1 second later | 478 * It succeeds if retrying 1 second later |
480 * or if running xhost +localhost on shell. | 479 * or if running xhost +localhost on shell. |
481 * | 480 * |
482 */ | 481 */ |
483 if (SDL_Display == NULL) { | 482 if (SDL_Display == NULL) { |
484 SDL_Delay (1000); | 483 SDL_Delay(1000); |
485 SDL_Display = XOpenDisplay (display); | 484 SDL_Display = XOpenDisplay(display); |
486 } | 485 } |
487 #endif | 486 #endif |
488 if (SDL_Display == NULL) { | 487 if (SDL_Display == NULL) { |
489 SDL_SetError ("Couldn't open X11 display"); | 488 SDL_SetError("Couldn't open X11 display"); |
490 return (-1); | 489 return (-1); |
491 } | 490 } |
492 #ifdef X11_DEBUG | 491 #ifdef X11_DEBUG |
493 XSynchronize (SDL_Display, True); | 492 XSynchronize(SDL_Display, True); |
494 #endif | 493 #endif |
495 | 494 |
496 /* Create an alternate X display for graphics updates -- allows us | 495 /* Create an alternate X display for graphics updates -- allows us |
497 to do graphics updates in a separate thread from event handling. | 496 to do graphics updates in a separate thread from event handling. |
498 Thread-safe X11 doesn't seem to exist. | 497 Thread-safe X11 doesn't seem to exist. |
499 */ | 498 */ |
500 GFX_Display = XOpenDisplay (display); | 499 GFX_Display = XOpenDisplay(display); |
501 if (GFX_Display == NULL) { | 500 if (GFX_Display == NULL) { |
502 SDL_SetError ("Couldn't open X11 display"); | 501 SDL_SetError("Couldn't open X11 display"); |
503 return (-1); | 502 return (-1); |
504 } | 503 } |
505 | 504 |
506 /* Set the normal X error handler */ | 505 /* Set the normal X error handler */ |
507 X_handler = XSetErrorHandler (x_errhandler); | 506 X_handler = XSetErrorHandler(x_errhandler); |
508 | 507 |
509 /* Set the error handler if we lose the X display */ | 508 /* Set the error handler if we lose the X display */ |
510 XIO_handler = XSetIOErrorHandler (xio_errhandler); | 509 XIO_handler = XSetIOErrorHandler(xio_errhandler); |
511 | 510 |
512 /* Set the X extension error handler */ | 511 /* Set the X extension error handler */ |
513 Xext_handler = XSetExtensionErrorHandler (xext_errhandler); | 512 Xext_handler = XSetExtensionErrorHandler(xext_errhandler); |
514 | 513 |
515 /* use default screen (from $DISPLAY) */ | 514 /* use default screen (from $DISPLAY) */ |
516 SDL_Screen = DefaultScreen (SDL_Display); | 515 SDL_Screen = DefaultScreen(SDL_Display); |
517 | 516 |
518 #ifndef NO_SHARED_MEMORY | 517 #ifndef NO_SHARED_MEMORY |
519 /* Check for MIT shared memory extension */ | 518 /* Check for MIT shared memory extension */ |
520 use_mitshm = 0; | 519 use_mitshm = 0; |
521 if (local_X11) { | 520 if (local_X11) { |
522 use_mitshm = XShmQueryExtension (SDL_Display); | 521 use_mitshm = XShmQueryExtension(SDL_Display); |
523 } | 522 } |
524 #endif /* NO_SHARED_MEMORY */ | 523 #endif /* NO_SHARED_MEMORY */ |
525 | 524 |
526 /* Get the available visuals */ | 525 /* Get the available visuals */ |
527 if (X11_GetVisuals (this) < 0) | 526 if (X11_GetVisuals(this) < 0) |
528 return -1; | 527 return -1; |
529 | 528 |
530 /* Determine the default screen mode: | 529 /* Determine the default screen mode: |
531 Use the default visual (or at least one with the same depth) */ | 530 Use the default visual (or at least one with the same depth) */ |
532 SDL_DisplayColormap = DefaultColormap (SDL_Display, SDL_Screen); | 531 SDL_DisplayColormap = DefaultColormap(SDL_Display, SDL_Screen); |
533 for (i = 0; i < this->hidden->nvisuals; i++) | 532 for (i = 0; i < this->hidden->nvisuals; i++) |
534 if (this->hidden->visuals[i].depth == DefaultDepth (SDL_Display, | 533 if (this->hidden->visuals[i].depth == DefaultDepth(SDL_Display, |
535 SDL_Screen)) | 534 SDL_Screen)) |
536 break; | 535 break; |
537 if (i == this->hidden->nvisuals) { | 536 if (i == this->hidden->nvisuals) { |
538 /* default visual was useless, take the deepest one instead */ | 537 /* default visual was useless, take the deepest one instead */ |
539 i = 0; | 538 i = 0; |
540 } | 539 } |
541 SDL_Visual = this->hidden->visuals[i].visual; | 540 SDL_Visual = this->hidden->visuals[i].visual; |
542 if (SDL_Visual == DefaultVisual (SDL_Display, SDL_Screen)) { | 541 if (SDL_Visual == DefaultVisual(SDL_Display, SDL_Screen)) { |
543 SDL_XColorMap = SDL_DisplayColormap; | 542 SDL_XColorMap = SDL_DisplayColormap; |
544 } else { | 543 } else { |
545 SDL_XColorMap = XCreateColormap (SDL_Display, SDL_Root, | 544 SDL_XColorMap = XCreateColormap(SDL_Display, SDL_Root, |
546 SDL_Visual, AllocNone); | 545 SDL_Visual, AllocNone); |
547 } | 546 } |
548 desktop_mode.format = | 547 desktop_mode.format = |
549 X11_VisualToFormat (this->hidden->visuals[i].visual, | 548 X11_VisualToFormat(this->hidden->visuals[i].visual, |
550 this->hidden->visuals[i].depth, | 549 this->hidden->visuals[i].depth, |
551 this->hidden->visuals[i].bpp); | 550 this->hidden->visuals[i].bpp); |
552 desktop_mode.w = DisplayWidth (SDL_Display, SDL_Screen); | 551 desktop_mode.w = DisplayWidth(SDL_Display, SDL_Screen); |
553 desktop_mode.h = DisplayHeight (SDL_Display, SDL_Screen); | 552 desktop_mode.h = DisplayHeight(SDL_Display, SDL_Screen); |
554 desktop_mode.refresh_rate = 0; | 553 desktop_mode.refresh_rate = 0; |
555 SDL_AddVideoDisplay (&desktop_mode); | 554 SDL_AddVideoDisplay(&desktop_mode); |
556 | 555 |
557 /* Get the available video modes */ | 556 /* Get the available video modes */ |
558 if (X11_GetVideoModes (this) < 0) | 557 if (X11_GetVideoModes(this) < 0) |
559 return -1; | 558 return -1; |
560 | 559 |
561 X11_SaveVidModeGamma (this); | 560 X11_SaveVidModeGamma(this); |
562 | 561 |
563 /* Save DPMS and screensaver settings */ | 562 /* Save DPMS and screensaver settings */ |
564 X11_SaveScreenSaver (SDL_Display, &screensaver_timeout, &dpms_enabled); | 563 X11_SaveScreenSaver(SDL_Display, &screensaver_timeout, &dpms_enabled); |
565 X11_DisableScreenSaver (SDL_Display); | 564 X11_DisableScreenSaver(SDL_Display); |
566 | 565 |
567 /* See if we have been passed a window to use */ | 566 /* See if we have been passed a window to use */ |
568 SDL_windowid = SDL_getenv ("SDL_WINDOWID"); | 567 SDL_windowid = SDL_getenv("SDL_WINDOWID"); |
569 | 568 |
570 /* Create the fullscreen and managed windows */ | 569 /* Create the fullscreen and managed windows */ |
571 create_aux_windows (this); | 570 create_aux_windows(this); |
572 | 571 |
573 /* Create the blank cursor */ | 572 /* Create the blank cursor */ |
574 SDL_BlankCursor = this->CreateWMCursor (this, blank_cdata, blank_cmask, | 573 SDL_BlankCursor = this->CreateWMCursor(this, blank_cdata, blank_cmask, |
575 BLANK_CWIDTH, BLANK_CHEIGHT, | 574 BLANK_CWIDTH, BLANK_CHEIGHT, |
576 BLANK_CHOTX, BLANK_CHOTY); | 575 BLANK_CHOTX, BLANK_CHOTY); |
577 | 576 |
578 /* Fill in some window manager capabilities */ | 577 /* Fill in some window manager capabilities */ |
579 this->info.wm_available = 1; | 578 this->info.wm_available = 1; |
580 | 579 |
581 /* We're done! */ | 580 /* We're done! */ |
582 XFlush (SDL_Display); | 581 XFlush(SDL_Display); |
583 return (0); | 582 return (0); |
584 } | 583 } |
585 | 584 |
586 static void | 585 static void |
587 X11_DestroyWindow (_THIS, SDL_Surface * screen) | 586 X11_DestroyWindow(_THIS, SDL_Surface * screen) |
588 { | 587 { |
589 /* Clean up OpenGL */ | 588 /* Clean up OpenGL */ |
590 if (screen) { | 589 if (screen) { |
591 screen->flags &= ~SDL_INTERNALOPENGL; | 590 screen->flags &= ~SDL_INTERNALOPENGL; |
592 } | 591 } |
593 X11_GL_Shutdown (this); | 592 X11_GL_Shutdown(this); |
594 | 593 |
595 if (!SDL_windowid) { | 594 if (!SDL_windowid) { |
596 /* Hide the managed window */ | 595 /* Hide the managed window */ |
597 if (WMwindow) { | 596 if (WMwindow) { |
598 XUnmapWindow (SDL_Display, WMwindow); | 597 XUnmapWindow(SDL_Display, WMwindow); |
599 } | 598 } |
600 if (screen && (screen->flags & SDL_FULLSCREEN)) { | 599 if (screen && (screen->flags & SDL_FULLSCREEN)) { |
601 screen->flags &= ~SDL_FULLSCREEN; | 600 screen->flags &= ~SDL_FULLSCREEN; |
602 X11_LeaveFullScreen (this); | 601 X11_LeaveFullScreen(this); |
603 } | 602 } |
604 | 603 |
605 /* Destroy the output window */ | 604 /* Destroy the output window */ |
606 if (SDL_Window) { | 605 if (SDL_Window) { |
607 XDestroyWindow (SDL_Display, SDL_Window); | 606 XDestroyWindow(SDL_Display, SDL_Window); |
608 } | 607 } |
609 | 608 |
610 /* Free the colormap entries */ | 609 /* Free the colormap entries */ |
611 if (SDL_XPixels) { | 610 if (SDL_XPixels) { |
612 int numcolors; | 611 int numcolors; |
613 unsigned long pixel; | 612 unsigned long pixel; |
614 numcolors = SDL_Visual->map_entries; | 613 numcolors = SDL_Visual->map_entries; |
615 for (pixel = 0; pixel < numcolors; ++pixel) { | 614 for (pixel = 0; pixel < numcolors; ++pixel) { |
616 while (SDL_XPixels[pixel] > 0) { | 615 while (SDL_XPixels[pixel] > 0) { |
617 XFreeColors (GFX_Display, | 616 XFreeColors(GFX_Display, |
618 SDL_DisplayColormap, &pixel, 1, 0); | 617 SDL_DisplayColormap, &pixel, 1, 0); |
619 --SDL_XPixels[pixel]; | 618 --SDL_XPixels[pixel]; |
620 } | 619 } |
621 } | 620 } |
622 SDL_free (SDL_XPixels); | 621 SDL_free(SDL_XPixels); |
623 SDL_XPixels = NULL; | 622 SDL_XPixels = NULL; |
624 } | 623 } |
625 | 624 |
626 /* Free the graphics context */ | 625 /* Free the graphics context */ |
627 if (SDL_GC) { | 626 if (SDL_GC) { |
628 XFreeGC (SDL_Display, SDL_GC); | 627 XFreeGC(SDL_Display, SDL_GC); |
629 SDL_GC = 0; | 628 SDL_GC = 0; |
630 } | 629 } |
631 } | 630 } |
632 } | 631 } |
633 | 632 |
634 static SDL_bool | 633 static SDL_bool |
635 X11_WindowPosition (_THIS, int *x, int *y, int w, int h) | 634 X11_WindowPosition(_THIS, int *x, int *y, int w, int h) |
636 { | 635 { |
637 const char *window = SDL_getenv ("SDL_VIDEO_WINDOW_POS"); | 636 const char *window = SDL_getenv("SDL_VIDEO_WINDOW_POS"); |
638 const char *center = SDL_getenv ("SDL_VIDEO_CENTERED"); | 637 const char *center = SDL_getenv("SDL_VIDEO_CENTERED"); |
639 if (window) { | 638 if (window) { |
640 if (SDL_sscanf (window, "%d,%d", x, y) == 2) { | 639 if (SDL_sscanf(window, "%d,%d", x, y) == 2) { |
641 return SDL_TRUE; | 640 return SDL_TRUE; |
642 } | 641 } |
643 if (SDL_strcmp (window, "center") == 0) { | 642 if (SDL_strcmp(window, "center") == 0) { |
644 center = window; | 643 center = window; |
645 } | 644 } |
646 } | 645 } |
647 if (center) { | 646 if (center) { |
648 *x = (DisplayWidth (SDL_Display, SDL_Screen) - w) / 2; | 647 *x = (DisplayWidth(SDL_Display, SDL_Screen) - w) / 2; |
649 *y = (DisplayHeight (SDL_Display, SDL_Screen) - h) / 2; | 648 *y = (DisplayHeight(SDL_Display, SDL_Screen) - h) / 2; |
650 return SDL_TRUE; | 649 return SDL_TRUE; |
651 } | 650 } |
652 return SDL_FALSE; | 651 return SDL_FALSE; |
653 } | 652 } |
654 | 653 |
655 static void | 654 static void |
656 X11_SetSizeHints (_THIS, int w, int h, Uint32 flags) | 655 X11_SetSizeHints(_THIS, int w, int h, Uint32 flags) |
657 { | 656 { |
658 XSizeHints *hints; | 657 XSizeHints *hints; |
659 | 658 |
660 hints = XAllocSizeHints (); | 659 hints = XAllocSizeHints(); |
661 if (hints) { | 660 if (hints) { |
662 if (flags & SDL_RESIZABLE) { | 661 if (flags & SDL_RESIZABLE) { |
663 hints->min_width = 32; | 662 hints->min_width = 32; |
664 hints->min_height = 32; | 663 hints->min_height = 32; |
665 hints->max_height = 4096; | 664 hints->max_height = 4096; |
673 hints->x = 0; | 672 hints->x = 0; |
674 hints->y = 0; | 673 hints->y = 0; |
675 hints->flags |= USPosition; | 674 hints->flags |= USPosition; |
676 } else | 675 } else |
677 /* Center it, if desired */ | 676 /* Center it, if desired */ |
678 if (X11_WindowPosition (this, &hints->x, &hints->y, w, h)) { | 677 if (X11_WindowPosition(this, &hints->x, &hints->y, w, h)) { |
679 hints->flags |= USPosition; | 678 hints->flags |= USPosition; |
680 XMoveWindow (SDL_Display, WMwindow, hints->x, hints->y); | 679 XMoveWindow(SDL_Display, WMwindow, hints->x, hints->y); |
681 | 680 |
682 /* Flush the resize event so we don't catch it later */ | 681 /* Flush the resize event so we don't catch it later */ |
683 XSync (SDL_Display, True); | 682 XSync(SDL_Display, True); |
684 } | 683 } |
685 XSetWMNormalHints (SDL_Display, WMwindow, hints); | 684 XSetWMNormalHints(SDL_Display, WMwindow, hints); |
686 XFree (hints); | 685 XFree(hints); |
687 } | 686 } |
688 | 687 |
689 /* Respect the window caption style */ | 688 /* Respect the window caption style */ |
690 if (flags & SDL_NOFRAME) { | 689 if (flags & SDL_NOFRAME) { |
691 SDL_bool set; | 690 SDL_bool set; |
693 | 692 |
694 /* We haven't modified the window manager hints yet */ | 693 /* We haven't modified the window manager hints yet */ |
695 set = SDL_FALSE; | 694 set = SDL_FALSE; |
696 | 695 |
697 /* First try to set MWM hints */ | 696 /* First try to set MWM hints */ |
698 WM_HINTS = XInternAtom (SDL_Display, "_MOTIF_WM_HINTS", True); | 697 WM_HINTS = XInternAtom(SDL_Display, "_MOTIF_WM_HINTS", True); |
699 if (WM_HINTS != None) { | 698 if (WM_HINTS != None) { |
700 /* Hints used by Motif compliant window managers */ | 699 /* Hints used by Motif compliant window managers */ |
701 struct | 700 struct |
702 { | 701 { |
703 unsigned long flags; | 702 unsigned long flags; |
706 long input_mode; | 705 long input_mode; |
707 unsigned long status; | 706 unsigned long status; |
708 } MWMHints = { | 707 } MWMHints = { |
709 (1L << 1), 0, 0, 0, 0}; | 708 (1L << 1), 0, 0, 0, 0}; |
710 | 709 |
711 XChangeProperty (SDL_Display, WMwindow, | 710 XChangeProperty(SDL_Display, WMwindow, |
712 WM_HINTS, WM_HINTS, 32, | 711 WM_HINTS, WM_HINTS, 32, |
713 PropModeReplace, | 712 PropModeReplace, |
714 (unsigned char *) &MWMHints, | 713 (unsigned char *) &MWMHints, |
715 sizeof (MWMHints) / sizeof (long)); | 714 sizeof(MWMHints) / sizeof(long)); |
716 set = SDL_TRUE; | 715 set = SDL_TRUE; |
717 } | 716 } |
718 /* Now try to set KWM hints */ | 717 /* Now try to set KWM hints */ |
719 WM_HINTS = XInternAtom (SDL_Display, "KWM_WIN_DECORATION", True); | 718 WM_HINTS = XInternAtom(SDL_Display, "KWM_WIN_DECORATION", True); |
720 if (WM_HINTS != None) { | 719 if (WM_HINTS != None) { |
721 long KWMHints = 0; | 720 long KWMHints = 0; |
722 | 721 |
723 XChangeProperty (SDL_Display, WMwindow, | 722 XChangeProperty(SDL_Display, WMwindow, |
724 WM_HINTS, WM_HINTS, 32, | 723 WM_HINTS, WM_HINTS, 32, |
725 PropModeReplace, | 724 PropModeReplace, |
726 (unsigned char *) &KWMHints, | 725 (unsigned char *) &KWMHints, |
727 sizeof (KWMHints) / sizeof (long)); | 726 sizeof(KWMHints) / sizeof(long)); |
728 set = SDL_TRUE; | 727 set = SDL_TRUE; |
729 } | 728 } |
730 /* Now try to set GNOME hints */ | 729 /* Now try to set GNOME hints */ |
731 WM_HINTS = XInternAtom (SDL_Display, "_WIN_HINTS", True); | 730 WM_HINTS = XInternAtom(SDL_Display, "_WIN_HINTS", True); |
732 if (WM_HINTS != None) { | 731 if (WM_HINTS != None) { |
733 long GNOMEHints = 0; | 732 long GNOMEHints = 0; |
734 | 733 |
735 XChangeProperty (SDL_Display, WMwindow, | 734 XChangeProperty(SDL_Display, WMwindow, |
736 WM_HINTS, WM_HINTS, 32, | 735 WM_HINTS, WM_HINTS, 32, |
737 PropModeReplace, | 736 PropModeReplace, |
738 (unsigned char *) &GNOMEHints, | 737 (unsigned char *) &GNOMEHints, |
739 sizeof (GNOMEHints) / sizeof (long)); | 738 sizeof(GNOMEHints) / sizeof(long)); |
740 set = SDL_TRUE; | 739 set = SDL_TRUE; |
741 } | 740 } |
742 /* Finally set the transient hints if necessary */ | 741 /* Finally set the transient hints if necessary */ |
743 if (!set) { | 742 if (!set) { |
744 XSetTransientForHint (SDL_Display, WMwindow, SDL_Root); | 743 XSetTransientForHint(SDL_Display, WMwindow, SDL_Root); |
745 } | 744 } |
746 } else { | 745 } else { |
747 SDL_bool set; | 746 SDL_bool set; |
748 Atom WM_HINTS; | 747 Atom WM_HINTS; |
749 | 748 |
750 /* We haven't modified the window manager hints yet */ | 749 /* We haven't modified the window manager hints yet */ |
751 set = SDL_FALSE; | 750 set = SDL_FALSE; |
752 | 751 |
753 /* First try to unset MWM hints */ | 752 /* First try to unset MWM hints */ |
754 WM_HINTS = XInternAtom (SDL_Display, "_MOTIF_WM_HINTS", True); | 753 WM_HINTS = XInternAtom(SDL_Display, "_MOTIF_WM_HINTS", True); |
755 if (WM_HINTS != None) { | 754 if (WM_HINTS != None) { |
756 XDeleteProperty (SDL_Display, WMwindow, WM_HINTS); | 755 XDeleteProperty(SDL_Display, WMwindow, WM_HINTS); |
757 set = SDL_TRUE; | 756 set = SDL_TRUE; |
758 } | 757 } |
759 /* Now try to unset KWM hints */ | 758 /* Now try to unset KWM hints */ |
760 WM_HINTS = XInternAtom (SDL_Display, "KWM_WIN_DECORATION", True); | 759 WM_HINTS = XInternAtom(SDL_Display, "KWM_WIN_DECORATION", True); |
761 if (WM_HINTS != None) { | 760 if (WM_HINTS != None) { |
762 XDeleteProperty (SDL_Display, WMwindow, WM_HINTS); | 761 XDeleteProperty(SDL_Display, WMwindow, WM_HINTS); |
763 set = SDL_TRUE; | 762 set = SDL_TRUE; |
764 } | 763 } |
765 /* Now try to unset GNOME hints */ | 764 /* Now try to unset GNOME hints */ |
766 WM_HINTS = XInternAtom (SDL_Display, "_WIN_HINTS", True); | 765 WM_HINTS = XInternAtom(SDL_Display, "_WIN_HINTS", True); |
767 if (WM_HINTS != None) { | 766 if (WM_HINTS != None) { |
768 XDeleteProperty (SDL_Display, WMwindow, WM_HINTS); | 767 XDeleteProperty(SDL_Display, WMwindow, WM_HINTS); |
769 set = SDL_TRUE; | 768 set = SDL_TRUE; |
770 } | 769 } |
771 /* Finally unset the transient hints if necessary */ | 770 /* Finally unset the transient hints if necessary */ |
772 if (!set) { | 771 if (!set) { |
773 /* NOTE: Does this work? */ | 772 /* NOTE: Does this work? */ |
774 XSetTransientForHint (SDL_Display, WMwindow, None); | 773 XSetTransientForHint(SDL_Display, WMwindow, None); |
775 } | 774 } |
776 } | 775 } |
777 } | 776 } |
778 | 777 |
779 static int | 778 static int |
780 X11_CreateWindow (_THIS, SDL_Surface * screen, | 779 X11_CreateWindow(_THIS, SDL_Surface * screen, |
781 const SDL_DisplayMode * mode, Uint32 flags) | 780 const SDL_DisplayMode * mode, Uint32 flags) |
782 { | 781 { |
783 int i, depth; | 782 int i, depth; |
784 Visual *vis; | 783 Visual *vis; |
785 int vis_change; | 784 int vis_change; |
786 int bpp; | 785 int bpp; |
787 Uint32 Rmask, Gmask, Bmask, Amask; | 786 Uint32 Rmask, Gmask, Bmask, Amask; |
788 | 787 |
789 SDL_PixelFormatEnumToMasks (mode->format, &bpp, &Rmask, &Gmask, &Bmask, | 788 SDL_PixelFormatEnumToMasks(mode->format, &bpp, &Rmask, &Gmask, &Bmask, |
790 &Amask); | 789 &Amask); |
791 | 790 |
792 /* If a window is already present, destroy it and start fresh */ | 791 /* If a window is already present, destroy it and start fresh */ |
793 if (SDL_Window) { | 792 if (SDL_Window) { |
794 X11_DestroyWindow (this, screen); | 793 X11_DestroyWindow(this, screen); |
795 switch_waiting = 0; /* Prevent jump back to now-meaningless state. */ | 794 switch_waiting = 0; /* Prevent jump back to now-meaningless state. */ |
796 } | 795 } |
797 | 796 |
798 /* See if we have been given a window id */ | 797 /* See if we have been given a window id */ |
799 if (SDL_windowid) { | 798 if (SDL_windowid) { |
800 SDL_Window = SDL_strtol (SDL_windowid, NULL, 0); | 799 SDL_Window = SDL_strtol(SDL_windowid, NULL, 0); |
801 } else { | 800 } else { |
802 SDL_Window = 0; | 801 SDL_Window = 0; |
803 } | 802 } |
804 | 803 |
805 /* find out which visual we are going to use */ | 804 /* find out which visual we are going to use */ |
806 if (flags & SDL_INTERNALOPENGL) { | 805 if (flags & SDL_INTERNALOPENGL) { |
807 XVisualInfo *vi; | 806 XVisualInfo *vi; |
808 | 807 |
809 vi = X11_GL_GetVisual (this); | 808 vi = X11_GL_GetVisual(this); |
810 if (!vi) { | 809 if (!vi) { |
811 return -1; | 810 return -1; |
812 } | 811 } |
813 vis = vi->visual; | 812 vis = vi->visual; |
814 depth = vi->depth; | 813 depth = vi->depth; |
815 } else if (SDL_windowid) { | 814 } else if (SDL_windowid) { |
816 XWindowAttributes a; | 815 XWindowAttributes a; |
817 | 816 |
818 XGetWindowAttributes (SDL_Display, SDL_Window, &a); | 817 XGetWindowAttributes(SDL_Display, SDL_Window, &a); |
819 vis = a.visual; | 818 vis = a.visual; |
820 depth = a.depth; | 819 depth = a.depth; |
821 } else { | 820 } else { |
822 for (i = 0; i < this->hidden->nvisuals; i++) { | 821 for (i = 0; i < this->hidden->nvisuals; i++) { |
823 if (this->hidden->visuals[i].bpp == bpp && | 822 if (this->hidden->visuals[i].bpp == bpp && |
825 this->hidden->visuals[i].visual->green_mask == Gmask && | 824 this->hidden->visuals[i].visual->green_mask == Gmask && |
826 this->hidden->visuals[i].visual->blue_mask == Bmask) | 825 this->hidden->visuals[i].visual->blue_mask == Bmask) |
827 break; | 826 break; |
828 } | 827 } |
829 if (i == this->hidden->nvisuals) { | 828 if (i == this->hidden->nvisuals) { |
830 SDL_SetError ("No matching visual for requested depth"); | 829 SDL_SetError("No matching visual for requested depth"); |
831 return -1; /* should never happen */ | 830 return -1; /* should never happen */ |
832 } | 831 } |
833 vis = this->hidden->visuals[i].visual; | 832 vis = this->hidden->visuals[i].visual; |
834 depth = this->hidden->visuals[i].depth; | 833 depth = this->hidden->visuals[i].depth; |
835 } | 834 } |
836 #ifdef X11_DEBUG | 835 #ifdef X11_DEBUG |
837 printf ("Choosing %s visual at %d bpp - %d colormap entries\n", | 836 printf("Choosing %s visual at %d bpp - %d colormap entries\n", |
838 vis->class == PseudoColor ? "PseudoColor" : (vis->class == | 837 vis->class == PseudoColor ? "PseudoColor" : (vis->class == |
839 TrueColor ? | 838 TrueColor ? |
840 "TrueColor" : (vis-> | 839 "TrueColor" : (vis-> |
841 class | 840 class |
842 == | 841 == |
843 DirectColor | 842 DirectColor |
844 ? | 843 ? |
845 "DirectColor" | 844 "DirectColor" |
846 : | 845 : |
847 "Unknown")), | 846 "Unknown")), |
848 depth, vis->map_entries); | 847 depth, vis->map_entries); |
849 #endif | 848 #endif |
850 vis_change = (vis != SDL_Visual); | 849 vis_change = (vis != SDL_Visual); |
851 SDL_Visual = vis; | 850 SDL_Visual = vis; |
852 this->hidden->depth = depth; | 851 this->hidden->depth = depth; |
853 | 852 |
854 /* Allocate the new pixel format for this video mode */ | 853 /* Allocate the new pixel format for this video mode */ |
855 if (!SDL_ReallocFormat (screen, bpp, Rmask, Gmask, Bmask, Amask)) { | 854 if (!SDL_ReallocFormat(screen, bpp, Rmask, Gmask, Bmask, Amask)) { |
856 return -1; | 855 return -1; |
857 } | 856 } |
858 | 857 |
859 /* Create the appropriate colormap */ | 858 /* Create the appropriate colormap */ |
860 if (SDL_XColorMap != SDL_DisplayColormap) { | 859 if (SDL_XColorMap != SDL_DisplayColormap) { |
861 XFreeColormap (SDL_Display, SDL_XColorMap); | 860 XFreeColormap(SDL_Display, SDL_XColorMap); |
862 } | 861 } |
863 if (SDL_Visual->class == PseudoColor) { | 862 if (SDL_Visual->class == PseudoColor) { |
864 int ncolors; | 863 int ncolors; |
865 | 864 |
866 /* Allocate the pixel flags */ | 865 /* Allocate the pixel flags */ |
867 ncolors = SDL_Visual->map_entries; | 866 ncolors = SDL_Visual->map_entries; |
868 SDL_XPixels = SDL_malloc (ncolors * sizeof (int)); | 867 SDL_XPixels = SDL_malloc(ncolors * sizeof(int)); |
869 if (SDL_XPixels == NULL) { | 868 if (SDL_XPixels == NULL) { |
870 SDL_OutOfMemory (); | 869 SDL_OutOfMemory(); |
871 return -1; | 870 return -1; |
872 } | 871 } |
873 SDL_memset (SDL_XPixels, 0, ncolors * sizeof (*SDL_XPixels)); | 872 SDL_memset(SDL_XPixels, 0, ncolors * sizeof(*SDL_XPixels)); |
874 | 873 |
875 /* always allocate a private colormap on non-default visuals */ | 874 /* always allocate a private colormap on non-default visuals */ |
876 if (SDL_Visual != DefaultVisual (SDL_Display, SDL_Screen)) { | 875 if (SDL_Visual != DefaultVisual(SDL_Display, SDL_Screen)) { |
877 flags |= SDL_HWPALETTE; | 876 flags |= SDL_HWPALETTE; |
878 } | 877 } |
879 if (flags & SDL_HWPALETTE) { | 878 if (flags & SDL_HWPALETTE) { |
880 screen->flags |= SDL_HWPALETTE; | 879 screen->flags |= SDL_HWPALETTE; |
881 SDL_XColorMap = XCreateColormap (SDL_Display, SDL_Root, | 880 SDL_XColorMap = XCreateColormap(SDL_Display, SDL_Root, |
882 SDL_Visual, AllocAll); | 881 SDL_Visual, AllocAll); |
883 } else { | 882 } else { |
884 SDL_XColorMap = SDL_DisplayColormap; | 883 SDL_XColorMap = SDL_DisplayColormap; |
885 } | 884 } |
886 } else if (SDL_Visual->class == DirectColor) { | 885 } else if (SDL_Visual->class == DirectColor) { |
887 | 886 |
888 /* Create a colormap which we can manipulate for gamma */ | 887 /* Create a colormap which we can manipulate for gamma */ |
889 SDL_XColorMap = XCreateColormap (SDL_Display, SDL_Root, | 888 SDL_XColorMap = XCreateColormap(SDL_Display, SDL_Root, |
890 SDL_Visual, AllocAll); | 889 SDL_Visual, AllocAll); |
891 XSync (SDL_Display, False); | 890 XSync(SDL_Display, False); |
892 | 891 |
893 /* Initialize the colormap to the identity mapping */ | 892 /* Initialize the colormap to the identity mapping */ |
894 SDL_GetGammaRamp (0, 0, 0); | 893 SDL_GetGammaRamp(0, 0, 0); |
895 SDL_VideoSurface = screen; | 894 SDL_VideoSurface = screen; |
896 X11_SetGammaRamp (this, SDL_CurrentWindow.gamma); | 895 X11_SetGammaRamp(this, SDL_CurrentWindow.gamma); |
897 SDL_VideoSurface = NULL; | 896 SDL_VideoSurface = NULL; |
898 } else { | 897 } else { |
899 /* Create a read-only colormap for our window */ | 898 /* Create a read-only colormap for our window */ |
900 SDL_XColorMap = XCreateColormap (SDL_Display, SDL_Root, | 899 SDL_XColorMap = XCreateColormap(SDL_Display, SDL_Root, |
901 SDL_Visual, AllocNone); | 900 SDL_Visual, AllocNone); |
902 } | 901 } |
903 | 902 |
904 /* Recreate the auxiliary windows, if needed (required for GL) */ | 903 /* Recreate the auxiliary windows, if needed (required for GL) */ |
905 if (vis_change) | 904 if (vis_change) |
906 create_aux_windows (this); | 905 create_aux_windows(this); |
907 | 906 |
908 if (screen->flags & SDL_HWPALETTE) { | 907 if (screen->flags & SDL_HWPALETTE) { |
909 /* Since the full-screen window might have got a nonzero background | 908 /* Since the full-screen window might have got a nonzero background |
910 colour (0 is white on some displays), we should reset the | 909 colour (0 is white on some displays), we should reset the |
911 background to 0 here since that is what the user expects | 910 background to 0 here since that is what the user expects |
912 with a private colormap */ | 911 with a private colormap */ |
913 XSetWindowBackground (SDL_Display, FSwindow, 0); | 912 XSetWindowBackground(SDL_Display, FSwindow, 0); |
914 XClearWindow (SDL_Display, FSwindow); | 913 XClearWindow(SDL_Display, FSwindow); |
915 } | 914 } |
916 | 915 |
917 /* resize the (possibly new) window manager window */ | 916 /* resize the (possibly new) window manager window */ |
918 if (!SDL_windowid) { | 917 if (!SDL_windowid) { |
919 X11_SetSizeHints (this, mode->w, mode->h, flags); | 918 X11_SetSizeHints(this, mode->w, mode->h, flags); |
920 window_w = mode->w; | 919 window_w = mode->w; |
921 window_h = mode->h; | 920 window_h = mode->h; |
922 XResizeWindow (SDL_Display, WMwindow, mode->w, mode->h); | 921 XResizeWindow(SDL_Display, WMwindow, mode->w, mode->h); |
923 } | 922 } |
924 | 923 |
925 /* Create (or use) the X11 display window */ | 924 /* Create (or use) the X11 display window */ |
926 if (!SDL_windowid) { | 925 if (!SDL_windowid) { |
927 if (flags & SDL_INTERNALOPENGL) { | 926 if (flags & SDL_INTERNALOPENGL) { |
928 if (X11_GL_CreateWindow (this, mode->w, mode->h) < 0) { | 927 if (X11_GL_CreateWindow(this, mode->w, mode->h) < 0) { |
929 return (-1); | 928 return (-1); |
930 } | 929 } |
931 } else { | 930 } else { |
932 XSetWindowAttributes swa; | 931 XSetWindowAttributes swa; |
933 | 932 |
934 swa.background_pixel = 0; | 933 swa.background_pixel = 0; |
935 swa.border_pixel = 0; | 934 swa.border_pixel = 0; |
936 swa.colormap = SDL_XColorMap; | 935 swa.colormap = SDL_XColorMap; |
937 SDL_Window = XCreateWindow (SDL_Display, WMwindow, | 936 SDL_Window = XCreateWindow(SDL_Display, WMwindow, |
938 0, 0, mode->w, mode->h, 0, depth, | 937 0, 0, mode->w, mode->h, 0, depth, |
939 InputOutput, SDL_Visual, | 938 InputOutput, SDL_Visual, |
940 CWBackPixel | CWBorderPixel | 939 CWBackPixel | CWBorderPixel |
941 | CWColormap, &swa); | 940 | CWColormap, &swa); |
942 } | 941 } |
943 /* Only manage our input if we own the window */ | 942 /* Only manage our input if we own the window */ |
944 XSelectInput (SDL_Display, SDL_Window, | 943 XSelectInput(SDL_Display, SDL_Window, |
945 (EnterWindowMask | LeaveWindowMask | 944 (EnterWindowMask | LeaveWindowMask |
946 | ButtonPressMask | ButtonReleaseMask | 945 | ButtonPressMask | ButtonReleaseMask |
947 | PointerMotionMask | ExposureMask)); | 946 | PointerMotionMask | ExposureMask)); |
948 } | 947 } |
949 /* Create the graphics context here, once we have a window */ | 948 /* Create the graphics context here, once we have a window */ |
950 if (flags & SDL_INTERNALOPENGL) { | 949 if (flags & SDL_INTERNALOPENGL) { |
951 if (X11_GL_CreateContext (this) < 0) { | 950 if (X11_GL_CreateContext(this) < 0) { |
952 return (-1); | 951 return (-1); |
953 } else { | 952 } else { |
954 screen->flags |= SDL_INTERNALOPENGL; | 953 screen->flags |= SDL_INTERNALOPENGL; |
955 } | 954 } |
956 } else { | 955 } else { |
957 XGCValues gcv; | 956 XGCValues gcv; |
958 | 957 |
959 gcv.graphics_exposures = False; | 958 gcv.graphics_exposures = False; |
960 SDL_GC = XCreateGC (SDL_Display, SDL_Window, | 959 SDL_GC = XCreateGC(SDL_Display, SDL_Window, |
961 GCGraphicsExposures, &gcv); | 960 GCGraphicsExposures, &gcv); |
962 if (!SDL_GC) { | 961 if (!SDL_GC) { |
963 SDL_SetError ("Couldn't create graphics context"); | 962 SDL_SetError("Couldn't create graphics context"); |
964 return (-1); | 963 return (-1); |
965 } | 964 } |
966 } | 965 } |
967 | 966 |
968 /* Set our colormaps when not setting a GL mode */ | 967 /* Set our colormaps when not setting a GL mode */ |
969 if (!(flags & SDL_INTERNALOPENGL)) { | 968 if (!(flags & SDL_INTERNALOPENGL)) { |
970 XSetWindowColormap (SDL_Display, SDL_Window, SDL_XColorMap); | 969 XSetWindowColormap(SDL_Display, SDL_Window, SDL_XColorMap); |
971 if (!SDL_windowid) { | 970 if (!SDL_windowid) { |
972 XSetWindowColormap (SDL_Display, FSwindow, SDL_XColorMap); | 971 XSetWindowColormap(SDL_Display, FSwindow, SDL_XColorMap); |
973 XSetWindowColormap (SDL_Display, WMwindow, SDL_XColorMap); | 972 XSetWindowColormap(SDL_Display, WMwindow, SDL_XColorMap); |
974 } | 973 } |
975 } | 974 } |
976 #if 0 /* This is an experiment - are the graphics faster now? - nope. */ | 975 #if 0 /* This is an experiment - are the graphics faster now? - nope. */ |
977 if (SDL_getenv ("SDL_VIDEO_X11_BACKINGSTORE")) | 976 if (SDL_getenv("SDL_VIDEO_X11_BACKINGSTORE")) |
978 #endif | 977 #endif |
979 /* Cache the window in the server, when possible */ | 978 /* Cache the window in the server, when possible */ |
980 { | 979 { |
981 Screen *xscreen; | 980 Screen *xscreen; |
982 XSetWindowAttributes a; | 981 XSetWindowAttributes a; |
983 | 982 |
984 xscreen = ScreenOfDisplay (SDL_Display, SDL_Screen); | 983 xscreen = ScreenOfDisplay(SDL_Display, SDL_Screen); |
985 a.backing_store = DoesBackingStore (xscreen); | 984 a.backing_store = DoesBackingStore(xscreen); |
986 if (a.backing_store != NotUseful) { | 985 if (a.backing_store != NotUseful) { |
987 XChangeWindowAttributes (SDL_Display, SDL_Window, | 986 XChangeWindowAttributes(SDL_Display, SDL_Window, |
988 CWBackingStore, &a); | 987 CWBackingStore, &a); |
989 } | 988 } |
990 } | 989 } |
991 | 990 |
992 /* Update the internal keyboard state */ | 991 /* Update the internal keyboard state */ |
993 X11_SetKeyboardState (SDL_Display, NULL); | 992 X11_SetKeyboardState(SDL_Display, NULL); |
994 | 993 |
995 /* When the window is first mapped, ignore non-modifier keys */ | 994 /* When the window is first mapped, ignore non-modifier keys */ |
996 { | 995 { |
997 Uint8 *keys = SDL_GetKeyState (NULL); | 996 Uint8 *keys = SDL_GetKeyState(NULL); |
998 for (i = 0; i < SDLK_LAST; ++i) { | 997 for (i = 0; i < SDLK_LAST; ++i) { |
999 switch (i) { | 998 switch (i) { |
1000 case SDLK_NUMLOCK: | 999 case SDLK_NUMLOCK: |
1001 case SDLK_CAPSLOCK: | 1000 case SDLK_CAPSLOCK: |
1002 case SDLK_LCTRL: | 1001 case SDLK_LCTRL: |
1016 } | 1015 } |
1017 } | 1016 } |
1018 | 1017 |
1019 /* Map them both and go fullscreen, if requested */ | 1018 /* Map them both and go fullscreen, if requested */ |
1020 if (!SDL_windowid) { | 1019 if (!SDL_windowid) { |
1021 XMapWindow (SDL_Display, SDL_Window); | 1020 XMapWindow(SDL_Display, SDL_Window); |
1022 XMapWindow (SDL_Display, WMwindow); | 1021 XMapWindow(SDL_Display, WMwindow); |
1023 X11_WaitMapped (this, WMwindow); | 1022 X11_WaitMapped(this, WMwindow); |
1024 if (flags & SDL_FULLSCREEN) { | 1023 if (flags & SDL_FULLSCREEN) { |
1025 screen->flags |= SDL_FULLSCREEN; | 1024 screen->flags |= SDL_FULLSCREEN; |
1026 X11_EnterFullScreen (this); | 1025 X11_EnterFullScreen(this); |
1027 } else { | 1026 } else { |
1028 screen->flags &= ~SDL_FULLSCREEN; | 1027 screen->flags &= ~SDL_FULLSCREEN; |
1029 } | 1028 } |
1030 } | 1029 } |
1031 | 1030 |
1032 return (0); | 1031 return (0); |
1033 } | 1032 } |
1034 | 1033 |
1035 static int | 1034 static int |
1036 X11_ResizeWindow (_THIS, SDL_Surface * screen, int w, int h, Uint32 flags) | 1035 X11_ResizeWindow(_THIS, SDL_Surface * screen, int w, int h, Uint32 flags) |
1037 { | 1036 { |
1038 if (!SDL_windowid) { | 1037 if (!SDL_windowid) { |
1039 /* Resize the window manager window */ | 1038 /* Resize the window manager window */ |
1040 X11_SetSizeHints (this, w, h, flags); | 1039 X11_SetSizeHints(this, w, h, flags); |
1041 window_w = w; | 1040 window_w = w; |
1042 window_h = h; | 1041 window_h = h; |
1043 XResizeWindow (SDL_Display, WMwindow, w, h); | 1042 XResizeWindow(SDL_Display, WMwindow, w, h); |
1044 | 1043 |
1045 /* Resize the fullscreen and display windows */ | 1044 /* Resize the fullscreen and display windows */ |
1046 if (flags & SDL_FULLSCREEN) { | 1045 if (flags & SDL_FULLSCREEN) { |
1047 if (screen->flags & SDL_FULLSCREEN) { | 1046 if (screen->flags & SDL_FULLSCREEN) { |
1048 X11_ResizeFullScreen (this); | 1047 X11_ResizeFullScreen(this); |
1049 } else { | 1048 } else { |
1050 screen->flags |= SDL_FULLSCREEN; | 1049 screen->flags |= SDL_FULLSCREEN; |
1051 X11_EnterFullScreen (this); | 1050 X11_EnterFullScreen(this); |
1052 } | 1051 } |
1053 } else { | 1052 } else { |
1054 if (screen->flags & SDL_FULLSCREEN) { | 1053 if (screen->flags & SDL_FULLSCREEN) { |
1055 screen->flags &= ~SDL_FULLSCREEN; | 1054 screen->flags &= ~SDL_FULLSCREEN; |
1056 X11_LeaveFullScreen (this); | 1055 X11_LeaveFullScreen(this); |
1057 } | 1056 } |
1058 } | 1057 } |
1059 XResizeWindow (SDL_Display, SDL_Window, w, h); | 1058 XResizeWindow(SDL_Display, SDL_Window, w, h); |
1060 } | 1059 } |
1061 return (0); | 1060 return (0); |
1062 } | 1061 } |
1063 | 1062 |
1064 SDL_Surface * | 1063 SDL_Surface * |
1065 X11_SetVideoMode (_THIS, SDL_Surface * current, | 1064 X11_SetVideoMode(_THIS, SDL_Surface * current, |
1066 const SDL_DisplayMode * mode, Uint32 flags) | 1065 const SDL_DisplayMode * mode, Uint32 flags) |
1067 { | 1066 { |
1068 Uint32 saved_flags; | 1067 Uint32 saved_flags; |
1069 | 1068 |
1070 /* Lock the event thread, in multi-threading environments */ | 1069 /* Lock the event thread, in multi-threading environments */ |
1071 SDL_Lock_EventThread (); | 1070 SDL_Lock_EventThread(); |
1072 | 1071 |
1073 /* Check the combination of flags we were passed */ | 1072 /* Check the combination of flags we were passed */ |
1074 if (flags & SDL_FULLSCREEN) { | 1073 if (flags & SDL_FULLSCREEN) { |
1075 /* Clear fullscreen flag if not supported */ | 1074 /* Clear fullscreen flag if not supported */ |
1076 if (SDL_windowid) { | 1075 if (SDL_windowid) { |
1077 flags &= ~SDL_FULLSCREEN; | 1076 flags &= ~SDL_FULLSCREEN; |
1078 } | 1077 } |
1079 } | 1078 } |
1080 | 1079 |
1081 /* Flush any delayed updates */ | 1080 /* Flush any delayed updates */ |
1082 XSync (GFX_Display, False); | 1081 XSync(GFX_Display, False); |
1083 | 1082 |
1084 /* Set up the X11 window */ | 1083 /* Set up the X11 window */ |
1085 saved_flags = current->flags; | 1084 saved_flags = current->flags; |
1086 if ((SDL_Window) | 1085 if ((SDL_Window) |
1087 && ((saved_flags & SDL_INTERNALOPENGL) == | 1086 && ((saved_flags & SDL_INTERNALOPENGL) == |
1088 (flags & SDL_INTERNALOPENGL)) | 1087 (flags & SDL_INTERNALOPENGL)) |
1089 && (mode->format == SDL_CurrentDisplay.current_mode.format) | 1088 && (mode->format == SDL_CurrentDisplay.current_mode.format) |
1090 && ((saved_flags & SDL_NOFRAME) == (flags & SDL_NOFRAME))) { | 1089 && ((saved_flags & SDL_NOFRAME) == (flags & SDL_NOFRAME))) { |
1091 if (X11_ResizeWindow (this, current, mode->w, mode->h, flags) < 0) { | 1090 if (X11_ResizeWindow(this, current, mode->w, mode->h, flags) < 0) { |
1092 current = NULL; | 1091 current = NULL; |
1093 goto done; | 1092 goto done; |
1094 } | 1093 } |
1095 } else { | 1094 } else { |
1096 if (X11_CreateWindow (this, current, mode, flags) < 0) { | 1095 if (X11_CreateWindow(this, current, mode, flags) < 0) { |
1097 current = NULL; | 1096 current = NULL; |
1098 goto done; | 1097 goto done; |
1099 } | 1098 } |
1100 } | 1099 } |
1101 | 1100 |
1103 if (((current->w != mode->w) || (current->h != mode->h)) || | 1102 if (((current->w != mode->w) || (current->h != mode->h)) || |
1104 ((saved_flags & SDL_INTERNALOPENGL) != (flags & SDL_INTERNALOPENGL))) | 1103 ((saved_flags & SDL_INTERNALOPENGL) != (flags & SDL_INTERNALOPENGL))) |
1105 { | 1104 { |
1106 current->w = mode->w; | 1105 current->w = mode->w; |
1107 current->h = mode->h; | 1106 current->h = mode->h; |
1108 current->pitch = SDL_CalculatePitch (current); | 1107 current->pitch = SDL_CalculatePitch(current); |
1109 X11_ResizeImage (this, current, flags); | 1108 X11_ResizeImage(this, current, flags); |
1110 } | 1109 } |
1111 current->flags |= (flags & (SDL_RESIZABLE | SDL_NOFRAME)); | 1110 current->flags |= (flags & (SDL_RESIZABLE | SDL_NOFRAME)); |
1112 | 1111 |
1113 done: | 1112 done: |
1114 /* Release the event thread */ | 1113 /* Release the event thread */ |
1115 XSync (SDL_Display, False); | 1114 XSync(SDL_Display, False); |
1116 SDL_Unlock_EventThread (); | 1115 SDL_Unlock_EventThread(); |
1117 | 1116 |
1118 /* We're done! */ | 1117 /* We're done! */ |
1119 return (current); | 1118 return (current); |
1120 } | 1119 } |
1121 | 1120 |
1122 static int | 1121 static int |
1123 X11_ToggleFullScreen (_THIS, int on) | 1122 X11_ToggleFullScreen(_THIS, int on) |
1124 { | 1123 { |
1125 Uint32 event_thread; | 1124 Uint32 event_thread; |
1126 | 1125 |
1127 /* Don't switch if we don't own the window */ | 1126 /* Don't switch if we don't own the window */ |
1128 if (SDL_windowid) { | 1127 if (SDL_windowid) { |
1129 return (0); | 1128 return (0); |
1130 } | 1129 } |
1131 | 1130 |
1132 /* Don't lock if we are the event thread */ | 1131 /* Don't lock if we are the event thread */ |
1133 event_thread = SDL_EventThreadID (); | 1132 event_thread = SDL_EventThreadID(); |
1134 if (event_thread && (SDL_ThreadID () == event_thread)) { | 1133 if (event_thread && (SDL_ThreadID() == event_thread)) { |
1135 event_thread = 0; | 1134 event_thread = 0; |
1136 } | 1135 } |
1137 if (event_thread) { | 1136 if (event_thread) { |
1138 SDL_Lock_EventThread (); | 1137 SDL_Lock_EventThread(); |
1139 } | 1138 } |
1140 if (on) { | 1139 if (on) { |
1141 SDL_VideoSurface->flags |= SDL_FULLSCREEN; | 1140 SDL_VideoSurface->flags |= SDL_FULLSCREEN; |
1142 X11_EnterFullScreen (this); | 1141 X11_EnterFullScreen(this); |
1143 } else { | 1142 } else { |
1144 SDL_VideoSurface->flags &= ~SDL_FULLSCREEN; | 1143 SDL_VideoSurface->flags &= ~SDL_FULLSCREEN; |
1145 X11_LeaveFullScreen (this); | 1144 X11_LeaveFullScreen(this); |
1146 } | 1145 } |
1147 X11_RefreshDisplay (this); | 1146 X11_RefreshDisplay(this); |
1148 if (event_thread) { | 1147 if (event_thread) { |
1149 SDL_Unlock_EventThread (); | 1148 SDL_Unlock_EventThread(); |
1150 } | 1149 } |
1151 SDL_ResetKeyboard (); | 1150 SDL_ResetKeyboard(); |
1152 return (1); | 1151 return (1); |
1153 } | 1152 } |
1154 | 1153 |
1155 /* Update the current mouse state and position */ | 1154 /* Update the current mouse state and position */ |
1156 static void | 1155 static void |
1157 X11_UpdateMouse (_THIS) | 1156 X11_UpdateMouse(_THIS) |
1158 { | 1157 { |
1159 Window u1; | 1158 Window u1; |
1160 int u2; | 1159 int u2; |
1161 Window current_win; | 1160 Window current_win; |
1162 int x, y; | 1161 int x, y; |
1163 unsigned int mask; | 1162 unsigned int mask; |
1164 | 1163 |
1165 /* Lock the event thread, in multi-threading environments */ | 1164 /* Lock the event thread, in multi-threading environments */ |
1166 SDL_Lock_EventThread (); | 1165 SDL_Lock_EventThread(); |
1167 if (XQueryPointer (SDL_Display, SDL_Window, &u1, ¤t_win, | 1166 if (XQueryPointer(SDL_Display, SDL_Window, &u1, ¤t_win, |
1168 &u2, &u2, &x, &y, &mask)) { | 1167 &u2, &u2, &x, &y, &mask)) { |
1169 if ((x >= 0) && (x < SDL_VideoSurface->w) && | 1168 if ((x >= 0) && (x < SDL_VideoSurface->w) && |
1170 (y >= 0) && (y < SDL_VideoSurface->h)) { | 1169 (y >= 0) && (y < SDL_VideoSurface->h)) { |
1171 SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS); | 1170 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); |
1172 SDL_PrivateMouseMotion (0, 0, x, y); | 1171 SDL_PrivateMouseMotion(0, 0, x, y); |
1173 } else { | 1172 } else { |
1174 SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS); | 1173 SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS); |
1175 } | 1174 } |
1176 } | 1175 } |
1177 SDL_Unlock_EventThread (); | 1176 SDL_Unlock_EventThread(); |
1178 } | 1177 } |
1179 | 1178 |
1180 /* simple colour distance metric. Supposed to be better than a plain | 1179 /* simple colour distance metric. Supposed to be better than a plain |
1181 Euclidian distance anyway. */ | 1180 Euclidian distance anyway. */ |
1182 #define COLOUR_FACTOR 3 | 1181 #define COLOUR_FACTOR 3 |
1184 #define COLOUR_DIST(r1, g1, b1, r2, g2, b2) \ | 1183 #define COLOUR_DIST(r1, g1, b1, r2, g2, b2) \ |
1185 (COLOUR_FACTOR * (abs(r1 - r2) + abs(g1 - g2) + abs(b1 - b2)) \ | 1184 (COLOUR_FACTOR * (abs(r1 - r2) + abs(g1 - g2) + abs(b1 - b2)) \ |
1186 + LIGHT_FACTOR * abs(r1 + g1 + b1 - (r2 + g2 + b2))) | 1185 + LIGHT_FACTOR * abs(r1 + g1 + b1 - (r2 + g2 + b2))) |
1187 | 1186 |
1188 static void | 1187 static void |
1189 allocate_nearest (_THIS, SDL_Color * colors, SDL_Color * want, int nwant) | 1188 allocate_nearest(_THIS, SDL_Color * colors, SDL_Color * want, int nwant) |
1190 { | 1189 { |
1191 /* | 1190 /* |
1192 * There is no way to know which ones to choose from, so we retrieve | 1191 * There is no way to know which ones to choose from, so we retrieve |
1193 * the entire colormap and try the nearest possible, until we find one | 1192 * the entire colormap and try the nearest possible, until we find one |
1194 * that is shared. | 1193 * that is shared. |
1199 all[i].pixel = i; | 1198 all[i].pixel = i; |
1200 /* | 1199 /* |
1201 * XQueryColors sets the flags in the XColor struct, so we use | 1200 * XQueryColors sets the flags in the XColor struct, so we use |
1202 * that to keep track of which colours are available | 1201 * that to keep track of which colours are available |
1203 */ | 1202 */ |
1204 XQueryColors (GFX_Display, SDL_XColorMap, all, 256); | 1203 XQueryColors(GFX_Display, SDL_XColorMap, all, 256); |
1205 | 1204 |
1206 for (i = 0; i < nwant; i++) { | 1205 for (i = 0; i < nwant; i++) { |
1207 XColor *c; | 1206 XColor *c; |
1208 int j; | 1207 int j; |
1209 int best = 0; | 1208 int best = 0; |
1216 if (!all[j].flags) | 1215 if (!all[j].flags) |
1217 continue; /* unavailable colour cell */ | 1216 continue; /* unavailable colour cell */ |
1218 rj = all[j].red >> 8; | 1217 rj = all[j].red >> 8; |
1219 gj = all[j].green >> 8; | 1218 gj = all[j].green >> 8; |
1220 bj = all[j].blue >> 8; | 1219 bj = all[j].blue >> 8; |
1221 d2 = COLOUR_DIST (ri, gi, bi, rj, gj, bj); | 1220 d2 = COLOUR_DIST(ri, gi, bi, rj, gj, bj); |
1222 if (d2 < mindist) { | 1221 if (d2 < mindist) { |
1223 mindist = d2; | 1222 mindist = d2; |
1224 best = j; | 1223 best = j; |
1225 } | 1224 } |
1226 } | 1225 } |
1227 if (SDL_XPixels[best]) | 1226 if (SDL_XPixels[best]) |
1228 continue; /* already allocated, waste no more time */ | 1227 continue; /* already allocated, waste no more time */ |
1229 c = all + best; | 1228 c = all + best; |
1230 if (XAllocColor (GFX_Display, SDL_XColorMap, c)) { | 1229 if (XAllocColor(GFX_Display, SDL_XColorMap, c)) { |
1231 /* got it */ | 1230 /* got it */ |
1232 colors[c->pixel].r = c->red >> 8; | 1231 colors[c->pixel].r = c->red >> 8; |
1233 colors[c->pixel].g = c->green >> 8; | 1232 colors[c->pixel].g = c->green >> 8; |
1234 colors[c->pixel].b = c->blue >> 8; | 1233 colors[c->pixel].b = c->blue >> 8; |
1235 ++SDL_XPixels[c->pixel]; | 1234 ++SDL_XPixels[c->pixel]; |
1246 } | 1245 } |
1247 } | 1246 } |
1248 } | 1247 } |
1249 | 1248 |
1250 int | 1249 int |
1251 X11_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors) | 1250 X11_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors) |
1252 { | 1251 { |
1253 int nrej = 0; | 1252 int nrej = 0; |
1254 | 1253 |
1255 /* Check to make sure we have a colormap allocated */ | 1254 /* Check to make sure we have a colormap allocated */ |
1256 if (SDL_XPixels == NULL) { | 1255 if (SDL_XPixels == NULL) { |
1258 } | 1257 } |
1259 if ((SDL_VideoSurface->flags & SDL_HWPALETTE) == SDL_HWPALETTE) { | 1258 if ((SDL_VideoSurface->flags & SDL_HWPALETTE) == SDL_HWPALETTE) { |
1260 /* private writable colormap: just set the colours we need */ | 1259 /* private writable colormap: just set the colours we need */ |
1261 XColor *xcmap; | 1260 XColor *xcmap; |
1262 int i; | 1261 int i; |
1263 xcmap = SDL_stack_alloc (XColor, ncolors); | 1262 xcmap = SDL_stack_alloc(XColor, ncolors); |
1264 if (xcmap == NULL) | 1263 if (xcmap == NULL) |
1265 return 0; | 1264 return 0; |
1266 for (i = 0; i < ncolors; ++i) { | 1265 for (i = 0; i < ncolors; ++i) { |
1267 xcmap[i].pixel = i + firstcolor; | 1266 xcmap[i].pixel = i + firstcolor; |
1268 xcmap[i].red = (colors[i].r << 8) | colors[i].r; | 1267 xcmap[i].red = (colors[i].r << 8) | colors[i].r; |
1269 xcmap[i].green = (colors[i].g << 8) | colors[i].g; | 1268 xcmap[i].green = (colors[i].g << 8) | colors[i].g; |
1270 xcmap[i].blue = (colors[i].b << 8) | colors[i].b; | 1269 xcmap[i].blue = (colors[i].b << 8) | colors[i].b; |
1271 xcmap[i].flags = (DoRed | DoGreen | DoBlue); | 1270 xcmap[i].flags = (DoRed | DoGreen | DoBlue); |
1272 } | 1271 } |
1273 XStoreColors (GFX_Display, SDL_XColorMap, xcmap, ncolors); | 1272 XStoreColors(GFX_Display, SDL_XColorMap, xcmap, ncolors); |
1274 XSync (GFX_Display, False); | 1273 XSync(GFX_Display, False); |
1275 SDL_stack_free (xcmap); | 1274 SDL_stack_free(xcmap); |
1276 } else { | 1275 } else { |
1277 /* | 1276 /* |
1278 * Shared colormap: We only allocate read-only cells, which | 1277 * Shared colormap: We only allocate read-only cells, which |
1279 * increases the likelyhood of colour sharing with other | 1278 * increases the likelyhood of colour sharing with other |
1280 * clients. The pixel values will almost certainly be | 1279 * clients. The pixel values will almost certainly be |
1288 unsigned long *freelist; | 1287 unsigned long *freelist; |
1289 int i; | 1288 int i; |
1290 int nfree = 0; | 1289 int nfree = 0; |
1291 int nc = SDL_VideoSurface->format->palette->ncolors; | 1290 int nc = SDL_VideoSurface->format->palette->ncolors; |
1292 colors = SDL_VideoSurface->format->palette->colors; | 1291 colors = SDL_VideoSurface->format->palette->colors; |
1293 freelist = SDL_stack_alloc (unsigned long, nc); | 1292 freelist = SDL_stack_alloc(unsigned long, nc); |
1294 /* make sure multiple allocations of the same cell are freed */ | 1293 /* make sure multiple allocations of the same cell are freed */ |
1295 for (i = 0; i < ncolors; i++) { | 1294 for (i = 0; i < ncolors; i++) { |
1296 int pixel = firstcolor + i; | 1295 int pixel = firstcolor + i; |
1297 while (SDL_XPixels[pixel]) { | 1296 while (SDL_XPixels[pixel]) { |
1298 freelist[nfree++] = pixel; | 1297 freelist[nfree++] = pixel; |
1299 --SDL_XPixels[pixel]; | 1298 --SDL_XPixels[pixel]; |
1300 } | 1299 } |
1301 } | 1300 } |
1302 XFreeColors (GFX_Display, SDL_XColorMap, freelist, nfree, 0); | 1301 XFreeColors(GFX_Display, SDL_XColorMap, freelist, nfree, 0); |
1303 SDL_stack_free (freelist); | 1302 SDL_stack_free(freelist); |
1304 | 1303 |
1305 want = SDL_stack_alloc (SDL_Color, ncolors); | 1304 want = SDL_stack_alloc(SDL_Color, ncolors); |
1306 reject = SDL_stack_alloc (SDL_Color, ncolors); | 1305 reject = SDL_stack_alloc(SDL_Color, ncolors); |
1307 SDL_memcpy (want, colors + firstcolor, ncolors * sizeof (SDL_Color)); | 1306 SDL_memcpy(want, colors + firstcolor, ncolors * sizeof(SDL_Color)); |
1308 /* make sure the user isn't fooled by her own wishes | 1307 /* make sure the user isn't fooled by her own wishes |
1309 (black is safe, always available in the default colormap) */ | 1308 (black is safe, always available in the default colormap) */ |
1310 SDL_memset (colors + firstcolor, 0, ncolors * sizeof (SDL_Color)); | 1309 SDL_memset(colors + firstcolor, 0, ncolors * sizeof(SDL_Color)); |
1311 | 1310 |
1312 /* now try to allocate the colours */ | 1311 /* now try to allocate the colours */ |
1313 for (i = 0; i < ncolors; i++) { | 1312 for (i = 0; i < ncolors; i++) { |
1314 XColor col; | 1313 XColor col; |
1315 col.red = want[i].r << 8; | 1314 col.red = want[i].r << 8; |
1316 col.green = want[i].g << 8; | 1315 col.green = want[i].g << 8; |
1317 col.blue = want[i].b << 8; | 1316 col.blue = want[i].b << 8; |
1318 col.flags = DoRed | DoGreen | DoBlue; | 1317 col.flags = DoRed | DoGreen | DoBlue; |
1319 if (XAllocColor (GFX_Display, SDL_XColorMap, &col)) { | 1318 if (XAllocColor(GFX_Display, SDL_XColorMap, &col)) { |
1320 /* We got the colour, or at least the nearest | 1319 /* We got the colour, or at least the nearest |
1321 the hardware could get. */ | 1320 the hardware could get. */ |
1322 colors[col.pixel].r = col.red >> 8; | 1321 colors[col.pixel].r = col.red >> 8; |
1323 colors[col.pixel].g = col.green >> 8; | 1322 colors[col.pixel].g = col.green >> 8; |
1324 colors[col.pixel].b = col.blue >> 8; | 1323 colors[col.pixel].b = col.blue >> 8; |
1330 */ | 1329 */ |
1331 reject[nrej++] = want[i]; | 1330 reject[nrej++] = want[i]; |
1332 } | 1331 } |
1333 } | 1332 } |
1334 if (nrej) | 1333 if (nrej) |
1335 allocate_nearest (this, colors, reject, nrej); | 1334 allocate_nearest(this, colors, reject, nrej); |
1336 SDL_stack_free (reject); | 1335 SDL_stack_free(reject); |
1337 SDL_stack_free (want); | 1336 SDL_stack_free(want); |
1338 } | 1337 } |
1339 return nrej == 0; | 1338 return nrej == 0; |
1340 } | 1339 } |
1341 | 1340 |
1342 int | 1341 int |
1343 X11_SetGammaRamp (_THIS, Uint16 * ramp) | 1342 X11_SetGammaRamp(_THIS, Uint16 * ramp) |
1344 { | 1343 { |
1345 int i, ncolors; | 1344 int i, ncolors; |
1346 XColor xcmap[256]; | 1345 XColor xcmap[256]; |
1347 | 1346 |
1348 /* See if actually setting the gamma is supported */ | 1347 /* See if actually setting the gamma is supported */ |
1349 if (SDL_Visual->class != DirectColor) { | 1348 if (SDL_Visual->class != DirectColor) { |
1350 SDL_SetError ("Gamma correction not supported on this visual"); | 1349 SDL_SetError("Gamma correction not supported on this visual"); |
1351 return (-1); | 1350 return (-1); |
1352 } | 1351 } |
1353 | 1352 |
1354 /* Calculate the appropriate palette for the given gamma ramp */ | 1353 /* Calculate the appropriate palette for the given gamma ramp */ |
1355 ncolors = SDL_Visual->map_entries; | 1354 ncolors = SDL_Visual->map_entries; |
1356 for (i = 0; i < ncolors; ++i) { | 1355 for (i = 0; i < ncolors; ++i) { |
1357 Uint8 c = (256 * i / ncolors); | 1356 Uint8 c = (256 * i / ncolors); |
1358 xcmap[i].pixel = SDL_MapRGB (SDL_VideoSurface->format, c, c, c); | 1357 xcmap[i].pixel = SDL_MapRGB(SDL_VideoSurface->format, c, c, c); |
1359 xcmap[i].red = ramp[0 * 256 + c]; | 1358 xcmap[i].red = ramp[0 * 256 + c]; |
1360 xcmap[i].green = ramp[1 * 256 + c]; | 1359 xcmap[i].green = ramp[1 * 256 + c]; |
1361 xcmap[i].blue = ramp[2 * 256 + c]; | 1360 xcmap[i].blue = ramp[2 * 256 + c]; |
1362 xcmap[i].flags = (DoRed | DoGreen | DoBlue); | 1361 xcmap[i].flags = (DoRed | DoGreen | DoBlue); |
1363 } | 1362 } |
1364 XStoreColors (GFX_Display, SDL_XColorMap, xcmap, ncolors); | 1363 XStoreColors(GFX_Display, SDL_XColorMap, xcmap, ncolors); |
1365 XSync (GFX_Display, False); | 1364 XSync(GFX_Display, False); |
1366 return (0); | 1365 return (0); |
1367 } | 1366 } |
1368 | 1367 |
1369 /* Note: If we are terminated, this could be called in the middle of | 1368 /* Note: If we are terminated, this could be called in the middle of |
1370 another SDL video routine -- notably UpdateRects. | 1369 another SDL video routine -- notably UpdateRects. |
1371 */ | 1370 */ |
1372 void | 1371 void |
1373 X11_VideoQuit (_THIS) | 1372 X11_VideoQuit(_THIS) |
1374 { | 1373 { |
1375 /* Shutdown everything that's still up */ | 1374 /* Shutdown everything that's still up */ |
1376 /* The event thread should be done, so we can touch SDL_Display */ | 1375 /* The event thread should be done, so we can touch SDL_Display */ |
1377 if (SDL_Display != NULL) { | 1376 if (SDL_Display != NULL) { |
1378 /* Flush any delayed updates */ | 1377 /* Flush any delayed updates */ |
1379 XSync (GFX_Display, False); | 1378 XSync(GFX_Display, False); |
1380 | 1379 |
1381 /* Close the connection with the IM server */ | 1380 /* Close the connection with the IM server */ |
1382 #ifdef X_HAVE_UTF8_STRING | 1381 #ifdef X_HAVE_UTF8_STRING |
1383 if (SDL_IC != NULL) { | 1382 if (SDL_IC != NULL) { |
1384 XDestroyIC (SDL_IC); | 1383 XDestroyIC(SDL_IC); |
1385 SDL_IC = NULL; | 1384 SDL_IC = NULL; |
1386 } | 1385 } |
1387 if (SDL_IM != NULL) { | 1386 if (SDL_IM != NULL) { |
1388 XCloseIM (SDL_IM); | 1387 XCloseIM(SDL_IM); |
1389 SDL_IM = NULL; | 1388 SDL_IM = NULL; |
1390 } | 1389 } |
1391 #endif | 1390 #endif |
1392 | 1391 |
1393 /* Start shutting down the windows */ | 1392 /* Start shutting down the windows */ |
1394 X11_DestroyImage (this, SDL_VideoSurface); | 1393 X11_DestroyImage(this, SDL_VideoSurface); |
1395 X11_DestroyWindow (this, SDL_VideoSurface); | 1394 X11_DestroyWindow(this, SDL_VideoSurface); |
1396 X11_FreeVideoModes (this); | 1395 X11_FreeVideoModes(this); |
1397 if (SDL_XColorMap != SDL_DisplayColormap) { | 1396 if (SDL_XColorMap != SDL_DisplayColormap) { |
1398 XFreeColormap (SDL_Display, SDL_XColorMap); | 1397 XFreeColormap(SDL_Display, SDL_XColorMap); |
1399 } | 1398 } |
1400 if (SDL_iconcolors) { | 1399 if (SDL_iconcolors) { |
1401 unsigned long pixel; | 1400 unsigned long pixel; |
1402 Colormap dcmap = DefaultColormap (SDL_Display, | 1401 Colormap dcmap = DefaultColormap(SDL_Display, |
1403 SDL_Screen); | 1402 SDL_Screen); |
1404 for (pixel = 0; pixel < 256; ++pixel) { | 1403 for (pixel = 0; pixel < 256; ++pixel) { |
1405 while (SDL_iconcolors[pixel] > 0) { | 1404 while (SDL_iconcolors[pixel] > 0) { |
1406 XFreeColors (GFX_Display, dcmap, &pixel, 1, 0); | 1405 XFreeColors(GFX_Display, dcmap, &pixel, 1, 0); |
1407 --SDL_iconcolors[pixel]; | 1406 --SDL_iconcolors[pixel]; |
1408 } | 1407 } |
1409 } | 1408 } |
1410 SDL_free (SDL_iconcolors); | 1409 SDL_free(SDL_iconcolors); |
1411 SDL_iconcolors = NULL; | 1410 SDL_iconcolors = NULL; |
1412 } | 1411 } |
1413 if (xinerama) { | 1412 if (xinerama) { |
1414 XFree (xinerama); | 1413 XFree(xinerama); |
1415 } | 1414 } |
1416 | 1415 |
1417 /* Restore gamma settings if they've changed */ | 1416 /* Restore gamma settings if they've changed */ |
1418 if (SDL_GetAppState () & SDL_APPACTIVE) { | 1417 if (SDL_GetAppState() & SDL_APPACTIVE) { |
1419 X11_SwapVidModeGamma (this); | 1418 X11_SwapVidModeGamma(this); |
1420 } | 1419 } |
1421 | 1420 |
1422 /* Restore DPMS and screensaver settings */ | 1421 /* Restore DPMS and screensaver settings */ |
1423 X11_RestoreScreenSaver (SDL_Display, screensaver_timeout, | 1422 X11_RestoreScreenSaver(SDL_Display, screensaver_timeout, |
1424 dpms_enabled); | 1423 dpms_enabled); |
1425 | 1424 |
1426 /* Free that blank cursor */ | 1425 /* Free that blank cursor */ |
1427 if (SDL_BlankCursor != NULL) { | 1426 if (SDL_BlankCursor != NULL) { |
1428 this->FreeWMCursor (this, SDL_BlankCursor); | 1427 this->FreeWMCursor(this, SDL_BlankCursor); |
1429 SDL_BlankCursor = NULL; | 1428 SDL_BlankCursor = NULL; |
1430 } | 1429 } |
1431 | 1430 |
1432 /* Close the X11 graphics connection */ | 1431 /* Close the X11 graphics connection */ |
1433 if (GFX_Display != NULL) { | 1432 if (GFX_Display != NULL) { |
1434 XCloseDisplay (GFX_Display); | 1433 XCloseDisplay(GFX_Display); |
1435 GFX_Display = NULL; | 1434 GFX_Display = NULL; |
1436 } | 1435 } |
1437 | 1436 |
1438 /* Close the X11 display connection */ | 1437 /* Close the X11 display connection */ |
1439 XCloseDisplay (SDL_Display); | 1438 XCloseDisplay(SDL_Display); |
1440 SDL_Display = NULL; | 1439 SDL_Display = NULL; |
1441 | 1440 |
1442 /* Reset the X11 error handlers */ | 1441 /* Reset the X11 error handlers */ |
1443 if (XIO_handler) { | 1442 if (XIO_handler) { |
1444 XSetIOErrorHandler (XIO_handler); | 1443 XSetIOErrorHandler(XIO_handler); |
1445 } | 1444 } |
1446 if (X_handler) { | 1445 if (X_handler) { |
1447 XSetErrorHandler (X_handler); | 1446 XSetErrorHandler(X_handler); |
1448 } | 1447 } |
1449 | 1448 |
1450 /* Unload GL library after X11 shuts down */ | 1449 /* Unload GL library after X11 shuts down */ |
1451 X11_GL_UnloadLibrary (this); | 1450 X11_GL_UnloadLibrary(this); |
1452 } | 1451 } |
1453 if (SDL_VideoSurface && (SDL_VideoSurface->flags & SDL_HWSURFACE)) { | 1452 if (SDL_VideoSurface && (SDL_VideoSurface->flags & SDL_HWSURFACE)) { |
1454 /* Direct screen access, no memory buffer */ | 1453 /* Direct screen access, no memory buffer */ |
1455 SDL_VideoSurface->pixels = NULL; | 1454 SDL_VideoSurface->pixels = NULL; |
1456 } | 1455 } |