Mercurial > sdl-ios-xcode
annotate src/video/x11/SDL_x11mouse.c @ 1338:604d73db6802
Removed uses of stdlib.h and string.h
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 07 Feb 2006 09:29:18 +0000 |
parents | 3692456e7b0f |
children | c71e05b4dc2e |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1168
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:
1168
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:
1168
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:
1168
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:
1168
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:
1168
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:
1168
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:
80
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 #include <X11/Xlib.h> | |
24 #include <X11/Xutil.h> | |
25 | |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
26 #include "SDL_stdlib.h" |
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
27 #include "SDL_string.h" |
0 | 28 #include "SDL_error.h" |
29 #include "SDL_mouse.h" | |
30 #include "SDL_events_c.h" | |
31 #include "SDL_cursor_c.h" | |
32 #include "SDL_x11dga_c.h" | |
33 #include "SDL_x11mouse_c.h" | |
34 | |
35 | |
36 /* The implementation dependent data for the window manager cursor */ | |
37 struct WMcursor { | |
38 Cursor x_cursor; | |
39 }; | |
40 | |
41 | |
42 void X11_FreeWMCursor(_THIS, WMcursor *cursor) | |
43 { | |
44 if ( SDL_Display != NULL ) { | |
45 SDL_Lock_EventThread(); | |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
888
diff
changeset
|
46 pXFreeCursor(SDL_Display, cursor->x_cursor); |
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
888
diff
changeset
|
47 pXSync(SDL_Display, False); |
0 | 48 SDL_Unlock_EventThread(); |
49 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
50 SDL_free(cursor); |
0 | 51 } |
52 | |
53 WMcursor *X11_CreateWMCursor(_THIS, | |
54 Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y) | |
55 { | |
56 WMcursor *cursor; | |
57 XGCValues GCvalues; | |
58 GC GCcursor; | |
59 XImage *data_image, *mask_image; | |
60 Pixmap data_pixmap, mask_pixmap; | |
61 int clen, i; | |
62 char *x_data, *x_mask; | |
63 static XColor black = { 0, 0, 0, 0 }; | |
64 static XColor white = { 0xffff, 0xffff, 0xffff, 0xffff }; | |
65 | |
66 /* Allocate the cursor memory */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
67 cursor = (WMcursor *)SDL_malloc(sizeof(WMcursor)); |
0 | 68 if ( cursor == NULL ) { |
69 SDL_OutOfMemory(); | |
70 return(NULL); | |
71 } | |
72 | |
73 /* Mix the mask and the data */ | |
74 clen = (w/8)*h; | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
75 x_data = (char *)SDL_malloc(clen); |
0 | 76 if ( x_data == NULL ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
77 SDL_free(cursor); |
0 | 78 SDL_OutOfMemory(); |
79 return(NULL); | |
80 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
81 x_mask = (char *)SDL_malloc(clen); |
0 | 82 if ( x_mask == NULL ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
83 SDL_free(cursor); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
84 SDL_free(x_data); |
0 | 85 SDL_OutOfMemory(); |
86 return(NULL); | |
87 } | |
88 for ( i=0; i<clen; ++i ) { | |
89 /* The mask is OR'd with the data to turn inverted color | |
90 pixels black since inverted color cursors aren't supported | |
91 under X11. | |
92 */ | |
93 x_mask[i] = data[i] | mask[i]; | |
94 x_data[i] = data[i]; | |
95 } | |
96 | |
97 /* Prevent the event thread from running while we use the X server */ | |
98 SDL_Lock_EventThread(); | |
99 | |
100 /* Create the data image */ | |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
888
diff
changeset
|
101 data_image = pXCreateImage(SDL_Display, |
0 | 102 DefaultVisual(SDL_Display, SDL_Screen), |
103 1, XYBitmap, 0, x_data, w, h, 8, w/8); | |
104 data_image->byte_order = MSBFirst; | |
105 data_image->bitmap_bit_order = MSBFirst; | |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
888
diff
changeset
|
106 data_pixmap = pXCreatePixmap(SDL_Display, SDL_Root, w, h, 1); |
0 | 107 |
108 /* Create the data mask */ | |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
888
diff
changeset
|
109 mask_image = pXCreateImage(SDL_Display, |
0 | 110 DefaultVisual(SDL_Display, SDL_Screen), |
111 1, XYBitmap, 0, x_mask, w, h, 8, w/8); | |
112 mask_image->byte_order = MSBFirst; | |
113 mask_image->bitmap_bit_order = MSBFirst; | |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
888
diff
changeset
|
114 mask_pixmap = pXCreatePixmap(SDL_Display, SDL_Root, w, h, 1); |
0 | 115 |
116 /* Create the graphics context */ | |
117 GCvalues.function = GXcopy; | |
118 GCvalues.foreground = ~0; | |
119 GCvalues.background = 0; | |
120 GCvalues.plane_mask = AllPlanes; | |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
888
diff
changeset
|
121 GCcursor = pXCreateGC(SDL_Display, data_pixmap, |
0 | 122 (GCFunction|GCForeground|GCBackground|GCPlaneMask), |
123 &GCvalues); | |
124 | |
125 /* Blit the images to the pixmaps */ | |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
888
diff
changeset
|
126 pXPutImage(SDL_Display, data_pixmap, GCcursor, data_image, |
0 | 127 0, 0, 0, 0, w, h); |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
888
diff
changeset
|
128 pXPutImage(SDL_Display, mask_pixmap, GCcursor, mask_image, |
0 | 129 0, 0, 0, 0, w, h); |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
888
diff
changeset
|
130 pXFreeGC(SDL_Display, GCcursor); |
0 | 131 /* These free the x_data and x_mask memory pointers */ |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
888
diff
changeset
|
132 pXDestroyImage(data_image); |
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
888
diff
changeset
|
133 pXDestroyImage(mask_image); |
0 | 134 |
135 /* Create the cursor */ | |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
888
diff
changeset
|
136 cursor->x_cursor = pXCreatePixmapCursor(SDL_Display, data_pixmap, |
0 | 137 mask_pixmap, &black, &white, hot_x, hot_y); |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
888
diff
changeset
|
138 pXFreePixmap(SDL_Display, data_pixmap); |
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
888
diff
changeset
|
139 pXFreePixmap(SDL_Display, mask_pixmap); |
0 | 140 |
141 /* 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:
888
diff
changeset
|
142 pXSync(SDL_Display, False); |
0 | 143 SDL_Unlock_EventThread(); |
144 | |
145 return(cursor); | |
146 } | |
147 | |
148 int X11_ShowWMCursor(_THIS, WMcursor *cursor) | |
149 { | |
150 /* Don't do anything if the display is gone */ | |
151 if ( SDL_Display == NULL ) { | |
152 return(0); | |
153 } | |
154 | |
155 /* Set the X11 cursor cursor, or blank if cursor is NULL */ | |
156 if ( SDL_Window ) { | |
157 SDL_Lock_EventThread(); | |
158 if ( cursor == NULL ) { | |
159 if ( SDL_BlankCursor != NULL ) { | |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
888
diff
changeset
|
160 pXDefineCursor(SDL_Display, SDL_Window, |
0 | 161 SDL_BlankCursor->x_cursor); |
162 } | |
163 } else { | |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
888
diff
changeset
|
164 pXDefineCursor(SDL_Display, SDL_Window, cursor->x_cursor); |
0 | 165 } |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
888
diff
changeset
|
166 pXSync(SDL_Display, False); |
0 | 167 SDL_Unlock_EventThread(); |
168 } | |
169 return(1); | |
170 } | |
171 | |
172 void X11_WarpWMCursor(_THIS, Uint16 x, Uint16 y) | |
173 { | |
174 if ( using_dga & DGA_MOUSE ) { | |
527
5c74ac147358
Fixed mouse warp position bug with offset video modes
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
175 SDL_PrivateMouseMotion(0, 0, x, y); |
5c74ac147358
Fixed mouse warp position bug with offset video modes
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
176 } else if ( mouse_relative) { |
5c74ac147358
Fixed mouse warp position bug with offset video modes
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
177 /* RJR: March 28, 2000 |
5c74ac147358
Fixed mouse warp position bug with offset video modes
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
178 leave physical cursor at center of screen if |
5c74ac147358
Fixed mouse warp position bug with offset video modes
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
179 mouse hidden and grabbed */ |
0 | 180 SDL_PrivateMouseMotion(0, 0, x, y); |
181 } else { | |
182 SDL_Lock_EventThread(); | |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
888
diff
changeset
|
183 pXWarpPointer(SDL_Display, None, SDL_Window, 0, 0, 0, 0, x, y); |
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
888
diff
changeset
|
184 pXSync(SDL_Display, False); |
0 | 185 SDL_Unlock_EventThread(); |
186 } | |
187 } | |
188 | |
189 /* Sets the mouse acceleration from a string of the form: | |
190 2/1/0 | |
191 The first number is the numerator, followed by the acceleration | |
192 denumenator and threshold. | |
193 */ | |
194 static void SetMouseAccel(_THIS, const char *accel_param) | |
195 { | |
196 int i; | |
197 int accel_value[3]; | |
198 char *mouse_param, *mouse_param_buf, *pin; | |
199 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
200 mouse_param_buf = (char *)SDL_malloc(SDL_strlen(accel_param)+1); |
0 | 201 if ( ! mouse_param_buf ) { |
202 return; | |
203 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
204 SDL_strcpy(mouse_param_buf, accel_param); |
0 | 205 mouse_param = mouse_param_buf; |
206 | |
207 for ( i=0; (i < 3) && mouse_param; ++i ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
208 pin = SDL_strchr(mouse_param, '/'); |
0 | 209 if ( pin ) { |
210 *pin = '\0'; | |
211 } | |
212 accel_value[i] = atoi(mouse_param); | |
213 if ( pin ) { | |
214 mouse_param = pin+1; | |
215 } else { | |
216 mouse_param = NULL; | |
217 } | |
218 } | |
219 if ( mouse_param_buf ) { | |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
888
diff
changeset
|
220 pXChangePointerControl(SDL_Display, True, True, |
0 | 221 accel_value[0], accel_value[1], accel_value[2]); |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
222 SDL_free(mouse_param_buf); |
0 | 223 } |
224 } | |
225 | |
226 /* Check to see if we need to enter or leave mouse relative mode */ | |
227 void X11_CheckMouseModeNoLock(_THIS) | |
228 { | |
79
ffadd05de74d
Allow the user to override the relative mouse mode.
Sam Lantinga <slouken@lokigames.com>
parents:
78
diff
changeset
|
229 char *env_override; |
ffadd05de74d
Allow the user to override the relative mouse mode.
Sam Lantinga <slouken@lokigames.com>
parents:
78
diff
changeset
|
230 int enable_relative = 1; |
ffadd05de74d
Allow the user to override the relative mouse mode.
Sam Lantinga <slouken@lokigames.com>
parents:
78
diff
changeset
|
231 |
ffadd05de74d
Allow the user to override the relative mouse mode.
Sam Lantinga <slouken@lokigames.com>
parents:
78
diff
changeset
|
232 /* Allow the user to override the relative mouse mode. |
ffadd05de74d
Allow the user to override the relative mouse mode.
Sam Lantinga <slouken@lokigames.com>
parents:
78
diff
changeset
|
233 They almost never want to do this, as it seriously affects |
ffadd05de74d
Allow the user to override the relative mouse mode.
Sam Lantinga <slouken@lokigames.com>
parents:
78
diff
changeset
|
234 applications that rely on continuous relative mouse motion. |
ffadd05de74d
Allow the user to override the relative mouse mode.
Sam Lantinga <slouken@lokigames.com>
parents:
78
diff
changeset
|
235 */ |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
236 env_override = SDL_getenv("SDL_MOUSE_RELATIVE"); |
79
ffadd05de74d
Allow the user to override the relative mouse mode.
Sam Lantinga <slouken@lokigames.com>
parents:
78
diff
changeset
|
237 if ( env_override ) { |
ffadd05de74d
Allow the user to override the relative mouse mode.
Sam Lantinga <slouken@lokigames.com>
parents:
78
diff
changeset
|
238 enable_relative = atoi(env_override); |
ffadd05de74d
Allow the user to override the relative mouse mode.
Sam Lantinga <slouken@lokigames.com>
parents:
78
diff
changeset
|
239 } |
ffadd05de74d
Allow the user to override the relative mouse mode.
Sam Lantinga <slouken@lokigames.com>
parents:
78
diff
changeset
|
240 |
0 | 241 /* If the mouse is hidden and input is grabbed, we use relative mode */ |
79
ffadd05de74d
Allow the user to override the relative mouse mode.
Sam Lantinga <slouken@lokigames.com>
parents:
78
diff
changeset
|
242 if ( enable_relative && |
ffadd05de74d
Allow the user to override the relative mouse mode.
Sam Lantinga <slouken@lokigames.com>
parents:
78
diff
changeset
|
243 !(SDL_cursorstate & CURSOR_VISIBLE) && |
0 | 244 (this->input_grab != SDL_GRAB_OFF) && |
79
ffadd05de74d
Allow the user to override the relative mouse mode.
Sam Lantinga <slouken@lokigames.com>
parents:
78
diff
changeset
|
245 (SDL_GetAppState() & SDL_APPACTIVE) ) { |
0 | 246 if ( ! mouse_relative ) { |
247 X11_EnableDGAMouse(this); | |
248 if ( ! (using_dga & DGA_MOUSE) ) { | |
249 char *xmouse_accel; | |
250 | |
251 SDL_GetMouseState(&mouse_last.x, &mouse_last.y); | |
252 /* Use as raw mouse mickeys as possible */ | |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
888
diff
changeset
|
253 pXGetPointerControl(SDL_Display, |
0 | 254 &mouse_accel.numerator, |
255 &mouse_accel.denominator, | |
256 &mouse_accel.threshold); | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
257 xmouse_accel=SDL_getenv("SDL_VIDEO_X11_MOUSEACCEL"); |
0 | 258 if ( xmouse_accel ) { |
259 SetMouseAccel(this, xmouse_accel); | |
260 } | |
261 } | |
262 mouse_relative = 1; | |
263 } | |
264 } else { | |
265 if ( mouse_relative ) { | |
266 if ( using_dga & DGA_MOUSE ) { | |
267 X11_DisableDGAMouse(this); | |
268 } else { | |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
888
diff
changeset
|
269 pXChangePointerControl(SDL_Display, True, True, |
0 | 270 mouse_accel.numerator, |
271 mouse_accel.denominator, | |
272 mouse_accel.threshold); | |
273 } | |
274 mouse_relative = 0; | |
275 } | |
276 } | |
277 } | |
278 void X11_CheckMouseMode(_THIS) | |
279 { | |
280 SDL_Lock_EventThread(); | |
281 X11_CheckMouseModeNoLock(this); | |
282 SDL_Unlock_EventThread(); | |
283 } |