src/video/directfb/SDL_DirectFB_events.c
author Ryan C. Gordon <icculus@icculus.org>
Fri, 06 Jan 2006 13:20:10 +0000
changeset 1234 73676c1f56ee
parent 769 b8d311d90021
child 1312 c9b51268668f
permissions -rw-r--r--
For sanity's sake, removed the '&' when passing copy_row array to asm.
slouken@167
     1
/*
slouken@167
     2
	SDL - Simple DirectMedia Layer
slouken@769
     3
    Copyright (C) 1997-2004 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@464
   103
  keymap[DIKI_A - DIKI_UNKNOWN] = SDLK_a;
slouken@464
   104
  keymap[DIKI_B - DIKI_UNKNOWN] = SDLK_b;
slouken@464
   105
  keymap[DIKI_C - DIKI_UNKNOWN] = SDLK_c;
slouken@464
   106
  keymap[DIKI_D - DIKI_UNKNOWN] = SDLK_d;
slouken@464
   107
  keymap[DIKI_E - DIKI_UNKNOWN] = SDLK_e;
slouken@464
   108
  keymap[DIKI_F - DIKI_UNKNOWN] = SDLK_f;
slouken@464
   109
  keymap[DIKI_G - DIKI_UNKNOWN] = SDLK_g;
slouken@464
   110
  keymap[DIKI_H - DIKI_UNKNOWN] = SDLK_h;
slouken@464
   111
  keymap[DIKI_I - DIKI_UNKNOWN] = SDLK_i;
slouken@464
   112
  keymap[DIKI_J - DIKI_UNKNOWN] = SDLK_j;
slouken@464
   113
  keymap[DIKI_K - DIKI_UNKNOWN] = SDLK_k;
slouken@464
   114
  keymap[DIKI_L - DIKI_UNKNOWN] = SDLK_l;
slouken@464
   115
  keymap[DIKI_M - DIKI_UNKNOWN] = SDLK_m;
slouken@464
   116
  keymap[DIKI_N - DIKI_UNKNOWN] = SDLK_n;
slouken@464
   117
  keymap[DIKI_O - DIKI_UNKNOWN] = SDLK_o;
slouken@464
   118
  keymap[DIKI_P - DIKI_UNKNOWN] = SDLK_p;
slouken@464
   119
  keymap[DIKI_Q - DIKI_UNKNOWN] = SDLK_q;
slouken@464
   120
  keymap[DIKI_R - DIKI_UNKNOWN] = SDLK_r;
slouken@464
   121
  keymap[DIKI_S - DIKI_UNKNOWN] = SDLK_s;
slouken@464
   122
  keymap[DIKI_T - DIKI_UNKNOWN] = SDLK_t;
slouken@464
   123
  keymap[DIKI_U - DIKI_UNKNOWN] = SDLK_u;
slouken@464
   124
  keymap[DIKI_V - DIKI_UNKNOWN] = SDLK_v;
slouken@464
   125
  keymap[DIKI_W - DIKI_UNKNOWN] = SDLK_w;
slouken@464
   126
  keymap[DIKI_X - DIKI_UNKNOWN] = SDLK_x;
slouken@464
   127
  keymap[DIKI_Y - DIKI_UNKNOWN] = SDLK_y;
slouken@464
   128
  keymap[DIKI_Z - DIKI_UNKNOWN] = SDLK_z;
slouken@167
   129
  
slouken@464
   130
  keymap[DIKI_0 - DIKI_UNKNOWN] = SDLK_0;
slouken@464
   131
  keymap[DIKI_1 - DIKI_UNKNOWN] = SDLK_1;
slouken@464
   132
  keymap[DIKI_2 - DIKI_UNKNOWN] = SDLK_2;
slouken@464
   133
  keymap[DIKI_3 - DIKI_UNKNOWN] = SDLK_3;
slouken@464
   134
  keymap[DIKI_4 - DIKI_UNKNOWN] = SDLK_4;
slouken@464
   135
  keymap[DIKI_5 - DIKI_UNKNOWN] = SDLK_5;
slouken@464
   136
  keymap[DIKI_6 - DIKI_UNKNOWN] = SDLK_6;
slouken@464
   137
  keymap[DIKI_7 - DIKI_UNKNOWN] = SDLK_7;
slouken@464
   138
  keymap[DIKI_8 - DIKI_UNKNOWN] = SDLK_8;
slouken@464
   139
  keymap[DIKI_9 - DIKI_UNKNOWN] = SDLK_9;
slouken@167
   140
  
slouken@464
   141
  keymap[DIKI_F1 - DIKI_UNKNOWN] = SDLK_F1;
slouken@464
   142
  keymap[DIKI_F2 - DIKI_UNKNOWN] = SDLK_F2;
slouken@464
   143
  keymap[DIKI_F3 - DIKI_UNKNOWN] = SDLK_F3;
slouken@464
   144
  keymap[DIKI_F4 - DIKI_UNKNOWN] = SDLK_F4;
slouken@464
   145
  keymap[DIKI_F5 - DIKI_UNKNOWN] = SDLK_F5;
slouken@464
   146
  keymap[DIKI_F6 - DIKI_UNKNOWN] = SDLK_F6;
slouken@464
   147
  keymap[DIKI_F7 - DIKI_UNKNOWN] = SDLK_F7;
slouken@464
   148
  keymap[DIKI_F8 - DIKI_UNKNOWN] = SDLK_F8;
slouken@464
   149
  keymap[DIKI_F9 - DIKI_UNKNOWN] = SDLK_F9;
slouken@464
   150
  keymap[DIKI_F10 - DIKI_UNKNOWN] = SDLK_F10;
slouken@464
   151
  keymap[DIKI_F11 - DIKI_UNKNOWN] = SDLK_F11;
slouken@464
   152
  keymap[DIKI_F12 - DIKI_UNKNOWN] = SDLK_F12;
slouken@167
   153
  
slouken@464
   154
  keymap[DIKI_ESCAPE - DIKI_UNKNOWN] = SDLK_ESCAPE;
slouken@464
   155
  keymap[DIKI_LEFT - DIKI_UNKNOWN] = SDLK_LEFT;
slouken@464
   156
  keymap[DIKI_RIGHT - DIKI_UNKNOWN] = SDLK_RIGHT;
slouken@464
   157
  keymap[DIKI_UP - DIKI_UNKNOWN] = SDLK_UP;
slouken@464
   158
  keymap[DIKI_DOWN - DIKI_UNKNOWN] = SDLK_DOWN;
slouken@464
   159
  keymap[DIKI_CONTROL_L - DIKI_UNKNOWN] = SDLK_LCTRL;
slouken@464
   160
  keymap[DIKI_CONTROL_R - DIKI_UNKNOWN] = SDLK_RCTRL;
slouken@464
   161
  keymap[DIKI_SHIFT_L - DIKI_UNKNOWN] = SDLK_LSHIFT;
slouken@464
   162
  keymap[DIKI_SHIFT_R - DIKI_UNKNOWN] = SDLK_RSHIFT;
slouken@464
   163
  keymap[DIKI_ALT_L - DIKI_UNKNOWN] = SDLK_LALT;
slouken@464
   164
  keymap[DIKI_ALTGR - DIKI_UNKNOWN] = SDLK_RALT;
slouken@464
   165
  keymap[DIKI_TAB - DIKI_UNKNOWN] = SDLK_TAB;
slouken@464
   166
  keymap[DIKI_ENTER - DIKI_UNKNOWN] = SDLK_RETURN;
slouken@464
   167
  keymap[DIKI_SPACE - DIKI_UNKNOWN] = SDLK_SPACE;
slouken@464
   168
  keymap[DIKI_BACKSPACE - DIKI_UNKNOWN] = SDLK_BACKSPACE;
slouken@464
   169
  keymap[DIKI_INSERT - DIKI_UNKNOWN] = SDLK_INSERT;
slouken@464
   170
  keymap[DIKI_DELETE - DIKI_UNKNOWN] = SDLK_DELETE;
slouken@464
   171
  keymap[DIKI_HOME - DIKI_UNKNOWN] = SDLK_HOME;
slouken@464
   172
  keymap[DIKI_END - DIKI_UNKNOWN] = SDLK_END;
slouken@464
   173
  keymap[DIKI_PAGE_UP - DIKI_UNKNOWN] = SDLK_PAGEUP;
slouken@464
   174
  keymap[DIKI_PAGE_DOWN - DIKI_UNKNOWN] = SDLK_PAGEDOWN;
slouken@464
   175
  keymap[DIKI_CAPS_LOCK - DIKI_UNKNOWN] = SDLK_CAPSLOCK;
slouken@464
   176
  keymap[DIKI_NUM_LOCK - DIKI_UNKNOWN] = SDLK_NUMLOCK;
slouken@464
   177
  keymap[DIKI_SCROLL_LOCK - DIKI_UNKNOWN] = SDLK_SCROLLOCK;
slouken@464
   178
  keymap[DIKI_PRINT - DIKI_UNKNOWN] = SDLK_PRINT;
slouken@464
   179
  keymap[DIKI_PAUSE - DIKI_UNKNOWN] = SDLK_PAUSE;
slouken@464
   180
  keymap[DIKI_KP_DIV - DIKI_UNKNOWN] = SDLK_KP_DIVIDE;
slouken@464
   181
  keymap[DIKI_KP_MULT - DIKI_UNKNOWN] = SDLK_KP_MULTIPLY;
slouken@464
   182
  keymap[DIKI_KP_MINUS - DIKI_UNKNOWN] = SDLK_KP_MINUS;
slouken@464
   183
  keymap[DIKI_KP_PLUS - DIKI_UNKNOWN] = SDLK_KP_PLUS;
slouken@464
   184
  keymap[DIKI_KP_ENTER - DIKI_UNKNOWN] = SDLK_KP_ENTER;
slouken@167
   185
}
slouken@167
   186
slouken@167
   187
slouken@167
   188
static SDL_keysym *DirectFB_TranslateKey (DFBInputEvent *ev, SDL_keysym *keysym)
slouken@167
   189
{
slouken@167
   190
  /* Set the keysym information */
slouken@382
   191
  keysym->scancode = ev->key_id;
slouken@382
   192
  keysym->mod = KMOD_NONE; /* FIXME */
slouken@382
   193
  keysym->unicode = (DFB_KEY_TYPE (ev->key_symbol) == DIKT_UNICODE) ? ev->key_symbol : 0;
slouken@167
   194
slouken@382
   195
  if (ev->key_symbol > 0 && ev->key_symbol < 128)
slouken@382
   196
    keysym->sym = ev->key_symbol;
slouken@167
   197
  else
slouken@464
   198
    keysym->sym = keymap[ev->key_id - DIKI_UNKNOWN];
slouken@167
   199
slouken@167
   200
  return keysym;
slouken@167
   201
}
slouken@167
   202
slouken@167
   203
static int DirectFB_TranslateButton (DFBInputEvent *ev)
slouken@167
   204
{
slouken@167
   205
  switch (ev->button)
slouken@167
   206
    {
slouken@167
   207
    case DIBI_LEFT:
slouken@167
   208
      return 1;
slouken@167
   209
    case DIBI_MIDDLE:
slouken@167
   210
      return 2;
slouken@167
   211
    case DIBI_RIGHT:
slouken@167
   212
      return 3;
slouken@167
   213
    default:
slouken@167
   214
      return 0;
slouken@167
   215
    }
slouken@167
   216
}