src/video/directfb/SDL_DirectFB_events.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 26 Feb 2002 14:38:53 +0000
changeset 286 3ea69fd0b095
parent 252 e8157fcb3114
child 297 f6ffac90895c
permissions -rw-r--r--
Updated for DirectFB 0.9.9
slouken@167
     1
/*
slouken@167
     2
	SDL - Simple DirectMedia Layer
slouken@167
     3
	Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
slouken@167
     4
slouken@167
     5
	This library is free software; you can redistribute it and/or
slouken@167
     6
	modify it under the terms of the GNU Library General Public
slouken@167
     7
	License as published by the Free Software Foundation; either
slouken@167
     8
	version 2 of the License, or (at your option) any later version.
slouken@167
     9
slouken@167
    10
	This library is distributed in the hope that it will be useful,
slouken@167
    11
	but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@167
    12
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@167
    13
	Library General Public License for more details.
slouken@167
    14
slouken@167
    15
	You should have received a copy of the GNU Library General Public
slouken@167
    16
	License along with this library; if not, write to the Free
slouken@167
    17
	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@167
    18
slouken@167
    19
	Sam Lantinga
slouken@252
    20
	slouken@libsdl.org
slouken@167
    21
*/
slouken@167
    22
slouken@167
    23
#ifdef SAVE_RCSID
slouken@167
    24
static char rcsid =
slouken@167
    25
 "@(#) $Id$";
slouken@167
    26
#endif
slouken@167
    27
slouken@167
    28
/* Handle the event stream, converting DirectFB input events into SDL events */
slouken@167
    29
slouken@167
    30
#include <sys/types.h>
slouken@167
    31
#include <sys/time.h>
slouken@167
    32
#include <stdlib.h>
slouken@167
    33
#include <stdio.h>
slouken@167
    34
#include <unistd.h>
slouken@167
    35
#include <fcntl.h>
slouken@167
    36
#include <termios.h>
slouken@167
    37
slouken@167
    38
#include <directfb.h>
slouken@167
    39
slouken@167
    40
#include "SDL.h"
slouken@167
    41
#include "SDL_sysevents.h"
slouken@167
    42
#include "SDL_sysvideo.h"
slouken@167
    43
#include "SDL_events_c.h"
slouken@167
    44
#include "SDL_DirectFB_video.h"
slouken@167
    45
#include "SDL_DirectFB_events.h"
slouken@167
    46
slouken@167
    47
/* The translation tables from a DirectFB keycode to a SDL keysym */
slouken@167
    48
static SDLKey keymap[256];
slouken@167
    49
static SDL_keysym *DirectFB_TranslateKey (DFBInputEvent *ev, SDL_keysym *keysym);
slouken@167
    50
static int DirectFB_TranslateButton (DFBInputEvent *ev);
slouken@167
    51
slouken@167
    52
static int posted = 0;
slouken@167
    53
slouken@167
    54
slouken@167
    55
void DirectFB_PumpEvents (_THIS)
slouken@167
    56
{
slouken@167
    57
  DFBInputEvent evt;
slouken@167
    58
slouken@286
    59
  while (HIDDEN->eventbuffer->GetEvent (HIDDEN->eventbuffer,
slouken@286
    60
                                        DFB_EVENT (&evt)) == DFB_OK)
slouken@167
    61
    {
slouken@167
    62
      SDL_keysym keysym;
slouken@167
    63
slouken@167
    64
      switch (evt.type)
slouken@167
    65
        {
slouken@167
    66
        case DIET_BUTTONPRESS:
slouken@167
    67
          posted += SDL_PrivateMouseButton(SDL_PRESSED,
slouken@167
    68
                                           DirectFB_TranslateButton (&evt), 0, 0);
slouken@167
    69
          break;
slouken@167
    70
        case DIET_BUTTONRELEASE:
slouken@167
    71
          posted += SDL_PrivateMouseButton(SDL_RELEASED,
slouken@167
    72
                                           DirectFB_TranslateButton (&evt), 0, 0);
slouken@167
    73
          break;
slouken@167
    74
        case DIET_KEYPRESS:
slouken@167
    75
          posted += SDL_PrivateKeyboard(SDL_PRESSED, DirectFB_TranslateKey(&evt, &keysym));
slouken@167
    76
          break;
slouken@167
    77
        case DIET_KEYRELEASE:
slouken@167
    78
          posted += SDL_PrivateKeyboard(SDL_RELEASED, DirectFB_TranslateKey(&evt, &keysym));
slouken@167
    79
          break;
slouken@167
    80
        case DIET_AXISMOTION:
slouken@167
    81
          if (evt.flags & DIEF_AXISREL)
slouken@167
    82
            {
slouken@167
    83
              if (evt.axis == DIAI_X)
slouken@167
    84
                posted += SDL_PrivateMouseMotion(0, 1, evt.axisrel, 0);
slouken@167
    85
              else if (evt.axis == DIAI_Y)
slouken@167
    86
                posted += SDL_PrivateMouseMotion(0, 1, 0, evt.axisrel);
slouken@167
    87
            }
slouken@167
    88
          break;
slouken@167
    89
        default:
slouken@167
    90
          ;
slouken@167
    91
        }
slouken@167
    92
    }
slouken@167
    93
}
slouken@167
    94
slouken@167
    95
void DirectFB_InitOSKeymap (_THIS)
slouken@167
    96
{
slouken@167
    97
  int i;
slouken@167
    98
	
slouken@167
    99
  /* Initialize the DirectFB key translation table */
slouken@167
   100
  for (i=0; i<SDL_TABLESIZE(keymap); ++i)
slouken@167
   101
    keymap[i] = SDLK_UNKNOWN;
slouken@167
   102
slouken@167
   103
  keymap[DIKC_A] = SDLK_a;
slouken@167
   104
  keymap[DIKC_B] = SDLK_b;
slouken@167
   105
  keymap[DIKC_C] = SDLK_c;
slouken@167
   106
  keymap[DIKC_D] = SDLK_d;
slouken@167
   107
  keymap[DIKC_E] = SDLK_e;
slouken@167
   108
  keymap[DIKC_F] = SDLK_f;
slouken@167
   109
  keymap[DIKC_G] = SDLK_g;
slouken@167
   110
  keymap[DIKC_H] = SDLK_h;
slouken@167
   111
  keymap[DIKC_I] = SDLK_i;
slouken@167
   112
  keymap[DIKC_J] = SDLK_j;
slouken@167
   113
  keymap[DIKC_K] = SDLK_k;
slouken@167
   114
  keymap[DIKC_L] = SDLK_l;
slouken@167
   115
  keymap[DIKC_M] = SDLK_m;
slouken@167
   116
  keymap[DIKC_N] = SDLK_n;
slouken@167
   117
  keymap[DIKC_O] = SDLK_o;
slouken@167
   118
  keymap[DIKC_P] = SDLK_p;
slouken@167
   119
  keymap[DIKC_Q] = SDLK_q;
slouken@167
   120
  keymap[DIKC_R] = SDLK_r;
slouken@167
   121
  keymap[DIKC_S] = SDLK_s;
slouken@167
   122
  keymap[DIKC_T] = SDLK_t;
slouken@167
   123
  keymap[DIKC_U] = SDLK_u;
slouken@167
   124
  keymap[DIKC_V] = SDLK_v;
slouken@167
   125
  keymap[DIKC_W] = SDLK_w;
slouken@167
   126
  keymap[DIKC_X] = SDLK_x;
slouken@167
   127
  keymap[DIKC_Y] = SDLK_y;
slouken@167
   128
  keymap[DIKC_Z] = SDLK_z;
slouken@167
   129
  
slouken@167
   130
  keymap[DIKC_0] = SDLK_0;
slouken@167
   131
  keymap[DIKC_1] = SDLK_1;
slouken@167
   132
  keymap[DIKC_2] = SDLK_2;
slouken@167
   133
  keymap[DIKC_3] = SDLK_3;
slouken@167
   134
  keymap[DIKC_4] = SDLK_4;
slouken@167
   135
  keymap[DIKC_5] = SDLK_5;
slouken@167
   136
  keymap[DIKC_6] = SDLK_6;
slouken@167
   137
  keymap[DIKC_7] = SDLK_7;
slouken@167
   138
  keymap[DIKC_8] = SDLK_8;
slouken@167
   139
  keymap[DIKC_9] = SDLK_9;
slouken@167
   140
  
slouken@167
   141
  keymap[DIKC_F1] = SDLK_F1;
slouken@167
   142
  keymap[DIKC_F2] = SDLK_F2;
slouken@167
   143
  keymap[DIKC_F3] = SDLK_F3;
slouken@167
   144
  keymap[DIKC_F4] = SDLK_F4;
slouken@167
   145
  keymap[DIKC_F5] = SDLK_F5;
slouken@167
   146
  keymap[DIKC_F6] = SDLK_F6;
slouken@167
   147
  keymap[DIKC_F7] = SDLK_F7;
slouken@167
   148
  keymap[DIKC_F8] = SDLK_F8;
slouken@167
   149
  keymap[DIKC_F9] = SDLK_F9;
slouken@167
   150
  keymap[DIKC_F10] = SDLK_F10;
slouken@167
   151
  keymap[DIKC_F11] = SDLK_F11;
slouken@167
   152
  keymap[DIKC_F12] = SDLK_F12;
slouken@167
   153
  
slouken@167
   154
  keymap[DIKC_ESCAPE] = SDLK_ESCAPE;
slouken@167
   155
  keymap[DIKC_LEFT] = SDLK_LEFT;
slouken@167
   156
  keymap[DIKC_RIGHT] = SDLK_RIGHT;
slouken@167
   157
  keymap[DIKC_UP] = SDLK_UP;
slouken@167
   158
  keymap[DIKC_DOWN] = SDLK_DOWN;
slouken@167
   159
  keymap[DIKC_CTRL] = SDLK_LCTRL;
slouken@167
   160
  keymap[DIKC_SHIFT] = SDLK_LSHIFT;
slouken@167
   161
  keymap[DIKC_ALT] = SDLK_LALT;
slouken@167
   162
  keymap[DIKC_ALTGR] = SDLK_RALT;
slouken@167
   163
  keymap[DIKC_TAB] = SDLK_TAB;
slouken@167
   164
  keymap[DIKC_ENTER] = SDLK_RETURN;
slouken@167
   165
  keymap[DIKC_SPACE] = SDLK_SPACE;
slouken@167
   166
  keymap[DIKC_BACKSPACE] = SDLK_BACKSPACE;
slouken@167
   167
  keymap[DIKC_INSERT] = SDLK_INSERT;
slouken@167
   168
  keymap[DIKC_DELETE] = SDLK_DELETE;
slouken@167
   169
  keymap[DIKC_HOME] = SDLK_HOME;
slouken@167
   170
  keymap[DIKC_END] = SDLK_END;
slouken@167
   171
  keymap[DIKC_PAGEUP] = SDLK_PAGEUP;
slouken@167
   172
  keymap[DIKC_PAGEDOWN] = SDLK_PAGEDOWN;
slouken@167
   173
  keymap[DIKC_CAPSLOCK] = SDLK_CAPSLOCK;
slouken@167
   174
  keymap[DIKC_NUMLOCK] = SDLK_NUMLOCK;
slouken@167
   175
  keymap[DIKC_SCRLOCK] = SDLK_SCROLLOCK;
slouken@167
   176
  keymap[DIKC_PRINT] = SDLK_PRINT;
slouken@167
   177
  keymap[DIKC_PAUSE] = SDLK_PAUSE;
slouken@167
   178
  keymap[DIKC_KP_DIV] = SDLK_KP_DIVIDE;
slouken@167
   179
  keymap[DIKC_KP_MULT] = SDLK_KP_MULTIPLY;
slouken@167
   180
  keymap[DIKC_KP_MINUS] = SDLK_KP_MINUS;
slouken@167
   181
  keymap[DIKC_KP_PLUS] = SDLK_KP_PLUS;
slouken@167
   182
  keymap[DIKC_KP_ENTER] = SDLK_KP_ENTER;
slouken@167
   183
  
slouken@167
   184
  keymap[DIKC_OK] = SDLK_RETURN;
slouken@167
   185
  keymap[DIKC_CANCEL] = SDLK_BREAK;
slouken@167
   186
  keymap[DIKC_CLEAR] = SDLK_DELETE;
slouken@167
   187
  keymap[DIKC_POWER] = SDLK_POWER;
slouken@167
   188
  keymap[DIKC_POWER2] = SDLK_POWER;
slouken@167
   189
  keymap[DIKC_MENU] = SDLK_MENU;
slouken@167
   190
  keymap[DIKC_HELP] = SDLK_HELP;
slouken@167
   191
  keymap[DIKC_BACK] = SDLK_ESCAPE;
slouken@167
   192
}
slouken@167
   193
slouken@167
   194
slouken@167
   195
static SDL_keysym *DirectFB_TranslateKey (DFBInputEvent *ev, SDL_keysym *keysym)
slouken@167
   196
{
slouken@167
   197
  /* Set the keysym information */
slouken@167
   198
  keysym->scancode = ev->keycode;
slouken@167
   199
  keysym->mod = KMOD_NONE;
slouken@167
   200
  keysym->unicode = 0;
slouken@167
   201
slouken@167
   202
  if (ev->key_ascii > 0 && ev->key_ascii < 128)
slouken@167
   203
    keysym->sym = ev->key_ascii;
slouken@167
   204
  else
slouken@167
   205
    keysym->sym = keymap[ev->keycode];
slouken@167
   206
slouken@167
   207
  return keysym;
slouken@167
   208
}
slouken@167
   209
slouken@167
   210
static int DirectFB_TranslateButton (DFBInputEvent *ev)
slouken@167
   211
{
slouken@167
   212
  switch (ev->button)
slouken@167
   213
    {
slouken@167
   214
    case DIBI_LEFT:
slouken@167
   215
      return 1;
slouken@167
   216
    case DIBI_MIDDLE:
slouken@167
   217
      return 2;
slouken@167
   218
    case DIBI_RIGHT:
slouken@167
   219
      return 3;
slouken@167
   220
    default:
slouken@167
   221
      return 0;
slouken@167
   222
    }
slouken@167
   223
}