Skip to content

Latest commit

 

History

History
1430 lines (1286 loc) · 40.2 KB

SDL_x11video.c

File metadata and controls

1430 lines (1286 loc) · 40.2 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
57
58
59
60
61
62
63
64
65
66
/* 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
67
Apr 26, 2001
Apr 26, 2001
68
69
70
71
/* X11 driver bootstrap functions */
static int X11_Available(void)
{
Nov 5, 2005
Nov 5, 2005
72
73
Display *display = NULL;
if ( SDL_X11_LoadSymbols() ) {
Mar 22, 2006
Mar 22, 2006
74
display = XOpenDisplay(NULL);
Nov 5, 2005
Nov 5, 2005
75
if ( display != NULL ) {
Mar 22, 2006
Mar 22, 2006
76
XCloseDisplay(display);
Nov 5, 2005
Nov 5, 2005
77
78
}
SDL_X11_UnloadSymbols();
Apr 26, 2001
Apr 26, 2001
79
80
81
82
83
84
85
86
}
return(display != NULL);
}
static void X11_DeleteDevice(SDL_VideoDevice *device)
{
if ( device ) {
if ( device->hidden ) {
Feb 7, 2006
Feb 7, 2006
87
SDL_free(device->hidden);
Apr 26, 2001
Apr 26, 2001
88
89
}
if ( device->gl_data ) {
Feb 7, 2006
Feb 7, 2006
90
SDL_free(device->gl_data);
Apr 26, 2001
Apr 26, 2001
91
}
Feb 7, 2006
Feb 7, 2006
92
SDL_free(device);
Nov 5, 2005
Nov 5, 2005
93
SDL_X11_UnloadSymbols();
Apr 26, 2001
Apr 26, 2001
94
95
96
97
98
}
}
static SDL_VideoDevice *X11_CreateDevice(int devindex)
{
Nov 5, 2005
Nov 5, 2005
99
100
101
102
SDL_VideoDevice *device = NULL;
if ( SDL_X11_LoadSymbols() ) {
/* Initialize all variables that we clean on shutdown */
Feb 7, 2006
Feb 7, 2006
103
device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
Nov 5, 2005
Nov 5, 2005
104
if ( device ) {
Feb 7, 2006
Feb 7, 2006
105
SDL_memset(device, 0, (sizeof *device));
Nov 5, 2005
Nov 5, 2005
106
device->hidden = (struct SDL_PrivateVideoData *)
Feb 7, 2006
Feb 7, 2006
107
SDL_malloc((sizeof *device->hidden));
Nov 5, 2005
Nov 5, 2005
108
device->gl_data = (struct SDL_PrivateGLData *)
Feb 7, 2006
Feb 7, 2006
109
SDL_malloc((sizeof *device->gl_data));
Nov 5, 2005
Nov 5, 2005
110
111
112
113
114
115
116
}
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
117
118
SDL_memset(device->hidden, 0, (sizeof *device->hidden));
SDL_memset(device->gl_data, 0, (sizeof *device->gl_data));
Nov 5, 2005
Nov 5, 2005
119
120
121
122
123
124
125
126
127
128
/* 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
129
#if SDL_VIDEO_DRIVER_X11_XV
Nov 5, 2005
Nov 5, 2005
130
device->CreateYUVOverlay = X11_CreateYUVOverlay;
Apr 26, 2001
Apr 26, 2001
131
#endif
Nov 5, 2005
Nov 5, 2005
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
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
148
#if SDL_VIDEO_OPENGL_GLX
Nov 5, 2005
Nov 5, 2005
149
150
151
152
153
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
154
#endif
Nov 5, 2005
Nov 5, 2005
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
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
170
171
172
173
174
175
176
177
178
179
180
181
182
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
183
#if SDL_VIDEO_DRIVER_X11_VIDMODE
Apr 26, 2001
Apr 26, 2001
184
185
extern int vm_error;
#endif
Feb 16, 2006
Feb 16, 2006
186
#if SDL_VIDEO_DRIVER_X11_DGAMOUSE
Apr 26, 2001
Apr 26, 2001
187
188
189
extern int dga_error;
#endif
Feb 16, 2006
Feb 16, 2006
190
#if SDL_VIDEO_DRIVER_X11_VIDMODE
Apr 26, 2001
Apr 26, 2001
191
192
193
194
195
196
197
198
199
/* 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
200
#ifdef X11_DEBUG
Apr 26, 2001
Apr 26, 2001
201
{ char errmsg[1024];
Mar 22, 2006
Mar 22, 2006
202
XGetErrorText(d, e->error_code, errmsg, sizeof(errmsg));
Apr 26, 2001
Apr 26, 2001
203
204
205
206
207
printf("VidMode error: %s\n", errmsg);
}
#endif
return(0);
}
Feb 16, 2006
Feb 16, 2006
208
#endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */
Apr 26, 2001
Apr 26, 2001
209
Feb 16, 2006
Feb 16, 2006
210
#if SDL_VIDEO_DRIVER_X11_DGAMOUSE
Apr 26, 2001
Apr 26, 2001
211
212
213
214
/* 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
215
#ifdef X11_DEBUG
Apr 26, 2001
Apr 26, 2001
216
{ char errmsg[1024];
Mar 22, 2006
Mar 22, 2006
217
XGetErrorText(d, e->error_code, errmsg, sizeof(errmsg));
Apr 26, 2001
Apr 26, 2001
218
219
220
221
222
printf("DGA error: %s\n", errmsg);
}
#endif
return(0);
}
Feb 16, 2006
Feb 16, 2006
223
#endif /* SDL_VIDEO_DRIVER_X11_DGAMOUSE */
Apr 26, 2001
Apr 26, 2001
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
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
244
245
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
246
{
May 4, 2006
May 4, 2006
247
#ifdef X11_DEBUG
Jan 14, 2006
Jan 14, 2006
248
249
printf("Xext error inside SDL (may be harmless):\n");
printf(" Extension \"%s\" %s on display \"%s\".\n",
Mar 23, 2006
Mar 23, 2006
250
ext, reason, XDisplayString(d));
Jan 14, 2006
Jan 14, 2006
251
252
#endif
Feb 7, 2006
Feb 7, 2006
253
if (SDL_strcmp(reason, "missing") == 0) {
Jan 14, 2006
Jan 14, 2006
254
255
256
257
258
259
260
261
262
/*
* 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
263
return Xext_handler(d, ext, reason);
Jan 14, 2006
Jan 14, 2006
264
265
}
Feb 3, 2006
Feb 3, 2006
266
267
268
269
/* Find out what class name we should use */
static char *get_classname(char *classname, int maxlen)
{
char *spot;
Feb 21, 2006
Feb 21, 2006
270
#if defined(__LINUX__) || defined(__FREEBSD__)
Feb 3, 2006
Feb 3, 2006
271
272
273
274
275
276
char procfile[1024];
char linkfile[1024];
int linksize;
#endif
/* First allow environment variable override */
Feb 7, 2006
Feb 7, 2006
277
spot = SDL_getenv("SDL_VIDEO_X11_WMCLASS");
Feb 3, 2006
Feb 3, 2006
278
if ( spot ) {
Feb 19, 2006
Feb 19, 2006
279
SDL_strlcpy(classname, spot, maxlen);
Feb 3, 2006
Feb 3, 2006
280
281
282
283
return classname;
}
/* Next look at the application's executable name */
Feb 21, 2006
Feb 21, 2006
284
285
#if defined(__LINUX__) || defined(__FREEBSD__)
#if defined(__LINUX__)
Feb 7, 2006
Feb 7, 2006
286
SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/exe", getpid());
Feb 21, 2006
Feb 21, 2006
287
#elif defined(__FREEBSD__)
Feb 7, 2006
Feb 7, 2006
288
SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/file", getpid());
Feb 3, 2006
Feb 3, 2006
289
290
291
292
293
294
#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
295
spot = SDL_strrchr(linkfile, '/');
Feb 3, 2006
Feb 3, 2006
296
if ( spot ) {
Feb 19, 2006
Feb 19, 2006
297
SDL_strlcpy(classname, spot+1, maxlen);
Feb 3, 2006
Feb 3, 2006
298
} else {
Feb 19, 2006
Feb 19, 2006
299
SDL_strlcpy(classname, linkfile, maxlen);
Feb 3, 2006
Feb 3, 2006
300
301
302
}
return classname;
}
Feb 21, 2006
Feb 21, 2006
303
#endif /* __LINUX__ */
Feb 3, 2006
Feb 3, 2006
304
305
/* Finally use the default we've used forever */
Feb 19, 2006
Feb 19, 2006
306
SDL_strlcpy(classname, "SDL_App", maxlen);
Feb 3, 2006
Feb 3, 2006
307
308
309
return classname;
}
Apr 26, 2001
Apr 26, 2001
310
311
312
/* Create auxiliary (toplevel) windows with the current visual */
static void create_aux_windows(_THIS)
{
May 4, 2006
May 4, 2006
313
int x = 0, y = 0;
Mar 20, 2006
Mar 20, 2006
314
315
Atom _NET_WM_NAME;
Atom _NET_WM_ICON_NAME;
Feb 3, 2006
Feb 3, 2006
316
char classname[1024];
Apr 26, 2001
Apr 26, 2001
317
318
XSetWindowAttributes xattr;
XWMHints *hints;
Mar 20, 2006
Mar 20, 2006
319
XTextProperty titleprop, titlepropUTF8, iconprop, iconpropUTF8;
Apr 26, 2001
Apr 26, 2001
320
321
int def_vis = (SDL_Visual == DefaultVisual(SDL_Display, SDL_Screen));
Mar 20, 2006
Mar 20, 2006
322
/* Look up some useful Atoms */
Mar 22, 2006
Mar 22, 2006
323
324
325
WM_DELETE_WINDOW = XInternAtom(SDL_Display, "WM_DELETE_WINDOW", False);
_NET_WM_NAME = XInternAtom(SDL_Display, "_NET_WM_NAME", False);
_NET_WM_ICON_NAME = XInternAtom(SDL_Display, "_NET_WM_ICON_NAME", False);
Mar 20, 2006
Mar 20, 2006
326
Apr 26, 2001
Apr 26, 2001
327
328
329
/* Don't create any extra windows if we are being managed */
if ( SDL_windowid ) {
FSwindow = 0;
Feb 7, 2006
Feb 7, 2006
330
WMwindow = SDL_strtol(SDL_windowid, NULL, 0);
Apr 26, 2001
Apr 26, 2001
331
332
333
334
return;
}
if(FSwindow)
Mar 22, 2006
Mar 22, 2006
335
XDestroyWindow(SDL_Display, FSwindow);
Apr 26, 2001
Apr 26, 2001
336
May 4, 2006
May 4, 2006
337
338
339
340
341
342
#if SDL_VIDEO_DRIVER_X11_VIDMODE
if ( use_xinerama ) {
x = xinerama_info.x_org;
y = xinerama_info.y_org;
}
#endif
Apr 26, 2001
Apr 26, 2001
343
344
345
346
347
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
348
FSwindow = XCreateWindow(SDL_Display, SDL_Root,
May 4, 2006
May 4, 2006
349
x, y, 32, 32, 0,
Apr 26, 2001
Apr 26, 2001
350
351
352
353
354
this->hidden->depth, InputOutput, SDL_Visual,
CWOverrideRedirect | CWBackPixel | CWBorderPixel
| CWColormap,
&xattr);
Mar 22, 2006
Mar 22, 2006
355
XSelectInput(SDL_Display, FSwindow, StructureNotifyMask);
Apr 26, 2001
Apr 26, 2001
356
357
358
359
360
361
/* Tell KDE to keep the fullscreen window on top */
{
XEvent ev;
long mask;
Feb 7, 2006
Feb 7, 2006
362
SDL_memset(&ev, 0, sizeof(ev));
Apr 26, 2001
Apr 26, 2001
363
364
ev.xclient.type = ClientMessage;
ev.xclient.window = SDL_Root;
Mar 22, 2006
Mar 22, 2006
365
ev.xclient.message_type = XInternAtom(SDL_Display,
Apr 26, 2001
Apr 26, 2001
366
367
368
369
370
"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
371
XSendEvent(SDL_Display, SDL_Root, False, mask, &ev);
Apr 26, 2001
Apr 26, 2001
372
373
374
}
hints = NULL;
Mar 20, 2006
Mar 20, 2006
375
376
titleprop.value = titlepropUTF8.value = NULL;
iconprop.value = iconpropUTF8.value = NULL;
Apr 26, 2001
Apr 26, 2001
377
378
if(WMwindow) {
/* All window attributes must survive the recreation */
Mar 22, 2006
Mar 22, 2006
379
380
381
382
383
384
hints = XGetWMHints(SDL_Display, WMwindow);
XGetTextProperty(SDL_Display, WMwindow, &titleprop, XA_WM_NAME);
XGetTextProperty(SDL_Display, WMwindow, &titlepropUTF8, _NET_WM_NAME);
XGetTextProperty(SDL_Display, WMwindow, &iconprop, XA_WM_ICON_NAME);
XGetTextProperty(SDL_Display, WMwindow, &iconpropUTF8, _NET_WM_ICON_NAME);
XDestroyWindow(SDL_Display, WMwindow);
Apr 26, 2001
Apr 26, 2001
385
386
387
388
}
/* Create the window for windowed management */
/* (reusing the xattr structure above) */
May 4, 2006
May 4, 2006
389
390
WMwindow = XCreateWindow(SDL_Display, SDL_Root,
x, y, 32, 32, 0,
Apr 26, 2001
Apr 26, 2001
391
392
393
394
395
396
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
397
hints = XAllocWMHints();
Apr 26, 2001
Apr 26, 2001
398
399
400
hints->input = True;
hints->flags = InputHint;
}
Mar 22, 2006
Mar 22, 2006
401
402
XSetWMHints(SDL_Display, WMwindow, hints);
XFree(hints);
Apr 26, 2001
Apr 26, 2001
403
if(titleprop.value) {
Mar 22, 2006
Mar 22, 2006
404
405
XSetTextProperty(SDL_Display, WMwindow, &titleprop, XA_WM_NAME);
XFree(titleprop.value);
Apr 26, 2001
Apr 26, 2001
406
}
Mar 20, 2006
Mar 20, 2006
407
if(titlepropUTF8.value) {
Mar 22, 2006
Mar 22, 2006
408
409
XSetTextProperty(SDL_Display, WMwindow, &titlepropUTF8, _NET_WM_NAME);
XFree(titlepropUTF8.value);
Mar 20, 2006
Mar 20, 2006
410
}
Apr 26, 2001
Apr 26, 2001
411
if(iconprop.value) {
Mar 22, 2006
Mar 22, 2006
412
413
XSetTextProperty(SDL_Display, WMwindow, &iconprop, XA_WM_ICON_NAME);
XFree(iconprop.value);
Apr 26, 2001
Apr 26, 2001
414
}
Mar 20, 2006
Mar 20, 2006
415
if(iconpropUTF8.value) {
Mar 22, 2006
Mar 22, 2006
416
417
XSetTextProperty(SDL_Display, WMwindow, &iconpropUTF8, _NET_WM_ICON_NAME);
XFree(iconpropUTF8.value);
Mar 20, 2006
Mar 20, 2006
418
}
Apr 26, 2001
Apr 26, 2001
419
Mar 22, 2006
Mar 22, 2006
420
XSelectInput(SDL_Display, WMwindow,
Apr 26, 2001
Apr 26, 2001
421
422
423
424
FocusChangeMask | KeyPressMask | KeyReleaseMask
| PropertyChangeMask | StructureNotifyMask | KeymapStateMask);
/* Set the class hints so we can get an icon (AfterStep) */
Feb 3, 2006
Feb 3, 2006
425
get_classname(classname, sizeof(classname));
Apr 26, 2001
Apr 26, 2001
426
427
{
XClassHint *classhints;
Mar 22, 2006
Mar 22, 2006
428
classhints = XAllocClassHint();
Apr 26, 2001
Apr 26, 2001
429
if(classhints != NULL) {
Aug 19, 2002
Aug 19, 2002
430
431
classhints->res_name = classname;
classhints->res_class = classname;
Mar 22, 2006
Mar 22, 2006
432
433
XSetClassHint(SDL_Display, WMwindow, classhints);
XFree(classhints);
Apr 26, 2001
Apr 26, 2001
434
435
436
}
}
Nov 21, 2005
Nov 21, 2005
437
/* Setup the communication with the IM server */
Mar 22, 2006
Mar 22, 2006
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
SDL_IM = NULL;
SDL_IC = NULL;
#ifdef X_HAVE_UTF8_STRING
if (SDL_X11_HAVE_UTF8) {
SDL_IM = XOpenIM(SDL_Display, NULL, classname, classname);
if (SDL_IM == NULL) {
SDL_SetError("no input method could be opened");
} else {
SDL_IC = pXCreateIC(SDL_IM,
XNClientWindow, WMwindow,
XNFocusWindow, WMwindow,
XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
XNResourceName, classname,
XNResourceClass, classname,
NULL);
if (SDL_IC == NULL) {
SDL_SetError("no input context could be created");
XCloseIM(SDL_IM);
SDL_IM = NULL;
}
}
Nov 21, 2005
Nov 21, 2005
461
}
Mar 22, 2006
Mar 22, 2006
462
#endif
Nov 21, 2005
Nov 21, 2005
463
Mar 22, 2006
Mar 22, 2006
464
465
/* Allow the window to be deleted by the window manager */
XSetWMProtocols(SDL_Display, WMwindow, &WM_DELETE_WINDOW, 1);
Apr 26, 2001
Apr 26, 2001
466
467
468
469
470
471
472
473
474
475
}
static int X11_VideoInit(_THIS, SDL_PixelFormat *vformat)
{
char *display;
int i;
/* Open the X11 display */
display = NULL; /* Get it from DISPLAY environment variable */
Mar 22, 2006
Mar 22, 2006
476
477
if ( (SDL_strncmp(XDisplayName(display), ":", 1) == 0) ||
(SDL_strncmp(XDisplayName(display), "unix:", 5) == 0) ) {
Apr 26, 2001
Apr 26, 2001
478
479
480
481
local_X11 = 1;
} else {
local_X11 = 0;
}
Mar 22, 2006
Mar 22, 2006
482
SDL_Display = XOpenDisplay(display);
Feb 16, 2006
Feb 16, 2006
483
#if defined(__osf__) && defined(SDL_VIDEO_DRIVER_X11_DYNAMIC)
Jan 30, 2006
Jan 30, 2006
484
485
486
487
488
489
490
491
492
493
/* 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
494
SDL_Display = XOpenDisplay(display);
Jan 30, 2006
Jan 30, 2006
495
496
}
#endif
Apr 26, 2001
Apr 26, 2001
497
498
499
500
501
if ( SDL_Display == NULL ) {
SDL_SetError("Couldn't open X11 display");
return(-1);
}
#ifdef X11_DEBUG
Mar 22, 2006
Mar 22, 2006
502
XSynchronize(SDL_Display, True);
Apr 26, 2001
Apr 26, 2001
503
504
505
506
507
508
#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
509
GFX_Display = XOpenDisplay(display);
Apr 26, 2001
Apr 26, 2001
510
511
512
513
514
515
if ( GFX_Display == NULL ) {
SDL_SetError("Couldn't open X11 display");
return(-1);
}
/* Set the normal X error handler */
Mar 22, 2006
Mar 22, 2006
516
X_handler = XSetErrorHandler(x_errhandler);
Apr 26, 2001
Apr 26, 2001
517
518
/* Set the error handler if we lose the X display */
Mar 22, 2006
Mar 22, 2006
519
XIO_handler = XSetIOErrorHandler(xio_errhandler);
Apr 26, 2001
Apr 26, 2001
520
Jan 14, 2006
Jan 14, 2006
521
/* Set the X extension error handler */
Mar 22, 2006
Mar 22, 2006
522
Xext_handler = XSetExtensionErrorHandler(xext_errhandler);
Jan 14, 2006
Jan 14, 2006
523
Apr 26, 2001
Apr 26, 2001
524
525
526
527
528
/* 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
529
use_mitshm = 0;
Apr 26, 2001
Apr 26, 2001
530
if ( local_X11 ) {
Mar 22, 2006
Mar 22, 2006
531
use_mitshm = XShmQueryExtension(SDL_Display);
Apr 26, 2001
Apr 26, 2001
532
533
534
535
536
537
538
}
#endif /* NO_SHARED_MEMORY */
/* Get the available video modes */
if(X11_GetVideoModes(this) < 0)
return -1;
Mar 15, 2006
Mar 15, 2006
539
540
541
542
/* 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
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
/* 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
558
SDL_XColorMap = XCreateColormap(SDL_Display, SDL_Root,
Apr 26, 2001
Apr 26, 2001
559
560
561
562
563
564
565
566
567
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
568
569
570
if ( this->hidden->depth == 32 ) {
vformat->Amask = (0xFFFFFFFF & ~(vformat->Rmask|vformat->Gmask|vformat->Bmask));
}
Apr 26, 2001
Apr 26, 2001
571
572
573
X11_SaveVidModeGamma(this);
/* See if we have been passed a window to use */
Feb 7, 2006
Feb 7, 2006
574
SDL_windowid = SDL_getenv("SDL_WINDOWID");
Apr 26, 2001
Apr 26, 2001
575
576
577
578
579
580
581
582
583
584
585
586
587
/* 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
588
XFlush(SDL_Display);
Apr 26, 2001
Apr 26, 2001
589
590
591
592
593
594
595
596
597
598
599
600
601
602
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
603
XUnmapWindow(SDL_Display, WMwindow);
Apr 26, 2001
Apr 26, 2001
604
605
606
607
608
609
610
611
}
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
612
XDestroyWindow(SDL_Display, SDL_Window);
Apr 26, 2001
Apr 26, 2001
613
614
615
616
617
618
619
620
621
}
/* 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
622
XFreeColors(GFX_Display,
Apr 26, 2001
Apr 26, 2001
623
624
625
626
SDL_DisplayColormap,&pixel,1,0);
--SDL_XPixels[pixel];
}
}
Feb 7, 2006
Feb 7, 2006
627
SDL_free(SDL_XPixels);
Apr 26, 2001
Apr 26, 2001
628
629
630
631
632
SDL_XPixels = NULL;
}
/* Free the graphics context */
if ( SDL_GC ) {
Mar 22, 2006
Mar 22, 2006
633
XFreeGC(SDL_Display, SDL_GC);
Apr 26, 2001
Apr 26, 2001
634
635
636
637
638
SDL_GC = 0;
}
}
}
Sep 16, 2002
Sep 16, 2002
639
640
static SDL_bool X11_WindowPosition(_THIS, int *x, int *y, int w, int h)
{
Feb 7, 2006
Feb 7, 2006
641
642
const char *window = SDL_getenv("SDL_VIDEO_WINDOW_POS");
const char *center = SDL_getenv("SDL_VIDEO_CENTERED");
Sep 16, 2002
Sep 16, 2002
643
if ( window ) {
Feb 7, 2006
Feb 7, 2006
644
if ( SDL_sscanf(window, "%d,%d", x, y) == 2 ) {
Sep 16, 2002
Sep 16, 2002
645
646
return SDL_TRUE;
}
Feb 7, 2006
Feb 7, 2006
647
if ( SDL_strcmp(window, "center") == 0 ) {
Sep 16, 2002
Sep 16, 2002
648
649
650
651
652
653
654
655
656
657
658
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
659
660
661
662
static void X11_SetSizeHints(_THIS, int w, int h, Uint32 flags)
{
XSizeHints *hints;
Mar 22, 2006
Mar 22, 2006
663
hints = XAllocSizeHints();
Apr 26, 2001
Apr 26, 2001
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
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
681
if ( X11_WindowPosition(this, &hints->x, &hints->y, w, h) ) {
Apr 26, 2001
Apr 26, 2001
682
hints->flags |= USPosition;
Mar 22, 2006
Mar 22, 2006
683
XMoveWindow(SDL_Display, WMwindow, hints->x, hints->y);
Apr 26, 2001
Apr 26, 2001
684
685
/* Flush the resize event so we don't catch it later */
Mar 22, 2006
Mar 22, 2006
686
XSync(SDL_Display, True);
Apr 26, 2001
Apr 26, 2001
687
}
Mar 22, 2006
Mar 22, 2006
688
689
XSetWMNormalHints(SDL_Display, WMwindow, hints);
XFree(hints);
Apr 26, 2001
Apr 26, 2001
690
691
692
693
694
695
696
697
698
699
700
}
/* 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
701
WM_HINTS = XInternAtom(SDL_Display, "_MOTIF_WM_HINTS", True);
Apr 26, 2001
Apr 26, 2001
702
703
704
705
706
707
708
709
710
711
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
712
XChangeProperty(SDL_Display, WMwindow,
Apr 26, 2001
Apr 26, 2001
713
714
715
716
717
718
719
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
720
WM_HINTS = XInternAtom(SDL_Display, "KWM_WIN_DECORATION", True);
Apr 26, 2001
Apr 26, 2001
721
722
723
if ( WM_HINTS != None ) {
long KWMHints = 0;
Mar 22, 2006
Mar 22, 2006
724
XChangeProperty(SDL_Display, WMwindow,
Apr 26, 2001
Apr 26, 2001
725
726
727
728
729
730
731
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
732
WM_HINTS = XInternAtom(SDL_Display, "_WIN_HINTS", True);
Apr 26, 2001
Apr 26, 2001
733
734
735
if ( WM_HINTS != None ) {
long GNOMEHints = 0;
Mar 22, 2006
Mar 22, 2006
736
XChangeProperty(SDL_Display, WMwindow,
Apr 26, 2001
Apr 26, 2001
737
738
739
740
741
742
743
744
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
745
XSetTransientForHint(SDL_Display, WMwindow, SDL_Root);
Apr 26, 2001
Apr 26, 2001
746
747
748
749
750
751
752
753
754
}
} 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
755
WM_HINTS = XInternAtom(SDL_Display, "_MOTIF_WM_HINTS", True);
Apr 26, 2001
Apr 26, 2001
756
if ( WM_HINTS != None ) {
Mar 22, 2006
Mar 22, 2006
757
XDeleteProperty(SDL_Display, WMwindow, WM_HINTS);
Apr 26, 2001
Apr 26, 2001
758
759
760
set = SDL_TRUE;
}
/* Now try to unset KWM hints */
Mar 22, 2006
Mar 22, 2006
761
WM_HINTS = XInternAtom(SDL_Display, "KWM_WIN_DECORATION", True);
Apr 26, 2001
Apr 26, 2001
762
if ( WM_HINTS != None ) {
Mar 22, 2006
Mar 22, 2006
763
XDeleteProperty(SDL_Display, WMwindow, WM_HINTS);
Apr 26, 2001
Apr 26, 2001
764
765
766
set = SDL_TRUE;
}
/* Now try to unset GNOME hints */
Mar 22, 2006
Mar 22, 2006
767
WM_HINTS = XInternAtom(SDL_Display, "_WIN_HINTS", True);
Apr 26, 2001
Apr 26, 2001
768
if ( WM_HINTS != None ) {
Mar 22, 2006
Mar 22, 2006
769
XDeleteProperty(SDL_Display, WMwindow, WM_HINTS);
Apr 26, 2001
Apr 26, 2001
770
771
772
773
774
set = SDL_TRUE;
}
/* Finally unset the transient hints if necessary */
if ( ! set ) {
/* NOTE: Does this work? */
Mar 22, 2006
Mar 22, 2006
775
XSetTransientForHint(SDL_Display, WMwindow, None);
Apr 26, 2001
Apr 26, 2001
776
777
778
779
780
781
782
783
784
785
}
}
}
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
786
Uint32 Amask;
Apr 26, 2001
Apr 26, 2001
787
788
789
790
/* If a window is already present, destroy it and start fresh */
if ( SDL_Window ) {
X11_DestroyWindow(this, screen);
Feb 26, 2004
Feb 26, 2004
791
switch_waiting = 0; /* Prevent jump back to now-meaningless state. */
Apr 26, 2001
Apr 26, 2001
792
793
794
795
}
/* See if we have been given a window id */
if ( SDL_windowid ) {
Feb 7, 2006
Feb 7, 2006
796
SDL_Window = SDL_strtol(SDL_windowid, NULL, 0);
Apr 26, 2001
Apr 26, 2001
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
} 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
814
XGetWindowAttributes(SDL_Display, SDL_Window, &a);
Apr 26, 2001
Apr 26, 2001
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
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
837
838
839
840
841
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
842
if ( ! SDL_ReallocFormat(screen, bpp,
Apr 17, 2006
Apr 17, 2006
843
vis->red_mask, vis->green_mask, vis->blue_mask, Amask) ) {
Apr 26, 2001
Apr 26, 2001
844
return -1;
Apr 17, 2006
Apr 17, 2006
845
}
Apr 26, 2001
Apr 26, 2001
846
847
848
/* Create the appropriate colormap */
if ( SDL_XColorMap != SDL_DisplayColormap ) {
Mar 22, 2006
Mar 22, 2006
849
XFreeColormap(SDL_Display, SDL_XColorMap);
Apr 26, 2001
Apr 26, 2001
850
851
852
853
854
855
}
if ( SDL_Visual->class == PseudoColor ) {
int ncolors;
/* Allocate the pixel flags */
ncolors = SDL_Visual->map_entries;
Feb 7, 2006
Feb 7, 2006
856
SDL_XPixels = SDL_malloc(ncolors * sizeof(int));
Apr 26, 2001
Apr 26, 2001
857
858
859
860
if(SDL_XPixels == NULL) {
SDL_OutOfMemory();
return -1;
}
Feb 7, 2006
Feb 7, 2006
861
SDL_memset(SDL_XPixels, 0, ncolors * sizeof(*SDL_XPixels));
Apr 26, 2001
Apr 26, 2001
862
863
864
865
866
867
868
/* 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
869
SDL_XColorMap = XCreateColormap(SDL_Display, SDL_Root,
Apr 26, 2001
Apr 26, 2001
870
871
872
873
874
875
876
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
877
SDL_XColorMap = XCreateColormap(SDL_Display, SDL_Root,
Apr 26, 2001
Apr 26, 2001
878
SDL_Visual, AllocAll);
Mar 22, 2006
Mar 22, 2006
879
XSync(SDL_Display, False);
Apr 26, 2001
Apr 26, 2001
880
881
882
883
884
885
886
887
/* 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
888
SDL_XColorMap = XCreateColormap(SDL_Display, SDL_Root,
Apr 26, 2001
Apr 26, 2001
889
890
891
892
893
894
895
896
897
898
899
900
SDL_Visual, AllocNone);
}
/* Recreate the auxiliary windows, if needed (required for GL) */
if ( vis_change )
create_aux_windows(this);
if(screen->flags & SDL_HWPALETTE) {
/* Since the full-screen window might have got a nonzero background
colour (0 is white on some displays), we should reset the
background to 0 here since that is what the user expects
with a private colormap */
Mar 22, 2006
Mar 22, 2006
901
902
XSetWindowBackground(SDL_Display, FSwindow, 0);
XClearWindow(SDL_Display, FSwindow);
Apr 26, 2001
Apr 26, 2001
903
904
905
906
907
}
/* resize the (possibly new) window manager window */
if( !SDL_windowid ) {
X11_SetSizeHints(this, w, h, flags);
Mar 15, 2006
Mar 15, 2006
908
909
window_w = w;
window_h = h;
Mar 22, 2006
Mar 22, 2006
910
XResizeWindow(SDL_Display, WMwindow, w, h);
Apr 26, 2001
Apr 26, 2001
911
912
913
914
915
916
917
918
919
920
921
922
923
924
}
/* Create (or use) the X11 display window */
if ( !SDL_windowid ) {
if ( flags & SDL_OPENGL ) {
if ( X11_GL_CreateWindow(this, w, h) < 0 ) {
return(-1);
}
} else {
XSetWindowAttributes swa;
swa.background_pixel = 0;
swa.border_pixel = 0;
swa.colormap = SDL_XColorMap;
Mar 22, 2006
Mar 22, 2006
925
SDL_Window = XCreateWindow(SDL_Display, WMwindow,
Apr 26, 2001
Apr 26, 2001
926
927
928
929
930
931
0, 0, w, h, 0, depth,
InputOutput, SDL_Visual,
CWBackPixel | CWBorderPixel
| CWColormap, &swa);
}
/* Only manage our input if we own the window */
Mar 22, 2006
Mar 22, 2006
932
XSelectInput(SDL_Display, SDL_Window,
Apr 26, 2001
Apr 26, 2001
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
( EnterWindowMask | LeaveWindowMask
| ButtonPressMask | ButtonReleaseMask
| PointerMotionMask | ExposureMask ));
}
/* Create the graphics context here, once we have a window */
if ( flags & SDL_OPENGL ) {
if ( X11_GL_CreateContext(this) < 0 ) {
return(-1);
} else {
screen->flags |= SDL_OPENGL;
}
} else {
XGCValues gcv;
gcv.graphics_exposures = False;
Mar 22, 2006
Mar 22, 2006
948
SDL_GC = XCreateGC(SDL_Display, SDL_Window,
Apr 26, 2001
Apr 26, 2001
949
950
951
952
953
954
955
956
957
GCGraphicsExposures, &gcv);
if ( ! SDL_GC ) {
SDL_SetError("Couldn't create graphics context");
return(-1);
}
}
/* Set our colormaps when not setting a GL mode */
if ( ! (flags & SDL_OPENGL) ) {
Mar 22, 2006
Mar 22, 2006
958
XSetWindowColormap(SDL_Display, SDL_Window, SDL_XColorMap);
Apr 26, 2001
Apr 26, 2001
959
if( !SDL_windowid ) {
Mar 22, 2006
Mar 22, 2006
960
961
XSetWindowColormap(SDL_Display, FSwindow, SDL_XColorMap);
XSetWindowColormap(SDL_Display, WMwindow, SDL_XColorMap);
Apr 26, 2001
Apr 26, 2001
962
963
964
965
}
}
#if 0 /* This is an experiment - are the graphics faster now? - nope. */
Feb 7, 2006
Feb 7, 2006
966
if ( SDL_getenv("SDL_VIDEO_X11_BACKINGSTORE") )
Apr 26, 2001
Apr 26, 2001
967
968
969
970
971
972
973
974
975
#endif
/* Cache the window in the server, when possible */
{
Screen *xscreen;
XSetWindowAttributes a;
xscreen = ScreenOfDisplay(SDL_Display, SDL_Screen);
a.backing_store = DoesBackingStore(xscreen);
if ( a.backing_store != NotUseful ) {
Mar 22, 2006
Mar 22, 2006
976
XChangeWindowAttributes(SDL_Display, SDL_Window,
Apr 26, 2001
Apr 26, 2001
977
978
979
980
981
CWBackingStore, &a);
}
}
/* Update the internal keyboard state */
Feb 4, 2006
Feb 4, 2006
982
X11_SetKeyboardState(SDL_Display, NULL);
Apr 26, 2001
Apr 26, 2001
983
Aug 18, 2002
Aug 18, 2002
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* When the window is first mapped, ignore non-modifier keys */
{
Uint8 *keys = SDL_GetKeyState(NULL);
for ( i = 0; i < SDLK_LAST; ++i ) {
switch (i) {
case SDLK_NUMLOCK:
case SDLK_CAPSLOCK:
case SDLK_LCTRL:
case SDLK_RCTRL:
case SDLK_LSHIFT:
case SDLK_RSHIFT:
case SDLK_LALT:
case SDLK_RALT:
case SDLK_LMETA:
case SDLK_RMETA:
case SDLK_MODE:
break;