comparison src/video/directfb/SDL_DirectFB_events.c @ 2737:140a7edcf2bd

Date: Sun, 31 Aug 2008 17:53:59 +0200 From: Couriersud Subject: Re: Updated DirectFB driver for SDL1.3 attached is a patch which brings the directfb driver in line with current svn. In addition: * driver now is in line with the structure of the X11 driver. This adds a couple of files. * driver now supports relative mouse movements
author Sam Lantinga <slouken@libsdl.org>
date Sun, 31 Aug 2008 16:04:32 +0000
parents 204be4fc2726
children 99210400e8b9
comparison
equal deleted inserted replaced
2736:ae653575d4af 2737:140a7edcf2bd
45 DirectFB_SetContext(_THIS, SDL_WindowID id) 45 DirectFB_SetContext(_THIS, SDL_WindowID id)
46 { 46 {
47 #if (DIRECTFB_MAJOR_VERSION >= 1) 47 #if (DIRECTFB_MAJOR_VERSION >= 1)
48 /* FIXME: does not work on 1.0/1.2 with radeon driver 48 /* FIXME: does not work on 1.0/1.2 with radeon driver
49 * the approach did work with the matrox driver 49 * the approach did work with the matrox driver
50 * Perhaps make this depending on env var, e.g. SDLDIRECTFB_SWITCHCONTEXT_SUPPORTED 50 * This has simply no effect.
51 */ 51 */
52 52
53 if (getenv("SDLDIRECTFB_SWITCHCONTEXT_SUPPORTED") != NULL) { 53 SDL_Window *window = SDL_GetWindowFromID(id);
54 SDL_DFB_DEVICEDATA(_this); 54 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
55 SDL_Window *window = SDL_GetWindowFromID(id); 55 DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
56 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); 56 int ret;
57 DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata; 57
58 if (dispdata->vidID >= 0 && dispdata->vidIDinuse) { 58 if (dispdata->vidIDinuse)
59 IDirectFBDisplayLayer *lay = NULL; 59 SDL_DFB_CHECKERR(dispdata->vidlayer->
60 devdata->dfb->GetDisplayLayer(devdata->dfb, dispdata->vidID, 60 SwitchContext(dispdata->vidlayer, DFB_TRUE));
61 &lay); 61
62 if (lay) 62 error:
63 lay->SwitchContext(lay, DFB_TRUE); 63 return;
64 }
65 }
66 #endif 64 #endif
67 65
68 } 66 }
69 67
70 void 68 void
71 DirectFB_PumpEventsWindow(_THIS) 69 DirectFB_PumpEventsWindow(_THIS)
72 { 70 {
73 SDL_DFB_DEVICEDATA(_this); 71 SDL_DFB_DEVICEDATA(_this);
74 DFB_WindowData *p; 72 DFB_WindowData *p;
75 DFBWindowEvent evt; 73 DFBWindowEvent evt;
74 DFBInputEvent ievt;
75 SDL_WindowID grabbed_window;
76 char text[5]; 76 char text[5];
77 77
78 grabbed_window = -1;
79
78 for (p = devdata->firstwin; p != NULL; p = p->next) { 80 for (p = devdata->firstwin; p != NULL; p = p->next) {
81 SDL_Window *w = SDL_GetWindowFromID(p->id);
82
83 if (w->flags & SDL_WINDOW_INPUT_GRABBED) {
84 grabbed_window = p->id;
85 }
86
79 while (p->eventbuffer->GetEvent(p->eventbuffer, 87 while (p->eventbuffer->GetEvent(p->eventbuffer,
80 DFB_EVENT(&evt)) == DFB_OK) { 88 DFB_EVENT(&evt)) == DFB_OK) {
81 SDL_keysym keysym; 89 SDL_keysym keysym;
82 90
83 if (evt.clazz = DFEC_WINDOW) { 91 if (evt.clazz == DFEC_WINDOW) {
84 switch (evt.type) { 92 switch (evt.type) {
85 case DWET_BUTTONDOWN: 93 case DWET_BUTTONDOWN:
86 SDL_SendMouseButton(devdata->mouse, SDL_PRESSED, 94 SDL_SendMouseButton(devdata->mouse, SDL_PRESSED,
87 DirectFB_TranslateButton(evt.button)); 95 DirectFB_TranslateButton(evt.button));
88 break; 96 break;
89 case DWET_BUTTONUP: 97 case DWET_BUTTONUP:
90 SDL_SendMouseButton(devdata->mouse, SDL_RELEASED, 98 SDL_SendMouseButton(devdata->mouse, SDL_RELEASED,
91 DirectFB_TranslateButton(evt.button)); 99 DirectFB_TranslateButton(evt.button));
92 break; 100 break;
93 case DWET_MOTION: 101 case DWET_MOTION:
94 SDL_SendMouseMotion(devdata->mouse, 0, evt.cx, evt.cy); 102 if (!(w->flags & SDL_WINDOW_INPUT_GRABBED))
103 SDL_SendMouseMotion(devdata->mouse, 0, evt.cx, evt.cy,
104 0);
95 break; 105 break;
96 case DWET_KEYDOWN: 106 case DWET_KEYDOWN:
97 DirectFB_TranslateKey(_this, &evt, &keysym); 107 DirectFB_TranslateKey(_this, &evt, &keysym);
98 SDL_SendKeyboardKey(devdata->keyboard, SDL_PRESSED, 108 SDL_SendKeyboardKey(devdata->keyboard, SDL_PRESSED,
99 keysym.scancode); 109 keysym.scancode);
109 DirectFB_TranslateKey(_this, &evt, &keysym); 119 DirectFB_TranslateKey(_this, &evt, &keysym);
110 SDL_SendKeyboardKey(devdata->keyboard, SDL_RELEASED, 120 SDL_SendKeyboardKey(devdata->keyboard, SDL_RELEASED,
111 keysym.scancode); 121 keysym.scancode);
112 break; 122 break;
113 case DWET_POSITION_SIZE: 123 case DWET_POSITION_SIZE:
114 SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_MOVED, evt.x, 124 if (evt.x != w->x || evt.y != w->y)
115 evt.y); 125 SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_MOVED,
116 SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_RESIZED, evt.w, 126 evt.x, evt.y);
117 evt.h); 127 if (evt.w != w->w || evt.h != w->h)
128 SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_RESIZED,
129 evt.w, evt.h);
118 break; 130 break;
119 case DWET_POSITION: 131 case DWET_POSITION:
120 SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_MOVED, evt.x, 132 if (evt.x != w->x || evt.y != w->y)
121 evt.y); 133 SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_MOVED,
134 evt.x, evt.y);
122 break; 135 break;
123 case DWET_SIZE: 136 case DWET_SIZE:
124 SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_RESIZED, evt.w, 137 if (evt.w != w->w || evt.h != w->h)
125 evt.h); 138 SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_RESIZED,
139 evt.w, evt.h);
126 break; 140 break;
127 case DWET_CLOSE: 141 case DWET_CLOSE:
128 SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_CLOSE, 0, 0); 142 SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_CLOSE, 0, 0);
129 break; 143 break;
130 case DWET_GOTFOCUS: 144 case DWET_GOTFOCUS:
137 SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_FOCUS_LOST, 0, 151 SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_FOCUS_LOST, 0,
138 0); 152 0);
139 SDL_SetKeyboardFocus(devdata->keyboard, 0); 153 SDL_SetKeyboardFocus(devdata->keyboard, 0);
140 break; 154 break;
141 case DWET_ENTER: 155 case DWET_ENTER:
142 //SDL_DirectFB_ReshowCursor(_this, 0); 156 /* SDL_DirectFB_ReshowCursor(_this, 0); */
143 SDL_SetMouseFocus(devdata->mouse, p->id); 157 SDL_SetMouseFocus(devdata->mouse, p->id);
144 SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_ENTER, 0, 0); 158 SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_ENTER, 0, 0);
145 break; 159 break;
146 case DWET_LEAVE: 160 case DWET_LEAVE:
147 SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_LEAVE, 0, 0); 161 SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_LEAVE, 0, 0);
148 SDL_SetMouseFocus(devdata->mouse, 0); 162 SDL_SetMouseFocus(devdata->mouse, 0);
149 //SDL_DirectFB_ReshowCursor(_this, 1); 163 /* SDL_DirectFB_ReshowCursor(_this, 1); */
150 break; 164 break;
151 default: 165 default:
152 ; 166 ;
153 } 167 }
168 } else
169 printf("Event Clazz %d\n", evt.clazz);
170
171 }
172 }
173
174 /* Now get relative events in case we need them */
175 while (devdata->events->GetEvent(devdata->events,
176 DFB_EVENT(&ievt)) == DFB_OK) {
177 if (grabbed_window >= 0) {
178 switch (ievt.type) {
179 case DIET_AXISMOTION:
180 if (ievt.flags & DIEF_AXISREL) {
181 if (ievt.axis == DIAI_X)
182 SDL_SendMouseMotion(devdata->mouse, 1, ievt.axisrel,
183 0, 0);
184 else if (ievt.axis == DIAI_Y)
185 SDL_SendMouseMotion(devdata->mouse, 1, 0,
186 ievt.axisrel, 0);
187 }
188 break;
189 default:
190 ;
154 } 191 }
155 } 192 }
156 } 193 }
157 } 194 }
158 195
229 keymap[DIKI_ALT_R - DIKI_UNKNOWN] = SDL_SCANCODE_RALT; 266 keymap[DIKI_ALT_R - DIKI_UNKNOWN] = SDL_SCANCODE_RALT;
230 keymap[DIKI_META_L - DIKI_UNKNOWN] = SDL_SCANCODE_LGUI; 267 keymap[DIKI_META_L - DIKI_UNKNOWN] = SDL_SCANCODE_LGUI;
231 keymap[DIKI_META_R - DIKI_UNKNOWN] = SDL_SCANCODE_RGUI; 268 keymap[DIKI_META_R - DIKI_UNKNOWN] = SDL_SCANCODE_RGUI;
232 keymap[DIKI_SUPER_L - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION; 269 keymap[DIKI_SUPER_L - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
233 keymap[DIKI_SUPER_R - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION; 270 keymap[DIKI_SUPER_R - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
234 //FIXME:Do we read hyper keys ? 271 /* FIXME:Do we read hyper keys ?
235 //keymap[DIKI_HYPER_L - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION; 272 * keymap[DIKI_HYPER_L - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
236 //keymap[DIKI_HYPER_R - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION; 273 * keymap[DIKI_HYPER_R - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
274 */
237 keymap[DIKI_TAB - DIKI_UNKNOWN] = SDL_SCANCODE_TAB; 275 keymap[DIKI_TAB - DIKI_UNKNOWN] = SDL_SCANCODE_TAB;
238 keymap[DIKI_ENTER - DIKI_UNKNOWN] = SDL_SCANCODE_RETURN; 276 keymap[DIKI_ENTER - DIKI_UNKNOWN] = SDL_SCANCODE_RETURN;
239 keymap[DIKI_SPACE - DIKI_UNKNOWN] = SDL_SCANCODE_SPACE; 277 keymap[DIKI_SPACE - DIKI_UNKNOWN] = SDL_SCANCODE_SPACE;
240 keymap[DIKI_BACKSPACE - DIKI_UNKNOWN] = SDL_SCANCODE_BACKSPACE; 278 keymap[DIKI_BACKSPACE - DIKI_UNKNOWN] = SDL_SCANCODE_BACKSPACE;
241 keymap[DIKI_INSERT - DIKI_UNKNOWN] = SDL_SCANCODE_INSERT; 279 keymap[DIKI_INSERT - DIKI_UNKNOWN] = SDL_SCANCODE_INSERT;
288 { 326 {
289 SDL_DFB_DEVICEDATA(_this); 327 SDL_DFB_DEVICEDATA(_this);
290 328
291 if (evt->key_code >= 0 329 if (evt->key_code >= 0
292 && evt->key_code < SDL_arraysize(linux_scancode_table)) 330 && evt->key_code < SDL_arraysize(linux_scancode_table))
293 keysym->scancode = linux_scancode_table[evt->key_code]; // key_id; 331 keysym->scancode = linux_scancode_table[evt->key_code];
294 else 332 else
295 keysym->scancode = SDL_SCANCODE_UNKNOWN; 333 keysym->scancode = SDL_SCANCODE_UNKNOWN;
296 334
297 if (keysym->scancode == SDL_SCANCODE_UNKNOWN || devdata->kbdgeneric) { 335 if (keysym->scancode == SDL_SCANCODE_UNKNOWN || devdata->kbdgeneric) {
298 if (evt->key_id - DIKI_UNKNOWN < SDL_arraysize(keymap)) 336 if (evt->key_id - DIKI_UNKNOWN < SDL_arraysize(keymap))
329 input_device_cb(DFBInputDeviceID device_id, DFBInputDeviceDescription desc, 367 input_device_cb(DFBInputDeviceID device_id, DFBInputDeviceDescription desc,
330 void *callbackdata) 368 void *callbackdata)
331 { 369 {
332 DFB_DeviceData *devdata = callbackdata; 370 DFB_DeviceData *devdata = callbackdata;
333 SDL_Keyboard keyboard; 371 SDL_Keyboard keyboard;
334 SDL_scancode scancode;
335 SDLKey keymap[SDL_NUM_SCANCODES]; 372 SDLKey keymap[SDL_NUM_SCANCODES];
336 373
337 if ((desc.caps & DIDTF_KEYBOARD) && device_id == DIDID_KEYBOARD) { 374 if ((desc.caps & DIDTF_KEYBOARD) && device_id == DIDID_KEYBOARD) {
338 SDL_zero(keyboard); 375 SDL_zero(keyboard);
339 devdata->keyboard = SDL_AddKeyboard(&keyboard, -1); 376 devdata->keyboard = SDL_AddKeyboard(&keyboard, -1);
358 395
359 SDL_DFB_CHECK(devdata->dfb-> 396 SDL_DFB_CHECK(devdata->dfb->
360 EnumInputDevices(devdata->dfb, input_device_cb, devdata)); 397 EnumInputDevices(devdata->dfb, input_device_cb, devdata));
361 } 398 }
362 399
400 void
401 DirectFB_QuitKeyboard(_THIS)
402 {
403 SDL_DFB_DEVICEDATA(_this);
404 int ret;
405
406 SDL_DelKeyboard(devdata->keyboard);
407
408 }
409
363 #if 0 410 #if 0
364 /* FIXME: Remove once determined this is not needed in fullscreen mode */ 411 /* FIXME: Remove once determined this is not needed in fullscreen mode */
365 void 412 void
366 DirectFB_PumpEvents(_THIS) 413 DirectFB_PumpEvents(_THIS)
367 { 414 {
381 mod = 0; 428 mod = 0;
382 429
383 switch (evt.type) { 430 switch (evt.type) {
384 case DIET_BUTTONPRESS: 431 case DIET_BUTTONPRESS:
385 posted += SDL_PrivateMouseButton(SDL_PRESSED, 432 posted += SDL_PrivateMouseButton(SDL_PRESSED,
386 DirectFB_TranslateButton 433 DirectFB_TranslateButton(evt.
387 (evt.button), 0, 0); 434 button),
435 0, 0);
388 break; 436 break;
389 case DIET_BUTTONRELEASE: 437 case DIET_BUTTONRELEASE:
390 posted += SDL_PrivateMouseButton(SDL_RELEASED, 438 posted += SDL_PrivateMouseButton(SDL_RELEASED,
391 DirectFB_TranslateButton 439 DirectFB_TranslateButton(evt.
392 (evt.button), 0, 0); 440 button),
441 0, 0);
393 break; 442 break;
394 case DIET_KEYPRESS: 443 case DIET_KEYPRESS:
395 posted += SDL_PrivateKeyboard(SDL_PRESSED, 444 posted += SDL_PrivateKeyboard(SDL_PRESSED,
396 DirectFB_TranslateKey 445 DirectFB_TranslateKey(evt.
397 (evt.key_id, evt.key_symbol, 446 key_id,
398 mod, &keysym)); 447 evt.
448 key_symbol,
449 mod,
450 &keysym));
399 break; 451 break;
400 case DIET_KEYRELEASE: 452 case DIET_KEYRELEASE:
401 posted += SDL_PrivateKeyboard(SDL_RELEASED, 453 posted += SDL_PrivateKeyboard(SDL_RELEASED,
402 DirectFB_TranslateKey 454 DirectFB_TranslateKey(evt.
403 (evt.key_id, evt.key_symbol, 455 key_id,
404 mod, &keysym)); 456 evt.
457 key_symbol,
458 mod,
459 &keysym));
405 break; 460 break;
406 case DIET_AXISMOTION: 461 case DIET_AXISMOTION:
407 if (evt.flags & DIEF_AXISREL) { 462 if (evt.flags & DIEF_AXISREL) {
408 if (evt.axis == DIAI_X) 463 if (evt.axis == DIAI_X)
409 posted += 464 posted +=