Mercurial > sdl-ios-xcode
annotate src/video/ggi/SDL_ggievents.c @ 1312:c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
I batch edited these files, so please let me know if I've accidentally removed anybody's
credit here.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 01 Feb 2006 06:32:25 +0000 |
parents | b8d311d90021 |
children | 604d73db6802 |
rev | line source |
---|---|
0 | 1 /* |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
6 modify it under the terms 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:
769
diff
changeset
|
7 License as published by the Free Software Foundation; either |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
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:
769
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:
769
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:
769
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
19 Sam Lantinga |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
20 slouken@libsdl.org |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
21 */ |
0 | 22 |
23 /* Handle the event stream, converting GGI events into SDL events */ | |
24 | |
25 #include <sys/types.h> | |
26 #include <sys/time.h> | |
27 #include <stdlib.h> | |
28 #include <stdio.h> | |
29 #include <unistd.h> | |
30 #include <fcntl.h> | |
31 #include <termios.h> | |
32 | |
33 #include <ggi/keyboard.h> | |
34 | |
35 #include "SDL_ggikeys.h" | |
36 | |
37 #include "SDL.h" | |
38 #include "SDL_sysevents.h" | |
39 #include "SDL_sysvideo.h" | |
40 #include "SDL_events_c.h" | |
41 #include "SDL_ggivideo.h" | |
42 #include "SDL_ggievents_c.h" | |
43 | |
44 /* The translation tables from a GGI keycode to a SDL keysym */ | |
45 static SDLKey keymap[128]; | |
46 static SDL_keysym *GGI_TranslateKey(ggi_event *ev, SDL_keysym *keysym); | |
47 | |
48 static int posted = 0; | |
49 | |
50 void GGI_PumpEvents(_THIS) | |
51 { | |
52 struct timeval *tvp, tv = { 0, 0 }; | |
53 ggi_event ev; | |
54 | |
55 tvp = &tv; | |
56 | |
57 /* ggiFlush(VIS); */ | |
58 | |
59 while (ggiEventPoll(VIS, emAll, tvp)) | |
60 /* while (ggiEventPoll(VIS, (emKeyboard | emPointer | emCommand), tvp)) */ | |
61 { | |
62 int queueevent_mouse = 0, queueevent_kbd = 0; | |
63 static int buttons = 0; | |
64 static int mouse_x = 0, mouse_y = 0, mouse_z = 0; | |
65 int x = 0, y = 0, z = 0, rx = 0, ry = 0, rz = 0; | |
66 uint32 sym; | |
67 int pressed_mouse, pressed_kbd; | |
68 SDL_keysym keysym; | |
69 | |
70 posted = 0; | |
71 | |
72 /* FIXME: We do not actually want all events, only | |
73 * mouse and keyboard events. Having to handle all | |
74 * events will slow things down. */ | |
75 | |
76 ggiEventRead(VIS, &ev, emAll); | |
77 /* ggiEventRead(VIS, &ev, (emKeyboard | emPointer | emCommand)); */ | |
78 | |
79 switch (ev.any.type) | |
80 { | |
81 case evPtrRelative: | |
82 x = ev.pmove.x; | |
83 y = ev.pmove.y; | |
84 z = ev.pmove.wheel; | |
85 posted += SDL_PrivateMouseMotion(0, 1, x, y); | |
86 break; | |
87 case evPtrAbsolute: | |
88 if (mouse_x != ev.pmove.x || mouse_y != ev.pmove.y || mouse_z != ev.pmove.wheel) | |
89 { | |
90 x = ev.pmove.x - mouse_x; | |
91 y = ev.pmove.y - mouse_y; | |
92 z = ev.pmove.wheel - mouse_z; | |
93 mouse_x = ev.pmove.x; | |
94 mouse_y = ev.pmove.y; | |
95 mouse_z = ev.pmove.wheel; | |
96 posted += SDL_PrivateMouseMotion(0, 1, x, y); | |
97 } | |
98 break; | |
99 case evPtrButtonPress: | |
100 posted += SDL_PrivateMouseButton(SDL_PRESSED, ev.pbutton.button, 0, 0); | |
101 break; | |
102 case evPtrButtonRelease: | |
103 posted += SDL_PrivateMouseButton(SDL_RELEASED, ev.pbutton.button, 0, 0); | |
104 break; | |
105 case evKeyPress: | |
106 case evKeyRepeat: | |
107 posted += SDL_PrivateKeyboard(SDL_PRESSED, GGI_TranslateKey(&ev, &keysym)); | |
108 break; | |
109 case evKeyRelease: | |
110 posted += SDL_PrivateKeyboard(SDL_RELEASED, GGI_TranslateKey(&ev, &keysym)); | |
111 break; | |
112 case evCommand: | |
113 fprintf(stderr, "Command event %x recieved\n", ev.cmd.code); | |
114 break; | |
115 default: | |
116 fprintf(stderr, "Unhandled event type %d\n", ev.any.type); | |
117 break; | |
118 } | |
119 } | |
120 | |
121 } | |
122 | |
123 void GGI_InitOSKeymap(_THIS) | |
124 { | |
125 int i; | |
126 | |
127 /* Initialize the GGI key translation table */ | |
128 for ( i=0; i<SDL_TABLESIZE(keymap); ++i ) | |
129 keymap[i] = SDLK_UNKNOWN; | |
130 | |
131 keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE; | |
132 keymap[SCANCODE_1] = SDLK_1; | |
133 keymap[SCANCODE_2] = SDLK_2; | |
134 keymap[SCANCODE_3] = SDLK_3; | |
135 keymap[SCANCODE_4] = SDLK_4; | |
136 keymap[SCANCODE_5] = SDLK_5; | |
137 keymap[SCANCODE_6] = SDLK_6; | |
138 keymap[SCANCODE_7] = SDLK_7; | |
139 keymap[SCANCODE_8] = SDLK_8; | |
140 keymap[SCANCODE_9] = SDLK_9; | |
141 keymap[SCANCODE_0] = SDLK_0; | |
142 keymap[SCANCODE_MINUS] = SDLK_MINUS; | |
143 keymap[SCANCODE_EQUAL] = SDLK_EQUALS; | |
144 keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE; | |
145 keymap[SCANCODE_TAB] = SDLK_TAB; | |
146 keymap[SCANCODE_Q] = SDLK_q; | |
147 keymap[SCANCODE_W] = SDLK_w; | |
148 keymap[SCANCODE_E] = SDLK_e; | |
149 keymap[SCANCODE_R] = SDLK_r; | |
150 keymap[SCANCODE_T] = SDLK_t; | |
151 keymap[SCANCODE_Y] = SDLK_y; | |
152 keymap[SCANCODE_U] = SDLK_u; | |
153 keymap[SCANCODE_I] = SDLK_i; | |
154 keymap[SCANCODE_O] = SDLK_o; | |
155 keymap[SCANCODE_P] = SDLK_p; | |
156 keymap[SCANCODE_BRACKET_LEFT] = SDLK_LEFTBRACKET; | |
157 keymap[SCANCODE_BRACKET_RIGHT] = SDLK_RIGHTBRACKET; | |
158 keymap[SCANCODE_ENTER] = SDLK_RETURN; | |
159 keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL; | |
160 keymap[SCANCODE_A] = SDLK_a; | |
161 keymap[SCANCODE_S] = SDLK_s; | |
162 keymap[SCANCODE_D] = SDLK_d; | |
163 keymap[SCANCODE_F] = SDLK_f; | |
164 keymap[SCANCODE_G] = SDLK_g; | |
165 keymap[SCANCODE_H] = SDLK_h; | |
166 keymap[SCANCODE_J] = SDLK_j; | |
167 keymap[SCANCODE_K] = SDLK_k; | |
168 keymap[SCANCODE_L] = SDLK_l; | |
169 keymap[SCANCODE_SEMICOLON] = SDLK_SEMICOLON; | |
170 keymap[SCANCODE_APOSTROPHE] = SDLK_QUOTE; | |
171 keymap[SCANCODE_GRAVE] = SDLK_BACKQUOTE; | |
172 keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT; | |
173 keymap[SCANCODE_BACKSLASH] = SDLK_BACKSLASH; | |
174 keymap[SCANCODE_Z] = SDLK_z; | |
175 keymap[SCANCODE_X] = SDLK_x; | |
176 keymap[SCANCODE_C] = SDLK_c; | |
177 keymap[SCANCODE_V] = SDLK_v; | |
178 keymap[SCANCODE_B] = SDLK_b; | |
179 keymap[SCANCODE_N] = SDLK_n; | |
180 keymap[SCANCODE_M] = SDLK_m; | |
181 keymap[SCANCODE_COMMA] = SDLK_COMMA; | |
182 keymap[SCANCODE_PERIOD] = SDLK_PERIOD; | |
183 keymap[SCANCODE_SLASH] = SDLK_SLASH; | |
184 keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT; | |
185 keymap[SCANCODE_KEYPADMULTIPLY] = SDLK_KP_MULTIPLY; | |
186 keymap[SCANCODE_LEFTALT] = SDLK_LALT; | |
187 keymap[SCANCODE_SPACE] = SDLK_SPACE; | |
188 keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK; | |
189 keymap[SCANCODE_F1] = SDLK_F1; | |
190 keymap[SCANCODE_F2] = SDLK_F2; | |
191 keymap[SCANCODE_F3] = SDLK_F3; | |
192 keymap[SCANCODE_F4] = SDLK_F4; | |
193 keymap[SCANCODE_F5] = SDLK_F5; | |
194 keymap[SCANCODE_F6] = SDLK_F6; | |
195 keymap[SCANCODE_F7] = SDLK_F7; | |
196 keymap[SCANCODE_F8] = SDLK_F8; | |
197 keymap[SCANCODE_F9] = SDLK_F9; | |
198 keymap[SCANCODE_F10] = SDLK_F10; | |
199 keymap[SCANCODE_NUMLOCK] = SDLK_NUMLOCK; | |
200 keymap[SCANCODE_SCROLLLOCK] = SDLK_SCROLLOCK; | |
201 keymap[SCANCODE_KEYPAD7] = SDLK_KP7; | |
202 keymap[SCANCODE_CURSORUPLEFT] = SDLK_KP7; | |
203 keymap[SCANCODE_KEYPAD8] = SDLK_KP8; | |
204 keymap[SCANCODE_CURSORUP] = SDLK_KP8; | |
205 keymap[SCANCODE_KEYPAD9] = SDLK_KP9; | |
206 keymap[SCANCODE_CURSORUPRIGHT] = SDLK_KP9; | |
207 keymap[SCANCODE_KEYPADMINUS] = SDLK_KP_MINUS; | |
208 keymap[SCANCODE_KEYPAD4] = SDLK_KP4; | |
209 keymap[SCANCODE_CURSORLEFT] = SDLK_KP4; | |
210 keymap[SCANCODE_KEYPAD5] = SDLK_KP5; | |
211 keymap[SCANCODE_KEYPAD6] = SDLK_KP6; | |
212 keymap[SCANCODE_CURSORRIGHT] = SDLK_KP6; | |
213 keymap[SCANCODE_KEYPADPLUS] = SDLK_KP_PLUS; | |
214 keymap[SCANCODE_KEYPAD1] = SDLK_KP1; | |
215 keymap[SCANCODE_CURSORDOWNLEFT] = SDLK_KP1; | |
216 keymap[SCANCODE_KEYPAD2] = SDLK_KP2; | |
217 keymap[SCANCODE_CURSORDOWN] = SDLK_KP2; | |
218 keymap[SCANCODE_KEYPAD3] = SDLK_KP3; | |
219 keymap[SCANCODE_CURSORDOWNRIGHT] = SDLK_KP3; | |
220 keymap[SCANCODE_KEYPAD0] = SDLK_KP0; | |
221 keymap[SCANCODE_KEYPADPERIOD] = SDLK_KP_PERIOD; | |
222 keymap[SCANCODE_LESS] = SDLK_LESS; | |
223 keymap[SCANCODE_F11] = SDLK_F11; | |
224 keymap[SCANCODE_F12] = SDLK_F12; | |
225 keymap[SCANCODE_KEYPADENTER] = SDLK_KP_ENTER; | |
226 keymap[SCANCODE_RIGHTCONTROL] = SDLK_RCTRL; | |
227 keymap[SCANCODE_CONTROL] = SDLK_RCTRL; | |
228 keymap[SCANCODE_KEYPADDIVIDE] = SDLK_KP_DIVIDE; | |
229 keymap[SCANCODE_PRINTSCREEN] = SDLK_PRINT; | |
230 keymap[SCANCODE_RIGHTALT] = SDLK_RALT; | |
231 keymap[SCANCODE_BREAK] = SDLK_BREAK; | |
232 keymap[SCANCODE_BREAK_ALTERNATIVE] = SDLK_UNKNOWN; | |
233 keymap[SCANCODE_HOME] = SDLK_HOME; | |
234 keymap[SCANCODE_CURSORBLOCKUP] = SDLK_UP; | |
235 keymap[SCANCODE_PAGEUP] = SDLK_PAGEUP; | |
236 keymap[SCANCODE_CURSORBLOCKLEFT] = SDLK_LEFT; | |
237 keymap[SCANCODE_CURSORBLOCKRIGHT] = SDLK_RIGHT; | |
238 keymap[SCANCODE_END] = SDLK_END; | |
239 keymap[SCANCODE_CURSORBLOCKDOWN] = SDLK_DOWN; | |
240 keymap[SCANCODE_PAGEDOWN] = SDLK_PAGEDOWN; | |
241 keymap[SCANCODE_INSERT] = SDLK_INSERT; | |
242 keymap[SCANCODE_REMOVE] = SDLK_DELETE; | |
243 keymap[119] = SDLK_PAUSE; | |
244 keymap[SCANCODE_RIGHTWIN] = SDLK_RSUPER; | |
245 keymap[SCANCODE_LEFTWIN] = SDLK_LSUPER; | |
246 keymap[127] = SDLK_MENU; | |
247 } | |
248 | |
249 | |
250 | |
251 static SDL_keysym *GGI_TranslateKey(gii_event *ev, SDL_keysym *keysym) | |
252 { | |
253 /* Set the keysym information */ | |
254 keysym->scancode = ev->key.button; | |
255 keysym->sym = keymap[ev->key.button]; | |
256 keysym->mod = KMOD_NONE; | |
257 | |
258 /* If UNICODE is on, get the UNICODE value for the key */ | |
259 keysym->unicode = 0; | |
260 if (SDL_TranslateUNICODE) | |
261 { | |
262 keysym->unicode = GII_UNICODE(ev->key.sym); | |
263 } | |
264 | |
265 return keysym; | |
266 } |