Skip to content

Latest commit

 

History

History
1549 lines (1395 loc) · 43.8 KB

SDL_x11video.c

File metadata and controls

1549 lines (1395 loc) · 43.8 KB
 
Apr 26, 2001
Apr 26, 2001
1
2
/*
SDL - Simple DirectMedia Layer
Feb 1, 2006
Feb 1, 2006
3
Copyright (C) 1997-2006 Sam Lantinga
Apr 26, 2001
Apr 26, 2001
4
5
This library is free software; you can redistribute it and/or
Feb 1, 2006
Feb 1, 2006
6
modify it under the terms of the GNU Lesser General Public
Apr 26, 2001
Apr 26, 2001
7
License as published by the Free Software Foundation; either
Feb 1, 2006
Feb 1, 2006
8
version 2.1 of the License, or (at your option) any later version.
Apr 26, 2001
Apr 26, 2001
9
10
11
12
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Feb 1, 2006
Feb 1, 2006
13
Lesser General Public License for more details.
Apr 26, 2001
Apr 26, 2001
14
Feb 1, 2006
Feb 1, 2006
15
16
17
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Apr 26, 2001
Apr 26, 2001
18
19
Sam Lantinga
Dec 14, 2001
Dec 14, 2001
20
slouken@libsdl.org
Apr 26, 2001
Apr 26, 2001
21
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
Apr 26, 2001
Apr 26, 2001
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* X11 based SDL video driver implementation.
Note: This implementation does not currently need X11 thread locking,
since the event thread uses a separate X connection and any
additional locking necessary is handled internally. However,
if full locking is neccessary, take a look at XInitThreads().
*/
#include <unistd.h>
#include <sys/ioctl.h>
#ifdef MTRR_SUPPORT
#include <asm/mtrr.h>
#include <sys/fcntl.h>
#endif
Feb 10, 2006
Feb 10, 2006
38
#include "SDL_endian.h"
Apr 26, 2001
Apr 26, 2001
39
40
41
42
#include "SDL_timer.h"
#include "SDL_thread.h"
#include "SDL_video.h"
#include "SDL_mouse.h"
Feb 16, 2006
Feb 16, 2006
43
44
45
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "../../events/SDL_events_c.h"
Apr 26, 2001
Apr 26, 2001
46
47
48
49
50
51
52
53
54
#include "SDL_x11video.h"
#include "SDL_x11wm_c.h"
#include "SDL_x11mouse_c.h"
#include "SDL_x11events_c.h"
#include "SDL_x11modes_c.h"
#include "SDL_x11image_c.h"
#include "SDL_x11yuv_c.h"
#include "SDL_x11gl_c.h"
#include "SDL_x11gamma_c.h"
Feb 16, 2006
Feb 16, 2006
55
#include "../blank_cursor.h"
Apr 26, 2001
Apr 26, 2001
56
Jun 25, 2007
Jun 25, 2007
57
58
59
60
#ifdef X_HAVE_UTF8_STRING
#include <locale.h>
#endif
Apr 26, 2001
Apr 26, 2001
61
62
63
64
65
66
67
68
69
70
/* Initialization/Query functions */
static int X11_VideoInit(_THIS, SDL_PixelFormat *vformat);
static SDL_Surface *X11_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
static int X11_ToggleFullScreen(_THIS, int on);
static void X11_UpdateMouse(_THIS);
static int X11_SetColors(_THIS, int firstcolor, int ncolors,
SDL_Color *colors);
static int X11_SetGammaRamp(_THIS, Uint16 *ramp);
static void X11_VideoQuit(_THIS);
Nov 5, 2005
Nov 5, 2005
71
Apr 26, 2001
Apr 26, 2001
72
73
74
75
/* X11 driver bootstrap functions */
static int X11_Available(void)
{
Nov 5, 2005
Nov 5, 2005
76
77
Display *display = NULL;
if ( SDL_X11_LoadSymbols() ) {
Mar 22, 2006
Mar 22, 2006
78
display = XOpenDisplay(NULL);
Nov 5, 2005
Nov 5, 2005
79
if ( display != NULL ) {
Mar 22, 2006
Mar 22, 2006
80
XCloseDisplay(display);
Nov 5, 2005
Nov 5, 2005
81
82
}
SDL_X11_UnloadSymbols();
Apr 26, 2001
Apr 26, 2001
83
84
85
86
87
88
89
90
}
return(display != NULL);
}
static void X11_DeleteDevice(SDL_VideoDevice *device)
{
if ( device ) {
if ( device->hidden ) {
Feb 7, 2006
Feb 7, 2006
91
SDL_free(device->hidden);
Apr 26, 2001
Apr 26, 2001
92
93
}
if ( device->gl_data ) {
Feb 7, 2006
Feb 7, 2006
94
SDL_free(device->gl_data);
Apr 26, 2001
Apr 26, 2001
95
}
Feb 7, 2006
Feb 7, 2006
96
SDL_free(device);
Nov 5, 2005
Nov 5, 2005
97
SDL_X11_UnloadSymbols();
Apr 26, 2001
Apr 26, 2001
98
99
100
101
102
}
}
static SDL_VideoDevice *X11_CreateDevice(int devindex)
{
Nov 5, 2005
Nov 5, 2005
103
104
105
106
SDL_VideoDevice *device = NULL;
if ( SDL_X11_LoadSymbols() ) {
/* Initialize all variables that we clean on shutdown */
Feb 7, 2006
Feb 7, 2006
107
device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
Nov 5, 2005
Nov 5, 2005
108
if ( device ) {
Feb 7, 2006
Feb 7, 2006
109
SDL_memset(device, 0, (sizeof *device));
Nov 5, 2005
Nov 5, 2005
110
device->hidden = (struct SDL_PrivateVideoData *)
Feb 7, 2006
Feb 7, 2006
111
SDL_malloc((sizeof *device->hidden));
Jun 25, 2007
Jun 25, 2007
112
SDL_memset(device->hidden, 0, (sizeof *device->hidden));
Nov 5, 2005
Nov 5, 2005
113
device->gl_data = (struct SDL_PrivateGLData *)
Feb 7, 2006
Feb 7, 2006
114
SDL_malloc((sizeof *device->gl_data));
Jun 25, 2007
Jun 25, 2007
115
SDL_memset(device->gl_data, 0, (sizeof *device->gl_data));
Nov 5, 2005
Nov 5, 2005
116
117
118
119
120
121
122
}
if ( (device == NULL) || (device->hidden == NULL) ||
(device->gl_data == NULL) ) {
SDL_OutOfMemory();
X11_DeleteDevice(device); /* calls SDL_X11_UnloadSymbols(). */
return(0);
}
Feb 7, 2006
Feb 7, 2006
123
124
SDL_memset(device->hidden, 0, (sizeof *device->hidden));
SDL_memset(device->gl_data, 0, (sizeof *device->gl_data));
Nov 5, 2005
Nov 5, 2005
125
126
127
128
129
130
131
132
133
134
/* Set the driver flags */
device->handles_any_size = 1;
/* Set the function pointers */
device->VideoInit = X11_VideoInit;
device->ListModes = X11_ListModes;
device->SetVideoMode = X11_SetVideoMode;
device->ToggleFullScreen = X11_ToggleFullScreen;
device->UpdateMouse = X11_UpdateMouse;
Feb 16, 2006
Feb 16, 2006
135
#if SDL_VIDEO_DRIVER_X11_XV
Nov 5, 2005
Nov 5, 2005
136
device->CreateYUVOverlay = X11_CreateYUVOverlay;
Apr 26, 2001
Apr 26, 2001
137
#endif
Nov 5, 2005
Nov 5, 2005
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
device->SetColors = X11_SetColors;
device->UpdateRects = NULL;
device->VideoQuit = X11_VideoQuit;
device->AllocHWSurface = X11_AllocHWSurface;
device->CheckHWBlit = NULL;
device->FillHWRect = NULL;
device->SetHWColorKey = NULL;
device->SetHWAlpha = NULL;
device->LockHWSurface = X11_LockHWSurface;
device->UnlockHWSurface = X11_UnlockHWSurface;
device->FlipHWSurface = X11_FlipHWSurface;
device->FreeHWSurface = X11_FreeHWSurface;
device->SetGamma = X11_SetVidModeGamma;
device->GetGamma = X11_GetVidModeGamma;
device->SetGammaRamp = X11_SetGammaRamp;
device->GetGammaRamp = NULL;
Feb 16, 2006
Feb 16, 2006
154
#if SDL_VIDEO_OPENGL_GLX
Nov 5, 2005
Nov 5, 2005
155
156
157
158
159
device->GL_LoadLibrary = X11_GL_LoadLibrary;
device->GL_GetProcAddress = X11_GL_GetProcAddress;
device->GL_GetAttribute = X11_GL_GetAttribute;
device->GL_MakeCurrent = X11_GL_MakeCurrent;
device->GL_SwapBuffers = X11_GL_SwapBuffers;
Apr 26, 2001
Apr 26, 2001
160
#endif
Nov 5, 2005
Nov 5, 2005
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
device->SetCaption = X11_SetCaption;
device->SetIcon = X11_SetIcon;
device->IconifyWindow = X11_IconifyWindow;
device->GrabInput = X11_GrabInput;
device->GetWMInfo = X11_GetWMInfo;
device->FreeWMCursor = X11_FreeWMCursor;
device->CreateWMCursor = X11_CreateWMCursor;
device->ShowWMCursor = X11_ShowWMCursor;
device->WarpWMCursor = X11_WarpWMCursor;
device->CheckMouseMode = X11_CheckMouseMode;
device->InitOSKeymap = X11_InitOSKeymap;
device->PumpEvents = X11_PumpEvents;
device->free = X11_DeleteDevice;
}
Apr 26, 2001
Apr 26, 2001
176
177
178
179
180
181
182
183
184
185
186
187
188
return device;
}
VideoBootStrap X11_bootstrap = {
"x11", "X Window System",
X11_Available, X11_CreateDevice
};
/* Normal X11 error handler routine */
static int (*X_handler)(Display *, XErrorEvent *) = NULL;
static int x_errhandler(Display *d, XErrorEvent *e)
{
Feb 16, 2006
Feb 16, 2006
189
#if SDL_VIDEO_DRIVER_X11_VIDMODE
Apr 26, 2001
Apr 26, 2001
190
191
extern int vm_error;
#endif
Feb 16, 2006
Feb 16, 2006
192
#if SDL_VIDEO_DRIVER_X11_DGAMOUSE
Apr 26, 2001
Apr 26, 2001
193
194
195
extern int dga_error;
#endif
Feb 16, 2006
Feb 16, 2006
196
#if SDL_VIDEO_DRIVER_X11_VIDMODE
Apr 26, 2001
Apr 26, 2001
197
198
199
200
201
202
203
204
205
/* VidMode errors are non-fatal. :) */
/* Are the errors offset by one from the error base?
e.g. the error base is 143, the code is 148, and the
actual error is XF86VidModeExtensionDisabled (4) ?
*/
if ( (vm_error >= 0) &&
(((e->error_code == BadRequest)&&(e->request_code == vm_error)) ||
((e->error_code > vm_error) &&
(e->error_code <= (vm_error+XF86VidModeNumberErrors)))) ) {
May 4, 2006
May 4, 2006
206
#ifdef X11_DEBUG
Apr 26, 2001
Apr 26, 2001
207
{ char errmsg[1024];
Mar 22, 2006
Mar 22, 2006
208
XGetErrorText(d, e->error_code, errmsg, sizeof(errmsg));
Apr 26, 2001
Apr 26, 2001
209
210
211
212
213
printf("VidMode error: %s\n", errmsg);
}
#endif
return(0);
}
Feb 16, 2006
Feb 16, 2006
214
#endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */
Apr 26, 2001
Apr 26, 2001
215
Feb 16, 2006
Feb 16, 2006
216
#if SDL_VIDEO_DRIVER_X11_DGAMOUSE
Apr 26, 2001
Apr 26, 2001
217
218
219
220
/* DGA errors can be non-fatal. :) */
if ( (dga_error >= 0) &&
((e->error_code > dga_error) &&
(e->error_code <= (dga_error+XF86DGANumberErrors))) ) {
May 4, 2006
May 4, 2006
221
#ifdef X11_DEBUG
Apr 26, 2001
Apr 26, 2001
222
{ char errmsg[1024];
Mar 22, 2006
Mar 22, 2006
223
XGetErrorText(d, e->error_code, errmsg, sizeof(errmsg));
Apr 26, 2001
Apr 26, 2001
224
225
226
227
228
printf("DGA error: %s\n", errmsg);
}
#endif
return(0);
}
Feb 16, 2006
Feb 16, 2006
229
#endif /* SDL_VIDEO_DRIVER_X11_DGAMOUSE */
Apr 26, 2001
Apr 26, 2001
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
return(X_handler(d,e));
}
/* X11 I/O error handler routine */
static int (*XIO_handler)(Display *) = NULL;
static int xio_errhandler(Display *d)
{
/* Ack! Lost X11 connection! */
/* We will crash if we try to clean up our display */
if ( current_video->hidden->Ximage ) {
SDL_VideoSurface->pixels = NULL;
}
current_video->hidden->X11_Display = NULL;
/* Continue with the standard X11 error handler */
return(XIO_handler(d));
}
Mar 23, 2006
Mar 23, 2006
250
251
static int (*Xext_handler)(Display *, _Xconst char *, _Xconst char *) = NULL;
static int xext_errhandler(Display *d, _Xconst char *ext, _Xconst char *reason)
Jan 14, 2006
Jan 14, 2006
252
{
May 4, 2006
May 4, 2006
253
#ifdef X11_DEBUG
Jan 14, 2006
Jan 14, 2006
254
255
printf("Xext error inside SDL (may be harmless):\n");
printf(" Extension \"%s\" %s on display \"%s\".\n",
Mar 23, 2006
Mar 23, 2006
256
ext, reason, XDisplayString(d));
Jan 14, 2006
Jan 14, 2006
257
258
#endif
Feb 7, 2006
Feb 7, 2006
259
if (SDL_strcmp(reason, "missing") == 0) {
Jan 14, 2006
Jan 14, 2006
260
261
262
263
264
265
266
267
268
/*
* Since the query itself, elsewhere, can handle a missing extension
* and the default behaviour in Xlib is to write to stderr, which
* generates unnecessary bug reports, we just ignore these.
*/
return 0;
}
/* Everything else goes to the default handler... */
Mar 23, 2006
Mar 23, 2006
269
return Xext_handler(d, ext, reason);
Jan 14, 2006
Jan 14, 2006
270
271
}
Feb 3, 2006
Feb 3, 2006
272
273
274
275
/* Find out what class name we should use */
static char *get_classname(char *classname, int maxlen)
{
char *spot;
Feb 21, 2006
Feb 21, 2006
276
#if defined(__LINUX__) || defined(__FREEBSD__)
Feb 3, 2006
Feb 3, 2006
277
278
279
280
281
282
char procfile[1024];
char linkfile[1024];
int linksize;
#endif
/* First allow environment variable override */
Feb 7, 2006
Feb 7, 2006
283
spot = SDL_getenv("SDL_VIDEO_X11_WMCLASS");
Feb 3, 2006
Feb 3, 2006
284
if ( spot ) {
Feb 19, 2006
Feb 19, 2006
285
SDL_strlcpy(classname, spot, maxlen);
Feb 3, 2006
Feb 3, 2006
286
287
288
289
return classname;
}
/* Next look at the application's executable name */
Feb 21, 2006
Feb 21, 2006
290
291
#if defined(__LINUX__) || defined(__FREEBSD__)
#if defined(__LINUX__)
Feb 7, 2006
Feb 7, 2006
292
SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/exe", getpid());
Feb 21, 2006
Feb 21, 2006
293
#elif defined(__FREEBSD__)
Feb 7, 2006
Feb 7, 2006
294
SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/file", getpid());
Feb 3, 2006
Feb 3, 2006
295
296
297
298
299
300
#else
#error Where can we find the executable name?
#endif
linksize = readlink(procfile, linkfile, sizeof(linkfile)-1);
if ( linksize > 0 ) {
linkfile[linksize] = '\0';
Feb 7, 2006
Feb 7, 2006
301
spot = SDL_strrchr(linkfile, '/');
Feb 3, 2006
Feb 3, 2006
302
if ( spot ) {
Feb 19, 2006
Feb 19, 2006
303
SDL_strlcpy(classname, spot+1, maxlen);
Feb 3, 2006
Feb 3, 2006
304
} else {
Feb 19, 2006
Feb 19, 2006
305
SDL_strlcpy(classname, linkfile, maxlen);
Feb 3, 2006
Feb 3, 2006
306
307
308
}
return classname;
}
Feb 21, 2006
Feb 21, 2006
309
#endif /* __LINUX__ */
Feb 3, 2006
Feb 3, 2006
310
311
/* Finally use the default we've used forever */
Feb 19, 2006
Feb 19, 2006
312
SDL_strlcpy(classname, "SDL_App", maxlen);
Feb 3, 2006
Feb 3, 2006
313
314
315
return classname;
}
Apr 26, 2001
Apr 26, 2001
316
317
318
/* Create auxiliary (toplevel) windows with the current visual */
static void create_aux_windows(_THIS)
{
May 4, 2006
May 4, 2006
319
int x = 0, y = 0;
Feb 3, 2006
Feb 3, 2006
320
char classname[1024];
Apr 26, 2001
Apr 26, 2001
321
322
XSetWindowAttributes xattr;
XWMHints *hints;
Jun 25, 2007
Jun 25, 2007
323
unsigned long app_event_mask;
Apr 26, 2001
Apr 26, 2001
324
325
int def_vis = (SDL_Visual == DefaultVisual(SDL_Display, SDL_Screen));
Mar 20, 2006
Mar 20, 2006
326
/* Look up some useful Atoms */
Mar 22, 2006
Mar 22, 2006
327
WM_DELETE_WINDOW = XInternAtom(SDL_Display, "WM_DELETE_WINDOW", False);
Mar 20, 2006
Mar 20, 2006
328
Apr 26, 2001
Apr 26, 2001
329
330
331
/* Don't create any extra windows if we are being managed */
if ( SDL_windowid ) {
FSwindow = 0;
Feb 7, 2006
Feb 7, 2006
332
WMwindow = SDL_strtol(SDL_windowid, NULL, 0);
Apr 26, 2001
Apr 26, 2001
333
334
335
336
return;
}
if(FSwindow)
Mar 22, 2006
Mar 22, 2006
337
XDestroyWindow(SDL_Display, FSwindow);
Apr 26, 2001
Apr 26, 2001
338
Jun 20, 2006
Jun 20, 2006
339
#if SDL_VIDEO_DRIVER_X11_XINERAMA
May 4, 2006
May 4, 2006
340
341
342
343
344
if ( use_xinerama ) {
x = xinerama_info.x_org;
y = xinerama_info.y_org;
}
#endif
Apr 26, 2001
Apr 26, 2001
345
346
347
348
349
xattr.override_redirect = True;
xattr.background_pixel = def_vis ? BlackPixel(SDL_Display, SDL_Screen) : 0;
xattr.border_pixel = 0;
xattr.colormap = SDL_XColorMap;
Mar 22, 2006
Mar 22, 2006
350
FSwindow = XCreateWindow(SDL_Display, SDL_Root,
May 4, 2006
May 4, 2006
351
x, y, 32, 32, 0,
Apr 26, 2001
Apr 26, 2001
352
353
354
355
356
this->hidden->depth, InputOutput, SDL_Visual,
CWOverrideRedirect | CWBackPixel | CWBorderPixel
| CWColormap,
&xattr);
Mar 22, 2006
Mar 22, 2006
357
XSelectInput(SDL_Display, FSwindow, StructureNotifyMask);
Apr 26, 2001
Apr 26, 2001
358
359
360
361
362
363
/* Tell KDE to keep the fullscreen window on top */
{
XEvent ev;
long mask;
Feb 7, 2006
Feb 7, 2006
364
SDL_memset(&ev, 0, sizeof(ev));
Apr 26, 2001
Apr 26, 2001
365
366
ev.xclient.type = ClientMessage;
ev.xclient.window = SDL_Root;
Mar 22, 2006
Mar 22, 2006
367
ev.xclient.message_type = XInternAtom(SDL_Display,
Apr 26, 2001
Apr 26, 2001
368
369
370
371
372
"KWM_KEEP_ON_TOP", False);
ev.xclient.format = 32;
ev.xclient.data.l[0] = FSwindow;
ev.xclient.data.l[1] = CurrentTime;
mask = SubstructureRedirectMask;
Mar 22, 2006
Mar 22, 2006
373
XSendEvent(SDL_Display, SDL_Root, False, mask, &ev);
Apr 26, 2001
Apr 26, 2001
374
375
376
377
378
}
hints = NULL;
if(WMwindow) {
/* All window attributes must survive the recreation */
Mar 22, 2006
Mar 22, 2006
379
380
hints = XGetWMHints(SDL_Display, WMwindow);
XDestroyWindow(SDL_Display, WMwindow);
Apr 26, 2001
Apr 26, 2001
381
382
383
384
}
/* Create the window for windowed management */
/* (reusing the xattr structure above) */
May 4, 2006
May 4, 2006
385
386
WMwindow = XCreateWindow(SDL_Display, SDL_Root,
x, y, 32, 32, 0,
Apr 26, 2001
Apr 26, 2001
387
388
389
390
391
392
this->hidden->depth, InputOutput, SDL_Visual,
CWBackPixel | CWBorderPixel | CWColormap,
&xattr);
/* Set the input hints so we get keyboard input */
if(!hints) {
Mar 22, 2006
Mar 22, 2006
393
hints = XAllocWMHints();
Apr 26, 2001
Apr 26, 2001
394
395
396
hints->input = True;
hints->flags = InputHint;
}
Mar 22, 2006
Mar 22, 2006
397
398
XSetWMHints(SDL_Display, WMwindow, hints);
XFree(hints);
May 5, 2006
May 5, 2006
399
X11_SetCaptionNoLock(this, this->wm_title, this->wm_icon);
Apr 26, 2001
Apr 26, 2001
400
Jun 25, 2007
Jun 25, 2007
401
402
403
app_event_mask = FocusChangeMask | KeyPressMask | KeyReleaseMask
| PropertyChangeMask | StructureNotifyMask | KeymapStateMask;
XSelectInput(SDL_Display, WMwindow, app_event_mask);
Apr 26, 2001
Apr 26, 2001
404
405
/* Set the class hints so we can get an icon (AfterStep) */
Feb 3, 2006
Feb 3, 2006
406
get_classname(classname, sizeof(classname));
Apr 26, 2001
Apr 26, 2001
407
408
{
XClassHint *classhints;
Mar 22, 2006
Mar 22, 2006
409
classhints = XAllocClassHint();
Apr 26, 2001
Apr 26, 2001
410
if(classhints != NULL) {
Aug 19, 2002
Aug 19, 2002
411
412
classhints->res_name = classname;
classhints->res_class = classname;
Mar 22, 2006
Mar 22, 2006
413
414
XSetClassHint(SDL_Display, WMwindow, classhints);
XFree(classhints);
Apr 26, 2001
Apr 26, 2001
415
416
417
}
}
Jun 15, 2007
Jun 15, 2007
418
/* Setup the communication with the IM server */
Jun 25, 2007
Jun 25, 2007
419
420
421
/* create_aux_windows may be called several times against the same
Display. We should reuse the SDL_IM if one has been opened for
the Display, so we should not simply reset SDL_IM here. */
Mar 22, 2006
Mar 22, 2006
422
423
424
#ifdef X_HAVE_UTF8_STRING
if (SDL_X11_HAVE_UTF8) {
Jun 25, 2007
Jun 25, 2007
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
/* Discard obsolete resources if any. */
if (SDL_IM != NULL && SDL_Display != XDisplayOfIM(SDL_IM)) {
/* Just a double check. I don't think this
code is ever executed. */
SDL_SetError("display has changed while an IM is kept");
if (SDL_IC) {
XUnsetICFocus(SDL_IC);
XDestroyIC(SDL_IC);
SDL_IC = NULL;
}
XCloseIM(SDL_IM);
SDL_IM = NULL;
}
/* Open an input method. */
if (SDL_IM == NULL) {
Jul 14, 2007
Jul 14, 2007
441
442
443
char *old_locale = NULL, *old_modifiers = NULL;
const char *p;
size_t n;
Jun 25, 2007
Jun 25, 2007
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
/* I'm not comfortable to do locale setup
here. However, we need C library locale
(and xlib modifiers) to be set based on the
user's preference to use XIM, and many
existing game programs doesn't take care of
users' locale preferences, so someone other
than the game program should do it.
Moreover, ones say that some game programs
heavily rely on the C locale behaviour,
e.g., strcol()'s, and we can't change the C
library locale. Given the situation, I
couldn't find better place to do the
job... */
/* Save the current (application program's)
locale settings. */
Jul 14, 2007
Jul 14, 2007
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
p = setlocale(LC_ALL, NULL);
if ( p ) {
n = SDL_strlen(p)+1;
old_locale = SDL_stack_alloc(char, n);
if ( old_locale ) {
SDL_strlcpy(old_locale, p, n);
}
}
p = XSetLocaleModifiers(NULL);
if ( p ) {
n = SDL_strlen(p)+1;
old_modifiers = SDL_stack_alloc(char, n);
if ( old_modifiers ) {
SDL_strlcpy(old_modifiers, p, n);
}
Jun 25, 2007
Jun 25, 2007
475
476
477
478
479
480
481
482
483
484
485
}
/* Fetch the user's preferences and open the
input method with them. */
setlocale(LC_ALL, "");
XSetLocaleModifiers("");
SDL_IM = XOpenIM(SDL_Display, NULL, classname, classname);
/* Restore the application's locale settings
so that we don't break the application's
expected behaviour. */
Jul 14, 2007
Jul 14, 2007
486
if ( old_locale ) {
Jun 25, 2007
Jun 25, 2007
487
488
489
490
491
/* We need to restore the C library
locale first, since the
interpretation of the X modifier
may depend on it. */
setlocale(LC_ALL, old_locale);
Jul 14, 2007
Jul 14, 2007
492
493
494
SDL_stack_free(old_locale);
}
if ( old_modifiers ) {
Jun 25, 2007
Jun 25, 2007
495
XSetLocaleModifiers(old_modifiers);
Jul 14, 2007
Jul 14, 2007
496
SDL_stack_free(old_modifiers);
Jun 25, 2007
Jun 25, 2007
497
498
499
500
}
}
/* Create a new input context for the new window just created. */
Mar 22, 2006
Mar 22, 2006
501
502
503
if (SDL_IM == NULL) {
SDL_SetError("no input method could be opened");
} else {
Jun 25, 2007
Jun 25, 2007
504
505
506
507
508
509
510
511
512
513
514
if (SDL_IC != NULL) {
/* Discard the old IC before creating new one. */
XUnsetICFocus(SDL_IC);
XDestroyIC(SDL_IC);
}
/* Theoretically we should check the current IM supports
PreeditNothing+StatusNothing style (i.e., root window method)
before creating the IC. However, it is the bottom line method,
and we supports any other options. If the IM didn't support
root window method, the following call fails, and SDL falls
back to pre-XIM keyboard handling. */
Mar 22, 2006
Mar 22, 2006
515
516
517
SDL_IC = pXCreateIC(SDL_IM,
XNClientWindow, WMwindow,
XNFocusWindow, WMwindow,
Jun 25, 2007
Jun 25, 2007
518
XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
Mar 22, 2006
Mar 22, 2006
519
520
521
522
523
524
525
526
XNResourceName, classname,
XNResourceClass, classname,
NULL);
if (SDL_IC == NULL) {
SDL_SetError("no input context could be created");
XCloseIM(SDL_IM);
SDL_IM = NULL;
Jun 25, 2007
Jun 25, 2007
527
528
529
530
531
532
533
534
535
536
} else {
/* We need to receive X events that an IM wants and to pass
them to the IM through XFilterEvent. The set of events may
vary depending on the IM implementation and the options
specified through various routes. Although unlikely, the
xlib specification allows IM to change the event requirement
with its own circumstances, it is safe to call SelectInput
whenever we re-create an IC. */
unsigned long mask = 0;
char *ret = pXGetICValues(SDL_IC, XNFilterEvents, &mask, NULL);
Jul 8, 2007
Jul 8, 2007
537
538
539
540
541
542
543
544
545
546
547
if (ret != NULL) {
XUnsetICFocus(SDL_IC);
XDestroyIC(SDL_IC);
SDL_IC = NULL;
SDL_SetError("no input context could be created");
XCloseIM(SDL_IM);
SDL_IM = NULL;
} else {
XSelectInput(SDL_Display, WMwindow, app_event_mask | mask);
XSetICFocus(SDL_IC);
}
Mar 22, 2006
Mar 22, 2006
548
549
}
}
Nov 21, 2005
Nov 21, 2005
550
}
Mar 22, 2006
Mar 22, 2006
551
#endif
Nov 21, 2005
Nov 21, 2005
552
Mar 22, 2006
Mar 22, 2006
553
554
/* Allow the window to be deleted by the window manager */
XSetWMProtocols(SDL_Display, WMwindow, &WM_DELETE_WINDOW, 1);
Apr 26, 2001
Apr 26, 2001
555
556
557
558
}
static int X11_VideoInit(_THIS, SDL_PixelFormat *vformat)
{
Feb 29, 2008
Feb 29, 2008
559
const char *env;
Apr 26, 2001
Apr 26, 2001
560
561
562
563
564
565
char *display;
int i;
/* Open the X11 display */
display = NULL; /* Get it from DISPLAY environment variable */
Mar 22, 2006
Mar 22, 2006
566
567
if ( (SDL_strncmp(XDisplayName(display), ":", 1) == 0) ||
(SDL_strncmp(XDisplayName(display), "unix:", 5) == 0) ) {
Apr 26, 2001
Apr 26, 2001
568
569
570
571
local_X11 = 1;
} else {
local_X11 = 0;
}
Mar 22, 2006
Mar 22, 2006
572
SDL_Display = XOpenDisplay(display);
Feb 16, 2006
Feb 16, 2006
573
#if defined(__osf__) && defined(SDL_VIDEO_DRIVER_X11_DYNAMIC)
Jan 30, 2006
Jan 30, 2006
574
575
576
577
578
579
580
581
582
583
/* On Tru64 if linking without -lX11, it fails and you get following message.
* Xlib: connection to ":0.0" refused by server
* Xlib: XDM authorization key matches an existing client!
*
* It succeeds if retrying 1 second later
* or if running xhost +localhost on shell.
*
*/
if ( SDL_Display == NULL ) {
SDL_Delay(1000);
Mar 22, 2006
Mar 22, 2006
584
SDL_Display = XOpenDisplay(display);
Jan 30, 2006
Jan 30, 2006
585
586
}
#endif
Apr 26, 2001
Apr 26, 2001
587
588
589
590
591
if ( SDL_Display == NULL ) {
SDL_SetError("Couldn't open X11 display");
return(-1);
}
#ifdef X11_DEBUG
Mar 22, 2006
Mar 22, 2006
592
XSynchronize(SDL_Display, True);
Apr 26, 2001
Apr 26, 2001
593
594
595
596
597
598
#endif
/* Create an alternate X display for graphics updates -- allows us
to do graphics updates in a separate thread from event handling.
Thread-safe X11 doesn't seem to exist.
*/
Mar 22, 2006
Mar 22, 2006
599
GFX_Display = XOpenDisplay(display);
Apr 26, 2001
Apr 26, 2001
600
if ( GFX_Display == NULL ) {
Jun 15, 2007
Jun 15, 2007
601
602
XCloseDisplay(SDL_Display);
SDL_Display = NULL;
Apr 26, 2001
Apr 26, 2001
603
604
605
606
607
SDL_SetError("Couldn't open X11 display");
return(-1);
}
/* Set the normal X error handler */
Mar 22, 2006
Mar 22, 2006
608
X_handler = XSetErrorHandler(x_errhandler);
Apr 26, 2001
Apr 26, 2001
609
610
/* Set the error handler if we lose the X display */
Mar 22, 2006
Mar 22, 2006
611
XIO_handler = XSetIOErrorHandler(xio_errhandler);
Apr 26, 2001
Apr 26, 2001
612
Jan 14, 2006
Jan 14, 2006
613
/* Set the X extension error handler */
Mar 22, 2006
Mar 22, 2006
614
Xext_handler = XSetExtensionErrorHandler(xext_errhandler);
Jan 14, 2006
Jan 14, 2006
615
Apr 26, 2001
Apr 26, 2001
616
617
618
619
620
/* use default screen (from $DISPLAY) */
SDL_Screen = DefaultScreen(SDL_Display);
#ifndef NO_SHARED_MEMORY
/* Check for MIT shared memory extension */
Dec 7, 2002
Dec 7, 2002
621
use_mitshm = 0;
Apr 26, 2001
Apr 26, 2001
622
if ( local_X11 ) {
Mar 22, 2006
Mar 22, 2006
623
use_mitshm = XShmQueryExtension(SDL_Display);
Apr 26, 2001
Apr 26, 2001
624
625
626
627
}
#endif /* NO_SHARED_MEMORY */
/* Get the available video modes */
Jun 15, 2007
Jun 15, 2007
628
629
630
631
632
if(X11_GetVideoModes(this) < 0) {
XCloseDisplay(GFX_Display);
GFX_Display = NULL;
XCloseDisplay(SDL_Display);
SDL_Display = NULL;
Apr 26, 2001
Apr 26, 2001
633
return -1;
Jun 15, 2007
Jun 15, 2007
634
}
Apr 26, 2001
Apr 26, 2001
635
Mar 15, 2006
Mar 15, 2006
636
637
638
639
/* Determine the current screen size */
this->info.current_w = DisplayWidth(SDL_Display, SDL_Screen);
this->info.current_h = DisplayHeight(SDL_Display, SDL_Screen);
Apr 26, 2001
Apr 26, 2001
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
/* Determine the default screen depth:
Use the default visual (or at least one with the same depth) */
SDL_DisplayColormap = DefaultColormap(SDL_Display, SDL_Screen);
for(i = 0; i < this->hidden->nvisuals; i++)
if(this->hidden->visuals[i].depth == DefaultDepth(SDL_Display,
SDL_Screen))
break;
if(i == this->hidden->nvisuals) {
/* default visual was useless, take the deepest one instead */
i = 0;
}
SDL_Visual = this->hidden->visuals[i].visual;
if ( SDL_Visual == DefaultVisual(SDL_Display, SDL_Screen) ) {
SDL_XColorMap = SDL_DisplayColormap;
} else {
Mar 22, 2006
Mar 22, 2006
655
SDL_XColorMap = XCreateColormap(SDL_Display, SDL_Root,
Apr 26, 2001
Apr 26, 2001
656
657
658
659
660
661
662
663
664
SDL_Visual, AllocNone);
}
this->hidden->depth = this->hidden->visuals[i].depth;
vformat->BitsPerPixel = this->hidden->visuals[i].bpp;
if ( vformat->BitsPerPixel > 8 ) {
vformat->Rmask = SDL_Visual->red_mask;
vformat->Gmask = SDL_Visual->green_mask;
vformat->Bmask = SDL_Visual->blue_mask;
}
Apr 17, 2006
Apr 17, 2006
665
666
667
if ( this->hidden->depth == 32 ) {
vformat->Amask = (0xFFFFFFFF & ~(vformat->Rmask|vformat->Gmask|vformat->Bmask));
}
Apr 26, 2001
Apr 26, 2001
668
669
X11_SaveVidModeGamma(this);
Dec 29, 2007
Dec 29, 2007
670
671
/* Allow environment override of screensaver disable. */
env = SDL_getenv("SDL_VIDEO_ALLOW_SCREENSAVER");
Feb 29, 2008
Feb 29, 2008
672
673
674
675
676
677
678
679
680
if ( env ) {
allow_screensaver = SDL_atoi(env);
} else {
#ifdef SDL_VIDEO_DISABLE_SCREENSAVER
allow_screensaver = 0;
#else
allow_screensaver = 1;
#endif
}
May 8, 2006
May 8, 2006
681
Apr 26, 2001
Apr 26, 2001
682
/* See if we have been passed a window to use */
Feb 7, 2006
Feb 7, 2006
683
SDL_windowid = SDL_getenv("SDL_WINDOWID");
Apr 26, 2001
Apr 26, 2001
684
685
686
687
688
689
690
691
692
693
694
695
696
/* Create the fullscreen and managed windows */
create_aux_windows(this);
/* Create the blank cursor */
SDL_BlankCursor = this->CreateWMCursor(this, blank_cdata, blank_cmask,
BLANK_CWIDTH, BLANK_CHEIGHT,
BLANK_CHOTX, BLANK_CHOTY);
/* Fill in some window manager capabilities */
this->info.wm_available = 1;
/* We're done! */
Mar 22, 2006
Mar 22, 2006
697
XFlush(SDL_Display);
Apr 26, 2001
Apr 26, 2001
698
699
700
701
702
703
704
705
706
707
708
709
710
711
return(0);
}
static void X11_DestroyWindow(_THIS, SDL_Surface *screen)
{
/* Clean up OpenGL */
if ( screen ) {
screen->flags &= ~(SDL_OPENGL|SDL_OPENGLBLIT);
}
X11_GL_Shutdown(this);
if ( ! SDL_windowid ) {
/* Hide the managed window */
if ( WMwindow ) {
Mar 22, 2006
Mar 22, 2006
712
XUnmapWindow(SDL_Display, WMwindow);
Apr 26, 2001
Apr 26, 2001
713
714
715
716
717
718
719
720
}
if ( screen && (screen->flags & SDL_FULLSCREEN) ) {
screen->flags &= ~SDL_FULLSCREEN;
X11_LeaveFullScreen(this);
}
/* Destroy the output window */
if ( SDL_Window ) {
Mar 22, 2006
Mar 22, 2006
721
XDestroyWindow(SDL_Display, SDL_Window);
Apr 26, 2001
Apr 26, 2001
722
723
724
725
726
727
728
729
730
}
/* Free the colormap entries */
if ( SDL_XPixels ) {
int numcolors;
unsigned long pixel;
numcolors = SDL_Visual->map_entries;
for ( pixel=0; pixel<numcolors; ++pixel ) {
while ( SDL_XPixels[pixel] > 0 ) {
Mar 22, 2006
Mar 22, 2006
731
XFreeColors(GFX_Display,
Apr 26, 2001
Apr 26, 2001
732
733
734
735
SDL_DisplayColormap,&pixel,1,0);
--SDL_XPixels[pixel];
}
}
Feb 7, 2006
Feb 7, 2006
736
SDL_free(SDL_XPixels);
Apr 26, 2001
Apr 26, 2001
737
738
739
740
741
SDL_XPixels = NULL;
}
/* Free the graphics context */
if ( SDL_GC ) {
Mar 22, 2006
Mar 22, 2006
742
XFreeGC(SDL_Display, SDL_GC);
Apr 26, 2001
Apr 26, 2001
743
744
745
746
747
SDL_GC = 0;
}
}
}
Sep 16, 2002
Sep 16, 2002
748
749
static SDL_bool X11_WindowPosition(_THIS, int *x, int *y, int w, int h)
{
Feb 7, 2006
Feb 7, 2006
750
751
const char *window = SDL_getenv("SDL_VIDEO_WINDOW_POS");
const char *center = SDL_getenv("SDL_VIDEO_CENTERED");
Sep 16, 2002
Sep 16, 2002
752
if ( window ) {
Feb 7, 2006
Feb 7, 2006
753
if ( SDL_sscanf(window, "%d,%d", x, y) == 2 ) {
Sep 16, 2002
Sep 16, 2002
754
755
return SDL_TRUE;
}
Feb 7, 2006
Feb 7, 2006
756
if ( SDL_strcmp(window, "center") == 0 ) {
Sep 16, 2002
Sep 16, 2002
757
758
759
760
761
762
763
764
765
766
767
center = window;
}
}
if ( center ) {
*x = (DisplayWidth(SDL_Display, SDL_Screen) - w)/2;
*y = (DisplayHeight(SDL_Display, SDL_Screen) - h)/2;
return SDL_TRUE;
}
return SDL_FALSE;
}
Apr 26, 2001
Apr 26, 2001
768
769
770
771
static void X11_SetSizeHints(_THIS, int w, int h, Uint32 flags)
{
XSizeHints *hints;
Mar 22, 2006
Mar 22, 2006
772
hints = XAllocSizeHints();
Apr 26, 2001
Apr 26, 2001
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
if ( hints ) {
if ( flags & SDL_RESIZABLE ) {
hints->min_width = 32;
hints->min_height = 32;
hints->max_height = 4096;
hints->max_width = 4096;
} else {
hints->min_width = hints->max_width = w;
hints->min_height = hints->max_height = h;
}
hints->flags = PMaxSize | PMinSize;
if ( flags & SDL_FULLSCREEN ) {
hints->x = 0;
hints->y = 0;
hints->flags |= USPosition;
} else
/* Center it, if desired */
Sep 16, 2002
Sep 16, 2002
790
if ( X11_WindowPosition(this, &hints->x, &hints->y, w, h) ) {
Apr 26, 2001
Apr 26, 2001
791
hints->flags |= USPosition;
Mar 22, 2006
Mar 22, 2006
792
XMoveWindow(SDL_Display, WMwindow, hints->x, hints->y);
Apr 26, 2001
Apr 26, 2001
793
794
/* Flush the resize event so we don't catch it later */
Mar 22, 2006
Mar 22, 2006
795
XSync(SDL_Display, True);
Apr 26, 2001
Apr 26, 2001
796
}
Mar 22, 2006
Mar 22, 2006
797
798
XSetWMNormalHints(SDL_Display, WMwindow, hints);
XFree(hints);
Apr 26, 2001
Apr 26, 2001
799
800
801
802
803
804
805
806
807
808
809
}
/* Respect the window caption style */
if ( flags & SDL_NOFRAME ) {
SDL_bool set;
Atom WM_HINTS;
/* We haven't modified the window manager hints yet */
set = SDL_FALSE;
/* First try to set MWM hints */
Mar 22, 2006
Mar 22, 2006
810
WM_HINTS = XInternAtom(SDL_Display, "_MOTIF_WM_HINTS", True);
Apr 26, 2001
Apr 26, 2001
811
812
813
814
815
816
817
818
819
820
if ( WM_HINTS != None ) {
/* Hints used by Motif compliant window managers */
struct {
unsigned long flags;
unsigned long functions;
unsigned long decorations;
long input_mode;
unsigned long status;
} MWMHints = { (1L << 1), 0, 0, 0, 0 };
Mar 22, 2006
Mar 22, 2006
821
XChangeProperty(SDL_Display, WMwindow,
Apr 26, 2001
Apr 26, 2001
822
823
824
825
826
827
828
WM_HINTS, WM_HINTS, 32,
PropModeReplace,
(unsigned char *)&MWMHints,
sizeof(MWMHints)/sizeof(long));
set = SDL_TRUE;
}
/* Now try to set KWM hints */
Mar 22, 2006
Mar 22, 2006
829
WM_HINTS = XInternAtom(SDL_Display, "KWM_WIN_DECORATION", True);
Apr 26, 2001
Apr 26, 2001
830
831
832
if ( WM_HINTS != None ) {
long KWMHints = 0;
Mar 22, 2006
Mar 22, 2006
833
XChangeProperty(SDL_Display, WMwindow,
Apr 26, 2001
Apr 26, 2001
834
835
836
837
838
839
840
WM_HINTS, WM_HINTS, 32,
PropModeReplace,
(unsigned char *)&KWMHints,
sizeof(KWMHints)/sizeof(long));
set = SDL_TRUE;
}
/* Now try to set GNOME hints */
Mar 22, 2006
Mar 22, 2006
841
WM_HINTS = XInternAtom(SDL_Display, "_WIN_HINTS", True);
Apr 26, 2001
Apr 26, 2001
842
843
844
if ( WM_HINTS != None ) {
long GNOMEHints = 0;
Mar 22, 2006
Mar 22, 2006
845
XChangeProperty(SDL_Display, WMwindow,
Apr 26, 2001
Apr 26, 2001
846
847
848
849
850
851
852
853
WM_HINTS, WM_HINTS, 32,
PropModeReplace,
(unsigned char *)&GNOMEHints,
sizeof(GNOMEHints)/sizeof(long));
set = SDL_TRUE;
}
/* Finally set the transient hints if necessary */
if ( ! set ) {
Mar 22, 2006
Mar 22, 2006
854
XSetTransientForHint(SDL_Display, WMwindow, SDL_Root);
Apr 26, 2001
Apr 26, 2001
855
856
857
858
859
860
861
862
863
}
} else {
SDL_bool set;
Atom WM_HINTS;
/* We haven't modified the window manager hints yet */
set = SDL_FALSE;
/* First try to unset MWM hints */
Mar 22, 2006
Mar 22, 2006
864
WM_HINTS = XInternAtom(SDL_Display, "_MOTIF_WM_HINTS", True);
Apr 26, 2001
Apr 26, 2001
865
if ( WM_HINTS != None ) {
Mar 22, 2006
Mar 22, 2006
866
XDeleteProperty(SDL_Display, WMwindow, WM_HINTS);
Apr 26, 2001
Apr 26, 2001
867
868
869
set = SDL_TRUE;
}
/* Now try to unset KWM hints */
Mar 22, 2006
Mar 22, 2006
870
WM_HINTS = XInternAtom(SDL_Display, "KWM_WIN_DECORATION", True);
Apr 26, 2001
Apr 26, 2001
871
if ( WM_HINTS != None ) {
Mar 22, 2006
Mar 22, 2006
872
XDeleteProperty(SDL_Display, WMwindow, WM_HINTS);
Apr 26, 2001
Apr 26, 2001
873
874
875
set = SDL_TRUE;
}
/* Now try to unset GNOME hints */
Mar 22, 2006
Mar 22, 2006
876
WM_HINTS = XInternAtom(SDL_Display, "_WIN_HINTS", True);
Apr 26, 2001
Apr 26, 2001
877
if ( WM_HINTS != None ) {
Mar 22, 2006
Mar 22, 2006
878
XDeleteProperty(SDL_Display, WMwindow, WM_HINTS);
Apr 26, 2001
Apr 26, 2001
879
880
881
882
883
set = SDL_TRUE;
}
/* Finally unset the transient hints if necessary */
if ( ! set ) {
/* NOTE: Does this work? */
Mar 22, 2006
Mar 22, 2006
884
XSetTransientForHint(SDL_Display, WMwindow, None);
Apr 26, 2001
Apr 26, 2001
885
886
887
888
889
890
891
892
893
894
}
}
}
static int X11_CreateWindow(_THIS, SDL_Surface *screen,
int w, int h, int bpp, Uint32 flags)
{
int i, depth;
Visual *vis;
int vis_change;
Apr 17, 2006
Apr 17, 2006
895
Uint32 Amask;
Apr 26, 2001
Apr 26, 2001
896
897
898
899
/* If a window is already present, destroy it and start fresh */
if ( SDL_Window ) {
X11_DestroyWindow(this, screen);
Feb 26, 2004
Feb 26, 2004
900
switch_waiting = 0; /* Prevent jump back to now-meaningless state. */
Apr 26, 2001
Apr 26, 2001
901
902
903
904
}
/* See if we have been given a window id */
if ( SDL_windowid ) {
Feb 7, 2006
Feb 7, 2006
905
SDL_Window = SDL_strtol(SDL_windowid, NULL, 0);
Apr 26, 2001
Apr 26, 2001
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
} else {
SDL_Window = 0;
}
/* find out which visual we are going to use */
if ( flags & SDL_OPENGL ) {
XVisualInfo *vi;
vi = X11_GL_GetVisual(this);
if( !vi ) {
return -1;
}
vis = vi->visual;
depth = vi->depth;
} else if ( SDL_windowid ) {
XWindowAttributes a;
Mar 22, 2006
Mar 22, 2006
923
XGetWindowAttributes(SDL_Display, SDL_Window, &a);
Apr 26, 2001
Apr 26, 2001
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
vis = a.visual;
depth = a.depth;
} else {
for ( i = 0; i < this->hidden->nvisuals; i++ ) {
if ( this->hidden->visuals[i].bpp == bpp )
break;
}
if ( i == this->hidden->nvisuals ) {
SDL_SetError("No matching visual for requested depth");
return -1; /* should never happen */
}
vis = this->hidden->visuals[i].visual;
depth = this->hidden->visuals[i].depth;
}
#ifdef X11_DEBUG
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);
#endif
vis_change = (vis != SDL_Visual);
SDL_Visual = vis;
this->hidden->depth = depth;
/* Allocate the new pixel format for this video mode */
Apr 17, 2006
Apr 17, 2006
946
947
948
949
950
if ( this->hidden->depth == 32 ) {
Amask = (0xFFFFFFFF & ~(vis->red_mask|vis->green_mask|vis->blue_mask));
} else {
Amask = 0;
}
Apr 26, 2001
Apr 26, 2001
951
if ( ! SDL_ReallocFormat(screen, bpp,
Apr 17, 2006
Apr 17, 2006
952
vis->red_mask, vis->green_mask, vis->blue_mask, Amask) ) {
Apr 26, 2001
Apr 26, 2001
953
return -1;
Apr 17, 2006
Apr 17, 2006
954
}
Apr 26, 2001
Apr 26, 2001
955
956
957
/* Create the appropriate colormap */
if ( SDL_XColorMap != SDL_DisplayColormap ) {
Mar 22, 2006
Mar 22, 2006
958
XFreeColormap(SDL_Display, SDL_XColorMap);
Apr 26, 2001
Apr 26, 2001
959
960
961
962
963
964
}
if ( SDL_Visual->class == PseudoColor ) {
int ncolors;
/* Allocate the pixel flags */
ncolors = SDL_Visual->map_entries;
Feb 7, 2006
Feb 7, 2006
965
SDL_XPixels = SDL_malloc(ncolors * sizeof(int));
Apr 26, 2001
Apr 26, 2001
966
967
968
969
if(SDL_XPixels == NULL) {
SDL_OutOfMemory();
return -1;
}
Feb 7, 2006
Feb 7, 2006
970
SDL_memset(SDL_XPixels, 0, ncolors * sizeof(*SDL_XPixels));
Apr 26, 2001
Apr 26, 2001
971
972
973
974
975
976
977
/* always allocate a private colormap on non-default visuals */
if ( SDL_Visual != DefaultVisual(SDL_Display, SDL_Screen) ) {
flags |= SDL_HWPALETTE;
}
if ( flags & SDL_HWPALETTE ) {
screen->flags |= SDL_HWPALETTE;
Mar 22, 2006
Mar 22, 2006
978
SDL_XColorMap = XCreateColormap(SDL_Display, SDL_Root,
Apr 26, 2001
Apr 26, 2001
979
980
981
982
983
984
985
SDL_Visual, AllocAll);
} else {
SDL_XColorMap = SDL_DisplayColormap;
}
} else if ( SDL_Visual->class == DirectColor ) {
/* Create a colormap which we can manipulate for gamma */
Mar 22, 2006
Mar 22, 2006
986
SDL_XColorMap = XCreateColormap(SDL_Display, SDL_Root,
Apr 26, 2001
Apr 26, 2001
987
SDL_Visual, AllocAll);
Mar 22, 2006
Mar 22, 2006
988
XSync(SDL_Display, False);
Apr 26, 2001
Apr 26, 2001
989
990
991
992
993
994
995
996
/* Initialize the colormap to the identity mapping */
SDL_GetGammaRamp(0, 0, 0);
this->screen = screen;
X11_SetGammaRamp(this, this->gamma);
this->screen = NULL;
} else {
/* Create a read-only colormap for our window */
Mar 22, 2006
Mar 22, 2006
997
SDL_XColorMap = XCreateColormap(SDL_Display, SDL_Root,
Apr 26, 2001
Apr 26, 2001
998
999
1000
SDL_Visual, AllocNone);
}