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