src/video/directfb/SDL_DirectFB_events.c
author Sam Lantinga
Thu, 29 Dec 2011 04:24:15 -0500
branchSDL-1.2
changeset 6109 469e95e71627
parent 4159 a1b03ba2fcd0
child 6137 4720145f848b
permissions -rw-r--r--
Fixed bug 1032

Matthias Hawran 2010-07-28 03:00:49 PDT
Hi,

I simply want to "forward" this post
(http://forums.libsdl.org/viewtopic.php?t=4123) about absolute mouse events not
being monitored by SDL 1.2 as directfb / tslib generates them.

It's fixed in 1.3 and IMHO it should be backported to 1.2

Included the patch from the post (thanks to Guillaume Chereau)

Cheers,
Matthias
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2009 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 
    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           else if (evt.flags & DIEF_AXISABS)
    83             {
    84               static int last_x, last_y;
    85               if (evt.axis == DIAI_X)
    86                 last_x = evt.axisabs;
    87               else if (evt.axis == DIAI_Y)
    88                 last_y = evt.axisabs;
    89               posted += SDL_PrivateMouseMotion(0, 0, last_x, last_y);
    90             }
    91           break;
    92         default:
    93           ;
    94         }
    95     }
    96 }
    97 
    98 void DirectFB_InitOSKeymap (_THIS)
    99 {
   100   int i;
   101 	
   102   /* Initialize the DirectFB key translation table */
   103   for (i=0; i<SDL_arraysize(keymap); ++i)
   104     keymap[i] = SDLK_UNKNOWN;
   105 
   106   keymap[DIKI_A - DIKI_UNKNOWN] = SDLK_a;
   107   keymap[DIKI_B - DIKI_UNKNOWN] = SDLK_b;
   108   keymap[DIKI_C - DIKI_UNKNOWN] = SDLK_c;
   109   keymap[DIKI_D - DIKI_UNKNOWN] = SDLK_d;
   110   keymap[DIKI_E - DIKI_UNKNOWN] = SDLK_e;
   111   keymap[DIKI_F - DIKI_UNKNOWN] = SDLK_f;
   112   keymap[DIKI_G - DIKI_UNKNOWN] = SDLK_g;
   113   keymap[DIKI_H - DIKI_UNKNOWN] = SDLK_h;
   114   keymap[DIKI_I - DIKI_UNKNOWN] = SDLK_i;
   115   keymap[DIKI_J - DIKI_UNKNOWN] = SDLK_j;
   116   keymap[DIKI_K - DIKI_UNKNOWN] = SDLK_k;
   117   keymap[DIKI_L - DIKI_UNKNOWN] = SDLK_l;
   118   keymap[DIKI_M - DIKI_UNKNOWN] = SDLK_m;
   119   keymap[DIKI_N - DIKI_UNKNOWN] = SDLK_n;
   120   keymap[DIKI_O - DIKI_UNKNOWN] = SDLK_o;
   121   keymap[DIKI_P - DIKI_UNKNOWN] = SDLK_p;
   122   keymap[DIKI_Q - DIKI_UNKNOWN] = SDLK_q;
   123   keymap[DIKI_R - DIKI_UNKNOWN] = SDLK_r;
   124   keymap[DIKI_S - DIKI_UNKNOWN] = SDLK_s;
   125   keymap[DIKI_T - DIKI_UNKNOWN] = SDLK_t;
   126   keymap[DIKI_U - DIKI_UNKNOWN] = SDLK_u;
   127   keymap[DIKI_V - DIKI_UNKNOWN] = SDLK_v;
   128   keymap[DIKI_W - DIKI_UNKNOWN] = SDLK_w;
   129   keymap[DIKI_X - DIKI_UNKNOWN] = SDLK_x;
   130   keymap[DIKI_Y - DIKI_UNKNOWN] = SDLK_y;
   131   keymap[DIKI_Z - DIKI_UNKNOWN] = SDLK_z;
   132   
   133   keymap[DIKI_0 - DIKI_UNKNOWN] = SDLK_0;
   134   keymap[DIKI_1 - DIKI_UNKNOWN] = SDLK_1;
   135   keymap[DIKI_2 - DIKI_UNKNOWN] = SDLK_2;
   136   keymap[DIKI_3 - DIKI_UNKNOWN] = SDLK_3;
   137   keymap[DIKI_4 - DIKI_UNKNOWN] = SDLK_4;
   138   keymap[DIKI_5 - DIKI_UNKNOWN] = SDLK_5;
   139   keymap[DIKI_6 - DIKI_UNKNOWN] = SDLK_6;
   140   keymap[DIKI_7 - DIKI_UNKNOWN] = SDLK_7;
   141   keymap[DIKI_8 - DIKI_UNKNOWN] = SDLK_8;
   142   keymap[DIKI_9 - DIKI_UNKNOWN] = SDLK_9;
   143   
   144   keymap[DIKI_F1 - DIKI_UNKNOWN] = SDLK_F1;
   145   keymap[DIKI_F2 - DIKI_UNKNOWN] = SDLK_F2;
   146   keymap[DIKI_F3 - DIKI_UNKNOWN] = SDLK_F3;
   147   keymap[DIKI_F4 - DIKI_UNKNOWN] = SDLK_F4;
   148   keymap[DIKI_F5 - DIKI_UNKNOWN] = SDLK_F5;
   149   keymap[DIKI_F6 - DIKI_UNKNOWN] = SDLK_F6;
   150   keymap[DIKI_F7 - DIKI_UNKNOWN] = SDLK_F7;
   151   keymap[DIKI_F8 - DIKI_UNKNOWN] = SDLK_F8;
   152   keymap[DIKI_F9 - DIKI_UNKNOWN] = SDLK_F9;
   153   keymap[DIKI_F10 - DIKI_UNKNOWN] = SDLK_F10;
   154   keymap[DIKI_F11 - DIKI_UNKNOWN] = SDLK_F11;
   155   keymap[DIKI_F12 - DIKI_UNKNOWN] = SDLK_F12;
   156   
   157   keymap[DIKI_ESCAPE - DIKI_UNKNOWN] = SDLK_ESCAPE;
   158   keymap[DIKI_LEFT - DIKI_UNKNOWN] = SDLK_LEFT;
   159   keymap[DIKI_RIGHT - DIKI_UNKNOWN] = SDLK_RIGHT;
   160   keymap[DIKI_UP - DIKI_UNKNOWN] = SDLK_UP;
   161   keymap[DIKI_DOWN - DIKI_UNKNOWN] = SDLK_DOWN;
   162   keymap[DIKI_CONTROL_L - DIKI_UNKNOWN] = SDLK_LCTRL;
   163   keymap[DIKI_CONTROL_R - DIKI_UNKNOWN] = SDLK_RCTRL;
   164   keymap[DIKI_SHIFT_L - DIKI_UNKNOWN] = SDLK_LSHIFT;
   165   keymap[DIKI_SHIFT_R - DIKI_UNKNOWN] = SDLK_RSHIFT;
   166   keymap[DIKI_ALT_L - DIKI_UNKNOWN] = SDLK_LALT;
   167   keymap[DIKI_ALT_R - DIKI_UNKNOWN] = SDLK_RALT;
   168   keymap[DIKI_TAB - DIKI_UNKNOWN] = SDLK_TAB;
   169   keymap[DIKI_ENTER - DIKI_UNKNOWN] = SDLK_RETURN;
   170   keymap[DIKI_SPACE - DIKI_UNKNOWN] = SDLK_SPACE;
   171   keymap[DIKI_BACKSPACE - DIKI_UNKNOWN] = SDLK_BACKSPACE;
   172   keymap[DIKI_INSERT - DIKI_UNKNOWN] = SDLK_INSERT;
   173   keymap[DIKI_DELETE - DIKI_UNKNOWN] = SDLK_DELETE;
   174   keymap[DIKI_HOME - DIKI_UNKNOWN] = SDLK_HOME;
   175   keymap[DIKI_END - DIKI_UNKNOWN] = SDLK_END;
   176   keymap[DIKI_PAGE_UP - DIKI_UNKNOWN] = SDLK_PAGEUP;
   177   keymap[DIKI_PAGE_DOWN - DIKI_UNKNOWN] = SDLK_PAGEDOWN;
   178   keymap[DIKI_CAPS_LOCK - DIKI_UNKNOWN] = SDLK_CAPSLOCK;
   179   keymap[DIKI_NUM_LOCK - DIKI_UNKNOWN] = SDLK_NUMLOCK;
   180   keymap[DIKI_SCROLL_LOCK - DIKI_UNKNOWN] = SDLK_SCROLLOCK;
   181   keymap[DIKI_PRINT - DIKI_UNKNOWN] = SDLK_PRINT;
   182   keymap[DIKI_PAUSE - DIKI_UNKNOWN] = SDLK_PAUSE;
   183   keymap[DIKI_KP_DIV - DIKI_UNKNOWN] = SDLK_KP_DIVIDE;
   184   keymap[DIKI_KP_MULT - DIKI_UNKNOWN] = SDLK_KP_MULTIPLY;
   185   keymap[DIKI_KP_MINUS - DIKI_UNKNOWN] = SDLK_KP_MINUS;
   186   keymap[DIKI_KP_PLUS - DIKI_UNKNOWN] = SDLK_KP_PLUS;
   187   keymap[DIKI_KP_ENTER - DIKI_UNKNOWN] = SDLK_KP_ENTER;
   188 }
   189 
   190 
   191 static SDL_keysym *DirectFB_TranslateKey (DFBInputEvent *ev, SDL_keysym *keysym)
   192 {
   193   /* Set the keysym information */
   194   keysym->scancode = ev->key_id;
   195   keysym->mod = KMOD_NONE; /* FIXME */
   196   keysym->unicode = (DFB_KEY_TYPE (ev->key_symbol) == DIKT_UNICODE) ? ev->key_symbol : 0;
   197 
   198   if (ev->key_symbol > 0 && ev->key_symbol < 128)
   199     keysym->sym = ev->key_symbol;
   200   else
   201     keysym->sym = keymap[ev->key_id - DIKI_UNKNOWN];
   202 
   203   return keysym;
   204 }
   205 
   206 static int DirectFB_TranslateButton (DFBInputEvent *ev)
   207 {
   208   switch (ev->button)
   209     {
   210     case DIBI_LEFT:
   211       return 1;
   212     case DIBI_MIDDLE:
   213       return 2;
   214     case DIBI_RIGHT:
   215       return 3;
   216     default:
   217       return 0;
   218     }
   219 }