comparison src/video/x11/SDL_x11video.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
53 #include "SDL_x11gl_c.h" 53 #include "SDL_x11gl_c.h"
54 #include "SDL_x11gamma_c.h" 54 #include "SDL_x11gamma_c.h"
55 #include "../blank_cursor.h" 55 #include "../blank_cursor.h"
56 56
57 /* Initialization/Query functions */ 57 /* Initialization/Query functions */
58 static int X11_VideoInit(_THIS, SDL_PixelFormat *vformat); 58 static int X11_VideoInit (_THIS);
59 static SDL_Surface *X11_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); 59 static SDL_Surface *X11_SetVideoMode (_THIS, SDL_Surface * current,
60 static int X11_ToggleFullScreen(_THIS, int on); 60 const SDL_DisplayMode * mode,
61 static void X11_UpdateMouse(_THIS); 61 Uint32 flags);
62 static int X11_SetColors(_THIS, int firstcolor, int ncolors, 62 static int X11_ToggleFullScreen (_THIS, int on);
63 SDL_Color *colors); 63 static void X11_UpdateMouse (_THIS);
64 static int X11_SetGammaRamp(_THIS, Uint16 *ramp); 64 static int X11_SetColors (_THIS, int firstcolor, int ncolors,
65 static void X11_VideoQuit(_THIS); 65 SDL_Color * colors);
66 static int X11_SetGammaRamp (_THIS, Uint16 * ramp);
67 static void X11_VideoQuit (_THIS);
66 68
67 69
68 /* X11 driver bootstrap functions */ 70 /* X11 driver bootstrap functions */
69 71
70 static int X11_Available(void) 72 static int
71 { 73 X11_Available (void)
72 Display *display = NULL; 74 {
73 if ( SDL_X11_LoadSymbols() ) { 75 Display *display = NULL;
74 display = XOpenDisplay(NULL); 76 if (SDL_X11_LoadSymbols ()) {
75 if ( display != NULL ) { 77 display = XOpenDisplay (NULL);
76 XCloseDisplay(display); 78 if (display != NULL) {
77 } 79 XCloseDisplay (display);
78 SDL_X11_UnloadSymbols(); 80 }
79 } 81 SDL_X11_UnloadSymbols ();
80 return(display != NULL); 82 }
81 } 83 return (display != NULL);
82 84 }
83 static void X11_DeleteDevice(SDL_VideoDevice *device) 85
84 { 86 static void
85 if ( device ) { 87 X11_DeleteDevice (SDL_VideoDevice * device)
86 if ( device->hidden ) { 88 {
87 SDL_free(device->hidden); 89 if (device) {
88 } 90 if (device->hidden) {
89 if ( device->gl_data ) { 91 SDL_free (device->hidden);
90 SDL_free(device->gl_data); 92 }
91 } 93 if (device->gl_data) {
92 SDL_free(device); 94 SDL_free (device->gl_data);
93 SDL_X11_UnloadSymbols(); 95 }
94 } 96 SDL_free (device);
95 } 97 SDL_X11_UnloadSymbols ();
96 98 }
97 static SDL_VideoDevice *X11_CreateDevice(int devindex) 99 }
98 { 100
99 SDL_VideoDevice *device = NULL; 101 static SDL_VideoDevice *
100 102 X11_CreateDevice (int devindex)
101 if ( SDL_X11_LoadSymbols() ) { 103 {
102 /* Initialize all variables that we clean on shutdown */ 104 SDL_VideoDevice *device = NULL;
103 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); 105
104 if ( device ) { 106 if (SDL_X11_LoadSymbols ()) {
105 SDL_memset(device, 0, (sizeof *device)); 107 /* Initialize all variables that we clean on shutdown */
106 device->hidden = (struct SDL_PrivateVideoData *) 108 device = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice));
107 SDL_malloc((sizeof *device->hidden)); 109 if (device) {
108 device->gl_data = (struct SDL_PrivateGLData *) 110 SDL_memset (device, 0, (sizeof *device));
109 SDL_malloc((sizeof *device->gl_data)); 111 device->hidden = (struct SDL_PrivateVideoData *)
110 } 112 SDL_malloc ((sizeof *device->hidden));
111 if ( (device == NULL) || (device->hidden == NULL) || 113 device->gl_data = (struct SDL_PrivateGLData *)
112 (device->gl_data == NULL) ) { 114 SDL_malloc ((sizeof *device->gl_data));
113 SDL_OutOfMemory(); 115 }
114 X11_DeleteDevice(device); /* calls SDL_X11_UnloadSymbols(). */ 116 if ((device == NULL) || (device->hidden == NULL) ||
115 return(0); 117 (device->gl_data == NULL)) {
116 } 118 SDL_OutOfMemory ();
117 SDL_memset(device->hidden, 0, (sizeof *device->hidden)); 119 X11_DeleteDevice (device); /* calls SDL_X11_UnloadSymbols(). */
118 SDL_memset(device->gl_data, 0, (sizeof *device->gl_data)); 120 return (0);
119 121 }
120 /* Set the driver flags */ 122 SDL_memset (device->hidden, 0, (sizeof *device->hidden));
121 device->handles_any_size = 1; 123 SDL_memset (device->gl_data, 0, (sizeof *device->gl_data));
122 124
123 /* Set the function pointers */ 125 /* Set the driver flags */
124 device->VideoInit = X11_VideoInit; 126 device->handles_any_size = 1;
125 device->ListModes = X11_ListModes; 127
126 device->SetVideoMode = X11_SetVideoMode; 128 /* Set the function pointers */
127 device->ToggleFullScreen = X11_ToggleFullScreen; 129 device->VideoInit = X11_VideoInit;
128 device->UpdateMouse = X11_UpdateMouse; 130 device->SetVideoMode = X11_SetVideoMode;
131 device->ToggleFullScreen = X11_ToggleFullScreen;
132 device->UpdateMouse = X11_UpdateMouse;
129 #if SDL_VIDEO_DRIVER_X11_XV 133 #if SDL_VIDEO_DRIVER_X11_XV
130 device->CreateYUVOverlay = X11_CreateYUVOverlay; 134 device->CreateYUVOverlay = X11_CreateYUVOverlay;
131 #endif 135 #endif
132 device->SetColors = X11_SetColors; 136 device->SetColors = X11_SetColors;
133 device->UpdateRects = NULL; 137 device->UpdateRects = NULL;
134 device->VideoQuit = X11_VideoQuit; 138 device->VideoQuit = X11_VideoQuit;
135 device->AllocHWSurface = X11_AllocHWSurface; 139 device->AllocHWSurface = X11_AllocHWSurface;
136 device->CheckHWBlit = NULL; 140 device->CheckHWBlit = NULL;
137 device->FillHWRect = NULL; 141 device->FillHWRect = NULL;
138 device->SetHWColorKey = NULL; 142 device->SetHWColorKey = NULL;
139 device->SetHWAlpha = NULL; 143 device->SetHWAlpha = NULL;
140 device->LockHWSurface = X11_LockHWSurface; 144 device->LockHWSurface = X11_LockHWSurface;
141 device->UnlockHWSurface = X11_UnlockHWSurface; 145 device->UnlockHWSurface = X11_UnlockHWSurface;
142 device->FlipHWSurface = X11_FlipHWSurface; 146 device->FlipHWSurface = X11_FlipHWSurface;
143 device->FreeHWSurface = X11_FreeHWSurface; 147 device->FreeHWSurface = X11_FreeHWSurface;
144 device->SetGamma = X11_SetVidModeGamma; 148 device->SetGamma = X11_SetVidModeGamma;
145 device->GetGamma = X11_GetVidModeGamma; 149 device->GetGamma = X11_GetVidModeGamma;
146 device->SetGammaRamp = X11_SetGammaRamp; 150 device->SetGammaRamp = X11_SetGammaRamp;
147 device->GetGammaRamp = NULL; 151 device->GetGammaRamp = NULL;
148 #if SDL_VIDEO_OPENGL_GLX 152 #if SDL_VIDEO_OPENGL_GLX
149 device->GL_LoadLibrary = X11_GL_LoadLibrary; 153 device->GL_LoadLibrary = X11_GL_LoadLibrary;
150 device->GL_GetProcAddress = X11_GL_GetProcAddress; 154 device->GL_GetProcAddress = X11_GL_GetProcAddress;
151 device->GL_GetAttribute = X11_GL_GetAttribute; 155 device->GL_GetAttribute = X11_GL_GetAttribute;
152 device->GL_MakeCurrent = X11_GL_MakeCurrent; 156 device->GL_MakeCurrent = X11_GL_MakeCurrent;
153 device->GL_SwapBuffers = X11_GL_SwapBuffers; 157 device->GL_SwapBuffers = X11_GL_SwapBuffers;
154 #endif 158 #endif
155 device->SetCaption = X11_SetCaption; 159 device->SetCaption = X11_SetCaption;
156 device->SetIcon = X11_SetIcon; 160 device->SetIcon = X11_SetIcon;
157 device->IconifyWindow = X11_IconifyWindow; 161 device->IconifyWindow = X11_IconifyWindow;
158 device->GrabInput = X11_GrabInput; 162 device->GrabInput = X11_GrabInput;
159 device->GetWMInfo = X11_GetWMInfo; 163 device->GetWMInfo = X11_GetWMInfo;
160 device->FreeWMCursor = X11_FreeWMCursor; 164 device->FreeWMCursor = X11_FreeWMCursor;
161 device->CreateWMCursor = X11_CreateWMCursor; 165 device->CreateWMCursor = X11_CreateWMCursor;
162 device->ShowWMCursor = X11_ShowWMCursor; 166 device->ShowWMCursor = X11_ShowWMCursor;
163 device->WarpWMCursor = X11_WarpWMCursor; 167 device->WarpWMCursor = X11_WarpWMCursor;
164 device->CheckMouseMode = X11_CheckMouseMode; 168 device->CheckMouseMode = X11_CheckMouseMode;
165 device->InitOSKeymap = X11_InitOSKeymap; 169 device->InitOSKeymap = X11_InitOSKeymap;
166 device->PumpEvents = X11_PumpEvents; 170 device->PumpEvents = X11_PumpEvents;
167 171
168 device->free = X11_DeleteDevice; 172 device->free = X11_DeleteDevice;
169 } 173 }
170 174
171 return device; 175 return device;
172 } 176 }
173 177
174 VideoBootStrap X11_bootstrap = { 178 VideoBootStrap X11_bootstrap = {
175 "x11", "X Window System", 179 "x11", "X Window System",
176 X11_Available, X11_CreateDevice 180 X11_Available, X11_CreateDevice
177 }; 181 };
178 182
179 /* Normal X11 error handler routine */ 183 /* Normal X11 error handler routine */
180 static int (*X_handler)(Display *, XErrorEvent *) = NULL; 184 static int (*X_handler) (Display *, XErrorEvent *) = NULL;
181 static int x_errhandler(Display *d, XErrorEvent *e) 185 static int
186 x_errhandler (Display * d, XErrorEvent * e)
182 { 187 {
183 #if SDL_VIDEO_DRIVER_X11_VIDMODE 188 #if SDL_VIDEO_DRIVER_X11_VIDMODE
184 extern int vm_error; 189 extern int vm_error;
185 #endif 190 #endif
186 #if SDL_VIDEO_DRIVER_X11_DGAMOUSE 191 #if SDL_VIDEO_DRIVER_X11_DGAMOUSE
187 extern int dga_error; 192 extern int dga_error;
188 #endif 193 #endif
189 194
190 #if SDL_VIDEO_DRIVER_X11_VIDMODE 195 #if SDL_VIDEO_DRIVER_X11_VIDMODE
191 /* VidMode errors are non-fatal. :) */ 196 /* VidMode errors are non-fatal. :) */
192 /* Are the errors offset by one from the error base? 197 /* Are the errors offset by one from the error base?
193 e.g. the error base is 143, the code is 148, and the 198 e.g. the error base is 143, the code is 148, and the
194 actual error is XF86VidModeExtensionDisabled (4) ? 199 actual error is XF86VidModeExtensionDisabled (4) ?
195 */ 200 */
196 if ( (vm_error >= 0) && 201 if ((vm_error >= 0) &&
197 (((e->error_code == BadRequest)&&(e->request_code == vm_error)) || 202 (((e->error_code == BadRequest) && (e->request_code == vm_error)) ||
198 ((e->error_code > vm_error) && 203 ((e->error_code > vm_error) &&
199 (e->error_code <= (vm_error+XF86VidModeNumberErrors)))) ) { 204 (e->error_code <= (vm_error + XF86VidModeNumberErrors))))) {
200 #ifdef X11_DEBUG 205 #ifdef X11_DEBUG
201 { char errmsg[1024]; 206 {
202 XGetErrorText(d, e->error_code, errmsg, sizeof(errmsg)); 207 char errmsg[1024];
203 printf("VidMode error: %s\n", errmsg); 208 XGetErrorText (d, e->error_code, errmsg, sizeof (errmsg));
204 } 209 printf ("VidMode error: %s\n", errmsg);
205 #endif 210 }
206 return(0); 211 #endif
207 } 212 return (0);
213 }
208 #endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */ 214 #endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */
209 215
210 #if SDL_VIDEO_DRIVER_X11_DGAMOUSE 216 #if SDL_VIDEO_DRIVER_X11_DGAMOUSE
211 /* DGA errors can be non-fatal. :) */ 217 /* DGA errors can be non-fatal. :) */
212 if ( (dga_error >= 0) && 218 if ((dga_error >= 0) &&
213 ((e->error_code > dga_error) && 219 ((e->error_code > dga_error) &&
214 (e->error_code <= (dga_error+XF86DGANumberErrors))) ) { 220 (e->error_code <= (dga_error + XF86DGANumberErrors)))) {
215 #ifdef X11_DEBUG 221 #ifdef X11_DEBUG
216 { char errmsg[1024]; 222 {
217 XGetErrorText(d, e->error_code, errmsg, sizeof(errmsg)); 223 char errmsg[1024];
218 printf("DGA error: %s\n", errmsg); 224 XGetErrorText (d, e->error_code, errmsg, sizeof (errmsg));
219 } 225 printf ("DGA error: %s\n", errmsg);
220 #endif 226 }
221 return(0); 227 #endif
222 } 228 return (0);
229 }
223 #endif /* SDL_VIDEO_DRIVER_X11_DGAMOUSE */ 230 #endif /* SDL_VIDEO_DRIVER_X11_DGAMOUSE */
224 231
225 return(X_handler(d,e)); 232 return (X_handler (d, e));
226 } 233 }
227 234
228 /* X11 I/O error handler routine */ 235 /* X11 I/O error handler routine */
229 static int (*XIO_handler)(Display *) = NULL; 236 static int (*XIO_handler) (Display *) = NULL;
230 static int xio_errhandler(Display *d) 237 static int
231 { 238 xio_errhandler (Display * d)
232 /* Ack! Lost X11 connection! */ 239 {
233 240 /* Ack! Lost X11 connection! */
234 /* We will crash if we try to clean up our display */ 241
235 if ( current_video->hidden->Ximage ) { 242 /* We will crash if we try to clean up our display */
236 SDL_VideoSurface->pixels = NULL; 243 if (current_video->hidden->Ximage) {
237 } 244 SDL_VideoSurface->pixels = NULL;
238 current_video->hidden->X11_Display = NULL; 245 }
239 246 current_video->hidden->X11_Display = NULL;
240 /* Continue with the standard X11 error handler */ 247
241 return(XIO_handler(d)); 248 /* Continue with the standard X11 error handler */
242 } 249 return (XIO_handler (d));
243 250 }
244 static int (*Xext_handler)(Display *, _Xconst char *, _Xconst char *) = NULL; 251
245 static int xext_errhandler(Display *d, _Xconst char *ext, _Xconst char *reason) 252 static int (*Xext_handler) (Display *, _Xconst char *, _Xconst char *) = NULL;
253 static int
254 xext_errhandler (Display * d, _Xconst char *ext, _Xconst char *reason)
246 { 255 {
247 #ifdef X11_DEBUG 256 #ifdef X11_DEBUG
248 printf("Xext error inside SDL (may be harmless):\n"); 257 printf ("Xext error inside SDL (may be harmless):\n");
249 printf(" Extension \"%s\" %s on display \"%s\".\n", 258 printf (" Extension \"%s\" %s on display \"%s\".\n",
250 ext, reason, XDisplayString(d)); 259 ext, reason, XDisplayString (d));
251 #endif 260 #endif
252 261
253 if (SDL_strcmp(reason, "missing") == 0) { 262 if (SDL_strcmp (reason, "missing") == 0) {
254 /* 263 /*
255 * Since the query itself, elsewhere, can handle a missing extension 264 * Since the query itself, elsewhere, can handle a missing extension
256 * and the default behaviour in Xlib is to write to stderr, which 265 * and the default behaviour in Xlib is to write to stderr, which
257 * generates unnecessary bug reports, we just ignore these. 266 * generates unnecessary bug reports, we just ignore these.
258 */ 267 */
259 return 0; 268 return 0;
260 } 269 }
261 270
262 /* Everything else goes to the default handler... */ 271 /* Everything else goes to the default handler... */
263 return Xext_handler(d, ext, reason); 272 return Xext_handler (d, ext, reason);
264 } 273 }
265 274
266 /* Find out what class name we should use */ 275 /* Find out what class name we should use */
267 static char *get_classname(char *classname, int maxlen) 276 static char *
268 { 277 get_classname (char *classname, int maxlen)
269 char *spot; 278 {
279 char *spot;
270 #if defined(__LINUX__) || defined(__FREEBSD__) 280 #if defined(__LINUX__) || defined(__FREEBSD__)
271 char procfile[1024]; 281 char procfile[1024];
272 char linkfile[1024]; 282 char linkfile[1024];
273 int linksize; 283 int linksize;
274 #endif 284 #endif
275 285
276 /* First allow environment variable override */ 286 /* First allow environment variable override */
277 spot = SDL_getenv("SDL_VIDEO_X11_WMCLASS"); 287 spot = SDL_getenv ("SDL_VIDEO_X11_WMCLASS");
278 if ( spot ) { 288 if (spot) {
279 SDL_strlcpy(classname, spot, maxlen); 289 SDL_strlcpy (classname, spot, maxlen);
280 return classname; 290 return classname;
281 } 291 }
282 292
283 /* Next look at the application's executable name */ 293 /* Next look at the application's executable name */
284 #if defined(__LINUX__) || defined(__FREEBSD__) 294 #if defined(__LINUX__) || defined(__FREEBSD__)
285 #if defined(__LINUX__) 295 #if defined(__LINUX__)
286 SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/exe", getpid()); 296 SDL_snprintf (procfile, SDL_arraysize (procfile), "/proc/%d/exe",
297 getpid ());
287 #elif defined(__FREEBSD__) 298 #elif defined(__FREEBSD__)
288 SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/file", getpid()); 299 SDL_snprintf (procfile, SDL_arraysize (procfile), "/proc/%d/file",
300 getpid ());
289 #else 301 #else
290 #error Where can we find the executable name? 302 #error Where can we find the executable name?
291 #endif 303 #endif
292 linksize = readlink(procfile, linkfile, sizeof(linkfile)-1); 304 linksize = readlink (procfile, linkfile, sizeof (linkfile) - 1);
293 if ( linksize > 0 ) { 305 if (linksize > 0) {
294 linkfile[linksize] = '\0'; 306 linkfile[linksize] = '\0';
295 spot = SDL_strrchr(linkfile, '/'); 307 spot = SDL_strrchr (linkfile, '/');
296 if ( spot ) { 308 if (spot) {
297 SDL_strlcpy(classname, spot+1, maxlen); 309 SDL_strlcpy (classname, spot + 1, maxlen);
298 } else { 310 } else {
299 SDL_strlcpy(classname, linkfile, maxlen); 311 SDL_strlcpy (classname, linkfile, maxlen);
300 } 312 }
301 return classname; 313 return classname;
302 } 314 }
303 #endif /* __LINUX__ */ 315 #endif /* __LINUX__ */
304 316
305 /* Finally use the default we've used forever */ 317 /* Finally use the default we've used forever */
306 SDL_strlcpy(classname, "SDL_App", maxlen); 318 SDL_strlcpy (classname, "SDL_App", maxlen);
307 return classname; 319 return classname;
308 } 320 }
309 321
310 /* Create auxiliary (toplevel) windows with the current visual */ 322 /* Create auxiliary (toplevel) windows with the current visual */
311 static void create_aux_windows(_THIS) 323 static void
324 create_aux_windows (_THIS)
312 { 325 {
313 int x = 0, y = 0; 326 int x = 0, y = 0;
314 char classname[1024]; 327 char classname[1024];
315 XSetWindowAttributes xattr; 328 XSetWindowAttributes xattr;
316 XWMHints *hints; 329 XWMHints *hints;
317 int def_vis = (SDL_Visual == DefaultVisual(SDL_Display, SDL_Screen)); 330 int def_vis = (SDL_Visual == DefaultVisual (SDL_Display, SDL_Screen));
318 331
319 /* Look up some useful Atoms */ 332 /* Look up some useful Atoms */
320 WM_DELETE_WINDOW = XInternAtom(SDL_Display, "WM_DELETE_WINDOW", False); 333 WM_DELETE_WINDOW = XInternAtom (SDL_Display, "WM_DELETE_WINDOW", False);
321 334
322 /* Don't create any extra windows if we are being managed */ 335 /* Don't create any extra windows if we are being managed */
323 if ( SDL_windowid ) { 336 if (SDL_windowid) {
324 FSwindow = 0; 337 FSwindow = 0;
325 WMwindow = SDL_strtol(SDL_windowid, NULL, 0); 338 WMwindow = SDL_strtol (SDL_windowid, NULL, 0);
326 return; 339 return;
327 } 340 }
328 341
329 if(FSwindow) 342 if (FSwindow)
330 XDestroyWindow(SDL_Display, FSwindow); 343 XDestroyWindow (SDL_Display, FSwindow);
331 344
332 #if SDL_VIDEO_DRIVER_X11_VIDMODE 345 #if SDL_VIDEO_DRIVER_X11_VIDMODE
333 if ( use_xinerama ) { 346 if (use_xinerama) {
334 x = xinerama_info.x_org; 347 x = xinerama[this->current_display].x_org;
335 y = xinerama_info.y_org; 348 y = xinerama[this->current_display].y_org;
336 } 349 }
337 #endif 350 #endif
338 xattr.override_redirect = True; 351 xattr.override_redirect = True;
339 xattr.background_pixel = def_vis ? BlackPixel(SDL_Display, SDL_Screen) : 0; 352 xattr.background_pixel =
353 def_vis ? BlackPixel (SDL_Display, SDL_Screen) : 0;
340 xattr.border_pixel = 0; 354 xattr.border_pixel = 0;
341 xattr.colormap = SDL_XColorMap; 355 xattr.colormap = SDL_XColorMap;
342 356
343 FSwindow = XCreateWindow(SDL_Display, SDL_Root, 357 FSwindow = XCreateWindow (SDL_Display, SDL_Root,
344 x, y, 32, 32, 0, 358 x, y, 32, 32, 0,
345 this->hidden->depth, InputOutput, SDL_Visual, 359 this->hidden->depth, InputOutput, SDL_Visual,
346 CWOverrideRedirect | CWBackPixel | CWBorderPixel 360 CWOverrideRedirect | CWBackPixel | CWBorderPixel
347 | CWColormap, 361 | CWColormap, &xattr);
348 &xattr); 362
349 363 XSelectInput (SDL_Display, FSwindow, StructureNotifyMask);
350 XSelectInput(SDL_Display, FSwindow, StructureNotifyMask);
351 364
352 /* Tell KDE to keep the fullscreen window on top */ 365 /* Tell KDE to keep the fullscreen window on top */
353 { 366 {
354 XEvent ev; 367 XEvent ev;
355 long mask; 368 long mask;
356 369
357 SDL_memset(&ev, 0, sizeof(ev)); 370 SDL_memset (&ev, 0, sizeof (ev));
358 ev.xclient.type = ClientMessage; 371 ev.xclient.type = ClientMessage;
359 ev.xclient.window = SDL_Root; 372 ev.xclient.window = SDL_Root;
360 ev.xclient.message_type = XInternAtom(SDL_Display, 373 ev.xclient.message_type = XInternAtom (SDL_Display,
361 "KWM_KEEP_ON_TOP", False); 374 "KWM_KEEP_ON_TOP", False);
362 ev.xclient.format = 32; 375 ev.xclient.format = 32;
363 ev.xclient.data.l[0] = FSwindow; 376 ev.xclient.data.l[0] = FSwindow;
364 ev.xclient.data.l[1] = CurrentTime; 377 ev.xclient.data.l[1] = CurrentTime;
365 mask = SubstructureRedirectMask; 378 mask = SubstructureRedirectMask;
366 XSendEvent(SDL_Display, SDL_Root, False, mask, &ev); 379 XSendEvent (SDL_Display, SDL_Root, False, mask, &ev);
367 } 380 }
368 381
369 hints = NULL; 382 hints = NULL;
370 if(WMwindow) { 383 if (WMwindow) {
371 /* All window attributes must survive the recreation */ 384 /* All window attributes must survive the recreation */
372 hints = XGetWMHints(SDL_Display, WMwindow); 385 hints = XGetWMHints (SDL_Display, WMwindow);
373 XDestroyWindow(SDL_Display, WMwindow); 386 XDestroyWindow (SDL_Display, WMwindow);
374 } 387 }
375 388
376 /* Create the window for windowed management */ 389 /* Create the window for windowed management */
377 /* (reusing the xattr structure above) */ 390 /* (reusing the xattr structure above) */
378 WMwindow = XCreateWindow(SDL_Display, SDL_Root, 391 WMwindow = XCreateWindow (SDL_Display, SDL_Root,
379 x, y, 32, 32, 0, 392 x, y, 32, 32, 0,
380 this->hidden->depth, InputOutput, SDL_Visual, 393 this->hidden->depth, InputOutput, SDL_Visual,
381 CWBackPixel | CWBorderPixel | CWColormap, 394 CWBackPixel | CWBorderPixel | CWColormap,
382 &xattr); 395 &xattr);
383 396
384 /* Set the input hints so we get keyboard input */ 397 /* Set the input hints so we get keyboard input */
385 if(!hints) { 398 if (!hints) {
386 hints = XAllocWMHints(); 399 hints = XAllocWMHints ();
387 hints->input = True; 400 hints->input = True;
388 hints->flags = InputHint; 401 hints->flags = InputHint;
389 } 402 }
390 XSetWMHints(SDL_Display, WMwindow, hints); 403 XSetWMHints (SDL_Display, WMwindow, hints);
391 XFree(hints); 404 XFree (hints);
392 X11_SetCaptionNoLock(this, this->wm_title, this->wm_icon); 405 X11_SetCaptionNoLock (this, SDL_CurrentWindow.wm_title,
393 406 SDL_CurrentWindow.wm_icon);
394 XSelectInput(SDL_Display, WMwindow, 407
395 FocusChangeMask | KeyPressMask | KeyReleaseMask 408 XSelectInput (SDL_Display, WMwindow,
396 | PropertyChangeMask | StructureNotifyMask | KeymapStateMask); 409 FocusChangeMask | KeyPressMask | KeyReleaseMask
410 | PropertyChangeMask | StructureNotifyMask |
411 KeymapStateMask);
397 412
398 /* Set the class hints so we can get an icon (AfterStep) */ 413 /* Set the class hints so we can get an icon (AfterStep) */
399 get_classname(classname, sizeof(classname)); 414 get_classname (classname, sizeof (classname));
400 { 415 {
401 XClassHint *classhints; 416 XClassHint *classhints;
402 classhints = XAllocClassHint(); 417 classhints = XAllocClassHint ();
403 if(classhints != NULL) { 418 if (classhints != NULL) {
404 classhints->res_name = classname; 419 classhints->res_name = classname;
405 classhints->res_class = classname; 420 classhints->res_class = classname;
406 XSetClassHint(SDL_Display, WMwindow, classhints); 421 XSetClassHint (SDL_Display, WMwindow, classhints);
407 XFree(classhints); 422 XFree (classhints);
408 } 423 }
409 } 424 }
410 425
411 /* Setup the communication with the IM server */ 426 /* Setup the communication with the IM server */
412 SDL_IM = NULL; 427 SDL_IM = NULL;
413 SDL_IC = NULL; 428 SDL_IC = NULL;
414 429
415 #ifdef X_HAVE_UTF8_STRING 430 #ifdef X_HAVE_UTF8_STRING
416 if (SDL_X11_HAVE_UTF8) { 431 if (SDL_X11_HAVE_UTF8) {
417 SDL_IM = XOpenIM(SDL_Display, NULL, classname, classname); 432 SDL_IM = XOpenIM (SDL_Display, NULL, classname, classname);
418 if (SDL_IM == NULL) { 433 if (SDL_IM == NULL) {
419 SDL_SetError("no input method could be opened"); 434 SDL_SetError ("no input method could be opened");
420 } else { 435 } else {
421 SDL_IC = pXCreateIC(SDL_IM, 436 SDL_IC = pXCreateIC (SDL_IM,
422 XNClientWindow, WMwindow, 437 XNClientWindow, WMwindow,
423 XNFocusWindow, WMwindow, 438 XNFocusWindow, WMwindow,
424 XNInputStyle, XIMPreeditNothing | XIMStatusNothing, 439 XNInputStyle,
425 XNResourceName, classname, 440 XIMPreeditNothing | XIMStatusNothing,
426 XNResourceClass, classname, 441 XNResourceName, classname,
427 NULL); 442 XNResourceClass, classname, NULL);
428 443
429 if (SDL_IC == NULL) { 444 if (SDL_IC == NULL) {
430 SDL_SetError("no input context could be created"); 445 SDL_SetError ("no input context could be created");
431 XCloseIM(SDL_IM); 446 XCloseIM (SDL_IM);
432 SDL_IM = NULL; 447 SDL_IM = NULL;
433 } 448 }
434 } 449 }
435 } 450 }
436 #endif 451 #endif
437 452
438 /* Allow the window to be deleted by the window manager */ 453 /* Allow the window to be deleted by the window manager */
439 XSetWMProtocols(SDL_Display, WMwindow, &WM_DELETE_WINDOW, 1); 454 XSetWMProtocols (SDL_Display, WMwindow, &WM_DELETE_WINDOW, 1);
440 } 455 }
441 456
442 static int X11_VideoInit(_THIS, SDL_PixelFormat *vformat) 457 static int
443 { 458 X11_VideoInit (_THIS)
444 char *display; 459 {
445 int i; 460 char *display;
446 461 int i;
447 /* Open the X11 display */ 462 SDL_DisplayMode desktop_mode;
448 display = NULL; /* Get it from DISPLAY environment variable */ 463
449 464 /* Open the X11 display */
450 if ( (SDL_strncmp(XDisplayName(display), ":", 1) == 0) || 465 display = NULL; /* Get it from DISPLAY environment variable */
451 (SDL_strncmp(XDisplayName(display), "unix:", 5) == 0) ) { 466
452 local_X11 = 1; 467 if ((SDL_strncmp (XDisplayName (display), ":", 1) == 0) ||
453 } else { 468 (SDL_strncmp (XDisplayName (display), "unix:", 5) == 0)) {
454 local_X11 = 0; 469 local_X11 = 1;
455 } 470 } else {
456 SDL_Display = XOpenDisplay(display); 471 local_X11 = 0;
472 }
473 SDL_Display = XOpenDisplay (display);
457 #if defined(__osf__) && defined(SDL_VIDEO_DRIVER_X11_DYNAMIC) 474 #if defined(__osf__) && defined(SDL_VIDEO_DRIVER_X11_DYNAMIC)
458 /* On Tru64 if linking without -lX11, it fails and you get following message. 475 /* On Tru64 if linking without -lX11, it fails and you get following message.
459 * Xlib: connection to ":0.0" refused by server 476 * Xlib: connection to ":0.0" refused by server
460 * Xlib: XDM authorization key matches an existing client! 477 * Xlib: XDM authorization key matches an existing client!
461 * 478 *
462 * It succeeds if retrying 1 second later 479 * It succeeds if retrying 1 second later
463 * or if running xhost +localhost on shell. 480 * or if running xhost +localhost on shell.
464 * 481 *
465 */ 482 */
466 if ( SDL_Display == NULL ) { 483 if (SDL_Display == NULL) {
467 SDL_Delay(1000); 484 SDL_Delay (1000);
468 SDL_Display = XOpenDisplay(display); 485 SDL_Display = XOpenDisplay (display);
469 } 486 }
470 #endif 487 #endif
471 if ( SDL_Display == NULL ) { 488 if (SDL_Display == NULL) {
472 SDL_SetError("Couldn't open X11 display"); 489 SDL_SetError ("Couldn't open X11 display");
473 return(-1); 490 return (-1);
474 } 491 }
475 #ifdef X11_DEBUG 492 #ifdef X11_DEBUG
476 XSynchronize(SDL_Display, True); 493 XSynchronize (SDL_Display, True);
477 #endif 494 #endif
478 495
479 /* Create an alternate X display for graphics updates -- allows us 496 /* Create an alternate X display for graphics updates -- allows us
480 to do graphics updates in a separate thread from event handling. 497 to do graphics updates in a separate thread from event handling.
481 Thread-safe X11 doesn't seem to exist. 498 Thread-safe X11 doesn't seem to exist.
482 */ 499 */
483 GFX_Display = XOpenDisplay(display); 500 GFX_Display = XOpenDisplay (display);
484 if ( GFX_Display == NULL ) { 501 if (GFX_Display == NULL) {
485 SDL_SetError("Couldn't open X11 display"); 502 SDL_SetError ("Couldn't open X11 display");
486 return(-1); 503 return (-1);
487 } 504 }
488 505
489 /* Set the normal X error handler */ 506 /* Set the normal X error handler */
490 X_handler = XSetErrorHandler(x_errhandler); 507 X_handler = XSetErrorHandler (x_errhandler);
491 508
492 /* Set the error handler if we lose the X display */ 509 /* Set the error handler if we lose the X display */
493 XIO_handler = XSetIOErrorHandler(xio_errhandler); 510 XIO_handler = XSetIOErrorHandler (xio_errhandler);
494 511
495 /* Set the X extension error handler */ 512 /* Set the X extension error handler */
496 Xext_handler = XSetExtensionErrorHandler(xext_errhandler); 513 Xext_handler = XSetExtensionErrorHandler (xext_errhandler);
497 514
498 /* use default screen (from $DISPLAY) */ 515 /* use default screen (from $DISPLAY) */
499 SDL_Screen = DefaultScreen(SDL_Display); 516 SDL_Screen = DefaultScreen (SDL_Display);
500 517
501 #ifndef NO_SHARED_MEMORY 518 #ifndef NO_SHARED_MEMORY
502 /* Check for MIT shared memory extension */ 519 /* Check for MIT shared memory extension */
503 use_mitshm = 0; 520 use_mitshm = 0;
504 if ( local_X11 ) { 521 if (local_X11) {
505 use_mitshm = XShmQueryExtension(SDL_Display); 522 use_mitshm = XShmQueryExtension (SDL_Display);
506 } 523 }
507 #endif /* NO_SHARED_MEMORY */ 524 #endif /* NO_SHARED_MEMORY */
508 525
509 /* Get the available video modes */ 526 /* Get the available visuals */
510 if(X11_GetVideoModes(this) < 0) 527 if (X11_GetVisuals (this) < 0)
511 return -1; 528 return -1;
512 529
513 /* Determine the current screen size */ 530 /* Determine the default screen mode:
514 this->info.current_w = DisplayWidth(SDL_Display, SDL_Screen); 531 Use the default visual (or at least one with the same depth) */
515 this->info.current_h = DisplayHeight(SDL_Display, SDL_Screen); 532 SDL_DisplayColormap = DefaultColormap (SDL_Display, SDL_Screen);
516 533 for (i = 0; i < this->hidden->nvisuals; i++)
517 /* Determine the default screen depth: 534 if (this->hidden->visuals[i].depth == DefaultDepth (SDL_Display,
518 Use the default visual (or at least one with the same depth) */ 535 SDL_Screen))
519 SDL_DisplayColormap = DefaultColormap(SDL_Display, SDL_Screen); 536 break;
520 for(i = 0; i < this->hidden->nvisuals; i++) 537 if (i == this->hidden->nvisuals) {
521 if(this->hidden->visuals[i].depth == DefaultDepth(SDL_Display, 538 /* default visual was useless, take the deepest one instead */
522 SDL_Screen)) 539 i = 0;
523 break; 540 }
524 if(i == this->hidden->nvisuals) { 541 SDL_Visual = this->hidden->visuals[i].visual;
525 /* default visual was useless, take the deepest one instead */ 542 if (SDL_Visual == DefaultVisual (SDL_Display, SDL_Screen)) {
526 i = 0; 543 SDL_XColorMap = SDL_DisplayColormap;
527 } 544 } else {
528 SDL_Visual = this->hidden->visuals[i].visual; 545 SDL_XColorMap = XCreateColormap (SDL_Display, SDL_Root,
529 if ( SDL_Visual == DefaultVisual(SDL_Display, SDL_Screen) ) { 546 SDL_Visual, AllocNone);
530 SDL_XColorMap = SDL_DisplayColormap; 547 }
531 } else { 548 desktop_mode.format =
532 SDL_XColorMap = XCreateColormap(SDL_Display, SDL_Root, 549 X11_VisualToFormat (this->hidden->visuals[i].visual,
533 SDL_Visual, AllocNone); 550 this->hidden->visuals[i].depth,
534 } 551 this->hidden->visuals[i].bpp);
535 this->hidden->depth = this->hidden->visuals[i].depth; 552 desktop_mode.w = DisplayWidth (SDL_Display, SDL_Screen);
536 vformat->BitsPerPixel = this->hidden->visuals[i].bpp; 553 desktop_mode.h = DisplayHeight (SDL_Display, SDL_Screen);
537 if ( vformat->BitsPerPixel > 8 ) { 554 desktop_mode.refresh_rate = 0;
538 vformat->Rmask = SDL_Visual->red_mask; 555 SDL_AddVideoDisplay (&desktop_mode);
539 vformat->Gmask = SDL_Visual->green_mask; 556
540 vformat->Bmask = SDL_Visual->blue_mask; 557 /* Get the available video modes */
541 } 558 if (X11_GetVideoModes (this) < 0)
542 if ( this->hidden->depth == 32 ) { 559 return -1;
543 vformat->Amask = (0xFFFFFFFF & ~(vformat->Rmask|vformat->Gmask|vformat->Bmask)); 560
544 } 561 X11_SaveVidModeGamma (this);
545 X11_SaveVidModeGamma(this); 562
546 563 /* Save DPMS and screensaver settings */
547 /* Save DPMS and screensaver settings */ 564 X11_SaveScreenSaver (SDL_Display, &screensaver_timeout, &dpms_enabled);
548 X11_SaveScreenSaver(SDL_Display, &screensaver_timeout, &dpms_enabled); 565 X11_DisableScreenSaver (SDL_Display);
549 X11_DisableScreenSaver(SDL_Display); 566
550 567 /* See if we have been passed a window to use */
551 /* See if we have been passed a window to use */ 568 SDL_windowid = SDL_getenv ("SDL_WINDOWID");
552 SDL_windowid = SDL_getenv("SDL_WINDOWID"); 569
553 570 /* Create the fullscreen and managed windows */
554 /* Create the fullscreen and managed windows */ 571 create_aux_windows (this);
555 create_aux_windows(this); 572
556 573 /* Create the blank cursor */
557 /* Create the blank cursor */ 574 SDL_BlankCursor = this->CreateWMCursor (this, blank_cdata, blank_cmask,
558 SDL_BlankCursor = this->CreateWMCursor(this, blank_cdata, blank_cmask, 575 BLANK_CWIDTH, BLANK_CHEIGHT,
559 BLANK_CWIDTH, BLANK_CHEIGHT, 576 BLANK_CHOTX, BLANK_CHOTY);
560 BLANK_CHOTX, BLANK_CHOTY); 577
561 578 /* Fill in some window manager capabilities */
562 /* Fill in some window manager capabilities */ 579 this->info.wm_available = 1;
563 this->info.wm_available = 1; 580
564 581 /* We're done! */
565 /* We're done! */ 582 XFlush (SDL_Display);
566 XFlush(SDL_Display); 583 return (0);
567 return(0); 584 }
568 } 585
569 586 static void
570 static void X11_DestroyWindow(_THIS, SDL_Surface *screen) 587 X11_DestroyWindow (_THIS, SDL_Surface * screen)
571 { 588 {
572 /* Clean up OpenGL */ 589 /* Clean up OpenGL */
573 if ( screen ) { 590 if (screen) {
574 screen->flags &= ~SDL_INTERNALOPENGL; 591 screen->flags &= ~SDL_INTERNALOPENGL;
575 } 592 }
576 X11_GL_Shutdown(this); 593 X11_GL_Shutdown (this);
577 594
578 if ( ! SDL_windowid ) { 595 if (!SDL_windowid) {
579 /* Hide the managed window */ 596 /* Hide the managed window */
580 if ( WMwindow ) { 597 if (WMwindow) {
581 XUnmapWindow(SDL_Display, WMwindow); 598 XUnmapWindow (SDL_Display, WMwindow);
582 } 599 }
583 if ( screen && (screen->flags & SDL_FULLSCREEN) ) { 600 if (screen && (screen->flags & SDL_FULLSCREEN)) {
584 screen->flags &= ~SDL_FULLSCREEN; 601 screen->flags &= ~SDL_FULLSCREEN;
585 X11_LeaveFullScreen(this); 602 X11_LeaveFullScreen (this);
586 } 603 }
587 604
588 /* Destroy the output window */ 605 /* Destroy the output window */
589 if ( SDL_Window ) { 606 if (SDL_Window) {
590 XDestroyWindow(SDL_Display, SDL_Window); 607 XDestroyWindow (SDL_Display, SDL_Window);
591 } 608 }
592 609
593 /* Free the colormap entries */ 610 /* Free the colormap entries */
594 if ( SDL_XPixels ) { 611 if (SDL_XPixels) {
595 int numcolors; 612 int numcolors;
596 unsigned long pixel; 613 unsigned long pixel;
597 numcolors = SDL_Visual->map_entries; 614 numcolors = SDL_Visual->map_entries;
598 for ( pixel=0; pixel<numcolors; ++pixel ) { 615 for (pixel = 0; pixel < numcolors; ++pixel) {
599 while ( SDL_XPixels[pixel] > 0 ) { 616 while (SDL_XPixels[pixel] > 0) {
600 XFreeColors(GFX_Display, 617 XFreeColors (GFX_Display,
601 SDL_DisplayColormap,&pixel,1,0); 618 SDL_DisplayColormap, &pixel, 1, 0);
602 --SDL_XPixels[pixel]; 619 --SDL_XPixels[pixel];
603 } 620 }
604 } 621 }
605 SDL_free(SDL_XPixels); 622 SDL_free (SDL_XPixels);
606 SDL_XPixels = NULL; 623 SDL_XPixels = NULL;
607 } 624 }
608 625
609 /* Free the graphics context */ 626 /* Free the graphics context */
610 if ( SDL_GC ) { 627 if (SDL_GC) {
611 XFreeGC(SDL_Display, SDL_GC); 628 XFreeGC (SDL_Display, SDL_GC);
612 SDL_GC = 0; 629 SDL_GC = 0;
613 } 630 }
614 } 631 }
615 } 632 }
616 633
617 static SDL_bool X11_WindowPosition(_THIS, int *x, int *y, int w, int h) 634 static SDL_bool
618 { 635 X11_WindowPosition (_THIS, int *x, int *y, int w, int h)
619 const char *window = SDL_getenv("SDL_VIDEO_WINDOW_POS"); 636 {
620 const char *center = SDL_getenv("SDL_VIDEO_CENTERED"); 637 const char *window = SDL_getenv ("SDL_VIDEO_WINDOW_POS");
621 if ( window ) { 638 const char *center = SDL_getenv ("SDL_VIDEO_CENTERED");
622 if ( SDL_sscanf(window, "%d,%d", x, y) == 2 ) { 639 if (window) {
623 return SDL_TRUE; 640 if (SDL_sscanf (window, "%d,%d", x, y) == 2) {
624 } 641 return SDL_TRUE;
625 if ( SDL_strcmp(window, "center") == 0 ) { 642 }
626 center = window; 643 if (SDL_strcmp (window, "center") == 0) {
627 } 644 center = window;
628 } 645 }
629 if ( center ) { 646 }
630 *x = (DisplayWidth(SDL_Display, SDL_Screen) - w)/2; 647 if (center) {
631 *y = (DisplayHeight(SDL_Display, SDL_Screen) - h)/2; 648 *x = (DisplayWidth (SDL_Display, SDL_Screen) - w) / 2;
632 return SDL_TRUE; 649 *y = (DisplayHeight (SDL_Display, SDL_Screen) - h) / 2;
633 } 650 return SDL_TRUE;
634 return SDL_FALSE; 651 }
635 } 652 return SDL_FALSE;
636 653 }
637 static void X11_SetSizeHints(_THIS, int w, int h, Uint32 flags) 654
638 { 655 static void
639 XSizeHints *hints; 656 X11_SetSizeHints (_THIS, int w, int h, Uint32 flags)
640 657 {
641 hints = XAllocSizeHints(); 658 XSizeHints *hints;
642 if ( hints ) { 659
643 if ( flags & SDL_RESIZABLE ) { 660 hints = XAllocSizeHints ();
644 hints->min_width = 32; 661 if (hints) {
645 hints->min_height = 32; 662 if (flags & SDL_RESIZABLE) {
646 hints->max_height = 4096; 663 hints->min_width = 32;
647 hints->max_width = 4096; 664 hints->min_height = 32;
648 } else { 665 hints->max_height = 4096;
649 hints->min_width = hints->max_width = w; 666 hints->max_width = 4096;
650 hints->min_height = hints->max_height = h; 667 } else {
651 } 668 hints->min_width = hints->max_width = w;
652 hints->flags = PMaxSize | PMinSize; 669 hints->min_height = hints->max_height = h;
653 if ( flags & SDL_FULLSCREEN ) { 670 }
654 hints->x = 0; 671 hints->flags = PMaxSize | PMinSize;
655 hints->y = 0; 672 if (flags & SDL_FULLSCREEN) {
656 hints->flags |= USPosition; 673 hints->x = 0;
657 } else 674 hints->y = 0;
658 /* Center it, if desired */ 675 hints->flags |= USPosition;
659 if ( X11_WindowPosition(this, &hints->x, &hints->y, w, h) ) { 676 } else
660 hints->flags |= USPosition; 677 /* Center it, if desired */
661 XMoveWindow(SDL_Display, WMwindow, hints->x, hints->y); 678 if (X11_WindowPosition (this, &hints->x, &hints->y, w, h)) {
662 679 hints->flags |= USPosition;
663 /* Flush the resize event so we don't catch it later */ 680 XMoveWindow (SDL_Display, WMwindow, hints->x, hints->y);
664 XSync(SDL_Display, True); 681
665 } 682 /* Flush the resize event so we don't catch it later */
666 XSetWMNormalHints(SDL_Display, WMwindow, hints); 683 XSync (SDL_Display, True);
667 XFree(hints); 684 }
668 } 685 XSetWMNormalHints (SDL_Display, WMwindow, hints);
669 686 XFree (hints);
670 /* Respect the window caption style */ 687 }
671 if ( flags & SDL_NOFRAME ) { 688
672 SDL_bool set; 689 /* Respect the window caption style */
673 Atom WM_HINTS; 690 if (flags & SDL_NOFRAME) {
674 691 SDL_bool set;
675 /* We haven't modified the window manager hints yet */ 692 Atom WM_HINTS;
676 set = SDL_FALSE; 693
677 694 /* We haven't modified the window manager hints yet */
678 /* First try to set MWM hints */ 695 set = SDL_FALSE;
679 WM_HINTS = XInternAtom(SDL_Display, "_MOTIF_WM_HINTS", True); 696
680 if ( WM_HINTS != None ) { 697 /* First try to set MWM hints */
681 /* Hints used by Motif compliant window managers */ 698 WM_HINTS = XInternAtom (SDL_Display, "_MOTIF_WM_HINTS", True);
682 struct { 699 if (WM_HINTS != None) {
683 unsigned long flags; 700 /* Hints used by Motif compliant window managers */
684 unsigned long functions; 701 struct
685 unsigned long decorations; 702 {
686 long input_mode; 703 unsigned long flags;
687 unsigned long status; 704 unsigned long functions;
688 } MWMHints = { (1L << 1), 0, 0, 0, 0 }; 705 unsigned long decorations;
689 706 long input_mode;
690 XChangeProperty(SDL_Display, WMwindow, 707 unsigned long status;
691 WM_HINTS, WM_HINTS, 32, 708 } MWMHints = {
692 PropModeReplace, 709 (1L << 1), 0, 0, 0, 0};
693 (unsigned char *)&MWMHints, 710
694 sizeof(MWMHints)/sizeof(long)); 711 XChangeProperty (SDL_Display, WMwindow,
695 set = SDL_TRUE; 712 WM_HINTS, WM_HINTS, 32,
696 } 713 PropModeReplace,
697 /* Now try to set KWM hints */ 714 (unsigned char *) &MWMHints,
698 WM_HINTS = XInternAtom(SDL_Display, "KWM_WIN_DECORATION", True); 715 sizeof (MWMHints) / sizeof (long));
699 if ( WM_HINTS != None ) { 716 set = SDL_TRUE;
700 long KWMHints = 0; 717 }
701 718 /* Now try to set KWM hints */
702 XChangeProperty(SDL_Display, WMwindow, 719 WM_HINTS = XInternAtom (SDL_Display, "KWM_WIN_DECORATION", True);
703 WM_HINTS, WM_HINTS, 32, 720 if (WM_HINTS != None) {
704 PropModeReplace, 721 long KWMHints = 0;
705 (unsigned char *)&KWMHints, 722
706 sizeof(KWMHints)/sizeof(long)); 723 XChangeProperty (SDL_Display, WMwindow,
707 set = SDL_TRUE; 724 WM_HINTS, WM_HINTS, 32,
708 } 725 PropModeReplace,
709 /* Now try to set GNOME hints */ 726 (unsigned char *) &KWMHints,
710 WM_HINTS = XInternAtom(SDL_Display, "_WIN_HINTS", True); 727 sizeof (KWMHints) / sizeof (long));
711 if ( WM_HINTS != None ) { 728 set = SDL_TRUE;
712 long GNOMEHints = 0; 729 }
713 730 /* Now try to set GNOME hints */
714 XChangeProperty(SDL_Display, WMwindow, 731 WM_HINTS = XInternAtom (SDL_Display, "_WIN_HINTS", True);
715 WM_HINTS, WM_HINTS, 32, 732 if (WM_HINTS != None) {
716 PropModeReplace, 733 long GNOMEHints = 0;
717 (unsigned char *)&GNOMEHints, 734
718 sizeof(GNOMEHints)/sizeof(long)); 735 XChangeProperty (SDL_Display, WMwindow,
719 set = SDL_TRUE; 736 WM_HINTS, WM_HINTS, 32,
720 } 737 PropModeReplace,
721 /* Finally set the transient hints if necessary */ 738 (unsigned char *) &GNOMEHints,
722 if ( ! set ) { 739 sizeof (GNOMEHints) / sizeof (long));
723 XSetTransientForHint(SDL_Display, WMwindow, SDL_Root); 740 set = SDL_TRUE;
724 } 741 }
725 } else { 742 /* Finally set the transient hints if necessary */
726 SDL_bool set; 743 if (!set) {
727 Atom WM_HINTS; 744 XSetTransientForHint (SDL_Display, WMwindow, SDL_Root);
728 745 }
729 /* We haven't modified the window manager hints yet */ 746 } else {
730 set = SDL_FALSE; 747 SDL_bool set;
731 748 Atom WM_HINTS;
732 /* First try to unset MWM hints */ 749
733 WM_HINTS = XInternAtom(SDL_Display, "_MOTIF_WM_HINTS", True); 750 /* We haven't modified the window manager hints yet */
734 if ( WM_HINTS != None ) { 751 set = SDL_FALSE;
735 XDeleteProperty(SDL_Display, WMwindow, WM_HINTS); 752
736 set = SDL_TRUE; 753 /* First try to unset MWM hints */
737 } 754 WM_HINTS = XInternAtom (SDL_Display, "_MOTIF_WM_HINTS", True);
738 /* Now try to unset KWM hints */ 755 if (WM_HINTS != None) {
739 WM_HINTS = XInternAtom(SDL_Display, "KWM_WIN_DECORATION", True); 756 XDeleteProperty (SDL_Display, WMwindow, WM_HINTS);
740 if ( WM_HINTS != None ) { 757 set = SDL_TRUE;
741 XDeleteProperty(SDL_Display, WMwindow, WM_HINTS); 758 }
742 set = SDL_TRUE; 759 /* Now try to unset KWM hints */
743 } 760 WM_HINTS = XInternAtom (SDL_Display, "KWM_WIN_DECORATION", True);
744 /* Now try to unset GNOME hints */ 761 if (WM_HINTS != None) {
745 WM_HINTS = XInternAtom(SDL_Display, "_WIN_HINTS", True); 762 XDeleteProperty (SDL_Display, WMwindow, WM_HINTS);
746 if ( WM_HINTS != None ) { 763 set = SDL_TRUE;
747 XDeleteProperty(SDL_Display, WMwindow, WM_HINTS); 764 }
748 set = SDL_TRUE; 765 /* Now try to unset GNOME hints */
749 } 766 WM_HINTS = XInternAtom (SDL_Display, "_WIN_HINTS", True);
750 /* Finally unset the transient hints if necessary */ 767 if (WM_HINTS != None) {
751 if ( ! set ) { 768 XDeleteProperty (SDL_Display, WMwindow, WM_HINTS);
752 /* NOTE: Does this work? */ 769 set = SDL_TRUE;
753 XSetTransientForHint(SDL_Display, WMwindow, None); 770 }
754 } 771 /* Finally unset the transient hints if necessary */
755 } 772 if (!set) {
756 } 773 /* NOTE: Does this work? */
757 774 XSetTransientForHint (SDL_Display, WMwindow, None);
758 static int X11_CreateWindow(_THIS, SDL_Surface *screen, 775 }
759 int w, int h, int bpp, Uint32 flags) 776 }
760 { 777 }
761 int i, depth; 778
762 Visual *vis; 779 static int
763 int vis_change; 780 X11_CreateWindow (_THIS, SDL_Surface * screen,
764 Uint32 Amask; 781 const SDL_DisplayMode * mode, Uint32 flags)
765 782 {
766 /* If a window is already present, destroy it and start fresh */ 783 int i, depth;
767 if ( SDL_Window ) { 784 Visual *vis;
768 X11_DestroyWindow(this, screen); 785 int vis_change;
769 switch_waiting = 0; /* Prevent jump back to now-meaningless state. */ 786 int bpp;
770 } 787 Uint32 Rmask, Gmask, Bmask, Amask;
771 788
772 /* See if we have been given a window id */ 789 SDL_PixelFormatEnumToMasks (mode->format, &bpp, &Rmask, &Gmask, &Bmask,
773 if ( SDL_windowid ) { 790 &Amask);
774 SDL_Window = SDL_strtol(SDL_windowid, NULL, 0); 791
775 } else { 792 /* If a window is already present, destroy it and start fresh */
776 SDL_Window = 0; 793 if (SDL_Window) {
777 } 794 X11_DestroyWindow (this, screen);
778 795 switch_waiting = 0; /* Prevent jump back to now-meaningless state. */
779 /* find out which visual we are going to use */ 796 }
780 if ( flags & SDL_INTERNALOPENGL ) { 797
781 XVisualInfo *vi; 798 /* See if we have been given a window id */
782 799 if (SDL_windowid) {
783 vi = X11_GL_GetVisual(this); 800 SDL_Window = SDL_strtol (SDL_windowid, NULL, 0);
784 if( !vi ) { 801 } else {
785 return -1; 802 SDL_Window = 0;
786 } 803 }
787 vis = vi->visual; 804
788 depth = vi->depth; 805 /* find out which visual we are going to use */
789 } else if ( SDL_windowid ) { 806 if (flags & SDL_INTERNALOPENGL) {
790 XWindowAttributes a; 807 XVisualInfo *vi;
791 808
792 XGetWindowAttributes(SDL_Display, SDL_Window, &a); 809 vi = X11_GL_GetVisual (this);
793 vis = a.visual; 810 if (!vi) {
794 depth = a.depth; 811 return -1;
795 } else { 812 }
796 for ( i = 0; i < this->hidden->nvisuals; i++ ) { 813 vis = vi->visual;
797 if ( this->hidden->visuals[i].bpp == bpp ) 814 depth = vi->depth;
798 break; 815 } else if (SDL_windowid) {
799 } 816 XWindowAttributes a;
800 if ( i == this->hidden->nvisuals ) { 817
801 SDL_SetError("No matching visual for requested depth"); 818 XGetWindowAttributes (SDL_Display, SDL_Window, &a);
802 return -1; /* should never happen */ 819 vis = a.visual;
803 } 820 depth = a.depth;
804 vis = this->hidden->visuals[i].visual; 821 } else {
805 depth = this->hidden->visuals[i].depth; 822 for (i = 0; i < this->hidden->nvisuals; i++) {
806 } 823 if (this->hidden->visuals[i].bpp == bpp &&
824 this->hidden->visuals[i].visual->red_mask == Rmask &&
825 this->hidden->visuals[i].visual->green_mask == Gmask &&
826 this->hidden->visuals[i].visual->blue_mask == Bmask)
827 break;
828 }
829 if (i == this->hidden->nvisuals) {
830 SDL_SetError ("No matching visual for requested depth");
831 return -1; /* should never happen */
832 }
833 vis = this->hidden->visuals[i].visual;
834 depth = this->hidden->visuals[i].depth;
835 }
807 #ifdef X11_DEBUG 836 #ifdef X11_DEBUG
808 printf("Choosing %s visual at %d bpp - %d colormap entries\n", vis->class == PseudoColor ? "PseudoColor" : (vis->class == TrueColor ? "TrueColor" : (vis->class == DirectColor ? "DirectColor" : "Unknown")), depth, vis->map_entries); 837 printf ("Choosing %s visual at %d bpp - %d colormap entries\n",
809 #endif 838 vis->class == PseudoColor ? "PseudoColor" : (vis->class ==
810 vis_change = (vis != SDL_Visual); 839 TrueColor ?
811 SDL_Visual = vis; 840 "TrueColor" : (vis->
812 this->hidden->depth = depth; 841 class
813 842 ==
814 /* Allocate the new pixel format for this video mode */ 843 DirectColor
815 if ( this->hidden->depth == 32 ) { 844 ?
816 Amask = (0xFFFFFFFF & ~(vis->red_mask|vis->green_mask|vis->blue_mask)); 845 "DirectColor"
817 } else { 846 :
818 Amask = 0; 847 "Unknown")),
819 } 848 depth, vis->map_entries);
820 if ( ! SDL_ReallocFormat(screen, bpp, 849 #endif
821 vis->red_mask, vis->green_mask, vis->blue_mask, Amask) ) { 850 vis_change = (vis != SDL_Visual);
822 return -1; 851 SDL_Visual = vis;
823 } 852 this->hidden->depth = depth;
824 853
825 /* Create the appropriate colormap */ 854 /* Allocate the new pixel format for this video mode */
826 if ( SDL_XColorMap != SDL_DisplayColormap ) { 855 if (!SDL_ReallocFormat (screen, bpp, Rmask, Gmask, Bmask, Amask)) {
827 XFreeColormap(SDL_Display, SDL_XColorMap); 856 return -1;
828 } 857 }
829 if ( SDL_Visual->class == PseudoColor ) { 858
830 int ncolors; 859 /* Create the appropriate colormap */
831 860 if (SDL_XColorMap != SDL_DisplayColormap) {
832 /* Allocate the pixel flags */ 861 XFreeColormap (SDL_Display, SDL_XColorMap);
833 ncolors = SDL_Visual->map_entries; 862 }
834 SDL_XPixels = SDL_malloc(ncolors * sizeof(int)); 863 if (SDL_Visual->class == PseudoColor) {
835 if(SDL_XPixels == NULL) { 864 int ncolors;
836 SDL_OutOfMemory(); 865
837 return -1; 866 /* Allocate the pixel flags */
838 } 867 ncolors = SDL_Visual->map_entries;
839 SDL_memset(SDL_XPixels, 0, ncolors * sizeof(*SDL_XPixels)); 868 SDL_XPixels = SDL_malloc (ncolors * sizeof (int));
840 869 if (SDL_XPixels == NULL) {
841 /* always allocate a private colormap on non-default visuals */ 870 SDL_OutOfMemory ();
842 if ( SDL_Visual != DefaultVisual(SDL_Display, SDL_Screen) ) { 871 return -1;
843 flags |= SDL_HWPALETTE; 872 }
844 } 873 SDL_memset (SDL_XPixels, 0, ncolors * sizeof (*SDL_XPixels));
845 if ( flags & SDL_HWPALETTE ) { 874
846 screen->flags |= SDL_HWPALETTE; 875 /* always allocate a private colormap on non-default visuals */
847 SDL_XColorMap = XCreateColormap(SDL_Display, SDL_Root, 876 if (SDL_Visual != DefaultVisual (SDL_Display, SDL_Screen)) {
848 SDL_Visual, AllocAll); 877 flags |= SDL_HWPALETTE;
849 } else { 878 }
850 SDL_XColorMap = SDL_DisplayColormap; 879 if (flags & SDL_HWPALETTE) {
851 } 880 screen->flags |= SDL_HWPALETTE;
852 } else if ( SDL_Visual->class == DirectColor ) { 881 SDL_XColorMap = XCreateColormap (SDL_Display, SDL_Root,
853 882 SDL_Visual, AllocAll);
854 /* Create a colormap which we can manipulate for gamma */ 883 } else {
855 SDL_XColorMap = XCreateColormap(SDL_Display, SDL_Root, 884 SDL_XColorMap = SDL_DisplayColormap;
856 SDL_Visual, AllocAll); 885 }
857 XSync(SDL_Display, False); 886 } else if (SDL_Visual->class == DirectColor) {
858 887
859 /* Initialize the colormap to the identity mapping */ 888 /* Create a colormap which we can manipulate for gamma */
860 SDL_GetGammaRamp(0, 0, 0); 889 SDL_XColorMap = XCreateColormap (SDL_Display, SDL_Root,
861 this->screen = screen; 890 SDL_Visual, AllocAll);
862 X11_SetGammaRamp(this, this->gamma); 891 XSync (SDL_Display, False);
863 this->screen = NULL; 892
864 } else { 893 /* Initialize the colormap to the identity mapping */
865 /* Create a read-only colormap for our window */ 894 SDL_GetGammaRamp (0, 0, 0);
866 SDL_XColorMap = XCreateColormap(SDL_Display, SDL_Root, 895 SDL_VideoSurface = screen;
867 SDL_Visual, AllocNone); 896 X11_SetGammaRamp (this, SDL_CurrentWindow.gamma);
868 } 897 SDL_VideoSurface = NULL;
869 898 } else {
870 /* Recreate the auxiliary windows, if needed (required for GL) */ 899 /* Create a read-only colormap for our window */
871 if ( vis_change ) 900 SDL_XColorMap = XCreateColormap (SDL_Display, SDL_Root,
872 create_aux_windows(this); 901 SDL_Visual, AllocNone);
873 902 }
874 if(screen->flags & SDL_HWPALETTE) { 903
875 /* Since the full-screen window might have got a nonzero background 904 /* Recreate the auxiliary windows, if needed (required for GL) */
876 colour (0 is white on some displays), we should reset the 905 if (vis_change)
877 background to 0 here since that is what the user expects 906 create_aux_windows (this);
878 with a private colormap */ 907
879 XSetWindowBackground(SDL_Display, FSwindow, 0); 908 if (screen->flags & SDL_HWPALETTE) {
880 XClearWindow(SDL_Display, FSwindow); 909 /* Since the full-screen window might have got a nonzero background
881 } 910 colour (0 is white on some displays), we should reset the
882 911 background to 0 here since that is what the user expects
883 /* resize the (possibly new) window manager window */ 912 with a private colormap */
884 if( !SDL_windowid ) { 913 XSetWindowBackground (SDL_Display, FSwindow, 0);
885 X11_SetSizeHints(this, w, h, flags); 914 XClearWindow (SDL_Display, FSwindow);
886 window_w = w; 915 }
887 window_h = h; 916
888 XResizeWindow(SDL_Display, WMwindow, w, h); 917 /* resize the (possibly new) window manager window */
889 } 918 if (!SDL_windowid) {
890 919 X11_SetSizeHints (this, mode->w, mode->h, flags);
891 /* Create (or use) the X11 display window */ 920 window_w = mode->w;
892 if ( !SDL_windowid ) { 921 window_h = mode->h;
893 if ( flags & SDL_INTERNALOPENGL ) { 922 XResizeWindow (SDL_Display, WMwindow, mode->w, mode->h);
894 if ( X11_GL_CreateWindow(this, w, h) < 0 ) { 923 }
895 return(-1); 924
896 } 925 /* Create (or use) the X11 display window */
897 } else { 926 if (!SDL_windowid) {
898 XSetWindowAttributes swa; 927 if (flags & SDL_INTERNALOPENGL) {
899 928 if (X11_GL_CreateWindow (this, mode->w, mode->h) < 0) {
900 swa.background_pixel = 0; 929 return (-1);
901 swa.border_pixel = 0; 930 }
902 swa.colormap = SDL_XColorMap; 931 } else {
903 SDL_Window = XCreateWindow(SDL_Display, WMwindow, 932 XSetWindowAttributes swa;
904 0, 0, w, h, 0, depth, 933
905 InputOutput, SDL_Visual, 934 swa.background_pixel = 0;
906 CWBackPixel | CWBorderPixel 935 swa.border_pixel = 0;
907 | CWColormap, &swa); 936 swa.colormap = SDL_XColorMap;
908 } 937 SDL_Window = XCreateWindow (SDL_Display, WMwindow,
909 /* Only manage our input if we own the window */ 938 0, 0, mode->w, mode->h, 0, depth,
910 XSelectInput(SDL_Display, SDL_Window, 939 InputOutput, SDL_Visual,
911 ( EnterWindowMask | LeaveWindowMask 940 CWBackPixel | CWBorderPixel
912 | ButtonPressMask | ButtonReleaseMask 941 | CWColormap, &swa);
913 | PointerMotionMask | ExposureMask )); 942 }
914 } 943 /* Only manage our input if we own the window */
915 /* Create the graphics context here, once we have a window */ 944 XSelectInput (SDL_Display, SDL_Window,
916 if ( flags & SDL_INTERNALOPENGL ) { 945 (EnterWindowMask | LeaveWindowMask
917 if ( X11_GL_CreateContext(this) < 0 ) { 946 | ButtonPressMask | ButtonReleaseMask
918 return(-1); 947 | PointerMotionMask | ExposureMask));
919 } else { 948 }
920 screen->flags |= SDL_INTERNALOPENGL; 949 /* Create the graphics context here, once we have a window */
921 } 950 if (flags & SDL_INTERNALOPENGL) {
922 } else { 951 if (X11_GL_CreateContext (this) < 0) {
923 XGCValues gcv; 952 return (-1);
924 953 } else {
925 gcv.graphics_exposures = False; 954 screen->flags |= SDL_INTERNALOPENGL;
926 SDL_GC = XCreateGC(SDL_Display, SDL_Window, 955 }
927 GCGraphicsExposures, &gcv); 956 } else {
928 if ( ! SDL_GC ) { 957 XGCValues gcv;
929 SDL_SetError("Couldn't create graphics context"); 958
930 return(-1); 959 gcv.graphics_exposures = False;
931 } 960 SDL_GC = XCreateGC (SDL_Display, SDL_Window,
932 } 961 GCGraphicsExposures, &gcv);
933 962 if (!SDL_GC) {
934 /* Set our colormaps when not setting a GL mode */ 963 SDL_SetError ("Couldn't create graphics context");
935 if ( ! (flags & SDL_INTERNALOPENGL) ) { 964 return (-1);
936 XSetWindowColormap(SDL_Display, SDL_Window, SDL_XColorMap); 965 }
937 if( !SDL_windowid ) { 966 }
938 XSetWindowColormap(SDL_Display, FSwindow, SDL_XColorMap); 967
939 XSetWindowColormap(SDL_Display, WMwindow, SDL_XColorMap); 968 /* Set our colormaps when not setting a GL mode */
940 } 969 if (!(flags & SDL_INTERNALOPENGL)) {
941 } 970 XSetWindowColormap (SDL_Display, SDL_Window, SDL_XColorMap);
942 971 if (!SDL_windowid) {
943 #if 0 /* This is an experiment - are the graphics faster now? - nope. */ 972 XSetWindowColormap (SDL_Display, FSwindow, SDL_XColorMap);
944 if ( SDL_getenv("SDL_VIDEO_X11_BACKINGSTORE") ) 973 XSetWindowColormap (SDL_Display, WMwindow, SDL_XColorMap);
945 #endif 974 }
946 /* Cache the window in the server, when possible */ 975 }
947 { 976 #if 0 /* This is an experiment - are the graphics faster now? - nope. */
948 Screen *xscreen; 977 if (SDL_getenv ("SDL_VIDEO_X11_BACKINGSTORE"))
949 XSetWindowAttributes a; 978 #endif
950 979 /* Cache the window in the server, when possible */
951 xscreen = ScreenOfDisplay(SDL_Display, SDL_Screen); 980 {
952 a.backing_store = DoesBackingStore(xscreen); 981 Screen *xscreen;
953 if ( a.backing_store != NotUseful ) { 982 XSetWindowAttributes a;
954 XChangeWindowAttributes(SDL_Display, SDL_Window, 983
955 CWBackingStore, &a); 984 xscreen = ScreenOfDisplay (SDL_Display, SDL_Screen);
956 } 985 a.backing_store = DoesBackingStore (xscreen);
957 } 986 if (a.backing_store != NotUseful) {
958 987 XChangeWindowAttributes (SDL_Display, SDL_Window,
959 /* Update the internal keyboard state */ 988 CWBackingStore, &a);
960 X11_SetKeyboardState(SDL_Display, NULL); 989 }
961 990 }
962 /* When the window is first mapped, ignore non-modifier keys */ 991
963 { 992 /* Update the internal keyboard state */
964 Uint8 *keys = SDL_GetKeyState(NULL); 993 X11_SetKeyboardState (SDL_Display, NULL);
965 for ( i = 0; i < SDLK_LAST; ++i ) { 994
966 switch (i) { 995 /* When the window is first mapped, ignore non-modifier keys */
967 case SDLK_NUMLOCK: 996 {
968 case SDLK_CAPSLOCK: 997 Uint8 *keys = SDL_GetKeyState (NULL);
969 case SDLK_LCTRL: 998 for (i = 0; i < SDLK_LAST; ++i) {
970 case SDLK_RCTRL: 999 switch (i) {
971 case SDLK_LSHIFT: 1000 case SDLK_NUMLOCK:
972 case SDLK_RSHIFT: 1001 case SDLK_CAPSLOCK:
973 case SDLK_LALT: 1002 case SDLK_LCTRL:
974 case SDLK_RALT: 1003 case SDLK_RCTRL:
975 case SDLK_LMETA: 1004 case SDLK_LSHIFT:
976 case SDLK_RMETA: 1005 case SDLK_RSHIFT:
977 case SDLK_MODE: 1006 case SDLK_LALT:
978 break; 1007 case SDLK_RALT:
979 default: 1008 case SDLK_LMETA:
980 keys[i] = SDL_RELEASED; 1009 case SDLK_RMETA:
981 break; 1010 case SDLK_MODE:
982 } 1011 break;
983 } 1012 default:
984 } 1013 keys[i] = SDL_RELEASED;
985 1014 break;
986 /* Map them both and go fullscreen, if requested */ 1015 }
987 if ( ! SDL_windowid ) { 1016 }
988 XMapWindow(SDL_Display, SDL_Window); 1017 }
989 XMapWindow(SDL_Display, WMwindow); 1018
990 X11_WaitMapped(this, WMwindow); 1019 /* Map them both and go fullscreen, if requested */
991 if ( flags & SDL_FULLSCREEN ) { 1020 if (!SDL_windowid) {
992 screen->flags |= SDL_FULLSCREEN; 1021 XMapWindow (SDL_Display, SDL_Window);
993 X11_EnterFullScreen(this); 1022 XMapWindow (SDL_Display, WMwindow);
994 } else { 1023 X11_WaitMapped (this, WMwindow);
995 screen->flags &= ~SDL_FULLSCREEN; 1024 if (flags & SDL_FULLSCREEN) {
996 } 1025 screen->flags |= SDL_FULLSCREEN;
997 } 1026 X11_EnterFullScreen (this);
998 1027 } else {
999 return(0); 1028 screen->flags &= ~SDL_FULLSCREEN;
1000 } 1029 }
1001 1030 }
1002 static int X11_ResizeWindow(_THIS, 1031
1003 SDL_Surface *screen, int w, int h, Uint32 flags) 1032 return (0);
1004 { 1033 }
1005 if ( ! SDL_windowid ) { 1034
1006 /* Resize the window manager window */ 1035 static int
1007 X11_SetSizeHints(this, w, h, flags); 1036 X11_ResizeWindow (_THIS, SDL_Surface * screen, int w, int h, Uint32 flags)
1008 window_w = w; 1037 {
1009 window_h = h; 1038 if (!SDL_windowid) {
1010 XResizeWindow(SDL_Display, WMwindow, w, h); 1039 /* Resize the window manager window */
1011 1040 X11_SetSizeHints (this, w, h, flags);
1012 /* Resize the fullscreen and display windows */ 1041 window_w = w;
1013 if ( flags & SDL_FULLSCREEN ) { 1042 window_h = h;
1014 if ( screen->flags & SDL_FULLSCREEN ) { 1043 XResizeWindow (SDL_Display, WMwindow, w, h);
1015 X11_ResizeFullScreen(this); 1044
1016 } else { 1045 /* Resize the fullscreen and display windows */
1017 screen->flags |= SDL_FULLSCREEN; 1046 if (flags & SDL_FULLSCREEN) {
1018 X11_EnterFullScreen(this); 1047 if (screen->flags & SDL_FULLSCREEN) {
1019 } 1048 X11_ResizeFullScreen (this);
1020 } else { 1049 } else {
1021 if ( screen->flags & SDL_FULLSCREEN ) { 1050 screen->flags |= SDL_FULLSCREEN;
1022 screen->flags &= ~SDL_FULLSCREEN; 1051 X11_EnterFullScreen (this);
1023 X11_LeaveFullScreen(this); 1052 }
1024 } 1053 } else {
1025 } 1054 if (screen->flags & SDL_FULLSCREEN) {
1026 XResizeWindow(SDL_Display, SDL_Window, w, h); 1055 screen->flags &= ~SDL_FULLSCREEN;
1027 } 1056 X11_LeaveFullScreen (this);
1028 return(0); 1057 }
1029 } 1058 }
1030 1059 XResizeWindow (SDL_Display, SDL_Window, w, h);
1031 SDL_Surface *X11_SetVideoMode(_THIS, SDL_Surface *current, 1060 }
1032 int width, int height, int bpp, Uint32 flags) 1061 return (0);
1033 { 1062 }
1034 Uint32 saved_flags; 1063
1035 1064 SDL_Surface *
1036 /* Lock the event thread, in multi-threading environments */ 1065 X11_SetVideoMode (_THIS, SDL_Surface * current,
1037 SDL_Lock_EventThread(); 1066 const SDL_DisplayMode * mode, Uint32 flags)
1038 1067 {
1039 /* Check the combination of flags we were passed */ 1068 Uint32 saved_flags;
1040 if ( flags & SDL_FULLSCREEN ) { 1069
1041 /* Clear fullscreen flag if not supported */ 1070 /* Lock the event thread, in multi-threading environments */
1042 if ( SDL_windowid ) { 1071 SDL_Lock_EventThread ();
1043 flags &= ~SDL_FULLSCREEN; 1072
1044 } 1073 /* Check the combination of flags we were passed */
1045 } 1074 if (flags & SDL_FULLSCREEN) {
1046 1075 /* Clear fullscreen flag if not supported */
1047 /* Flush any delayed updates */ 1076 if (SDL_windowid) {
1048 XSync(GFX_Display, False); 1077 flags &= ~SDL_FULLSCREEN;
1049 1078 }
1050 /* Set up the X11 window */ 1079 }
1051 saved_flags = current->flags; 1080
1052 if ( (SDL_Window) && ((saved_flags&SDL_INTERNALOPENGL) == (flags&SDL_INTERNALOPENGL)) 1081 /* Flush any delayed updates */
1053 && (bpp == current->format->BitsPerPixel) 1082 XSync (GFX_Display, False);
1054 && ((saved_flags&SDL_NOFRAME) == (flags&SDL_NOFRAME)) ) { 1083
1055 if (X11_ResizeWindow(this, current, width, height, flags) < 0) { 1084 /* Set up the X11 window */
1056 current = NULL; 1085 saved_flags = current->flags;
1057 goto done; 1086 if ((SDL_Window)
1058 } 1087 && ((saved_flags & SDL_INTERNALOPENGL) ==
1059 } else { 1088 (flags & SDL_INTERNALOPENGL))
1060 if (X11_CreateWindow(this,current,width,height,bpp,flags) < 0) { 1089 && (mode->format == SDL_CurrentDisplay.current_mode.format)
1061 current = NULL; 1090 && ((saved_flags & SDL_NOFRAME) == (flags & SDL_NOFRAME))) {
1062 goto done; 1091 if (X11_ResizeWindow (this, current, mode->w, mode->h, flags) < 0) {
1063 } 1092 current = NULL;
1064 } 1093 goto done;
1065 1094 }
1066 /* Set up the new mode framebuffer */ 1095 } else {
1067 if ( ((current->w != width) || (current->h != height)) || 1096 if (X11_CreateWindow (this, current, mode, flags) < 0) {
1068 ((saved_flags&SDL_INTERNALOPENGL) != (flags&SDL_INTERNALOPENGL)) ) { 1097 current = NULL;
1069 current->w = width; 1098 goto done;
1070 current->h = height; 1099 }
1071 current->pitch = SDL_CalculatePitch(current); 1100 }
1072 X11_ResizeImage(this, current, flags); 1101
1073 } 1102 /* Set up the new mode framebuffer */
1074 current->flags |= (flags&(SDL_RESIZABLE|SDL_NOFRAME)); 1103 if (((current->w != mode->w) || (current->h != mode->h)) ||
1104 ((saved_flags & SDL_INTERNALOPENGL) != (flags & SDL_INTERNALOPENGL)))
1105 {
1106 current->w = mode->w;
1107 current->h = mode->h;
1108 current->pitch = SDL_CalculatePitch (current);
1109 X11_ResizeImage (this, current, flags);
1110 }
1111 current->flags |= (flags & (SDL_RESIZABLE | SDL_NOFRAME));
1075 1112
1076 done: 1113 done:
1077 /* Release the event thread */ 1114 /* Release the event thread */
1078 XSync(SDL_Display, False); 1115 XSync (SDL_Display, False);
1079 SDL_Unlock_EventThread(); 1116 SDL_Unlock_EventThread ();
1080 1117
1081 /* We're done! */ 1118 /* We're done! */
1082 return(current); 1119 return (current);
1083 } 1120 }
1084 1121
1085 static int X11_ToggleFullScreen(_THIS, int on) 1122 static int
1086 { 1123 X11_ToggleFullScreen (_THIS, int on)
1087 Uint32 event_thread; 1124 {
1088 1125 Uint32 event_thread;
1089 /* Don't switch if we don't own the window */ 1126
1090 if ( SDL_windowid ) { 1127 /* Don't switch if we don't own the window */
1091 return(0); 1128 if (SDL_windowid) {
1092 } 1129 return (0);
1093 1130 }
1094 /* Don't lock if we are the event thread */ 1131
1095 event_thread = SDL_EventThreadID(); 1132 /* Don't lock if we are the event thread */
1096 if ( event_thread && (SDL_ThreadID() == event_thread) ) { 1133 event_thread = SDL_EventThreadID ();
1097 event_thread = 0; 1134 if (event_thread && (SDL_ThreadID () == event_thread)) {
1098 } 1135 event_thread = 0;
1099 if ( event_thread ) { 1136 }
1100 SDL_Lock_EventThread(); 1137 if (event_thread) {
1101 } 1138 SDL_Lock_EventThread ();
1102 if ( on ) { 1139 }
1103 this->screen->flags |= SDL_FULLSCREEN; 1140 if (on) {
1104 X11_EnterFullScreen(this); 1141 SDL_VideoSurface->flags |= SDL_FULLSCREEN;
1105 } else { 1142 X11_EnterFullScreen (this);
1106 this->screen->flags &= ~SDL_FULLSCREEN; 1143 } else {
1107 X11_LeaveFullScreen(this); 1144 SDL_VideoSurface->flags &= ~SDL_FULLSCREEN;
1108 } 1145 X11_LeaveFullScreen (this);
1109 X11_RefreshDisplay(this); 1146 }
1110 if ( event_thread ) { 1147 X11_RefreshDisplay (this);
1111 SDL_Unlock_EventThread(); 1148 if (event_thread) {
1112 } 1149 SDL_Unlock_EventThread ();
1113 SDL_ResetKeyboard(); 1150 }
1114 return(1); 1151 SDL_ResetKeyboard ();
1152 return (1);
1115 } 1153 }
1116 1154
1117 /* Update the current mouse state and position */ 1155 /* Update the current mouse state and position */
1118 static void X11_UpdateMouse(_THIS) 1156 static void
1119 { 1157 X11_UpdateMouse (_THIS)
1120 Window u1; int u2; 1158 {
1121 Window current_win; 1159 Window u1;
1122 int x, y; 1160 int u2;
1123 unsigned int mask; 1161 Window current_win;
1124 1162 int x, y;
1125 /* Lock the event thread, in multi-threading environments */ 1163 unsigned int mask;
1126 SDL_Lock_EventThread(); 1164
1127 if ( XQueryPointer(SDL_Display, SDL_Window, &u1, &current_win, 1165 /* Lock the event thread, in multi-threading environments */
1128 &u2, &u2, &x, &y, &mask) ) { 1166 SDL_Lock_EventThread ();
1129 if ( (x >= 0) && (x < SDL_VideoSurface->w) && 1167 if (XQueryPointer (SDL_Display, SDL_Window, &u1, &current_win,
1130 (y >= 0) && (y < SDL_VideoSurface->h) ) { 1168 &u2, &u2, &x, &y, &mask)) {
1131 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); 1169 if ((x >= 0) && (x < SDL_VideoSurface->w) &&
1132 SDL_PrivateMouseMotion(0, 0, x, y); 1170 (y >= 0) && (y < SDL_VideoSurface->h)) {
1133 } else { 1171 SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS);
1134 SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS); 1172 SDL_PrivateMouseMotion (0, 0, x, y);
1135 } 1173 } else {
1136 } 1174 SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS);
1137 SDL_Unlock_EventThread(); 1175 }
1176 }
1177 SDL_Unlock_EventThread ();
1138 } 1178 }
1139 1179
1140 /* simple colour distance metric. Supposed to be better than a plain 1180 /* simple colour distance metric. Supposed to be better than a plain
1141 Euclidian distance anyway. */ 1181 Euclidian distance anyway. */
1142 #define COLOUR_FACTOR 3 1182 #define COLOUR_FACTOR 3
1143 #define LIGHT_FACTOR 1 1183 #define LIGHT_FACTOR 1
1144 #define COLOUR_DIST(r1, g1, b1, r2, g2, b2) \ 1184 #define COLOUR_DIST(r1, g1, b1, r2, g2, b2) \
1145 (COLOUR_FACTOR * (abs(r1 - r2) + abs(g1 - g2) + abs(b1 - b2)) \ 1185 (COLOUR_FACTOR * (abs(r1 - r2) + abs(g1 - g2) + abs(b1 - b2)) \
1146 + LIGHT_FACTOR * abs(r1 + g1 + b1 - (r2 + g2 + b2))) 1186 + LIGHT_FACTOR * abs(r1 + g1 + b1 - (r2 + g2 + b2)))
1147 1187
1148 static void allocate_nearest(_THIS, SDL_Color *colors, 1188 static void
1149 SDL_Color *want, int nwant) 1189 allocate_nearest (_THIS, SDL_Color * colors, SDL_Color * want, int nwant)
1150 { 1190 {
1151 /* 1191 /*
1152 * There is no way to know which ones to choose from, so we retrieve 1192 * There is no way to know which ones to choose from, so we retrieve
1153 * the entire colormap and try the nearest possible, until we find one 1193 * the entire colormap and try the nearest possible, until we find one
1154 * that is shared. 1194 * that is shared.
1155 */ 1195 */
1156 XColor all[256]; 1196 XColor all[256];
1157 int i; 1197 int i;
1158 for(i = 0; i < 256; i++) 1198 for (i = 0; i < 256; i++)
1159 all[i].pixel = i; 1199 all[i].pixel = i;
1160 /* 1200 /*
1161 * XQueryColors sets the flags in the XColor struct, so we use 1201 * XQueryColors sets the flags in the XColor struct, so we use
1162 * that to keep track of which colours are available 1202 * that to keep track of which colours are available
1163 */ 1203 */
1164 XQueryColors(GFX_Display, SDL_XColorMap, all, 256); 1204 XQueryColors (GFX_Display, SDL_XColorMap, all, 256);
1165 1205
1166 for(i = 0; i < nwant; i++) { 1206 for (i = 0; i < nwant; i++) {
1167 XColor *c; 1207 XColor *c;
1168 int j; 1208 int j;
1169 int best = 0; 1209 int best = 0;
1170 int mindist = 0x7fffffff; 1210 int mindist = 0x7fffffff;
1171 int ri = want[i].r; 1211 int ri = want[i].r;
1172 int gi = want[i].g; 1212 int gi = want[i].g;
1173 int bi = want[i].b; 1213 int bi = want[i].b;
1174 for(j = 0; j < 256; j++) { 1214 for (j = 0; j < 256; j++) {
1175 int rj, gj, bj, d2; 1215 int rj, gj, bj, d2;
1176 if(!all[j].flags) 1216 if (!all[j].flags)
1177 continue; /* unavailable colour cell */ 1217 continue; /* unavailable colour cell */
1178 rj = all[j].red >> 8; 1218 rj = all[j].red >> 8;
1179 gj = all[j].green >> 8; 1219 gj = all[j].green >> 8;
1180 bj = all[j].blue >> 8; 1220 bj = all[j].blue >> 8;
1181 d2 = COLOUR_DIST(ri, gi, bi, rj, gj, bj); 1221 d2 = COLOUR_DIST (ri, gi, bi, rj, gj, bj);
1182 if(d2 < mindist) { 1222 if (d2 < mindist) {
1183 mindist = d2; 1223 mindist = d2;
1184 best = j; 1224 best = j;
1185 } 1225 }
1186 } 1226 }
1187 if(SDL_XPixels[best]) 1227 if (SDL_XPixels[best])
1188 continue; /* already allocated, waste no more time */ 1228 continue; /* already allocated, waste no more time */
1189 c = all + best; 1229 c = all + best;
1190 if(XAllocColor(GFX_Display, SDL_XColorMap, c)) { 1230 if (XAllocColor (GFX_Display, SDL_XColorMap, c)) {
1191 /* got it */ 1231 /* got it */
1192 colors[c->pixel].r = c->red >> 8; 1232 colors[c->pixel].r = c->red >> 8;
1193 colors[c->pixel].g = c->green >> 8; 1233 colors[c->pixel].g = c->green >> 8;
1194 colors[c->pixel].b = c->blue >> 8; 1234 colors[c->pixel].b = c->blue >> 8;
1195 ++SDL_XPixels[c->pixel]; 1235 ++SDL_XPixels[c->pixel];
1196 } else { 1236 } else {
1197 /* 1237 /*
1198 * The colour couldn't be allocated, probably being 1238 * The colour couldn't be allocated, probably being
1199 * owned as a r/w cell by another client. Flag it as 1239 * owned as a r/w cell by another client. Flag it as
1200 * unavailable and try again. The termination of the 1240 * unavailable and try again. The termination of the
1201 * loop is guaranteed since at least black and white 1241 * loop is guaranteed since at least black and white
1202 * are always there. 1242 * are always there.
1203 */ 1243 */
1204 c->flags = 0; 1244 c->flags = 0;
1205 i--; 1245 i--;
1206 } 1246 }
1207 } 1247 }
1208 } 1248 }
1209 1249
1210 int X11_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) 1250 int
1211 { 1251 X11_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors)
1212 int nrej = 0; 1252 {
1213 1253 int nrej = 0;
1214 /* Check to make sure we have a colormap allocated */ 1254
1215 if ( SDL_XPixels == NULL ) { 1255 /* Check to make sure we have a colormap allocated */
1216 return(0); 1256 if (SDL_XPixels == NULL) {
1217 } 1257 return (0);
1218 if ( (this->screen->flags & SDL_HWPALETTE) == SDL_HWPALETTE ) { 1258 }
1219 /* private writable colormap: just set the colours we need */ 1259 if ((SDL_VideoSurface->flags & SDL_HWPALETTE) == SDL_HWPALETTE) {
1220 XColor *xcmap; 1260 /* private writable colormap: just set the colours we need */
1221 int i; 1261 XColor *xcmap;
1222 xcmap = SDL_stack_alloc(XColor, ncolors); 1262 int i;
1223 if(xcmap == NULL) 1263 xcmap = SDL_stack_alloc (XColor, ncolors);
1224 return 0; 1264 if (xcmap == NULL)
1225 for ( i=0; i<ncolors; ++i ) { 1265 return 0;
1226 xcmap[i].pixel = i + firstcolor; 1266 for (i = 0; i < ncolors; ++i) {
1227 xcmap[i].red = (colors[i].r<<8)|colors[i].r; 1267 xcmap[i].pixel = i + firstcolor;
1228 xcmap[i].green = (colors[i].g<<8)|colors[i].g; 1268 xcmap[i].red = (colors[i].r << 8) | colors[i].r;
1229 xcmap[i].blue = (colors[i].b<<8)|colors[i].b; 1269 xcmap[i].green = (colors[i].g << 8) | colors[i].g;
1230 xcmap[i].flags = (DoRed|DoGreen|DoBlue); 1270 xcmap[i].blue = (colors[i].b << 8) | colors[i].b;
1231 } 1271 xcmap[i].flags = (DoRed | DoGreen | DoBlue);
1232 XStoreColors(GFX_Display, SDL_XColorMap, xcmap, ncolors); 1272 }
1233 XSync(GFX_Display, False); 1273 XStoreColors (GFX_Display, SDL_XColorMap, xcmap, ncolors);
1234 SDL_stack_free(xcmap); 1274 XSync (GFX_Display, False);
1235 } else { 1275 SDL_stack_free (xcmap);
1236 /* 1276 } else {
1237 * Shared colormap: We only allocate read-only cells, which 1277 /*
1238 * increases the likelyhood of colour sharing with other 1278 * Shared colormap: We only allocate read-only cells, which
1239 * clients. The pixel values will almost certainly be 1279 * increases the likelyhood of colour sharing with other
1240 * different from the requested ones, so the user has to 1280 * clients. The pixel values will almost certainly be
1241 * walk the colormap and see which index got what colour. 1281 * different from the requested ones, so the user has to
1242 * 1282 * walk the colormap and see which index got what colour.
1243 * We can work directly with the logical palette since it 1283 *
1244 * has already been set when we get here. 1284 * We can work directly with the logical palette since it
1245 */ 1285 * has already been set when we get here.
1246 SDL_Color *want, *reject; 1286 */
1247 unsigned long *freelist; 1287 SDL_Color *want, *reject;
1248 int i; 1288 unsigned long *freelist;
1249 int nfree = 0; 1289 int i;
1250 int nc = this->screen->format->palette->ncolors; 1290 int nfree = 0;
1251 colors = this->screen->format->palette->colors; 1291 int nc = SDL_VideoSurface->format->palette->ncolors;
1252 freelist = SDL_stack_alloc(unsigned long, nc); 1292 colors = SDL_VideoSurface->format->palette->colors;
1253 /* make sure multiple allocations of the same cell are freed */ 1293 freelist = SDL_stack_alloc (unsigned long, nc);
1254 for(i = 0; i < ncolors; i++) { 1294 /* make sure multiple allocations of the same cell are freed */
1255 int pixel = firstcolor + i; 1295 for (i = 0; i < ncolors; i++) {
1256 while(SDL_XPixels[pixel]) { 1296 int pixel = firstcolor + i;
1257 freelist[nfree++] = pixel; 1297 while (SDL_XPixels[pixel]) {
1258 --SDL_XPixels[pixel]; 1298 freelist[nfree++] = pixel;
1259 } 1299 --SDL_XPixels[pixel];
1260 } 1300 }
1261 XFreeColors(GFX_Display, SDL_XColorMap, freelist, nfree, 0); 1301 }
1262 SDL_stack_free(freelist); 1302 XFreeColors (GFX_Display, SDL_XColorMap, freelist, nfree, 0);
1263 1303 SDL_stack_free (freelist);
1264 want = SDL_stack_alloc(SDL_Color, ncolors); 1304
1265 reject = SDL_stack_alloc(SDL_Color, ncolors); 1305 want = SDL_stack_alloc (SDL_Color, ncolors);
1266 SDL_memcpy(want, colors + firstcolor, ncolors * sizeof(SDL_Color)); 1306 reject = SDL_stack_alloc (SDL_Color, ncolors);
1267 /* make sure the user isn't fooled by her own wishes 1307 SDL_memcpy (want, colors + firstcolor, ncolors * sizeof (SDL_Color));
1268 (black is safe, always available in the default colormap) */ 1308 /* make sure the user isn't fooled by her own wishes
1269 SDL_memset(colors + firstcolor, 0, ncolors * sizeof(SDL_Color)); 1309 (black is safe, always available in the default colormap) */
1270 1310 SDL_memset (colors + firstcolor, 0, ncolors * sizeof (SDL_Color));
1271 /* now try to allocate the colours */ 1311
1272 for(i = 0; i < ncolors; i++) { 1312 /* now try to allocate the colours */
1273 XColor col; 1313 for (i = 0; i < ncolors; i++) {
1274 col.red = want[i].r << 8; 1314 XColor col;
1275 col.green = want[i].g << 8; 1315 col.red = want[i].r << 8;
1276 col.blue = want[i].b << 8; 1316 col.green = want[i].g << 8;
1277 col.flags = DoRed | DoGreen | DoBlue; 1317 col.blue = want[i].b << 8;
1278 if(XAllocColor(GFX_Display, SDL_XColorMap, &col)) { 1318 col.flags = DoRed | DoGreen | DoBlue;
1279 /* We got the colour, or at least the nearest 1319 if (XAllocColor (GFX_Display, SDL_XColorMap, &col)) {
1280 the hardware could get. */ 1320 /* We got the colour, or at least the nearest
1281 colors[col.pixel].r = col.red >> 8; 1321 the hardware could get. */
1282 colors[col.pixel].g = col.green >> 8; 1322 colors[col.pixel].r = col.red >> 8;
1283 colors[col.pixel].b = col.blue >> 8; 1323 colors[col.pixel].g = col.green >> 8;
1284 ++SDL_XPixels[col.pixel]; 1324 colors[col.pixel].b = col.blue >> 8;
1285 } else { 1325 ++SDL_XPixels[col.pixel];
1286 /* 1326 } else {
1287 * no more free cells, add it to the list 1327 /*
1288 * of rejected colours 1328 * no more free cells, add it to the list
1289 */ 1329 * of rejected colours
1290 reject[nrej++] = want[i]; 1330 */
1291 } 1331 reject[nrej++] = want[i];
1292 } 1332 }
1293 if(nrej) 1333 }
1294 allocate_nearest(this, colors, reject, nrej); 1334 if (nrej)
1295 SDL_stack_free(reject); 1335 allocate_nearest (this, colors, reject, nrej);
1296 SDL_stack_free(want); 1336 SDL_stack_free (reject);
1297 } 1337 SDL_stack_free (want);
1298 return nrej == 0; 1338 }
1299 } 1339 return nrej == 0;
1300 1340 }
1301 int X11_SetGammaRamp(_THIS, Uint16 *ramp) 1341
1302 { 1342 int
1303 int i, ncolors; 1343 X11_SetGammaRamp (_THIS, Uint16 * ramp)
1304 XColor xcmap[256]; 1344 {
1305 1345 int i, ncolors;
1306 /* See if actually setting the gamma is supported */ 1346 XColor xcmap[256];
1307 if ( SDL_Visual->class != DirectColor ) { 1347
1308 SDL_SetError("Gamma correction not supported on this visual"); 1348 /* See if actually setting the gamma is supported */
1309 return(-1); 1349 if (SDL_Visual->class != DirectColor) {
1310 } 1350 SDL_SetError ("Gamma correction not supported on this visual");
1311 1351 return (-1);
1312 /* Calculate the appropriate palette for the given gamma ramp */ 1352 }
1313 ncolors = SDL_Visual->map_entries; 1353
1314 for ( i=0; i<ncolors; ++i ) { 1354 /* Calculate the appropriate palette for the given gamma ramp */
1315 Uint8 c = (256 * i / ncolors); 1355 ncolors = SDL_Visual->map_entries;
1316 xcmap[i].pixel = SDL_MapRGB(this->screen->format, c, c, c); 1356 for (i = 0; i < ncolors; ++i) {
1317 xcmap[i].red = ramp[0*256+c]; 1357 Uint8 c = (256 * i / ncolors);
1318 xcmap[i].green = ramp[1*256+c]; 1358 xcmap[i].pixel = SDL_MapRGB (SDL_VideoSurface->format, c, c, c);
1319 xcmap[i].blue = ramp[2*256+c]; 1359 xcmap[i].red = ramp[0 * 256 + c];
1320 xcmap[i].flags = (DoRed|DoGreen|DoBlue); 1360 xcmap[i].green = ramp[1 * 256 + c];
1321 } 1361 xcmap[i].blue = ramp[2 * 256 + c];
1322 XStoreColors(GFX_Display, SDL_XColorMap, xcmap, ncolors); 1362 xcmap[i].flags = (DoRed | DoGreen | DoBlue);
1323 XSync(GFX_Display, False); 1363 }
1324 return(0); 1364 XStoreColors (GFX_Display, SDL_XColorMap, xcmap, ncolors);
1365 XSync (GFX_Display, False);
1366 return (0);
1325 } 1367 }
1326 1368
1327 /* Note: If we are terminated, this could be called in the middle of 1369 /* Note: If we are terminated, this could be called in the middle of
1328 another SDL video routine -- notably UpdateRects. 1370 another SDL video routine -- notably UpdateRects.
1329 */ 1371 */
1330 void X11_VideoQuit(_THIS) 1372 void
1331 { 1373 X11_VideoQuit (_THIS)
1332 /* Shutdown everything that's still up */ 1374 {
1333 /* The event thread should be done, so we can touch SDL_Display */ 1375 /* Shutdown everything that's still up */
1334 if ( SDL_Display != NULL ) { 1376 /* The event thread should be done, so we can touch SDL_Display */
1335 /* Flush any delayed updates */ 1377 if (SDL_Display != NULL) {
1336 XSync(GFX_Display, False); 1378 /* Flush any delayed updates */
1337 1379 XSync (GFX_Display, False);
1338 /* Close the connection with the IM server */ 1380
1339 #ifdef X_HAVE_UTF8_STRING 1381 /* Close the connection with the IM server */
1340 if (SDL_IC != NULL) { 1382 #ifdef X_HAVE_UTF8_STRING
1341 XDestroyIC(SDL_IC); 1383 if (SDL_IC != NULL) {
1342 SDL_IC = NULL; 1384 XDestroyIC (SDL_IC);
1343 } 1385 SDL_IC = NULL;
1344 if (SDL_IM != NULL) { 1386 }
1345 XCloseIM(SDL_IM); 1387 if (SDL_IM != NULL) {
1346 SDL_IM = NULL; 1388 XCloseIM (SDL_IM);
1347 } 1389 SDL_IM = NULL;
1348 #endif 1390 }
1349 1391 #endif
1350 /* Start shutting down the windows */ 1392
1351 X11_DestroyImage(this, this->screen); 1393 /* Start shutting down the windows */
1352 X11_DestroyWindow(this, this->screen); 1394 X11_DestroyImage (this, SDL_VideoSurface);
1353 X11_FreeVideoModes(this); 1395 X11_DestroyWindow (this, SDL_VideoSurface);
1354 if ( SDL_XColorMap != SDL_DisplayColormap ) { 1396 X11_FreeVideoModes (this);
1355 XFreeColormap(SDL_Display, SDL_XColorMap); 1397 if (SDL_XColorMap != SDL_DisplayColormap) {
1356 } 1398 XFreeColormap (SDL_Display, SDL_XColorMap);
1357 if ( SDL_iconcolors ) { 1399 }
1358 unsigned long pixel; 1400 if (SDL_iconcolors) {
1359 Colormap dcmap = DefaultColormap(SDL_Display, 1401 unsigned long pixel;
1360 SDL_Screen); 1402 Colormap dcmap = DefaultColormap (SDL_Display,
1361 for(pixel = 0; pixel < 256; ++pixel) { 1403 SDL_Screen);
1362 while(SDL_iconcolors[pixel] > 0) { 1404 for (pixel = 0; pixel < 256; ++pixel) {
1363 XFreeColors(GFX_Display, 1405 while (SDL_iconcolors[pixel] > 0) {
1364 dcmap, &pixel, 1, 0); 1406 XFreeColors (GFX_Display, dcmap, &pixel, 1, 0);
1365 --SDL_iconcolors[pixel]; 1407 --SDL_iconcolors[pixel];
1366 } 1408 }
1367 } 1409 }
1368 SDL_free(SDL_iconcolors); 1410 SDL_free (SDL_iconcolors);
1369 SDL_iconcolors = NULL; 1411 SDL_iconcolors = NULL;
1370 } 1412 }
1371 1413 if (xinerama) {
1372 /* Restore gamma settings if they've changed */ 1414 XFree (xinerama);
1373 if ( SDL_GetAppState() & SDL_APPACTIVE ) { 1415 }
1374 X11_SwapVidModeGamma(this); 1416
1375 } 1417 /* Restore gamma settings if they've changed */
1376 1418 if (SDL_GetAppState () & SDL_APPACTIVE) {
1377 /* Restore DPMS and screensaver settings */ 1419 X11_SwapVidModeGamma (this);
1378 X11_RestoreScreenSaver(SDL_Display, screensaver_timeout, dpms_enabled); 1420 }
1379 1421
1380 /* Free that blank cursor */ 1422 /* Restore DPMS and screensaver settings */
1381 if ( SDL_BlankCursor != NULL ) { 1423 X11_RestoreScreenSaver (SDL_Display, screensaver_timeout,
1382 this->FreeWMCursor(this, SDL_BlankCursor); 1424 dpms_enabled);
1383 SDL_BlankCursor = NULL; 1425
1384 } 1426 /* Free that blank cursor */
1385 1427 if (SDL_BlankCursor != NULL) {
1386 /* Close the X11 graphics connection */ 1428 this->FreeWMCursor (this, SDL_BlankCursor);
1387 if ( GFX_Display != NULL ) { 1429 SDL_BlankCursor = NULL;
1388 XCloseDisplay(GFX_Display); 1430 }
1389 GFX_Display = NULL; 1431
1390 } 1432 /* Close the X11 graphics connection */
1391 1433 if (GFX_Display != NULL) {
1392 /* Close the X11 display connection */ 1434 XCloseDisplay (GFX_Display);
1393 XCloseDisplay(SDL_Display); 1435 GFX_Display = NULL;
1394 SDL_Display = NULL; 1436 }
1395 1437
1396 /* Reset the X11 error handlers */ 1438 /* Close the X11 display connection */
1397 if ( XIO_handler ) { 1439 XCloseDisplay (SDL_Display);
1398 XSetIOErrorHandler(XIO_handler); 1440 SDL_Display = NULL;
1399 } 1441
1400 if ( X_handler ) { 1442 /* Reset the X11 error handlers */
1401 XSetErrorHandler(X_handler); 1443 if (XIO_handler) {
1402 } 1444 XSetIOErrorHandler (XIO_handler);
1403 1445 }
1404 /* Unload GL library after X11 shuts down */ 1446 if (X_handler) {
1405 X11_GL_UnloadLibrary(this); 1447 XSetErrorHandler (X_handler);
1406 } 1448 }
1407 if ( this->screen && (this->screen->flags & SDL_HWSURFACE) ) { 1449
1408 /* Direct screen access, no memory buffer */ 1450 /* Unload GL library after X11 shuts down */
1409 this->screen->pixels = NULL; 1451 X11_GL_UnloadLibrary (this);
1410 } 1452 }
1411 } 1453 if (SDL_VideoSurface && (SDL_VideoSurface->flags & SDL_HWSURFACE)) {
1412 1454 /* Direct screen access, no memory buffer */
1455 SDL_VideoSurface->pixels = NULL;
1456 }
1457 }
1458
1459 /* vi: set ts=4 sw=4 expandtab: */