Mercurial > sdl-ios-xcode
annotate src/video/ggi/SDL_ggievents.c @ 563:04dcaf3da918
Massive Quartz input enhancements from Darrell Walisser. His email:
Enclosed is a patch that addresses the following:
--Various minor cleanups.
Removed dead/obsolete code, made some style cleanups
--Mouse Events
Now keep track of what button(s) were pressed so we know when to send
the mouse up event. This fixes the case where the mouse is dragged
outside of the game window and released (in which case we want to send
the mouse up event even though the mouse is outside the game window).
--Input Grabbing
Here is my take on the grabbing situation, which is the basis for the
new implementation.
There are 3 grab states, ungrabbed (UG), visible (VG), and invisible
(IG). Both VG and IG keep the mouse constrained to the window and
produce relative motion events. In VG the cursor is visible (duh), in
IG it is not. In VG, absolute motion events also work.
There are 6 actions that can affect grabbing:
1. Set Fullscreen/Window (F/W). In fullscreen, a visible grab should do
nothing. However, a fullscreen visible grab can be treated just like a
windowed visible grab, which is what I have done to help simplify
things.
2. Cursor hide/show (H/S). If the cursor is hidden when grabbing, the
grab is an invisible grab. If the cursor is visible, the grab should
just constrain the mouse to the window.
3. Input grab/ungrab(G/U). If grabbed, the cursor should be confined to
the window as should the keyboard input. On Mac OS X, the keyboard
input is implicitly grabbed by confining the cursor, except for
command-tab which can switch away from the application. Should the
window come to the foreground if the application is deactivated and
grab input is called? This isn't necessary in this implementation
because the grab state will be asserted upon activation.
Using my notation, these are all the cases that need to be handled
(state + action = new state).
UG+U = UG
UG+G = VG or IG, if cursor is visible or not
UG+H = UG
UG+S = UG
VG+U = UG
VG+G = VG
VG+H = IG
VG+S = VG
IG+U = UG
IG+G = IG
IG+H = IG
IG+S = VG
The cases that result in the same state can be ignored in the code,
which cuts it down to just 5 cases.
Another issue is what happens when the app loses/gains input focus from
deactivate/activate or iconify/deiconify. I think that if input focus
is ever lost (outside of SDL's control), the grab state should be
suspended and the cursor should become visible and active again. When
regained, the cursor should reappear in its original location and/or
grab state. This way, when reactivating the cursor is still in the same
position as before so apps shouldn't get confused when the next motion
event comes in. This is what I've done in this patch.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Fri, 27 Dec 2002 20:52:41 +0000 |
parents | f6ffac90895c |
children | b8d311d90021 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
297
f6ffac90895c
Updated copyright information for 2002
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 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 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 /* Handle the event stream, converting GGI events into SDL events */ | |
29 | |
30 #include <sys/types.h> | |
31 #include <sys/time.h> | |
32 #include <stdlib.h> | |
33 #include <stdio.h> | |
34 #include <unistd.h> | |
35 #include <fcntl.h> | |
36 #include <termios.h> | |
37 | |
38 #include <ggi/keyboard.h> | |
39 | |
40 #include "SDL_ggikeys.h" | |
41 | |
42 #include "SDL.h" | |
43 #include "SDL_sysevents.h" | |
44 #include "SDL_sysvideo.h" | |
45 #include "SDL_events_c.h" | |
46 #include "SDL_ggivideo.h" | |
47 #include "SDL_ggievents_c.h" | |
48 | |
49 /* The translation tables from a GGI keycode to a SDL keysym */ | |
50 static SDLKey keymap[128]; | |
51 static SDL_keysym *GGI_TranslateKey(ggi_event *ev, SDL_keysym *keysym); | |
52 | |
53 static int posted = 0; | |
54 | |
55 void GGI_PumpEvents(_THIS) | |
56 { | |
57 struct timeval *tvp, tv = { 0, 0 }; | |
58 ggi_event ev; | |
59 | |
60 tvp = &tv; | |
61 | |
62 /* ggiFlush(VIS); */ | |
63 | |
64 while (ggiEventPoll(VIS, emAll, tvp)) | |
65 /* while (ggiEventPoll(VIS, (emKeyboard | emPointer | emCommand), tvp)) */ | |
66 { | |
67 int queueevent_mouse = 0, queueevent_kbd = 0; | |
68 static int buttons = 0; | |
69 static int mouse_x = 0, mouse_y = 0, mouse_z = 0; | |
70 int x = 0, y = 0, z = 0, rx = 0, ry = 0, rz = 0; | |
71 uint32 sym; | |
72 int pressed_mouse, pressed_kbd; | |
73 SDL_keysym keysym; | |
74 | |
75 posted = 0; | |
76 | |
77 /* FIXME: We do not actually want all events, only | |
78 * mouse and keyboard events. Having to handle all | |
79 * events will slow things down. */ | |
80 | |
81 ggiEventRead(VIS, &ev, emAll); | |
82 /* ggiEventRead(VIS, &ev, (emKeyboard | emPointer | emCommand)); */ | |
83 | |
84 switch (ev.any.type) | |
85 { | |
86 case evPtrRelative: | |
87 x = ev.pmove.x; | |
88 y = ev.pmove.y; | |
89 z = ev.pmove.wheel; | |
90 posted += SDL_PrivateMouseMotion(0, 1, x, y); | |
91 break; | |
92 case evPtrAbsolute: | |
93 if (mouse_x != ev.pmove.x || mouse_y != ev.pmove.y || mouse_z != ev.pmove.wheel) | |
94 { | |
95 x = ev.pmove.x - mouse_x; | |
96 y = ev.pmove.y - mouse_y; | |
97 z = ev.pmove.wheel - mouse_z; | |
98 mouse_x = ev.pmove.x; | |
99 mouse_y = ev.pmove.y; | |
100 mouse_z = ev.pmove.wheel; | |
101 posted += SDL_PrivateMouseMotion(0, 1, x, y); | |
102 } | |
103 break; | |
104 case evPtrButtonPress: | |
105 posted += SDL_PrivateMouseButton(SDL_PRESSED, ev.pbutton.button, 0, 0); | |
106 break; | |
107 case evPtrButtonRelease: | |
108 posted += SDL_PrivateMouseButton(SDL_RELEASED, ev.pbutton.button, 0, 0); | |
109 break; | |
110 case evKeyPress: | |
111 case evKeyRepeat: | |
112 posted += SDL_PrivateKeyboard(SDL_PRESSED, GGI_TranslateKey(&ev, &keysym)); | |
113 break; | |
114 case evKeyRelease: | |
115 posted += SDL_PrivateKeyboard(SDL_RELEASED, GGI_TranslateKey(&ev, &keysym)); | |
116 break; | |
117 case evCommand: | |
118 fprintf(stderr, "Command event %x recieved\n", ev.cmd.code); | |
119 break; | |
120 default: | |
121 fprintf(stderr, "Unhandled event type %d\n", ev.any.type); | |
122 break; | |
123 } | |
124 } | |
125 | |
126 } | |
127 | |
128 void GGI_InitOSKeymap(_THIS) | |
129 { | |
130 int i; | |
131 | |
132 /* Initialize the GGI key translation table */ | |
133 for ( i=0; i<SDL_TABLESIZE(keymap); ++i ) | |
134 keymap[i] = SDLK_UNKNOWN; | |
135 | |
136 keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE; | |
137 keymap[SCANCODE_1] = SDLK_1; | |
138 keymap[SCANCODE_2] = SDLK_2; | |
139 keymap[SCANCODE_3] = SDLK_3; | |
140 keymap[SCANCODE_4] = SDLK_4; | |
141 keymap[SCANCODE_5] = SDLK_5; | |
142 keymap[SCANCODE_6] = SDLK_6; | |
143 keymap[SCANCODE_7] = SDLK_7; | |
144 keymap[SCANCODE_8] = SDLK_8; | |
145 keymap[SCANCODE_9] = SDLK_9; | |
146 keymap[SCANCODE_0] = SDLK_0; | |
147 keymap[SCANCODE_MINUS] = SDLK_MINUS; | |
148 keymap[SCANCODE_EQUAL] = SDLK_EQUALS; | |
149 keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE; | |
150 keymap[SCANCODE_TAB] = SDLK_TAB; | |
151 keymap[SCANCODE_Q] = SDLK_q; | |
152 keymap[SCANCODE_W] = SDLK_w; | |
153 keymap[SCANCODE_E] = SDLK_e; | |
154 keymap[SCANCODE_R] = SDLK_r; | |
155 keymap[SCANCODE_T] = SDLK_t; | |
156 keymap[SCANCODE_Y] = SDLK_y; | |
157 keymap[SCANCODE_U] = SDLK_u; | |
158 keymap[SCANCODE_I] = SDLK_i; | |
159 keymap[SCANCODE_O] = SDLK_o; | |
160 keymap[SCANCODE_P] = SDLK_p; | |
161 keymap[SCANCODE_BRACKET_LEFT] = SDLK_LEFTBRACKET; | |
162 keymap[SCANCODE_BRACKET_RIGHT] = SDLK_RIGHTBRACKET; | |
163 keymap[SCANCODE_ENTER] = SDLK_RETURN; | |
164 keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL; | |
165 keymap[SCANCODE_A] = SDLK_a; | |
166 keymap[SCANCODE_S] = SDLK_s; | |
167 keymap[SCANCODE_D] = SDLK_d; | |
168 keymap[SCANCODE_F] = SDLK_f; | |
169 keymap[SCANCODE_G] = SDLK_g; | |
170 keymap[SCANCODE_H] = SDLK_h; | |
171 keymap[SCANCODE_J] = SDLK_j; | |
172 keymap[SCANCODE_K] = SDLK_k; | |
173 keymap[SCANCODE_L] = SDLK_l; | |
174 keymap[SCANCODE_SEMICOLON] = SDLK_SEMICOLON; | |
175 keymap[SCANCODE_APOSTROPHE] = SDLK_QUOTE; | |
176 keymap[SCANCODE_GRAVE] = SDLK_BACKQUOTE; | |
177 keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT; | |
178 keymap[SCANCODE_BACKSLASH] = SDLK_BACKSLASH; | |
179 keymap[SCANCODE_Z] = SDLK_z; | |
180 keymap[SCANCODE_X] = SDLK_x; | |
181 keymap[SCANCODE_C] = SDLK_c; | |
182 keymap[SCANCODE_V] = SDLK_v; | |
183 keymap[SCANCODE_B] = SDLK_b; | |
184 keymap[SCANCODE_N] = SDLK_n; | |
185 keymap[SCANCODE_M] = SDLK_m; | |
186 keymap[SCANCODE_COMMA] = SDLK_COMMA; | |
187 keymap[SCANCODE_PERIOD] = SDLK_PERIOD; | |
188 keymap[SCANCODE_SLASH] = SDLK_SLASH; | |
189 keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT; | |
190 keymap[SCANCODE_KEYPADMULTIPLY] = SDLK_KP_MULTIPLY; | |
191 keymap[SCANCODE_LEFTALT] = SDLK_LALT; | |
192 keymap[SCANCODE_SPACE] = SDLK_SPACE; | |
193 keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK; | |
194 keymap[SCANCODE_F1] = SDLK_F1; | |
195 keymap[SCANCODE_F2] = SDLK_F2; | |
196 keymap[SCANCODE_F3] = SDLK_F3; | |
197 keymap[SCANCODE_F4] = SDLK_F4; | |
198 keymap[SCANCODE_F5] = SDLK_F5; | |
199 keymap[SCANCODE_F6] = SDLK_F6; | |
200 keymap[SCANCODE_F7] = SDLK_F7; | |
201 keymap[SCANCODE_F8] = SDLK_F8; | |
202 keymap[SCANCODE_F9] = SDLK_F9; | |
203 keymap[SCANCODE_F10] = SDLK_F10; | |
204 keymap[SCANCODE_NUMLOCK] = SDLK_NUMLOCK; | |
205 keymap[SCANCODE_SCROLLLOCK] = SDLK_SCROLLOCK; | |
206 keymap[SCANCODE_KEYPAD7] = SDLK_KP7; | |
207 keymap[SCANCODE_CURSORUPLEFT] = SDLK_KP7; | |
208 keymap[SCANCODE_KEYPAD8] = SDLK_KP8; | |
209 keymap[SCANCODE_CURSORUP] = SDLK_KP8; | |
210 keymap[SCANCODE_KEYPAD9] = SDLK_KP9; | |
211 keymap[SCANCODE_CURSORUPRIGHT] = SDLK_KP9; | |
212 keymap[SCANCODE_KEYPADMINUS] = SDLK_KP_MINUS; | |
213 keymap[SCANCODE_KEYPAD4] = SDLK_KP4; | |
214 keymap[SCANCODE_CURSORLEFT] = SDLK_KP4; | |
215 keymap[SCANCODE_KEYPAD5] = SDLK_KP5; | |
216 keymap[SCANCODE_KEYPAD6] = SDLK_KP6; | |
217 keymap[SCANCODE_CURSORRIGHT] = SDLK_KP6; | |
218 keymap[SCANCODE_KEYPADPLUS] = SDLK_KP_PLUS; | |
219 keymap[SCANCODE_KEYPAD1] = SDLK_KP1; | |
220 keymap[SCANCODE_CURSORDOWNLEFT] = SDLK_KP1; | |
221 keymap[SCANCODE_KEYPAD2] = SDLK_KP2; | |
222 keymap[SCANCODE_CURSORDOWN] = SDLK_KP2; | |
223 keymap[SCANCODE_KEYPAD3] = SDLK_KP3; | |
224 keymap[SCANCODE_CURSORDOWNRIGHT] = SDLK_KP3; | |
225 keymap[SCANCODE_KEYPAD0] = SDLK_KP0; | |
226 keymap[SCANCODE_KEYPADPERIOD] = SDLK_KP_PERIOD; | |
227 keymap[SCANCODE_LESS] = SDLK_LESS; | |
228 keymap[SCANCODE_F11] = SDLK_F11; | |
229 keymap[SCANCODE_F12] = SDLK_F12; | |
230 keymap[SCANCODE_KEYPADENTER] = SDLK_KP_ENTER; | |
231 keymap[SCANCODE_RIGHTCONTROL] = SDLK_RCTRL; | |
232 keymap[SCANCODE_CONTROL] = SDLK_RCTRL; | |
233 keymap[SCANCODE_KEYPADDIVIDE] = SDLK_KP_DIVIDE; | |
234 keymap[SCANCODE_PRINTSCREEN] = SDLK_PRINT; | |
235 keymap[SCANCODE_RIGHTALT] = SDLK_RALT; | |
236 keymap[SCANCODE_BREAK] = SDLK_BREAK; | |
237 keymap[SCANCODE_BREAK_ALTERNATIVE] = SDLK_UNKNOWN; | |
238 keymap[SCANCODE_HOME] = SDLK_HOME; | |
239 keymap[SCANCODE_CURSORBLOCKUP] = SDLK_UP; | |
240 keymap[SCANCODE_PAGEUP] = SDLK_PAGEUP; | |
241 keymap[SCANCODE_CURSORBLOCKLEFT] = SDLK_LEFT; | |
242 keymap[SCANCODE_CURSORBLOCKRIGHT] = SDLK_RIGHT; | |
243 keymap[SCANCODE_END] = SDLK_END; | |
244 keymap[SCANCODE_CURSORBLOCKDOWN] = SDLK_DOWN; | |
245 keymap[SCANCODE_PAGEDOWN] = SDLK_PAGEDOWN; | |
246 keymap[SCANCODE_INSERT] = SDLK_INSERT; | |
247 keymap[SCANCODE_REMOVE] = SDLK_DELETE; | |
248 keymap[119] = SDLK_PAUSE; | |
249 keymap[SCANCODE_RIGHTWIN] = SDLK_RSUPER; | |
250 keymap[SCANCODE_LEFTWIN] = SDLK_LSUPER; | |
251 keymap[127] = SDLK_MENU; | |
252 } | |
253 | |
254 | |
255 | |
256 static SDL_keysym *GGI_TranslateKey(gii_event *ev, SDL_keysym *keysym) | |
257 { | |
258 /* Set the keysym information */ | |
259 keysym->scancode = ev->key.button; | |
260 keysym->sym = keymap[ev->key.button]; | |
261 keysym->mod = KMOD_NONE; | |
262 | |
263 /* If UNICODE is on, get the UNICODE value for the key */ | |
264 keysym->unicode = 0; | |
265 if (SDL_TranslateUNICODE) | |
266 { | |
267 keysym->unicode = GII_UNICODE(ev->key.sym); | |
268 } | |
269 | |
270 return keysym; | |
271 } |