src/video/directfb/SDL_DirectFB_events.c
changeset 167 cb384ef627f6
child 252 e8157fcb3114
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/video/directfb/SDL_DirectFB_events.c	Tue Sep 04 22:53:46 2001 +0000
     1.3 @@ -0,0 +1,222 @@
     1.4 +/*
     1.5 +	SDL - Simple DirectMedia Layer
     1.6 +	Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     1.7 +
     1.8 +	This library is free software; you can redistribute it and/or
     1.9 +	modify it under the terms of the GNU Library General Public
    1.10 +	License as published by the Free Software Foundation; either
    1.11 +	version 2 of the License, or (at your option) any later version.
    1.12 +
    1.13 +	This library is distributed in the hope that it will be useful,
    1.14 +	but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 +	Library General Public License for more details.
    1.17 +
    1.18 +	You should have received a copy of the GNU Library General Public
    1.19 +	License along with this library; if not, write to the Free
    1.20 +	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.21 +
    1.22 +	Sam Lantinga
    1.23 +	slouken@devolution.com
    1.24 +*/
    1.25 +
    1.26 +#ifdef SAVE_RCSID
    1.27 +static char rcsid =
    1.28 + "@(#) $Id$";
    1.29 +#endif
    1.30 +
    1.31 +/* Handle the event stream, converting DirectFB input events into SDL events */
    1.32 +
    1.33 +#include <sys/types.h>
    1.34 +#include <sys/time.h>
    1.35 +#include <stdlib.h>
    1.36 +#include <stdio.h>
    1.37 +#include <unistd.h>
    1.38 +#include <fcntl.h>
    1.39 +#include <termios.h>
    1.40 +
    1.41 +#include <directfb.h>
    1.42 +
    1.43 +#include "SDL.h"
    1.44 +#include "SDL_sysevents.h"
    1.45 +#include "SDL_sysvideo.h"
    1.46 +#include "SDL_events_c.h"
    1.47 +#include "SDL_DirectFB_video.h"
    1.48 +#include "SDL_DirectFB_events.h"
    1.49 +
    1.50 +/* The translation tables from a DirectFB keycode to a SDL keysym */
    1.51 +static SDLKey keymap[256];
    1.52 +static SDL_keysym *DirectFB_TranslateKey (DFBInputEvent *ev, SDL_keysym *keysym);
    1.53 +static int DirectFB_TranslateButton (DFBInputEvent *ev);
    1.54 +
    1.55 +static int posted = 0;
    1.56 +
    1.57 +
    1.58 +void DirectFB_PumpEvents (_THIS)
    1.59 +{
    1.60 +  DFBInputEvent evt;
    1.61 +
    1.62 +  while (HIDDEN->inputbuffer->GetEvent (HIDDEN->inputbuffer, &evt) == DFB_OK)
    1.63 +    {
    1.64 +      SDL_keysym keysym;
    1.65 +
    1.66 +      switch (evt.type)
    1.67 +        {
    1.68 +        case DIET_BUTTONPRESS:
    1.69 +          posted += SDL_PrivateMouseButton(SDL_PRESSED,
    1.70 +                                           DirectFB_TranslateButton (&evt), 0, 0);
    1.71 +          break;
    1.72 +        case DIET_BUTTONRELEASE:
    1.73 +          posted += SDL_PrivateMouseButton(SDL_RELEASED,
    1.74 +                                           DirectFB_TranslateButton (&evt), 0, 0);
    1.75 +          break;
    1.76 +        case DIET_KEYPRESS:
    1.77 +          posted += SDL_PrivateKeyboard(SDL_PRESSED, DirectFB_TranslateKey(&evt, &keysym));
    1.78 +          break;
    1.79 +        case DIET_KEYRELEASE:
    1.80 +          posted += SDL_PrivateKeyboard(SDL_RELEASED, DirectFB_TranslateKey(&evt, &keysym));
    1.81 +          break;
    1.82 +        case DIET_AXISMOTION:
    1.83 +          if (evt.flags & DIEF_AXISREL)
    1.84 +            {
    1.85 +              if (evt.axis == DIAI_X)
    1.86 +                posted += SDL_PrivateMouseMotion(0, 1, evt.axisrel, 0);
    1.87 +              else if (evt.axis == DIAI_Y)
    1.88 +                posted += SDL_PrivateMouseMotion(0, 1, 0, evt.axisrel);
    1.89 +            }
    1.90 +          break;
    1.91 +        default:
    1.92 +          ;
    1.93 +        }
    1.94 +    }
    1.95 +}
    1.96 +
    1.97 +void DirectFB_InitOSKeymap (_THIS)
    1.98 +{
    1.99 +  int i;
   1.100 +	
   1.101 +  /* Initialize the DirectFB key translation table */
   1.102 +  for (i=0; i<SDL_TABLESIZE(keymap); ++i)
   1.103 +    keymap[i] = SDLK_UNKNOWN;
   1.104 +
   1.105 +  keymap[DIKC_A] = SDLK_a;
   1.106 +  keymap[DIKC_B] = SDLK_b;
   1.107 +  keymap[DIKC_C] = SDLK_c;
   1.108 +  keymap[DIKC_D] = SDLK_d;
   1.109 +  keymap[DIKC_E] = SDLK_e;
   1.110 +  keymap[DIKC_F] = SDLK_f;
   1.111 +  keymap[DIKC_G] = SDLK_g;
   1.112 +  keymap[DIKC_H] = SDLK_h;
   1.113 +  keymap[DIKC_I] = SDLK_i;
   1.114 +  keymap[DIKC_J] = SDLK_j;
   1.115 +  keymap[DIKC_K] = SDLK_k;
   1.116 +  keymap[DIKC_L] = SDLK_l;
   1.117 +  keymap[DIKC_M] = SDLK_m;
   1.118 +  keymap[DIKC_N] = SDLK_n;
   1.119 +  keymap[DIKC_O] = SDLK_o;
   1.120 +  keymap[DIKC_P] = SDLK_p;
   1.121 +  keymap[DIKC_Q] = SDLK_q;
   1.122 +  keymap[DIKC_R] = SDLK_r;
   1.123 +  keymap[DIKC_S] = SDLK_s;
   1.124 +  keymap[DIKC_T] = SDLK_t;
   1.125 +  keymap[DIKC_U] = SDLK_u;
   1.126 +  keymap[DIKC_V] = SDLK_v;
   1.127 +  keymap[DIKC_W] = SDLK_w;
   1.128 +  keymap[DIKC_X] = SDLK_x;
   1.129 +  keymap[DIKC_Y] = SDLK_y;
   1.130 +  keymap[DIKC_Z] = SDLK_z;
   1.131 +  
   1.132 +  keymap[DIKC_0] = SDLK_0;
   1.133 +  keymap[DIKC_1] = SDLK_1;
   1.134 +  keymap[DIKC_2] = SDLK_2;
   1.135 +  keymap[DIKC_3] = SDLK_3;
   1.136 +  keymap[DIKC_4] = SDLK_4;
   1.137 +  keymap[DIKC_5] = SDLK_5;
   1.138 +  keymap[DIKC_6] = SDLK_6;
   1.139 +  keymap[DIKC_7] = SDLK_7;
   1.140 +  keymap[DIKC_8] = SDLK_8;
   1.141 +  keymap[DIKC_9] = SDLK_9;
   1.142 +  
   1.143 +  keymap[DIKC_F1] = SDLK_F1;
   1.144 +  keymap[DIKC_F2] = SDLK_F2;
   1.145 +  keymap[DIKC_F3] = SDLK_F3;
   1.146 +  keymap[DIKC_F4] = SDLK_F4;
   1.147 +  keymap[DIKC_F5] = SDLK_F5;
   1.148 +  keymap[DIKC_F6] = SDLK_F6;
   1.149 +  keymap[DIKC_F7] = SDLK_F7;
   1.150 +  keymap[DIKC_F8] = SDLK_F8;
   1.151 +  keymap[DIKC_F9] = SDLK_F9;
   1.152 +  keymap[DIKC_F10] = SDLK_F10;
   1.153 +  keymap[DIKC_F11] = SDLK_F11;
   1.154 +  keymap[DIKC_F12] = SDLK_F12;
   1.155 +  
   1.156 +  keymap[DIKC_ESCAPE] = SDLK_ESCAPE;
   1.157 +  keymap[DIKC_LEFT] = SDLK_LEFT;
   1.158 +  keymap[DIKC_RIGHT] = SDLK_RIGHT;
   1.159 +  keymap[DIKC_UP] = SDLK_UP;
   1.160 +  keymap[DIKC_DOWN] = SDLK_DOWN;
   1.161 +  keymap[DIKC_CTRL] = SDLK_LCTRL;
   1.162 +  keymap[DIKC_SHIFT] = SDLK_LSHIFT;
   1.163 +  keymap[DIKC_ALT] = SDLK_LALT;
   1.164 +  keymap[DIKC_ALTGR] = SDLK_RALT;
   1.165 +  keymap[DIKC_TAB] = SDLK_TAB;
   1.166 +  keymap[DIKC_ENTER] = SDLK_RETURN;
   1.167 +  keymap[DIKC_SPACE] = SDLK_SPACE;
   1.168 +  keymap[DIKC_BACKSPACE] = SDLK_BACKSPACE;
   1.169 +  keymap[DIKC_INSERT] = SDLK_INSERT;
   1.170 +  keymap[DIKC_DELETE] = SDLK_DELETE;
   1.171 +  keymap[DIKC_HOME] = SDLK_HOME;
   1.172 +  keymap[DIKC_END] = SDLK_END;
   1.173 +  keymap[DIKC_PAGEUP] = SDLK_PAGEUP;
   1.174 +  keymap[DIKC_PAGEDOWN] = SDLK_PAGEDOWN;
   1.175 +  keymap[DIKC_CAPSLOCK] = SDLK_CAPSLOCK;
   1.176 +  keymap[DIKC_NUMLOCK] = SDLK_NUMLOCK;
   1.177 +  keymap[DIKC_SCRLOCK] = SDLK_SCROLLOCK;
   1.178 +  keymap[DIKC_PRINT] = SDLK_PRINT;
   1.179 +  keymap[DIKC_PAUSE] = SDLK_PAUSE;
   1.180 +  keymap[DIKC_KP_DIV] = SDLK_KP_DIVIDE;
   1.181 +  keymap[DIKC_KP_MULT] = SDLK_KP_MULTIPLY;
   1.182 +  keymap[DIKC_KP_MINUS] = SDLK_KP_MINUS;
   1.183 +  keymap[DIKC_KP_PLUS] = SDLK_KP_PLUS;
   1.184 +  keymap[DIKC_KP_ENTER] = SDLK_KP_ENTER;
   1.185 +  
   1.186 +  keymap[DIKC_OK] = SDLK_RETURN;
   1.187 +  keymap[DIKC_CANCEL] = SDLK_BREAK;
   1.188 +  keymap[DIKC_CLEAR] = SDLK_DELETE;
   1.189 +  keymap[DIKC_POWER] = SDLK_POWER;
   1.190 +  keymap[DIKC_POWER2] = SDLK_POWER;
   1.191 +  keymap[DIKC_MENU] = SDLK_MENU;
   1.192 +  keymap[DIKC_HELP] = SDLK_HELP;
   1.193 +  keymap[DIKC_BACK] = SDLK_ESCAPE;
   1.194 +}
   1.195 +
   1.196 +
   1.197 +static SDL_keysym *DirectFB_TranslateKey (DFBInputEvent *ev, SDL_keysym *keysym)
   1.198 +{
   1.199 +  /* Set the keysym information */
   1.200 +  keysym->scancode = ev->keycode;
   1.201 +  keysym->mod = KMOD_NONE;
   1.202 +  keysym->unicode = 0;
   1.203 +
   1.204 +  if (ev->key_ascii > 0 && ev->key_ascii < 128)
   1.205 +    keysym->sym = ev->key_ascii;
   1.206 +  else
   1.207 +    keysym->sym = keymap[ev->keycode];
   1.208 +
   1.209 +  return keysym;
   1.210 +}
   1.211 +
   1.212 +static int DirectFB_TranslateButton (DFBInputEvent *ev)
   1.213 +{
   1.214 +  switch (ev->button)
   1.215 +    {
   1.216 +    case DIBI_LEFT:
   1.217 +      return 1;
   1.218 +    case DIBI_MIDDLE:
   1.219 +      return 2;
   1.220 +    case DIBI_RIGHT:
   1.221 +      return 3;
   1.222 +    default:
   1.223 +      return 0;
   1.224 +    }
   1.225 +}