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