Mercurial > sdl-ios-xcode
annotate src/video/wscons/SDL_wsconsevents.c @ 1402:d910939febfa
Use consistent identifiers for the various platforms we support.
Make sure every source file includes SDL_config.h, so the proper system
headers are chosen.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 21 Feb 2006 08:46:50 +0000 |
parents | 1736c5e2173f |
children | 56f952883795 |
rev | line source |
---|---|
1187 | 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:
1187
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
1187 | 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:
1187
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
1187 | 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:
1187
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
1187 | 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:
1187
diff
changeset
|
13 Lesser General Public License for more details. |
1187 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1187
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:
1187
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:
1187
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
1187 | 18 |
19 Sam Lantinga | |
20 slouken@libsdl.org | |
21 */ | |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1383
diff
changeset
|
22 #include "SDL_config.h" |
1187 | 23 |
24 #include <sys/types.h> | |
25 #include <dev/wscons/wsdisplay_usl_io.h> | |
26 #include <sys/ioctl.h> | |
27 #include <fcntl.h> | |
28 #include <unistd.h> | |
29 #include <termios.h> | |
30 #include <errno.h> | |
31 #include <string.h> | |
32 | |
33 #include "SDL.h" | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
34 #include "../../events/SDL_sysevents.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
35 #include "../../events/SDL_events_c.h" |
1187 | 36 #include "SDL_wsconsvideo.h" |
37 #include "SDL_wsconsevents_c.h" | |
38 | |
39 static int posted = 0; | |
40 | |
41 int WSCONS_InitKeyboard(_THIS) | |
42 { | |
43 struct termios tty; | |
44 | |
45 if (ioctl(private->fd, WSKBDIO_GTYPE, &private->kbdType) == -1) { | |
46 WSCONS_ReportError("cannot get keyboard type: %s", strerror(errno)); | |
47 return -1; | |
48 } | |
49 | |
50 if (tcgetattr(private->fd, &private->saved_tty) == -1) { | |
51 WSCONS_ReportError("cannot get terminal attributes: %s", strerror(errno)); | |
52 return -1; | |
53 } | |
54 private->did_save_tty = 1; | |
55 tty = private->saved_tty; | |
56 tty.c_iflag = IGNPAR | IGNBRK; | |
57 tty.c_oflag = 0; | |
58 tty.c_cflag = CREAD | CS8; | |
59 tty.c_lflag = 0; | |
60 tty.c_cc[VTIME] = 0; | |
61 tty.c_cc[VMIN] = 1; | |
62 cfsetispeed(&tty, 9600); | |
63 cfsetospeed(&tty, 9600); | |
64 if (tcsetattr(private->fd, TCSANOW, &tty) < 0) { | |
65 WSCONS_ReportError("cannot set terminal attributes: %s", strerror(errno)); | |
66 return -1; | |
67 } | |
68 if (ioctl(private->fd, KDSKBMODE, K_RAW) == -1) { | |
69 WSCONS_ReportError("cannot set raw keyboard mode: %s", strerror(errno)); | |
70 return -1; | |
71 } | |
72 | |
73 return 0; | |
74 } | |
75 | |
76 void WSCONS_ReleaseKeyboard(_THIS) | |
77 { | |
78 if (private->fd != -1) { | |
79 if (ioctl(private->fd, KDSKBMODE, K_XLATE) == -1) { | |
80 WSCONS_ReportError("cannot restore keyboard to translated mode: %s", | |
81 strerror(errno)); | |
82 } | |
83 if (private->did_save_tty) { | |
84 if (tcsetattr(private->fd, TCSANOW, &private->saved_tty) < 0) { | |
85 WSCONS_ReportError("cannot restore keynoard attributes: %s", | |
86 strerror(errno)); | |
87 } | |
88 } | |
89 } | |
90 } | |
91 | |
92 static void updateMouse() | |
93 { | |
94 } | |
95 | |
96 static SDLKey keymap[128]; | |
97 | |
98 static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym) | |
99 { | |
100 keysym->scancode = scancode; | |
101 keysym->sym = SDLK_UNKNOWN; | |
102 keysym->mod = KMOD_NONE; | |
103 | |
1379
c0a74f199ecf
Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents:
1378
diff
changeset
|
104 if (scancode < SDL_arraysize(keymap)) |
1187 | 105 keysym->sym = keymap[scancode]; |
106 | |
107 if (keysym->sym == SDLK_UNKNOWN) | |
108 printf("Unknown mapping for scancode %d\n", scancode); | |
109 | |
110 return keysym; | |
111 } | |
112 | |
113 static void updateKeyboard(_THIS) | |
114 { | |
115 unsigned char buf[100]; | |
116 SDL_keysym keysym; | |
117 int n, i; | |
118 | |
119 if ((n = read(private->fd, buf, sizeof(buf))) > 0) { | |
120 for (i = 0; i < n; i++) { | |
1378
dc0e13e7e1ae
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
121 unsigned char c = buf[i] & 0x7f; |
1187 | 122 if (c == 224) // special key prefix -- what should we do with it? |
123 continue; | |
124 int release = (buf[i] & 0x80) != 0; | |
125 posted += SDL_PrivateKeyboard(release ? SDL_RELEASED : SDL_PRESSED, | |
126 TranslateKey(c, &keysym)); | |
127 } | |
128 } | |
129 } | |
130 | |
131 void WSCONS_PumpEvents(_THIS) | |
132 { | |
133 do { | |
134 posted = 0; | |
135 updateMouse(); | |
136 updateKeyboard(this); | |
137 } while (posted); | |
138 } | |
139 | |
140 void WSCONS_InitOSKeymap(_THIS) | |
141 { | |
142 int i; | |
143 | |
144 /* Make sure unknown keys are mapped correctly */ | |
1379
c0a74f199ecf
Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents:
1378
diff
changeset
|
145 for (i=0; i < SDL_arraysize(keymap); i++) { |
1187 | 146 keymap[i] = SDLK_UNKNOWN; |
147 } | |
148 | |
149 switch (private->kbdType) { | |
1383 | 150 #ifdef WSKBD_TYPE_ZAURUS |
1187 | 151 case WSKBD_TYPE_ZAURUS: |
152 /* top row */ | |
153 keymap[2] = SDLK_1; | |
154 keymap[3] = SDLK_2; | |
155 keymap[4] = SDLK_3; | |
156 keymap[5] = SDLK_4; | |
157 keymap[6] = SDLK_5; | |
158 keymap[7] = SDLK_6; | |
159 keymap[8] = SDLK_7; | |
160 keymap[9] = SDLK_8; | |
161 keymap[10] = SDLK_9; | |
162 keymap[11] = SDLK_0; | |
163 keymap[14] = SDLK_BACKSPACE; | |
164 | |
165 /* second row */ | |
166 keymap[16] = SDLK_q; | |
167 keymap[17] = SDLK_w; | |
168 keymap[18] = SDLK_e; | |
169 keymap[19] = SDLK_r; | |
170 keymap[20] = SDLK_t; | |
171 keymap[21] = SDLK_y; | |
172 keymap[22] = SDLK_u; | |
173 keymap[23] = SDLK_i; | |
174 keymap[24] = SDLK_o; | |
175 keymap[25] = SDLK_p; | |
176 | |
177 /* third row */ | |
178 keymap[15] = SDLK_TAB; | |
179 keymap[30] = SDLK_a; | |
180 keymap[31] = SDLK_s; | |
181 keymap[32] = SDLK_d; | |
182 keymap[33] = SDLK_f; | |
183 keymap[34] = SDLK_g; | |
184 keymap[35] = SDLK_h; | |
185 keymap[36] = SDLK_j; | |
186 keymap[37] = SDLK_k; | |
187 keymap[38] = SDLK_l; | |
188 | |
189 /* fourth row */ | |
190 keymap[42] = SDLK_LSHIFT; | |
191 keymap[44] = SDLK_z; | |
192 keymap[45] = SDLK_x; | |
193 keymap[46] = SDLK_c; | |
194 keymap[47] = SDLK_v; | |
195 keymap[48] = SDLK_b; | |
196 keymap[49] = SDLK_n; | |
197 keymap[50] = SDLK_m; | |
198 keymap[54] = SDLK_RSHIFT; | |
199 keymap[28] = SDLK_RETURN; | |
200 | |
201 /* fifth row */ | |
202 keymap[56] = SDLK_LALT; | |
203 keymap[29] = SDLK_LCTRL; | |
204 /* keymap[56] = ; */ | |
205 keymap[0] = SDLK_LSUPER; | |
206 keymap[12] = SDLK_MINUS; | |
207 keymap[57] = SDLK_SPACE; | |
208 keymap[51] = SDLK_COMMA; | |
209 keymap[52] = SDLK_PERIOD; | |
210 | |
211 /* misc */ | |
212 keymap[59] = SDLK_F1; | |
213 keymap[60] = SDLK_F2; | |
214 keymap[61] = SDLK_F3; | |
215 keymap[62] = SDLK_F4; | |
216 keymap[63] = SDLK_F5; | |
217 keymap[1] = SDLK_ESCAPE; | |
218 /* keymap[28] = SDLK_KP_ENTER; */ | |
219 keymap[72] = SDLK_UP; | |
220 keymap[75] = SDLK_LEFT; | |
221 keymap[77] = SDLK_RIGHT; | |
222 keymap[80] = SDLK_DOWN; | |
223 break; | |
1383 | 224 #endif /* WSKBD_TYPE_ZAURUS */ |
1187 | 225 |
226 default: | |
227 WSCONS_ReportError("Unable to map keys for keyboard type %u", | |
228 private->kbdType); | |
229 break; | |
230 } | |
231 } | |
232 | |
233 /* end of SDL_wsconsevents.c ... */ | |
234 |