comparison src/video/x11/SDL_x11mouse.c @ 1168:045f186426e1

Dynamically load X11 libraries like we currently do for alsa, esd, etc. This allows you to run an SDL program on a system without Xlib, since it'll just report the x11 target unavailable at runtime.
author Ryan C. Gordon <icculus@icculus.org>
date Sat, 05 Nov 2005 19:53:37 +0000
parents 07def9d03315
children c9b51268668f
comparison
equal deleted inserted replaced
1167:435c2e481299 1168:045f186426e1
48 48
49 void X11_FreeWMCursor(_THIS, WMcursor *cursor) 49 void X11_FreeWMCursor(_THIS, WMcursor *cursor)
50 { 50 {
51 if ( SDL_Display != NULL ) { 51 if ( SDL_Display != NULL ) {
52 SDL_Lock_EventThread(); 52 SDL_Lock_EventThread();
53 XFreeCursor(SDL_Display, cursor->x_cursor); 53 pXFreeCursor(SDL_Display, cursor->x_cursor);
54 XSync(SDL_Display, False); 54 pXSync(SDL_Display, False);
55 SDL_Unlock_EventThread(); 55 SDL_Unlock_EventThread();
56 } 56 }
57 free(cursor); 57 free(cursor);
58 } 58 }
59 59
103 103
104 /* Prevent the event thread from running while we use the X server */ 104 /* Prevent the event thread from running while we use the X server */
105 SDL_Lock_EventThread(); 105 SDL_Lock_EventThread();
106 106
107 /* Create the data image */ 107 /* Create the data image */
108 data_image = XCreateImage(SDL_Display, 108 data_image = pXCreateImage(SDL_Display,
109 DefaultVisual(SDL_Display, SDL_Screen), 109 DefaultVisual(SDL_Display, SDL_Screen),
110 1, XYBitmap, 0, x_data, w, h, 8, w/8); 110 1, XYBitmap, 0, x_data, w, h, 8, w/8);
111 data_image->byte_order = MSBFirst; 111 data_image->byte_order = MSBFirst;
112 data_image->bitmap_bit_order = MSBFirst; 112 data_image->bitmap_bit_order = MSBFirst;
113 data_pixmap = XCreatePixmap(SDL_Display, SDL_Root, w, h, 1); 113 data_pixmap = pXCreatePixmap(SDL_Display, SDL_Root, w, h, 1);
114 114
115 /* Create the data mask */ 115 /* Create the data mask */
116 mask_image = XCreateImage(SDL_Display, 116 mask_image = pXCreateImage(SDL_Display,
117 DefaultVisual(SDL_Display, SDL_Screen), 117 DefaultVisual(SDL_Display, SDL_Screen),
118 1, XYBitmap, 0, x_mask, w, h, 8, w/8); 118 1, XYBitmap, 0, x_mask, w, h, 8, w/8);
119 mask_image->byte_order = MSBFirst; 119 mask_image->byte_order = MSBFirst;
120 mask_image->bitmap_bit_order = MSBFirst; 120 mask_image->bitmap_bit_order = MSBFirst;
121 mask_pixmap = XCreatePixmap(SDL_Display, SDL_Root, w, h, 1); 121 mask_pixmap = pXCreatePixmap(SDL_Display, SDL_Root, w, h, 1);
122 122
123 /* Create the graphics context */ 123 /* Create the graphics context */
124 GCvalues.function = GXcopy; 124 GCvalues.function = GXcopy;
125 GCvalues.foreground = ~0; 125 GCvalues.foreground = ~0;
126 GCvalues.background = 0; 126 GCvalues.background = 0;
127 GCvalues.plane_mask = AllPlanes; 127 GCvalues.plane_mask = AllPlanes;
128 GCcursor = XCreateGC(SDL_Display, data_pixmap, 128 GCcursor = pXCreateGC(SDL_Display, data_pixmap,
129 (GCFunction|GCForeground|GCBackground|GCPlaneMask), 129 (GCFunction|GCForeground|GCBackground|GCPlaneMask),
130 &GCvalues); 130 &GCvalues);
131 131
132 /* Blit the images to the pixmaps */ 132 /* Blit the images to the pixmaps */
133 XPutImage(SDL_Display, data_pixmap, GCcursor, data_image, 133 pXPutImage(SDL_Display, data_pixmap, GCcursor, data_image,
134 0, 0, 0, 0, w, h); 134 0, 0, 0, 0, w, h);
135 XPutImage(SDL_Display, mask_pixmap, GCcursor, mask_image, 135 pXPutImage(SDL_Display, mask_pixmap, GCcursor, mask_image,
136 0, 0, 0, 0, w, h); 136 0, 0, 0, 0, w, h);
137 XFreeGC(SDL_Display, GCcursor); 137 pXFreeGC(SDL_Display, GCcursor);
138 /* These free the x_data and x_mask memory pointers */ 138 /* These free the x_data and x_mask memory pointers */
139 XDestroyImage(data_image); 139 pXDestroyImage(data_image);
140 XDestroyImage(mask_image); 140 pXDestroyImage(mask_image);
141 141
142 /* Create the cursor */ 142 /* Create the cursor */
143 cursor->x_cursor = XCreatePixmapCursor(SDL_Display, data_pixmap, 143 cursor->x_cursor = pXCreatePixmapCursor(SDL_Display, data_pixmap,
144 mask_pixmap, &black, &white, hot_x, hot_y); 144 mask_pixmap, &black, &white, hot_x, hot_y);
145 XFreePixmap(SDL_Display, data_pixmap); 145 pXFreePixmap(SDL_Display, data_pixmap);
146 XFreePixmap(SDL_Display, mask_pixmap); 146 pXFreePixmap(SDL_Display, mask_pixmap);
147 147
148 /* Release the event thread */ 148 /* Release the event thread */
149 XSync(SDL_Display, False); 149 pXSync(SDL_Display, False);
150 SDL_Unlock_EventThread(); 150 SDL_Unlock_EventThread();
151 151
152 return(cursor); 152 return(cursor);
153 } 153 }
154 154
162 /* Set the X11 cursor cursor, or blank if cursor is NULL */ 162 /* Set the X11 cursor cursor, or blank if cursor is NULL */
163 if ( SDL_Window ) { 163 if ( SDL_Window ) {
164 SDL_Lock_EventThread(); 164 SDL_Lock_EventThread();
165 if ( cursor == NULL ) { 165 if ( cursor == NULL ) {
166 if ( SDL_BlankCursor != NULL ) { 166 if ( SDL_BlankCursor != NULL ) {
167 XDefineCursor(SDL_Display, SDL_Window, 167 pXDefineCursor(SDL_Display, SDL_Window,
168 SDL_BlankCursor->x_cursor); 168 SDL_BlankCursor->x_cursor);
169 } 169 }
170 } else { 170 } else {
171 XDefineCursor(SDL_Display, SDL_Window, cursor->x_cursor); 171 pXDefineCursor(SDL_Display, SDL_Window, cursor->x_cursor);
172 } 172 }
173 XSync(SDL_Display, False); 173 pXSync(SDL_Display, False);
174 SDL_Unlock_EventThread(); 174 SDL_Unlock_EventThread();
175 } 175 }
176 return(1); 176 return(1);
177 } 177 }
178 178
185 leave physical cursor at center of screen if 185 leave physical cursor at center of screen if
186 mouse hidden and grabbed */ 186 mouse hidden and grabbed */
187 SDL_PrivateMouseMotion(0, 0, x, y); 187 SDL_PrivateMouseMotion(0, 0, x, y);
188 } else { 188 } else {
189 SDL_Lock_EventThread(); 189 SDL_Lock_EventThread();
190 XWarpPointer(SDL_Display, None, SDL_Window, 0, 0, 0, 0, x, y); 190 pXWarpPointer(SDL_Display, None, SDL_Window, 0, 0, 0, 0, x, y);
191 XSync(SDL_Display, False); 191 pXSync(SDL_Display, False);
192 SDL_Unlock_EventThread(); 192 SDL_Unlock_EventThread();
193 } 193 }
194 } 194 }
195 195
196 /* Sets the mouse acceleration from a string of the form: 196 /* Sets the mouse acceleration from a string of the form:
222 } else { 222 } else {
223 mouse_param = NULL; 223 mouse_param = NULL;
224 } 224 }
225 } 225 }
226 if ( mouse_param_buf ) { 226 if ( mouse_param_buf ) {
227 XChangePointerControl(SDL_Display, True, True, 227 pXChangePointerControl(SDL_Display, True, True,
228 accel_value[0], accel_value[1], accel_value[2]); 228 accel_value[0], accel_value[1], accel_value[2]);
229 free(mouse_param_buf); 229 free(mouse_param_buf);
230 } 230 }
231 } 231 }
232 232
255 if ( ! (using_dga & DGA_MOUSE) ) { 255 if ( ! (using_dga & DGA_MOUSE) ) {
256 char *xmouse_accel; 256 char *xmouse_accel;
257 257
258 SDL_GetMouseState(&mouse_last.x, &mouse_last.y); 258 SDL_GetMouseState(&mouse_last.x, &mouse_last.y);
259 /* Use as raw mouse mickeys as possible */ 259 /* Use as raw mouse mickeys as possible */
260 XGetPointerControl(SDL_Display, 260 pXGetPointerControl(SDL_Display,
261 &mouse_accel.numerator, 261 &mouse_accel.numerator,
262 &mouse_accel.denominator, 262 &mouse_accel.denominator,
263 &mouse_accel.threshold); 263 &mouse_accel.threshold);
264 xmouse_accel=getenv("SDL_VIDEO_X11_MOUSEACCEL"); 264 xmouse_accel=getenv("SDL_VIDEO_X11_MOUSEACCEL");
265 if ( xmouse_accel ) { 265 if ( xmouse_accel ) {
271 } else { 271 } else {
272 if ( mouse_relative ) { 272 if ( mouse_relative ) {
273 if ( using_dga & DGA_MOUSE ) { 273 if ( using_dga & DGA_MOUSE ) {
274 X11_DisableDGAMouse(this); 274 X11_DisableDGAMouse(this);
275 } else { 275 } else {
276 XChangePointerControl(SDL_Display, True, True, 276 pXChangePointerControl(SDL_Display, True, True,
277 mouse_accel.numerator, 277 mouse_accel.numerator,
278 mouse_accel.denominator, 278 mouse_accel.denominator,
279 mouse_accel.threshold); 279 mouse_accel.threshold);
280 } 280 }
281 mouse_relative = 0; 281 mouse_relative = 0;