comparison src/video/x11/SDL_x11video.c @ 1950:a344e42bce3b

Started work on the new X11 driver.
author Sam Lantinga <slouken@libsdl.org>
date Wed, 26 Jul 2006 06:34:54 +0000
parents
children 7177581dc9fa
comparison
equal deleted inserted replaced
1949:44b6f09a07d8 1950:a344e42bce3b
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2006 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
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
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21 */
22 #include "SDL_config.h"
23
24 #include "SDL_video.h"
25 #include "SDL_mouse.h"
26 #include "../SDL_sysvideo.h"
27 #include "../SDL_pixels_c.h"
28
29 #include "SDL_x11video.h"
30 //#include "SDL_d3drender.h"
31 //#include "SDL_gdirender.h"
32
33 /* Initialization/Query functions */
34 static int X11_VideoInit(_THIS);
35 static void X11_VideoQuit(_THIS);
36
37 /* X11 driver bootstrap functions */
38
39 static int
40 X11_Available(void)
41 {
42 Display *display = NULL;
43 if (SDL_X11_LoadSymbols()) {
44 display = XOpenDisplay(NULL);
45 if (display != NULL) {
46 XCloseDisplay(display);
47 }
48 SDL_X11_UnloadSymbols();
49 }
50 return (display != NULL);
51 }
52
53 static void
54 X11_DeleteDevice(SDL_VideoDevice * device)
55 {
56 SDL_VideoData *data = (SDL_VideoData *) device->driverdata;
57
58 if (data->display) {
59 XCloseDisplay(data->display);
60 }
61 SDL_free(device->driverdata);
62 SDL_free(device);
63
64 SDL_X11_UnloadSymbols();
65 }
66
67 static SDL_VideoDevice *
68 X11_CreateDevice(int devindex)
69 {
70 SDL_VideoDevice *device;
71 SDL_VideoData *data;
72 const char *display = NULL; /* Use the DISPLAY environment variable */
73
74 if (!SDL_X11_LoadSymbols()) {
75 return NULL;
76 }
77
78 /* Initialize all variables that we clean on shutdown */
79 device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
80 if (device) {
81 data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
82 }
83 if (!device || !data) {
84 SDL_OutOfMemory();
85 if (device) {
86 SDL_free(device);
87 }
88 return NULL;
89 }
90 device->driverdata = data;
91
92 /* FIXME: Do we need this?
93 if ( (SDL_strncmp(XDisplayName(display), ":", 1) == 0) ||
94 (SDL_strncmp(XDisplayName(display), "unix:", 5) == 0) ) {
95 local_X11 = 1;
96 } else {
97 local_X11 = 0;
98 }
99 */
100 data->display = XOpenDisplay(display);
101 #if defined(__osf__) && defined(SDL_VIDEO_DRIVER_X11_DYNAMIC)
102 /* On Tru64 if linking without -lX11, it fails and you get following message.
103 * Xlib: connection to ":0.0" refused by server
104 * Xlib: XDM authorization key matches an existing client!
105 *
106 * It succeeds if retrying 1 second later
107 * or if running xhost +localhost on shell.
108 */
109 if (data->display == NULL) {
110 SDL_Delay(1000);
111 data->display = XOpenDisplay(display);
112 }
113 #endif
114 if (data->display == NULL) {
115 SDL_free(device);
116 SDL_SetError("Couldn't open X11 display");
117 return NULL;
118 }
119 #ifdef X11_DEBUG
120 XSynchronize(data->display, True);
121 #endif
122
123 /* Set the function pointers */
124 device->VideoInit = X11_VideoInit;
125 device->VideoQuit = X11_VideoQuit;
126 device->GetDisplayModes = X11_GetDisplayModes;
127 device->SetDisplayMode = X11_SetDisplayMode;
128 // device->SetDisplayGammaRamp = X11_SetDisplayGammaRamp;
129 // device->GetDisplayGammaRamp = X11_GetDisplayGammaRamp;
130 // device->PumpEvents = X11_PumpEvents;
131
132 /*
133 device->CreateWindow = X11_CreateWindow;
134 device->CreateWindowFrom = X11_CreateWindowFrom;
135 device->SetWindowTitle = X11_SetWindowTitle;
136 device->SetWindowPosition = X11_SetWindowPosition;
137 device->SetWindowSize = X11_SetWindowSize;
138 device->ShowWindow = X11_ShowWindow;
139 device->HideWindow = X11_HideWindow;
140 device->RaiseWindow = X11_RaiseWindow;
141 device->MaximizeWindow = X11_MaximizeWindow;
142 device->MinimizeWindow = X11_MinimizeWindow;
143 device->RestoreWindow = X11_RestoreWindow;
144 device->SetWindowGrab = X11_SetWindowGrab;
145 device->DestroyWindow = X11_DestroyWindow;
146 device->GetWindowWMInfo = X11_GetWindowWMInfo;
147 #ifdef SDL_VIDEO_OPENGL
148 device->GL_LoadLibrary = X11_GL_LoadLibrary;
149 device->GL_GetProcAddress = X11_GL_GetProcAddress;
150 device->GL_CreateContext = X11_GL_CreateContext;
151 device->GL_MakeCurrent = X11_GL_MakeCurrent;
152 device->GL_SetSwapInterval = X11_GL_SetSwapInterval;
153 device->GL_GetSwapInterval = X11_GL_GetSwapInterval;
154 device->GL_SwapWindow = X11_GL_SwapWindow;
155 device->GL_DeleteContext = X11_GL_DeleteContext;
156 #endif
157 */
158
159 device->free = X11_DeleteDevice;
160
161 return device;
162 }
163
164 VideoBootStrap X11_bootstrap = {
165 "x11", "SDL X11 video driver",
166 X11_Available, X11_CreateDevice
167 };
168
169
170 int
171 X11_VideoInit(_THIS)
172 {
173 X11_InitModes(_this);
174
175 //#if SDL_VIDEO_RENDER_D3D
176 // D3D_AddRenderDriver(_this);
177 //#endif
178 //#if SDL_VIDEO_RENDER_GDI
179 // GDI_AddRenderDriver(_this);
180 //#endif
181
182 X11_InitKeyboard(_this);
183 X11_InitMouse(_this);
184
185 return 0;
186 }
187
188 void
189 X11_VideoQuit(_THIS)
190 {
191 X11_QuitModes(_this);
192 X11_QuitKeyboard(_this);
193 X11_QuitMouse(_this);
194 }
195
196 /* vim: set ts=4 sw=4 expandtab: */