Mercurial > sdl-ios-xcode
comparison src/video/directfb/SDL_DirectFB_events.c @ 3023:d72a0dd80e8b
DirectFB cleanups & simple window manager
- use SDL_getenv, not getenv ...
- no more support for 0.9.25 - not even mentioned any longer on directfb.org
- fix fullscreen issues
- add a simple window manager unless the directfb team comes up with a working wm.
The driver has support for a very, very basic window manager you may
want to use when runnning with "wm=default". Use
export SDL_DIRECTFB_WM=1
to enable basic window borders including icon support. In order to have the window title rendered,
you need to have the following font installed:
/usr/share/fonts/truetype/freefont/FreeSans.ttf
author | Couriersud <couriersud@arcor.de> |
---|---|
date | Sun, 11 Jan 2009 23:49:23 +0000 |
parents | 8cc00819c8d6 |
children | 490f3e4fe753 |
comparison
equal
deleted
inserted
replaced
3022:db20dde98dd3 | 3023:d72a0dd80e8b |
---|---|
58 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); | 58 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); |
59 DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata; | 59 DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata; |
60 int ret; | 60 int ret; |
61 | 61 |
62 if (dispdata->vidIDinuse) | 62 if (dispdata->vidIDinuse) |
63 SDL_DFB_CHECKERR(dispdata->vidlayer-> | 63 SDL_DFB_CHECKERR(dispdata->vidlayer->SwitchContext(dispdata->vidlayer, |
64 SwitchContext(dispdata->vidlayer, DFB_TRUE)); | 64 DFB_TRUE)); |
65 | 65 |
66 error: | 66 error: |
67 return; | 67 return; |
68 #endif | 68 #endif |
69 | 69 |
115 return index; | 115 return index; |
116 } | 116 } |
117 return -1; | 117 return -1; |
118 } | 118 } |
119 | 119 |
120 void | 120 static int |
121 DirectFB_PumpEventsWindow(_THIS) | 121 ClientXY(DFB_WindowData * p, int *x, int *y) |
122 { | 122 { |
123 SDL_DFB_DEVICEDATA(_this); | 123 int cx, cy; |
124 DFB_WindowData *p; | 124 |
125 DFBInputEvent ievt; | 125 cx = *x; |
126 Sint32 /* SDL_WindowID */ grabbed_window; | 126 cy = *y; |
127 | |
128 cx -= p->client.x; | |
129 cy -= p->client.y; | |
130 | |
131 if (cx < 0 || cy < 0) | |
132 return 0; | |
133 if (cx >= p->client.w || cy >= p->client.h) | |
134 return 0; | |
135 *x = cx; | |
136 *y = cy; | |
137 return 1; | |
138 } | |
139 | |
140 static void | |
141 ProcessWindowEvent(_THIS, DFB_WindowData * p, Uint32 flags, | |
142 DFBWindowEvent * evt) | |
143 { | |
144 SDL_DFB_DEVICEDATA(_this); | |
145 SDL_keysym keysym; | |
127 char text[5]; | 146 char text[5]; |
128 int kbd_idx; | 147 |
129 | 148 if (evt->clazz == DFEC_WINDOW) { |
130 grabbed_window = -1; | 149 switch (evt->type) { |
131 | 150 case DWET_BUTTONDOWN: |
132 for (p = devdata->firstwin; p != NULL; p = p->next) { | 151 if (ClientXY(p, &evt->x, &evt->y)) { |
133 DFBWindowEvent evt; | 152 if (!devdata->use_linux_input) { |
134 SDL_Window *w = SDL_GetWindowFromID(p->id); | 153 SDL_SendMouseMotion(devdata->mouse_id[0], 0, evt->x, |
135 | 154 evt->y, 0); |
136 if (w->flags & SDL_WINDOW_INPUT_GRABBED) { | 155 SDL_SendMouseButton(devdata->mouse_id[0], |
137 grabbed_window = p->id; | 156 SDL_PRESSED, |
138 } | 157 DirectFB_TranslateButton |
139 | 158 (evt->button)); |
140 while (p->eventbuffer->GetEvent(p->eventbuffer, | 159 } else { |
141 DFB_EVENT(&evt)) == DFB_OK) { | 160 MotionAllMice(_this, evt->x, evt->y); |
142 SDL_keysym keysym; | 161 } |
143 | 162 } |
144 if (evt.clazz == DFEC_WINDOW) { | 163 break; |
145 switch (evt.type) { | 164 case DWET_BUTTONUP: |
146 case DWET_BUTTONDOWN: | 165 if (ClientXY(p, &evt->x, &evt->y)) { |
147 if (!devdata->use_linux_input) { | 166 if (!devdata->use_linux_input) { |
148 SDL_SendMouseMotion(devdata->mouse_id[0], 0, evt.cx, | 167 SDL_SendMouseMotion(devdata->mouse_id[0], 0, evt->x, |
149 evt.cy, 0); | 168 evt->y, 0); |
150 SDL_SendMouseButton(devdata->mouse_id[0], SDL_PRESSED, | 169 SDL_SendMouseButton(devdata->mouse_id[0], |
151 DirectFB_TranslateButton(evt. | 170 SDL_RELEASED, |
152 button)); | 171 DirectFB_TranslateButton |
153 } else { | 172 (evt->button)); |
154 MotionAllMice(_this, evt.x, evt.y); | 173 } else { |
174 MotionAllMice(_this, evt->x, evt->y); | |
175 } | |
176 } | |
177 break; | |
178 case DWET_MOTION: | |
179 if (ClientXY(p, &evt->x, &evt->y)) { | |
180 SDL_Window *window = SDL_GetWindowFromID(p->sdl_id); | |
181 if (!devdata->use_linux_input) { | |
182 if (!(flags & SDL_WINDOW_INPUT_GRABBED)) | |
183 SDL_SendMouseMotion(devdata->mouse_id[0], 0, | |
184 evt->x, evt->y, 0); | |
185 } else { | |
186 /* relative movements are not exact! | |
187 * This code should limit the number of events sent. | |
188 * However it kills MAME axis recognition ... */ | |
189 static int cnt = 0; | |
190 if (1 && ++cnt > 20) { | |
191 MotionAllMice(_this, evt->x, evt->y); | |
192 cnt = 0; | |
155 } | 193 } |
156 break; | |
157 case DWET_BUTTONUP: | |
158 if (!devdata->use_linux_input) { | |
159 SDL_SendMouseMotion(devdata->mouse_id[0], 0, evt.cx, | |
160 evt.cy, 0); | |
161 SDL_SendMouseButton(devdata->mouse_id[0], | |
162 SDL_RELEASED, | |
163 DirectFB_TranslateButton(evt. | |
164 button)); | |
165 } else { | |
166 MotionAllMice(_this, evt.x, evt.y); | |
167 } | |
168 break; | |
169 case DWET_MOTION: | |
170 if (!devdata->use_linux_input) { | |
171 if (!(w->flags & SDL_WINDOW_INPUT_GRABBED)) | |
172 SDL_SendMouseMotion(devdata->mouse_id[0], 0, | |
173 evt.cx, evt.cy, 0); | |
174 } else { | |
175 /* relative movements are not exact! | |
176 * This code should limit the number of events sent. | |
177 * However it kills MAME axis recognition ... */ | |
178 static int cnt = 0; | |
179 if (1 && ++cnt > 20) { | |
180 MotionAllMice(_this, evt.x, evt.y); | |
181 cnt = 0; | |
182 } | |
183 } | |
184 break; | |
185 case DWET_KEYDOWN: | |
186 if (!devdata->use_linux_input) { | |
187 DirectFB_TranslateKey(_this, &evt, &keysym); | |
188 SDL_SendKeyboardKey(0, SDL_PRESSED, keysym.scancode); | |
189 if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) { | |
190 SDL_memcpy(text, &keysym.unicode, 4); | |
191 text[4] = 0; | |
192 if (*text) { | |
193 SDL_SendKeyboardText(0, text); | |
194 } | |
195 } | |
196 } | |
197 break; | |
198 case DWET_KEYUP: | |
199 if (!devdata->use_linux_input) { | |
200 DirectFB_TranslateKey(_this, &evt, &keysym); | |
201 SDL_SendKeyboardKey(0, SDL_RELEASED, keysym.scancode); | |
202 } | |
203 break; | |
204 case DWET_POSITION_SIZE: | |
205 if (evt.x != w->x || evt.y != w->y) | |
206 SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_MOVED, | |
207 evt.x, evt.y); | |
208 if (evt.w != w->w || evt.h != w->h) | |
209 SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_RESIZED, | |
210 evt.w, evt.h); | |
211 break; | |
212 case DWET_POSITION: | |
213 if (evt.x != w->x || evt.y != w->y) | |
214 SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_MOVED, | |
215 evt.x, evt.y); | |
216 break; | |
217 case DWET_SIZE: | |
218 if (evt.w != w->w || evt.h != w->h) | |
219 SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_RESIZED, | |
220 evt.w, evt.h); | |
221 break; | |
222 case DWET_CLOSE: | |
223 SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_CLOSE, 0, 0); | |
224 break; | |
225 case DWET_GOTFOCUS: | |
226 DirectFB_SetContext(_this, p->id); | |
227 FocusAllKeyboards(_this, p->id); | |
228 SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_FOCUS_GAINED, | |
229 0, 0); | |
230 break; | |
231 case DWET_LOSTFOCUS: | |
232 SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_FOCUS_LOST, 0, | |
233 0); | |
234 FocusAllKeyboards(_this, 0); | |
235 break; | |
236 case DWET_ENTER: | |
237 /* SDL_DirectFB_ReshowCursor(_this, 0); */ | |
238 FocusAllMice(_this, p->id); | |
239 MotionAllMice(_this, evt.x, evt.y); | |
240 SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_ENTER, 0, 0); | |
241 break; | |
242 case DWET_LEAVE: | |
243 SDL_SendWindowEvent(p->id, SDL_WINDOWEVENT_LEAVE, 0, 0); | |
244 FocusAllMice(_this, 0); | |
245 /* SDL_DirectFB_ReshowCursor(_this, 1); */ | |
246 break; | |
247 default: | |
248 ; | |
249 } | 194 } |
250 } else | 195 if (!(window->flags & SDL_WINDOW_MOUSE_FOCUS)) |
251 printf("Event Clazz %d\n", evt.clazz); | 196 SDL_SendWindowEvent(p->sdl_id, SDL_WINDOWEVENT_ENTER, 0, 0); |
252 | 197 } |
253 } | 198 break; |
254 } | 199 case DWET_KEYDOWN: |
255 | |
256 /* Now get relative events in case we need them */ | |
257 while (devdata->events->GetEvent(devdata->events, | |
258 DFB_EVENT(&ievt)) == DFB_OK) { | |
259 SDL_keysym keysym; | |
260 | |
261 switch (ievt.type) { | |
262 case DIET_AXISMOTION: | |
263 if (!devdata->use_linux_input) { | 200 if (!devdata->use_linux_input) { |
264 if ((grabbed_window >= 0) && (ievt.flags & DIEF_AXISREL)) { | 201 DirectFB_TranslateKey(_this, evt, &keysym); |
265 printf("rel devid %d\n", ievt.device_id); | 202 SDL_SendKeyboardKey(0, SDL_PRESSED, keysym.scancode); |
266 if (ievt.axis == DIAI_X) | |
267 SDL_SendMouseMotion(ievt.device_id, 1, ievt.axisrel, | |
268 0, 0); | |
269 else if (ievt.axis == DIAI_Y) | |
270 SDL_SendMouseMotion(ievt.device_id, 1, 0, | |
271 ievt.axisrel, 0); | |
272 } | |
273 } | |
274 break; | |
275 } | |
276 if (devdata->use_linux_input) { | |
277 IDirectFBInputDevice *idev; | |
278 static int last_x, last_y; | |
279 | |
280 switch (ievt.type) { | |
281 case DIET_AXISMOTION: | |
282 if (ievt.flags & DIEF_AXISABS) { | |
283 if (ievt.axis == DIAI_X) | |
284 last_x = ievt.axisabs; | |
285 else if (ievt.axis == DIAI_Y) | |
286 last_y = ievt.axisabs; | |
287 if (!(ievt.flags & DIEF_FOLLOW)) | |
288 SDL_SendMouseMotion(ievt.device_id, 0, last_x, last_y, | |
289 0); | |
290 } else if (ievt.flags & DIEF_AXISREL) { | |
291 //printf("rel %d %d\n", ievt.device_id, ievt.axisrel); | |
292 if (ievt.axis == DIAI_X) | |
293 SDL_SendMouseMotion(ievt.device_id, 1, ievt.axisrel, | |
294 0, 0); | |
295 else if (ievt.axis == DIAI_Y) | |
296 SDL_SendMouseMotion(ievt.device_id, 1, 0, | |
297 ievt.axisrel, 0); | |
298 } | |
299 break; | |
300 case DIET_KEYPRESS: | |
301 kbd_idx = KbdIndex(_this, ievt.device_id); | |
302 DirectFB_TranslateKeyInputEvent(_this, kbd_idx, &ievt, | |
303 &keysym); | |
304 SDL_SendKeyboardKey(kbd_idx, SDL_PRESSED, keysym.scancode); | |
305 if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) { | 203 if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) { |
306 SDL_memcpy(text, &keysym.unicode, 4); | 204 SDL_memcpy(text, &keysym.unicode, 4); |
307 text[4] = 0; | 205 text[4] = 0; |
308 if (*text) { | 206 if (*text) { |
309 SDL_SendKeyboardText(kbd_idx, text); | 207 SDL_SendKeyboardText(0, text); |
310 } | 208 } |
311 } | 209 } |
312 break; | 210 } |
313 case DIET_KEYRELEASE: | 211 break; |
314 kbd_idx = KbdIndex(_this, ievt.device_id); | 212 case DWET_KEYUP: |
315 DirectFB_TranslateKeyInputEvent(_this, kbd_idx, &ievt, | 213 if (!devdata->use_linux_input) { |
316 &keysym); | 214 DirectFB_TranslateKey(_this, evt, &keysym); |
317 SDL_SendKeyboardKey(kbd_idx, SDL_RELEASED, keysym.scancode); | 215 SDL_SendKeyboardKey(0, SDL_RELEASED, keysym.scancode); |
318 break; | 216 } |
319 case DIET_BUTTONPRESS: | 217 break; |
320 if (ievt.buttons & DIBM_LEFT) | 218 case DWET_POSITION: |
321 SDL_SendMouseButton(ievt.device_id, SDL_PRESSED, 1); | 219 if (ClientXY(p, &evt->x, &evt->y)) { |
322 if (ievt.buttons & DIBM_MIDDLE) | 220 SDL_SendWindowEvent(p->sdl_id, SDL_WINDOWEVENT_MOVED, |
323 SDL_SendMouseButton(ievt.device_id, SDL_PRESSED, 2); | 221 evt->x, evt->y); |
324 if (ievt.buttons & DIBM_RIGHT) | 222 } |
325 SDL_SendMouseButton(ievt.device_id, SDL_PRESSED, 3); | 223 break; |
326 break; | 224 case DWET_POSITION_SIZE: |
327 case DIET_BUTTONRELEASE: | 225 if (ClientXY(p, &evt->x, &evt->y)) { |
328 if (!(ievt.buttons & DIBM_LEFT)) | 226 SDL_SendWindowEvent(p->sdl_id, SDL_WINDOWEVENT_MOVED, |
329 SDL_SendMouseButton(ievt.device_id, SDL_RELEASED, 1); | 227 evt->x, evt->y); |
330 if (!(ievt.buttons & DIBM_MIDDLE)) | 228 } |
331 SDL_SendMouseButton(ievt.device_id, SDL_RELEASED, 2); | 229 /* fall throught */ |
332 if (!(ievt.buttons & DIBM_RIGHT)) | 230 case DWET_SIZE: |
333 SDL_SendMouseButton(ievt.device_id, SDL_RELEASED, 3); | 231 // FIXME: what about < 0 |
334 break; | 232 evt->w -= (p->theme.right_size + p->theme.left_size); |
335 } | 233 evt->h -= |
234 (p->theme.top_size + p->theme.bottom_size + | |
235 p->theme.caption_size); | |
236 SDL_SendWindowEvent(p->sdl_id, SDL_WINDOWEVENT_RESIZED, | |
237 evt->w, evt->h); | |
238 break; | |
239 case DWET_CLOSE: | |
240 SDL_SendWindowEvent(p->sdl_id, SDL_WINDOWEVENT_CLOSE, 0, 0); | |
241 break; | |
242 case DWET_GOTFOCUS: | |
243 DirectFB_SetContext(_this, p->sdl_id); | |
244 FocusAllKeyboards(_this, p->sdl_id); | |
245 SDL_SendWindowEvent(p->sdl_id, SDL_WINDOWEVENT_FOCUS_GAINED, | |
246 0, 0); | |
247 break; | |
248 case DWET_LOSTFOCUS: | |
249 SDL_SendWindowEvent(p->sdl_id, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0); | |
250 FocusAllKeyboards(_this, 0); | |
251 break; | |
252 case DWET_ENTER: | |
253 /* SDL_DirectFB_ReshowCursor(_this, 0); */ | |
254 FocusAllMice(_this, p->sdl_id); | |
255 // FIXME: when do we really enter ? | |
256 if (ClientXY(p, &evt->x, &evt->y)) | |
257 MotionAllMice(_this, evt->x, evt->y); | |
258 SDL_SendWindowEvent(p->sdl_id, SDL_WINDOWEVENT_ENTER, 0, 0); | |
259 break; | |
260 case DWET_LEAVE: | |
261 SDL_SendWindowEvent(p->sdl_id, SDL_WINDOWEVENT_LEAVE, 0, 0); | |
262 FocusAllMice(_this, 0); | |
263 /* SDL_DirectFB_ReshowCursor(_this, 1); */ | |
264 break; | |
265 default: | |
266 ; | |
336 } | 267 } |
268 } else | |
269 printf("Event Clazz %d\n", evt->clazz); | |
270 } | |
271 | |
272 static void | |
273 ProcessInputEvent(_THIS, Sint32 grabbed_window, DFBInputEvent * ievt) | |
274 { | |
275 SDL_DFB_DEVICEDATA(_this); | |
276 SDL_keysym keysym; | |
277 int kbd_idx; | |
278 char text[5]; | |
279 | |
280 if (!devdata->use_linux_input) { | |
281 if (ievt->type == DIET_AXISMOTION) { | |
282 if ((grabbed_window >= 0) && (ievt->flags & DIEF_AXISREL)) { | |
283 if (ievt->axis == DIAI_X) | |
284 SDL_SendMouseMotion(ievt->device_id, 1, | |
285 ievt->axisrel, 0, 0); | |
286 else if (ievt->axis == DIAI_Y) | |
287 SDL_SendMouseMotion(ievt->device_id, 1, 0, | |
288 ievt->axisrel, 0); | |
289 } | |
290 } | |
291 } else { | |
292 static int last_x, last_y; | |
293 | |
294 switch (ievt->type) { | |
295 case DIET_AXISMOTION: | |
296 if (ievt->flags & DIEF_AXISABS) { | |
297 if (ievt->axis == DIAI_X) | |
298 last_x = ievt->axisabs; | |
299 else if (ievt->axis == DIAI_Y) | |
300 last_y = ievt->axisabs; | |
301 if (!(ievt->flags & DIEF_FOLLOW)) { | |
302 SDL_Mouse *mouse = SDL_GetMouse(ievt->device_id); | |
303 SDL_Window *window = SDL_GetWindowFromID(mouse->focus); | |
304 if (window) { | |
305 DFB_WindowData *windata = | |
306 (DFB_WindowData *) window->driverdata; | |
307 int x, y; | |
308 | |
309 windata->window->GetPosition(windata->window, &x, &y); | |
310 SDL_SendMouseMotion(ievt->device_id, 0, | |
311 last_x - (x + | |
312 windata->client.x), | |
313 last_y - (y + | |
314 windata->client.y), 0); | |
315 } else { | |
316 SDL_SendMouseMotion(ievt->device_id, 0, last_x, | |
317 last_y, 0); | |
318 } | |
319 } | |
320 } else if (ievt->flags & DIEF_AXISREL) { | |
321 if (ievt->axis == DIAI_X) | |
322 SDL_SendMouseMotion(ievt->device_id, 1, | |
323 ievt->axisrel, 0, 0); | |
324 else if (ievt->axis == DIAI_Y) | |
325 SDL_SendMouseMotion(ievt->device_id, 1, 0, | |
326 ievt->axisrel, 0); | |
327 } | |
328 break; | |
329 case DIET_KEYPRESS: | |
330 kbd_idx = KbdIndex(_this, ievt->device_id); | |
331 DirectFB_TranslateKeyInputEvent(_this, kbd_idx, ievt, &keysym); | |
332 SDL_SendKeyboardKey(kbd_idx, SDL_PRESSED, keysym.scancode); | |
333 if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) { | |
334 SDL_memcpy(text, &keysym.unicode, 4); | |
335 text[4] = 0; | |
336 if (*text) { | |
337 SDL_SendKeyboardText(kbd_idx, text); | |
338 } | |
339 } | |
340 break; | |
341 case DIET_KEYRELEASE: | |
342 kbd_idx = KbdIndex(_this, ievt->device_id); | |
343 DirectFB_TranslateKeyInputEvent(_this, kbd_idx, ievt, &keysym); | |
344 SDL_SendKeyboardKey(kbd_idx, SDL_RELEASED, keysym.scancode); | |
345 break; | |
346 case DIET_BUTTONPRESS: | |
347 if (ievt->buttons & DIBM_LEFT) | |
348 SDL_SendMouseButton(ievt->device_id, SDL_PRESSED, 1); | |
349 if (ievt->buttons & DIBM_MIDDLE) | |
350 SDL_SendMouseButton(ievt->device_id, SDL_PRESSED, 2); | |
351 if (ievt->buttons & DIBM_RIGHT) | |
352 SDL_SendMouseButton(ievt->device_id, SDL_PRESSED, 3); | |
353 break; | |
354 case DIET_BUTTONRELEASE: | |
355 if (!(ievt->buttons & DIBM_LEFT)) | |
356 SDL_SendMouseButton(ievt->device_id, SDL_RELEASED, 1); | |
357 if (!(ievt->buttons & DIBM_MIDDLE)) | |
358 SDL_SendMouseButton(ievt->device_id, SDL_RELEASED, 2); | |
359 if (!(ievt->buttons & DIBM_RIGHT)) | |
360 SDL_SendMouseButton(ievt->device_id, SDL_RELEASED, 3); | |
361 break; | |
362 default: | |
363 break; /* please gcc */ | |
364 } | |
365 } | |
366 } | |
367 | |
368 void | |
369 DirectFB_PumpEventsWindow(_THIS) | |
370 { | |
371 SDL_DFB_DEVICEDATA(_this); | |
372 DFB_WindowData *p; | |
373 DFBInputEvent ievt; | |
374 Sint32 /* SDL_WindowID */ grabbed_window; | |
375 | |
376 grabbed_window = -1; | |
377 | |
378 for (p = devdata->firstwin; p != NULL; p = p->next) { | |
379 DFBWindowEvent evt; | |
380 SDL_Window *w = SDL_GetWindowFromID(p->sdl_id); | |
381 | |
382 if (w->flags & SDL_WINDOW_INPUT_GRABBED) { | |
383 grabbed_window = p->sdl_id; | |
384 } | |
385 | |
386 while (p->eventbuffer->GetEvent(p->eventbuffer, | |
387 DFB_EVENT(&evt)) == DFB_OK) { | |
388 if (!DirectFB_WM_ProcessEvent(_this, w, &evt)) | |
389 ProcessWindowEvent(_this, p, w->flags, &evt); | |
390 } | |
391 } | |
392 | |
393 /* Now get relative events in case we need them */ | |
394 while (devdata->events->GetEvent(devdata->events, | |
395 DFB_EVENT(&ievt)) == DFB_OK) { | |
396 ProcessInputEvent(_this, grabbed_window, &ievt); | |
337 } | 397 } |
338 } | 398 } |
339 | 399 |
340 void | 400 void |
341 DirectFB_InitOSKeymap(_THIS, SDLKey * keymap, int numkeys) | 401 DirectFB_InitOSKeymap(_THIS, SDLKey * keymap, int numkeys) |
468 static SDL_keysym * | 528 static SDL_keysym * |
469 DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt, SDL_keysym * keysym) | 529 DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt, SDL_keysym * keysym) |
470 { | 530 { |
471 SDL_DFB_DEVICEDATA(_this); | 531 SDL_DFB_DEVICEDATA(_this); |
472 | 532 |
473 if (evt->key_code >= 0 | 533 if (evt->key_code >= 0 && |
474 && evt->key_code < SDL_arraysize(linux_scancode_table)) | 534 evt->key_code < SDL_arraysize(linux_scancode_table)) |
475 keysym->scancode = linux_scancode_table[evt->key_code]; | 535 keysym->scancode = linux_scancode_table[evt->key_code]; |
476 else | 536 else |
477 keysym->scancode = SDL_SCANCODE_UNKNOWN; | 537 keysym->scancode = SDL_SCANCODE_UNKNOWN; |
478 | 538 |
479 if (keysym->scancode == SDL_SCANCODE_UNKNOWN | 539 if (keysym->scancode == SDL_SCANCODE_UNKNOWN || |
480 || devdata->keyboard[0].is_generic) { | 540 devdata->keyboard[0].is_generic) { |
481 if (evt->key_id - DIKI_UNKNOWN < SDL_arraysize(oskeymap)) | 541 if (evt->key_id - DIKI_UNKNOWN < SDL_arraysize(oskeymap)) |
482 keysym->scancode = oskeymap[evt->key_id - DIKI_UNKNOWN]; | 542 keysym->scancode = oskeymap[evt->key_id - DIKI_UNKNOWN]; |
483 else | 543 else |
484 keysym->scancode = SDL_SCANCODE_UNKNOWN; | 544 keysym->scancode = SDL_SCANCODE_UNKNOWN; |
485 } | 545 } |
486 | 546 |
487 keysym->unicode = | 547 keysym->unicode = |
488 (DFB_KEY_TYPE(evt->key_symbol) == DIKT_UNICODE) ? evt->key_symbol : 0; | 548 (DFB_KEY_TYPE(evt->key_symbol) == DIKT_UNICODE) ? evt->key_symbol : 0; |
489 if (keysym->unicode == 0 | 549 if (keysym->unicode == 0 && |
490 && (evt->key_symbol > 0 && evt->key_symbol < 255)) | 550 (evt->key_symbol > 0 && evt->key_symbol < 255)) |
491 keysym->unicode = evt->key_symbol; | 551 keysym->unicode = evt->key_symbol; |
492 | 552 |
493 return keysym; | 553 return keysym; |
494 } | 554 } |
495 | 555 |
497 DirectFB_TranslateKeyInputEvent(_THIS, int index, DFBInputEvent * evt, | 557 DirectFB_TranslateKeyInputEvent(_THIS, int index, DFBInputEvent * evt, |
498 SDL_keysym * keysym) | 558 SDL_keysym * keysym) |
499 { | 559 { |
500 SDL_DFB_DEVICEDATA(_this); | 560 SDL_DFB_DEVICEDATA(_this); |
501 | 561 |
502 if (evt->key_code >= 0 | 562 if (evt->key_code >= 0 && |
503 && evt->key_code < SDL_arraysize(linux_scancode_table)) | 563 evt->key_code < SDL_arraysize(linux_scancode_table)) |
504 keysym->scancode = linux_scancode_table[evt->key_code]; | 564 keysym->scancode = linux_scancode_table[evt->key_code]; |
505 else | 565 else |
506 keysym->scancode = SDL_SCANCODE_UNKNOWN; | 566 keysym->scancode = SDL_SCANCODE_UNKNOWN; |
507 | 567 |
508 if (keysym->scancode == SDL_SCANCODE_UNKNOWN | 568 if (keysym->scancode == SDL_SCANCODE_UNKNOWN || |
509 || devdata->keyboard[index].is_generic) { | 569 devdata->keyboard[index].is_generic) { |
510 if (evt->key_id - DIKI_UNKNOWN < SDL_arraysize(oskeymap)) | 570 if (evt->key_id - DIKI_UNKNOWN < SDL_arraysize(oskeymap)) |
511 keysym->scancode = oskeymap[evt->key_id - DIKI_UNKNOWN]; | 571 keysym->scancode = oskeymap[evt->key_id - DIKI_UNKNOWN]; |
512 else | 572 else |
513 keysym->scancode = SDL_SCANCODE_UNKNOWN; | 573 keysym->scancode = SDL_SCANCODE_UNKNOWN; |
514 } | 574 } |
515 | 575 |
516 keysym->unicode = | 576 keysym->unicode = |
517 (DFB_KEY_TYPE(evt->key_symbol) == DIKT_UNICODE) ? evt->key_symbol : 0; | 577 (DFB_KEY_TYPE(evt->key_symbol) == DIKT_UNICODE) ? evt->key_symbol : 0; |
518 if (keysym->unicode == 0 | 578 if (keysym->unicode == 0 && |
519 && (evt->key_symbol > 0 && evt->key_symbol < 255)) | 579 (evt->key_symbol > 0 && evt->key_symbol < 255)) |
520 keysym->unicode = evt->key_symbol; | 580 keysym->unicode = evt->key_symbol; |
521 | 581 |
522 return keysym; | 582 return keysym; |
523 } | 583 } |
584 | |
524 static int | 585 static int |
525 DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button) | 586 DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button) |
526 { | 587 { |
527 switch (button) { | 588 switch (button) { |
528 case DIBI_LEFT: | 589 case DIBI_LEFT: |
535 return 0; | 596 return 0; |
536 } | 597 } |
537 } | 598 } |
538 | 599 |
539 static DFBEnumerationResult | 600 static DFBEnumerationResult |
540 input_device_cb(DFBInputDeviceID device_id, DFBInputDeviceDescription desc, | 601 input_device_cb(DFBInputDeviceID device_id, |
541 void *callbackdata) | 602 DFBInputDeviceDescription desc, void *callbackdata) |
542 { | 603 { |
543 DFB_DeviceData *devdata = callbackdata; | 604 DFB_DeviceData *devdata = callbackdata; |
544 SDL_Keyboard keyboard; | 605 SDL_Keyboard keyboard; |
545 SDLKey keymap[SDL_NUM_SCANCODES]; | 606 SDLKey keymap[SDL_NUM_SCANCODES]; |
546 | 607 |
560 } | 621 } |
561 return DFENUM_OK; | 622 return DFENUM_OK; |
562 } | 623 } |
563 | 624 |
564 static DFBEnumerationResult | 625 static DFBEnumerationResult |
565 EnumKeyboards(DFBInputDeviceID device_id, DFBInputDeviceDescription desc, | 626 EnumKeyboards(DFBInputDeviceID device_id, |
566 void *callbackdata) | 627 DFBInputDeviceDescription desc, void *callbackdata) |
567 { | 628 { |
568 DFB_DeviceData *devdata = callbackdata; | 629 DFB_DeviceData *devdata = callbackdata; |
569 SDL_Keyboard keyboard; | 630 SDL_Keyboard keyboard; |
570 SDLKey keymap[SDL_NUM_SCANCODES]; | 631 SDLKey keymap[SDL_NUM_SCANCODES]; |
571 | 632 |
604 sys_ids = 0; | 665 sys_ids = 0; |
605 SDL_DFB_CHECK(devdata->dfb-> | 666 SDL_DFB_CHECK(devdata->dfb-> |
606 EnumInputDevices(devdata->dfb, EnumKeyboards, devdata)); | 667 EnumInputDevices(devdata->dfb, EnumKeyboards, devdata)); |
607 if (devdata->num_keyboard == 0) { | 668 if (devdata->num_keyboard == 0) { |
608 sys_ids = 1; | 669 sys_ids = 1; |
609 SDL_DFB_CHECK(devdata->dfb-> | 670 SDL_DFB_CHECK(devdata->dfb->EnumInputDevices(devdata->dfb, |
610 EnumInputDevices(devdata->dfb, EnumKeyboards, | 671 EnumKeyboards, |
611 devdata)); | 672 devdata)); |
612 } | 673 } |
613 } else { | 674 } else { |
614 SDL_DFB_CHECK(devdata->dfb-> | 675 SDL_DFB_CHECK(devdata->dfb->EnumInputDevices(devdata->dfb, |
615 EnumInputDevices(devdata->dfb, input_device_cb, | 676 input_device_cb, |
616 devdata)); | 677 devdata)); |
617 } | 678 } |
618 } | 679 } |
619 | 680 |
620 void | 681 void |
621 DirectFB_QuitKeyboard(_THIS) | 682 DirectFB_QuitKeyboard(_THIS) |
647 else | 708 else |
648 mod = 0; | 709 mod = 0; |
649 | 710 |
650 switch (evt.type) { | 711 switch (evt.type) { |
651 case DIET_BUTTONPRESS: | 712 case DIET_BUTTONPRESS: |
652 posted += SDL_PrivateMouseButton(SDL_PRESSED, | 713 posted += |
653 DirectFB_TranslateButton(evt. | 714 SDL_PrivateMouseButton(SDL_PRESSED, |
654 button), | 715 DirectFB_TranslateButton |
655 0, 0); | 716 (evt.button), 0, 0); |
656 break; | 717 break; |
657 case DIET_BUTTONRELEASE: | 718 case DIET_BUTTONRELEASE: |
658 posted += SDL_PrivateMouseButton(SDL_RELEASED, | 719 posted += |
659 DirectFB_TranslateButton(evt. | 720 SDL_PrivateMouseButton(SDL_RELEASED, |
660 button), | 721 DirectFB_TranslateButton |
661 0, 0); | 722 (evt.button), 0, 0); |
662 break; | 723 break; |
663 case DIET_KEYPRESS: | 724 case DIET_KEYPRESS: |
664 posted += SDL_PrivateKeyboard(SDL_PRESSED, | 725 posted += |
665 DirectFB_TranslateKey(evt. | 726 SDL_PrivateKeyboard(SDL_PRESSED, |
666 key_id, | 727 DirectFB_TranslateKey |
667 evt. | 728 (evt.key_id, evt.key_symbol, |
668 key_symbol, | 729 mod, &keysym)); |
669 mod, | |
670 &keysym)); | |
671 break; | 730 break; |
672 case DIET_KEYRELEASE: | 731 case DIET_KEYRELEASE: |
673 posted += SDL_PrivateKeyboard(SDL_RELEASED, | 732 posted += |
674 DirectFB_TranslateKey(evt. | 733 SDL_PrivateKeyboard(SDL_RELEASED, |
675 key_id, | 734 DirectFB_TranslateKey |
676 evt. | 735 (evt.key_id, evt.key_symbol, |
677 key_symbol, | 736 mod, &keysym)); |
678 mod, | |
679 &keysym)); | |
680 break; | 737 break; |
681 case DIET_AXISMOTION: | 738 case DIET_AXISMOTION: |
682 if (evt.flags & DIEF_AXISREL) { | 739 if (evt.flags & DIEF_AXISREL) { |
683 if (evt.axis == DIAI_X) | 740 if (evt.axis == DIAI_X) |
684 posted += | 741 posted += |