comparison src/video/x11/SDL_x11mouse.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
37 Cursor x_cursor; 37 Cursor x_cursor;
38 }; 38 };
39 39
40 40
41 void 41 void
42 X11_FreeWMCursor (_THIS, WMcursor * cursor) 42 X11_FreeWMCursor(_THIS, WMcursor * cursor)
43 { 43 {
44 if (SDL_Display != NULL) { 44 if (SDL_Display != NULL) {
45 SDL_Lock_EventThread (); 45 SDL_Lock_EventThread();
46 XFreeCursor (SDL_Display, cursor->x_cursor); 46 XFreeCursor(SDL_Display, cursor->x_cursor);
47 XSync (SDL_Display, False); 47 XSync(SDL_Display, False);
48 SDL_Unlock_EventThread (); 48 SDL_Unlock_EventThread();
49 } 49 }
50 SDL_free (cursor); 50 SDL_free(cursor);
51 } 51 }
52 52
53 WMcursor * 53 WMcursor *
54 X11_CreateWMCursor (_THIS, 54 X11_CreateWMCursor(_THIS,
55 Uint8 * data, Uint8 * mask, int w, int h, int hot_x, 55 Uint8 * data, Uint8 * mask, int w, int h, int hot_x,
56 int hot_y) 56 int hot_y)
57 { 57 {
58 WMcursor *cursor; 58 WMcursor *cursor;
59 XGCValues GCvalues; 59 XGCValues GCvalues;
60 GC GCcursor; 60 GC GCcursor;
61 XImage *data_image, *mask_image; 61 XImage *data_image, *mask_image;
64 char *x_data, *x_mask; 64 char *x_data, *x_mask;
65 static XColor black = { 0, 0, 0, 0 }; 65 static XColor black = { 0, 0, 0, 0 };
66 static XColor white = { 0xffff, 0xffff, 0xffff, 0xffff }; 66 static XColor white = { 0xffff, 0xffff, 0xffff, 0xffff };
67 67
68 /* Allocate the cursor memory */ 68 /* Allocate the cursor memory */
69 cursor = (WMcursor *) SDL_malloc (sizeof (WMcursor)); 69 cursor = (WMcursor *) SDL_malloc(sizeof(WMcursor));
70 if (cursor == NULL) { 70 if (cursor == NULL) {
71 SDL_OutOfMemory (); 71 SDL_OutOfMemory();
72 return (NULL); 72 return (NULL);
73 } 73 }
74 74
75 /* Mix the mask and the data */ 75 /* Mix the mask and the data */
76 clen = (w / 8) * h; 76 clen = (w / 8) * h;
77 x_data = (char *) SDL_malloc (clen); 77 x_data = (char *) SDL_malloc(clen);
78 if (x_data == NULL) { 78 if (x_data == NULL) {
79 SDL_free (cursor); 79 SDL_free(cursor);
80 SDL_OutOfMemory (); 80 SDL_OutOfMemory();
81 return (NULL); 81 return (NULL);
82 } 82 }
83 x_mask = (char *) SDL_malloc (clen); 83 x_mask = (char *) SDL_malloc(clen);
84 if (x_mask == NULL) { 84 if (x_mask == NULL) {
85 SDL_free (cursor); 85 SDL_free(cursor);
86 SDL_free (x_data); 86 SDL_free(x_data);
87 SDL_OutOfMemory (); 87 SDL_OutOfMemory();
88 return (NULL); 88 return (NULL);
89 } 89 }
90 for (i = 0; i < clen; ++i) { 90 for (i = 0; i < clen; ++i) {
91 /* The mask is OR'd with the data to turn inverted color 91 /* The mask is OR'd with the data to turn inverted color
92 pixels black since inverted color cursors aren't supported 92 pixels black since inverted color cursors aren't supported
95 x_mask[i] = data[i] | mask[i]; 95 x_mask[i] = data[i] | mask[i];
96 x_data[i] = data[i]; 96 x_data[i] = data[i];
97 } 97 }
98 98
99 /* Prevent the event thread from running while we use the X server */ 99 /* Prevent the event thread from running while we use the X server */
100 SDL_Lock_EventThread (); 100 SDL_Lock_EventThread();
101 101
102 /* Create the data image */ 102 /* Create the data image */
103 data_image = XCreateImage (SDL_Display, 103 data_image = XCreateImage(SDL_Display,
104 DefaultVisual (SDL_Display, SDL_Screen), 104 DefaultVisual(SDL_Display, SDL_Screen),
105 1, XYBitmap, 0, x_data, w, h, 8, w / 8); 105 1, XYBitmap, 0, x_data, w, h, 8, w / 8);
106 data_image->byte_order = MSBFirst; 106 data_image->byte_order = MSBFirst;
107 data_image->bitmap_bit_order = MSBFirst; 107 data_image->bitmap_bit_order = MSBFirst;
108 data_pixmap = XCreatePixmap (SDL_Display, SDL_Root, w, h, 1); 108 data_pixmap = XCreatePixmap(SDL_Display, SDL_Root, w, h, 1);
109 109
110 /* Create the data mask */ 110 /* Create the data mask */
111 mask_image = XCreateImage (SDL_Display, 111 mask_image = XCreateImage(SDL_Display,
112 DefaultVisual (SDL_Display, SDL_Screen), 112 DefaultVisual(SDL_Display, SDL_Screen),
113 1, XYBitmap, 0, x_mask, w, h, 8, w / 8); 113 1, XYBitmap, 0, x_mask, w, h, 8, w / 8);
114 mask_image->byte_order = MSBFirst; 114 mask_image->byte_order = MSBFirst;
115 mask_image->bitmap_bit_order = MSBFirst; 115 mask_image->bitmap_bit_order = MSBFirst;
116 mask_pixmap = XCreatePixmap (SDL_Display, SDL_Root, w, h, 1); 116 mask_pixmap = XCreatePixmap(SDL_Display, SDL_Root, w, h, 1);
117 117
118 /* Create the graphics context */ 118 /* Create the graphics context */
119 GCvalues.function = GXcopy; 119 GCvalues.function = GXcopy;
120 GCvalues.foreground = ~0; 120 GCvalues.foreground = ~0;
121 GCvalues.background = 0; 121 GCvalues.background = 0;
122 GCvalues.plane_mask = AllPlanes; 122 GCvalues.plane_mask = AllPlanes;
123 GCcursor = XCreateGC (SDL_Display, data_pixmap, 123 GCcursor = XCreateGC(SDL_Display, data_pixmap,
124 (GCFunction | GCForeground | GCBackground | 124 (GCFunction | GCForeground | GCBackground |
125 GCPlaneMask), &GCvalues); 125 GCPlaneMask), &GCvalues);
126 126
127 /* Blit the images to the pixmaps */ 127 /* Blit the images to the pixmaps */
128 XPutImage (SDL_Display, data_pixmap, GCcursor, data_image, 128 XPutImage(SDL_Display, data_pixmap, GCcursor, data_image,
129 0, 0, 0, 0, w, h); 129 0, 0, 0, 0, w, h);
130 XPutImage (SDL_Display, mask_pixmap, GCcursor, mask_image, 130 XPutImage(SDL_Display, mask_pixmap, GCcursor, mask_image,
131 0, 0, 0, 0, w, h); 131 0, 0, 0, 0, w, h);
132 XFreeGC (SDL_Display, GCcursor); 132 XFreeGC(SDL_Display, GCcursor);
133 /* These free the x_data and x_mask memory pointers */ 133 /* These free the x_data and x_mask memory pointers */
134 XDestroyImage (data_image); 134 XDestroyImage(data_image);
135 XDestroyImage (mask_image); 135 XDestroyImage(mask_image);
136 136
137 /* Create the cursor */ 137 /* Create the cursor */
138 cursor->x_cursor = XCreatePixmapCursor (SDL_Display, data_pixmap, 138 cursor->x_cursor = XCreatePixmapCursor(SDL_Display, data_pixmap,
139 mask_pixmap, &black, &white, 139 mask_pixmap, &black, &white,
140 hot_x, hot_y); 140 hot_x, hot_y);
141 XFreePixmap (SDL_Display, data_pixmap); 141 XFreePixmap(SDL_Display, data_pixmap);
142 XFreePixmap (SDL_Display, mask_pixmap); 142 XFreePixmap(SDL_Display, mask_pixmap);
143 143
144 /* Release the event thread */ 144 /* Release the event thread */
145 XSync (SDL_Display, False); 145 XSync(SDL_Display, False);
146 SDL_Unlock_EventThread (); 146 SDL_Unlock_EventThread();
147 147
148 return (cursor); 148 return (cursor);
149 } 149 }
150 150
151 int 151 int
152 X11_ShowWMCursor (_THIS, WMcursor * cursor) 152 X11_ShowWMCursor(_THIS, WMcursor * cursor)
153 { 153 {
154 /* Don't do anything if the display is gone */ 154 /* Don't do anything if the display is gone */
155 if (SDL_Display == NULL) { 155 if (SDL_Display == NULL) {
156 return (0); 156 return (0);
157 } 157 }
158 158
159 /* Set the X11 cursor cursor, or blank if cursor is NULL */ 159 /* Set the X11 cursor cursor, or blank if cursor is NULL */
160 if (SDL_Window) { 160 if (SDL_Window) {
161 SDL_Lock_EventThread (); 161 SDL_Lock_EventThread();
162 if (cursor == NULL) { 162 if (cursor == NULL) {
163 if (SDL_BlankCursor != NULL) { 163 if (SDL_BlankCursor != NULL) {
164 XDefineCursor (SDL_Display, SDL_Window, 164 XDefineCursor(SDL_Display, SDL_Window,
165 SDL_BlankCursor->x_cursor); 165 SDL_BlankCursor->x_cursor);
166 } 166 }
167 } else { 167 } else {
168 XDefineCursor (SDL_Display, SDL_Window, cursor->x_cursor); 168 XDefineCursor(SDL_Display, SDL_Window, cursor->x_cursor);
169 } 169 }
170 XSync (SDL_Display, False); 170 XSync(SDL_Display, False);
171 SDL_Unlock_EventThread (); 171 SDL_Unlock_EventThread();
172 } 172 }
173 return (1); 173 return (1);
174 } 174 }
175 175
176 void 176 void
177 X11_WarpWMCursor (_THIS, Uint16 x, Uint16 y) 177 X11_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
178 { 178 {
179 if (using_dga & DGA_MOUSE) { 179 if (using_dga & DGA_MOUSE) {
180 SDL_PrivateMouseMotion (0, 0, x, y); 180 SDL_PrivateMouseMotion(0, 0, x, y);
181 } else if (mouse_relative) { 181 } else if (mouse_relative) {
182 /* RJR: March 28, 2000 182 /* RJR: March 28, 2000
183 leave physical cursor at center of screen if 183 leave physical cursor at center of screen if
184 mouse hidden and grabbed */ 184 mouse hidden and grabbed */
185 SDL_PrivateMouseMotion (0, 0, x, y); 185 SDL_PrivateMouseMotion(0, 0, x, y);
186 } else { 186 } else {
187 SDL_Lock_EventThread (); 187 SDL_Lock_EventThread();
188 XWarpPointer (SDL_Display, None, SDL_Window, 0, 0, 0, 0, x, y); 188 XWarpPointer(SDL_Display, None, SDL_Window, 0, 0, 0, 0, x, y);
189 XSync (SDL_Display, False); 189 XSync(SDL_Display, False);
190 SDL_Unlock_EventThread (); 190 SDL_Unlock_EventThread();
191 } 191 }
192 } 192 }
193 193
194 /* Sets the mouse acceleration from a string of the form: 194 /* Sets the mouse acceleration from a string of the form:
195 2/1/0 195 2/1/0
196 The first number is the numerator, followed by the acceleration 196 The first number is the numerator, followed by the acceleration
197 denumenator and threshold. 197 denumenator and threshold.
198 */ 198 */
199 static void 199 static void
200 SetMouseAccel (_THIS, const char *accel_param) 200 SetMouseAccel(_THIS, const char *accel_param)
201 { 201 {
202 int i; 202 int i;
203 size_t len; 203 size_t len;
204 int accel_value[3]; 204 int accel_value[3];
205 char *mouse_param, *mouse_param_buf, *pin; 205 char *mouse_param, *mouse_param_buf, *pin;
206 206
207 len = SDL_strlen (accel_param) + 1; 207 len = SDL_strlen(accel_param) + 1;
208 mouse_param_buf = SDL_stack_alloc (char, len); 208 mouse_param_buf = SDL_stack_alloc(char, len);
209 if (!mouse_param_buf) { 209 if (!mouse_param_buf) {
210 return; 210 return;
211 } 211 }
212 SDL_strlcpy (mouse_param_buf, accel_param, len); 212 SDL_strlcpy(mouse_param_buf, accel_param, len);
213 mouse_param = mouse_param_buf; 213 mouse_param = mouse_param_buf;
214 214
215 for (i = 0; (i < 3) && mouse_param; ++i) { 215 for (i = 0; (i < 3) && mouse_param; ++i) {
216 pin = SDL_strchr (mouse_param, '/'); 216 pin = SDL_strchr(mouse_param, '/');
217 if (pin) { 217 if (pin) {
218 *pin = '\0'; 218 *pin = '\0';
219 } 219 }
220 accel_value[i] = atoi (mouse_param); 220 accel_value[i] = atoi(mouse_param);
221 if (pin) { 221 if (pin) {
222 mouse_param = pin + 1; 222 mouse_param = pin + 1;
223 } else { 223 } else {
224 mouse_param = NULL; 224 mouse_param = NULL;
225 } 225 }
226 } 226 }
227 if (mouse_param_buf) { 227 if (mouse_param_buf) {
228 XChangePointerControl (SDL_Display, True, True, 228 XChangePointerControl(SDL_Display, True, True,
229 accel_value[0], accel_value[1], 229 accel_value[0], accel_value[1], accel_value[2]);
230 accel_value[2]); 230 SDL_free(mouse_param_buf);
231 SDL_free (mouse_param_buf);
232 } 231 }
233 } 232 }
234 233
235 /* Check to see if we need to enter or leave mouse relative mode */ 234 /* Check to see if we need to enter or leave mouse relative mode */
236 void 235 void
237 X11_CheckMouseModeNoLock (_THIS) 236 X11_CheckMouseModeNoLock(_THIS)
238 { 237 {
239 const Uint8 full_focus = 238 const Uint8 full_focus =
240 (SDL_APPACTIVE | SDL_APPINPUTFOCUS | SDL_APPMOUSEFOCUS); 239 (SDL_APPACTIVE | SDL_APPINPUTFOCUS | SDL_APPMOUSEFOCUS);
241 char *env_override; 240 char *env_override;
242 int enable_relative = 1; 241 int enable_relative = 1;
243 242
244 /* Allow the user to override the relative mouse mode. 243 /* Allow the user to override the relative mouse mode.
245 They almost never want to do this, as it seriously affects 244 They almost never want to do this, as it seriously affects
246 applications that rely on continuous relative mouse motion. 245 applications that rely on continuous relative mouse motion.
247 */ 246 */
248 env_override = SDL_getenv ("SDL_MOUSE_RELATIVE"); 247 env_override = SDL_getenv("SDL_MOUSE_RELATIVE");
249 if (env_override) { 248 if (env_override) {
250 enable_relative = atoi (env_override); 249 enable_relative = atoi(env_override);
251 } 250 }
252 251
253 /* If the mouse is hidden and input is grabbed, we use relative mode */ 252 /* If the mouse is hidden and input is grabbed, we use relative mode */
254 if (enable_relative && 253 if (enable_relative &&
255 !(SDL_cursorstate & CURSOR_VISIBLE) && 254 !(SDL_cursorstate & CURSOR_VISIBLE) &&
256 (SDL_CurrentWindow.input_grab != SDL_GRAB_OFF) && 255 (SDL_CurrentWindow.input_grab != SDL_GRAB_OFF) &&
257 (SDL_GetAppState () & full_focus) == full_focus) { 256 (SDL_GetAppState() & full_focus) == full_focus) {
258 if (!mouse_relative) { 257 if (!mouse_relative) {
259 X11_EnableDGAMouse (this); 258 X11_EnableDGAMouse(this);
260 if (!(using_dga & DGA_MOUSE)) { 259 if (!(using_dga & DGA_MOUSE)) {
261 char *xmouse_accel; 260 char *xmouse_accel;
262 261
263 SDL_GetMouseState (&mouse_last.x, &mouse_last.y); 262 SDL_GetMouseState(&mouse_last.x, &mouse_last.y);
264 /* Use as raw mouse mickeys as possible */ 263 /* Use as raw mouse mickeys as possible */
265 XGetPointerControl (SDL_Display, 264 XGetPointerControl(SDL_Display,
266 &mouse_accel.numerator, 265 &mouse_accel.numerator,
267 &mouse_accel.denominator, 266 &mouse_accel.denominator,
268 &mouse_accel.threshold); 267 &mouse_accel.threshold);
269 xmouse_accel = SDL_getenv ("SDL_VIDEO_X11_MOUSEACCEL"); 268 xmouse_accel = SDL_getenv("SDL_VIDEO_X11_MOUSEACCEL");
270 if (xmouse_accel) { 269 if (xmouse_accel) {
271 SetMouseAccel (this, xmouse_accel); 270 SetMouseAccel(this, xmouse_accel);
272 } 271 }
273 } 272 }
274 mouse_relative = 1; 273 mouse_relative = 1;
275 } 274 }
276 } else { 275 } else {
277 if (mouse_relative) { 276 if (mouse_relative) {
278 if (using_dga & DGA_MOUSE) { 277 if (using_dga & DGA_MOUSE) {
279 X11_DisableDGAMouse (this); 278 X11_DisableDGAMouse(this);
280 } else { 279 } else {
281 XChangePointerControl (SDL_Display, True, True, 280 XChangePointerControl(SDL_Display, True, True,
282 mouse_accel.numerator, 281 mouse_accel.numerator,
283 mouse_accel.denominator, 282 mouse_accel.denominator,
284 mouse_accel.threshold); 283 mouse_accel.threshold);
285 } 284 }
286 mouse_relative = 0; 285 mouse_relative = 0;
287 } 286 }
288 } 287 }
289 } 288 }
290 void 289 void
291 X11_CheckMouseMode (_THIS) 290 X11_CheckMouseMode(_THIS)
292 { 291 {
293 SDL_Lock_EventThread (); 292 SDL_Lock_EventThread();
294 X11_CheckMouseModeNoLock (this); 293 X11_CheckMouseModeNoLock(this);
295 SDL_Unlock_EventThread (); 294 SDL_Unlock_EventThread();
296 } 295 }
297 296
298 /* vi: set ts=4 sw=4 expandtab: */ 297 /* vi: set ts=4 sw=4 expandtab: */