This repository has been archived by the owner on Feb 11, 2021. It is now read-only.
/
SDL_DirectFB_events.c
745 lines (669 loc) · 27.8 KB
1
/*
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Simple DirectMedia Layer
Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
20
21
22
23
*/
/* Handle the event stream, converting DirectFB input events into SDL events */
24
25
26
#include "SDL_DirectFB_video.h"
#include "SDL_DirectFB_window.h"
#include "SDL_DirectFB_modes.h"
27
28
29
30
#include "SDL_syswm.h"
#include "../../events/SDL_mouse_c.h"
31
#include "../../events/SDL_keyboard_c.h"
32
33
#include "../../events/SDL_windowevents_c.h"
#include "../../events/SDL_events_c.h"
34
#include "../../events/scancodes_linux.h"
35
36
#include "../../events/scancodes_xfree86.h"
37
38
#include "SDL_DirectFB_events.h"
39
#if USE_MULTI_API
40
41
#define SDL_SendMouseMotion_ex(w, id, relative, x, y, p) SDL_SendMouseMotion(id, relative, x, y, p)
#define SDL_SendMouseButton_ex(w, id, state, button) SDL_SendMouseButton(id, state, button)
42
43
44
#define SDL_SendKeyboardKey_ex(id, state, scancode) SDL_SendKeyboardKey(id, state, scancode)
#define SDL_SendKeyboardText_ex(id, text) SDL_SendKeyboardText(id, text)
#else
45
46
#define SDL_SendMouseMotion_ex(w, id, relative, x, y, p) SDL_SendMouseMotion(w, relative, x, y)
#define SDL_SendMouseButton_ex(w, id, state, button) SDL_SendMouseButton(w, state, button)
47
48
49
50
#define SDL_SendKeyboardKey_ex(id, state, scancode) SDL_SendKeyboardKey(state, scancode)
#define SDL_SendKeyboardText_ex(id, text) SDL_SendKeyboardText(text)
#endif
51
52
53
54
55
56
57
typedef struct _cb_data cb_data;
struct _cb_data
{
DFB_DeviceData *devdata;
int sys_ids;
int sys_kbd;
};
58
59
/* The translation tables from a DirectFB keycode to a SDL keysym */
60
static SDL_Scancode oskeymap[256];
61
62
63
64
65
66
static SDL_Keysym *DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt,
SDL_Keysym * keysym);
static SDL_Keysym *DirectFB_TranslateKeyInputEvent(_THIS, DFBInputEvent * evt,
SDL_Keysym * keysym);
67
68
static void DirectFB_InitOSKeymap(_THIS, SDL_Scancode * keypmap, int numkeys);
69
static int DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button);
70
71
static void UnicodeToUtf8( Uint16 w , char *utf8buf)
72
{
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
unsigned char *utf8s = (unsigned char *) utf8buf;
if ( w < 0x0080 ) {
utf8s[0] = ( unsigned char ) w;
utf8s[1] = 0;
}
else if ( w < 0x0800 ) {
utf8s[0] = 0xc0 | (( w ) >> 6 );
utf8s[1] = 0x80 | (( w ) & 0x3f );
utf8s[2] = 0;
}
else {
utf8s[0] = 0xe0 | (( w ) >> 12 );
utf8s[1] = 0x80 | (( ( w ) >> 6 ) & 0x3f );
utf8s[2] = 0x80 | (( w ) & 0x3f );
utf8s[3] = 0;
}
90
91
}
92
static void
93
FocusAllMice(_THIS, SDL_Window *window)
94
{
95
#if USE_MULTI_API
96
97
98
99
100
SDL_DFB_DEVICEDATA(_this);
int index;
for (index = 0; index < devdata->num_mice; index++)
SDL_SetMouseFocus(devdata->mouse_id[index], id);
101
102
103
#else
SDL_SetMouseFocus(window);
#endif
104
105
106
107
}
static void
108
FocusAllKeyboards(_THIS, SDL_Window *window)
109
{
110
#if USE_MULTI_API
111
112
113
114
115
SDL_DFB_DEVICEDATA(_this);
int index;
for (index = 0; index < devdata->num_keyboard; index++)
SDL_SetKeyboardFocus(index, id);
116
117
118
#else
SDL_SetKeyboardFocus(window);
#endif
119
120
121
122
123
}
static void
MotionAllMice(_THIS, int x, int y)
{
124
#if USE_MULTI_API
125
126
127
128
129
130
131
132
133
SDL_DFB_DEVICEDATA(_this);
int index;
for (index = 0; index < devdata->num_mice; index++) {
SDL_Mouse *mouse = SDL_GetMouse(index);
mouse->x = mouse->last_x = x;
mouse->y = mouse->last_y = y;
//SDL_SendMouseMotion(devdata->mouse_id[index], 0, x, y, 0);
}
134
#endif
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
}
static int
KbdIndex(_THIS, int id)
{
SDL_DFB_DEVICEDATA(_this);
int index;
for (index = 0; index < devdata->num_keyboard; index++) {
if (devdata->keyboard[index].id == id)
return index;
}
return -1;
}
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
static int
ClientXY(DFB_WindowData * p, int *x, int *y)
{
int cx, cy;
cx = *x;
cy = *y;
cx -= p->client.x;
cy -= p->client.y;
if (cx < 0 || cy < 0)
return 0;
if (cx >= p->client.w || cy >= p->client.h)
return 0;
*x = cx;
*y = cy;
return 1;
}
static void
171
ProcessWindowEvent(_THIS, SDL_Window *sdlwin, DFBWindowEvent * evt)
172
173
{
SDL_DFB_DEVICEDATA(_this);
174
SDL_DFB_WINDOWDATA(sdlwin);
175
SDL_Keysym keysym;
176
char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
177
178
179
180
if (evt->clazz == DFEC_WINDOW) {
switch (evt->type) {
case DWET_BUTTONDOWN:
181
if (ClientXY(windata, &evt->x, &evt->y)) {
182
if (!devdata->use_linux_input) {
183
SDL_SendMouseMotion_ex(sdlwin, devdata->mouse_id[0], 0, evt->x,
184
evt->y, 0);
185
SDL_SendMouseButton_ex(sdlwin, devdata->mouse_id[0],
186
187
188
189
190
191
192
193
194
SDL_PRESSED,
DirectFB_TranslateButton
(evt->button));
} else {
MotionAllMice(_this, evt->x, evt->y);
}
}
break;
case DWET_BUTTONUP:
195
if (ClientXY(windata, &evt->x, &evt->y)) {
196
if (!devdata->use_linux_input) {
197
SDL_SendMouseMotion_ex(sdlwin, devdata->mouse_id[0], 0, evt->x,
198
evt->y, 0);
199
SDL_SendMouseButton_ex(sdlwin, devdata->mouse_id[0],
200
201
202
203
204
205
206
207
208
SDL_RELEASED,
DirectFB_TranslateButton
(evt->button));
} else {
MotionAllMice(_this, evt->x, evt->y);
}
}
break;
case DWET_MOTION:
209
if (ClientXY(windata, &evt->x, &evt->y)) {
210
if (!devdata->use_linux_input) {
211
212
if (!(sdlwin->flags & SDL_WINDOW_INPUT_GRABBED))
SDL_SendMouseMotion_ex(sdlwin, devdata->mouse_id[0], 0,
213
214
215
216
217
218
219
220
221
222
223
evt->x, evt->y, 0);
} else {
/* relative movements are not exact!
* This code should limit the number of events sent.
* However it kills MAME axis recognition ... */
static int cnt = 0;
if (1 && ++cnt > 20) {
MotionAllMice(_this, evt->x, evt->y);
cnt = 0;
}
}
224
225
if (!(sdlwin->flags & SDL_WINDOW_MOUSE_FOCUS))
SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_ENTER, 0,
226
0);
227
228
229
230
231
}
break;
case DWET_KEYDOWN:
if (!devdata->use_linux_input) {
DirectFB_TranslateKey(_this, evt, &keysym);
232
//printf("Scancode %d %d %d\n", keysym.scancode, evt->key_code, evt->key_id);
233
SDL_SendKeyboardKey_ex(0, SDL_PRESSED, keysym.scancode);
234
if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
235
236
SDL_zero(text);
UnicodeToUtf8(keysym.unicode, text);
237
if (*text) {
238
SDL_SendKeyboardText_ex(0, text);
239
240
241
242
243
244
245
}
}
}
break;
case DWET_KEYUP:
if (!devdata->use_linux_input) {
DirectFB_TranslateKey(_this, evt, &keysym);
246
SDL_SendKeyboardKey_ex(0, SDL_RELEASED, keysym.scancode);
247
248
249
}
break;
case DWET_POSITION:
250
251
if (ClientXY(windata, &evt->x, &evt->y)) {
SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_MOVED,
252
253
254
255
evt->x, evt->y);
}
break;
case DWET_POSITION_SIZE:
256
257
if (ClientXY(windata, &evt->x, &evt->y)) {
SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_MOVED,
258
259
260
261
262
evt->x, evt->y);
}
/* fall throught */
case DWET_SIZE:
// FIXME: what about < 0
263
evt->w -= (windata->theme.right_size + windata->theme.left_size);
264
evt->h -=
265
266
267
(windata->theme.top_size + windata->theme.bottom_size +
windata->theme.caption_size);
SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_RESIZED,
268
269
270
evt->w, evt->h);
break;
case DWET_CLOSE:
271
SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_CLOSE, 0, 0);
272
273
break;
case DWET_GOTFOCUS:
274
275
276
DirectFB_SetContext(_this, sdlwin);
FocusAllKeyboards(_this, sdlwin);
SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_FOCUS_GAINED,
277
278
279
0, 0);
break;
case DWET_LOSTFOCUS:
280
SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
281
282
283
284
FocusAllKeyboards(_this, 0);
break;
case DWET_ENTER:
/* SDL_DirectFB_ReshowCursor(_this, 0); */
285
FocusAllMice(_this, sdlwin);
286
// FIXME: when do we really enter ?
287
if (ClientXY(windata, &evt->x, &evt->y))
288
MotionAllMice(_this, evt->x, evt->y);
289
SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_ENTER, 0, 0);
290
291
break;
case DWET_LEAVE:
292
SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_LEAVE, 0, 0);
293
294
295
296
297
298
299
300
301
302
303
FocusAllMice(_this, 0);
/* SDL_DirectFB_ReshowCursor(_this, 1); */
break;
default:
;
}
} else
printf("Event Clazz %d\n", evt->clazz);
}
static void
304
ProcessInputEvent(_THIS, DFBInputEvent * ievt)
305
306
{
SDL_DFB_DEVICEDATA(_this);
307
SDL_Keysym keysym;
308
int kbd_idx;
309
char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
310
311
312
if (!devdata->use_linux_input) {
if (ievt->type == DIET_AXISMOTION) {
313
if ((devdata->grabbed_window != NULL) && (ievt->flags & DIEF_AXISREL)) {
314
if (ievt->axis == DIAI_X)
315
SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1,
316
317
ievt->axisrel, 0, 0);
else if (ievt->axis == DIAI_Y)
318
SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1, 0,
319
320
321
322
323
324
325
326
327
328
329
330
331
332
ievt->axisrel, 0);
}
}
} else {
static int last_x, last_y;
switch (ievt->type) {
case DIET_AXISMOTION:
if (ievt->flags & DIEF_AXISABS) {
if (ievt->axis == DIAI_X)
last_x = ievt->axisabs;
else if (ievt->axis == DIAI_Y)
last_y = ievt->axisabs;
if (!(ievt->flags & DIEF_FOLLOW)) {
333
#if USE_MULTI_API
334
335
SDL_Mouse *mouse = SDL_GetMouse(ievt->device_id);
SDL_Window *window = SDL_GetWindowFromID(mouse->focus);
336
337
338
#else
SDL_Window *window = devdata->grabbed_window;
#endif
339
340
341
342
343
if (window) {
DFB_WindowData *windata =
(DFB_WindowData *) window->driverdata;
int x, y;
344
windata->dfbwin->GetPosition(windata->dfbwin, &x, &y);
345
SDL_SendMouseMotion_ex(window, ievt->device_id, 0,
346
347
348
349
350
last_x - (x +
windata->client.x),
last_y - (y +
windata->client.y), 0);
} else {
351
SDL_SendMouseMotion_ex(window, ievt->device_id, 0, last_x,
352
353
354
355
356
last_y, 0);
}
}
} else if (ievt->flags & DIEF_AXISREL) {
if (ievt->axis == DIAI_X)
357
SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1,
358
359
ievt->axisrel, 0, 0);
else if (ievt->axis == DIAI_Y)
360
SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1, 0,
361
362
363
364
365
ievt->axisrel, 0);
}
break;
case DIET_KEYPRESS:
kbd_idx = KbdIndex(_this, ievt->device_id);
366
367
DirectFB_TranslateKeyInputEvent(_this, ievt, &keysym);
//printf("Scancode %d %d %d\n", keysym.scancode, evt->key_code, evt->key_id);
368
SDL_SendKeyboardKey_ex(kbd_idx, SDL_PRESSED, keysym.scancode);
369
if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
370
371
SDL_zero(text);
UnicodeToUtf8(keysym.unicode, text);
372
if (*text) {
373
SDL_SendKeyboardText_ex(kbd_idx, text);
374
375
376
377
378
}
}
break;
case DIET_KEYRELEASE:
kbd_idx = KbdIndex(_this, ievt->device_id);
379
DirectFB_TranslateKeyInputEvent(_this, ievt, &keysym);
380
SDL_SendKeyboardKey_ex(kbd_idx, SDL_RELEASED, keysym.scancode);
381
382
383
break;
case DIET_BUTTONPRESS:
if (ievt->buttons & DIBM_LEFT)
384
SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_PRESSED, 1);
385
if (ievt->buttons & DIBM_MIDDLE)
386
SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_PRESSED, 2);
387
if (ievt->buttons & DIBM_RIGHT)
388
SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_PRESSED, 3);
389
390
391
break;
case DIET_BUTTONRELEASE:
if (!(ievt->buttons & DIBM_LEFT))
392
SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_RELEASED, 1);
393
if (!(ievt->buttons & DIBM_MIDDLE))
394
SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_RELEASED, 2);
395
if (!(ievt->buttons & DIBM_RIGHT))
396
SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_RELEASED, 3);
397
398
399
400
401
402
403
break;
default:
break; /* please gcc */
}
}
}
404
void
405
DirectFB_PumpEventsWindow(_THIS)
406
{
407
SDL_DFB_DEVICEDATA(_this);
408
DFBInputEvent ievt;
409
SDL_Window *w;
410
411
412
for (w = devdata->firstwin; w != NULL; w = w->next) {
SDL_DFB_WINDOWDATA(w);
413
DFBWindowEvent evt;
414
415
while (windata->eventbuffer->GetEvent(windata->eventbuffer,
416
DFB_EVENT(&evt)) == DFB_OK) {
417
418
419
420
421
422
423
424
425
426
427
if (!DirectFB_WM_ProcessEvent(_this, w, &evt)) {
/* Send a SDL_SYSWMEVENT if the application wants them */
if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) {
SDL_SysWMmsg wmmsg;
SDL_VERSION(&wmmsg.version);
wmmsg.subsystem = SDL_SYSWM_DIRECTFB;
wmmsg.msg.dfb.event.window = evt;
SDL_SendSysWMEvent(&wmmsg);
}
ProcessWindowEvent(_this, w, &evt);
}
428
429
430
431
432
433
}
}
/* Now get relative events in case we need them */
while (devdata->events->GetEvent(devdata->events,
DFB_EVENT(&ievt)) == DFB_OK) {
434
435
436
437
438
439
440
441
if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) {
SDL_SysWMmsg wmmsg;
SDL_VERSION(&wmmsg.version);
wmmsg.subsystem = SDL_SYSWM_DIRECTFB;
wmmsg.msg.dfb.event.input = ievt;
SDL_SendSysWMEvent(&wmmsg);
}
442
ProcessInputEvent(_this, &ievt);
443
444
445
}
}
446
void
447
DirectFB_InitOSKeymap(_THIS, SDL_Scancode * keymap, int numkeys)
448
{
449
450
451
int i;
/* Initialize the DirectFB key translation table */
452
for (i = 0; i < numkeys; ++i)
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
keymap[i] = SDL_SCANCODE_UNKNOWN;
keymap[DIKI_A - DIKI_UNKNOWN] = SDL_SCANCODE_A;
keymap[DIKI_B - DIKI_UNKNOWN] = SDL_SCANCODE_B;
keymap[DIKI_C - DIKI_UNKNOWN] = SDL_SCANCODE_C;
keymap[DIKI_D - DIKI_UNKNOWN] = SDL_SCANCODE_D;
keymap[DIKI_E - DIKI_UNKNOWN] = SDL_SCANCODE_E;
keymap[DIKI_F - DIKI_UNKNOWN] = SDL_SCANCODE_F;
keymap[DIKI_G - DIKI_UNKNOWN] = SDL_SCANCODE_G;
keymap[DIKI_H - DIKI_UNKNOWN] = SDL_SCANCODE_H;
keymap[DIKI_I - DIKI_UNKNOWN] = SDL_SCANCODE_I;
keymap[DIKI_J - DIKI_UNKNOWN] = SDL_SCANCODE_J;
keymap[DIKI_K - DIKI_UNKNOWN] = SDL_SCANCODE_K;
keymap[DIKI_L - DIKI_UNKNOWN] = SDL_SCANCODE_L;
keymap[DIKI_M - DIKI_UNKNOWN] = SDL_SCANCODE_M;
keymap[DIKI_N - DIKI_UNKNOWN] = SDL_SCANCODE_N;
keymap[DIKI_O - DIKI_UNKNOWN] = SDL_SCANCODE_O;
keymap[DIKI_P - DIKI_UNKNOWN] = SDL_SCANCODE_P;
keymap[DIKI_Q - DIKI_UNKNOWN] = SDL_SCANCODE_Q;
keymap[DIKI_R - DIKI_UNKNOWN] = SDL_SCANCODE_R;
keymap[DIKI_S - DIKI_UNKNOWN] = SDL_SCANCODE_S;
keymap[DIKI_T - DIKI_UNKNOWN] = SDL_SCANCODE_T;
keymap[DIKI_U - DIKI_UNKNOWN] = SDL_SCANCODE_U;
keymap[DIKI_V - DIKI_UNKNOWN] = SDL_SCANCODE_V;
keymap[DIKI_W - DIKI_UNKNOWN] = SDL_SCANCODE_W;
keymap[DIKI_X - DIKI_UNKNOWN] = SDL_SCANCODE_X;
keymap[DIKI_Y - DIKI_UNKNOWN] = SDL_SCANCODE_Y;
keymap[DIKI_Z - DIKI_UNKNOWN] = SDL_SCANCODE_Z;
keymap[DIKI_0 - DIKI_UNKNOWN] = SDL_SCANCODE_0;
keymap[DIKI_1 - DIKI_UNKNOWN] = SDL_SCANCODE_1;
keymap[DIKI_2 - DIKI_UNKNOWN] = SDL_SCANCODE_2;
keymap[DIKI_3 - DIKI_UNKNOWN] = SDL_SCANCODE_3;
keymap[DIKI_4 - DIKI_UNKNOWN] = SDL_SCANCODE_4;
keymap[DIKI_5 - DIKI_UNKNOWN] = SDL_SCANCODE_5;
keymap[DIKI_6 - DIKI_UNKNOWN] = SDL_SCANCODE_6;
keymap[DIKI_7 - DIKI_UNKNOWN] = SDL_SCANCODE_7;
keymap[DIKI_8 - DIKI_UNKNOWN] = SDL_SCANCODE_8;
keymap[DIKI_9 - DIKI_UNKNOWN] = SDL_SCANCODE_9;
keymap[DIKI_F1 - DIKI_UNKNOWN] = SDL_SCANCODE_F1;
keymap[DIKI_F2 - DIKI_UNKNOWN] = SDL_SCANCODE_F2;
keymap[DIKI_F3 - DIKI_UNKNOWN] = SDL_SCANCODE_F3;
keymap[DIKI_F4 - DIKI_UNKNOWN] = SDL_SCANCODE_F4;
keymap[DIKI_F5 - DIKI_UNKNOWN] = SDL_SCANCODE_F5;
keymap[DIKI_F6 - DIKI_UNKNOWN] = SDL_SCANCODE_F6;
keymap[DIKI_F7 - DIKI_UNKNOWN] = SDL_SCANCODE_F7;
keymap[DIKI_F8 - DIKI_UNKNOWN] = SDL_SCANCODE_F8;
keymap[DIKI_F9 - DIKI_UNKNOWN] = SDL_SCANCODE_F9;
keymap[DIKI_F10 - DIKI_UNKNOWN] = SDL_SCANCODE_F10;
keymap[DIKI_F11 - DIKI_UNKNOWN] = SDL_SCANCODE_F11;
keymap[DIKI_F12 - DIKI_UNKNOWN] = SDL_SCANCODE_F12;
keymap[DIKI_ESCAPE - DIKI_UNKNOWN] = SDL_SCANCODE_ESCAPE;
keymap[DIKI_LEFT - DIKI_UNKNOWN] = SDL_SCANCODE_LEFT;
keymap[DIKI_RIGHT - DIKI_UNKNOWN] = SDL_SCANCODE_RIGHT;
keymap[DIKI_UP - DIKI_UNKNOWN] = SDL_SCANCODE_UP;
keymap[DIKI_DOWN - DIKI_UNKNOWN] = SDL_SCANCODE_DOWN;
keymap[DIKI_CONTROL_L - DIKI_UNKNOWN] = SDL_SCANCODE_LCTRL;
keymap[DIKI_CONTROL_R - DIKI_UNKNOWN] = SDL_SCANCODE_RCTRL;
keymap[DIKI_SHIFT_L - DIKI_UNKNOWN] = SDL_SCANCODE_LSHIFT;
keymap[DIKI_SHIFT_R - DIKI_UNKNOWN] = SDL_SCANCODE_RSHIFT;
keymap[DIKI_ALT_L - DIKI_UNKNOWN] = SDL_SCANCODE_LALT;
keymap[DIKI_ALT_R - DIKI_UNKNOWN] = SDL_SCANCODE_RALT;
keymap[DIKI_META_L - DIKI_UNKNOWN] = SDL_SCANCODE_LGUI;
keymap[DIKI_META_R - DIKI_UNKNOWN] = SDL_SCANCODE_RGUI;
keymap[DIKI_SUPER_L - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
keymap[DIKI_SUPER_R - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
521
522
523
524
/* FIXME:Do we read hyper keys ?
* keymap[DIKI_HYPER_L - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
* keymap[DIKI_HYPER_R - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
*/
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
keymap[DIKI_TAB - DIKI_UNKNOWN] = SDL_SCANCODE_TAB;
keymap[DIKI_ENTER - DIKI_UNKNOWN] = SDL_SCANCODE_RETURN;
keymap[DIKI_SPACE - DIKI_UNKNOWN] = SDL_SCANCODE_SPACE;
keymap[DIKI_BACKSPACE - DIKI_UNKNOWN] = SDL_SCANCODE_BACKSPACE;
keymap[DIKI_INSERT - DIKI_UNKNOWN] = SDL_SCANCODE_INSERT;
keymap[DIKI_DELETE - DIKI_UNKNOWN] = SDL_SCANCODE_DELETE;
keymap[DIKI_HOME - DIKI_UNKNOWN] = SDL_SCANCODE_HOME;
keymap[DIKI_END - DIKI_UNKNOWN] = SDL_SCANCODE_END;
keymap[DIKI_PAGE_UP - DIKI_UNKNOWN] = SDL_SCANCODE_PAGEUP;
keymap[DIKI_PAGE_DOWN - DIKI_UNKNOWN] = SDL_SCANCODE_PAGEDOWN;
keymap[DIKI_CAPS_LOCK - DIKI_UNKNOWN] = SDL_SCANCODE_CAPSLOCK;
keymap[DIKI_NUM_LOCK - DIKI_UNKNOWN] = SDL_SCANCODE_NUMLOCKCLEAR;
keymap[DIKI_SCROLL_LOCK - DIKI_UNKNOWN] = SDL_SCANCODE_SCROLLLOCK;
keymap[DIKI_PRINT - DIKI_UNKNOWN] = SDL_SCANCODE_PRINTSCREEN;
keymap[DIKI_PAUSE - DIKI_UNKNOWN] = SDL_SCANCODE_PAUSE;
keymap[DIKI_KP_EQUAL - DIKI_UNKNOWN] = SDL_SCANCODE_KP_EQUALS;
keymap[DIKI_KP_DECIMAL - DIKI_UNKNOWN] = SDL_SCANCODE_KP_PERIOD;
keymap[DIKI_KP_0 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_0;
keymap[DIKI_KP_1 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_1;
keymap[DIKI_KP_2 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_2;
keymap[DIKI_KP_3 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_3;
keymap[DIKI_KP_4 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_4;
keymap[DIKI_KP_5 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_5;
keymap[DIKI_KP_6 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_6;
keymap[DIKI_KP_7 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_7;
keymap[DIKI_KP_8 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_8;
keymap[DIKI_KP_9 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_9;
keymap[DIKI_KP_DIV - DIKI_UNKNOWN] = SDL_SCANCODE_KP_DIVIDE;
keymap[DIKI_KP_MULT - DIKI_UNKNOWN] = SDL_SCANCODE_KP_MULTIPLY;
keymap[DIKI_KP_MINUS - DIKI_UNKNOWN] = SDL_SCANCODE_KP_MINUS;
keymap[DIKI_KP_PLUS - DIKI_UNKNOWN] = SDL_SCANCODE_KP_PLUS;
keymap[DIKI_KP_ENTER - DIKI_UNKNOWN] = SDL_SCANCODE_KP_ENTER;
keymap[DIKI_QUOTE_LEFT - DIKI_UNKNOWN] = SDL_SCANCODE_GRAVE; /* TLDE */
keymap[DIKI_MINUS_SIGN - DIKI_UNKNOWN] = SDL_SCANCODE_MINUS; /* AE11 */
keymap[DIKI_EQUALS_SIGN - DIKI_UNKNOWN] = SDL_SCANCODE_EQUALS; /* AE12 */
keymap[DIKI_BRACKET_LEFT - DIKI_UNKNOWN] = SDL_SCANCODE_RIGHTBRACKET; /* AD11 */
keymap[DIKI_BRACKET_RIGHT - DIKI_UNKNOWN] = SDL_SCANCODE_LEFTBRACKET; /* AD12 */
keymap[DIKI_BACKSLASH - DIKI_UNKNOWN] = SDL_SCANCODE_BACKSLASH; /* BKSL */
keymap[DIKI_SEMICOLON - DIKI_UNKNOWN] = SDL_SCANCODE_SEMICOLON; /* AC10 */
keymap[DIKI_QUOTE_RIGHT - DIKI_UNKNOWN] = SDL_SCANCODE_APOSTROPHE; /* AC11 */
keymap[DIKI_COMMA - DIKI_UNKNOWN] = SDL_SCANCODE_COMMA; /* AB08 */
keymap[DIKI_PERIOD - DIKI_UNKNOWN] = SDL_SCANCODE_PERIOD; /* AB09 */
keymap[DIKI_SLASH - DIKI_UNKNOWN] = SDL_SCANCODE_SLASH; /* AB10 */
keymap[DIKI_LESS_SIGN - DIKI_UNKNOWN] = SDL_SCANCODE_NONUSBACKSLASH; /* 103rd */
572
}
573
574
575
static SDL_Keysym *
DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt, SDL_Keysym * keysym)
576
{
577
SDL_DFB_DEVICEDATA(_this);
578
579
int kbd_idx = 0; /* Window events lag the device source KbdIndex(_this, evt->device_id); */
DFB_KeyboardData *kbd = &devdata->keyboard[kbd_idx];
580
581
582
583
584
585
keysym->scancode = SDL_SCANCODE_UNKNOWN;
if (kbd->map && evt->key_code >= kbd->map_adjust &&
evt->key_code < kbd->map_size + kbd->map_adjust)
keysym->scancode = kbd->map[evt->key_code - kbd->map_adjust];
586
587
if (keysym->scancode == SDL_SCANCODE_UNKNOWN ||
588
devdata->keyboard[kbd_idx].is_generic) {
589
590
if (evt->key_id - DIKI_UNKNOWN < SDL_arraysize(oskeymap))
keysym->scancode = oskeymap[evt->key_id - DIKI_UNKNOWN];
591
592
593
else
keysym->scancode = SDL_SCANCODE_UNKNOWN;
}
594
595
596
keysym->unicode =
(DFB_KEY_TYPE(evt->key_symbol) == DIKT_UNICODE) ? evt->key_symbol : 0;
597
598
if (keysym->unicode == 0 &&
(evt->key_symbol > 0 && evt->key_symbol < 255))
599
keysym->unicode = evt->key_symbol;
600
601
return keysym;
602
603
}
604
static SDL_Keysym *
605
DirectFB_TranslateKeyInputEvent(_THIS, DFBInputEvent * evt,
606
SDL_Keysym * keysym)
607
608
{
SDL_DFB_DEVICEDATA(_this);
609
610
int kbd_idx = KbdIndex(_this, evt->device_id);
DFB_KeyboardData *kbd = &devdata->keyboard[kbd_idx];
611
612
keysym->scancode = SDL_SCANCODE_UNKNOWN;
613
614
615
616
617
618
if (kbd->map && evt->key_code >= kbd->map_adjust &&
evt->key_code < kbd->map_size + kbd->map_adjust)
keysym->scancode = kbd->map[evt->key_code - kbd->map_adjust];
if (keysym->scancode == SDL_SCANCODE_UNKNOWN || devdata->keyboard[kbd_idx].is_generic) {
619
620
621
622
623
624
625
626
if (evt->key_id - DIKI_UNKNOWN < SDL_arraysize(oskeymap))
keysym->scancode = oskeymap[evt->key_id - DIKI_UNKNOWN];
else
keysym->scancode = SDL_SCANCODE_UNKNOWN;
}
keysym->unicode =
(DFB_KEY_TYPE(evt->key_symbol) == DIKT_UNICODE) ? evt->key_symbol : 0;
627
628
if (keysym->unicode == 0 &&
(evt->key_symbol > 0 && evt->key_symbol < 255))
629
630
631
632
keysym->unicode = evt->key_symbol;
return keysym;
}
633
634
static int
635
DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button)
636
{
637
switch (button) {
638
case DIBI_LEFT:
639
return 1;
640
case DIBI_MIDDLE:
641
return 2;
642
case DIBI_RIGHT:
643
return 3;
644
default:
645
return 0;
646
647
}
}
648
649
static DFBEnumerationResult
650
EnumKeyboards(DFBInputDeviceID device_id,
651
DFBInputDeviceDescription desc, void *callbackdata)
652
{
653
654
cb_data *cb = callbackdata;
DFB_DeviceData *devdata = cb->devdata;
655
#if USE_MULTI_API
656
SDL_Keyboard keyboard;
657
#endif
658
SDL_Keycode keymap[SDL_NUM_SCANCODES];
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
if (!cb->sys_kbd) {
if (cb->sys_ids) {
if (device_id >= 0x10)
return DFENUM_OK;
} else {
if (device_id < 0x10)
return DFENUM_OK;
}
} else {
if (device_id != DIDID_KEYBOARD)
return DFENUM_OK;
}
if ((desc.caps & DIDTF_KEYBOARD)) {
674
#if USE_MULTI_API
675
SDL_zero(keyboard);
676
SDL_AddKeyboard(&keyboard, devdata->num_keyboard);
677
#endif
678
679
devdata->keyboard[devdata->num_keyboard].id = device_id;
devdata->keyboard[devdata->num_keyboard].is_generic = 0;
680
if (!strncmp("X11", desc.name, 3))
681
682
683
684
685
686
687
688
689
{
devdata->keyboard[devdata->num_keyboard].map = xfree86_scancode_table2;
devdata->keyboard[devdata->num_keyboard].map_size = SDL_arraysize(xfree86_scancode_table2);
devdata->keyboard[devdata->num_keyboard].map_adjust = 8;
} else {
devdata->keyboard[devdata->num_keyboard].map = linux_scancode_table;
devdata->keyboard[devdata->num_keyboard].map_size = SDL_arraysize(linux_scancode_table);
devdata->keyboard[devdata->num_keyboard].map_adjust = 0;
}
690
691
692
SDL_DFB_LOG("Keyboard %d - %s\n", device_id, desc.name);
693
SDL_GetDefaultKeymap(keymap);
694
#if USE_MULTI_API
695
SDL_SetKeymap(devdata->num_keyboard, 0, keymap, SDL_NUM_SCANCODES);
696
697
698
#else
SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES);
#endif
699
700
devdata->num_keyboard++;
701
702
if (cb->sys_kbd)
return DFENUM_CANCEL;
703
704
}
return DFENUM_OK;
705
706
707
708
709
710
}
void
DirectFB_InitKeyboard(_THIS)
{
SDL_DFB_DEVICEDATA(_this);
711
712
cb_data cb;
713
714
715
DirectFB_InitOSKeymap(_this, &oskeymap[0], SDL_arraysize(oskeymap));
devdata->num_keyboard = 0;
716
717
cb.devdata = devdata;
718
if (devdata->use_linux_input) {
719
720
cb.sys_kbd = 0;
cb.sys_ids = 0;
721
SDL_DFB_CHECK(devdata->dfb->
722
EnumInputDevices(devdata->dfb, EnumKeyboards, &cb));
723
if (devdata->num_keyboard == 0) {
724
cb.sys_ids = 1;
725
726
SDL_DFB_CHECK(devdata->dfb->EnumInputDevices(devdata->dfb,
EnumKeyboards,
727
&cb));
728
}
729
730
} else {
cb.sys_kbd = 1;
731
SDL_DFB_CHECK(devdata->dfb->EnumInputDevices(devdata->dfb,
732
733
EnumKeyboards,
&cb));
734
}
735
736
}
737
738
739
void
DirectFB_QuitKeyboard(_THIS)
{
740
//SDL_DFB_DEVICEDATA(_this);
741
742
SDL_KeyboardQuit();
743
744
}