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