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