src/video/directfb/SDL_DirectFB_events.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 02 Mar 2013 20:44:16 -0800
changeset 6950 1ddb72193079
parent 6885 700f1b25f77f
child 7191 75360622e65f
permissions -rw-r--r--
Added a mouse ID to the mouse events, which set to the special value SDL_TOUCH_MOUSEID for mouse events simulated by touch input.
slouken@167
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@6885
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
slouken@167
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@167
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@167
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@167
    20
*/
slouken@6044
    21
#include "SDL_config.h"
slouken@6044
    22
slouken@6044
    23
#if SDL_VIDEO_DRIVER_DIRECTFB
slouken@167
    24
slouken@167
    25
/* Handle the event stream, converting DirectFB input events into SDL events */
slouken@167
    26
slouken@5199
    27
#include "SDL_DirectFB_video.h"
slouken@5199
    28
#include "SDL_DirectFB_window.h"
slouken@5199
    29
#include "SDL_DirectFB_modes.h"
slouken@167
    30
slouken@5199
    31
#include "SDL_syswm.h"
slouken@5199
    32
slouken@5199
    33
#include "../../events/SDL_mouse_c.h"
slouken@5199
    34
#include "../../events/SDL_keyboard_c.h"
slouken@5199
    35
#include "../../events/SDL_windowevents_c.h"
slouken@1361
    36
#include "../../events/SDL_events_c.h"
slouken@2721
    37
#include "../../events/scancodes_linux.h"
slouken@5199
    38
#include "../../events/scancodes_xfree86.h"
slouken@5199
    39
slouken@167
    40
#include "SDL_DirectFB_events.h"
slouken@167
    41
slouken@4568
    42
#if USE_MULTI_API
slouken@6950
    43
#define SDL_SendMouseMotion_ex(w, id, relative, x, y, p) SDL_SendMouseMotion(w, id, relative, x, y, p)
slouken@6950
    44
#define SDL_SendMouseButton_ex(w, id, state, button) SDL_SendMouseButton(w, id, state, button)
slouken@4568
    45
#define SDL_SendKeyboardKey_ex(id, state, scancode) SDL_SendKeyboardKey(id, state, scancode)
slouken@4568
    46
#define SDL_SendKeyboardText_ex(id, text) SDL_SendKeyboardText(id, text)
slouken@4568
    47
#else
slouken@6950
    48
#define SDL_SendMouseMotion_ex(w, id, relative, x, y, p) SDL_SendMouseMotion(w, id, relative, x, y)
slouken@6950
    49
#define SDL_SendMouseButton_ex(w, id, state, button) SDL_SendMouseButton(w, id, state, button)
slouken@4568
    50
#define SDL_SendKeyboardKey_ex(id, state, scancode) SDL_SendKeyboardKey(state, scancode)
slouken@4568
    51
#define SDL_SendKeyboardText_ex(id, text) SDL_SendKeyboardText(text)
slouken@4568
    52
#endif
slouken@4568
    53
slouken@4636
    54
typedef struct _cb_data cb_data;
slouken@4636
    55
struct _cb_data 
slouken@4636
    56
{
slouken@4636
    57
	DFB_DeviceData *devdata;	
slouken@4636
    58
	int sys_ids;
slouken@4636
    59
	int sys_kbd;
slouken@4636
    60
};
slouken@4568
    61
slouken@167
    62
/* The translation tables from a DirectFB keycode to a SDL keysym */
slouken@5218
    63
static SDL_Scancode oskeymap[256];
slouken@4636
    64
slouken@2226
    65
slouken@5218
    66
static SDL_Keysym *DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt,
slouken@5218
    67
                                         SDL_Keysym * keysym);
slouken@5218
    68
static SDL_Keysym *DirectFB_TranslateKeyInputEvent(_THIS, DFBInputEvent * evt,
slouken@5218
    69
                                                   SDL_Keysym * keysym);
slouken@167
    70
slouken@5218
    71
static void DirectFB_InitOSKeymap(_THIS, SDL_Scancode * keypmap, int numkeys);
slouken@2226
    72
static int DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button);
slouken@167
    73
slouken@5199
    74
static void UnicodeToUtf8( Uint16 w , char *utf8buf)
slouken@2721
    75
{
slouken@5199
    76
        unsigned char *utf8s = (unsigned char *) utf8buf;
slouken@5199
    77
        
slouken@5199
    78
    if ( w < 0x0080 ) {
slouken@5199
    79
        utf8s[0] = ( unsigned char ) w;
slouken@5199
    80
        utf8s[1] = 0;
slouken@5199
    81
    }
slouken@5199
    82
    else if ( w < 0x0800 ) {
slouken@5199
    83
        utf8s[0] = 0xc0 | (( w ) >> 6 );
slouken@5199
    84
        utf8s[1] = 0x80 | (( w ) & 0x3f );
slouken@5199
    85
        utf8s[2] = 0;  
slouken@5199
    86
    }
slouken@5199
    87
    else {
slouken@5199
    88
        utf8s[0] = 0xe0 | (( w ) >> 12 );
slouken@5199
    89
        utf8s[1] = 0x80 | (( ( w ) >> 6 ) & 0x3f );
slouken@5199
    90
        utf8s[2] = 0x80 | (( w ) & 0x3f );
slouken@5199
    91
        utf8s[3] = 0;
slouken@5199
    92
    }    
slouken@2721
    93
}
slouken@2721
    94
slouken@2860
    95
static void
slouken@3685
    96
FocusAllMice(_THIS, SDL_Window *window)
slouken@2860
    97
{
slouken@4568
    98
#if USE_MULTI_API
slouken@2860
    99
    SDL_DFB_DEVICEDATA(_this);
slouken@2860
   100
    int index;
slouken@2860
   101
slouken@2860
   102
    for (index = 0; index < devdata->num_mice; index++)
slouken@2860
   103
        SDL_SetMouseFocus(devdata->mouse_id[index], id);
slouken@4568
   104
#else
slouken@4568
   105
    SDL_SetMouseFocus(window);
slouken@4568
   106
#endif
slouken@2860
   107
}
slouken@2860
   108
slouken@2860
   109
slouken@2860
   110
static void
slouken@3685
   111
FocusAllKeyboards(_THIS, SDL_Window *window)
slouken@2860
   112
{
slouken@4568
   113
#if USE_MULTI_API
slouken@2860
   114
    SDL_DFB_DEVICEDATA(_this);
slouken@2860
   115
    int index;
slouken@2860
   116
slouken@2860
   117
    for (index = 0; index < devdata->num_keyboard; index++)
slouken@2860
   118
        SDL_SetKeyboardFocus(index, id);
slouken@4568
   119
#else
slouken@4568
   120
    SDL_SetKeyboardFocus(window);
slouken@4568
   121
#endif
slouken@2860
   122
}
slouken@2860
   123
slouken@2860
   124
static void
slouken@2860
   125
MotionAllMice(_THIS, int x, int y)
slouken@2860
   126
{
slouken@4568
   127
#if USE_MULTI_API
slouken@2860
   128
    SDL_DFB_DEVICEDATA(_this);
slouken@2860
   129
    int index;
slouken@2860
   130
slouken@2860
   131
    for (index = 0; index < devdata->num_mice; index++) {
slouken@2860
   132
        SDL_Mouse *mouse = SDL_GetMouse(index);
slouken@2860
   133
        mouse->x = mouse->last_x = x;
slouken@2860
   134
        mouse->y = mouse->last_y = y;
slouken@2860
   135
        //SDL_SendMouseMotion(devdata->mouse_id[index], 0, x, y, 0);
slouken@2860
   136
    }
slouken@4568
   137
#endif
slouken@2860
   138
}
slouken@2860
   139
slouken@2860
   140
static int
slouken@2860
   141
KbdIndex(_THIS, int id)
slouken@2860
   142
{
slouken@2860
   143
    SDL_DFB_DEVICEDATA(_this);
slouken@2860
   144
    int index;
slouken@2860
   145
slouken@2860
   146
    for (index = 0; index < devdata->num_keyboard; index++) {
slouken@2860
   147
        if (devdata->keyboard[index].id == id)
slouken@2860
   148
            return index;
slouken@2860
   149
    }
slouken@2860
   150
    return -1;
slouken@2860
   151
}
slouken@2860
   152
couriersud@3023
   153
static int
couriersud@3023
   154
ClientXY(DFB_WindowData * p, int *x, int *y)
couriersud@3023
   155
{
couriersud@3023
   156
    int cx, cy;
couriersud@3023
   157
couriersud@3023
   158
    cx = *x;
couriersud@3023
   159
    cy = *y;
couriersud@3023
   160
couriersud@3023
   161
    cx -= p->client.x;
couriersud@3023
   162
    cy -= p->client.y;
couriersud@3023
   163
couriersud@3023
   164
    if (cx < 0 || cy < 0)
couriersud@3023
   165
        return 0;
couriersud@3023
   166
    if (cx >= p->client.w || cy >= p->client.h)
couriersud@3023
   167
        return 0;
couriersud@3023
   168
    *x = cx;
couriersud@3023
   169
    *y = cy;
couriersud@3023
   170
    return 1;
couriersud@3023
   171
}
couriersud@3023
   172
couriersud@3023
   173
static void
slouken@5199
   174
ProcessWindowEvent(_THIS, SDL_Window *sdlwin, DFBWindowEvent * evt)
couriersud@3023
   175
{
couriersud@3023
   176
    SDL_DFB_DEVICEDATA(_this);
slouken@5199
   177
    SDL_DFB_WINDOWDATA(sdlwin);
slouken@5218
   178
    SDL_Keysym keysym;
slouken@5199
   179
    char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
couriersud@3023
   180
couriersud@3023
   181
    if (evt->clazz == DFEC_WINDOW) {
couriersud@3023
   182
        switch (evt->type) {
couriersud@3023
   183
        case DWET_BUTTONDOWN:
slouken@5199
   184
            if (ClientXY(windata, &evt->x, &evt->y)) {
couriersud@3023
   185
                if (!devdata->use_linux_input) {
slouken@5199
   186
                    SDL_SendMouseMotion_ex(sdlwin, devdata->mouse_id[0], 0, evt->x,
couriersud@3023
   187
                                        evt->y, 0);
slouken@5199
   188
                    SDL_SendMouseButton_ex(sdlwin, devdata->mouse_id[0],
couriersud@3023
   189
                                        SDL_PRESSED,
couriersud@3023
   190
                                        DirectFB_TranslateButton
couriersud@3023
   191
                                        (evt->button));
couriersud@3023
   192
                } else {
couriersud@3023
   193
                    MotionAllMice(_this, evt->x, evt->y);
couriersud@3023
   194
                }
couriersud@3023
   195
            }
couriersud@3023
   196
            break;
couriersud@3023
   197
        case DWET_BUTTONUP:
slouken@5199
   198
            if (ClientXY(windata, &evt->x, &evt->y)) {
couriersud@3023
   199
                if (!devdata->use_linux_input) {
slouken@5199
   200
                    SDL_SendMouseMotion_ex(sdlwin, devdata->mouse_id[0], 0, evt->x,
couriersud@3023
   201
                                        evt->y, 0);
slouken@5199
   202
                    SDL_SendMouseButton_ex(sdlwin, devdata->mouse_id[0],
couriersud@3023
   203
                                        SDL_RELEASED,
couriersud@3023
   204
                                        DirectFB_TranslateButton
couriersud@3023
   205
                                        (evt->button));
couriersud@3023
   206
                } else {
couriersud@3023
   207
                    MotionAllMice(_this, evt->x, evt->y);
couriersud@3023
   208
                }
couriersud@3023
   209
            }
couriersud@3023
   210
            break;
couriersud@3023
   211
        case DWET_MOTION:
slouken@5199
   212
            if (ClientXY(windata, &evt->x, &evt->y)) {
couriersud@3023
   213
                if (!devdata->use_linux_input) {
slouken@5199
   214
                    if (!(sdlwin->flags & SDL_WINDOW_INPUT_GRABBED))
slouken@5199
   215
                        SDL_SendMouseMotion_ex(sdlwin, devdata->mouse_id[0], 0,
couriersud@3023
   216
                                            evt->x, evt->y, 0);
couriersud@3023
   217
                } else {
couriersud@3023
   218
                    /* relative movements are not exact! 
couriersud@3023
   219
                     * This code should limit the number of events sent.
couriersud@3023
   220
                     * However it kills MAME axis recognition ... */
couriersud@3023
   221
                    static int cnt = 0;
couriersud@3023
   222
                    if (1 && ++cnt > 20) {
couriersud@3023
   223
                        MotionAllMice(_this, evt->x, evt->y);
couriersud@3023
   224
                        cnt = 0;
couriersud@3023
   225
                    }
couriersud@3023
   226
                }
slouken@5199
   227
                if (!(sdlwin->flags & SDL_WINDOW_MOUSE_FOCUS))
slouken@5199
   228
                    SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_ENTER, 0,
slouken@3040
   229
                                        0);
couriersud@3023
   230
            }
couriersud@3023
   231
            break;
couriersud@3023
   232
        case DWET_KEYDOWN:
couriersud@3023
   233
            if (!devdata->use_linux_input) {
couriersud@3023
   234
                DirectFB_TranslateKey(_this, evt, &keysym);
slouken@5199
   235
                //printf("Scancode %d  %d %d\n", keysym.scancode, evt->key_code, evt->key_id);
slouken@4568
   236
                SDL_SendKeyboardKey_ex(0, SDL_PRESSED, keysym.scancode);
couriersud@3023
   237
                if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
slouken@5199
   238
	                SDL_zero(text);
slouken@5199
   239
                    UnicodeToUtf8(keysym.unicode, text);
couriersud@3023
   240
                    if (*text) {
slouken@4568
   241
                        SDL_SendKeyboardText_ex(0, text);
couriersud@3023
   242
                    }
couriersud@3023
   243
                }
couriersud@3023
   244
            }
couriersud@3023
   245
            break;
couriersud@3023
   246
        case DWET_KEYUP:
couriersud@3023
   247
            if (!devdata->use_linux_input) {
couriersud@3023
   248
                DirectFB_TranslateKey(_this, evt, &keysym);
slouken@4568
   249
                SDL_SendKeyboardKey_ex(0, SDL_RELEASED, keysym.scancode);
couriersud@3023
   250
            }
couriersud@3023
   251
            break;
couriersud@3023
   252
        case DWET_POSITION:
slouken@5199
   253
            if (ClientXY(windata, &evt->x, &evt->y)) {
slouken@5199
   254
                SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_MOVED,
couriersud@3023
   255
                                    evt->x, evt->y);
couriersud@3023
   256
            }
couriersud@3023
   257
            break;
couriersud@3023
   258
        case DWET_POSITION_SIZE:
slouken@5199
   259
            if (ClientXY(windata, &evt->x, &evt->y)) {
slouken@5199
   260
                SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_MOVED,
couriersud@3023
   261
                                    evt->x, evt->y);
couriersud@3023
   262
            }
couriersud@3023
   263
            /* fall throught */
couriersud@3023
   264
        case DWET_SIZE:
couriersud@3023
   265
            // FIXME: what about < 0
slouken@5199
   266
            evt->w -= (windata->theme.right_size + windata->theme.left_size);
couriersud@3023
   267
            evt->h -=
slouken@5199
   268
                (windata->theme.top_size + windata->theme.bottom_size +
slouken@5199
   269
                 windata->theme.caption_size);
slouken@5199
   270
            SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_RESIZED,
couriersud@3023
   271
                                evt->w, evt->h);
couriersud@3023
   272
            break;
couriersud@3023
   273
        case DWET_CLOSE:
slouken@5199
   274
            SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_CLOSE, 0, 0);
couriersud@3023
   275
            break;
couriersud@3023
   276
        case DWET_GOTFOCUS:
slouken@5199
   277
            DirectFB_SetContext(_this, sdlwin);
slouken@5199
   278
            FocusAllKeyboards(_this, sdlwin);
slouken@5199
   279
            SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_FOCUS_GAINED,
couriersud@3023
   280
                                0, 0);
couriersud@3023
   281
            break;
couriersud@3023
   282
        case DWET_LOSTFOCUS:
slouken@5199
   283
            SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
couriersud@3023
   284
            FocusAllKeyboards(_this, 0);
couriersud@3023
   285
            break;
couriersud@3023
   286
        case DWET_ENTER:
couriersud@3023
   287
            /* SDL_DirectFB_ReshowCursor(_this, 0); */
slouken@5199
   288
            FocusAllMice(_this, sdlwin);
couriersud@3023
   289
            // FIXME: when do we really enter ?
slouken@5199
   290
            if (ClientXY(windata, &evt->x, &evt->y))
couriersud@3023
   291
                MotionAllMice(_this, evt->x, evt->y);
slouken@5199
   292
            SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_ENTER, 0, 0);
couriersud@3023
   293
            break;
couriersud@3023
   294
        case DWET_LEAVE:
slouken@5199
   295
            SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_LEAVE, 0, 0);
couriersud@3023
   296
            FocusAllMice(_this, 0);
couriersud@3023
   297
            /* SDL_DirectFB_ReshowCursor(_this, 1); */
couriersud@3023
   298
            break;
couriersud@3023
   299
        default:
couriersud@3023
   300
            ;
couriersud@3023
   301
        }
couriersud@3023
   302
    } else
couriersud@3023
   303
        printf("Event Clazz %d\n", evt->clazz);
couriersud@3023
   304
}
couriersud@3023
   305
couriersud@3023
   306
static void
slouken@4636
   307
ProcessInputEvent(_THIS, DFBInputEvent * ievt)
couriersud@3023
   308
{
couriersud@3023
   309
    SDL_DFB_DEVICEDATA(_this);
slouken@5218
   310
    SDL_Keysym keysym;
couriersud@3023
   311
    int kbd_idx;
slouken@5199
   312
    char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
couriersud@3023
   313
couriersud@3023
   314
    if (!devdata->use_linux_input) {
couriersud@3023
   315
        if (ievt->type == DIET_AXISMOTION) {
slouken@4636
   316
            if ((devdata->grabbed_window != NULL) && (ievt->flags & DIEF_AXISREL)) {
couriersud@3023
   317
                if (ievt->axis == DIAI_X)
slouken@4636
   318
                    SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1,
couriersud@3023
   319
                                        ievt->axisrel, 0, 0);
couriersud@3023
   320
                else if (ievt->axis == DIAI_Y)
slouken@4636
   321
                    SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1, 0,
couriersud@3023
   322
                                        ievt->axisrel, 0);
couriersud@3023
   323
            }
couriersud@3023
   324
        }
couriersud@3023
   325
    } else {
couriersud@3023
   326
        static int last_x, last_y;
couriersud@3023
   327
couriersud@3023
   328
        switch (ievt->type) {
couriersud@3023
   329
        case DIET_AXISMOTION:
couriersud@3023
   330
            if (ievt->flags & DIEF_AXISABS) {
couriersud@3023
   331
                if (ievt->axis == DIAI_X)
couriersud@3023
   332
                    last_x = ievt->axisabs;
couriersud@3023
   333
                else if (ievt->axis == DIAI_Y)
couriersud@3023
   334
                    last_y = ievt->axisabs;
couriersud@3023
   335
                if (!(ievt->flags & DIEF_FOLLOW)) {
slouken@4636
   336
#if USE_MULTI_API
couriersud@3023
   337
                    SDL_Mouse *mouse = SDL_GetMouse(ievt->device_id);
couriersud@3023
   338
                    SDL_Window *window = SDL_GetWindowFromID(mouse->focus);
slouken@4636
   339
#else
slouken@4636
   340
                    SDL_Window *window = devdata->grabbed_window;
slouken@4636
   341
#endif
couriersud@3023
   342
                    if (window) {
couriersud@3023
   343
                        DFB_WindowData *windata =
couriersud@3023
   344
                            (DFB_WindowData *) window->driverdata;
couriersud@3023
   345
                        int x, y;
couriersud@3023
   346
slouken@5199
   347
                        windata->dfbwin->GetPosition(windata->dfbwin, &x, &y);
slouken@4636
   348
                        SDL_SendMouseMotion_ex(window, ievt->device_id, 0,
couriersud@3023
   349
                                            last_x - (x +
couriersud@3023
   350
                                                      windata->client.x),
couriersud@3023
   351
                                            last_y - (y +
couriersud@3023
   352
                                                      windata->client.y), 0);
couriersud@3023
   353
                    } else {
slouken@4636
   354
                        SDL_SendMouseMotion_ex(window, ievt->device_id, 0, last_x,
couriersud@3023
   355
                                            last_y, 0);
couriersud@3023
   356
                    }
couriersud@3023
   357
                }
couriersud@3023
   358
            } else if (ievt->flags & DIEF_AXISREL) {
couriersud@3023
   359
                if (ievt->axis == DIAI_X)
slouken@4636
   360
                    SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1,
couriersud@3023
   361
                                        ievt->axisrel, 0, 0);
couriersud@3023
   362
                else if (ievt->axis == DIAI_Y)
slouken@4636
   363
                    SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1, 0,
couriersud@3023
   364
                                        ievt->axisrel, 0);
couriersud@3023
   365
            }
couriersud@3023
   366
            break;
couriersud@3023
   367
        case DIET_KEYPRESS:
couriersud@3023
   368
            kbd_idx = KbdIndex(_this, ievt->device_id);
slouken@5199
   369
            DirectFB_TranslateKeyInputEvent(_this, ievt, &keysym);
slouken@5199
   370
            //printf("Scancode %d  %d %d\n", keysym.scancode, evt->key_code, evt->key_id);
slouken@4568
   371
            SDL_SendKeyboardKey_ex(kbd_idx, SDL_PRESSED, keysym.scancode);
couriersud@3023
   372
            if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
slouken@5199
   373
                SDL_zero(text);
slouken@5199
   374
                UnicodeToUtf8(keysym.unicode, text);
couriersud@3023
   375
                if (*text) {
slouken@4568
   376
                    SDL_SendKeyboardText_ex(kbd_idx, text);
couriersud@3023
   377
                }
couriersud@3023
   378
            }
couriersud@3023
   379
            break;
couriersud@3023
   380
        case DIET_KEYRELEASE:
couriersud@3023
   381
            kbd_idx = KbdIndex(_this, ievt->device_id);
slouken@5199
   382
            DirectFB_TranslateKeyInputEvent(_this, ievt, &keysym);
slouken@4636
   383
            SDL_SendKeyboardKey_ex(kbd_idx, SDL_RELEASED, keysym.scancode);
couriersud@3023
   384
            break;
couriersud@3023
   385
        case DIET_BUTTONPRESS:
couriersud@3023
   386
            if (ievt->buttons & DIBM_LEFT)
slouken@4636
   387
                SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_PRESSED, 1);
couriersud@3023
   388
            if (ievt->buttons & DIBM_MIDDLE)
slouken@4636
   389
                SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_PRESSED, 2);
couriersud@3023
   390
            if (ievt->buttons & DIBM_RIGHT)
slouken@4636
   391
                SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_PRESSED, 3);
couriersud@3023
   392
            break;
couriersud@3023
   393
        case DIET_BUTTONRELEASE:
couriersud@3023
   394
            if (!(ievt->buttons & DIBM_LEFT))
slouken@4636
   395
                SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_RELEASED, 1);
couriersud@3023
   396
            if (!(ievt->buttons & DIBM_MIDDLE))
slouken@4636
   397
                SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_RELEASED, 2);
couriersud@3023
   398
            if (!(ievt->buttons & DIBM_RIGHT))
slouken@4636
   399
                SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_RELEASED, 3);
couriersud@3023
   400
            break;
couriersud@3023
   401
        default:
couriersud@3023
   402
            break;              /* please gcc */
couriersud@3023
   403
        }
couriersud@3023
   404
    }
couriersud@3023
   405
}
couriersud@3023
   406
slouken@1895
   407
void
slouken@2226
   408
DirectFB_PumpEventsWindow(_THIS)
slouken@167
   409
{
slouken@2226
   410
    SDL_DFB_DEVICEDATA(_this);
slouken@2737
   411
    DFBInputEvent ievt;
slouken@5199
   412
    SDL_Window *w;
slouken@2737
   413
slouken@5199
   414
    for (w = devdata->firstwin; w != NULL; w = w->next) {
slouken@5199
   415
        SDL_DFB_WINDOWDATA(w);
slouken@2860
   416
        DFBWindowEvent evt;
slouken@2737
   417
slouken@5199
   418
        while (windata->eventbuffer->GetEvent(windata->eventbuffer,
slouken@2226
   419
                                        DFB_EVENT(&evt)) == DFB_OK) {
slouken@5199
   420
            if (!DirectFB_WM_ProcessEvent(_this, w, &evt)) {
slouken@5199
   421
                /* Send a SDL_SYSWMEVENT if the application wants them */
slouken@5199
   422
                if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) {
slouken@5199
   423
                    SDL_SysWMmsg wmmsg;
slouken@5199
   424
                    SDL_VERSION(&wmmsg.version);
slouken@5199
   425
                    wmmsg.subsystem = SDL_SYSWM_DIRECTFB;
slouken@5199
   426
                    wmmsg.msg.dfb.event.window = evt;
slouken@5199
   427
                    SDL_SendSysWMEvent(&wmmsg);
slouken@5199
   428
                }
slouken@5199
   429
                ProcessWindowEvent(_this, w, &evt);
slouken@5199
   430
            }
slouken@2737
   431
        }
slouken@2737
   432
    }
slouken@2737
   433
slouken@2737
   434
    /* Now get relative events in case we need them */
slouken@2737
   435
    while (devdata->events->GetEvent(devdata->events,
slouken@2737
   436
                                     DFB_EVENT(&ievt)) == DFB_OK) {
slouken@5199
   437
slouken@5199
   438
    	if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) {
slouken@5199
   439
            SDL_SysWMmsg wmmsg;
slouken@5199
   440
            SDL_VERSION(&wmmsg.version);
slouken@5199
   441
            wmmsg.subsystem = SDL_SYSWM_DIRECTFB;
slouken@5199
   442
            wmmsg.msg.dfb.event.input = ievt;
slouken@5199
   443
            SDL_SendSysWMEvent(&wmmsg);
slouken@5199
   444
        }
slouken@4636
   445
        ProcessInputEvent(_this, &ievt);
slouken@167
   446
    }
slouken@167
   447
}
slouken@167
   448
slouken@1895
   449
void
slouken@5218
   450
DirectFB_InitOSKeymap(_THIS, SDL_Scancode * keymap, int numkeys)
slouken@167
   451
{
slouken@1895
   452
    int i;
slouken@167
   453
slouken@1895
   454
    /* Initialize the DirectFB key translation table */
slouken@2860
   455
    for (i = 0; i < numkeys; ++i)
slouken@2721
   456
        keymap[i] = SDL_SCANCODE_UNKNOWN;
slouken@1895
   457
slouken@2721
   458
    keymap[DIKI_A - DIKI_UNKNOWN] = SDL_SCANCODE_A;
slouken@2721
   459
    keymap[DIKI_B - DIKI_UNKNOWN] = SDL_SCANCODE_B;
slouken@2721
   460
    keymap[DIKI_C - DIKI_UNKNOWN] = SDL_SCANCODE_C;
slouken@2721
   461
    keymap[DIKI_D - DIKI_UNKNOWN] = SDL_SCANCODE_D;
slouken@2721
   462
    keymap[DIKI_E - DIKI_UNKNOWN] = SDL_SCANCODE_E;
slouken@2721
   463
    keymap[DIKI_F - DIKI_UNKNOWN] = SDL_SCANCODE_F;
slouken@2721
   464
    keymap[DIKI_G - DIKI_UNKNOWN] = SDL_SCANCODE_G;
slouken@2721
   465
    keymap[DIKI_H - DIKI_UNKNOWN] = SDL_SCANCODE_H;
slouken@2721
   466
    keymap[DIKI_I - DIKI_UNKNOWN] = SDL_SCANCODE_I;
slouken@2721
   467
    keymap[DIKI_J - DIKI_UNKNOWN] = SDL_SCANCODE_J;
slouken@2721
   468
    keymap[DIKI_K - DIKI_UNKNOWN] = SDL_SCANCODE_K;
slouken@2721
   469
    keymap[DIKI_L - DIKI_UNKNOWN] = SDL_SCANCODE_L;
slouken@2721
   470
    keymap[DIKI_M - DIKI_UNKNOWN] = SDL_SCANCODE_M;
slouken@2721
   471
    keymap[DIKI_N - DIKI_UNKNOWN] = SDL_SCANCODE_N;
slouken@2721
   472
    keymap[DIKI_O - DIKI_UNKNOWN] = SDL_SCANCODE_O;
slouken@2721
   473
    keymap[DIKI_P - DIKI_UNKNOWN] = SDL_SCANCODE_P;
slouken@2721
   474
    keymap[DIKI_Q - DIKI_UNKNOWN] = SDL_SCANCODE_Q;
slouken@2721
   475
    keymap[DIKI_R - DIKI_UNKNOWN] = SDL_SCANCODE_R;
slouken@2721
   476
    keymap[DIKI_S - DIKI_UNKNOWN] = SDL_SCANCODE_S;
slouken@2721
   477
    keymap[DIKI_T - DIKI_UNKNOWN] = SDL_SCANCODE_T;
slouken@2721
   478
    keymap[DIKI_U - DIKI_UNKNOWN] = SDL_SCANCODE_U;
slouken@2721
   479
    keymap[DIKI_V - DIKI_UNKNOWN] = SDL_SCANCODE_V;
slouken@2721
   480
    keymap[DIKI_W - DIKI_UNKNOWN] = SDL_SCANCODE_W;
slouken@2721
   481
    keymap[DIKI_X - DIKI_UNKNOWN] = SDL_SCANCODE_X;
slouken@2721
   482
    keymap[DIKI_Y - DIKI_UNKNOWN] = SDL_SCANCODE_Y;
slouken@2721
   483
    keymap[DIKI_Z - DIKI_UNKNOWN] = SDL_SCANCODE_Z;
slouken@1895
   484
slouken@2721
   485
    keymap[DIKI_0 - DIKI_UNKNOWN] = SDL_SCANCODE_0;
slouken@2721
   486
    keymap[DIKI_1 - DIKI_UNKNOWN] = SDL_SCANCODE_1;
slouken@2721
   487
    keymap[DIKI_2 - DIKI_UNKNOWN] = SDL_SCANCODE_2;
slouken@2721
   488
    keymap[DIKI_3 - DIKI_UNKNOWN] = SDL_SCANCODE_3;
slouken@2721
   489
    keymap[DIKI_4 - DIKI_UNKNOWN] = SDL_SCANCODE_4;
slouken@2721
   490
    keymap[DIKI_5 - DIKI_UNKNOWN] = SDL_SCANCODE_5;
slouken@2721
   491
    keymap[DIKI_6 - DIKI_UNKNOWN] = SDL_SCANCODE_6;
slouken@2721
   492
    keymap[DIKI_7 - DIKI_UNKNOWN] = SDL_SCANCODE_7;
slouken@2721
   493
    keymap[DIKI_8 - DIKI_UNKNOWN] = SDL_SCANCODE_8;
slouken@2721
   494
    keymap[DIKI_9 - DIKI_UNKNOWN] = SDL_SCANCODE_9;
slouken@1895
   495
slouken@2721
   496
    keymap[DIKI_F1 - DIKI_UNKNOWN] = SDL_SCANCODE_F1;
slouken@2721
   497
    keymap[DIKI_F2 - DIKI_UNKNOWN] = SDL_SCANCODE_F2;
slouken@2721
   498
    keymap[DIKI_F3 - DIKI_UNKNOWN] = SDL_SCANCODE_F3;
slouken@2721
   499
    keymap[DIKI_F4 - DIKI_UNKNOWN] = SDL_SCANCODE_F4;
slouken@2721
   500
    keymap[DIKI_F5 - DIKI_UNKNOWN] = SDL_SCANCODE_F5;
slouken@2721
   501
    keymap[DIKI_F6 - DIKI_UNKNOWN] = SDL_SCANCODE_F6;
slouken@2721
   502
    keymap[DIKI_F7 - DIKI_UNKNOWN] = SDL_SCANCODE_F7;
slouken@2721
   503
    keymap[DIKI_F8 - DIKI_UNKNOWN] = SDL_SCANCODE_F8;
slouken@2721
   504
    keymap[DIKI_F9 - DIKI_UNKNOWN] = SDL_SCANCODE_F9;
slouken@2721
   505
    keymap[DIKI_F10 - DIKI_UNKNOWN] = SDL_SCANCODE_F10;
slouken@2721
   506
    keymap[DIKI_F11 - DIKI_UNKNOWN] = SDL_SCANCODE_F11;
slouken@2721
   507
    keymap[DIKI_F12 - DIKI_UNKNOWN] = SDL_SCANCODE_F12;
slouken@1895
   508
slouken@2721
   509
    keymap[DIKI_ESCAPE - DIKI_UNKNOWN] = SDL_SCANCODE_ESCAPE;
slouken@2721
   510
    keymap[DIKI_LEFT - DIKI_UNKNOWN] = SDL_SCANCODE_LEFT;
slouken@2721
   511
    keymap[DIKI_RIGHT - DIKI_UNKNOWN] = SDL_SCANCODE_RIGHT;
slouken@2721
   512
    keymap[DIKI_UP - DIKI_UNKNOWN] = SDL_SCANCODE_UP;
slouken@2721
   513
    keymap[DIKI_DOWN - DIKI_UNKNOWN] = SDL_SCANCODE_DOWN;
slouken@2721
   514
    keymap[DIKI_CONTROL_L - DIKI_UNKNOWN] = SDL_SCANCODE_LCTRL;
slouken@2721
   515
    keymap[DIKI_CONTROL_R - DIKI_UNKNOWN] = SDL_SCANCODE_RCTRL;
slouken@2721
   516
    keymap[DIKI_SHIFT_L - DIKI_UNKNOWN] = SDL_SCANCODE_LSHIFT;
slouken@2721
   517
    keymap[DIKI_SHIFT_R - DIKI_UNKNOWN] = SDL_SCANCODE_RSHIFT;
slouken@2721
   518
    keymap[DIKI_ALT_L - DIKI_UNKNOWN] = SDL_SCANCODE_LALT;
slouken@2721
   519
    keymap[DIKI_ALT_R - DIKI_UNKNOWN] = SDL_SCANCODE_RALT;
slouken@2721
   520
    keymap[DIKI_META_L - DIKI_UNKNOWN] = SDL_SCANCODE_LGUI;
slouken@2721
   521
    keymap[DIKI_META_R - DIKI_UNKNOWN] = SDL_SCANCODE_RGUI;
slouken@2721
   522
    keymap[DIKI_SUPER_L - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
slouken@2721
   523
    keymap[DIKI_SUPER_R - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
slouken@2737
   524
    /* FIXME:Do we read hyper keys ?
slouken@2737
   525
     * keymap[DIKI_HYPER_L - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
slouken@2737
   526
     * keymap[DIKI_HYPER_R - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
slouken@2737
   527
     */
slouken@2721
   528
    keymap[DIKI_TAB - DIKI_UNKNOWN] = SDL_SCANCODE_TAB;
slouken@2721
   529
    keymap[DIKI_ENTER - DIKI_UNKNOWN] = SDL_SCANCODE_RETURN;
slouken@2721
   530
    keymap[DIKI_SPACE - DIKI_UNKNOWN] = SDL_SCANCODE_SPACE;
slouken@2721
   531
    keymap[DIKI_BACKSPACE - DIKI_UNKNOWN] = SDL_SCANCODE_BACKSPACE;
slouken@2721
   532
    keymap[DIKI_INSERT - DIKI_UNKNOWN] = SDL_SCANCODE_INSERT;
slouken@2721
   533
    keymap[DIKI_DELETE - DIKI_UNKNOWN] = SDL_SCANCODE_DELETE;
slouken@2721
   534
    keymap[DIKI_HOME - DIKI_UNKNOWN] = SDL_SCANCODE_HOME;
slouken@2721
   535
    keymap[DIKI_END - DIKI_UNKNOWN] = SDL_SCANCODE_END;
slouken@2721
   536
    keymap[DIKI_PAGE_UP - DIKI_UNKNOWN] = SDL_SCANCODE_PAGEUP;
slouken@2721
   537
    keymap[DIKI_PAGE_DOWN - DIKI_UNKNOWN] = SDL_SCANCODE_PAGEDOWN;
slouken@2721
   538
    keymap[DIKI_CAPS_LOCK - DIKI_UNKNOWN] = SDL_SCANCODE_CAPSLOCK;
slouken@2721
   539
    keymap[DIKI_NUM_LOCK - DIKI_UNKNOWN] = SDL_SCANCODE_NUMLOCKCLEAR;
slouken@2721
   540
    keymap[DIKI_SCROLL_LOCK - DIKI_UNKNOWN] = SDL_SCANCODE_SCROLLLOCK;
slouken@2721
   541
    keymap[DIKI_PRINT - DIKI_UNKNOWN] = SDL_SCANCODE_PRINTSCREEN;
slouken@2721
   542
    keymap[DIKI_PAUSE - DIKI_UNKNOWN] = SDL_SCANCODE_PAUSE;
slouken@2226
   543
slouken@2721
   544
    keymap[DIKI_KP_EQUAL - DIKI_UNKNOWN] = SDL_SCANCODE_KP_EQUALS;
slouken@2721
   545
    keymap[DIKI_KP_DECIMAL - DIKI_UNKNOWN] = SDL_SCANCODE_KP_PERIOD;
slouken@2721
   546
    keymap[DIKI_KP_0 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_0;
slouken@2721
   547
    keymap[DIKI_KP_1 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_1;
slouken@2721
   548
    keymap[DIKI_KP_2 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_2;
slouken@2721
   549
    keymap[DIKI_KP_3 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_3;
slouken@2721
   550
    keymap[DIKI_KP_4 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_4;
slouken@2721
   551
    keymap[DIKI_KP_5 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_5;
slouken@2721
   552
    keymap[DIKI_KP_6 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_6;
slouken@2721
   553
    keymap[DIKI_KP_7 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_7;
slouken@2721
   554
    keymap[DIKI_KP_8 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_8;
slouken@2721
   555
    keymap[DIKI_KP_9 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_9;
slouken@2721
   556
    keymap[DIKI_KP_DIV - DIKI_UNKNOWN] = SDL_SCANCODE_KP_DIVIDE;
slouken@2721
   557
    keymap[DIKI_KP_MULT - DIKI_UNKNOWN] = SDL_SCANCODE_KP_MULTIPLY;
slouken@2721
   558
    keymap[DIKI_KP_MINUS - DIKI_UNKNOWN] = SDL_SCANCODE_KP_MINUS;
slouken@2721
   559
    keymap[DIKI_KP_PLUS - DIKI_UNKNOWN] = SDL_SCANCODE_KP_PLUS;
slouken@2721
   560
    keymap[DIKI_KP_ENTER - DIKI_UNKNOWN] = SDL_SCANCODE_KP_ENTER;
slouken@2226
   561
slouken@2721
   562
    keymap[DIKI_QUOTE_LEFT - DIKI_UNKNOWN] = SDL_SCANCODE_GRAVE;        /*  TLDE  */
slouken@2721
   563
    keymap[DIKI_MINUS_SIGN - DIKI_UNKNOWN] = SDL_SCANCODE_MINUS;        /*  AE11  */
slouken@2721
   564
    keymap[DIKI_EQUALS_SIGN - DIKI_UNKNOWN] = SDL_SCANCODE_EQUALS;      /*  AE12  */
slouken@2721
   565
    keymap[DIKI_BRACKET_LEFT - DIKI_UNKNOWN] = SDL_SCANCODE_RIGHTBRACKET;       /*  AD11  */
slouken@2721
   566
    keymap[DIKI_BRACKET_RIGHT - DIKI_UNKNOWN] = SDL_SCANCODE_LEFTBRACKET;       /*  AD12  */
slouken@2721
   567
    keymap[DIKI_BACKSLASH - DIKI_UNKNOWN] = SDL_SCANCODE_BACKSLASH;     /*  BKSL  */
slouken@2721
   568
    keymap[DIKI_SEMICOLON - DIKI_UNKNOWN] = SDL_SCANCODE_SEMICOLON;     /*  AC10  */
slouken@2721
   569
    keymap[DIKI_QUOTE_RIGHT - DIKI_UNKNOWN] = SDL_SCANCODE_APOSTROPHE;  /*  AC11  */
slouken@2721
   570
    keymap[DIKI_COMMA - DIKI_UNKNOWN] = SDL_SCANCODE_COMMA;     /*  AB08  */
slouken@2721
   571
    keymap[DIKI_PERIOD - DIKI_UNKNOWN] = SDL_SCANCODE_PERIOD;   /*  AB09  */
slouken@2721
   572
    keymap[DIKI_SLASH - DIKI_UNKNOWN] = SDL_SCANCODE_SLASH;     /*  AB10  */
slouken@2721
   573
    keymap[DIKI_LESS_SIGN - DIKI_UNKNOWN] = SDL_SCANCODE_NONUSBACKSLASH;        /*  103rd  */
slouken@2721
   574
slouken@167
   575
}
slouken@167
   576
slouken@5218
   577
static SDL_Keysym *
slouken@5218
   578
DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt, SDL_Keysym * keysym)
slouken@2226
   579
{
slouken@2721
   580
    SDL_DFB_DEVICEDATA(_this);
slouken@5199
   581
    int kbd_idx = 0; /* Window events lag the device source KbdIndex(_this, evt->device_id); */
slouken@5199
   582
    DFB_KeyboardData *kbd = &devdata->keyboard[kbd_idx];
slouken@167
   583
slouken@5199
   584
    keysym->scancode = SDL_SCANCODE_UNKNOWN;
slouken@5199
   585
slouken@5199
   586
    if (kbd->map && evt->key_code >= kbd->map_adjust &&
slouken@5199
   587
	    evt->key_code < kbd->map_size + kbd->map_adjust)
slouken@5199
   588
	    keysym->scancode = kbd->map[evt->key_code - kbd->map_adjust];
slouken@2226
   589
couriersud@3023
   590
    if (keysym->scancode == SDL_SCANCODE_UNKNOWN ||
slouken@5199
   591
        devdata->keyboard[kbd_idx].is_generic) {
slouken@2860
   592
        if (evt->key_id - DIKI_UNKNOWN < SDL_arraysize(oskeymap))
slouken@2860
   593
            keysym->scancode = oskeymap[evt->key_id - DIKI_UNKNOWN];
slouken@2721
   594
        else
slouken@2721
   595
            keysym->scancode = SDL_SCANCODE_UNKNOWN;
slouken@2721
   596
    }
slouken@2226
   597
slouken@1895
   598
    keysym->unicode =
slouken@2721
   599
        (DFB_KEY_TYPE(evt->key_symbol) == DIKT_UNICODE) ? evt->key_symbol : 0;
couriersud@3023
   600
    if (keysym->unicode == 0 &&
couriersud@3023
   601
        (evt->key_symbol > 0 && evt->key_symbol < 255))
slouken@2721
   602
        keysym->unicode = evt->key_symbol;
slouken@167
   603
slouken@1895
   604
    return keysym;
slouken@167
   605
}
slouken@167
   606
slouken@5218
   607
static SDL_Keysym *
slouken@5199
   608
DirectFB_TranslateKeyInputEvent(_THIS, DFBInputEvent * evt,
slouken@5218
   609
                                SDL_Keysym * keysym)
slouken@2860
   610
{
slouken@2860
   611
    SDL_DFB_DEVICEDATA(_this);
slouken@5199
   612
    int kbd_idx = KbdIndex(_this, evt->device_id);
slouken@5199
   613
    DFB_KeyboardData *kbd = &devdata->keyboard[kbd_idx];
slouken@2860
   614
slouken@5199
   615
    keysym->scancode = SDL_SCANCODE_UNKNOWN;
slouken@2860
   616
slouken@5199
   617
    if (kbd->map && evt->key_code >= kbd->map_adjust &&
slouken@5199
   618
	    evt->key_code < kbd->map_size + kbd->map_adjust)
slouken@5199
   619
	    keysym->scancode = kbd->map[evt->key_code - kbd->map_adjust];
slouken@5199
   620
slouken@5199
   621
    if (keysym->scancode == SDL_SCANCODE_UNKNOWN || devdata->keyboard[kbd_idx].is_generic) {
slouken@2860
   622
        if (evt->key_id - DIKI_UNKNOWN < SDL_arraysize(oskeymap))
slouken@2860
   623
            keysym->scancode = oskeymap[evt->key_id - DIKI_UNKNOWN];
slouken@2860
   624
        else
slouken@2860
   625
            keysym->scancode = SDL_SCANCODE_UNKNOWN;
slouken@2860
   626
    }
slouken@2860
   627
slouken@2860
   628
    keysym->unicode =
slouken@2860
   629
        (DFB_KEY_TYPE(evt->key_symbol) == DIKT_UNICODE) ? evt->key_symbol : 0;
couriersud@3023
   630
    if (keysym->unicode == 0 &&
couriersud@3023
   631
        (evt->key_symbol > 0 && evt->key_symbol < 255))
slouken@2860
   632
        keysym->unicode = evt->key_symbol;
slouken@2860
   633
slouken@2860
   634
    return keysym;
slouken@2860
   635
}
couriersud@3023
   636
slouken@1895
   637
static int
slouken@2226
   638
DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button)
slouken@167
   639
{
slouken@2226
   640
    switch (button) {
slouken@167
   641
    case DIBI_LEFT:
slouken@1895
   642
        return 1;
slouken@167
   643
    case DIBI_MIDDLE:
slouken@1895
   644
        return 2;
slouken@167
   645
    case DIBI_RIGHT:
slouken@1895
   646
        return 3;
slouken@167
   647
    default:
slouken@1895
   648
        return 0;
slouken@167
   649
    }
slouken@167
   650
}
slouken@1895
   651
slouken@2721
   652
static DFBEnumerationResult
slouken@4636
   653
EnumKeyboards(DFBInputDeviceID device_id,
couriersud@3023
   654
                DFBInputDeviceDescription desc, void *callbackdata)
slouken@2721
   655
{
slouken@4636
   656
	cb_data *cb = callbackdata;
slouken@4636
   657
    DFB_DeviceData *devdata = cb->devdata;
slouken@4568
   658
#if USE_MULTI_API
slouken@2721
   659
    SDL_Keyboard keyboard;
slouken@4568
   660
#endif
slouken@5220
   661
    SDL_Keycode keymap[SDL_NUM_SCANCODES];
slouken@2721
   662
slouken@4636
   663
	if (!cb->sys_kbd) {
slouken@4636
   664
		if (cb->sys_ids) {
slouken@4636
   665
		    if (device_id >= 0x10)
slouken@4636
   666
		        return DFENUM_OK;
slouken@4636
   667
		} else {
slouken@4636
   668
		    if (device_id < 0x10)
slouken@4636
   669
		        return DFENUM_OK;
slouken@4636
   670
		}
slouken@4636
   671
	} else {
slouken@4636
   672
		if (device_id != DIDID_KEYBOARD)
slouken@4636
   673
		    return DFENUM_OK;
slouken@4636
   674
	}
slouken@4636
   675
	
slouken@4636
   676
    if ((desc.caps & DIDTF_KEYBOARD)) {
slouken@4568
   677
#if USE_MULTI_API
slouken@2721
   678
        SDL_zero(keyboard);
slouken@4636
   679
        SDL_AddKeyboard(&keyboard, devdata->num_keyboard);
slouken@4568
   680
#endif
slouken@2860
   681
        devdata->keyboard[devdata->num_keyboard].id = device_id;
slouken@2860
   682
        devdata->keyboard[devdata->num_keyboard].is_generic = 0;
slouken@2860
   683
        if (!strncmp("X11", desc.name, 3))
slouken@5199
   684
        {
slouken@5199
   685
        	devdata->keyboard[devdata->num_keyboard].map = xfree86_scancode_table2;
slouken@5199
   686
        	devdata->keyboard[devdata->num_keyboard].map_size = SDL_arraysize(xfree86_scancode_table2);
slouken@5199
   687
			devdata->keyboard[devdata->num_keyboard].map_adjust = 8;
slouken@5199
   688
        } else {
slouken@5199
   689
        	devdata->keyboard[devdata->num_keyboard].map = linux_scancode_table;
slouken@5199
   690
        	devdata->keyboard[devdata->num_keyboard].map_size = SDL_arraysize(linux_scancode_table);
slouken@5199
   691
			devdata->keyboard[devdata->num_keyboard].map_adjust = 0;
slouken@5199
   692
        }
slouken@2860
   693
slouken@5199
   694
		SDL_DFB_LOG("Keyboard %d - %s\n", device_id, desc.name);
slouken@5199
   695
		
slouken@2860
   696
        SDL_GetDefaultKeymap(keymap);
slouken@4636
   697
#if USE_MULTI_API
slouken@2860
   698
        SDL_SetKeymap(devdata->num_keyboard, 0, keymap, SDL_NUM_SCANCODES);
slouken@4636
   699
#else
slouken@4636
   700
        SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES);
slouken@4636
   701
#endif
slouken@2860
   702
        devdata->num_keyboard++;
slouken@4636
   703
slouken@4636
   704
		if (cb->sys_kbd)
slouken@4636
   705
	        return DFENUM_CANCEL;
slouken@2860
   706
    }
slouken@2860
   707
    return DFENUM_OK;
slouken@2721
   708
}
slouken@2721
   709
slouken@2721
   710
void
slouken@2721
   711
DirectFB_InitKeyboard(_THIS)
slouken@2721
   712
{
slouken@2721
   713
    SDL_DFB_DEVICEDATA(_this);
slouken@4636
   714
	cb_data cb;    
slouken@4636
   715
	
slouken@2860
   716
    DirectFB_InitOSKeymap(_this, &oskeymap[0], SDL_arraysize(oskeymap));
slouken@2721
   717
slouken@2860
   718
    devdata->num_keyboard = 0;
slouken@4636
   719
    cb.devdata = devdata;
slouken@4636
   720
    
slouken@2998
   721
    if (devdata->use_linux_input) {
slouken@4636
   722
    	cb.sys_kbd = 0;
slouken@4636
   723
        cb.sys_ids = 0;
slouken@3013
   724
        SDL_DFB_CHECK(devdata->dfb->
slouken@4636
   725
                      EnumInputDevices(devdata->dfb, EnumKeyboards, &cb));
slouken@2860
   726
        if (devdata->num_keyboard == 0) {
slouken@4636
   727
            cb.sys_ids = 1;
couriersud@3023
   728
            SDL_DFB_CHECK(devdata->dfb->EnumInputDevices(devdata->dfb,
couriersud@3023
   729
                                                         EnumKeyboards,
slouken@4636
   730
                                                         &cb));
slouken@2860
   731
        }
slouken@4636
   732
    } else {
slouken@4636
   733
    	cb.sys_kbd = 1;
couriersud@3023
   734
        SDL_DFB_CHECK(devdata->dfb->EnumInputDevices(devdata->dfb,
slouken@4636
   735
                                                     EnumKeyboards,
slouken@4636
   736
                                                     &cb));
slouken@2860
   737
    }
slouken@2721
   738
}
slouken@2721
   739
slouken@2737
   740
void
slouken@2737
   741
DirectFB_QuitKeyboard(_THIS)
slouken@2737
   742
{
slouken@4636
   743
    //SDL_DFB_DEVICEDATA(_this);
slouken@2737
   744
slouken@2860
   745
    SDL_KeyboardQuit();
slouken@2737
   746
slouken@2737
   747
}
slouken@2737
   748
slouken@6044
   749
#endif /* SDL_VIDEO_DRIVER_DIRECTFB */