src/video/directfb/SDL_DirectFB_events.c
author Gabriel Jacobo <gabomdq@gmail.com>
Wed, 21 Aug 2013 09:47:10 -0300
changeset 7678 286c42d7c5ed
parent 7677 871d43c6968a
child 8093 b43765095a6f
permissions -rw-r--r--
OCD fixes: Adds a space after /* (glory to regular expressions!)
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@7191
    55
struct _cb_data
slouken@4636
    56
{
slouken@7191
    57
    DFB_DeviceData *devdata;
slouken@7191
    58
    int sys_ids;
slouken@7191
    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@7312
    67
                                         SDL_Keysym * keysym, Uint32 *unicode);
slouken@5218
    68
static SDL_Keysym *DirectFB_TranslateKeyInputEvent(_THIS, DFBInputEvent * evt,
slouken@7312
    69
                                                   SDL_Keysym * keysym, Uint32 *unicode);
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@7191
    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@7191
    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@7191
    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;
gabomdq@7678
   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@7312
   179
    Uint32 unicode;
slouken@5199
   180
    char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
couriersud@3023
   181
couriersud@3023
   182
    if (evt->clazz == DFEC_WINDOW) {
couriersud@3023
   183
        switch (evt->type) {
couriersud@3023
   184
        case DWET_BUTTONDOWN:
slouken@5199
   185
            if (ClientXY(windata, &evt->x, &evt->y)) {
couriersud@3023
   186
                if (!devdata->use_linux_input) {
slouken@5199
   187
                    SDL_SendMouseMotion_ex(sdlwin, devdata->mouse_id[0], 0, evt->x,
couriersud@3023
   188
                                        evt->y, 0);
slouken@5199
   189
                    SDL_SendMouseButton_ex(sdlwin, devdata->mouse_id[0],
couriersud@3023
   190
                                        SDL_PRESSED,
couriersud@3023
   191
                                        DirectFB_TranslateButton
couriersud@3023
   192
                                        (evt->button));
couriersud@3023
   193
                } else {
couriersud@3023
   194
                    MotionAllMice(_this, evt->x, evt->y);
couriersud@3023
   195
                }
couriersud@3023
   196
            }
couriersud@3023
   197
            break;
couriersud@3023
   198
        case DWET_BUTTONUP:
slouken@5199
   199
            if (ClientXY(windata, &evt->x, &evt->y)) {
couriersud@3023
   200
                if (!devdata->use_linux_input) {
slouken@5199
   201
                    SDL_SendMouseMotion_ex(sdlwin, devdata->mouse_id[0], 0, evt->x,
couriersud@3023
   202
                                        evt->y, 0);
slouken@5199
   203
                    SDL_SendMouseButton_ex(sdlwin, devdata->mouse_id[0],
couriersud@3023
   204
                                        SDL_RELEASED,
couriersud@3023
   205
                                        DirectFB_TranslateButton
couriersud@3023
   206
                                        (evt->button));
couriersud@3023
   207
                } else {
couriersud@3023
   208
                    MotionAllMice(_this, evt->x, evt->y);
couriersud@3023
   209
                }
couriersud@3023
   210
            }
couriersud@3023
   211
            break;
couriersud@3023
   212
        case DWET_MOTION:
slouken@5199
   213
            if (ClientXY(windata, &evt->x, &evt->y)) {
couriersud@3023
   214
                if (!devdata->use_linux_input) {
slouken@5199
   215
                    if (!(sdlwin->flags & SDL_WINDOW_INPUT_GRABBED))
slouken@5199
   216
                        SDL_SendMouseMotion_ex(sdlwin, devdata->mouse_id[0], 0,
couriersud@3023
   217
                                            evt->x, evt->y, 0);
couriersud@3023
   218
                } else {
slouken@7191
   219
                    /* relative movements are not exact!
couriersud@3023
   220
                     * This code should limit the number of events sent.
couriersud@3023
   221
                     * However it kills MAME axis recognition ... */
couriersud@3023
   222
                    static int cnt = 0;
couriersud@3023
   223
                    if (1 && ++cnt > 20) {
couriersud@3023
   224
                        MotionAllMice(_this, evt->x, evt->y);
couriersud@3023
   225
                        cnt = 0;
couriersud@3023
   226
                    }
couriersud@3023
   227
                }
slouken@5199
   228
                if (!(sdlwin->flags & SDL_WINDOW_MOUSE_FOCUS))
slouken@5199
   229
                    SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_ENTER, 0,
slouken@3040
   230
                                        0);
couriersud@3023
   231
            }
couriersud@3023
   232
            break;
couriersud@3023
   233
        case DWET_KEYDOWN:
couriersud@3023
   234
            if (!devdata->use_linux_input) {
slouken@7312
   235
                DirectFB_TranslateKey(_this, evt, &keysym, &unicode);
gabomdq@7678
   236
                /* printf("Scancode %d  %d %d\n", keysym.scancode, evt->key_code, evt->key_id); */
slouken@4568
   237
                SDL_SendKeyboardKey_ex(0, SDL_PRESSED, keysym.scancode);
couriersud@3023
   238
                if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
slouken@7191
   239
                    SDL_zero(text);
slouken@7312
   240
                    UnicodeToUtf8(unicode, text);
couriersud@3023
   241
                    if (*text) {
slouken@4568
   242
                        SDL_SendKeyboardText_ex(0, text);
couriersud@3023
   243
                    }
couriersud@3023
   244
                }
couriersud@3023
   245
            }
couriersud@3023
   246
            break;
couriersud@3023
   247
        case DWET_KEYUP:
couriersud@3023
   248
            if (!devdata->use_linux_input) {
slouken@7312
   249
                DirectFB_TranslateKey(_this, evt, &keysym, &unicode);
slouken@4568
   250
                SDL_SendKeyboardKey_ex(0, SDL_RELEASED, keysym.scancode);
couriersud@3023
   251
            }
couriersud@3023
   252
            break;
couriersud@3023
   253
        case DWET_POSITION:
slouken@5199
   254
            if (ClientXY(windata, &evt->x, &evt->y)) {
slouken@5199
   255
                SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_MOVED,
couriersud@3023
   256
                                    evt->x, evt->y);
couriersud@3023
   257
            }
couriersud@3023
   258
            break;
couriersud@3023
   259
        case DWET_POSITION_SIZE:
slouken@5199
   260
            if (ClientXY(windata, &evt->x, &evt->y)) {
slouken@5199
   261
                SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_MOVED,
couriersud@3023
   262
                                    evt->x, evt->y);
couriersud@3023
   263
            }
couriersud@3023
   264
            /* fall throught */
couriersud@3023
   265
        case DWET_SIZE:
slouken@7191
   266
            /* FIXME: what about < 0 */
slouken@5199
   267
            evt->w -= (windata->theme.right_size + windata->theme.left_size);
couriersud@3023
   268
            evt->h -=
slouken@5199
   269
                (windata->theme.top_size + windata->theme.bottom_size +
slouken@5199
   270
                 windata->theme.caption_size);
slouken@5199
   271
            SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_RESIZED,
couriersud@3023
   272
                                evt->w, evt->h);
couriersud@3023
   273
            break;
couriersud@3023
   274
        case DWET_CLOSE:
slouken@5199
   275
            SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_CLOSE, 0, 0);
couriersud@3023
   276
            break;
couriersud@3023
   277
        case DWET_GOTFOCUS:
slouken@5199
   278
            DirectFB_SetContext(_this, sdlwin);
slouken@5199
   279
            FocusAllKeyboards(_this, sdlwin);
slouken@5199
   280
            SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_FOCUS_GAINED,
couriersud@3023
   281
                                0, 0);
couriersud@3023
   282
            break;
couriersud@3023
   283
        case DWET_LOSTFOCUS:
slouken@5199
   284
            SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
couriersud@3023
   285
            FocusAllKeyboards(_this, 0);
couriersud@3023
   286
            break;
couriersud@3023
   287
        case DWET_ENTER:
couriersud@3023
   288
            /* SDL_DirectFB_ReshowCursor(_this, 0); */
slouken@5199
   289
            FocusAllMice(_this, sdlwin);
slouken@7191
   290
            /* FIXME: when do we really enter ? */
slouken@5199
   291
            if (ClientXY(windata, &evt->x, &evt->y))
couriersud@3023
   292
                MotionAllMice(_this, evt->x, evt->y);
slouken@5199
   293
            SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_ENTER, 0, 0);
couriersud@3023
   294
            break;
couriersud@3023
   295
        case DWET_LEAVE:
slouken@5199
   296
            SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_LEAVE, 0, 0);
couriersud@3023
   297
            FocusAllMice(_this, 0);
couriersud@3023
   298
            /* SDL_DirectFB_ReshowCursor(_this, 1); */
couriersud@3023
   299
            break;
couriersud@3023
   300
        default:
couriersud@3023
   301
            ;
couriersud@3023
   302
        }
couriersud@3023
   303
    } else
couriersud@3023
   304
        printf("Event Clazz %d\n", evt->clazz);
couriersud@3023
   305
}
couriersud@3023
   306
couriersud@3023
   307
static void
slouken@4636
   308
ProcessInputEvent(_THIS, DFBInputEvent * ievt)
couriersud@3023
   309
{
couriersud@3023
   310
    SDL_DFB_DEVICEDATA(_this);
slouken@5218
   311
    SDL_Keysym keysym;
couriersud@3023
   312
    int kbd_idx;
slouken@7312
   313
    Uint32 unicode;
slouken@5199
   314
    char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
couriersud@3023
   315
couriersud@3023
   316
    if (!devdata->use_linux_input) {
couriersud@3023
   317
        if (ievt->type == DIET_AXISMOTION) {
slouken@4636
   318
            if ((devdata->grabbed_window != NULL) && (ievt->flags & DIEF_AXISREL)) {
couriersud@3023
   319
                if (ievt->axis == DIAI_X)
slouken@4636
   320
                    SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1,
couriersud@3023
   321
                                        ievt->axisrel, 0, 0);
couriersud@3023
   322
                else if (ievt->axis == DIAI_Y)
slouken@4636
   323
                    SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1, 0,
couriersud@3023
   324
                                        ievt->axisrel, 0);
couriersud@3023
   325
            }
couriersud@3023
   326
        }
couriersud@3023
   327
    } else {
couriersud@3023
   328
        static int last_x, last_y;
couriersud@3023
   329
couriersud@3023
   330
        switch (ievt->type) {
couriersud@3023
   331
        case DIET_AXISMOTION:
couriersud@3023
   332
            if (ievt->flags & DIEF_AXISABS) {
couriersud@3023
   333
                if (ievt->axis == DIAI_X)
couriersud@3023
   334
                    last_x = ievt->axisabs;
couriersud@3023
   335
                else if (ievt->axis == DIAI_Y)
couriersud@3023
   336
                    last_y = ievt->axisabs;
couriersud@3023
   337
                if (!(ievt->flags & DIEF_FOLLOW)) {
slouken@4636
   338
#if USE_MULTI_API
couriersud@3023
   339
                    SDL_Mouse *mouse = SDL_GetMouse(ievt->device_id);
couriersud@3023
   340
                    SDL_Window *window = SDL_GetWindowFromID(mouse->focus);
slouken@4636
   341
#else
slouken@4636
   342
                    SDL_Window *window = devdata->grabbed_window;
slouken@4636
   343
#endif
couriersud@3023
   344
                    if (window) {
couriersud@3023
   345
                        DFB_WindowData *windata =
couriersud@3023
   346
                            (DFB_WindowData *) window->driverdata;
couriersud@3023
   347
                        int x, y;
couriersud@3023
   348
slouken@5199
   349
                        windata->dfbwin->GetPosition(windata->dfbwin, &x, &y);
slouken@4636
   350
                        SDL_SendMouseMotion_ex(window, ievt->device_id, 0,
couriersud@3023
   351
                                            last_x - (x +
couriersud@3023
   352
                                                      windata->client.x),
couriersud@3023
   353
                                            last_y - (y +
couriersud@3023
   354
                                                      windata->client.y), 0);
couriersud@3023
   355
                    } else {
slouken@4636
   356
                        SDL_SendMouseMotion_ex(window, ievt->device_id, 0, last_x,
couriersud@3023
   357
                                            last_y, 0);
couriersud@3023
   358
                    }
couriersud@3023
   359
                }
couriersud@3023
   360
            } else if (ievt->flags & DIEF_AXISREL) {
couriersud@3023
   361
                if (ievt->axis == DIAI_X)
slouken@4636
   362
                    SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1,
couriersud@3023
   363
                                        ievt->axisrel, 0, 0);
couriersud@3023
   364
                else if (ievt->axis == DIAI_Y)
slouken@4636
   365
                    SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1, 0,
couriersud@3023
   366
                                        ievt->axisrel, 0);
couriersud@3023
   367
            }
couriersud@3023
   368
            break;
couriersud@3023
   369
        case DIET_KEYPRESS:
couriersud@3023
   370
            kbd_idx = KbdIndex(_this, ievt->device_id);
slouken@7312
   371
            DirectFB_TranslateKeyInputEvent(_this, ievt, &keysym, &unicode);
gabomdq@7678
   372
            /* printf("Scancode %d  %d %d\n", keysym.scancode, evt->key_code, evt->key_id); */
slouken@4568
   373
            SDL_SendKeyboardKey_ex(kbd_idx, SDL_PRESSED, keysym.scancode);
couriersud@3023
   374
            if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
slouken@5199
   375
                SDL_zero(text);
slouken@7312
   376
                UnicodeToUtf8(unicode, text);
couriersud@3023
   377
                if (*text) {
slouken@4568
   378
                    SDL_SendKeyboardText_ex(kbd_idx, text);
couriersud@3023
   379
                }
couriersud@3023
   380
            }
couriersud@3023
   381
            break;
couriersud@3023
   382
        case DIET_KEYRELEASE:
couriersud@3023
   383
            kbd_idx = KbdIndex(_this, ievt->device_id);
slouken@7312
   384
            DirectFB_TranslateKeyInputEvent(_this, ievt, &keysym, &unicode);
slouken@4636
   385
            SDL_SendKeyboardKey_ex(kbd_idx, SDL_RELEASED, keysym.scancode);
couriersud@3023
   386
            break;
couriersud@3023
   387
        case DIET_BUTTONPRESS:
couriersud@3023
   388
            if (ievt->buttons & DIBM_LEFT)
slouken@4636
   389
                SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_PRESSED, 1);
couriersud@3023
   390
            if (ievt->buttons & DIBM_MIDDLE)
slouken@4636
   391
                SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_PRESSED, 2);
couriersud@3023
   392
            if (ievt->buttons & DIBM_RIGHT)
slouken@4636
   393
                SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_PRESSED, 3);
couriersud@3023
   394
            break;
couriersud@3023
   395
        case DIET_BUTTONRELEASE:
couriersud@3023
   396
            if (!(ievt->buttons & DIBM_LEFT))
slouken@4636
   397
                SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_RELEASED, 1);
couriersud@3023
   398
            if (!(ievt->buttons & DIBM_MIDDLE))
slouken@4636
   399
                SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_RELEASED, 2);
couriersud@3023
   400
            if (!(ievt->buttons & DIBM_RIGHT))
slouken@4636
   401
                SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_RELEASED, 3);
couriersud@3023
   402
            break;
couriersud@3023
   403
        default:
couriersud@3023
   404
            break;              /* please gcc */
couriersud@3023
   405
        }
couriersud@3023
   406
    }
couriersud@3023
   407
}
couriersud@3023
   408
slouken@1895
   409
void
slouken@2226
   410
DirectFB_PumpEventsWindow(_THIS)
slouken@167
   411
{
slouken@2226
   412
    SDL_DFB_DEVICEDATA(_this);
slouken@2737
   413
    DFBInputEvent ievt;
slouken@5199
   414
    SDL_Window *w;
slouken@2737
   415
slouken@5199
   416
    for (w = devdata->firstwin; w != NULL; w = w->next) {
slouken@5199
   417
        SDL_DFB_WINDOWDATA(w);
slouken@2860
   418
        DFBWindowEvent evt;
slouken@2737
   419
slouken@5199
   420
        while (windata->eventbuffer->GetEvent(windata->eventbuffer,
slouken@2226
   421
                                        DFB_EVENT(&evt)) == DFB_OK) {
slouken@5199
   422
            if (!DirectFB_WM_ProcessEvent(_this, w, &evt)) {
slouken@5199
   423
                /* Send a SDL_SYSWMEVENT if the application wants them */
slouken@5199
   424
                if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) {
slouken@5199
   425
                    SDL_SysWMmsg wmmsg;
slouken@5199
   426
                    SDL_VERSION(&wmmsg.version);
slouken@5199
   427
                    wmmsg.subsystem = SDL_SYSWM_DIRECTFB;
slouken@5199
   428
                    wmmsg.msg.dfb.event.window = evt;
slouken@5199
   429
                    SDL_SendSysWMEvent(&wmmsg);
slouken@5199
   430
                }
slouken@5199
   431
                ProcessWindowEvent(_this, w, &evt);
slouken@5199
   432
            }
slouken@2737
   433
        }
slouken@2737
   434
    }
slouken@2737
   435
slouken@2737
   436
    /* Now get relative events in case we need them */
slouken@2737
   437
    while (devdata->events->GetEvent(devdata->events,
slouken@2737
   438
                                     DFB_EVENT(&ievt)) == DFB_OK) {
slouken@5199
   439
slouken@7191
   440
        if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) {
slouken@5199
   441
            SDL_SysWMmsg wmmsg;
slouken@5199
   442
            SDL_VERSION(&wmmsg.version);
slouken@5199
   443
            wmmsg.subsystem = SDL_SYSWM_DIRECTFB;
slouken@5199
   444
            wmmsg.msg.dfb.event.input = ievt;
slouken@5199
   445
            SDL_SendSysWMEvent(&wmmsg);
slouken@5199
   446
        }
slouken@4636
   447
        ProcessInputEvent(_this, &ievt);
slouken@167
   448
    }
slouken@167
   449
}
slouken@167
   450
slouken@1895
   451
void
slouken@5218
   452
DirectFB_InitOSKeymap(_THIS, SDL_Scancode * keymap, int numkeys)
slouken@167
   453
{
slouken@1895
   454
    int i;
slouken@167
   455
slouken@1895
   456
    /* Initialize the DirectFB key translation table */
slouken@2860
   457
    for (i = 0; i < numkeys; ++i)
slouken@2721
   458
        keymap[i] = SDL_SCANCODE_UNKNOWN;
slouken@1895
   459
slouken@2721
   460
    keymap[DIKI_A - DIKI_UNKNOWN] = SDL_SCANCODE_A;
slouken@2721
   461
    keymap[DIKI_B - DIKI_UNKNOWN] = SDL_SCANCODE_B;
slouken@2721
   462
    keymap[DIKI_C - DIKI_UNKNOWN] = SDL_SCANCODE_C;
slouken@2721
   463
    keymap[DIKI_D - DIKI_UNKNOWN] = SDL_SCANCODE_D;
slouken@2721
   464
    keymap[DIKI_E - DIKI_UNKNOWN] = SDL_SCANCODE_E;
slouken@2721
   465
    keymap[DIKI_F - DIKI_UNKNOWN] = SDL_SCANCODE_F;
slouken@2721
   466
    keymap[DIKI_G - DIKI_UNKNOWN] = SDL_SCANCODE_G;
slouken@2721
   467
    keymap[DIKI_H - DIKI_UNKNOWN] = SDL_SCANCODE_H;
slouken@2721
   468
    keymap[DIKI_I - DIKI_UNKNOWN] = SDL_SCANCODE_I;
slouken@2721
   469
    keymap[DIKI_J - DIKI_UNKNOWN] = SDL_SCANCODE_J;
slouken@2721
   470
    keymap[DIKI_K - DIKI_UNKNOWN] = SDL_SCANCODE_K;
slouken@2721
   471
    keymap[DIKI_L - DIKI_UNKNOWN] = SDL_SCANCODE_L;
slouken@2721
   472
    keymap[DIKI_M - DIKI_UNKNOWN] = SDL_SCANCODE_M;
slouken@2721
   473
    keymap[DIKI_N - DIKI_UNKNOWN] = SDL_SCANCODE_N;
slouken@2721
   474
    keymap[DIKI_O - DIKI_UNKNOWN] = SDL_SCANCODE_O;
slouken@2721
   475
    keymap[DIKI_P - DIKI_UNKNOWN] = SDL_SCANCODE_P;
slouken@2721
   476
    keymap[DIKI_Q - DIKI_UNKNOWN] = SDL_SCANCODE_Q;
slouken@2721
   477
    keymap[DIKI_R - DIKI_UNKNOWN] = SDL_SCANCODE_R;
slouken@2721
   478
    keymap[DIKI_S - DIKI_UNKNOWN] = SDL_SCANCODE_S;
slouken@2721
   479
    keymap[DIKI_T - DIKI_UNKNOWN] = SDL_SCANCODE_T;
slouken@2721
   480
    keymap[DIKI_U - DIKI_UNKNOWN] = SDL_SCANCODE_U;
slouken@2721
   481
    keymap[DIKI_V - DIKI_UNKNOWN] = SDL_SCANCODE_V;
slouken@2721
   482
    keymap[DIKI_W - DIKI_UNKNOWN] = SDL_SCANCODE_W;
slouken@2721
   483
    keymap[DIKI_X - DIKI_UNKNOWN] = SDL_SCANCODE_X;
slouken@2721
   484
    keymap[DIKI_Y - DIKI_UNKNOWN] = SDL_SCANCODE_Y;
slouken@2721
   485
    keymap[DIKI_Z - DIKI_UNKNOWN] = SDL_SCANCODE_Z;
slouken@1895
   486
slouken@2721
   487
    keymap[DIKI_0 - DIKI_UNKNOWN] = SDL_SCANCODE_0;
slouken@2721
   488
    keymap[DIKI_1 - DIKI_UNKNOWN] = SDL_SCANCODE_1;
slouken@2721
   489
    keymap[DIKI_2 - DIKI_UNKNOWN] = SDL_SCANCODE_2;
slouken@2721
   490
    keymap[DIKI_3 - DIKI_UNKNOWN] = SDL_SCANCODE_3;
slouken@2721
   491
    keymap[DIKI_4 - DIKI_UNKNOWN] = SDL_SCANCODE_4;
slouken@2721
   492
    keymap[DIKI_5 - DIKI_UNKNOWN] = SDL_SCANCODE_5;
slouken@2721
   493
    keymap[DIKI_6 - DIKI_UNKNOWN] = SDL_SCANCODE_6;
slouken@2721
   494
    keymap[DIKI_7 - DIKI_UNKNOWN] = SDL_SCANCODE_7;
slouken@2721
   495
    keymap[DIKI_8 - DIKI_UNKNOWN] = SDL_SCANCODE_8;
slouken@2721
   496
    keymap[DIKI_9 - DIKI_UNKNOWN] = SDL_SCANCODE_9;
slouken@1895
   497
slouken@2721
   498
    keymap[DIKI_F1 - DIKI_UNKNOWN] = SDL_SCANCODE_F1;
slouken@2721
   499
    keymap[DIKI_F2 - DIKI_UNKNOWN] = SDL_SCANCODE_F2;
slouken@2721
   500
    keymap[DIKI_F3 - DIKI_UNKNOWN] = SDL_SCANCODE_F3;
slouken@2721
   501
    keymap[DIKI_F4 - DIKI_UNKNOWN] = SDL_SCANCODE_F4;
slouken@2721
   502
    keymap[DIKI_F5 - DIKI_UNKNOWN] = SDL_SCANCODE_F5;
slouken@2721
   503
    keymap[DIKI_F6 - DIKI_UNKNOWN] = SDL_SCANCODE_F6;
slouken@2721
   504
    keymap[DIKI_F7 - DIKI_UNKNOWN] = SDL_SCANCODE_F7;
slouken@2721
   505
    keymap[DIKI_F8 - DIKI_UNKNOWN] = SDL_SCANCODE_F8;
slouken@2721
   506
    keymap[DIKI_F9 - DIKI_UNKNOWN] = SDL_SCANCODE_F9;
slouken@2721
   507
    keymap[DIKI_F10 - DIKI_UNKNOWN] = SDL_SCANCODE_F10;
slouken@2721
   508
    keymap[DIKI_F11 - DIKI_UNKNOWN] = SDL_SCANCODE_F11;
slouken@2721
   509
    keymap[DIKI_F12 - DIKI_UNKNOWN] = SDL_SCANCODE_F12;
slouken@1895
   510
slouken@2721
   511
    keymap[DIKI_ESCAPE - DIKI_UNKNOWN] = SDL_SCANCODE_ESCAPE;
slouken@2721
   512
    keymap[DIKI_LEFT - DIKI_UNKNOWN] = SDL_SCANCODE_LEFT;
slouken@2721
   513
    keymap[DIKI_RIGHT - DIKI_UNKNOWN] = SDL_SCANCODE_RIGHT;
slouken@2721
   514
    keymap[DIKI_UP - DIKI_UNKNOWN] = SDL_SCANCODE_UP;
slouken@2721
   515
    keymap[DIKI_DOWN - DIKI_UNKNOWN] = SDL_SCANCODE_DOWN;
slouken@2721
   516
    keymap[DIKI_CONTROL_L - DIKI_UNKNOWN] = SDL_SCANCODE_LCTRL;
slouken@2721
   517
    keymap[DIKI_CONTROL_R - DIKI_UNKNOWN] = SDL_SCANCODE_RCTRL;
slouken@2721
   518
    keymap[DIKI_SHIFT_L - DIKI_UNKNOWN] = SDL_SCANCODE_LSHIFT;
slouken@2721
   519
    keymap[DIKI_SHIFT_R - DIKI_UNKNOWN] = SDL_SCANCODE_RSHIFT;
slouken@2721
   520
    keymap[DIKI_ALT_L - DIKI_UNKNOWN] = SDL_SCANCODE_LALT;
slouken@2721
   521
    keymap[DIKI_ALT_R - DIKI_UNKNOWN] = SDL_SCANCODE_RALT;
slouken@2721
   522
    keymap[DIKI_META_L - DIKI_UNKNOWN] = SDL_SCANCODE_LGUI;
slouken@2721
   523
    keymap[DIKI_META_R - DIKI_UNKNOWN] = SDL_SCANCODE_RGUI;
slouken@2721
   524
    keymap[DIKI_SUPER_L - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
slouken@2721
   525
    keymap[DIKI_SUPER_R - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
slouken@2737
   526
    /* FIXME:Do we read hyper keys ?
slouken@2737
   527
     * keymap[DIKI_HYPER_L - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
slouken@2737
   528
     * keymap[DIKI_HYPER_R - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
slouken@2737
   529
     */
slouken@2721
   530
    keymap[DIKI_TAB - DIKI_UNKNOWN] = SDL_SCANCODE_TAB;
slouken@2721
   531
    keymap[DIKI_ENTER - DIKI_UNKNOWN] = SDL_SCANCODE_RETURN;
slouken@2721
   532
    keymap[DIKI_SPACE - DIKI_UNKNOWN] = SDL_SCANCODE_SPACE;
slouken@2721
   533
    keymap[DIKI_BACKSPACE - DIKI_UNKNOWN] = SDL_SCANCODE_BACKSPACE;
slouken@2721
   534
    keymap[DIKI_INSERT - DIKI_UNKNOWN] = SDL_SCANCODE_INSERT;
slouken@2721
   535
    keymap[DIKI_DELETE - DIKI_UNKNOWN] = SDL_SCANCODE_DELETE;
slouken@2721
   536
    keymap[DIKI_HOME - DIKI_UNKNOWN] = SDL_SCANCODE_HOME;
slouken@2721
   537
    keymap[DIKI_END - DIKI_UNKNOWN] = SDL_SCANCODE_END;
slouken@2721
   538
    keymap[DIKI_PAGE_UP - DIKI_UNKNOWN] = SDL_SCANCODE_PAGEUP;
slouken@2721
   539
    keymap[DIKI_PAGE_DOWN - DIKI_UNKNOWN] = SDL_SCANCODE_PAGEDOWN;
slouken@2721
   540
    keymap[DIKI_CAPS_LOCK - DIKI_UNKNOWN] = SDL_SCANCODE_CAPSLOCK;
slouken@2721
   541
    keymap[DIKI_NUM_LOCK - DIKI_UNKNOWN] = SDL_SCANCODE_NUMLOCKCLEAR;
slouken@2721
   542
    keymap[DIKI_SCROLL_LOCK - DIKI_UNKNOWN] = SDL_SCANCODE_SCROLLLOCK;
slouken@2721
   543
    keymap[DIKI_PRINT - DIKI_UNKNOWN] = SDL_SCANCODE_PRINTSCREEN;
slouken@2721
   544
    keymap[DIKI_PAUSE - DIKI_UNKNOWN] = SDL_SCANCODE_PAUSE;
slouken@2226
   545
slouken@2721
   546
    keymap[DIKI_KP_EQUAL - DIKI_UNKNOWN] = SDL_SCANCODE_KP_EQUALS;
slouken@2721
   547
    keymap[DIKI_KP_DECIMAL - DIKI_UNKNOWN] = SDL_SCANCODE_KP_PERIOD;
slouken@2721
   548
    keymap[DIKI_KP_0 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_0;
slouken@2721
   549
    keymap[DIKI_KP_1 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_1;
slouken@2721
   550
    keymap[DIKI_KP_2 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_2;
slouken@2721
   551
    keymap[DIKI_KP_3 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_3;
slouken@2721
   552
    keymap[DIKI_KP_4 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_4;
slouken@2721
   553
    keymap[DIKI_KP_5 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_5;
slouken@2721
   554
    keymap[DIKI_KP_6 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_6;
slouken@2721
   555
    keymap[DIKI_KP_7 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_7;
slouken@2721
   556
    keymap[DIKI_KP_8 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_8;
slouken@2721
   557
    keymap[DIKI_KP_9 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_9;
slouken@2721
   558
    keymap[DIKI_KP_DIV - DIKI_UNKNOWN] = SDL_SCANCODE_KP_DIVIDE;
slouken@2721
   559
    keymap[DIKI_KP_MULT - DIKI_UNKNOWN] = SDL_SCANCODE_KP_MULTIPLY;
slouken@2721
   560
    keymap[DIKI_KP_MINUS - DIKI_UNKNOWN] = SDL_SCANCODE_KP_MINUS;
slouken@2721
   561
    keymap[DIKI_KP_PLUS - DIKI_UNKNOWN] = SDL_SCANCODE_KP_PLUS;
slouken@2721
   562
    keymap[DIKI_KP_ENTER - DIKI_UNKNOWN] = SDL_SCANCODE_KP_ENTER;
slouken@2226
   563
slouken@2721
   564
    keymap[DIKI_QUOTE_LEFT - DIKI_UNKNOWN] = SDL_SCANCODE_GRAVE;        /*  TLDE  */
slouken@2721
   565
    keymap[DIKI_MINUS_SIGN - DIKI_UNKNOWN] = SDL_SCANCODE_MINUS;        /*  AE11  */
slouken@2721
   566
    keymap[DIKI_EQUALS_SIGN - DIKI_UNKNOWN] = SDL_SCANCODE_EQUALS;      /*  AE12  */
slouken@2721
   567
    keymap[DIKI_BRACKET_LEFT - DIKI_UNKNOWN] = SDL_SCANCODE_RIGHTBRACKET;       /*  AD11  */
slouken@2721
   568
    keymap[DIKI_BRACKET_RIGHT - DIKI_UNKNOWN] = SDL_SCANCODE_LEFTBRACKET;       /*  AD12  */
slouken@2721
   569
    keymap[DIKI_BACKSLASH - DIKI_UNKNOWN] = SDL_SCANCODE_BACKSLASH;     /*  BKSL  */
slouken@2721
   570
    keymap[DIKI_SEMICOLON - DIKI_UNKNOWN] = SDL_SCANCODE_SEMICOLON;     /*  AC10  */
slouken@2721
   571
    keymap[DIKI_QUOTE_RIGHT - DIKI_UNKNOWN] = SDL_SCANCODE_APOSTROPHE;  /*  AC11  */
slouken@2721
   572
    keymap[DIKI_COMMA - DIKI_UNKNOWN] = SDL_SCANCODE_COMMA;     /*  AB08  */
slouken@2721
   573
    keymap[DIKI_PERIOD - DIKI_UNKNOWN] = SDL_SCANCODE_PERIOD;   /*  AB09  */
slouken@2721
   574
    keymap[DIKI_SLASH - DIKI_UNKNOWN] = SDL_SCANCODE_SLASH;     /*  AB10  */
slouken@2721
   575
    keymap[DIKI_LESS_SIGN - DIKI_UNKNOWN] = SDL_SCANCODE_NONUSBACKSLASH;        /*  103rd  */
slouken@2721
   576
slouken@167
   577
}
slouken@167
   578
slouken@5218
   579
static SDL_Keysym *
slouken@7312
   580
DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt, SDL_Keysym * keysym, Uint32 *unicode)
slouken@2226
   581
{
slouken@2721
   582
    SDL_DFB_DEVICEDATA(_this);
slouken@5199
   583
    int kbd_idx = 0; /* Window events lag the device source KbdIndex(_this, evt->device_id); */
slouken@5199
   584
    DFB_KeyboardData *kbd = &devdata->keyboard[kbd_idx];
slouken@167
   585
slouken@5199
   586
    keysym->scancode = SDL_SCANCODE_UNKNOWN;
slouken@5199
   587
slouken@5199
   588
    if (kbd->map && evt->key_code >= kbd->map_adjust &&
slouken@7191
   589
        evt->key_code < kbd->map_size + kbd->map_adjust)
slouken@7191
   590
        keysym->scancode = kbd->map[evt->key_code - kbd->map_adjust];
slouken@2226
   591
couriersud@3023
   592
    if (keysym->scancode == SDL_SCANCODE_UNKNOWN ||
slouken@5199
   593
        devdata->keyboard[kbd_idx].is_generic) {
slouken@2860
   594
        if (evt->key_id - DIKI_UNKNOWN < SDL_arraysize(oskeymap))
slouken@2860
   595
            keysym->scancode = oskeymap[evt->key_id - DIKI_UNKNOWN];
slouken@2721
   596
        else
slouken@2721
   597
            keysym->scancode = SDL_SCANCODE_UNKNOWN;
slouken@2721
   598
    }
slouken@2226
   599
slouken@7312
   600
    *unicode =
slouken@2721
   601
        (DFB_KEY_TYPE(evt->key_symbol) == DIKT_UNICODE) ? evt->key_symbol : 0;
slouken@7312
   602
    if (*unicode == 0 &&
couriersud@3023
   603
        (evt->key_symbol > 0 && evt->key_symbol < 255))
slouken@7312
   604
        *unicode = evt->key_symbol;
slouken@167
   605
slouken@1895
   606
    return keysym;
slouken@167
   607
}
slouken@167
   608
slouken@5218
   609
static SDL_Keysym *
slouken@5199
   610
DirectFB_TranslateKeyInputEvent(_THIS, DFBInputEvent * evt,
slouken@7312
   611
                                SDL_Keysym * keysym, Uint32 *unicode)
slouken@2860
   612
{
slouken@2860
   613
    SDL_DFB_DEVICEDATA(_this);
slouken@5199
   614
    int kbd_idx = KbdIndex(_this, evt->device_id);
slouken@5199
   615
    DFB_KeyboardData *kbd = &devdata->keyboard[kbd_idx];
slouken@2860
   616
slouken@5199
   617
    keysym->scancode = SDL_SCANCODE_UNKNOWN;
slouken@2860
   618
slouken@5199
   619
    if (kbd->map && evt->key_code >= kbd->map_adjust &&
slouken@7191
   620
        evt->key_code < kbd->map_size + kbd->map_adjust)
slouken@7191
   621
        keysym->scancode = kbd->map[evt->key_code - kbd->map_adjust];
slouken@5199
   622
slouken@5199
   623
    if (keysym->scancode == SDL_SCANCODE_UNKNOWN || devdata->keyboard[kbd_idx].is_generic) {
slouken@2860
   624
        if (evt->key_id - DIKI_UNKNOWN < SDL_arraysize(oskeymap))
slouken@2860
   625
            keysym->scancode = oskeymap[evt->key_id - DIKI_UNKNOWN];
slouken@2860
   626
        else
slouken@2860
   627
            keysym->scancode = SDL_SCANCODE_UNKNOWN;
slouken@2860
   628
    }
slouken@2860
   629
slouken@7312
   630
    *unicode =
slouken@2860
   631
        (DFB_KEY_TYPE(evt->key_symbol) == DIKT_UNICODE) ? evt->key_symbol : 0;
slouken@7312
   632
    if (*unicode == 0 &&
couriersud@3023
   633
        (evt->key_symbol > 0 && evt->key_symbol < 255))
slouken@7312
   634
        *unicode = evt->key_symbol;
slouken@2860
   635
slouken@2860
   636
    return keysym;
slouken@2860
   637
}
couriersud@3023
   638
slouken@1895
   639
static int
slouken@2226
   640
DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button)
slouken@167
   641
{
slouken@2226
   642
    switch (button) {
slouken@167
   643
    case DIBI_LEFT:
slouken@1895
   644
        return 1;
slouken@167
   645
    case DIBI_MIDDLE:
slouken@1895
   646
        return 2;
slouken@167
   647
    case DIBI_RIGHT:
slouken@1895
   648
        return 3;
slouken@167
   649
    default:
slouken@1895
   650
        return 0;
slouken@167
   651
    }
slouken@167
   652
}
slouken@1895
   653
slouken@2721
   654
static DFBEnumerationResult
slouken@4636
   655
EnumKeyboards(DFBInputDeviceID device_id,
couriersud@3023
   656
                DFBInputDeviceDescription desc, void *callbackdata)
slouken@2721
   657
{
slouken@7191
   658
    cb_data *cb = callbackdata;
slouken@4636
   659
    DFB_DeviceData *devdata = cb->devdata;
slouken@4568
   660
#if USE_MULTI_API
slouken@2721
   661
    SDL_Keyboard keyboard;
slouken@4568
   662
#endif
slouken@5220
   663
    SDL_Keycode keymap[SDL_NUM_SCANCODES];
slouken@2721
   664
slouken@7191
   665
    if (!cb->sys_kbd) {
slouken@7191
   666
        if (cb->sys_ids) {
slouken@7191
   667
            if (device_id >= 0x10)
slouken@7191
   668
                return DFENUM_OK;
slouken@7191
   669
        } else {
slouken@7191
   670
            if (device_id < 0x10)
slouken@7191
   671
                return DFENUM_OK;
slouken@7191
   672
        }
slouken@7191
   673
    } else {
slouken@7191
   674
        if (device_id != DIDID_KEYBOARD)
slouken@7191
   675
            return DFENUM_OK;
slouken@7191
   676
    }
slouken@7191
   677
slouken@4636
   678
    if ((desc.caps & DIDTF_KEYBOARD)) {
slouken@4568
   679
#if USE_MULTI_API
slouken@2721
   680
        SDL_zero(keyboard);
slouken@4636
   681
        SDL_AddKeyboard(&keyboard, devdata->num_keyboard);
slouken@4568
   682
#endif
slouken@2860
   683
        devdata->keyboard[devdata->num_keyboard].id = device_id;
slouken@2860
   684
        devdata->keyboard[devdata->num_keyboard].is_generic = 0;
slouken@2860
   685
        if (!strncmp("X11", desc.name, 3))
slouken@5199
   686
        {
slouken@7191
   687
            devdata->keyboard[devdata->num_keyboard].map = xfree86_scancode_table2;
slouken@7191
   688
            devdata->keyboard[devdata->num_keyboard].map_size = SDL_arraysize(xfree86_scancode_table2);
slouken@7191
   689
            devdata->keyboard[devdata->num_keyboard].map_adjust = 8;
slouken@5199
   690
        } else {
slouken@7191
   691
            devdata->keyboard[devdata->num_keyboard].map = linux_scancode_table;
slouken@7191
   692
            devdata->keyboard[devdata->num_keyboard].map_size = SDL_arraysize(linux_scancode_table);
slouken@7191
   693
            devdata->keyboard[devdata->num_keyboard].map_adjust = 0;
slouken@5199
   694
        }
slouken@2860
   695
slouken@7191
   696
        SDL_DFB_LOG("Keyboard %d - %s\n", device_id, desc.name);
slouken@7191
   697
slouken@2860
   698
        SDL_GetDefaultKeymap(keymap);
slouken@4636
   699
#if USE_MULTI_API
slouken@2860
   700
        SDL_SetKeymap(devdata->num_keyboard, 0, keymap, SDL_NUM_SCANCODES);
slouken@4636
   701
#else
slouken@4636
   702
        SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES);
slouken@4636
   703
#endif
slouken@2860
   704
        devdata->num_keyboard++;
slouken@4636
   705
slouken@7191
   706
        if (cb->sys_kbd)
slouken@7191
   707
            return DFENUM_CANCEL;
slouken@2860
   708
    }
slouken@2860
   709
    return DFENUM_OK;
slouken@2721
   710
}
slouken@2721
   711
slouken@2721
   712
void
slouken@2721
   713
DirectFB_InitKeyboard(_THIS)
slouken@2721
   714
{
slouken@2721
   715
    SDL_DFB_DEVICEDATA(_this);
slouken@7191
   716
    cb_data cb;
slouken@7191
   717
slouken@2860
   718
    DirectFB_InitOSKeymap(_this, &oskeymap[0], SDL_arraysize(oskeymap));
slouken@2721
   719
slouken@2860
   720
    devdata->num_keyboard = 0;
slouken@4636
   721
    cb.devdata = devdata;
slouken@7191
   722
slouken@2998
   723
    if (devdata->use_linux_input) {
slouken@7191
   724
        cb.sys_kbd = 0;
slouken@4636
   725
        cb.sys_ids = 0;
slouken@3013
   726
        SDL_DFB_CHECK(devdata->dfb->
slouken@4636
   727
                      EnumInputDevices(devdata->dfb, EnumKeyboards, &cb));
slouken@2860
   728
        if (devdata->num_keyboard == 0) {
slouken@4636
   729
            cb.sys_ids = 1;
couriersud@3023
   730
            SDL_DFB_CHECK(devdata->dfb->EnumInputDevices(devdata->dfb,
couriersud@3023
   731
                                                         EnumKeyboards,
slouken@4636
   732
                                                         &cb));
slouken@2860
   733
        }
slouken@4636
   734
    } else {
slouken@7191
   735
        cb.sys_kbd = 1;
couriersud@3023
   736
        SDL_DFB_CHECK(devdata->dfb->EnumInputDevices(devdata->dfb,
slouken@4636
   737
                                                     EnumKeyboards,
slouken@4636
   738
                                                     &cb));
slouken@2860
   739
    }
slouken@2721
   740
}
slouken@2721
   741
slouken@2737
   742
void
slouken@2737
   743
DirectFB_QuitKeyboard(_THIS)
slouken@2737
   744
{
gabomdq@7678
   745
    /* SDL_DFB_DEVICEDATA(_this); */
slouken@2737
   746
slouken@2860
   747
    SDL_KeyboardQuit();
slouken@2737
   748
slouken@2737
   749
}
slouken@2737
   750
slouken@6044
   751
#endif /* SDL_VIDEO_DRIVER_DIRECTFB */