Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
1458 lines (1310 loc) · 46.8 KB

SDL_x11video.c

File metadata and controls

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