Mercurial > sdl-ios-xcode
comparison src/video/wscons/SDL_wsconsevents.c @ 1662:782fd950bd46 SDL-1.3
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.
The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce
The headers are being converted to automatically generate doxygen documentation.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 28 May 2006 13:04:16 +0000 |
parents | 56f952883795 |
children | 4da1ee79c9af |
comparison
equal
deleted
inserted
replaced
1661:281d3f4870e5 | 1662:782fd950bd46 |
---|---|
22 #include "SDL_config.h" | 22 #include "SDL_config.h" |
23 | 23 |
24 #include <sys/types.h> | 24 #include <sys/types.h> |
25 #include <dev/wscons/wsdisplay_usl_io.h> | 25 #include <dev/wscons/wsdisplay_usl_io.h> |
26 #include <sys/ioctl.h> | 26 #include <sys/ioctl.h> |
27 #include <fcntl.h> | 27 #include <fcntl.h> |
28 #include <unistd.h> | 28 #include <unistd.h> |
29 #include <termios.h> | 29 #include <termios.h> |
30 #include <errno.h> | 30 #include <errno.h> |
31 #include <string.h> | 31 #include <string.h> |
32 | 32 |
33 #include "SDL.h" | 33 #include "SDL.h" |
34 #include "../../events/SDL_sysevents.h" | 34 #include "../../events/SDL_sysevents.h" |
35 #include "../../events/SDL_events_c.h" | 35 #include "../../events/SDL_events_c.h" |
36 #include "SDL_wsconsvideo.h" | 36 #include "SDL_wsconsvideo.h" |
37 #include "SDL_wsconsevents_c.h" | 37 #include "SDL_wsconsevents_c.h" |
38 | 38 |
39 static int posted = 0; | 39 static int posted = 0; |
40 | 40 |
41 int WSCONS_InitKeyboard(_THIS) | 41 int |
42 { | 42 WSCONS_InitKeyboard (_THIS) |
43 struct termios tty; | 43 { |
44 | 44 struct termios tty; |
45 if (ioctl(private->fd, WSKBDIO_GTYPE, &private->kbdType) == -1) { | 45 |
46 WSCONS_ReportError("cannot get keyboard type: %s", strerror(errno)); | 46 if (ioctl (private->fd, WSKBDIO_GTYPE, &private->kbdType) == -1) { |
47 return -1; | 47 WSCONS_ReportError ("cannot get keyboard type: %s", strerror (errno)); |
48 } | 48 return -1; |
49 | 49 } |
50 if (tcgetattr(private->fd, &private->saved_tty) == -1) { | 50 |
51 WSCONS_ReportError("cannot get terminal attributes: %s", strerror(errno)); | 51 if (tcgetattr (private->fd, &private->saved_tty) == -1) { |
52 return -1; | 52 WSCONS_ReportError ("cannot get terminal attributes: %s", |
53 } | 53 strerror (errno)); |
54 private->did_save_tty = 1; | 54 return -1; |
55 tty = private->saved_tty; | 55 } |
56 tty.c_iflag = IGNPAR | IGNBRK; | 56 private->did_save_tty = 1; |
57 tty.c_oflag = 0; | 57 tty = private->saved_tty; |
58 tty.c_cflag = CREAD | CS8; | 58 tty.c_iflag = IGNPAR | IGNBRK; |
59 tty.c_lflag = 0; | 59 tty.c_oflag = 0; |
60 tty.c_cc[VTIME] = 0; | 60 tty.c_cflag = CREAD | CS8; |
61 tty.c_cc[VMIN] = 1; | 61 tty.c_lflag = 0; |
62 cfsetispeed(&tty, 9600); | 62 tty.c_cc[VTIME] = 0; |
63 cfsetospeed(&tty, 9600); | 63 tty.c_cc[VMIN] = 1; |
64 if (tcsetattr(private->fd, TCSANOW, &tty) < 0) { | 64 cfsetispeed (&tty, 9600); |
65 WSCONS_ReportError("cannot set terminal attributes: %s", strerror(errno)); | 65 cfsetospeed (&tty, 9600); |
66 return -1; | 66 if (tcsetattr (private->fd, TCSANOW, &tty) < 0) { |
67 } | 67 WSCONS_ReportError ("cannot set terminal attributes: %s", |
68 if (ioctl(private->fd, KDSKBMODE, K_RAW) == -1) { | 68 strerror (errno)); |
69 WSCONS_ReportError("cannot set raw keyboard mode: %s", strerror(errno)); | 69 return -1; |
70 return -1; | 70 } |
71 } | 71 if (ioctl (private->fd, KDSKBMODE, K_RAW) == -1) { |
72 | 72 WSCONS_ReportError ("cannot set raw keyboard mode: %s", |
73 return 0; | 73 strerror (errno)); |
74 } | 74 return -1; |
75 | 75 } |
76 void WSCONS_ReleaseKeyboard(_THIS) | 76 |
77 { | 77 return 0; |
78 if (private->fd != -1) { | 78 } |
79 if (ioctl(private->fd, KDSKBMODE, K_XLATE) == -1) { | 79 |
80 WSCONS_ReportError("cannot restore keyboard to translated mode: %s", | 80 void |
81 strerror(errno)); | 81 WSCONS_ReleaseKeyboard (_THIS) |
82 } | 82 { |
83 if (private->did_save_tty) { | 83 if (private->fd != -1) { |
84 if (tcsetattr(private->fd, TCSANOW, &private->saved_tty) < 0) { | 84 if (ioctl (private->fd, KDSKBMODE, K_XLATE) == -1) { |
85 WSCONS_ReportError("cannot restore keynoard attributes: %s", | 85 WSCONS_ReportError |
86 strerror(errno)); | 86 ("cannot restore keyboard to translated mode: %s", |
87 } | 87 strerror (errno)); |
88 } | 88 } |
89 } | 89 if (private->did_save_tty) { |
90 } | 90 if (tcsetattr (private->fd, TCSANOW, &private->saved_tty) < 0) { |
91 | 91 WSCONS_ReportError |
92 static void updateMouse() | 92 ("cannot restore keynoard attributes: %s", |
93 strerror (errno)); | |
94 } | |
95 } | |
96 } | |
97 } | |
98 | |
99 static void | |
100 updateMouse () | |
93 { | 101 { |
94 } | 102 } |
95 | 103 |
96 static SDLKey keymap[128]; | 104 static SDLKey keymap[128]; |
97 | 105 |
98 static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym) | 106 static SDL_keysym * |
99 { | 107 TranslateKey (int scancode, SDL_keysym * keysym) |
100 keysym->scancode = scancode; | 108 { |
101 keysym->sym = SDLK_UNKNOWN; | 109 keysym->scancode = scancode; |
102 keysym->mod = KMOD_NONE; | 110 keysym->sym = SDLK_UNKNOWN; |
103 | 111 keysym->mod = KMOD_NONE; |
104 if (scancode < SDL_arraysize(keymap)) | 112 |
105 keysym->sym = keymap[scancode]; | 113 if (scancode < SDL_arraysize (keymap)) |
106 | 114 keysym->sym = keymap[scancode]; |
107 if (keysym->sym == SDLK_UNKNOWN) | 115 |
108 printf("Unknown mapping for scancode %d\n", scancode); | 116 if (keysym->sym == SDLK_UNKNOWN) |
109 | 117 printf ("Unknown mapping for scancode %d\n", scancode); |
110 return keysym; | 118 |
111 } | 119 return keysym; |
112 | 120 } |
113 static void updateKeyboard(_THIS) | 121 |
114 { | 122 static void |
115 unsigned char buf[100]; | 123 updateKeyboard (_THIS) |
116 SDL_keysym keysym; | 124 { |
117 int n, i; | 125 unsigned char buf[100]; |
118 | 126 SDL_keysym keysym; |
119 if ((n = read(private->fd, buf, sizeof(buf))) > 0) { | 127 int n, i; |
120 for (i = 0; i < n; i++) { | 128 |
121 unsigned char c = buf[i] & 0x7f; | 129 if ((n = read (private->fd, buf, sizeof (buf))) > 0) { |
122 if (c == 224) // special key prefix -- what should we do with it? | 130 for (i = 0; i < n; i++) { |
123 continue; | 131 unsigned char c = buf[i] & 0x7f; |
124 posted += SDL_PrivateKeyboard((buf[i] & 0x80) ? SDL_RELEASED : SDL_PRESSED, | 132 if (c == 224) // special key prefix -- what should we do with it? |
125 TranslateKey(c, &keysym)); | 133 continue; |
126 } | 134 posted += |
127 } | 135 SDL_PrivateKeyboard ((buf[i] & 0x80) ? SDL_RELEASED : |
128 } | 136 SDL_PRESSED, TranslateKey (c, &keysym)); |
129 | 137 } |
130 void WSCONS_PumpEvents(_THIS) | 138 } |
131 { | 139 } |
132 do { | 140 |
133 posted = 0; | 141 void |
134 updateMouse(); | 142 WSCONS_PumpEvents (_THIS) |
135 updateKeyboard(this); | 143 { |
136 } while (posted); | 144 do { |
137 } | 145 posted = 0; |
138 | 146 updateMouse (); |
139 void WSCONS_InitOSKeymap(_THIS) | 147 updateKeyboard (this); |
140 { | 148 } |
141 int i; | 149 while (posted); |
142 | 150 } |
143 /* Make sure unknown keys are mapped correctly */ | 151 |
144 for (i=0; i < SDL_arraysize(keymap); i++) { | 152 void |
145 keymap[i] = SDLK_UNKNOWN; | 153 WSCONS_InitOSKeymap (_THIS) |
146 } | 154 { |
147 | 155 int i; |
148 switch (private->kbdType) { | 156 |
157 /* Make sure unknown keys are mapped correctly */ | |
158 for (i = 0; i < SDL_arraysize (keymap); i++) { | |
159 keymap[i] = SDLK_UNKNOWN; | |
160 } | |
161 | |
162 switch (private->kbdType) { | |
149 #ifdef WSKBD_TYPE_ZAURUS | 163 #ifdef WSKBD_TYPE_ZAURUS |
150 case WSKBD_TYPE_ZAURUS: | 164 case WSKBD_TYPE_ZAURUS: |
151 /* top row */ | 165 /* top row */ |
152 keymap[2] = SDLK_1; | 166 keymap[2] = SDLK_1; |
153 keymap[3] = SDLK_2; | 167 keymap[3] = SDLK_2; |
154 keymap[4] = SDLK_3; | 168 keymap[4] = SDLK_3; |
155 keymap[5] = SDLK_4; | 169 keymap[5] = SDLK_4; |
156 keymap[6] = SDLK_5; | 170 keymap[6] = SDLK_5; |
157 keymap[7] = SDLK_6; | 171 keymap[7] = SDLK_6; |
158 keymap[8] = SDLK_7; | 172 keymap[8] = SDLK_7; |
159 keymap[9] = SDLK_8; | 173 keymap[9] = SDLK_8; |
160 keymap[10] = SDLK_9; | 174 keymap[10] = SDLK_9; |
161 keymap[11] = SDLK_0; | 175 keymap[11] = SDLK_0; |
162 keymap[14] = SDLK_BACKSPACE; | 176 keymap[14] = SDLK_BACKSPACE; |
163 | 177 |
164 /* second row */ | 178 /* second row */ |
165 keymap[16] = SDLK_q; | 179 keymap[16] = SDLK_q; |
166 keymap[17] = SDLK_w; | 180 keymap[17] = SDLK_w; |
167 keymap[18] = SDLK_e; | 181 keymap[18] = SDLK_e; |
168 keymap[19] = SDLK_r; | 182 keymap[19] = SDLK_r; |
169 keymap[20] = SDLK_t; | 183 keymap[20] = SDLK_t; |
170 keymap[21] = SDLK_y; | 184 keymap[21] = SDLK_y; |
171 keymap[22] = SDLK_u; | 185 keymap[22] = SDLK_u; |
172 keymap[23] = SDLK_i; | 186 keymap[23] = SDLK_i; |
173 keymap[24] = SDLK_o; | 187 keymap[24] = SDLK_o; |
174 keymap[25] = SDLK_p; | 188 keymap[25] = SDLK_p; |
175 | 189 |
176 /* third row */ | 190 /* third row */ |
177 keymap[15] = SDLK_TAB; | 191 keymap[15] = SDLK_TAB; |
178 keymap[30] = SDLK_a; | 192 keymap[30] = SDLK_a; |
179 keymap[31] = SDLK_s; | 193 keymap[31] = SDLK_s; |
180 keymap[32] = SDLK_d; | 194 keymap[32] = SDLK_d; |
181 keymap[33] = SDLK_f; | 195 keymap[33] = SDLK_f; |
182 keymap[34] = SDLK_g; | 196 keymap[34] = SDLK_g; |
183 keymap[35] = SDLK_h; | 197 keymap[35] = SDLK_h; |
184 keymap[36] = SDLK_j; | 198 keymap[36] = SDLK_j; |
185 keymap[37] = SDLK_k; | 199 keymap[37] = SDLK_k; |
186 keymap[38] = SDLK_l; | 200 keymap[38] = SDLK_l; |
187 | 201 |
188 /* fourth row */ | 202 /* fourth row */ |
189 keymap[42] = SDLK_LSHIFT; | 203 keymap[42] = SDLK_LSHIFT; |
190 keymap[44] = SDLK_z; | 204 keymap[44] = SDLK_z; |
191 keymap[45] = SDLK_x; | 205 keymap[45] = SDLK_x; |
192 keymap[46] = SDLK_c; | 206 keymap[46] = SDLK_c; |
193 keymap[47] = SDLK_v; | 207 keymap[47] = SDLK_v; |
194 keymap[48] = SDLK_b; | 208 keymap[48] = SDLK_b; |
195 keymap[49] = SDLK_n; | 209 keymap[49] = SDLK_n; |
196 keymap[50] = SDLK_m; | 210 keymap[50] = SDLK_m; |
197 keymap[54] = SDLK_RSHIFT; | 211 keymap[54] = SDLK_RSHIFT; |
198 keymap[28] = SDLK_RETURN; | 212 keymap[28] = SDLK_RETURN; |
199 | 213 |
200 /* fifth row */ | 214 /* fifth row */ |
201 keymap[56] = SDLK_LALT; | 215 keymap[56] = SDLK_LALT; |
202 keymap[29] = SDLK_LCTRL; | 216 keymap[29] = SDLK_LCTRL; |
203 /* keymap[56] = ; */ | 217 /* keymap[56] = ; */ |
204 keymap[0] = SDLK_LSUPER; | 218 keymap[0] = SDLK_LSUPER; |
205 keymap[12] = SDLK_MINUS; | 219 keymap[12] = SDLK_MINUS; |
206 keymap[57] = SDLK_SPACE; | 220 keymap[57] = SDLK_SPACE; |
207 keymap[51] = SDLK_COMMA; | 221 keymap[51] = SDLK_COMMA; |
208 keymap[52] = SDLK_PERIOD; | 222 keymap[52] = SDLK_PERIOD; |
209 | 223 |
210 /* misc */ | 224 /* misc */ |
211 keymap[59] = SDLK_F1; | 225 keymap[59] = SDLK_F1; |
212 keymap[60] = SDLK_F2; | 226 keymap[60] = SDLK_F2; |
213 keymap[61] = SDLK_F3; | 227 keymap[61] = SDLK_F3; |
214 keymap[62] = SDLK_F4; | 228 keymap[62] = SDLK_F4; |
215 keymap[63] = SDLK_F5; | 229 keymap[63] = SDLK_F5; |
216 keymap[1] = SDLK_ESCAPE; | 230 keymap[1] = SDLK_ESCAPE; |
217 /* keymap[28] = SDLK_KP_ENTER; */ | 231 /* keymap[28] = SDLK_KP_ENTER; */ |
218 keymap[72] = SDLK_UP; | 232 keymap[72] = SDLK_UP; |
219 keymap[75] = SDLK_LEFT; | 233 keymap[75] = SDLK_LEFT; |
220 keymap[77] = SDLK_RIGHT; | 234 keymap[77] = SDLK_RIGHT; |
221 keymap[80] = SDLK_DOWN; | 235 keymap[80] = SDLK_DOWN; |
222 break; | 236 break; |
223 #endif /* WSKBD_TYPE_ZAURUS */ | 237 #endif /* WSKBD_TYPE_ZAURUS */ |
224 | 238 |
225 default: | 239 default: |
226 WSCONS_ReportError("Unable to map keys for keyboard type %u", | 240 WSCONS_ReportError ("Unable to map keys for keyboard type %u", |
227 private->kbdType); | 241 private->kbdType); |
228 break; | 242 break; |
229 } | 243 } |
230 } | 244 } |
231 | 245 |
232 /* end of SDL_wsconsevents.c ... */ | 246 /* end of SDL_wsconsevents.c ... */ |
233 | 247 /* vi: set ts=4 sw=4 expandtab: */ |