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