Mercurial > sdl-ios-xcode
comparison src/video/x11/SDL_x11wm.c @ 1168:045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
This allows you to run an SDL program on a system without Xlib, since it'll
just report the x11 target unavailable at runtime.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sat, 05 Nov 2005 19:53:37 +0000 |
parents | 3acd16ea0180 |
children | c9b51268668f |
comparison
equal
deleted
inserted
replaced
1167:435c2e481299 | 1168:045f186426e1 |
---|---|
121 while(SDL_iconcolors[i]) { | 121 while(SDL_iconcolors[i]) { |
122 freelist[nfree++] = i; | 122 freelist[nfree++] = i; |
123 SDL_iconcolors[i]--; | 123 SDL_iconcolors[i]--; |
124 } | 124 } |
125 } | 125 } |
126 XFreeColors(GFX_Display, dcmap, freelist, nfree, 0); | 126 pXFreeColors(GFX_Display, dcmap, freelist, nfree, 0); |
127 } | 127 } |
128 if(!SDL_iconcolors) | 128 if(!SDL_iconcolors) |
129 SDL_iconcolors = malloc(256 * sizeof *SDL_iconcolors); | 129 SDL_iconcolors = malloc(256 * sizeof *SDL_iconcolors); |
130 memset(SDL_iconcolors, 0, 256 * sizeof *SDL_iconcolors); | 130 memset(SDL_iconcolors, 0, 256 * sizeof *SDL_iconcolors); |
131 | 131 |
136 XColor c; | 136 XColor c; |
137 c.red = want[i].r << 8; | 137 c.red = want[i].r << 8; |
138 c.green = want[i].g << 8; | 138 c.green = want[i].g << 8; |
139 c.blue = want[i].b << 8; | 139 c.blue = want[i].b << 8; |
140 c.flags = DoRed | DoGreen | DoBlue; | 140 c.flags = DoRed | DoGreen | DoBlue; |
141 if(XAllocColor(GFX_Display, dcmap, &c)) { | 141 if(pXAllocColor(GFX_Display, dcmap, &c)) { |
142 /* got the colour */ | 142 /* got the colour */ |
143 SDL_iconcolors[c.pixel]++; | 143 SDL_iconcolors[c.pixel]++; |
144 got[c.pixel] = want[i]; | 144 got[c.pixel] = want[i]; |
145 } else { | 145 } else { |
146 missing = 1; | 146 missing = 1; |
150 /* Some colours were apparently missing, so we just | 150 /* Some colours were apparently missing, so we just |
151 allocate all the rest as well */ | 151 allocate all the rest as well */ |
152 XColor cols[256]; | 152 XColor cols[256]; |
153 for(i = 0; i < 256; i++) | 153 for(i = 0; i < 256; i++) |
154 cols[i].pixel = i; | 154 cols[i].pixel = i; |
155 XQueryColors(GFX_Display, dcmap, cols, 256); | 155 pXQueryColors(GFX_Display, dcmap, cols, 256); |
156 for(i = 0; i < 256; i++) { | 156 for(i = 0; i < 256; i++) { |
157 got[i].r = cols[i].red >> 8; | 157 got[i].r = cols[i].red >> 8; |
158 got[i].g = cols[i].green >> 8; | 158 got[i].g = cols[i].green >> 8; |
159 got[i].b = cols[i].blue >> 8; | 159 got[i].b = cols[i].blue >> 8; |
160 if(!SDL_iconcolors[i]) { | 160 if(!SDL_iconcolors[i]) { |
161 if(XAllocColor(GFX_Display, dcmap, | 161 if(pXAllocColor(GFX_Display, dcmap, |
162 cols + i)) { | 162 cols + i)) { |
163 SDL_iconcolors[i] = 1; | 163 SDL_iconcolors[i] = 1; |
164 } else { | 164 } else { |
165 /* index not available */ | 165 /* index not available */ |
166 got[i].r = 0; | 166 got[i].r = 0; |
189 goto done; | 189 goto done; |
190 } | 190 } |
191 memset(LSBmask, 0, masksize); | 191 memset(LSBmask, 0, masksize); |
192 for(i = 0; i < masksize; i++) | 192 for(i = 0; i < masksize; i++) |
193 LSBmask[i] = reverse_byte(mask[i]); | 193 LSBmask[i] = reverse_byte(mask[i]); |
194 mask_pixmap = XCreatePixmapFromBitmapData(SDL_Display, WMwindow, | 194 mask_pixmap = pXCreatePixmapFromBitmapData(SDL_Display, WMwindow, |
195 (char *)LSBmask, | 195 (char *)LSBmask, |
196 sicon->w, sicon->h, | 196 sicon->w, sicon->h, |
197 1L, 0L, 1); | 197 1L, 0L, 1); |
198 | 198 |
199 /* Transfer the image to an X11 pixmap */ | 199 /* Transfer the image to an X11 pixmap */ |
200 icon_image = XCreateImage(SDL_Display, | 200 icon_image = pXCreateImage(SDL_Display, |
201 DefaultVisual(SDL_Display, SDL_Screen), | 201 DefaultVisual(SDL_Display, SDL_Screen), |
202 DefaultDepth(SDL_Display, SDL_Screen), | 202 DefaultDepth(SDL_Display, SDL_Screen), |
203 ZPixmap, 0, sicon->pixels, | 203 ZPixmap, 0, sicon->pixels, |
204 sicon->w, sicon->h, | 204 sicon->w, sicon->h, |
205 32, 0); | 205 32, 0); |
206 icon_image->byte_order = (SDL_BYTEORDER == SDL_BIG_ENDIAN) | 206 icon_image->byte_order = (SDL_BYTEORDER == SDL_BIG_ENDIAN) |
207 ? MSBFirst : LSBFirst; | 207 ? MSBFirst : LSBFirst; |
208 icon_pixmap = XCreatePixmap(SDL_Display, SDL_Root, sicon->w, sicon->h, | 208 icon_pixmap = pXCreatePixmap(SDL_Display, SDL_Root, sicon->w, sicon->h, |
209 DefaultDepth(SDL_Display, SDL_Screen)); | 209 DefaultDepth(SDL_Display, SDL_Screen)); |
210 gc = XCreateGC(SDL_Display, icon_pixmap, 0, &GCvalues); | 210 gc = pXCreateGC(SDL_Display, icon_pixmap, 0, &GCvalues); |
211 XPutImage(SDL_Display, icon_pixmap, gc, icon_image, | 211 pXPutImage(SDL_Display, icon_pixmap, gc, icon_image, |
212 0, 0, 0, 0, sicon->w, sicon->h); | 212 0, 0, 0, 0, sicon->w, sicon->h); |
213 XFreeGC(SDL_Display, gc); | 213 pXFreeGC(SDL_Display, gc); |
214 XDestroyImage(icon_image); | 214 pXDestroyImage(icon_image); |
215 free(LSBmask); | 215 free(LSBmask); |
216 sicon->pixels = NULL; | 216 sicon->pixels = NULL; |
217 | 217 |
218 /* Some buggy window managers (some versions of Enlightenment, it | 218 /* Some buggy window managers (some versions of Enlightenment, it |
219 seems) need an icon window *and* icon pixmap to work properly, while | 219 seems) need an icon window *and* icon pixmap to work properly, while |
220 it screws up others. The default is only to use a pixmap. */ | 220 it screws up others. The default is only to use a pixmap. */ |
221 p = getenv("SDL_VIDEO_X11_ICONWIN"); | 221 p = getenv("SDL_VIDEO_X11_ICONWIN"); |
222 if(p && *p) { | 222 if(p && *p) { |
223 icon_window = XCreateSimpleWindow(SDL_Display, SDL_Root, | 223 icon_window = pXCreateSimpleWindow(SDL_Display, SDL_Root, |
224 0, 0, sicon->w, sicon->h, 0, | 224 0, 0, sicon->w, sicon->h, 0, |
225 CopyFromParent, | 225 CopyFromParent, |
226 CopyFromParent); | 226 CopyFromParent); |
227 XSetWindowBackgroundPixmap(SDL_Display, icon_window, | 227 pXSetWindowBackgroundPixmap(SDL_Display, icon_window, |
228 icon_pixmap); | 228 icon_pixmap); |
229 XClearWindow(SDL_Display, icon_window); | 229 pXClearWindow(SDL_Display, icon_window); |
230 } | 230 } |
231 | 231 |
232 /* Set the window icon to the icon pixmap (and icon window) */ | 232 /* Set the window icon to the icon pixmap (and icon window) */ |
233 wmhints = XAllocWMHints(); | 233 wmhints = pXAllocWMHints(); |
234 wmhints->flags = (IconPixmapHint | IconMaskHint); | 234 wmhints->flags = (IconPixmapHint | IconMaskHint); |
235 wmhints->icon_pixmap = icon_pixmap; | 235 wmhints->icon_pixmap = icon_pixmap; |
236 wmhints->icon_mask = mask_pixmap; | 236 wmhints->icon_mask = mask_pixmap; |
237 if(icon_window != None) { | 237 if(icon_window != None) { |
238 wmhints->flags |= IconWindowHint; | 238 wmhints->flags |= IconWindowHint; |
239 wmhints->icon_window = icon_window; | 239 wmhints->icon_window = icon_window; |
240 } | 240 } |
241 XSetWMHints(SDL_Display, WMwindow, wmhints); | 241 pXSetWMHints(SDL_Display, WMwindow, wmhints); |
242 XFree(wmhints); | 242 pXFree(wmhints); |
243 XSync(SDL_Display, False); | 243 pXSync(SDL_Display, False); |
244 | 244 |
245 done: | 245 done: |
246 SDL_Unlock_EventThread(); | 246 SDL_Unlock_EventThread(); |
247 SDL_FreeSurface(sicon); | 247 SDL_FreeSurface(sicon); |
248 } | 248 } |
255 SDL_Lock_EventThread(); | 255 SDL_Lock_EventThread(); |
256 | 256 |
257 if ( title != NULL ) { | 257 if ( title != NULL ) { |
258 int error = XLocaleNotSupported; | 258 int error = XLocaleNotSupported; |
259 #ifdef X_HAVE_UTF8_STRING | 259 #ifdef X_HAVE_UTF8_STRING |
260 error = Xutf8TextListToTextProperty(SDL_Display, | 260 error = pXutf8TextListToTextProperty(SDL_Display, |
261 (char **)&title, 1, XUTF8StringStyle, | 261 (char **)&title, 1, XUTF8StringStyle, |
262 &titleprop); | 262 &titleprop); |
263 #endif | 263 #endif |
264 if ( error != Success ) { | 264 if ( error != Success ) { |
265 XStringListToTextProperty((char **)&title, 1, | 265 pXStringListToTextProperty((char **)&title, 1, |
266 &titleprop); | 266 &titleprop); |
267 } | 267 } |
268 XSetWMName(SDL_Display, WMwindow, &titleprop); | 268 pXSetWMName(SDL_Display, WMwindow, &titleprop); |
269 XFree(titleprop.value); | 269 pXFree(titleprop.value); |
270 } | 270 } |
271 if ( icon != NULL ) { | 271 if ( icon != NULL ) { |
272 int error = XLocaleNotSupported; | 272 int error = XLocaleNotSupported; |
273 #ifdef X_HAVE_UTF8_STRING | 273 #ifdef X_HAVE_UTF8_STRING |
274 error = Xutf8TextListToTextProperty(SDL_Display, | 274 error = pXutf8TextListToTextProperty(SDL_Display, |
275 (char **)&icon, 1, XUTF8StringStyle, &iconprop); | 275 (char **)&icon, 1, XUTF8StringStyle, &iconprop); |
276 #endif | 276 #endif |
277 if ( error != Success ) { | 277 if ( error != Success ) { |
278 XStringListToTextProperty((char **)&icon, 1, &iconprop); | 278 pXStringListToTextProperty((char **)&icon, 1, &iconprop); |
279 } | 279 } |
280 XSetWMIconName(SDL_Display, WMwindow, &iconprop); | 280 pXSetWMIconName(SDL_Display, WMwindow, &iconprop); |
281 XFree(iconprop.value); | 281 pXFree(iconprop.value); |
282 } | 282 } |
283 XSync(SDL_Display, False); | 283 pXSync(SDL_Display, False); |
284 | 284 |
285 SDL_Unlock_EventThread(); | 285 SDL_Unlock_EventThread(); |
286 } | 286 } |
287 | 287 |
288 /* Iconify the window */ | 288 /* Iconify the window */ |
289 int X11_IconifyWindow(_THIS) | 289 int X11_IconifyWindow(_THIS) |
290 { | 290 { |
291 int result; | 291 int result; |
292 | 292 |
293 SDL_Lock_EventThread(); | 293 SDL_Lock_EventThread(); |
294 result = XIconifyWindow(SDL_Display, WMwindow, SDL_Screen); | 294 result = pXIconifyWindow(SDL_Display, WMwindow, SDL_Screen); |
295 XSync(SDL_Display, False); | 295 pXSync(SDL_Display, False); |
296 SDL_Unlock_EventThread(); | 296 SDL_Unlock_EventThread(); |
297 return(result); | 297 return(result); |
298 } | 298 } |
299 | 299 |
300 SDL_GrabMode X11_GrabInputNoLock(_THIS, SDL_GrabMode mode) | 300 SDL_GrabMode X11_GrabInputNoLock(_THIS, SDL_GrabMode mode) |
306 } | 306 } |
307 if ( ! SDL_Window ) { | 307 if ( ! SDL_Window ) { |
308 return(mode); /* Will be set later on mode switch */ | 308 return(mode); /* Will be set later on mode switch */ |
309 } | 309 } |
310 if ( mode == SDL_GRAB_OFF ) { | 310 if ( mode == SDL_GRAB_OFF ) { |
311 XUngrabPointer(SDL_Display, CurrentTime); | 311 pXUngrabPointer(SDL_Display, CurrentTime); |
312 XUngrabKeyboard(SDL_Display, CurrentTime); | 312 pXUngrabKeyboard(SDL_Display, CurrentTime); |
313 } else { | 313 } else { |
314 if ( this->screen->flags & SDL_FULLSCREEN ) { | 314 if ( this->screen->flags & SDL_FULLSCREEN ) { |
315 /* Unbind the mouse from the fullscreen window */ | 315 /* Unbind the mouse from the fullscreen window */ |
316 XUngrabPointer(SDL_Display, CurrentTime); | 316 pXUngrabPointer(SDL_Display, CurrentTime); |
317 } | 317 } |
318 /* Try to grab the mouse */ | 318 /* Try to grab the mouse */ |
319 #if 0 /* We'll wait here until we actually grab, otherwise behavior undefined */ | 319 #if 0 /* We'll wait here until we actually grab, otherwise behavior undefined */ |
320 for ( numtries = 0; numtries < 10; ++numtries ) { | 320 for ( numtries = 0; numtries < 10; ++numtries ) { |
321 #else | 321 #else |
322 while ( 1 ) { | 322 while ( 1 ) { |
323 #endif | 323 #endif |
324 result = XGrabPointer(SDL_Display, SDL_Window, True, 0, | 324 result = pXGrabPointer(SDL_Display, SDL_Window, True, 0, |
325 GrabModeAsync, GrabModeAsync, | 325 GrabModeAsync, GrabModeAsync, |
326 SDL_Window, None, CurrentTime); | 326 SDL_Window, None, CurrentTime); |
327 if ( result == GrabSuccess ) { | 327 if ( result == GrabSuccess ) { |
328 break; | 328 break; |
329 } | 329 } |
331 } | 331 } |
332 if ( result != GrabSuccess ) { | 332 if ( result != GrabSuccess ) { |
333 /* Uh, oh, what do we do here? */ ; | 333 /* Uh, oh, what do we do here? */ ; |
334 } | 334 } |
335 /* Now grab the keyboard */ | 335 /* Now grab the keyboard */ |
336 XGrabKeyboard(SDL_Display, WMwindow, True, | 336 pXGrabKeyboard(SDL_Display, WMwindow, True, |
337 GrabModeAsync, GrabModeAsync, CurrentTime); | 337 GrabModeAsync, GrabModeAsync, CurrentTime); |
338 | 338 |
339 /* Raise the window if we grab the mouse */ | 339 /* Raise the window if we grab the mouse */ |
340 if ( !(this->screen->flags & SDL_FULLSCREEN) ) | 340 if ( !(this->screen->flags & SDL_FULLSCREEN) ) |
341 XRaiseWindow(SDL_Display, WMwindow); | 341 pXRaiseWindow(SDL_Display, WMwindow); |
342 | 342 |
343 /* Make sure we register input focus */ | 343 /* Make sure we register input focus */ |
344 SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS); | 344 SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS); |
345 } | 345 } |
346 XSync(SDL_Display, False); | 346 pXSync(SDL_Display, False); |
347 | 347 |
348 return(mode); | 348 return(mode); |
349 } | 349 } |
350 | 350 |
351 SDL_GrabMode X11_GrabInput(_THIS, SDL_GrabMode mode) | 351 SDL_GrabMode X11_GrabInput(_THIS, SDL_GrabMode mode) |
366 } | 366 } |
367 static void unlock_display(void) | 367 static void unlock_display(void) |
368 { | 368 { |
369 /* Make sure any X11 transactions are completed */ | 369 /* Make sure any X11 transactions are completed */ |
370 SDL_VideoDevice *this = current_video; | 370 SDL_VideoDevice *this = current_video; |
371 XSync(SDL_Display, False); | 371 pXSync(SDL_Display, False); |
372 SDL_Unlock_EventThread(); | 372 SDL_Unlock_EventThread(); |
373 } | 373 } |
374 int X11_GetWMInfo(_THIS, SDL_SysWMinfo *info) | 374 int X11_GetWMInfo(_THIS, SDL_SysWMinfo *info) |
375 { | 375 { |
376 if ( info->version.major <= SDL_MAJOR_VERSION ) { | 376 if ( info->version.major <= SDL_MAJOR_VERSION ) { |