comparison src/video/x11/SDL_x11wm.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents 14717b52abc0
children 4da1ee79c9af
comparison
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
31 #include "../SDL_pixels_c.h" 31 #include "../SDL_pixels_c.h"
32 #include "../../events/SDL_events_c.h" 32 #include "../../events/SDL_events_c.h"
33 #include "SDL_x11modes_c.h" 33 #include "SDL_x11modes_c.h"
34 #include "SDL_x11wm_c.h" 34 #include "SDL_x11wm_c.h"
35 35
36 static Uint8 reverse_byte(Uint8 x) 36 static Uint8
37 { 37 reverse_byte (Uint8 x)
38 x = (x & 0xaa) >> 1 | (x & 0x55) << 1; 38 {
39 x = (x & 0xcc) >> 2 | (x & 0x33) << 2; 39 x = (x & 0xaa) >> 1 | (x & 0x55) << 1;
40 x = (x & 0xf0) >> 4 | (x & 0x0f) << 4; 40 x = (x & 0xcc) >> 2 | (x & 0x33) << 2;
41 return x; 41 x = (x & 0xf0) >> 4 | (x & 0x0f) << 4;
42 } 42 return x;
43 43 }
44 void X11_SetIcon(_THIS, SDL_Surface *icon, Uint8 *mask) 44
45 { 45 void
46 SDL_Surface *sicon; 46 X11_SetIcon (_THIS, SDL_Surface * icon, Uint8 * mask)
47 XWMHints *wmhints; 47 {
48 XImage *icon_image; 48 SDL_Surface *sicon;
49 Pixmap icon_pixmap; 49 XWMHints *wmhints;
50 Pixmap mask_pixmap; 50 XImage *icon_image;
51 Window icon_window = None; 51 Pixmap icon_pixmap;
52 GC gc; 52 Pixmap mask_pixmap;
53 XGCValues GCvalues; 53 Window icon_window = None;
54 int i, dbpp; 54 GC gc;
55 SDL_Rect bounds; 55 XGCValues GCvalues;
56 Uint8 *LSBmask; 56 int i, dbpp;
57 Visual *dvis; 57 SDL_Rect bounds;
58 char *p; 58 Uint8 *LSBmask;
59 int masksize; 59 Visual *dvis;
60 60 char *p;
61 SDL_Lock_EventThread(); 61 int masksize;
62 62
63 /* The icon must use the default visual, depth and colormap of the 63 SDL_Lock_EventThread ();
64 screen, so it might need a conversion */ 64
65 dvis = DefaultVisual(SDL_Display, SDL_Screen); 65 /* The icon must use the default visual, depth and colormap of the
66 dbpp = DefaultDepth(SDL_Display, SDL_Screen); 66 screen, so it might need a conversion */
67 for(i = 0; i < this->hidden->nvisuals; i++) { 67 dvis = DefaultVisual (SDL_Display, SDL_Screen);
68 if(this->hidden->visuals[i].visual == dvis) { 68 dbpp = DefaultDepth (SDL_Display, SDL_Screen);
69 dbpp = this->hidden->visuals[i].bpp; 69 for (i = 0; i < this->hidden->nvisuals; i++) {
70 break; 70 if (this->hidden->visuals[i].visual == dvis) {
71 } 71 dbpp = this->hidden->visuals[i].bpp;
72 } 72 break;
73 73 }
74 /* The Visual struct is supposed to be opaque but we cheat a little */ 74 }
75 sicon = SDL_CreateRGBSurface(SDL_SWSURFACE, icon->w, icon->h, 75
76 dbpp, 76 /* The Visual struct is supposed to be opaque but we cheat a little */
77 dvis->red_mask, dvis->green_mask, 77 sicon = SDL_CreateRGBSurface (SDL_SWSURFACE, icon->w, icon->h,
78 dvis->blue_mask, 0); 78 dbpp,
79 if ( sicon == NULL ) 79 dvis->red_mask, dvis->green_mask,
80 goto done; 80 dvis->blue_mask, 0);
81 81 if (sicon == NULL)
82 if(dbpp == 8) { 82 goto done;
83 /* Default visual is 8bit; we need to allocate colours from 83
84 the default colormap */ 84 if (dbpp == 8) {
85 SDL_Color want[256], got[256]; 85 /* Default visual is 8bit; we need to allocate colours from
86 int nwant; 86 the default colormap */
87 Colormap dcmap; 87 SDL_Color want[256], got[256];
88 int missing; 88 int nwant;
89 dcmap = DefaultColormap(SDL_Display, SDL_Screen); 89 Colormap dcmap;
90 if(icon->format->palette) { 90 int missing;
91 /* The icon has a palette as well - we just have to 91 dcmap = DefaultColormap (SDL_Display, SDL_Screen);
92 find those colours */ 92 if (icon->format->palette) {
93 nwant = icon->format->palette->ncolors; 93 /* The icon has a palette as well - we just have to
94 SDL_memcpy(want, icon->format->palette->colors, 94 find those colours */
95 nwant * sizeof want[0]); 95 nwant = icon->format->palette->ncolors;
96 } else { 96 SDL_memcpy (want, icon->format->palette->colors,
97 /* try the standard 6x6x6 cube for lack of better 97 nwant * sizeof want[0]);
98 ideas */ 98 } else {
99 int r, g, b, i; 99 /* try the standard 6x6x6 cube for lack of better
100 for(r = i = 0; r < 256; r += 0x33) 100 ideas */
101 for(g = 0; g < 256; g += 0x33) 101 int r, g, b, i;
102 for(b = 0; b < 256; b += 0x33, i++) { 102 for (r = i = 0; r < 256; r += 0x33)
103 want[i].r = r; 103 for (g = 0; g < 256; g += 0x33)
104 want[i].g = g; 104 for (b = 0; b < 256; b += 0x33, i++) {
105 want[i].b = b; 105 want[i].r = r;
106 } 106 want[i].g = g;
107 nwant = 216; 107 want[i].b = b;
108 } 108 }
109 if(SDL_iconcolors) { 109 nwant = 216;
110 /* free already allocated colours first */ 110 }
111 unsigned long freelist[512]; 111 if (SDL_iconcolors) {
112 int nfree = 0; 112 /* free already allocated colours first */
113 for(i = 0; i < 256; i++) { 113 unsigned long freelist[512];
114 while(SDL_iconcolors[i]) { 114 int nfree = 0;
115 freelist[nfree++] = i; 115 for (i = 0; i < 256; i++) {
116 SDL_iconcolors[i]--; 116 while (SDL_iconcolors[i]) {
117 } 117 freelist[nfree++] = i;
118 } 118 SDL_iconcolors[i]--;
119 XFreeColors(GFX_Display, dcmap, freelist, nfree, 0); 119 }
120 } 120 }
121 if(!SDL_iconcolors) 121 XFreeColors (GFX_Display, dcmap, freelist, nfree, 0);
122 SDL_iconcolors = SDL_malloc(256 * sizeof *SDL_iconcolors); 122 }
123 SDL_memset(SDL_iconcolors, 0, 256 * sizeof *SDL_iconcolors); 123 if (!SDL_iconcolors)
124 124 SDL_iconcolors = SDL_malloc (256 * sizeof *SDL_iconcolors);
125 /* try to allocate the colours */ 125 SDL_memset (SDL_iconcolors, 0, 256 * sizeof *SDL_iconcolors);
126 SDL_memset(got, 0, sizeof got); 126
127 missing = 0; 127 /* try to allocate the colours */
128 for(i = 0; i < nwant; i++) { 128 SDL_memset (got, 0, sizeof got);
129 XColor c; 129 missing = 0;
130 c.red = want[i].r << 8; 130 for (i = 0; i < nwant; i++) {
131 c.green = want[i].g << 8; 131 XColor c;
132 c.blue = want[i].b << 8; 132 c.red = want[i].r << 8;
133 c.flags = DoRed | DoGreen | DoBlue; 133 c.green = want[i].g << 8;
134 if(XAllocColor(GFX_Display, dcmap, &c)) { 134 c.blue = want[i].b << 8;
135 /* got the colour */ 135 c.flags = DoRed | DoGreen | DoBlue;
136 SDL_iconcolors[c.pixel]++; 136 if (XAllocColor (GFX_Display, dcmap, &c)) {
137 got[c.pixel] = want[i]; 137 /* got the colour */
138 } else { 138 SDL_iconcolors[c.pixel]++;
139 missing = 1; 139 got[c.pixel] = want[i];
140 } 140 } else {
141 } 141 missing = 1;
142 if(missing) { 142 }
143 /* Some colours were apparently missing, so we just 143 }
144 allocate all the rest as well */ 144 if (missing) {
145 XColor cols[256]; 145 /* Some colours were apparently missing, so we just
146 for(i = 0; i < 256; i++) 146 allocate all the rest as well */
147 cols[i].pixel = i; 147 XColor cols[256];
148 XQueryColors(GFX_Display, dcmap, cols, 256); 148 for (i = 0; i < 256; i++)
149 for(i = 0; i < 256; i++) { 149 cols[i].pixel = i;
150 got[i].r = cols[i].red >> 8; 150 XQueryColors (GFX_Display, dcmap, cols, 256);
151 got[i].g = cols[i].green >> 8; 151 for (i = 0; i < 256; i++) {
152 got[i].b = cols[i].blue >> 8; 152 got[i].r = cols[i].red >> 8;
153 if(!SDL_iconcolors[i]) { 153 got[i].g = cols[i].green >> 8;
154 if(XAllocColor(GFX_Display, dcmap, 154 got[i].b = cols[i].blue >> 8;
155 cols + i)) { 155 if (!SDL_iconcolors[i]) {
156 SDL_iconcolors[i] = 1; 156 if (XAllocColor (GFX_Display, dcmap, cols + i)) {
157 } else { 157 SDL_iconcolors[i] = 1;
158 /* index not available */ 158 } else {
159 got[i].r = 0; 159 /* index not available */
160 got[i].g = 0; 160 got[i].r = 0;
161 got[i].b = 0; 161 got[i].g = 0;
162 } 162 got[i].b = 0;
163 } 163 }
164 } 164 }
165 } 165 }
166 166 }
167 SDL_SetColors(sicon, got, 0, 256); 167
168 } 168 SDL_SetColors (sicon, got, 0, 256);
169 169 }
170 bounds.x = 0; 170
171 bounds.y = 0; 171 bounds.x = 0;
172 bounds.w = icon->w; 172 bounds.y = 0;
173 bounds.h = icon->h; 173 bounds.w = icon->w;
174 if ( SDL_LowerBlit(icon, &bounds, sicon, &bounds) < 0 ) 174 bounds.h = icon->h;
175 goto done; 175 if (SDL_LowerBlit (icon, &bounds, sicon, &bounds) < 0)
176 176 goto done;
177 /* We need the mask as given, except in LSBfirst format instead of 177
178 MSBfirst. Reverse the bits in each byte. */ 178 /* We need the mask as given, except in LSBfirst format instead of
179 masksize = ((sicon->w + 7) >> 3) * sicon->h; 179 MSBfirst. Reverse the bits in each byte. */
180 LSBmask = SDL_malloc(masksize); 180 masksize = ((sicon->w + 7) >> 3) * sicon->h;
181 if ( LSBmask == NULL ) { 181 LSBmask = SDL_malloc (masksize);
182 goto done; 182 if (LSBmask == NULL) {
183 } 183 goto done;
184 SDL_memset(LSBmask, 0, masksize); 184 }
185 for(i = 0; i < masksize; i++) 185 SDL_memset (LSBmask, 0, masksize);
186 LSBmask[i] = reverse_byte(mask[i]); 186 for (i = 0; i < masksize; i++)
187 mask_pixmap = XCreatePixmapFromBitmapData(SDL_Display, WMwindow, 187 LSBmask[i] = reverse_byte (mask[i]);
188 (char *)LSBmask, 188 mask_pixmap = XCreatePixmapFromBitmapData (SDL_Display, WMwindow,
189 sicon->w, sicon->h, 189 (char *) LSBmask,
190 1L, 0L, 1); 190 sicon->w, sicon->h, 1L, 0L, 1);
191 191
192 /* Transfer the image to an X11 pixmap */ 192 /* Transfer the image to an X11 pixmap */
193 icon_image = XCreateImage(SDL_Display, 193 icon_image = XCreateImage (SDL_Display,
194 DefaultVisual(SDL_Display, SDL_Screen), 194 DefaultVisual (SDL_Display, SDL_Screen),
195 DefaultDepth(SDL_Display, SDL_Screen), 195 DefaultDepth (SDL_Display, SDL_Screen),
196 ZPixmap, 0, sicon->pixels, 196 ZPixmap, 0, sicon->pixels,
197 sicon->w, sicon->h, 197 sicon->w, sicon->h, 32, 0);
198 32, 0); 198 icon_image->byte_order = (SDL_BYTEORDER == SDL_BIG_ENDIAN)
199 icon_image->byte_order = (SDL_BYTEORDER == SDL_BIG_ENDIAN) 199 ? MSBFirst : LSBFirst;
200 ? MSBFirst : LSBFirst; 200 icon_pixmap = XCreatePixmap (SDL_Display, SDL_Root, sicon->w, sicon->h,
201 icon_pixmap = XCreatePixmap(SDL_Display, SDL_Root, sicon->w, sicon->h, 201 DefaultDepth (SDL_Display, SDL_Screen));
202 DefaultDepth(SDL_Display, SDL_Screen)); 202 gc = XCreateGC (SDL_Display, icon_pixmap, 0, &GCvalues);
203 gc = XCreateGC(SDL_Display, icon_pixmap, 0, &GCvalues); 203 XPutImage (SDL_Display, icon_pixmap, gc, icon_image,
204 XPutImage(SDL_Display, icon_pixmap, gc, icon_image, 204 0, 0, 0, 0, sicon->w, sicon->h);
205 0, 0, 0, 0, sicon->w, sicon->h); 205 XFreeGC (SDL_Display, gc);
206 XFreeGC(SDL_Display, gc); 206 XDestroyImage (icon_image);
207 XDestroyImage(icon_image); 207 SDL_free (LSBmask);
208 SDL_free(LSBmask); 208 sicon->pixels = NULL;
209 sicon->pixels = NULL; 209
210 210 /* Some buggy window managers (some versions of Enlightenment, it
211 /* Some buggy window managers (some versions of Enlightenment, it 211 seems) need an icon window *and* icon pixmap to work properly, while
212 seems) need an icon window *and* icon pixmap to work properly, while 212 it screws up others. The default is only to use a pixmap. */
213 it screws up others. The default is only to use a pixmap. */ 213 p = SDL_getenv ("SDL_VIDEO_X11_ICONWIN");
214 p = SDL_getenv("SDL_VIDEO_X11_ICONWIN"); 214 if (p && *p) {
215 if(p && *p) { 215 icon_window = XCreateSimpleWindow (SDL_Display, SDL_Root,
216 icon_window = XCreateSimpleWindow(SDL_Display, SDL_Root, 216 0, 0, sicon->w, sicon->h, 0,
217 0, 0, sicon->w, sicon->h, 0, 217 CopyFromParent, CopyFromParent);
218 CopyFromParent, 218 XSetWindowBackgroundPixmap (SDL_Display, icon_window, icon_pixmap);
219 CopyFromParent); 219 XClearWindow (SDL_Display, icon_window);
220 XSetWindowBackgroundPixmap(SDL_Display, icon_window, 220 }
221 icon_pixmap); 221
222 XClearWindow(SDL_Display, icon_window); 222 /* Set the window icon to the icon pixmap (and icon window) */
223 } 223 wmhints = XAllocWMHints ();
224 224 wmhints->flags = (IconPixmapHint | IconMaskHint);
225 /* Set the window icon to the icon pixmap (and icon window) */ 225 wmhints->icon_pixmap = icon_pixmap;
226 wmhints = XAllocWMHints(); 226 wmhints->icon_mask = mask_pixmap;
227 wmhints->flags = (IconPixmapHint | IconMaskHint); 227 if (icon_window != None) {
228 wmhints->icon_pixmap = icon_pixmap; 228 wmhints->flags |= IconWindowHint;
229 wmhints->icon_mask = mask_pixmap; 229 wmhints->icon_window = icon_window;
230 if(icon_window != None) { 230 }
231 wmhints->flags |= IconWindowHint; 231 XSetWMHints (SDL_Display, WMwindow, wmhints);
232 wmhints->icon_window = icon_window; 232 XFree (wmhints);
233 } 233 XSync (SDL_Display, False);
234 XSetWMHints(SDL_Display, WMwindow, wmhints);
235 XFree(wmhints);
236 XSync(SDL_Display, False);
237 234
238 done: 235 done:
239 SDL_Unlock_EventThread(); 236 SDL_Unlock_EventThread ();
240 SDL_FreeSurface(sicon); 237 SDL_FreeSurface (sicon);
241 } 238 }
242 239
243 void X11_SetCaptionNoLock(_THIS, const char *title, const char *icon) 240 void
244 { 241 X11_SetCaptionNoLock (_THIS, const char *title, const char *icon)
245 XTextProperty titleprop, iconprop; 242 {
246 Status status; 243 XTextProperty titleprop, iconprop;
244 Status status;
247 245
248 #ifdef X_HAVE_UTF8_STRING 246 #ifdef X_HAVE_UTF8_STRING
249 Atom _NET_WM_NAME; 247 Atom _NET_WM_NAME;
250 Atom _NET_WM_ICON_NAME; 248 Atom _NET_WM_ICON_NAME;
251 249
252 /* Look up some useful Atoms */ 250 /* Look up some useful Atoms */
253 if (SDL_X11_HAVE_UTF8) { 251 if (SDL_X11_HAVE_UTF8) {
254 _NET_WM_NAME = XInternAtom(SDL_Display, "_NET_WM_NAME", False); 252 _NET_WM_NAME = XInternAtom (SDL_Display, "_NET_WM_NAME", False);
255 _NET_WM_ICON_NAME = XInternAtom(SDL_Display, "_NET_WM_ICON_NAME", False); 253 _NET_WM_ICON_NAME =
256 } 254 XInternAtom (SDL_Display, "_NET_WM_ICON_NAME", False);
255 }
257 #endif 256 #endif
258 257
259 if ( title != NULL ) { 258 if (title != NULL) {
260 char *title_latin1 = SDL_iconv_utf8_latin1((char *)title); 259 char *title_latin1 = SDL_iconv_utf8_latin1 ((char *) title);
261 if ( !title_latin1 ) { 260 if (!title_latin1) {
262 SDL_OutOfMemory(); 261 SDL_OutOfMemory ();
263 return; 262 return;
264 } 263 }
265 status = XStringListToTextProperty(&title_latin1, 1, &titleprop); 264 status = XStringListToTextProperty (&title_latin1, 1, &titleprop);
266 SDL_free(title_latin1); 265 SDL_free (title_latin1);
267 if ( status ) { 266 if (status) {
268 XSetTextProperty(SDL_Display, WMwindow, &titleprop, XA_WM_NAME); 267 XSetTextProperty (SDL_Display, WMwindow, &titleprop, XA_WM_NAME);
269 XFree(titleprop.value); 268 XFree (titleprop.value);
270 } 269 }
271 #ifdef X_HAVE_UTF8_STRING 270 #ifdef X_HAVE_UTF8_STRING
272 if (SDL_X11_HAVE_UTF8) { 271 if (SDL_X11_HAVE_UTF8) {
273 status = Xutf8TextListToTextProperty(SDL_Display, 272 status = Xutf8TextListToTextProperty (SDL_Display,
274 (char **)&title, 1, XUTF8StringStyle, &titleprop); 273 (char **) &title, 1,
275 if ( status == Success ) { 274 XUTF8StringStyle,
276 XSetTextProperty(SDL_Display, WMwindow, &titleprop, _NET_WM_NAME); 275 &titleprop);
277 XFree(titleprop.value); 276 if (status == Success) {
278 } 277 XSetTextProperty (SDL_Display, WMwindow, &titleprop,
279 } 278 _NET_WM_NAME);
279 XFree (titleprop.value);
280 }
281 }
280 #endif 282 #endif
281 } 283 }
282 if ( icon != NULL ) { 284 if (icon != NULL) {
283 char *icon_latin1 = SDL_iconv_utf8_latin1((char *)icon); 285 char *icon_latin1 = SDL_iconv_utf8_latin1 ((char *) icon);
284 if ( !icon_latin1 ) { 286 if (!icon_latin1) {
285 SDL_OutOfMemory(); 287 SDL_OutOfMemory ();
286 return; 288 return;
287 } 289 }
288 status = XStringListToTextProperty(&icon_latin1, 1, &iconprop); 290 status = XStringListToTextProperty (&icon_latin1, 1, &iconprop);
289 SDL_free(icon_latin1); 291 SDL_free (icon_latin1);
290 if ( status ) { 292 if (status) {
291 XSetTextProperty(SDL_Display, WMwindow, &iconprop, XA_WM_ICON_NAME); 293 XSetTextProperty (SDL_Display, WMwindow, &iconprop,
292 XFree(iconprop.value); 294 XA_WM_ICON_NAME);
293 } 295 XFree (iconprop.value);
296 }
294 #ifdef X_HAVE_UTF8_STRING 297 #ifdef X_HAVE_UTF8_STRING
295 if (SDL_X11_HAVE_UTF8) { 298 if (SDL_X11_HAVE_UTF8) {
296 status = Xutf8TextListToTextProperty(SDL_Display, 299 status = Xutf8TextListToTextProperty (SDL_Display,
297 (char **)&icon, 1, XUTF8StringStyle, &iconprop); 300 (char **) &icon, 1,
298 if ( status == Success ) { 301 XUTF8StringStyle,
299 XSetTextProperty(SDL_Display, WMwindow, &iconprop, _NET_WM_ICON_NAME); 302 &iconprop);
300 XFree(iconprop.value); 303 if (status == Success) {
301 } 304 XSetTextProperty (SDL_Display, WMwindow, &iconprop,
302 } 305 _NET_WM_ICON_NAME);
306 XFree (iconprop.value);
307 }
308 }
303 #endif 309 #endif
304 } 310 }
305 XSync(SDL_Display, False); 311 XSync (SDL_Display, False);
306 } 312 }
307 313
308 void X11_SetCaption(_THIS, const char *title, const char *icon) 314 void
309 { 315 X11_SetCaption (_THIS, const char *title, const char *icon)
310 SDL_Lock_EventThread(); 316 {
311 X11_SetCaptionNoLock(this, title, icon); 317 SDL_Lock_EventThread ();
312 SDL_Unlock_EventThread(); 318 X11_SetCaptionNoLock (this, title, icon);
319 SDL_Unlock_EventThread ();
313 } 320 }
314 321
315 /* Iconify the window */ 322 /* Iconify the window */
316 int X11_IconifyWindow(_THIS) 323 int
317 { 324 X11_IconifyWindow (_THIS)
318 int result; 325 {
319 326 int result;
320 SDL_Lock_EventThread(); 327
321 result = XIconifyWindow(SDL_Display, WMwindow, SDL_Screen); 328 SDL_Lock_EventThread ();
322 XSync(SDL_Display, False); 329 result = XIconifyWindow (SDL_Display, WMwindow, SDL_Screen);
323 SDL_Unlock_EventThread(); 330 XSync (SDL_Display, False);
324 return(result); 331 SDL_Unlock_EventThread ();
325 } 332 return (result);
326 333 }
327 SDL_GrabMode X11_GrabInputNoLock(_THIS, SDL_GrabMode mode) 334
328 { 335 SDL_GrabMode
329 int result; 336 X11_GrabInputNoLock (_THIS, SDL_GrabMode mode)
330 337 {
331 if ( this->screen == NULL ) { 338 int result;
332 return(SDL_GRAB_OFF); 339
333 } 340 if (SDL_VideoSurface == NULL) {
334 if ( ! SDL_Window ) { 341 return (SDL_GRAB_OFF);
335 return(mode); /* Will be set later on mode switch */ 342 }
336 } 343 if (!SDL_Window) {
337 if ( mode == SDL_GRAB_OFF ) { 344 return (mode); /* Will be set later on mode switch */
338 XUngrabPointer(SDL_Display, CurrentTime); 345 }
339 XUngrabKeyboard(SDL_Display, CurrentTime); 346 if (mode == SDL_GRAB_OFF) {
340 } else { 347 XUngrabPointer (SDL_Display, CurrentTime);
341 if ( this->screen->flags & SDL_FULLSCREEN ) { 348 XUngrabKeyboard (SDL_Display, CurrentTime);
342 /* Unbind the mouse from the fullscreen window */ 349 } else {
343 XUngrabPointer(SDL_Display, CurrentTime); 350 if (SDL_VideoSurface->flags & SDL_FULLSCREEN) {
344 } 351 /* Unbind the mouse from the fullscreen window */
345 /* Try to grab the mouse */ 352 XUngrabPointer (SDL_Display, CurrentTime);
346 #if 0 /* We'll wait here until we actually grab, otherwise behavior undefined */ 353 }
347 for ( numtries = 0; numtries < 10; ++numtries ) { 354 /* Try to grab the mouse */
355 #if 0 /* We'll wait here until we actually grab, otherwise behavior undefined */
356 for (numtries = 0; numtries < 10; ++numtries) {
348 #else 357 #else
349 for ( ; ; ) { 358 for (;;) {
350 #endif 359 #endif
351 result = XGrabPointer(SDL_Display, SDL_Window, True, 0, 360 result = XGrabPointer (SDL_Display, SDL_Window, True, 0,
352 GrabModeAsync, GrabModeAsync, 361 GrabModeAsync, GrabModeAsync,
353 SDL_Window, None, CurrentTime); 362 SDL_Window, None, CurrentTime);
354 if ( result == GrabSuccess ) { 363 if (result == GrabSuccess) {
355 break; 364 break;
356 } 365 }
357 SDL_Delay(100); 366 SDL_Delay (100);
358 } 367 }
359 if ( result != GrabSuccess ) { 368 if (result != GrabSuccess) {
360 /* Uh, oh, what do we do here? */ ; 369 /* Uh, oh, what do we do here? */ ;
361 } 370 }
362 /* Now grab the keyboard */ 371 /* Now grab the keyboard */
363 XGrabKeyboard(SDL_Display, WMwindow, True, 372 XGrabKeyboard (SDL_Display, WMwindow, True,
364 GrabModeAsync, GrabModeAsync, CurrentTime); 373 GrabModeAsync, GrabModeAsync, CurrentTime);
365 374
366 /* Raise the window if we grab the mouse */ 375 /* Raise the window if we grab the mouse */
367 if ( !(this->screen->flags & SDL_FULLSCREEN) ) 376 if (!(SDL_VideoSurface->flags & SDL_FULLSCREEN))
368 XRaiseWindow(SDL_Display, WMwindow); 377 XRaiseWindow (SDL_Display, WMwindow);
369 378
370 /* Make sure we register input focus */ 379 /* Make sure we register input focus */
371 SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS); 380 SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS);
372 } 381 }
373 XSync(SDL_Display, False); 382 XSync (SDL_Display, False);
374 383
375 return(mode); 384 return (mode);
376 } 385 }
377 386
378 SDL_GrabMode X11_GrabInput(_THIS, SDL_GrabMode mode) 387 SDL_GrabMode
379 { 388 X11_GrabInput (_THIS, SDL_GrabMode mode)
380 SDL_Lock_EventThread(); 389 {
381 mode = X11_GrabInputNoLock(this, mode); 390 SDL_Lock_EventThread ();
382 SDL_Unlock_EventThread(); 391 mode = X11_GrabInputNoLock (this, mode);
383 392 SDL_Unlock_EventThread ();
384 return(mode); 393
394 return (mode);
385 } 395 }
386 396
387 /* If 'info' is the right version, this function fills it and returns 1. 397 /* If 'info' is the right version, this function fills it and returns 1.
388 Otherwise, in case of a version mismatch, it returns -1. 398 Otherwise, in case of a version mismatch, it returns -1.
389 */ 399 */
390 static void lock_display(void) 400 static void
391 { 401 lock_display (void)
392 SDL_Lock_EventThread(); 402 {
393 } 403 SDL_Lock_EventThread ();
394 static void unlock_display(void) 404 }
395 { 405 static void
396 /* Make sure any X11 transactions are completed */ 406 unlock_display (void)
397 SDL_VideoDevice *this = current_video; 407 {
398 XSync(SDL_Display, False); 408 /* Make sure any X11 transactions are completed */
399 SDL_Unlock_EventThread(); 409 SDL_VideoDevice *this = current_video;
400 } 410 XSync (SDL_Display, False);
401 int X11_GetWMInfo(_THIS, SDL_SysWMinfo *info) 411 SDL_Unlock_EventThread ();
402 { 412 }
403 if ( info->version.major <= SDL_MAJOR_VERSION ) { 413
404 info->subsystem = SDL_SYSWM_X11; 414 int
405 info->info.x11.display = SDL_Display; 415 X11_GetWMInfo (_THIS, SDL_SysWMinfo * info)
406 info->info.x11.window = SDL_Window; 416 {
407 if ( SDL_VERSIONNUM(info->version.major, 417 if (info->version.major <= SDL_MAJOR_VERSION) {
408 info->version.minor, 418 info->subsystem = SDL_SYSWM_X11;
409 info->version.patch) >= 1002 ) { 419 info->info.x11.display = SDL_Display;
410 info->info.x11.fswindow = FSwindow; 420 info->info.x11.window = SDL_Window;
411 info->info.x11.wmwindow = WMwindow; 421 if (SDL_VERSIONNUM (info->version.major,
412 } 422 info->version.minor,
413 info->info.x11.lock_func = lock_display; 423 info->version.patch) >= 1002) {
414 info->info.x11.unlock_func = unlock_display; 424 info->info.x11.fswindow = FSwindow;
415 return(1); 425 info->info.x11.wmwindow = WMwindow;
416 } else { 426 }
417 SDL_SetError("Application not compiled with SDL %d.%d\n", 427 info->info.x11.lock_func = lock_display;
418 SDL_MAJOR_VERSION, SDL_MINOR_VERSION); 428 info->info.x11.unlock_func = unlock_display;
419 return(-1); 429 return (1);
420 } 430 } else {
421 } 431 SDL_SetError ("Application not compiled with SDL %d.%d\n",
432 SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
433 return (-1);
434 }
435 }
436
437 /* vi: set ts=4 sw=4 expandtab: */