Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
703 lines (633 loc) · 27.4 KB

SDL_DirectFB_events.c

File metadata and controls

703 lines (633 loc) · 27.4 KB
 
Feb 1, 2006
Feb 1, 2006
2
SDL - Simple DirectMedia Layer
Dec 8, 2008
Dec 8, 2008
3
Copyright (C) 1997-2009 Sam Lantinga
Feb 1, 2006
Feb 1, 2006
5
6
7
8
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
Feb 1, 2006
Feb 1, 2006
10
11
12
13
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
Feb 1, 2006
Feb 1, 2006
15
16
17
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Feb 1, 2006
Feb 1, 2006
19
20
Sam Lantinga
slouken@libsdl.org
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
23
24
25
26
27
/* Handle the event stream, converting DirectFB input events into SDL events */
#include <directfb.h>
Feb 16, 2006
Feb 16, 2006
28
29
30
#include "../SDL_sysvideo.h"
#include "../../events/SDL_sysevents.h"
#include "../../events/SDL_events_c.h"
Aug 26, 2008
Aug 26, 2008
31
32
#include "../../events/SDL_keyboard_c.h"
#include "../../events/scancodes_linux.h"
33
34
35
#include "SDL_DirectFB_events.h"
/* The translation tables from a DirectFB keycode to a SDL keysym */
Dec 8, 2008
Dec 8, 2008
36
37
static SDLKey oskeymap[256];
static int sys_ids;
Aug 26, 2008
Aug 26, 2008
39
static SDL_keysym *DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt,
Aug 11, 2007
Aug 11, 2007
40
SDL_keysym * keysym);
Dec 8, 2008
Dec 8, 2008
41
42
43
static SDL_keysym *DirectFB_TranslateKeyInputEvent(_THIS, int index,
DFBInputEvent * evt,
SDL_keysym * keysym);
Dec 8, 2008
Dec 8, 2008
45
static void DirectFB_InitOSKeymap(_THIS, SDLKey * keypmap, int numkeys);
Aug 11, 2007
Aug 11, 2007
46
static int DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button);
Aug 26, 2008
Aug 26, 2008
48
49
50
51
52
53
static void
DirectFB_SetContext(_THIS, SDL_WindowID id)
{
#if (DIRECTFB_MAJOR_VERSION >= 1)
/* FIXME: does not work on 1.0/1.2 with radeon driver
* the approach did work with the matrox driver
Aug 31, 2008
Aug 31, 2008
54
* This has simply no effect.
Aug 26, 2008
Aug 26, 2008
55
56
*/
Aug 31, 2008
Aug 31, 2008
57
58
59
60
61
62
63
64
65
66
67
SDL_Window *window = SDL_GetWindowFromID(id);
SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
int ret;
if (dispdata->vidIDinuse)
SDL_DFB_CHECKERR(dispdata->vidlayer->
SwitchContext(dispdata->vidlayer, DFB_TRUE));
error:
return;
Aug 26, 2008
Aug 26, 2008
68
69
70
71
#endif
}
Dec 8, 2008
Dec 8, 2008
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
static void
FocusAllMice(_THIS, SDL_WindowID id)
{
SDL_DFB_DEVICEDATA(_this);
int index;
for (index = 0; index < devdata->num_mice; index++)
SDL_SetMouseFocus(devdata->mouse_id[index], id);
}
static void
FocusAllKeyboards(_THIS, SDL_WindowID id)
{
SDL_DFB_DEVICEDATA(_this);
int index;
for (index = 0; index < devdata->num_keyboard; index++)
SDL_SetKeyboardFocus(index, id);
}
static void
MotionAllMice(_THIS, int x, int y)
{
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);
}
}
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;
}
Jul 10, 2006
Jul 10, 2006
120
void
Aug 11, 2007
Aug 11, 2007
121
DirectFB_PumpEventsWindow(_THIS)
Aug 11, 2007
Aug 11, 2007
123
124
SDL_DFB_DEVICEDATA(_this);
DFB_WindowData *p;
Aug 31, 2008
Aug 31, 2008
125
DFBInputEvent ievt;
Dec 8, 2008
Dec 8, 2008
126
Sint32 /* SDL_WindowID */ grabbed_window;
Aug 26, 2008
Aug 26, 2008
127
char text[5];
Dec 8, 2008
Dec 8, 2008
128
int kbd_idx;
Aug 31, 2008
Aug 31, 2008
130
131
grabbed_window = -1;
Aug 11, 2007
Aug 11, 2007
132
for (p = devdata->firstwin; p != NULL; p = p->next) {
Dec 8, 2008
Dec 8, 2008
133
DFBWindowEvent evt;
Aug 31, 2008
Aug 31, 2008
134
135
136
137
138
139
SDL_Window *w = SDL_GetWindowFromID(p->id);
if (w->flags & SDL_WINDOW_INPUT_GRABBED) {
grabbed_window = p->id;
}
Aug 11, 2007
Aug 11, 2007
140
141
142
while (p->eventbuffer->GetEvent(p->eventbuffer,
DFB_EVENT(&evt)) == DFB_OK) {
SDL_keysym keysym;
Aug 31, 2008
Aug 31, 2008
144
if (evt.clazz == DFEC_WINDOW) {
Aug 11, 2007
Aug 11, 2007
145
146
switch (evt.type) {
case DWET_BUTTONDOWN:
Jan 4, 2009
Jan 4, 2009
147
if (!devdata->use_linux_input) {
Dec 8, 2008
Dec 8, 2008
148
149
150
151
152
153
154
155
SDL_SendMouseMotion(devdata->mouse_id[0], 0, evt.cx,
evt.cy, 0);
SDL_SendMouseButton(devdata->mouse_id[0], SDL_PRESSED,
DirectFB_TranslateButton(evt.
button));
} else {
MotionAllMice(_this, evt.x, evt.y);
}
Aug 11, 2007
Aug 11, 2007
156
157
break;
case DWET_BUTTONUP:
Jan 4, 2009
Jan 4, 2009
158
if (!devdata->use_linux_input) {
Dec 8, 2008
Dec 8, 2008
159
160
161
162
163
164
165
166
167
SDL_SendMouseMotion(devdata->mouse_id[0], 0, evt.cx,
evt.cy, 0);
SDL_SendMouseButton(devdata->mouse_id[0],
SDL_RELEASED,
DirectFB_TranslateButton(evt.
button));
} else {
MotionAllMice(_this, evt.x, evt.y);
}
Aug 11, 2007
Aug 11, 2007
168
169
break;
case DWET_MOTION:
Jan 4, 2009
Jan 4, 2009
170
if (!devdata->use_linux_input) {
Dec 8, 2008
Dec 8, 2008
171
172
173
174
175
176
177
178
179
180
181
182
183
if (!(w->flags & SDL_WINDOW_INPUT_GRABBED))
SDL_SendMouseMotion(devdata->mouse_id[0], 0,
evt.cx, evt.cy, 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;
}
}
Aug 11, 2007
Aug 11, 2007
184
185
break;
case DWET_KEYDOWN:
Jan 4, 2009
Jan 4, 2009
186
if (!devdata->use_linux_input) {
Dec 8, 2008
Dec 8, 2008
187
188
189
190
191
192
193
194
DirectFB_TranslateKey(_this, &evt, &keysym);
SDL_SendKeyboardKey(0, SDL_PRESSED, keysym.scancode);
if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
SDL_memcpy(text, &keysym.unicode, 4);
text[4] = 0;
if (*text) {
SDL_SendKeyboardText(0, text);
}
Aug 26, 2008
Aug 26, 2008
195
196
}
}
Aug 11, 2007
Aug 11, 2007
197
198
break;
case DWET_KEYUP:
Jan 4, 2009
Jan 4, 2009
199
if (!devdata->use_linux_input) {
Dec 8, 2008
Dec 8, 2008
200
201
202
DirectFB_TranslateKey(_this, &evt, &keysym);
SDL_SendKeyboardKey(0, SDL_RELEASED, keysym.scancode);
}
Aug 11, 2007
Aug 11, 2007
203
204
break;
case DWET_POSITION_SIZE:
Aug 31, 2008
Aug 31, 2008
205
206
207
208
209
210
if (evt.x != w->x || evt.y != w->y)
SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_MOVED,
evt.x, evt.y);
if (evt.w != w->w || evt.h != w->h)
SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_RESIZED,
evt.w, evt.h);
Aug 11, 2007
Aug 11, 2007
211
212
break;
case DWET_POSITION:
Aug 31, 2008
Aug 31, 2008
213
214
215
if (evt.x != w->x || evt.y != w->y)
SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_MOVED,
evt.x, evt.y);
Aug 11, 2007
Aug 11, 2007
216
217
break;
case DWET_SIZE:
Aug 31, 2008
Aug 31, 2008
218
219
220
if (evt.w != w->w || evt.h != w->h)
SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_RESIZED,
evt.w, evt.h);
Aug 11, 2007
Aug 11, 2007
221
222
223
224
225
break;
case DWET_CLOSE:
SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_CLOSE, 0, 0);
break;
case DWET_GOTFOCUS:
Aug 26, 2008
Aug 26, 2008
226
DirectFB_SetContext(_this, p->id);
Dec 8, 2008
Dec 8, 2008
227
FocusAllKeyboards(_this, p->id);
Aug 26, 2008
Aug 26, 2008
228
229
SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_FOCUS_GAINED,
0, 0);
Aug 11, 2007
Aug 11, 2007
230
231
break;
case DWET_LOSTFOCUS:
Aug 26, 2008
Aug 26, 2008
232
233
SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_FOCUS_LOST, 0,
0);
Dec 8, 2008
Dec 8, 2008
234
FocusAllKeyboards(_this, 0);
Aug 11, 2007
Aug 11, 2007
235
236
break;
case DWET_ENTER:
Aug 31, 2008
Aug 31, 2008
237
/* SDL_DirectFB_ReshowCursor(_this, 0); */
Dec 8, 2008
Dec 8, 2008
238
239
FocusAllMice(_this, p->id);
MotionAllMice(_this, evt.x, evt.y);
Aug 26, 2008
Aug 26, 2008
240
SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_ENTER, 0, 0);
Aug 11, 2007
Aug 11, 2007
241
242
break;
case DWET_LEAVE:
Aug 26, 2008
Aug 26, 2008
243
SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_LEAVE, 0, 0);
Dec 8, 2008
Dec 8, 2008
244
FocusAllMice(_this, 0);
Aug 31, 2008
Aug 31, 2008
245
/* SDL_DirectFB_ReshowCursor(_this, 1); */
Aug 11, 2007
Aug 11, 2007
246
247
248
249
break;
default:
;
}
Aug 31, 2008
Aug 31, 2008
250
251
252
253
254
255
256
257
258
} else
printf("Event Clazz %d\n", evt.clazz);
}
}
/* Now get relative events in case we need them */
while (devdata->events->GetEvent(devdata->events,
DFB_EVENT(&ievt)) == DFB_OK) {
Dec 8, 2008
Dec 8, 2008
259
260
261
262
SDL_keysym keysym;
switch (ievt.type) {
case DIET_AXISMOTION:
Jan 4, 2009
Jan 4, 2009
263
if (!devdata->use_linux_input) {
Dec 8, 2008
Dec 8, 2008
264
265
266
267
268
269
270
271
272
273
274
275
if ((grabbed_window >= 0) && (ievt.flags & DIEF_AXISREL)) {
printf("rel devid %d\n", ievt.device_id);
if (ievt.axis == DIAI_X)
SDL_SendMouseMotion(ievt.device_id, 1, ievt.axisrel,
0, 0);
else if (ievt.axis == DIAI_Y)
SDL_SendMouseMotion(ievt.device_id, 1, 0,
ievt.axisrel, 0);
}
}
break;
}
Jan 4, 2009
Jan 4, 2009
276
if (devdata->use_linux_input) {
Dec 8, 2008
Dec 8, 2008
277
278
279
IDirectFBInputDevice *idev;
static int last_x, last_y;
Aug 31, 2008
Aug 31, 2008
280
281
switch (ievt.type) {
case DIET_AXISMOTION:
Dec 8, 2008
Dec 8, 2008
282
if (ievt.flags & DIEF_AXISABS) {
Aug 31, 2008
Aug 31, 2008
283
if (ievt.axis == DIAI_X)
Dec 8, 2008
Dec 8, 2008
284
285
286
287
288
289
290
291
292
293
last_x = ievt.axisabs;
else if (ievt.axis == DIAI_Y)
last_y = ievt.axisabs;
if (!(ievt.flags & DIEF_FOLLOW))
SDL_SendMouseMotion(ievt.device_id, 0, last_x, last_y,
0);
} else if (ievt.flags & DIEF_AXISREL) {
//printf("rel %d %d\n", ievt.device_id, ievt.axisrel);
if (ievt.axis == DIAI_X)
SDL_SendMouseMotion(ievt.device_id, 1, ievt.axisrel,
Aug 31, 2008
Aug 31, 2008
294
295
0, 0);
else if (ievt.axis == DIAI_Y)
Dec 8, 2008
Dec 8, 2008
296
SDL_SendMouseMotion(ievt.device_id, 1, 0,
Aug 31, 2008
Aug 31, 2008
297
298
299
ievt.axisrel, 0);
}
break;
Dec 8, 2008
Dec 8, 2008
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
case DIET_KEYPRESS:
kbd_idx = KbdIndex(_this, ievt.device_id);
DirectFB_TranslateKeyInputEvent(_this, kbd_idx, &ievt,
&keysym);
SDL_SendKeyboardKey(kbd_idx, SDL_PRESSED, keysym.scancode);
if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
SDL_memcpy(text, &keysym.unicode, 4);
text[4] = 0;
if (*text) {
SDL_SendKeyboardText(kbd_idx, text);
}
}
break;
case DIET_KEYRELEASE:
kbd_idx = KbdIndex(_this, ievt.device_id);
DirectFB_TranslateKeyInputEvent(_this, kbd_idx, &ievt,
&keysym);
SDL_SendKeyboardKey(kbd_idx, SDL_RELEASED, keysym.scancode);
break;
case DIET_BUTTONPRESS:
if (ievt.buttons & DIBM_LEFT)
SDL_SendMouseButton(ievt.device_id, SDL_PRESSED, 1);
if (ievt.buttons & DIBM_MIDDLE)
SDL_SendMouseButton(ievt.device_id, SDL_PRESSED, 2);
if (ievt.buttons & DIBM_RIGHT)
SDL_SendMouseButton(ievt.device_id, SDL_PRESSED, 3);
break;
case DIET_BUTTONRELEASE:
if (!(ievt.buttons & DIBM_LEFT))
SDL_SendMouseButton(ievt.device_id, SDL_RELEASED, 1);
if (!(ievt.buttons & DIBM_MIDDLE))
SDL_SendMouseButton(ievt.device_id, SDL_RELEASED, 2);
if (!(ievt.buttons & DIBM_RIGHT))
SDL_SendMouseButton(ievt.device_id, SDL_RELEASED, 3);
break;
335
336
337
338
339
}
}
}
}
Jul 10, 2006
Jul 10, 2006
340
void
Dec 8, 2008
Dec 8, 2008
341
DirectFB_InitOSKeymap(_THIS, SDLKey * keymap, int numkeys)
Jul 10, 2006
Jul 10, 2006
343
344
345
int i;
/* Initialize the DirectFB key translation table */
Dec 8, 2008
Dec 8, 2008
346
for (i = 0; i < numkeys; ++i)
Aug 26, 2008
Aug 26, 2008
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
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;
Aug 31, 2008
Aug 31, 2008
415
416
417
418
/* FIXME:Do we read hyper keys ?
* keymap[DIKI_HYPER_L - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
* keymap[DIKI_HYPER_R - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
*/
Aug 26, 2008
Aug 26, 2008
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
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 */
Aug 11, 2007
Aug 11, 2007
466
}
Jul 10, 2006
Jul 10, 2006
468
static SDL_keysym *
Aug 26, 2008
Aug 26, 2008
469
DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt, SDL_keysym * keysym)
Aug 26, 2008
Aug 26, 2008
471
SDL_DFB_DEVICEDATA(_this);
Aug 11, 2007
Aug 11, 2007
472
Aug 26, 2008
Aug 26, 2008
473
474
if (evt->key_code >= 0
&& evt->key_code < SDL_arraysize(linux_scancode_table))
Aug 31, 2008
Aug 31, 2008
475
keysym->scancode = linux_scancode_table[evt->key_code];
Aug 26, 2008
Aug 26, 2008
476
477
else
keysym->scancode = SDL_SCANCODE_UNKNOWN;
Aug 11, 2007
Aug 11, 2007
478
Dec 8, 2008
Dec 8, 2008
479
480
481
482
if (keysym->scancode == SDL_SCANCODE_UNKNOWN
|| devdata->keyboard[0].is_generic) {
if (evt->key_id - DIKI_UNKNOWN < SDL_arraysize(oskeymap))
keysym->scancode = oskeymap[evt->key_id - DIKI_UNKNOWN];
Aug 26, 2008
Aug 26, 2008
483
484
485
else
keysym->scancode = SDL_SCANCODE_UNKNOWN;
}
Jul 10, 2006
Jul 10, 2006
486
Aug 26, 2008
Aug 26, 2008
487
488
489
490
491
keysym->unicode =
(DFB_KEY_TYPE(evt->key_symbol) == DIKT_UNICODE) ? evt->key_symbol : 0;
if (keysym->unicode == 0
&& (evt->key_symbol > 0 && evt->key_symbol < 255))
keysym->unicode = evt->key_symbol;
Jul 10, 2006
Jul 10, 2006
492
493
return keysym;
Dec 8, 2008
Dec 8, 2008
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
521
522
523
static SDL_keysym *
DirectFB_TranslateKeyInputEvent(_THIS, int index, DFBInputEvent * evt,
SDL_keysym * keysym)
{
SDL_DFB_DEVICEDATA(_this);
if (evt->key_code >= 0
&& evt->key_code < SDL_arraysize(linux_scancode_table))
keysym->scancode = linux_scancode_table[evt->key_code];
else
keysym->scancode = SDL_SCANCODE_UNKNOWN;
if (keysym->scancode == SDL_SCANCODE_UNKNOWN
|| devdata->keyboard[index].is_generic) {
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;
if (keysym->unicode == 0
&& (evt->key_symbol > 0 && evt->key_symbol < 255))
keysym->unicode = evt->key_symbol;
return keysym;
}
Jul 10, 2006
Jul 10, 2006
524
static int
Aug 11, 2007
Aug 11, 2007
525
DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button)
Aug 11, 2007
Aug 11, 2007
527
switch (button) {
528
case DIBI_LEFT:
Jul 10, 2006
Jul 10, 2006
529
return 1;
530
case DIBI_MIDDLE:
Jul 10, 2006
Jul 10, 2006
531
return 2;
532
case DIBI_RIGHT:
Jul 10, 2006
Jul 10, 2006
533
return 3;
Jul 10, 2006
Jul 10, 2006
535
return 0;
Jul 10, 2006
Jul 10, 2006
538
Aug 26, 2008
Aug 26, 2008
539
540
541
542
543
544
545
546
547
548
static DFBEnumerationResult
input_device_cb(DFBInputDeviceID device_id, DFBInputDeviceDescription desc,
void *callbackdata)
{
DFB_DeviceData *devdata = callbackdata;
SDL_Keyboard keyboard;
SDLKey keymap[SDL_NUM_SCANCODES];
if ((desc.caps & DIDTF_KEYBOARD) && device_id == DIDID_KEYBOARD) {
SDL_zero(keyboard);
Dec 8, 2008
Dec 8, 2008
549
550
551
SDL_AddKeyboard(&keyboard, 0);
devdata->keyboard[0].id = device_id;
devdata->keyboard[0].is_generic = 0;
Aug 26, 2008
Aug 26, 2008
552
if (!strncmp("X11", desc.name, 3))
Dec 8, 2008
Dec 8, 2008
553
devdata->keyboard[0].is_generic = 1;
Aug 26, 2008
Aug 26, 2008
554
555
SDL_GetDefaultKeymap(keymap);
Dec 8, 2008
Dec 8, 2008
556
557
558
559
SDL_SetKeymap(0, 0, keymap, SDL_NUM_SCANCODES);
devdata->num_keyboard++;
return DFENUM_CANCEL;
Aug 26, 2008
Aug 26, 2008
560
}
Dec 8, 2008
Dec 8, 2008
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
return DFENUM_OK;
}
static DFBEnumerationResult
EnumKeyboards(DFBInputDeviceID device_id, DFBInputDeviceDescription desc,
void *callbackdata)
{
DFB_DeviceData *devdata = callbackdata;
SDL_Keyboard keyboard;
SDLKey keymap[SDL_NUM_SCANCODES];
if (sys_ids) {
if (device_id >= 0x10)
return DFENUM_OK;
} else {
if (device_id < 0x10)
return DFENUM_OK;
}
if ((desc.caps & DIDTF_KEYBOARD)) {
SDL_zero(keyboard);
SDL_AddKeyboard(&keyboard, devdata->num_keyboard);
devdata->keyboard[devdata->num_keyboard].id = device_id;
devdata->keyboard[devdata->num_keyboard].is_generic = 0;
if (!strncmp("X11", desc.name, 3))
devdata->keyboard[devdata->num_keyboard].is_generic = 1;
SDL_GetDefaultKeymap(keymap);
SDL_SetKeymap(devdata->num_keyboard, 0, keymap, SDL_NUM_SCANCODES);
devdata->num_keyboard++;
}
return DFENUM_OK;
Aug 26, 2008
Aug 26, 2008
592
593
594
595
596
597
598
599
}
void
DirectFB_InitKeyboard(_THIS)
{
SDL_DFB_DEVICEDATA(_this);
int ret;
Dec 8, 2008
Dec 8, 2008
600
601
602
DirectFB_InitOSKeymap(_this, &oskeymap[0], SDL_arraysize(oskeymap));
devdata->num_keyboard = 0;
Jan 4, 2009
Jan 4, 2009
603
if (devdata->use_linux_input) {
Dec 8, 2008
Dec 8, 2008
604
605
606
607
608
609
610
611
612
613
614
615
616
617
sys_ids = 0;
SDL_DFB_CHECK(devdata->dfb->
EnumInputDevices(devdata->dfb, EnumKeyboards, devdata));
if (devdata->num_keyboard == 0) {
sys_ids = 1;
SDL_DFB_CHECK(devdata->dfb->
EnumInputDevices(devdata->dfb, EnumKeyboards,
devdata));
}
} else {
SDL_DFB_CHECK(devdata->dfb->
EnumInputDevices(devdata->dfb, input_device_cb,
devdata));
}
Aug 26, 2008
Aug 26, 2008
618
619
}
Aug 31, 2008
Aug 31, 2008
620
621
622
623
624
625
void
DirectFB_QuitKeyboard(_THIS)
{
SDL_DFB_DEVICEDATA(_this);
int ret;
Dec 8, 2008
Dec 8, 2008
626
SDL_KeyboardQuit();
Aug 31, 2008
Aug 31, 2008
627
628
629
}
Aug 11, 2007
Aug 11, 2007
630
#if 0
Aug 26, 2008
Aug 26, 2008
631
/* FIXME: Remove once determined this is not needed in fullscreen mode */
Aug 11, 2007
Aug 11, 2007
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
void
DirectFB_PumpEvents(_THIS)
{
SDL_DFB_DEVICEDATA(_this);
DFBInputEvent evt;
static last_x = 0, last_y = 0;
while (devdata->eventbuffer->GetEvent(devdata->eventbuffer,
DFB_EVENT(&evt)) == DFB_OK) {
SDL_keysym keysym;
DFBInputDeviceModifierMask mod;
if (evt.clazz = DFEC_INPUT) {
if (evt.flags & DIEF_MODIFIERS)
mod = evt.modifiers;
else
mod = 0;
switch (evt.type) {
case DIET_BUTTONPRESS:
posted += SDL_PrivateMouseButton(SDL_PRESSED,
Aug 31, 2008
Aug 31, 2008
653
654
655
DirectFB_TranslateButton(evt.
button),
0, 0);
Aug 11, 2007
Aug 11, 2007
656
657
658
break;
case DIET_BUTTONRELEASE:
posted += SDL_PrivateMouseButton(SDL_RELEASED,
Aug 31, 2008
Aug 31, 2008
659
660
661
DirectFB_TranslateButton(evt.
button),
0, 0);
Aug 11, 2007
Aug 11, 2007
662
663
664
break;
case DIET_KEYPRESS:
posted += SDL_PrivateKeyboard(SDL_PRESSED,
Aug 31, 2008
Aug 31, 2008
665
666
667
668
669
670
DirectFB_TranslateKey(evt.
key_id,
evt.
key_symbol,
mod,
&keysym));
Aug 11, 2007
Aug 11, 2007
671
672
673
break;
case DIET_KEYRELEASE:
posted += SDL_PrivateKeyboard(SDL_RELEASED,
Aug 31, 2008
Aug 31, 2008
674
675
676
677
678
679
DirectFB_TranslateKey(evt.
key_id,
evt.
key_symbol,
mod,
&keysym));
Aug 11, 2007
Aug 11, 2007
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
break;
case DIET_AXISMOTION:
if (evt.flags & DIEF_AXISREL) {
if (evt.axis == DIAI_X)
posted +=
SDL_PrivateMouseMotion(0, 1, evt.axisrel, 0);
else if (evt.axis == DIAI_Y)
posted +=
SDL_PrivateMouseMotion(0, 1, 0, evt.axisrel);
} else if (evt.flags & DIEF_AXISABS) {
if (evt.axis == DIAI_X)
last_x = evt.axisabs;
else if (evt.axis == DIAI_Y)
last_y = evt.axisabs;
posted += SDL_PrivateMouseMotion(0, 0, last_x, last_y);
}
break;
default:
;
}
}
}
}
#endif