Mercurial > sdl-ios-xcode
comparison src/video/directfb/SDL_DirectFB_events.c @ 5202:164f20ba08eb
Updated the DirectFB support, from Couriersud
attached is a working directfb driver diff which works with the current
changes. There are a number of changes around it as well, e.g.
configure.in.
The directfb renderdriver right now still depends on a some "includes"
from src/video/directfb. That's why it is not yet moved to the new
render folder.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 05 Feb 2011 16:07:10 -0800 |
parents | dc0dfdd58f27 |
children | 572a73d71b5f |
comparison
equal
deleted
inserted
replaced
5201:7c3422025c35 | 5202:164f20ba08eb |
---|---|
16 License along with this library; if not, write to the Free Software | 16 License along with this library; if not, write to the Free Software |
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | 17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
18 | 18 |
19 Sam Lantinga | 19 Sam Lantinga |
20 slouken@libsdl.org | 20 slouken@libsdl.org |
21 | |
22 SDL1.3 DirectFB driver by couriersud@arcor.de | |
23 | |
21 */ | 24 */ |
22 #include "SDL_config.h" | |
23 | 25 |
24 /* Handle the event stream, converting DirectFB input events into SDL events */ | 26 /* Handle the event stream, converting DirectFB input events into SDL events */ |
25 | 27 |
26 #include <directfb.h> | 28 #include "SDL_DirectFB_video.h" |
27 | 29 #include "SDL_DirectFB_window.h" |
28 #include "../SDL_sysvideo.h" | 30 #include "SDL_DirectFB_modes.h" |
31 | |
32 #include "SDL_syswm.h" | |
33 | |
34 #include "../../events/SDL_mouse_c.h" | |
35 #include "../../events/SDL_keyboard_c.h" | |
36 #include "../../events/SDL_windowevents_c.h" | |
29 #include "../../events/SDL_events_c.h" | 37 #include "../../events/SDL_events_c.h" |
30 #include "../../events/SDL_keyboard_c.h" | |
31 #include "../../events/scancodes_linux.h" | 38 #include "../../events/scancodes_linux.h" |
39 #include "../../events/scancodes_xfree86.h" | |
40 | |
32 #include "SDL_DirectFB_events.h" | 41 #include "SDL_DirectFB_events.h" |
33 | 42 |
34 #if USE_MULTI_API | 43 #if USE_MULTI_API |
35 #define SDL_SendMouseMotion_ex(w, id, relative, x, y, p) SDL_SendMouseMotion(id, relative, x, y, p) | 44 #define SDL_SendMouseMotion_ex(w, id, relative, x, y, p) SDL_SendMouseMotion(id, relative, x, y, p) |
36 #define SDL_SendMouseButton_ex(w, id, state, button) SDL_SendMouseButton(id, state, button) | 45 #define SDL_SendMouseButton_ex(w, id, state, button) SDL_SendMouseButton(id, state, button) |
50 int sys_ids; | 59 int sys_ids; |
51 int sys_kbd; | 60 int sys_kbd; |
52 }; | 61 }; |
53 | 62 |
54 /* The translation tables from a DirectFB keycode to a SDL keysym */ | 63 /* The translation tables from a DirectFB keycode to a SDL keysym */ |
55 static SDLKey oskeymap[256]; | 64 static SDL_ScanCode oskeymap[256]; |
56 | 65 |
57 | 66 |
58 static SDL_KeySym *DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt, | 67 static SDL_KeySym *DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt, |
59 SDL_KeySym * keysym); | 68 SDL_KeySym * keysym); |
60 static SDL_KeySym *DirectFB_TranslateKeyInputEvent(_THIS, int index, | 69 static SDL_KeySym *DirectFB_TranslateKeyInputEvent(_THIS, DFBInputEvent * evt, |
61 DFBInputEvent * evt, | |
62 SDL_KeySym * keysym); | 70 SDL_KeySym * keysym); |
63 | 71 |
64 static void DirectFB_InitOSKeymap(_THIS, SDLKey * keypmap, int numkeys); | 72 static void DirectFB_InitOSKeymap(_THIS, SDL_ScanCode * keypmap, int numkeys); |
65 static int DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button); | 73 static int DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button); |
66 | 74 |
67 static void | 75 static void UnicodeToUtf8( Uint16 w , char *utf8buf) |
68 DirectFB_SetContext(_THIS, SDL_Window *window) | 76 { |
69 { | 77 unsigned char *utf8s = (unsigned char *) utf8buf; |
70 #if (DFB_VERSION_ATLEAST(1,0,0)) | 78 |
71 /* FIXME: does not work on 1.0/1.2 with radeon driver | 79 if ( w < 0x0080 ) { |
72 * the approach did work with the matrox driver | 80 utf8s[0] = ( unsigned char ) w; |
73 * This has simply no effect. | 81 utf8s[1] = 0; |
74 */ | 82 } |
75 | 83 else if ( w < 0x0800 ) { |
76 SDL_VideoDisplay *display = window->display; | 84 utf8s[0] = 0xc0 | (( w ) >> 6 ); |
77 DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata; | 85 utf8s[1] = 0x80 | (( w ) & 0x3f ); |
78 | 86 utf8s[2] = 0; |
79 /* FIXME: should we handle the error */ | 87 } |
80 if (dispdata->vidIDinuse) | 88 else { |
81 SDL_DFB_CHECK(dispdata->vidlayer->SwitchContext(dispdata->vidlayer, | 89 utf8s[0] = 0xe0 | (( w ) >> 12 ); |
82 DFB_TRUE)); | 90 utf8s[1] = 0x80 | (( ( w ) >> 6 ) & 0x3f ); |
83 #endif | 91 utf8s[2] = 0x80 | (( w ) & 0x3f ); |
84 | 92 utf8s[3] = 0; |
93 } | |
85 } | 94 } |
86 | 95 |
87 static void | 96 static void |
88 FocusAllMice(_THIS, SDL_Window *window) | 97 FocusAllMice(_THIS, SDL_Window *window) |
89 { | 98 { |
161 *y = cy; | 170 *y = cy; |
162 return 1; | 171 return 1; |
163 } | 172 } |
164 | 173 |
165 static void | 174 static void |
166 ProcessWindowEvent(_THIS, DFB_WindowData * p, Uint32 flags, | 175 ProcessWindowEvent(_THIS, SDL_Window *sdlwin, DFBWindowEvent * evt) |
167 DFBWindowEvent * evt) | 176 { |
168 { | 177 SDL_DFB_DEVICEDATA(_this); |
169 SDL_DFB_DEVICEDATA(_this); | 178 SDL_DFB_WINDOWDATA(sdlwin); |
170 SDL_KeySym keysym; | 179 SDL_KeySym keysym; |
171 char text[5]; | 180 char text[SDL_TEXTINPUTEVENT_TEXT_SIZE]; |
172 | 181 |
173 if (evt->clazz == DFEC_WINDOW) { | 182 if (evt->clazz == DFEC_WINDOW) { |
174 switch (evt->type) { | 183 switch (evt->type) { |
175 case DWET_BUTTONDOWN: | 184 case DWET_BUTTONDOWN: |
176 if (ClientXY(p, &evt->x, &evt->y)) { | 185 if (ClientXY(windata, &evt->x, &evt->y)) { |
177 if (!devdata->use_linux_input) { | 186 if (!devdata->use_linux_input) { |
178 SDL_SendMouseMotion_ex(p->sdl_window, devdata->mouse_id[0], 0, evt->x, | 187 SDL_SendMouseMotion_ex(sdlwin, devdata->mouse_id[0], 0, evt->x, |
179 evt->y, 0); | 188 evt->y, 0); |
180 SDL_SendMouseButton_ex(p->sdl_window, devdata->mouse_id[0], | 189 SDL_SendMouseButton_ex(sdlwin, devdata->mouse_id[0], |
181 SDL_PRESSED, | 190 SDL_PRESSED, |
182 DirectFB_TranslateButton | 191 DirectFB_TranslateButton |
183 (evt->button)); | 192 (evt->button)); |
184 } else { | 193 } else { |
185 MotionAllMice(_this, evt->x, evt->y); | 194 MotionAllMice(_this, evt->x, evt->y); |
186 } | 195 } |
187 } | 196 } |
188 break; | 197 break; |
189 case DWET_BUTTONUP: | 198 case DWET_BUTTONUP: |
190 if (ClientXY(p, &evt->x, &evt->y)) { | 199 if (ClientXY(windata, &evt->x, &evt->y)) { |
191 if (!devdata->use_linux_input) { | 200 if (!devdata->use_linux_input) { |
192 SDL_SendMouseMotion_ex(p->sdl_window, devdata->mouse_id[0], 0, evt->x, | 201 SDL_SendMouseMotion_ex(sdlwin, devdata->mouse_id[0], 0, evt->x, |
193 evt->y, 0); | 202 evt->y, 0); |
194 SDL_SendMouseButton_ex(p->sdl_window, devdata->mouse_id[0], | 203 SDL_SendMouseButton_ex(sdlwin, devdata->mouse_id[0], |
195 SDL_RELEASED, | 204 SDL_RELEASED, |
196 DirectFB_TranslateButton | 205 DirectFB_TranslateButton |
197 (evt->button)); | 206 (evt->button)); |
198 } else { | 207 } else { |
199 MotionAllMice(_this, evt->x, evt->y); | 208 MotionAllMice(_this, evt->x, evt->y); |
200 } | 209 } |
201 } | 210 } |
202 break; | 211 break; |
203 case DWET_MOTION: | 212 case DWET_MOTION: |
204 if (ClientXY(p, &evt->x, &evt->y)) { | 213 if (ClientXY(windata, &evt->x, &evt->y)) { |
205 SDL_Window *window = p->sdl_window; | |
206 if (!devdata->use_linux_input) { | 214 if (!devdata->use_linux_input) { |
207 if (!(flags & SDL_WINDOW_INPUT_GRABBED)) | 215 if (!(sdlwin->flags & SDL_WINDOW_INPUT_GRABBED)) |
208 SDL_SendMouseMotion_ex(p->sdl_window, devdata->mouse_id[0], 0, | 216 SDL_SendMouseMotion_ex(sdlwin, devdata->mouse_id[0], 0, |
209 evt->x, evt->y, 0); | 217 evt->x, evt->y, 0); |
210 } else { | 218 } else { |
211 /* relative movements are not exact! | 219 /* relative movements are not exact! |
212 * This code should limit the number of events sent. | 220 * This code should limit the number of events sent. |
213 * However it kills MAME axis recognition ... */ | 221 * However it kills MAME axis recognition ... */ |
215 if (1 && ++cnt > 20) { | 223 if (1 && ++cnt > 20) { |
216 MotionAllMice(_this, evt->x, evt->y); | 224 MotionAllMice(_this, evt->x, evt->y); |
217 cnt = 0; | 225 cnt = 0; |
218 } | 226 } |
219 } | 227 } |
220 if (!(window->flags & SDL_WINDOW_MOUSE_FOCUS)) | 228 if (!(sdlwin->flags & SDL_WINDOW_MOUSE_FOCUS)) |
221 SDL_SendWindowEvent(p->sdl_window, SDL_WINDOWEVENT_ENTER, 0, | 229 SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_ENTER, 0, |
222 0); | 230 0); |
223 } | 231 } |
224 break; | 232 break; |
225 case DWET_KEYDOWN: | 233 case DWET_KEYDOWN: |
226 if (!devdata->use_linux_input) { | 234 if (!devdata->use_linux_input) { |
227 DirectFB_TranslateKey(_this, evt, &keysym); | 235 DirectFB_TranslateKey(_this, evt, &keysym); |
236 //printf("Scancode %d %d %d\n", keysym.scancode, evt->key_code, evt->key_id); | |
228 SDL_SendKeyboardKey_ex(0, SDL_PRESSED, keysym.scancode); | 237 SDL_SendKeyboardKey_ex(0, SDL_PRESSED, keysym.scancode); |
229 if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) { | 238 if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) { |
230 SDL_memcpy(text, &keysym.unicode, 4); | 239 SDL_zero(text); |
231 text[4] = 0; | 240 UnicodeToUtf8(keysym.unicode, text); |
232 if (*text) { | 241 if (*text) { |
233 SDL_SendKeyboardText_ex(0, text); | 242 SDL_SendKeyboardText_ex(0, text); |
234 } | 243 } |
235 } | 244 } |
236 } | 245 } |
240 DirectFB_TranslateKey(_this, evt, &keysym); | 249 DirectFB_TranslateKey(_this, evt, &keysym); |
241 SDL_SendKeyboardKey_ex(0, SDL_RELEASED, keysym.scancode); | 250 SDL_SendKeyboardKey_ex(0, SDL_RELEASED, keysym.scancode); |
242 } | 251 } |
243 break; | 252 break; |
244 case DWET_POSITION: | 253 case DWET_POSITION: |
245 if (ClientXY(p, &evt->x, &evt->y)) { | 254 if (ClientXY(windata, &evt->x, &evt->y)) { |
246 SDL_SendWindowEvent(p->sdl_window, SDL_WINDOWEVENT_MOVED, | 255 SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_MOVED, |
247 evt->x, evt->y); | 256 evt->x, evt->y); |
248 } | 257 } |
249 break; | 258 break; |
250 case DWET_POSITION_SIZE: | 259 case DWET_POSITION_SIZE: |
251 if (ClientXY(p, &evt->x, &evt->y)) { | 260 if (ClientXY(windata, &evt->x, &evt->y)) { |
252 SDL_SendWindowEvent(p->sdl_window, SDL_WINDOWEVENT_MOVED, | 261 SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_MOVED, |
253 evt->x, evt->y); | 262 evt->x, evt->y); |
254 } | 263 } |
255 /* fall throught */ | 264 /* fall throught */ |
256 case DWET_SIZE: | 265 case DWET_SIZE: |
257 // FIXME: what about < 0 | 266 // FIXME: what about < 0 |
258 evt->w -= (p->theme.right_size + p->theme.left_size); | 267 evt->w -= (windata->theme.right_size + windata->theme.left_size); |
259 evt->h -= | 268 evt->h -= |
260 (p->theme.top_size + p->theme.bottom_size + | 269 (windata->theme.top_size + windata->theme.bottom_size + |
261 p->theme.caption_size); | 270 windata->theme.caption_size); |
262 SDL_SendWindowEvent(p->sdl_window, SDL_WINDOWEVENT_RESIZED, | 271 SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_RESIZED, |
263 evt->w, evt->h); | 272 evt->w, evt->h); |
264 break; | 273 break; |
265 case DWET_CLOSE: | 274 case DWET_CLOSE: |
266 SDL_SendWindowEvent(p->sdl_window, SDL_WINDOWEVENT_CLOSE, 0, 0); | 275 SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_CLOSE, 0, 0); |
267 break; | 276 break; |
268 case DWET_GOTFOCUS: | 277 case DWET_GOTFOCUS: |
269 DirectFB_SetContext(_this, p->sdl_window); | 278 DirectFB_SetContext(_this, sdlwin); |
270 FocusAllKeyboards(_this, p->sdl_window); | 279 FocusAllKeyboards(_this, sdlwin); |
271 SDL_SendWindowEvent(p->sdl_window, SDL_WINDOWEVENT_FOCUS_GAINED, | 280 SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_FOCUS_GAINED, |
272 0, 0); | 281 0, 0); |
273 break; | 282 break; |
274 case DWET_LOSTFOCUS: | 283 case DWET_LOSTFOCUS: |
275 SDL_SendWindowEvent(p->sdl_window, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0); | 284 SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0); |
276 FocusAllKeyboards(_this, 0); | 285 FocusAllKeyboards(_this, 0); |
277 break; | 286 break; |
278 case DWET_ENTER: | 287 case DWET_ENTER: |
279 /* SDL_DirectFB_ReshowCursor(_this, 0); */ | 288 /* SDL_DirectFB_ReshowCursor(_this, 0); */ |
280 FocusAllMice(_this, p->sdl_window); | 289 FocusAllMice(_this, sdlwin); |
281 // FIXME: when do we really enter ? | 290 // FIXME: when do we really enter ? |
282 if (ClientXY(p, &evt->x, &evt->y)) | 291 if (ClientXY(windata, &evt->x, &evt->y)) |
283 MotionAllMice(_this, evt->x, evt->y); | 292 MotionAllMice(_this, evt->x, evt->y); |
284 SDL_SendWindowEvent(p->sdl_window, SDL_WINDOWEVENT_ENTER, 0, 0); | 293 SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_ENTER, 0, 0); |
285 break; | 294 break; |
286 case DWET_LEAVE: | 295 case DWET_LEAVE: |
287 SDL_SendWindowEvent(p->sdl_window, SDL_WINDOWEVENT_LEAVE, 0, 0); | 296 SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_LEAVE, 0, 0); |
288 FocusAllMice(_this, 0); | 297 FocusAllMice(_this, 0); |
289 /* SDL_DirectFB_ReshowCursor(_this, 1); */ | 298 /* SDL_DirectFB_ReshowCursor(_this, 1); */ |
290 break; | 299 break; |
291 default: | 300 default: |
292 ; | 301 ; |
299 ProcessInputEvent(_THIS, DFBInputEvent * ievt) | 308 ProcessInputEvent(_THIS, DFBInputEvent * ievt) |
300 { | 309 { |
301 SDL_DFB_DEVICEDATA(_this); | 310 SDL_DFB_DEVICEDATA(_this); |
302 SDL_KeySym keysym; | 311 SDL_KeySym keysym; |
303 int kbd_idx; | 312 int kbd_idx; |
304 char text[5]; | 313 char text[SDL_TEXTINPUTEVENT_TEXT_SIZE]; |
305 | 314 |
306 if (!devdata->use_linux_input) { | 315 if (!devdata->use_linux_input) { |
307 if (ievt->type == DIET_AXISMOTION) { | 316 if (ievt->type == DIET_AXISMOTION) { |
308 if ((devdata->grabbed_window != NULL) && (ievt->flags & DIEF_AXISREL)) { | 317 if ((devdata->grabbed_window != NULL) && (ievt->flags & DIEF_AXISREL)) { |
309 if (ievt->axis == DIAI_X) | 318 if (ievt->axis == DIAI_X) |
334 if (window) { | 343 if (window) { |
335 DFB_WindowData *windata = | 344 DFB_WindowData *windata = |
336 (DFB_WindowData *) window->driverdata; | 345 (DFB_WindowData *) window->driverdata; |
337 int x, y; | 346 int x, y; |
338 | 347 |
339 windata->window->GetPosition(windata->window, &x, &y); | 348 windata->dfbwin->GetPosition(windata->dfbwin, &x, &y); |
340 SDL_SendMouseMotion_ex(window, ievt->device_id, 0, | 349 SDL_SendMouseMotion_ex(window, ievt->device_id, 0, |
341 last_x - (x + | 350 last_x - (x + |
342 windata->client.x), | 351 windata->client.x), |
343 last_y - (y + | 352 last_y - (y + |
344 windata->client.y), 0); | 353 windata->client.y), 0); |
356 ievt->axisrel, 0); | 365 ievt->axisrel, 0); |
357 } | 366 } |
358 break; | 367 break; |
359 case DIET_KEYPRESS: | 368 case DIET_KEYPRESS: |
360 kbd_idx = KbdIndex(_this, ievt->device_id); | 369 kbd_idx = KbdIndex(_this, ievt->device_id); |
361 DirectFB_TranslateKeyInputEvent(_this, kbd_idx, ievt, &keysym); | 370 DirectFB_TranslateKeyInputEvent(_this, ievt, &keysym); |
371 //printf("Scancode %d %d %d\n", keysym.scancode, evt->key_code, evt->key_id); | |
362 SDL_SendKeyboardKey_ex(kbd_idx, SDL_PRESSED, keysym.scancode); | 372 SDL_SendKeyboardKey_ex(kbd_idx, SDL_PRESSED, keysym.scancode); |
363 if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) { | 373 if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) { |
364 SDL_memcpy(text, &keysym.unicode, 4); | 374 SDL_zero(text); |
365 text[4] = 0; | 375 UnicodeToUtf8(keysym.unicode, text); |
366 if (*text) { | 376 if (*text) { |
367 SDL_SendKeyboardText_ex(kbd_idx, text); | 377 SDL_SendKeyboardText_ex(kbd_idx, text); |
368 } | 378 } |
369 } | 379 } |
370 break; | 380 break; |
371 case DIET_KEYRELEASE: | 381 case DIET_KEYRELEASE: |
372 kbd_idx = KbdIndex(_this, ievt->device_id); | 382 kbd_idx = KbdIndex(_this, ievt->device_id); |
373 DirectFB_TranslateKeyInputEvent(_this, kbd_idx, ievt, &keysym); | 383 DirectFB_TranslateKeyInputEvent(_this, ievt, &keysym); |
374 SDL_SendKeyboardKey_ex(kbd_idx, SDL_RELEASED, keysym.scancode); | 384 SDL_SendKeyboardKey_ex(kbd_idx, SDL_RELEASED, keysym.scancode); |
375 break; | 385 break; |
376 case DIET_BUTTONPRESS: | 386 case DIET_BUTTONPRESS: |
377 if (ievt->buttons & DIBM_LEFT) | 387 if (ievt->buttons & DIBM_LEFT) |
378 SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_PRESSED, 1); | 388 SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_PRESSED, 1); |
397 | 407 |
398 void | 408 void |
399 DirectFB_PumpEventsWindow(_THIS) | 409 DirectFB_PumpEventsWindow(_THIS) |
400 { | 410 { |
401 SDL_DFB_DEVICEDATA(_this); | 411 SDL_DFB_DEVICEDATA(_this); |
402 DFB_WindowData *p; | |
403 DFBInputEvent ievt; | 412 DFBInputEvent ievt; |
404 | 413 SDL_Window *w; |
405 for (p = devdata->firstwin; p != NULL; p = p->next) { | 414 |
415 for (w = devdata->firstwin; w != NULL; w = w->next) { | |
416 SDL_DFB_WINDOWDATA(w); | |
406 DFBWindowEvent evt; | 417 DFBWindowEvent evt; |
407 SDL_Window *w = p->sdl_window; | 418 |
408 | 419 while (windata->eventbuffer->GetEvent(windata->eventbuffer, |
409 while (p->eventbuffer->GetEvent(p->eventbuffer, | |
410 DFB_EVENT(&evt)) == DFB_OK) { | 420 DFB_EVENT(&evt)) == DFB_OK) { |
411 if (!DirectFB_WM_ProcessEvent(_this, w, &evt)) | 421 if (!DirectFB_WM_ProcessEvent(_this, w, &evt)) { |
412 ProcessWindowEvent(_this, p, w->flags, &evt); | 422 /* Send a SDL_SYSWMEVENT if the application wants them */ |
423 if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) { | |
424 SDL_SysWMmsg wmmsg; | |
425 SDL_VERSION(&wmmsg.version); | |
426 wmmsg.subsystem = SDL_SYSWM_DIRECTFB; | |
427 wmmsg.msg.dfb.event.window = evt; | |
428 SDL_SendSysWMEvent(&wmmsg); | |
429 } | |
430 ProcessWindowEvent(_this, w, &evt); | |
431 } | |
413 } | 432 } |
414 } | 433 } |
415 | 434 |
416 /* Now get relative events in case we need them */ | 435 /* Now get relative events in case we need them */ |
417 while (devdata->events->GetEvent(devdata->events, | 436 while (devdata->events->GetEvent(devdata->events, |
418 DFB_EVENT(&ievt)) == DFB_OK) { | 437 DFB_EVENT(&ievt)) == DFB_OK) { |
438 | |
439 if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) { | |
440 SDL_SysWMmsg wmmsg; | |
441 SDL_VERSION(&wmmsg.version); | |
442 wmmsg.subsystem = SDL_SYSWM_DIRECTFB; | |
443 wmmsg.msg.dfb.event.input = ievt; | |
444 SDL_SendSysWMEvent(&wmmsg); | |
445 } | |
419 ProcessInputEvent(_this, &ievt); | 446 ProcessInputEvent(_this, &ievt); |
420 } | 447 } |
421 } | 448 } |
422 | 449 |
423 void | 450 void |
424 DirectFB_InitOSKeymap(_THIS, SDLKey * keymap, int numkeys) | 451 DirectFB_InitOSKeymap(_THIS, SDL_ScanCode * keymap, int numkeys) |
425 { | 452 { |
426 int i; | 453 int i; |
427 | 454 |
428 /* Initialize the DirectFB key translation table */ | 455 /* Initialize the DirectFB key translation table */ |
429 for (i = 0; i < numkeys; ++i) | 456 for (i = 0; i < numkeys; ++i) |
550 | 577 |
551 static SDL_KeySym * | 578 static SDL_KeySym * |
552 DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt, SDL_KeySym * keysym) | 579 DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt, SDL_KeySym * keysym) |
553 { | 580 { |
554 SDL_DFB_DEVICEDATA(_this); | 581 SDL_DFB_DEVICEDATA(_this); |
555 | 582 int kbd_idx = 0; /* Window events lag the device source KbdIndex(_this, evt->device_id); */ |
556 if (evt->key_code >= 0 && | 583 DFB_KeyboardData *kbd = &devdata->keyboard[kbd_idx]; |
557 evt->key_code < SDL_arraysize(linux_scancode_table)) | 584 |
558 keysym->scancode = linux_scancode_table[evt->key_code]; | 585 keysym->scancode = SDL_SCANCODE_UNKNOWN; |
559 else | 586 |
560 keysym->scancode = SDL_SCANCODE_UNKNOWN; | 587 if (kbd->map && evt->key_code >= kbd->map_adjust && |
588 evt->key_code < kbd->map_size + kbd->map_adjust) | |
589 keysym->scancode = kbd->map[evt->key_code - kbd->map_adjust]; | |
561 | 590 |
562 if (keysym->scancode == SDL_SCANCODE_UNKNOWN || | 591 if (keysym->scancode == SDL_SCANCODE_UNKNOWN || |
563 devdata->keyboard[0].is_generic) { | 592 devdata->keyboard[kbd_idx].is_generic) { |
564 if (evt->key_id - DIKI_UNKNOWN < SDL_arraysize(oskeymap)) | 593 if (evt->key_id - DIKI_UNKNOWN < SDL_arraysize(oskeymap)) |
565 keysym->scancode = oskeymap[evt->key_id - DIKI_UNKNOWN]; | 594 keysym->scancode = oskeymap[evt->key_id - DIKI_UNKNOWN]; |
566 else | 595 else |
567 keysym->scancode = SDL_SCANCODE_UNKNOWN; | 596 keysym->scancode = SDL_SCANCODE_UNKNOWN; |
568 } | 597 } |
575 | 604 |
576 return keysym; | 605 return keysym; |
577 } | 606 } |
578 | 607 |
579 static SDL_KeySym * | 608 static SDL_KeySym * |
580 DirectFB_TranslateKeyInputEvent(_THIS, int index, DFBInputEvent * evt, | 609 DirectFB_TranslateKeyInputEvent(_THIS, DFBInputEvent * evt, |
581 SDL_KeySym * keysym) | 610 SDL_KeySym * keysym) |
582 { | 611 { |
583 SDL_DFB_DEVICEDATA(_this); | 612 SDL_DFB_DEVICEDATA(_this); |
584 | 613 int kbd_idx = KbdIndex(_this, evt->device_id); |
585 if (evt->key_code >= 0 && | 614 DFB_KeyboardData *kbd = &devdata->keyboard[kbd_idx]; |
586 evt->key_code < SDL_arraysize(linux_scancode_table)) | 615 |
587 keysym->scancode = linux_scancode_table[evt->key_code]; | 616 keysym->scancode = SDL_SCANCODE_UNKNOWN; |
588 else | 617 |
589 keysym->scancode = SDL_SCANCODE_UNKNOWN; | 618 if (kbd->map && evt->key_code >= kbd->map_adjust && |
590 | 619 evt->key_code < kbd->map_size + kbd->map_adjust) |
591 if (keysym->scancode == SDL_SCANCODE_UNKNOWN || | 620 keysym->scancode = kbd->map[evt->key_code - kbd->map_adjust]; |
592 devdata->keyboard[index].is_generic) { | 621 |
622 if (keysym->scancode == SDL_SCANCODE_UNKNOWN || devdata->keyboard[kbd_idx].is_generic) { | |
593 if (evt->key_id - DIKI_UNKNOWN < SDL_arraysize(oskeymap)) | 623 if (evt->key_id - DIKI_UNKNOWN < SDL_arraysize(oskeymap)) |
594 keysym->scancode = oskeymap[evt->key_id - DIKI_UNKNOWN]; | 624 keysym->scancode = oskeymap[evt->key_id - DIKI_UNKNOWN]; |
595 else | 625 else |
596 keysym->scancode = SDL_SCANCODE_UNKNOWN; | 626 keysym->scancode = SDL_SCANCODE_UNKNOWN; |
597 } | 627 } |
650 SDL_AddKeyboard(&keyboard, devdata->num_keyboard); | 680 SDL_AddKeyboard(&keyboard, devdata->num_keyboard); |
651 #endif | 681 #endif |
652 devdata->keyboard[devdata->num_keyboard].id = device_id; | 682 devdata->keyboard[devdata->num_keyboard].id = device_id; |
653 devdata->keyboard[devdata->num_keyboard].is_generic = 0; | 683 devdata->keyboard[devdata->num_keyboard].is_generic = 0; |
654 if (!strncmp("X11", desc.name, 3)) | 684 if (!strncmp("X11", desc.name, 3)) |
655 devdata->keyboard[devdata->num_keyboard].is_generic = 1; | 685 { |
656 | 686 devdata->keyboard[devdata->num_keyboard].map = xfree86_scancode_table2; |
687 devdata->keyboard[devdata->num_keyboard].map_size = SDL_arraysize(xfree86_scancode_table2); | |
688 devdata->keyboard[devdata->num_keyboard].map_adjust = 8; | |
689 } else { | |
690 devdata->keyboard[devdata->num_keyboard].map = linux_scancode_table; | |
691 devdata->keyboard[devdata->num_keyboard].map_size = SDL_arraysize(linux_scancode_table); | |
692 devdata->keyboard[devdata->num_keyboard].map_adjust = 0; | |
693 } | |
694 | |
695 SDL_DFB_LOG("Keyboard %d - %s\n", device_id, desc.name); | |
696 | |
657 SDL_GetDefaultKeymap(keymap); | 697 SDL_GetDefaultKeymap(keymap); |
658 #if USE_MULTI_API | 698 #if USE_MULTI_API |
659 SDL_SetKeymap(devdata->num_keyboard, 0, keymap, SDL_NUM_SCANCODES); | 699 SDL_SetKeymap(devdata->num_keyboard, 0, keymap, SDL_NUM_SCANCODES); |
660 #else | 700 #else |
661 SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES); | 701 SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES); |
705 | 745 |
706 SDL_KeyboardQuit(); | 746 SDL_KeyboardQuit(); |
707 | 747 |
708 } | 748 } |
709 | 749 |
710 #if 0 | |
711 /* FIXME: Remove once determined this is not needed in fullscreen mode */ | |
712 void | |
713 DirectFB_PumpEvents(_THIS) | |
714 { | |
715 SDL_DFB_DEVICEDATA(_this); | |
716 DFBInputEvent evt; | |
717 static last_x = 0, last_y = 0; | |
718 | |
719 while (devdata->eventbuffer->GetEvent(devdata->eventbuffer, | |
720 DFB_EVENT(&evt)) == DFB_OK) { | |
721 SDL_KeySym keysym; | |
722 DFBInputDeviceModifierMask mod; | |
723 | |
724 if (evt.clazz = DFEC_INPUT) { | |
725 if (evt.flags & DIEF_MODIFIERS) | |
726 mod = evt.modifiers; | |
727 else | |
728 mod = 0; | |
729 | |
730 switch (evt.type) { | |
731 case DIET_BUTTONPRESS: | |
732 posted += | |
733 SDL_PrivateMouseButton(SDL_PRESSED, | |
734 DirectFB_TranslateButton | |
735 (evt.button), 0, 0); | |
736 break; | |
737 case DIET_BUTTONRELEASE: | |
738 posted += | |
739 SDL_PrivateMouseButton(SDL_RELEASED, | |
740 DirectFB_TranslateButton | |
741 (evt.button), 0, 0); | |
742 break; | |
743 case DIET_KEYPRESS: | |
744 posted += | |
745 SDL_PrivateKeyboard(SDL_PRESSED, | |
746 DirectFB_TranslateKey | |
747 (evt.key_id, evt.key_symbol, | |
748 mod, &keysym)); | |
749 break; | |
750 case DIET_KEYRELEASE: | |
751 posted += | |
752 SDL_PrivateKeyboard(SDL_RELEASED, | |
753 DirectFB_TranslateKey | |
754 (evt.key_id, evt.key_symbol, | |
755 mod, &keysym)); | |
756 break; | |
757 case DIET_AXISMOTION: | |
758 if (evt.flags & DIEF_AXISREL) { | |
759 if (evt.axis == DIAI_X) | |
760 posted += | |
761 SDL_PrivateMouseMotion(0, 1, evt.axisrel, 0); | |
762 else if (evt.axis == DIAI_Y) | |
763 posted += | |
764 SDL_PrivateMouseMotion(0, 1, 0, evt.axisrel); | |
765 } else if (evt.flags & DIEF_AXISABS) { | |
766 if (evt.axis == DIAI_X) | |
767 last_x = evt.axisabs; | |
768 else if (evt.axis == DIAI_Y) | |
769 last_y = evt.axisabs; | |
770 posted += SDL_PrivateMouseMotion(0, 0, last_x, last_y); | |
771 } | |
772 break; | |
773 default: | |
774 ; | |
775 } | |
776 } | |
777 } | |
778 } | |
779 #endif | |
780 |