Mercurial > sdl-ios-xcode
annotate src/video/cybergfx/SDL_cgxwm.c @ 1319:66f6c64c2c69
Logic bug in X11 Unicode input shutdown...was checking for == NULL
when it should be != NULL.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Wed, 01 Feb 2006 19:59:02 +0000 |
parents | c9b51268668f |
children | 3692456e7b0f |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 #include "SDL_version.h" | |
24 #include "SDL_error.h" | |
25 #include "SDL_timer.h" | |
26 #include "SDL_video.h" | |
27 #include "SDL_syswm.h" | |
28 #include "SDL_events_c.h" | |
29 #include "SDL_pixels_c.h" | |
30 #include "SDL_cgxmodes_c.h" | |
31 #include "SDL_cgxwm_c.h" | |
32 | |
33 /* This is necessary for working properly with Enlightenment, etc. */ | |
34 #define USE_ICON_WINDOW | |
35 | |
36 void CGX_SetIcon(_THIS, SDL_Surface *icon, Uint8 *mask) | |
37 { | |
38 #if 0 | |
39 SDL_Surface *sicon; | |
40 XWMHints *wmhints; | |
41 XImage *icon_image; | |
42 Pixmap icon_pixmap; | |
43 Pixmap mask_pixmap; | |
44 #ifdef USE_ICON_WINDOW | |
45 Window icon_window; | |
46 #endif | |
47 GC GC; | |
48 XGCValues GCvalues; | |
49 int i, b, dbpp; | |
50 SDL_Rect bounds; | |
51 Uint8 *LSBmask, *color_tried; | |
52 Visual *dvis; | |
53 | |
54 /* Lock the event thread, in multi-threading environments */ | |
55 SDL_Lock_EventThread(); | |
56 | |
57 /* The icon must use the default visual, depth and colormap of the | |
58 screen, so it might need a conversion */ | |
59 dbpp = DefaultDepth(SDL_Display, SDL_Screen); | |
60 switch(dbpp) { | |
61 case 15: | |
62 dbpp = 16; break; | |
63 case 24: | |
64 dbpp = 32; break; | |
65 } | |
66 dvis = DefaultVisual(SDL_Display, SDL_Screen); | |
67 | |
68 /* The Visual struct is supposed to be opaque but we cheat a little */ | |
69 sicon = SDL_CreateRGBSurface(SDL_SWSURFACE, icon->w, icon->h, | |
70 dbpp, | |
71 dvis->red_mask, dvis->green_mask, | |
72 dvis->blue_mask, 0); | |
73 | |
74 if ( sicon == NULL ) { | |
75 goto done; | |
76 } | |
77 /* If we already have allocated colours from the default colormap, | |
78 copy them */ | |
79 if(SDL_Visual == dvis && SDL_XColorMap == SDL_DisplayColormap | |
80 && this->screen->format->palette && sicon->format->palette) { | |
81 memcpy(sicon->format->palette->colors, | |
82 this->screen->format->palette->colors, | |
83 this->screen->format->palette->ncolors * sizeof(SDL_Color)); | |
84 } | |
85 | |
86 bounds.x = 0; | |
87 bounds.y = 0; | |
88 bounds.w = icon->w; | |
89 bounds.h = icon->h; | |
90 if ( SDL_LowerBlit(icon, &bounds, sicon, &bounds) < 0 ) | |
91 goto done; | |
92 | |
93 /* Lock down the colors used in the colormap */ | |
94 color_tried = NULL; | |
95 if ( sicon->format->BitsPerPixel == 8 ) { | |
96 SDL_Palette *palette; | |
97 Uint8 *p; | |
98 XColor wanted; | |
99 | |
100 palette = sicon->format->palette; | |
101 color_tried = malloc(palette->ncolors); | |
102 if ( color_tried == NULL ) { | |
103 goto done; | |
104 } | |
105 if ( SDL_iconcolors != NULL ) { | |
106 free(SDL_iconcolors); | |
107 } | |
108 SDL_iconcolors = malloc(palette->ncolors | |
109 * sizeof(*SDL_iconcolors)); | |
110 if ( SDL_iconcolors == NULL ) { | |
111 free(color_tried); | |
112 goto done; | |
113 } | |
114 memset(color_tried, 0, palette->ncolors); | |
115 memset(SDL_iconcolors, 0, | |
116 palette->ncolors * sizeof(*SDL_iconcolors)); | |
117 | |
118 p = (Uint8 *)sicon->pixels; | |
119 for ( i = sicon->w*sicon->h; i > 0; --i, ++p ) { | |
120 if ( ! color_tried[*p] ) { | |
121 wanted.pixel = *p; | |
122 wanted.red = (palette->colors[*p].r<<8); | |
123 wanted.green = (palette->colors[*p].g<<8); | |
124 wanted.blue = (palette->colors[*p].b<<8); | |
125 wanted.flags = (DoRed|DoGreen|DoBlue); | |
126 if (XAllocColor(SDL_Display, | |
127 SDL_DisplayColormap, &wanted)) { | |
128 ++SDL_iconcolors[wanted.pixel]; | |
129 } | |
130 color_tried[*p] = 1; | |
131 } | |
132 } | |
133 } | |
134 if ( color_tried != NULL ) { | |
135 free(color_tried); | |
136 } | |
137 | |
138 /* Translate mask data to LSB order and set the icon mask */ | |
139 i = (sicon->w/8)*sicon->h; | |
140 LSBmask = (Uint8 *)malloc(i); | |
141 if ( LSBmask == NULL ) { | |
142 goto done; | |
143 } | |
144 memset(LSBmask, 0, i); | |
145 while ( --i >= 0 ) { | |
146 for ( b=0; b<8; ++b ) | |
147 LSBmask[i] |= (((mask[i]>>b)&0x01)<<(7-b)); | |
148 } | |
149 mask_pixmap = XCreatePixmapFromBitmapData(SDL_Display, WMwindow, | |
150 LSBmask, sicon->w, sicon->h, 1L, 0L, 1); | |
151 | |
152 /* Transfer the image to an X11 pixmap */ | |
153 icon_image = XCreateImage(SDL_Display, | |
154 DefaultVisual(SDL_Display, SDL_Screen), | |
155 DefaultDepth(SDL_Display, SDL_Screen), | |
156 ZPixmap, 0, (char *)sicon->pixels, sicon->w, sicon->h, | |
157 ((sicon->format)->BytesPerPixel == 3) ? 32 : | |
158 (sicon->format)->BytesPerPixel*8, 0); | |
159 icon_pixmap = XCreatePixmap(SDL_Display, SDL_Root, sicon->w, sicon->h, | |
160 DefaultDepth(SDL_Display, SDL_Screen)); | |
161 GC = XCreateGC(SDL_Display, icon_pixmap, 0, &GCvalues); | |
162 XPutImage(SDL_Display, icon_pixmap, GC, icon_image, | |
163 0, 0, 0, 0, sicon->w, sicon->h); | |
164 XFreeGC(SDL_Display, GC); | |
165 XDestroyImage(icon_image); | |
166 free(LSBmask); | |
167 sicon->pixels = NULL; | |
168 | |
169 #ifdef USE_ICON_WINDOW | |
170 /* Create an icon window and set the pixmap as its background */ | |
171 icon_window = XCreateSimpleWindow(SDL_Display, SDL_Root, | |
172 0, 0, sicon->w, sicon->h, 0, | |
173 CopyFromParent, CopyFromParent); | |
174 XSetWindowBackgroundPixmap(SDL_Display, icon_window, icon_pixmap); | |
175 XClearWindow(SDL_Display, icon_window); | |
176 #endif | |
177 | |
178 /* Set the window icon to the icon pixmap (and icon window) */ | |
179 wmhints = XAllocWMHints(); | |
180 wmhints->flags = (IconPixmapHint | IconMaskHint); | |
181 wmhints->icon_pixmap = icon_pixmap; | |
182 wmhints->icon_mask = mask_pixmap; | |
183 #ifdef USE_ICON_WINDOW | |
184 wmhints->flags |= IconWindowHint; | |
185 wmhints->icon_window = icon_window; | |
186 #endif | |
187 XSetWMHints(SDL_Display, WMwindow, wmhints); | |
188 XFree(wmhints); | |
189 XSync(SDL_Display, False); | |
190 | |
191 done: | |
192 SDL_Unlock_EventThread(); | |
193 if ( sicon != NULL ) { | |
194 SDL_FreeSurface(sicon); | |
195 } | |
196 #endif | |
197 return; | |
198 } | |
199 | |
200 void CGX_SetCaption(_THIS, const char *title, const char *icon) | |
201 { | |
202 if(SDL_Window) | |
203 SetWindowTitles(SDL_Window,(char *)title,NULL); | |
204 } | |
205 | |
206 /* Iconify the window */ | |
207 int CGX_IconifyWindow(_THIS) | |
208 { | |
209 #if 0 | |
210 int result; | |
211 | |
212 SDL_Lock_EventThread(); | |
213 result = XIconifyWindow(SDL_Display, WMwindow, SDL_Screen); | |
214 XSync(SDL_Display, False); | |
215 SDL_Unlock_EventThread(); | |
216 return(result); | |
217 #else | |
218 return 0; | |
219 #endif | |
220 } | |
221 | |
222 #if 0 | |
223 SDL_GrabMode X11_GrabInputNoLock(_THIS, SDL_GrabMode mode) | |
224 { | |
225 int numtries, result; | |
226 | |
227 if ( this->screen == NULL ) { | |
228 return(SDL_GRAB_OFF); | |
229 } | |
230 if ( ! SDL_Window ) { | |
231 return(mode); /* Will be set later on mode switch */ | |
232 } | |
233 if ( mode == SDL_GRAB_OFF ) { | |
234 XUngrabPointer(SDL_Display, CurrentTime); | |
235 if ( this->screen->flags & SDL_FULLSCREEN ) { | |
236 /* Rebind the mouse to the fullscreen window */ | |
237 for ( numtries = 0; numtries < 10; ++numtries ) { | |
238 result = XGrabPointer(SDL_Display, FSwindow, | |
239 True, 0, | |
240 GrabModeAsync, GrabModeAsync, | |
241 FSwindow, None, CurrentTime); | |
242 if ( result == AlreadyGrabbed ) { | |
243 break; | |
244 } | |
245 SDL_Delay(100); | |
246 } | |
247 } | |
248 #ifdef GRAB_FULLSCREEN | |
249 if ( !(this->screen->flags & SDL_FULLSCREEN) ) | |
250 #endif | |
251 XUngrabKeyboard(SDL_Display, CurrentTime); | |
252 } else { | |
253 if ( this->screen->flags & SDL_FULLSCREEN ) { | |
254 /* Unbind the mouse from the fullscreen window */ | |
255 XUngrabPointer(SDL_Display, CurrentTime); | |
256 } | |
257 /* Try to grab the mouse */ | |
258 for ( numtries = 0; numtries < 10; ++numtries ) { | |
259 result = XGrabPointer(SDL_Display, SDL_Window, True, 0, | |
260 GrabModeAsync, GrabModeAsync, | |
261 SDL_Window, None, CurrentTime); | |
262 if ( result != AlreadyGrabbed ) { | |
263 break; | |
264 } | |
265 SDL_Delay(100); | |
266 } | |
267 #ifdef GRAB_FULLSCREEN | |
268 if ( !(this->screen->flags & SDL_FULLSCREEN) ) | |
269 #endif | |
270 XGrabKeyboard(SDL_Display, WMwindow, True, | |
271 GrabModeAsync, GrabModeAsync, CurrentTime); | |
272 } | |
273 XSync(SDL_Display, False); | |
274 | |
275 return(mode); | |
276 } | |
277 | |
278 SDL_GrabMode X11_GrabInput(_THIS, SDL_GrabMode mode) | |
279 { | |
280 SDL_Lock_EventThread(); | |
281 mode = X11_GrabInputNoLock(this, mode); | |
282 SDL_Unlock_EventThread(); | |
283 | |
284 return(mode); | |
285 } | |
286 | |
287 /* If 'info' is the right version, this function fills it and returns 1. | |
288 Otherwise, in case of a version mismatch, it returns -1. | |
289 */ | |
290 static void lock_display(void) | |
291 { | |
292 SDL_Lock_EventThread(); | |
293 } | |
294 static void unlock_display(void) | |
295 { | |
296 /* Make sure any X11 transactions are completed */ | |
297 SDL_VideoDevice *this = current_video; | |
298 XSync(SDL_Display, False); | |
299 SDL_Unlock_EventThread(); | |
300 } | |
301 | |
302 #endif | |
303 | |
304 int CGX_GetWMInfo(_THIS, SDL_SysWMinfo *info) | |
305 { | |
306 if ( info->version.major <= SDL_MAJOR_VERSION ) { | |
307 #if 0 | |
308 info->subsystem = SDL_SYSWM_X11; | |
309 info->info.x11.display = SDL_Display; | |
310 info->info.x11.window = SDL_Window; | |
311 if ( SDL_VERSIONNUM(info->version.major, | |
312 info->version.minor, | |
313 info->version.patch) >= 1002 ) { | |
314 info->info.x11.fswindow = FSwindow; | |
315 info->info.x11.wmwindow = WMwindow; | |
316 } | |
317 info->info.x11.lock_func = lock_display; | |
318 info->info.x11.unlock_func = unlock_display; | |
319 #endif | |
320 return(1); | |
321 } else { | |
322 SDL_SetError("Application not compiled with SDL %d.%d\n", | |
323 SDL_MAJOR_VERSION, SDL_MINOR_VERSION); | |
324 return(-1); | |
325 } | |
326 } |