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