Mercurial > sdl-ios-xcode
comparison src/video/x11/SDL_x11video.c @ 1336:3692456e7b0f
Use SDL_ prefixed versions of C library functions.
FIXME:
Change #include <stdlib.h> to #include "SDL_stdlib.h"
Change #include <string.h> to #include "SDL_string.h"
Make sure nothing else broke because of this...
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 07 Feb 2006 06:59:48 +0000 |
parents | d12a63a8d95a |
children | 604d73db6802 |
comparison
equal
deleted
inserted
replaced
1335:c39265384763 | 1336:3692456e7b0f |
---|---|
43 | 43 |
44 #ifdef HAVE_ALLOCA | 44 #ifdef HAVE_ALLOCA |
45 #define ALLOCA(n) ((void*)alloca(n)) | 45 #define ALLOCA(n) ((void*)alloca(n)) |
46 #define FREEA(p) | 46 #define FREEA(p) |
47 #else | 47 #else |
48 #define ALLOCA(n) malloc(n) | 48 #define ALLOCA(n) SDL_malloc(n) |
49 #define FREEA(p) free(p) | 49 #define FREEA(p) SDL_free(p) |
50 #endif | 50 #endif |
51 | 51 |
52 #include "SDL.h" | 52 #include "SDL.h" |
53 #include "SDL_error.h" | 53 #include "SDL_error.h" |
54 #include "SDL_timer.h" | 54 #include "SDL_timer.h" |
98 | 98 |
99 static void X11_DeleteDevice(SDL_VideoDevice *device) | 99 static void X11_DeleteDevice(SDL_VideoDevice *device) |
100 { | 100 { |
101 if ( device ) { | 101 if ( device ) { |
102 if ( device->hidden ) { | 102 if ( device->hidden ) { |
103 free(device->hidden); | 103 SDL_free(device->hidden); |
104 } | 104 } |
105 if ( device->gl_data ) { | 105 if ( device->gl_data ) { |
106 free(device->gl_data); | 106 SDL_free(device->gl_data); |
107 } | 107 } |
108 free(device); | 108 SDL_free(device); |
109 SDL_X11_UnloadSymbols(); | 109 SDL_X11_UnloadSymbols(); |
110 } | 110 } |
111 } | 111 } |
112 | 112 |
113 static SDL_VideoDevice *X11_CreateDevice(int devindex) | 113 static SDL_VideoDevice *X11_CreateDevice(int devindex) |
114 { | 114 { |
115 SDL_VideoDevice *device = NULL; | 115 SDL_VideoDevice *device = NULL; |
116 | 116 |
117 if ( SDL_X11_LoadSymbols() ) { | 117 if ( SDL_X11_LoadSymbols() ) { |
118 /* Initialize all variables that we clean on shutdown */ | 118 /* Initialize all variables that we clean on shutdown */ |
119 device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice)); | 119 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); |
120 if ( device ) { | 120 if ( device ) { |
121 memset(device, 0, (sizeof *device)); | 121 SDL_memset(device, 0, (sizeof *device)); |
122 device->hidden = (struct SDL_PrivateVideoData *) | 122 device->hidden = (struct SDL_PrivateVideoData *) |
123 malloc((sizeof *device->hidden)); | 123 SDL_malloc((sizeof *device->hidden)); |
124 device->gl_data = (struct SDL_PrivateGLData *) | 124 device->gl_data = (struct SDL_PrivateGLData *) |
125 malloc((sizeof *device->gl_data)); | 125 SDL_malloc((sizeof *device->gl_data)); |
126 } | 126 } |
127 if ( (device == NULL) || (device->hidden == NULL) || | 127 if ( (device == NULL) || (device->hidden == NULL) || |
128 (device->gl_data == NULL) ) { | 128 (device->gl_data == NULL) ) { |
129 SDL_OutOfMemory(); | 129 SDL_OutOfMemory(); |
130 X11_DeleteDevice(device); /* calls SDL_X11_UnloadSymbols(). */ | 130 X11_DeleteDevice(device); /* calls SDL_X11_UnloadSymbols(). */ |
131 return(0); | 131 return(0); |
132 } | 132 } |
133 memset(device->hidden, 0, (sizeof *device->hidden)); | 133 SDL_memset(device->hidden, 0, (sizeof *device->hidden)); |
134 memset(device->gl_data, 0, (sizeof *device->gl_data)); | 134 SDL_memset(device->gl_data, 0, (sizeof *device->gl_data)); |
135 | 135 |
136 /* Set the driver flags */ | 136 /* Set the driver flags */ |
137 device->handles_any_size = 1; | 137 device->handles_any_size = 1; |
138 | 138 |
139 /* Set the function pointers */ | 139 /* Set the function pointers */ |
264 printf("Xext error inside SDL (may be harmless):\n"); | 264 printf("Xext error inside SDL (may be harmless):\n"); |
265 printf(" Extension \"%s\" %s on display \"%s\".\n", | 265 printf(" Extension \"%s\" %s on display \"%s\".\n", |
266 ext_name, reason, pXDisplayString(d)); | 266 ext_name, reason, pXDisplayString(d)); |
267 #endif | 267 #endif |
268 | 268 |
269 if (strcmp(reason, "missing") == 0) { | 269 if (SDL_strcmp(reason, "missing") == 0) { |
270 /* | 270 /* |
271 * Since the query itself, elsewhere, can handle a missing extension | 271 * Since the query itself, elsewhere, can handle a missing extension |
272 * and the default behaviour in Xlib is to write to stderr, which | 272 * and the default behaviour in Xlib is to write to stderr, which |
273 * generates unnecessary bug reports, we just ignore these. | 273 * generates unnecessary bug reports, we just ignore these. |
274 */ | 274 */ |
288 char linkfile[1024]; | 288 char linkfile[1024]; |
289 int linksize; | 289 int linksize; |
290 #endif | 290 #endif |
291 | 291 |
292 /* First allow environment variable override */ | 292 /* First allow environment variable override */ |
293 spot = getenv("SDL_VIDEO_X11_WMCLASS"); | 293 spot = SDL_getenv("SDL_VIDEO_X11_WMCLASS"); |
294 if ( spot ) { | 294 if ( spot ) { |
295 strncpy(classname, spot, maxlen); | 295 SDL_strncpy(classname, spot, maxlen); |
296 return classname; | 296 return classname; |
297 } | 297 } |
298 | 298 |
299 /* Next look at the application's executable name */ | 299 /* Next look at the application's executable name */ |
300 #if defined(linux) || defined(__FreeBSD__) | 300 #if defined(linux) || defined(__FreeBSD__) |
306 #error Where can we find the executable name? | 306 #error Where can we find the executable name? |
307 #endif | 307 #endif |
308 linksize = readlink(procfile, linkfile, sizeof(linkfile)-1); | 308 linksize = readlink(procfile, linkfile, sizeof(linkfile)-1); |
309 if ( linksize > 0 ) { | 309 if ( linksize > 0 ) { |
310 linkfile[linksize] = '\0'; | 310 linkfile[linksize] = '\0'; |
311 spot = strrchr(linkfile, '/'); | 311 spot = SDL_strrchr(linkfile, '/'); |
312 if ( spot ) { | 312 if ( spot ) { |
313 strncpy(classname, spot+1, maxlen); | 313 SDL_strncpy(classname, spot+1, maxlen); |
314 } else { | 314 } else { |
315 strncpy(classname, linkfile, maxlen); | 315 SDL_strncpy(classname, linkfile, maxlen); |
316 } | 316 } |
317 return classname; | 317 return classname; |
318 } | 318 } |
319 #endif /* linux */ | 319 #endif /* linux */ |
320 | 320 |
321 /* Finally use the default we've used forever */ | 321 /* Finally use the default we've used forever */ |
322 strncpy(classname, "SDL_App", maxlen); | 322 SDL_strncpy(classname, "SDL_App", maxlen); |
323 return classname; | 323 return classname; |
324 } | 324 } |
325 | 325 |
326 /* Create auxiliary (toplevel) windows with the current visual */ | 326 /* Create auxiliary (toplevel) windows with the current visual */ |
327 static void create_aux_windows(_THIS) | 327 static void create_aux_windows(_THIS) |
333 int def_vis = (SDL_Visual == DefaultVisual(SDL_Display, SDL_Screen)); | 333 int def_vis = (SDL_Visual == DefaultVisual(SDL_Display, SDL_Screen)); |
334 | 334 |
335 /* Don't create any extra windows if we are being managed */ | 335 /* Don't create any extra windows if we are being managed */ |
336 if ( SDL_windowid ) { | 336 if ( SDL_windowid ) { |
337 FSwindow = 0; | 337 FSwindow = 0; |
338 WMwindow = strtol(SDL_windowid, NULL, 0); | 338 WMwindow = SDL_strtol(SDL_windowid, NULL, 0); |
339 return; | 339 return; |
340 } | 340 } |
341 | 341 |
342 if(FSwindow) | 342 if(FSwindow) |
343 pXDestroyWindow(SDL_Display, FSwindow); | 343 pXDestroyWindow(SDL_Display, FSwindow); |
359 /* Tell KDE to keep the fullscreen window on top */ | 359 /* Tell KDE to keep the fullscreen window on top */ |
360 { | 360 { |
361 XEvent ev; | 361 XEvent ev; |
362 long mask; | 362 long mask; |
363 | 363 |
364 memset(&ev, 0, sizeof(ev)); | 364 SDL_memset(&ev, 0, sizeof(ev)); |
365 ev.xclient.type = ClientMessage; | 365 ev.xclient.type = ClientMessage; |
366 ev.xclient.window = SDL_Root; | 366 ev.xclient.window = SDL_Root; |
367 ev.xclient.message_type = pXInternAtom(SDL_Display, | 367 ev.xclient.message_type = pXInternAtom(SDL_Display, |
368 "KWM_KEEP_ON_TOP", False); | 368 "KWM_KEEP_ON_TOP", False); |
369 ev.xclient.format = 32; | 369 ev.xclient.format = 32; |
459 int i; | 459 int i; |
460 | 460 |
461 /* Open the X11 display */ | 461 /* Open the X11 display */ |
462 display = NULL; /* Get it from DISPLAY environment variable */ | 462 display = NULL; /* Get it from DISPLAY environment variable */ |
463 | 463 |
464 if ( (strncmp(pXDisplayName(display), ":", 1) == 0) || | 464 if ( (SDL_strncmp(pXDisplayName(display), ":", 1) == 0) || |
465 (strncmp(pXDisplayName(display), "unix:", 5) == 0) ) { | 465 (SDL_strncmp(pXDisplayName(display), "unix:", 5) == 0) ) { |
466 local_X11 = 1; | 466 local_X11 = 1; |
467 } else { | 467 } else { |
468 local_X11 = 0; | 468 local_X11 = 0; |
469 } | 469 } |
470 SDL_Display = pXOpenDisplay(display); | 470 SDL_Display = pXOpenDisplay(display); |
550 vformat->Bmask = SDL_Visual->blue_mask; | 550 vformat->Bmask = SDL_Visual->blue_mask; |
551 } | 551 } |
552 X11_SaveVidModeGamma(this); | 552 X11_SaveVidModeGamma(this); |
553 | 553 |
554 /* See if we have been passed a window to use */ | 554 /* See if we have been passed a window to use */ |
555 SDL_windowid = getenv("SDL_WINDOWID"); | 555 SDL_windowid = SDL_getenv("SDL_WINDOWID"); |
556 | 556 |
557 /* Create the fullscreen and managed windows */ | 557 /* Create the fullscreen and managed windows */ |
558 create_aux_windows(this); | 558 create_aux_windows(this); |
559 | 559 |
560 /* Create the blank cursor */ | 560 /* Create the blank cursor */ |
603 pXFreeColors(GFX_Display, | 603 pXFreeColors(GFX_Display, |
604 SDL_DisplayColormap,&pixel,1,0); | 604 SDL_DisplayColormap,&pixel,1,0); |
605 --SDL_XPixels[pixel]; | 605 --SDL_XPixels[pixel]; |
606 } | 606 } |
607 } | 607 } |
608 free(SDL_XPixels); | 608 SDL_free(SDL_XPixels); |
609 SDL_XPixels = NULL; | 609 SDL_XPixels = NULL; |
610 } | 610 } |
611 | 611 |
612 /* Free the graphics context */ | 612 /* Free the graphics context */ |
613 if ( SDL_GC ) { | 613 if ( SDL_GC ) { |
617 } | 617 } |
618 } | 618 } |
619 | 619 |
620 static SDL_bool X11_WindowPosition(_THIS, int *x, int *y, int w, int h) | 620 static SDL_bool X11_WindowPosition(_THIS, int *x, int *y, int w, int h) |
621 { | 621 { |
622 const char *window = getenv("SDL_VIDEO_WINDOW_POS"); | 622 const char *window = SDL_getenv("SDL_VIDEO_WINDOW_POS"); |
623 const char *center = getenv("SDL_VIDEO_CENTERED"); | 623 const char *center = SDL_getenv("SDL_VIDEO_CENTERED"); |
624 if ( window ) { | 624 if ( window ) { |
625 if ( sscanf(window, "%d,%d", x, y) == 2 ) { | 625 if ( SDL_sscanf(window, "%d,%d", x, y) == 2 ) { |
626 return SDL_TRUE; | 626 return SDL_TRUE; |
627 } | 627 } |
628 if ( strcmp(window, "center") == 0 ) { | 628 if ( SDL_strcmp(window, "center") == 0 ) { |
629 center = window; | 629 center = window; |
630 } | 630 } |
631 } | 631 } |
632 if ( center ) { | 632 if ( center ) { |
633 *x = (DisplayWidth(SDL_Display, SDL_Screen) - w)/2; | 633 *x = (DisplayWidth(SDL_Display, SDL_Screen) - w)/2; |
771 switch_waiting = 0; /* Prevent jump back to now-meaningless state. */ | 771 switch_waiting = 0; /* Prevent jump back to now-meaningless state. */ |
772 } | 772 } |
773 | 773 |
774 /* See if we have been given a window id */ | 774 /* See if we have been given a window id */ |
775 if ( SDL_windowid ) { | 775 if ( SDL_windowid ) { |
776 SDL_Window = strtol(SDL_windowid, NULL, 0); | 776 SDL_Window = SDL_strtol(SDL_windowid, NULL, 0); |
777 } else { | 777 } else { |
778 SDL_Window = 0; | 778 SDL_Window = 0; |
779 } | 779 } |
780 | 780 |
781 /* find out which visual we are going to use */ | 781 /* find out which visual we are going to use */ |
825 if ( SDL_Visual->class == PseudoColor ) { | 825 if ( SDL_Visual->class == PseudoColor ) { |
826 int ncolors; | 826 int ncolors; |
827 | 827 |
828 /* Allocate the pixel flags */ | 828 /* Allocate the pixel flags */ |
829 ncolors = SDL_Visual->map_entries; | 829 ncolors = SDL_Visual->map_entries; |
830 SDL_XPixels = malloc(ncolors * sizeof(int)); | 830 SDL_XPixels = SDL_malloc(ncolors * sizeof(int)); |
831 if(SDL_XPixels == NULL) { | 831 if(SDL_XPixels == NULL) { |
832 SDL_OutOfMemory(); | 832 SDL_OutOfMemory(); |
833 return -1; | 833 return -1; |
834 } | 834 } |
835 memset(SDL_XPixels, 0, ncolors * sizeof(*SDL_XPixels)); | 835 SDL_memset(SDL_XPixels, 0, ncolors * sizeof(*SDL_XPixels)); |
836 | 836 |
837 /* always allocate a private colormap on non-default visuals */ | 837 /* always allocate a private colormap on non-default visuals */ |
838 if ( SDL_Visual != DefaultVisual(SDL_Display, SDL_Screen) ) { | 838 if ( SDL_Visual != DefaultVisual(SDL_Display, SDL_Screen) ) { |
839 flags |= SDL_HWPALETTE; | 839 flags |= SDL_HWPALETTE; |
840 } | 840 } |
935 pXSetWindowColormap(SDL_Display, WMwindow, SDL_XColorMap); | 935 pXSetWindowColormap(SDL_Display, WMwindow, SDL_XColorMap); |
936 } | 936 } |
937 } | 937 } |
938 | 938 |
939 #if 0 /* This is an experiment - are the graphics faster now? - nope. */ | 939 #if 0 /* This is an experiment - are the graphics faster now? - nope. */ |
940 if ( getenv("SDL_VIDEO_X11_BACKINGSTORE") ) | 940 if ( SDL_getenv("SDL_VIDEO_X11_BACKINGSTORE") ) |
941 #endif | 941 #endif |
942 /* Cache the window in the server, when possible */ | 942 /* Cache the window in the server, when possible */ |
943 { | 943 { |
944 Screen *xscreen; | 944 Screen *xscreen; |
945 XSetWindowAttributes a; | 945 XSetWindowAttributes a; |
1257 pXFreeColors(GFX_Display, SDL_XColorMap, freelist, nfree, 0); | 1257 pXFreeColors(GFX_Display, SDL_XColorMap, freelist, nfree, 0); |
1258 FREEA(freelist); | 1258 FREEA(freelist); |
1259 | 1259 |
1260 want = ALLOCA(ncolors * sizeof(SDL_Color)); | 1260 want = ALLOCA(ncolors * sizeof(SDL_Color)); |
1261 reject = ALLOCA(ncolors * sizeof(SDL_Color)); | 1261 reject = ALLOCA(ncolors * sizeof(SDL_Color)); |
1262 memcpy(want, colors + firstcolor, ncolors * sizeof(SDL_Color)); | 1262 SDL_memcpy(want, colors + firstcolor, ncolors * sizeof(SDL_Color)); |
1263 /* make sure the user isn't fooled by her own wishes | 1263 /* make sure the user isn't fooled by her own wishes |
1264 (black is safe, always available in the default colormap) */ | 1264 (black is safe, always available in the default colormap) */ |
1265 memset(colors + firstcolor, 0, ncolors * sizeof(SDL_Color)); | 1265 SDL_memset(colors + firstcolor, 0, ncolors * sizeof(SDL_Color)); |
1266 | 1266 |
1267 /* now try to allocate the colours */ | 1267 /* now try to allocate the colours */ |
1268 for(i = 0; i < ncolors; i++) { | 1268 for(i = 0; i < ncolors; i++) { |
1269 XColor col; | 1269 XColor col; |
1270 col.red = want[i].r << 8; | 1270 col.red = want[i].r << 8; |
1359 pXFreeColors(GFX_Display, | 1359 pXFreeColors(GFX_Display, |
1360 dcmap, &pixel, 1, 0); | 1360 dcmap, &pixel, 1, 0); |
1361 --SDL_iconcolors[pixel]; | 1361 --SDL_iconcolors[pixel]; |
1362 } | 1362 } |
1363 } | 1363 } |
1364 free(SDL_iconcolors); | 1364 SDL_free(SDL_iconcolors); |
1365 SDL_iconcolors = NULL; | 1365 SDL_iconcolors = NULL; |
1366 } | 1366 } |
1367 /* Restore gamma settings if they've changed */ | 1367 /* Restore gamma settings if they've changed */ |
1368 if ( SDL_GetAppState() & SDL_APPACTIVE ) { | 1368 if ( SDL_GetAppState() & SDL_APPACTIVE ) { |
1369 X11_SwapVidModeGamma(this); | 1369 X11_SwapVidModeGamma(this); |