Ubuntu Pastebin

Paste from bschaefer at Fri, 29 May 2015 19:44:57 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
static void Mir_HandleKeyEvent(MirSurface const* surface, MirKeyboardEvent const* key_event)
{
    xkb_keysym_t key_code;
    MirKeyboardAction action;
    SDLKey key = SDLK_UNKNOWN;
    Uint8 key_state = 0;
    int scan_code;
    char text[8];
    int size = 0;

    action    = mir_keyboard_event_action(key_event);
    key_code  = mir_keyboard_event_key_code(key_event);
    scan_code = mir_keyboard_event_scan_code(key_event);

    if (action == mir_keyboard_action_down)
        key_state = SDL_PRESSED;
    else if (action == mir_keyboard_action_up)
        key_state = SDL_RELEASED;

    switch (key_code >> 8)
    {
        case(0x00):
            key = key_code & 0xFF;
          break;
        case(0xFF):
            key = MISC_keymap[key_code & 0xFF];
          break;
        default:
          break;
    }

    size = xkb_keysym_to_utf8(key_code, text, sizeof text);

    SDL_keysym keysym;
    keysym.sym      = key;
    keysym.scancode = scan_code + MIN_KEYCODE;
    keysym.mod      = KMOD_NONE;
    memcpy(&keysym.unicode, text, size);

    SDL_PrivateKeyboard(key_state, &keysym);
}
Download as text