• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2     SDL - Simple DirectMedia Layer
3     Copyright (C) 1997-2006 Sam Lantinga
4 
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Lesser General Public
7     License as published by the Free Software Foundation; either
8     version 2.1 of the License, or (at your option) any later version.
9 
10     This library is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13     Lesser General Public License for more details.
14 
15     You should have received a copy of the GNU Lesser General Public
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
18 
19     Sam Lantinga
20     slouken@libsdl.org
21 */
22 #include "SDL_config.h"
23 
24 /* Handle the event stream, converting DirectFB input events into SDL events */
25 
26 #include <sys/types.h>
27 #include <sys/time.h>
28 #include <unistd.h>
29 #include <fcntl.h>
30 #include <termios.h>
31 
32 #include <directfb.h>
33 
34 #include "SDL.h"
35 #include "../SDL_sysvideo.h"
36 #include "../../events/SDL_sysevents.h"
37 #include "../../events/SDL_events_c.h"
38 #include "SDL_DirectFB_video.h"
39 #include "SDL_DirectFB_events.h"
40 
41 /* The translation tables from a DirectFB keycode to a SDL keysym */
42 static SDLKey keymap[256];
43 static SDL_keysym *DirectFB_TranslateKey (DFBInputEvent *ev, SDL_keysym *keysym);
44 static int DirectFB_TranslateButton (DFBInputEvent *ev);
45 
46 static int posted = 0;
47 
48 
DirectFB_PumpEvents(_THIS)49 void DirectFB_PumpEvents (_THIS)
50 {
51   DFBInputEvent evt;
52 
53   while (HIDDEN->eventbuffer->GetEvent (HIDDEN->eventbuffer,
54                                         DFB_EVENT (&evt)) == DFB_OK)
55     {
56       SDL_keysym keysym;
57 
58       switch (evt.type)
59         {
60         case DIET_BUTTONPRESS:
61           posted += SDL_PrivateMouseButton(SDL_PRESSED,
62                                            DirectFB_TranslateButton (&evt), 0, 0);
63           break;
64         case DIET_BUTTONRELEASE:
65           posted += SDL_PrivateMouseButton(SDL_RELEASED,
66                                            DirectFB_TranslateButton (&evt), 0, 0);
67           break;
68         case DIET_KEYPRESS:
69           posted += SDL_PrivateKeyboard(SDL_PRESSED, DirectFB_TranslateKey(&evt, &keysym));
70           break;
71         case DIET_KEYRELEASE:
72           posted += SDL_PrivateKeyboard(SDL_RELEASED, DirectFB_TranslateKey(&evt, &keysym));
73           break;
74         case DIET_AXISMOTION:
75           if (evt.flags & DIEF_AXISREL)
76             {
77               if (evt.axis == DIAI_X)
78                 posted += SDL_PrivateMouseMotion(0, 1, evt.axisrel, 0);
79               else if (evt.axis == DIAI_Y)
80                 posted += SDL_PrivateMouseMotion(0, 1, 0, evt.axisrel);
81             }
82           break;
83         default:
84           ;
85         }
86     }
87 }
88 
DirectFB_InitOSKeymap(_THIS)89 void DirectFB_InitOSKeymap (_THIS)
90 {
91   int i;
92 
93   /* Initialize the DirectFB key translation table */
94   for (i=0; i<SDL_arraysize(keymap); ++i)
95     keymap[i] = SDLK_UNKNOWN;
96 
97   keymap[DIKI_A - DIKI_UNKNOWN] = SDLK_a;
98   keymap[DIKI_B - DIKI_UNKNOWN] = SDLK_b;
99   keymap[DIKI_C - DIKI_UNKNOWN] = SDLK_c;
100   keymap[DIKI_D - DIKI_UNKNOWN] = SDLK_d;
101   keymap[DIKI_E - DIKI_UNKNOWN] = SDLK_e;
102   keymap[DIKI_F - DIKI_UNKNOWN] = SDLK_f;
103   keymap[DIKI_G - DIKI_UNKNOWN] = SDLK_g;
104   keymap[DIKI_H - DIKI_UNKNOWN] = SDLK_h;
105   keymap[DIKI_I - DIKI_UNKNOWN] = SDLK_i;
106   keymap[DIKI_J - DIKI_UNKNOWN] = SDLK_j;
107   keymap[DIKI_K - DIKI_UNKNOWN] = SDLK_k;
108   keymap[DIKI_L - DIKI_UNKNOWN] = SDLK_l;
109   keymap[DIKI_M - DIKI_UNKNOWN] = SDLK_m;
110   keymap[DIKI_N - DIKI_UNKNOWN] = SDLK_n;
111   keymap[DIKI_O - DIKI_UNKNOWN] = SDLK_o;
112   keymap[DIKI_P - DIKI_UNKNOWN] = SDLK_p;
113   keymap[DIKI_Q - DIKI_UNKNOWN] = SDLK_q;
114   keymap[DIKI_R - DIKI_UNKNOWN] = SDLK_r;
115   keymap[DIKI_S - DIKI_UNKNOWN] = SDLK_s;
116   keymap[DIKI_T - DIKI_UNKNOWN] = SDLK_t;
117   keymap[DIKI_U - DIKI_UNKNOWN] = SDLK_u;
118   keymap[DIKI_V - DIKI_UNKNOWN] = SDLK_v;
119   keymap[DIKI_W - DIKI_UNKNOWN] = SDLK_w;
120   keymap[DIKI_X - DIKI_UNKNOWN] = SDLK_x;
121   keymap[DIKI_Y - DIKI_UNKNOWN] = SDLK_y;
122   keymap[DIKI_Z - DIKI_UNKNOWN] = SDLK_z;
123 
124   keymap[DIKI_0 - DIKI_UNKNOWN] = SDLK_0;
125   keymap[DIKI_1 - DIKI_UNKNOWN] = SDLK_1;
126   keymap[DIKI_2 - DIKI_UNKNOWN] = SDLK_2;
127   keymap[DIKI_3 - DIKI_UNKNOWN] = SDLK_3;
128   keymap[DIKI_4 - DIKI_UNKNOWN] = SDLK_4;
129   keymap[DIKI_5 - DIKI_UNKNOWN] = SDLK_5;
130   keymap[DIKI_6 - DIKI_UNKNOWN] = SDLK_6;
131   keymap[DIKI_7 - DIKI_UNKNOWN] = SDLK_7;
132   keymap[DIKI_8 - DIKI_UNKNOWN] = SDLK_8;
133   keymap[DIKI_9 - DIKI_UNKNOWN] = SDLK_9;
134 
135   keymap[DIKI_F1 - DIKI_UNKNOWN] = SDLK_F1;
136   keymap[DIKI_F2 - DIKI_UNKNOWN] = SDLK_F2;
137   keymap[DIKI_F3 - DIKI_UNKNOWN] = SDLK_F3;
138   keymap[DIKI_F4 - DIKI_UNKNOWN] = SDLK_F4;
139   keymap[DIKI_F5 - DIKI_UNKNOWN] = SDLK_F5;
140   keymap[DIKI_F6 - DIKI_UNKNOWN] = SDLK_F6;
141   keymap[DIKI_F7 - DIKI_UNKNOWN] = SDLK_F7;
142   keymap[DIKI_F8 - DIKI_UNKNOWN] = SDLK_F8;
143   keymap[DIKI_F9 - DIKI_UNKNOWN] = SDLK_F9;
144   keymap[DIKI_F10 - DIKI_UNKNOWN] = SDLK_F10;
145   keymap[DIKI_F11 - DIKI_UNKNOWN] = SDLK_F11;
146   keymap[DIKI_F12 - DIKI_UNKNOWN] = SDLK_F12;
147 
148   keymap[DIKI_ESCAPE - DIKI_UNKNOWN] = SDLK_ESCAPE;
149   keymap[DIKI_LEFT - DIKI_UNKNOWN] = SDLK_LEFT;
150   keymap[DIKI_RIGHT - DIKI_UNKNOWN] = SDLK_RIGHT;
151   keymap[DIKI_UP - DIKI_UNKNOWN] = SDLK_UP;
152   keymap[DIKI_DOWN - DIKI_UNKNOWN] = SDLK_DOWN;
153   keymap[DIKI_CONTROL_L - DIKI_UNKNOWN] = SDLK_LCTRL;
154   keymap[DIKI_CONTROL_R - DIKI_UNKNOWN] = SDLK_RCTRL;
155   keymap[DIKI_SHIFT_L - DIKI_UNKNOWN] = SDLK_LSHIFT;
156   keymap[DIKI_SHIFT_R - DIKI_UNKNOWN] = SDLK_RSHIFT;
157   keymap[DIKI_ALT_L - DIKI_UNKNOWN] = SDLK_LALT;
158   keymap[DIKI_ALT_R - DIKI_UNKNOWN] = SDLK_RALT;
159   keymap[DIKI_TAB - DIKI_UNKNOWN] = SDLK_TAB;
160   keymap[DIKI_ENTER - DIKI_UNKNOWN] = SDLK_RETURN;
161   keymap[DIKI_SPACE - DIKI_UNKNOWN] = SDLK_SPACE;
162   keymap[DIKI_BACKSPACE - DIKI_UNKNOWN] = SDLK_BACKSPACE;
163   keymap[DIKI_INSERT - DIKI_UNKNOWN] = SDLK_INSERT;
164   keymap[DIKI_DELETE - DIKI_UNKNOWN] = SDLK_DELETE;
165   keymap[DIKI_HOME - DIKI_UNKNOWN] = SDLK_HOME;
166   keymap[DIKI_END - DIKI_UNKNOWN] = SDLK_END;
167   keymap[DIKI_PAGE_UP - DIKI_UNKNOWN] = SDLK_PAGEUP;
168   keymap[DIKI_PAGE_DOWN - DIKI_UNKNOWN] = SDLK_PAGEDOWN;
169   keymap[DIKI_CAPS_LOCK - DIKI_UNKNOWN] = SDLK_CAPSLOCK;
170   keymap[DIKI_NUM_LOCK - DIKI_UNKNOWN] = SDLK_NUMLOCK;
171   keymap[DIKI_SCROLL_LOCK - DIKI_UNKNOWN] = SDLK_SCROLLOCK;
172   keymap[DIKI_PRINT - DIKI_UNKNOWN] = SDLK_PRINT;
173   keymap[DIKI_PAUSE - DIKI_UNKNOWN] = SDLK_PAUSE;
174   keymap[DIKI_KP_DIV - DIKI_UNKNOWN] = SDLK_KP_DIVIDE;
175   keymap[DIKI_KP_MULT - DIKI_UNKNOWN] = SDLK_KP_MULTIPLY;
176   keymap[DIKI_KP_MINUS - DIKI_UNKNOWN] = SDLK_KP_MINUS;
177   keymap[DIKI_KP_PLUS - DIKI_UNKNOWN] = SDLK_KP_PLUS;
178   keymap[DIKI_KP_ENTER - DIKI_UNKNOWN] = SDLK_KP_ENTER;
179 }
180 
181 
DirectFB_TranslateKey(DFBInputEvent * ev,SDL_keysym * keysym)182 static SDL_keysym *DirectFB_TranslateKey (DFBInputEvent *ev, SDL_keysym *keysym)
183 {
184   /* Set the keysym information */
185   keysym->scancode = ev->key_id;
186   keysym->mod = KMOD_NONE; /* FIXME */
187   keysym->unicode = (DFB_KEY_TYPE (ev->key_symbol) == DIKT_UNICODE) ? ev->key_symbol : 0;
188 
189   if (ev->key_symbol > 0 && ev->key_symbol < 128)
190     keysym->sym = ev->key_symbol;
191   else
192     keysym->sym = keymap[ev->key_id - DIKI_UNKNOWN];
193 
194   return keysym;
195 }
196 
DirectFB_TranslateButton(DFBInputEvent * ev)197 static int DirectFB_TranslateButton (DFBInputEvent *ev)
198 {
199   switch (ev->button)
200     {
201     case DIBI_LEFT:
202       return 1;
203     case DIBI_MIDDLE:
204       return 2;
205     case DIBI_RIGHT:
206       return 3;
207     default:
208       return 0;
209     }
210 }
211