Check-in [344e19eb18]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:preliminary, hackish implementation of wayland key repeat
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 344e19eb186c9a3c3b665f3479941f685d2808e1
User & Date: chw 2017-01-02 19:48:23.311
Context
2017-01-03
10:57
small fix in SDL2 X11 video driver check-in: 14a9211ba1 user: chw tags: trunk
2017-01-02
19:48
preliminary, hackish implementation of wayland key repeat check-in: 344e19eb18 user: chw tags: trunk
08:50
add tcl upstream changes check-in: 96ef6083f8 user: chw tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to jni/SDL2/include/SDL_events.h.
193
194
195
196
197
198
199


200
201
202
203
204
205
206
    Uint32 timestamp;
    Uint32 windowID;    /**< The window with keyboard focus, if any */
    Uint8 state;        /**< ::SDL_PRESSED or ::SDL_RELEASED */
    Uint8 repeat;       /**< Non-zero if this is a key repeat */
    Uint8 padding2;
    Uint8 padding3;
    SDL_Keysym keysym;  /**< The key that was pressed or released */


} SDL_KeyboardEvent;

#define SDL_TEXTEDITINGEVENT_TEXT_SIZE (32)
/**
 *  \brief Keyboard text editing event structure (event.edit.*)
 */
typedef struct SDL_TextEditingEvent







>
>







193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
    Uint32 timestamp;
    Uint32 windowID;    /**< The window with keyboard focus, if any */
    Uint8 state;        /**< ::SDL_PRESSED or ::SDL_RELEASED */
    Uint8 repeat;       /**< Non-zero if this is a key repeat */
    Uint8 padding2;
    Uint8 padding3;
    SDL_Keysym keysym;  /**< The key that was pressed or released */
    Uint16 rate;        /**< Wayland: key repeat rate */
    Uint16 delay;       /**< Wayland: key repeat delay */
} SDL_KeyboardEvent;

#define SDL_TEXTEDITINGEVENT_TEXT_SIZE (32)
/**
 *  \brief Keyboard text editing event structure (event.edit.*)
 */
typedef struct SDL_TextEditingEvent
Changes to jni/SDL2/src/core/linux/SDL_evdev.c.
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
                        break;
                    }

                    /* Probably keyboard */
                    scan_code = SDL_EVDEV_translate_keycode(events[i].code);
                    if (scan_code != SDL_SCANCODE_UNKNOWN) {
                        if (events[i].value == 0) {
                            SDL_SendKeyboardKey(SDL_RELEASED, scan_code);
                        } else if (events[i].value == 1 || events[i].value == 2 /* key repeated */) {
                            SDL_SendKeyboardKey(SDL_PRESSED, scan_code);
#ifdef SDL_INPUT_LINUXKD
                            SDL_EVDEV_do_text_input(events[i].code);
#endif /* SDL_INPUT_LINUXKD */
                        }
                    }
                    break;
                case EV_ABS:







|

|







444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
                        break;
                    }

                    /* Probably keyboard */
                    scan_code = SDL_EVDEV_translate_keycode(events[i].code);
                    if (scan_code != SDL_SCANCODE_UNKNOWN) {
                        if (events[i].value == 0) {
                            SDL_SendKeyboardKey(SDL_RELEASED, scan_code, 0, 0);
                        } else if (events[i].value == 1 || events[i].value == 2 /* key repeated */) {
                            SDL_SendKeyboardKey(SDL_PRESSED, scan_code, 0, 0);
#ifdef SDL_INPUT_LINUXKD
                            SDL_EVDEV_do_text_input(events[i].code);
#endif /* SDL_INPUT_LINUXKD */
                        }
                    }
                    break;
                case EV_ABS:
Changes to jni/SDL2/src/core/winrt/SDL_winrtapp_direct3d.cpp.
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
{
    WINRT_ProcessCharacterReceivedEvent(args);
}

template <typename BackButtonEventArgs>
static void WINRT_OnBackButtonPressed(BackButtonEventArgs ^ args)
{
    SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_AC_BACK);
    SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_AC_BACK);

    if (SDL_GetHintBoolean(SDL_HINT_WINRT_HANDLE_BACK_BUTTON, SDL_FALSE)) {
        args->Handled = true;
    }
}

#if NTDDI_VERSION == NTDDI_WIN10







|
|







815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
{
    WINRT_ProcessCharacterReceivedEvent(args);
}

template <typename BackButtonEventArgs>
static void WINRT_OnBackButtonPressed(BackButtonEventArgs ^ args)
{
    SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_AC_BACK, 0, 0);
    SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_AC_BACK, 0, 0);

    if (SDL_GetHintBoolean(SDL_HINT_WINRT_HANDLE_BACK_BUTTON, SDL_FALSE)) {
        args->Handled = true;
    }
}

#if NTDDI_VERSION == NTDDI_WIN10
Changes to jni/SDL2/src/events/SDL_keyboard.c.
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
    SDL_Scancode scancode;

#ifdef DEBUG_KEYBOARD
    printf("Resetting keyboard\n");
#endif
    for (scancode = 0; scancode < SDL_NUM_SCANCODES; ++scancode) {
        if (keyboard->keystate[scancode] == SDL_PRESSED) {
            SDL_SendKeyboardKey(SDL_RELEASED, scancode);
        }
    }
}

void
SDL_GetDefaultKeymap(SDL_Keycode * keymap)
{







|







567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
    SDL_Scancode scancode;

#ifdef DEBUG_KEYBOARD
    printf("Resetting keyboard\n");
#endif
    for (scancode = 0; scancode < SDL_NUM_SCANCODES; ++scancode) {
        if (keyboard->keystate[scancode] == SDL_PRESSED) {
            SDL_SendKeyboardKey(SDL_RELEASED, scancode, 0, 0);
        }
    }
}

void
SDL_GetDefaultKeymap(SDL_Keycode * keymap)
{
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
                video->StartTextInput(video);
            }
        }
    }
}

int
SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
{
    SDL_Keyboard *keyboard = &SDL_keyboard;
    int posted;
    SDL_Keymod modifier;
    SDL_Keycode keycode;
    Uint16 modstate;
    Uint32 type;







|







654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
                video->StartTextInput(video);
            }
        }
    }
}

int
SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode, Uint16 rate, Uint16 delay)
{
    SDL_Keyboard *keyboard = &SDL_keyboard;
    int posted;
    SDL_Keymod modifier;
    SDL_Keycode keycode;
    Uint16 modstate;
    Uint32 type;
761
762
763
764
765
766
767


768
769
770
771
772
773
774
        event.key.type = type;
        event.key.state = state;
        event.key.repeat = repeat;
        event.key.keysym.scancode = scancode;
        event.key.keysym.sym = keycode;
        event.key.keysym.mod = modstate;
        event.key.windowID = keyboard->focus ? keyboard->focus->id : 0;


        posted = (SDL_PushEvent(&event) > 0);
    }
    return (posted);
}

int
SDL_SendKeyboardText(const char *text)







>
>







761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
        event.key.type = type;
        event.key.state = state;
        event.key.repeat = repeat;
        event.key.keysym.scancode = scancode;
        event.key.keysym.sym = keycode;
        event.key.keysym.mod = modstate;
        event.key.windowID = keyboard->focus ? keyboard->focus->id : 0;
        event.key.rate = rate;
        event.key.delay = delay;
        posted = (SDL_PushEvent(&event) > 0);
    }
    return (posted);
}

int
SDL_SendKeyboardText(const char *text)
Changes to jni/SDL2/src/events/SDL_keyboard_c.h.
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
   VideoQuit()). */
extern void SDL_SetScancodeName(SDL_Scancode scancode, const char *name);

/* Set the keyboard focus window */
extern void SDL_SetKeyboardFocus(SDL_Window * window);

/* Send a keyboard key event */
extern int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode);

/* Send keyboard text input */
extern int SDL_SendKeyboardText(const char *text);

/* Send editing text for selected range from start to end */
extern int SDL_SendEditingText(const char *text, int start, int end);








|







44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
   VideoQuit()). */
extern void SDL_SetScancodeName(SDL_Scancode scancode, const char *name);

/* Set the keyboard focus window */
extern void SDL_SetKeyboardFocus(SDL_Window * window);

/* Send a keyboard key event */
extern int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode, Uint16 rate, Uint16 delay);

/* Send keyboard text input */
extern int SDL_SendKeyboardText(const char *text);

/* Send editing text for selected range from start to end */
extern int SDL_SendEditingText(const char *text, int start, int end);

Changes to jni/SDL2/src/main/haiku/SDL_BApp.h.
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
        }

        /* Make sure this isn't a repeated event (key pressed and held) */
        if(state == SDL_PRESSED && BE_GetKeyState(scancode) == SDL_PRESSED) {
            return;
        }
        BE_SetKeyState(scancode, state);
        SDL_SendKeyboardKey(state, BE_GetScancodeFromBeKey(scancode));
        
        if (state == SDL_PRESSED && SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
            const int8 *keyUtf8;
            ssize_t count;
            if (msg->FindData("key-utf8", B_INT8_TYPE, (const void**)&keyUtf8, &count) == B_OK) {
                char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
                SDL_zero(text);







|







268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
        }

        /* Make sure this isn't a repeated event (key pressed and held) */
        if(state == SDL_PRESSED && BE_GetKeyState(scancode) == SDL_PRESSED) {
            return;
        }
        BE_SetKeyState(scancode, state);
        SDL_SendKeyboardKey(state, BE_GetScancodeFromBeKey(scancode), 0, 0);
        
        if (state == SDL_PRESSED && SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
            const int8 *keyUtf8;
            ssize_t count;
            if (msg->FindData("key-utf8", B_INT8_TYPE, (const void**)&keyUtf8, &count) == B_OK) {
                char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
                SDL_zero(text);
Changes to jni/SDL2/src/video/android/SDL_androidkeyboard.c.
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
    }
    return scancode;
}

int
Android_OnKeyDown(int keycode)
{
    return SDL_SendKeyboardKey(SDL_PRESSED, TranslateKeycode(keycode));
}

int
Android_OnKeyUp(int keycode)
{
    return SDL_SendKeyboardKey(SDL_RELEASED, TranslateKeycode(keycode));
}

SDL_bool
Android_HasScreenKeyboardSupport(_THIS)
{
    return SDL_TRUE;
}







|





|







335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
    }
    return scancode;
}

int
Android_OnKeyDown(int keycode)
{
    return SDL_SendKeyboardKey(SDL_PRESSED, TranslateKeycode(keycode), 0, 0);
}

int
Android_OnKeyUp(int keycode)
{
    return SDL_SendKeyboardKey(SDL_RELEASED, TranslateKeycode(keycode), 0, 0);
}

SDL_bool
Android_HasScreenKeyboardSupport(_THIS)
{
    return SDL_TRUE;
}
Changes to jni/SDL2/src/video/directfb/SDL_DirectFB_events.c.
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "../../events/scancodes_xfree86.h"

#include "SDL_DirectFB_events.h"

#if USE_MULTI_API
#define SDL_SendMouseMotion_ex(w, id, relative, x, y, p) SDL_SendMouseMotion(w, id, relative, x, y, p)
#define SDL_SendMouseButton_ex(w, id, state, button) SDL_SendMouseButton(w, id, state, button)
#define SDL_SendKeyboardKey_ex(id, state, scancode) SDL_SendKeyboardKey(id, state, scancode)
#define SDL_SendKeyboardText_ex(id, text) SDL_SendKeyboardText(id, text)
#else
#define SDL_SendMouseMotion_ex(w, id, relative, x, y, p) SDL_SendMouseMotion(w, id, relative, x, y)
#define SDL_SendMouseButton_ex(w, id, state, button) SDL_SendMouseButton(w, id, state, button)
#define SDL_SendKeyboardKey_ex(id, state, scancode) SDL_SendKeyboardKey(state, scancode)
#define SDL_SendKeyboardText_ex(id, text) SDL_SendKeyboardText(text)
#endif

typedef struct _cb_data cb_data;
struct _cb_data
{
    DFB_DeviceData *devdata;







|




|







38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "../../events/scancodes_xfree86.h"

#include "SDL_DirectFB_events.h"

#if USE_MULTI_API
#define SDL_SendMouseMotion_ex(w, id, relative, x, y, p) SDL_SendMouseMotion(w, id, relative, x, y, p)
#define SDL_SendMouseButton_ex(w, id, state, button) SDL_SendMouseButton(w, id, state, button)
#define SDL_SendKeyboardKey_ex(id, state, scancode) SDL_SendKeyboardKey(id, state, scancode, 0, 0)
#define SDL_SendKeyboardText_ex(id, text) SDL_SendKeyboardText(id, text)
#else
#define SDL_SendMouseMotion_ex(w, id, relative, x, y, p) SDL_SendMouseMotion(w, id, relative, x, y)
#define SDL_SendMouseButton_ex(w, id, state, button) SDL_SendMouseButton(w, id, state, button)
#define SDL_SendKeyboardKey_ex(id, state, scancode) SDL_SendKeyboardKey(state, scancode, 0, 0)
#define SDL_SendKeyboardText_ex(id, text) SDL_SendKeyboardText(text)
#endif

typedef struct _cb_data cb_data;
struct _cb_data
{
    DFB_DeviceData *devdata;
Changes to jni/SDL2/src/video/emscripten/SDL_emscriptenevents.c.
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
                        scancode = SDL_SCANCODE_RALT;
                        break;
                    case SDL_SCANCODE_LGUI:
                        scancode = SDL_SCANCODE_RGUI;
                        break;
                }
            }
            SDL_SendKeyboardKey(eventType == EMSCRIPTEN_EVENT_KEYDOWN ? SDL_PRESSED : SDL_RELEASED, scancode);
        }
    }

    SDL_bool prevent_default = SDL_GetEventState(eventType == EMSCRIPTEN_EVENT_KEYDOWN ? SDL_KEYDOWN : SDL_KEYUP) == SDL_ENABLE;

    /* if TEXTINPUT events are enabled we can't prevent keydown or we won't get keypress
     * we need to ALWAYS prevent backspace and tab otherwise chrome takes action and does bad navigation UX







|







491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
                        scancode = SDL_SCANCODE_RALT;
                        break;
                    case SDL_SCANCODE_LGUI:
                        scancode = SDL_SCANCODE_RGUI;
                        break;
                }
            }
            SDL_SendKeyboardKey(eventType == EMSCRIPTEN_EVENT_KEYDOWN ? SDL_PRESSED : SDL_RELEASED, scancode, 0, 0);
        }
    }

    SDL_bool prevent_default = SDL_GetEventState(eventType == EMSCRIPTEN_EVENT_KEYDOWN ? SDL_KEYDOWN : SDL_KEYUP) == SDL_ENABLE;

    /* if TEXTINPUT events are enabled we can't prevent keydown or we won't get keypress
     * we need to ALWAYS prevent backspace and tab otherwise chrome takes action and does bad navigation UX
Changes to jni/SDL2/src/video/mir/SDL_mirevents.c.
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
    if (action == mir_keyboard_action_up)
        key_state = SDL_RELEASED;

    if (event_scancode < SDL_arraysize(xfree86_scancode_table2))
        sdl_scancode = xfree86_scancode_table2[event_scancode];

    if (sdl_scancode != SDL_SCANCODE_UNKNOWN)
        SDL_SendKeyboardKey(key_state, sdl_scancode);

    if (key_state == SDL_PRESSED)
        HandleKeyText(key_code);
}

static void
HandleMouseButton(SDL_Window* sdl_window, Uint8 state, MirPointerEvent const* pointer)







|







74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
    if (action == mir_keyboard_action_up)
        key_state = SDL_RELEASED;

    if (event_scancode < SDL_arraysize(xfree86_scancode_table2))
        sdl_scancode = xfree86_scancode_table2[event_scancode];

    if (sdl_scancode != SDL_SCANCODE_UNKNOWN)
        SDL_SendKeyboardKey(key_state, sdl_scancode, 0, 0);

    if (key_state == SDL_PRESSED)
        HandleKeyText(key_code);
}

static void
HandleMouseButton(SDL_Window* sdl_window, Uint8 state, MirPointerEvent const* pointer)
Changes to jni/SDL2/src/video/nacl/SDL_naclevents.c.
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
                    case PP_INPUTEVENT_TYPE_TOUCHMOVE:
                    case PP_INPUTEVENT_TYPE_TOUCHEND:
                    case PP_INPUTEVENT_TYPE_TOUCHCANCEL:
                        /* FIXME: Touch events */
                        break;
                      
                    case PP_INPUTEVENT_TYPE_KEYDOWN:
                        SDL_SendKeyboardKey(SDL_PRESSED, SDL_NACL_translate_keycode(driverdata->ppb_keyboard_input_event->GetKeyCode(event)));
                        break;
                        
                    case PP_INPUTEVENT_TYPE_KEYUP:
                        SDL_SendKeyboardKey(SDL_RELEASED, SDL_NACL_translate_keycode(driverdata->ppb_keyboard_input_event->GetKeyCode(event)));
                        break;
                        
                    case PP_INPUTEVENT_TYPE_CHAR:
                        var = driverdata->ppb_keyboard_input_event->GetCharacterText(event);
                        str = driverdata->ppb_var->VarToUtf8(var, &str_len);
                        /* str is not null terminated! */
                        if ( str_len >= SDL_arraysize(text) ) {







|



|







377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
                    case PP_INPUTEVENT_TYPE_TOUCHMOVE:
                    case PP_INPUTEVENT_TYPE_TOUCHEND:
                    case PP_INPUTEVENT_TYPE_TOUCHCANCEL:
                        /* FIXME: Touch events */
                        break;
                      
                    case PP_INPUTEVENT_TYPE_KEYDOWN:
                        SDL_SendKeyboardKey(SDL_PRESSED, SDL_NACL_translate_keycode(driverdata->ppb_keyboard_input_event->GetKeyCode(event)), 0, 0);
                        break;
                        
                    case PP_INPUTEVENT_TYPE_KEYUP:
                        SDL_SendKeyboardKey(SDL_RELEASED, SDL_NACL_translate_keycode(driverdata->ppb_keyboard_input_event->GetKeyCode(event)), 0, 0);
                        break;
                        
                    case PP_INPUTEVENT_TYPE_CHAR:
                        var = driverdata->ppb_keyboard_input_event->GetCharacterText(event);
                        str = driverdata->ppb_var->VarToUtf8(var, &str_len);
                        /* str is not null terminated! */
                        if ( str_len >= SDL_arraysize(text) ) {
Changes to jni/SDL2/src/video/psp/SDL_pspevents.c.
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110

                /* out of date
                SDL_PrivateKeyboard((keys & keymap_psp[i].id) ?
                            SDL_PRESSED : SDL_RELEASED,
                            &sym);
        */
                SDL_SendKeyboardKey((keys & keymap_psp[i].id) ?
                                    SDL_PRESSED : SDL_RELEASED, SDL_GetScancodeFromKey(keymap_psp[i].sym));
            }
        }
    }

#ifdef PSPIRKEYB
    if (irkbd_ready) {
            unsigned char buffer[255];







|







96
97
98
99
100
101
102
103
104
105
106
107
108
109
110

                /* out of date
                SDL_PrivateKeyboard((keys & keymap_psp[i].id) ?
                            SDL_PRESSED : SDL_RELEASED,
                            &sym);
        */
                SDL_SendKeyboardKey((keys & keymap_psp[i].id) ?
                                    SDL_PRESSED : SDL_RELEASED, SDL_GetScancodeFromKey(keymap_psp[i].sym), 0, 0);
            }
        }
    }

#ifdef PSPIRKEYB
    if (irkbd_ready) {
            unsigned char buffer[255];
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
                        raw = scanData->raw;
                        pressed = scanData->pressed;
                sym.scancode = raw;
                sym.sym = keymap[raw];
                /* not tested */
                /* SDL_PrivateKeyboard(pressed?SDL_PRESSED:SDL_RELEASED, &sym); */
                SDL_SendKeyboardKey((keys & keymap_psp[i].id) ?
                                    SDL_PRESSED : SDL_RELEASED, SDL_GetScancodeFromKey(keymap[raw]));

                }
            }
        }
    }
#endif
    sceKernelDelayThread(0);







|







120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
                        raw = scanData->raw;
                        pressed = scanData->pressed;
                sym.scancode = raw;
                sym.sym = keymap[raw];
                /* not tested */
                /* SDL_PrivateKeyboard(pressed?SDL_PRESSED:SDL_RELEASED, &sym); */
                SDL_SendKeyboardKey((keys & keymap_psp[i].id) ?
                                    SDL_PRESSED : SDL_RELEASED, SDL_GetScancodeFromKey(keymap[raw]), 0, 0);

                }
            }
        }
    }
#endif
    sceKernelDelayThread(0);
Changes to jni/SDL2/src/video/wayland/SDL_waylandevents.c.
64
65
66
67
68
69
70





71
72
73
74
75
76
77
    double dx_frac;
    double dy_frac;

    struct {
        struct xkb_keymap *keymap;
        struct xkb_state *state;
    } xkb;





};

void
Wayland_PumpEvents(_THIS)
{
    SDL_VideoData *d = _this->driverdata;
    struct pollfd pfd[1];







>
>
>
>
>







64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
    double dx_frac;
    double dy_frac;

    struct {
        struct xkb_keymap *keymap;
        struct xkb_state *state;
    } xkb;

#ifdef WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION
    Uint16 key_rate;
    Uint16 key_delay;
#endif
};

void
Wayland_PumpEvents(_THIS)
{
    SDL_VideoData *d = _this->driverdata;
    struct pollfd pfd[1];
354
355
356
357
358
359
360
361
362








363
364

365
366
367
368
369
370
371
    uint32_t scancode;
    char text[8];
    int size;

    if (key < SDL_arraysize(xfree86_scancode_table2)) {
        scancode = xfree86_scancode_table2[key];

        // TODO when do we get WL_KEYBOARD_KEY_STATE_REPEAT?
        if (scancode != SDL_SCANCODE_UNKNOWN)








            SDL_SendKeyboardKey(state == WL_KEYBOARD_KEY_STATE_PRESSED ?
                                SDL_PRESSED : SDL_RELEASED, scancode);

    }

    if (!window || window->keyboard_device != input || !input->xkb.state)
        return;

    // TODO can this happen?
    if (WAYLAND_xkb_state_key_get_syms(input->xkb.state, key + 8, &syms) != 1)







<
|
>
>
>
>
>
>
>
>

|
>







359
360
361
362
363
364
365

366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
    uint32_t scancode;
    char text[8];
    int size;

    if (key < SDL_arraysize(xfree86_scancode_table2)) {
        scancode = xfree86_scancode_table2[key];


        if (scancode != SDL_SCANCODE_UNKNOWN) {
            Uint16 rate = 0, delay = 0;

#ifdef WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION
            if (WAYLAND_xkb_keymap_key_repeats(input->xkb.keymap, key + 8)) {
                rate = input->key_rate;
                delay = input->key_delay;
            }
#endif
            SDL_SendKeyboardKey(state == WL_KEYBOARD_KEY_STATE_PRESSED ?
                                SDL_PRESSED : SDL_RELEASED, scancode, rate, delay);
        }
    }

    if (!window || window->keyboard_device != input || !input->xkb.state)
        return;

    // TODO can this happen?
    if (WAYLAND_xkb_state_key_get_syms(input->xkb.state, key + 8, &syms) != 1)
391
392
393
394
395
396
397




















398
399
400
401
402
403
404



405
406
407
408
409
410
411
                          uint32_t group)
{
    struct SDL_WaylandInput *input = data;

    WAYLAND_xkb_state_update_mask(input->xkb.state, mods_depressed, mods_latched,
                          mods_locked, 0, 0, group);
}





















static const struct wl_keyboard_listener keyboard_listener = {
    keyboard_handle_keymap,
    keyboard_handle_enter,
    keyboard_handle_leave,
    keyboard_handle_key,
    keyboard_handle_modifiers,



};

static void
seat_handle_capabilities(void *data, struct wl_seat *seat,
                         enum wl_seat_capability caps)
{
    struct SDL_WaylandInput *input = data;







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







>
>
>







404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
                          uint32_t group)
{
    struct SDL_WaylandInput *input = data;

    WAYLAND_xkb_state_update_mask(input->xkb.state, mods_depressed, mods_latched,
                          mods_locked, 0, 0, group);
}

#ifdef WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION
static void
keyboard_handle_repeat_info(void *data, struct wl_keyboard *keyboard,
                            int32_t rate, int32_t delay)
{
    struct SDL_WaylandInput *input = data;

    if (rate > 0 && rate <= 0xffff) {
        input->key_rate = rate;
    } else {
        input->key_rate = 0;
    }
    if (delay > 0 && delay <= 0xffff) {
        input->key_delay = delay;
    } else {
        input->key_delay = 0;
    }
}
#endif

static const struct wl_keyboard_listener keyboard_listener = {
    keyboard_handle_keymap,
    keyboard_handle_enter,
    keyboard_handle_leave,
    keyboard_handle_key,
    keyboard_handle_modifiers,
#ifdef WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION
    keyboard_handle_repeat_info,
#endif
};

static void
seat_handle_capabilities(void *data, struct wl_seat *seat,
                         enum wl_seat_capability caps)
{
    struct SDL_WaylandInput *input = data;
680
681
682
683
684
685
686



687
688
689
690
691
692
693
    if (input == NULL)
        return;

    input->display = d;
    input->seat = wl_registry_bind(d->registry, id, &wl_seat_interface, 1);
    input->sx_w = wl_fixed_from_int(0);
    input->sy_w = wl_fixed_from_int(0);



    d->input = input;
    
    if (d->data_device_manager != NULL) {
        data_device = SDL_calloc(1, sizeof *data_device);
        if (data_device == NULL) {
            return;
        }







>
>
>







716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
    if (input == NULL)
        return;

    input->display = d;
    input->seat = wl_registry_bind(d->registry, id, &wl_seat_interface, 1);
    input->sx_w = wl_fixed_from_int(0);
    input->sy_w = wl_fixed_from_int(0);
    /* preset to 25 chars/second, 660 ms repeat delay */
    input->key_rate = 25;
    input->key_delay = 660;
    d->input = input;
    
    if (d->data_device_manager != NULL) {
        data_device = SDL_calloc(1, sizeof *data_device);
        if (data_device == NULL) {
            return;
        }
Changes to jni/SDL2/src/video/wayland/SDL_waylandsym.h.
99
100
101
102
103
104
105

106
107
108
109
110
111
112
SDL_WAYLAND_SYM(void, wl_cursor_theme_destroy, (struct wl_cursor_theme *))
SDL_WAYLAND_SYM(struct wl_cursor *, wl_cursor_theme_get_cursor, (struct wl_cursor_theme *, const char *))
SDL_WAYLAND_SYM(struct wl_buffer *, wl_cursor_image_get_buffer, (struct wl_cursor_image *))
SDL_WAYLAND_SYM(int, wl_cursor_frame, (struct wl_cursor *, uint32_t))

SDL_WAYLAND_MODULE(WAYLAND_XKB)
SDL_WAYLAND_SYM(int, xkb_state_key_get_syms, (struct xkb_state *, xkb_keycode_t, const xkb_keysym_t **))

SDL_WAYLAND_SYM(int, xkb_keysym_to_utf8, (xkb_keysym_t, char *, size_t) )
SDL_WAYLAND_SYM(struct xkb_keymap *, xkb_keymap_new_from_string, (struct xkb_context *, const char *, enum xkb_keymap_format, enum xkb_keymap_compile_flags))
SDL_WAYLAND_SYM(struct xkb_state *, xkb_state_new, (struct xkb_keymap *) )
SDL_WAYLAND_SYM(void, xkb_keymap_unref, (struct xkb_keymap *) )
SDL_WAYLAND_SYM(void, xkb_state_unref, (struct xkb_state *) )
SDL_WAYLAND_SYM(void, xkb_context_unref, (struct xkb_context *) )
SDL_WAYLAND_SYM(struct xkb_context *, xkb_context_new, (enum xkb_context_flags flags) )







>







99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
SDL_WAYLAND_SYM(void, wl_cursor_theme_destroy, (struct wl_cursor_theme *))
SDL_WAYLAND_SYM(struct wl_cursor *, wl_cursor_theme_get_cursor, (struct wl_cursor_theme *, const char *))
SDL_WAYLAND_SYM(struct wl_buffer *, wl_cursor_image_get_buffer, (struct wl_cursor_image *))
SDL_WAYLAND_SYM(int, wl_cursor_frame, (struct wl_cursor *, uint32_t))

SDL_WAYLAND_MODULE(WAYLAND_XKB)
SDL_WAYLAND_SYM(int, xkb_state_key_get_syms, (struct xkb_state *, xkb_keycode_t, const xkb_keysym_t **))
SDL_WAYLAND_SYM(int, xkb_keymap_key_repeats, (struct xkb_keymap *, xkb_keycode_t))
SDL_WAYLAND_SYM(int, xkb_keysym_to_utf8, (xkb_keysym_t, char *, size_t) )
SDL_WAYLAND_SYM(struct xkb_keymap *, xkb_keymap_new_from_string, (struct xkb_context *, const char *, enum xkb_keymap_format, enum xkb_keymap_compile_flags))
SDL_WAYLAND_SYM(struct xkb_state *, xkb_state_new, (struct xkb_keymap *) )
SDL_WAYLAND_SYM(void, xkb_keymap_unref, (struct xkb_keymap *) )
SDL_WAYLAND_SYM(void, xkb_state_unref, (struct xkb_state *) )
SDL_WAYLAND_SYM(void, xkb_context_unref, (struct xkb_context *) )
SDL_WAYLAND_SYM(struct xkb_context *, xkb_context_new, (enum xkb_context_flags flags) )
Changes to jni/SDL2/src/video/windows/SDL_windowsevents.c.
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
                /* ALT+F4: Close window */
                if (code == SDL_SCANCODE_F4 && ShouldGenerateWindowCloseOnAltF4()) {
                    SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
                }
            }

            if (code != SDL_SCANCODE_UNKNOWN) {
                SDL_SendKeyboardKey(SDL_PRESSED, code);
            }
        }
 
        returnCode = 0;
        break;

    case WM_SYSKEYUP:
    case WM_KEYUP:
        {
            SDL_Scancode code = WindowsScanCodeToSDLScanCode(lParam, wParam);
            const Uint8 *keyboardState = SDL_GetKeyboardState(NULL);

            if (code != SDL_SCANCODE_UNKNOWN) {
                if (code == SDL_SCANCODE_PRINTSCREEN &&
                    keyboardState[code] == SDL_RELEASED) {
                    SDL_SendKeyboardKey(SDL_PRESSED, code);
                }
                SDL_SendKeyboardKey(SDL_RELEASED, code);
            }
        }
        returnCode = 0;
        break;

    case WM_UNICHAR:
        if ( wParam == UNICODE_NOCHAR ) {







|















|

|







605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
                /* ALT+F4: Close window */
                if (code == SDL_SCANCODE_F4 && ShouldGenerateWindowCloseOnAltF4()) {
                    SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
                }
            }

            if (code != SDL_SCANCODE_UNKNOWN) {
                SDL_SendKeyboardKey(SDL_PRESSED, code, 0, 0);
            }
        }
 
        returnCode = 0;
        break;

    case WM_SYSKEYUP:
    case WM_KEYUP:
        {
            SDL_Scancode code = WindowsScanCodeToSDLScanCode(lParam, wParam);
            const Uint8 *keyboardState = SDL_GetKeyboardState(NULL);

            if (code != SDL_SCANCODE_UNKNOWN) {
                if (code == SDL_SCANCODE_PRINTSCREEN &&
                    keyboardState[code] == SDL_RELEASED) {
                    SDL_SendKeyboardKey(SDL_PRESSED, code, 0, 0);
                }
                SDL_SendKeyboardKey(SDL_RELEASED, code, 0, 0);
            }
        }
        returnCode = 0;
        break;

    case WM_UNICHAR:
        if ( wParam == UNICODE_NOCHAR ) {
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042

    /* Windows loses a shift KEYUP event when you have both pressed at once and let go of one.
       You won't get a KEYUP until both are released, and that keyup will only be for the second
       key you released. Take heroic measures and check the keystate as of the last handled event,
       and if we think a key is pressed when Windows doesn't, unstick it in SDL's state. */
    keystate = SDL_GetKeyboardState(NULL);
    if ((keystate[SDL_SCANCODE_LSHIFT] == SDL_PRESSED) && !(GetKeyState(VK_LSHIFT) & 0x8000)) {
        SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LSHIFT);
    }
    if ((keystate[SDL_SCANCODE_RSHIFT] == SDL_PRESSED) && !(GetKeyState(VK_RSHIFT) & 0x8000)) {
        SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RSHIFT);
    }
}

static int app_registered = 0;
LPTSTR SDL_Appname = NULL;
Uint32 SDL_Appstyle = 0;
HINSTANCE SDL_Instance = NULL;







|


|







1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042

    /* Windows loses a shift KEYUP event when you have both pressed at once and let go of one.
       You won't get a KEYUP until both are released, and that keyup will only be for the second
       key you released. Take heroic measures and check the keystate as of the last handled event,
       and if we think a key is pressed when Windows doesn't, unstick it in SDL's state. */
    keystate = SDL_GetKeyboardState(NULL);
    if ((keystate[SDL_SCANCODE_LSHIFT] == SDL_PRESSED) && !(GetKeyState(VK_LSHIFT) & 0x8000)) {
        SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LSHIFT, 0, 0);
    }
    if ((keystate[SDL_SCANCODE_RSHIFT] == SDL_PRESSED) && !(GetKeyState(VK_RSHIFT) & 0x8000)) {
        SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RSHIFT, 0, 0);
    }
}

static int app_registered = 0;
LPTSTR SDL_Appname = NULL;
Uint32 SDL_Appstyle = 0;
HINSTANCE SDL_Instance = NULL;
Changes to jni/SDL2/src/video/winrt/SDL_winrtkeyboard.cpp.
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
        args->VirtualKey,
        sdlScancode,
        SDL_GetScancodeName(sdlScancode),
        keycode,
        SDL_GetKeyName(keycode));
    //args->Handled = true;
#endif
    SDL_SendKeyboardKey(SDL_PRESSED, sdlScancode);
}

void
WINRT_ProcessKeyUpEvent(Windows::UI::Core::KeyEventArgs ^args)
{
    SDL_Scancode sdlScancode = WINRT_TranslateKeycode((int)args->VirtualKey, args->KeyStatus.ScanCode);
#if 0







|







332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
        args->VirtualKey,
        sdlScancode,
        SDL_GetScancodeName(sdlScancode),
        keycode,
        SDL_GetKeyName(keycode));
    //args->Handled = true;
#endif
    SDL_SendKeyboardKey(SDL_PRESSED, sdlScancode, 0, 0);
}

void
WINRT_ProcessKeyUpEvent(Windows::UI::Core::KeyEventArgs ^args)
{
    SDL_Scancode sdlScancode = WINRT_TranslateKeycode((int)args->VirtualKey, args->KeyStatus.ScanCode);
#if 0
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
        args->VirtualKey,
        sdlScancode,
        SDL_GetScancodeName(sdlScancode),
        keycode,
        SDL_GetKeyName(keycode));
    //args->Handled = true;
#endif
    SDL_SendKeyboardKey(SDL_RELEASED, sdlScancode);
}

void
WINRT_ProcessCharacterReceivedEvent(Windows::UI::Core::CharacterReceivedEventArgs ^args)
{
    wchar_t src_ucs2[2];
    char dest_utf8[16];







|







358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
        args->VirtualKey,
        sdlScancode,
        SDL_GetScancodeName(sdlScancode),
        keycode,
        SDL_GetKeyName(keycode));
    //args->Handled = true;
#endif
    SDL_SendKeyboardKey(SDL_RELEASED, sdlScancode, 0, 0);
}

void
WINRT_ProcessCharacterReceivedEvent(Windows::UI::Core::CharacterReceivedEventArgs ^args)
{
    wchar_t src_ucs2[2];
    char dest_utf8[16];
Changes to jni/SDL2/src/video/x11/SDL_x11events.c.
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
    if (X11_XQueryPointer(display, DefaultRootWindow(display), &junk_window, &junk_window, &x, &y, &x, &y, &mask)) {
        SDL_ToggleModState(KMOD_CAPS, (mask & LockMask) != 0);
        SDL_ToggleModState(KMOD_NUM, (mask & X11_GetNumLockModifierMask(_this)) != 0);
    }

    for (keycode = 0; keycode < 256; ++keycode) {
        if (keys[keycode / 8] & (1 << (keycode % 8))) {
            SDL_SendKeyboardKey(SDL_PRESSED, viddata->key_layout[keycode]);
        } else {
            SDL_SendKeyboardKey(SDL_RELEASED, viddata->key_layout[keycode]);
        }
    }
}


static void
X11_DispatchFocusIn(_THIS, SDL_WindowData *data)







|

|







355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
    if (X11_XQueryPointer(display, DefaultRootWindow(display), &junk_window, &junk_window, &x, &y, &x, &y, &mask)) {
        SDL_ToggleModState(KMOD_CAPS, (mask & LockMask) != 0);
        SDL_ToggleModState(KMOD_NUM, (mask & X11_GetNumLockModifierMask(_this)) != 0);
    }

    for (keycode = 0; keycode < 256; ++keycode) {
        if (keys[keycode / 8] & (1 << (keycode % 8))) {
            SDL_SendKeyboardKey(SDL_PRESSED, viddata->key_layout[keycode], 0, 0);
        } else {
            SDL_SendKeyboardKey(SDL_RELEASED, viddata->key_layout[keycode], 0, 0);
        }
    }
}


static void
X11_DispatchFocusIn(_THIS, SDL_WindowData *data)
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
        if (orig_keycode) {
#if defined(HAVE_IBUS_IBUS_H) || defined(HAVE_FCITX_FRONTEND_H)
            SDL_Scancode scancode = videodata->key_layout[orig_keycode];
            videodata->filter_code = orig_keycode;
            videodata->filter_time = xevent.xkey.time;

            if (orig_event_type == KeyPress) {
                SDL_SendKeyboardKey(SDL_PRESSED, scancode);
            } else {
                SDL_SendKeyboardKey(SDL_RELEASED, scancode);
            }
#endif
        }
        return;
    }

    /* Send a SDL_SYSWMEVENT if the application wants them */







|

|







574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
        if (orig_keycode) {
#if defined(HAVE_IBUS_IBUS_H) || defined(HAVE_FCITX_FRONTEND_H)
            SDL_Scancode scancode = videodata->key_layout[orig_keycode];
            videodata->filter_code = orig_keycode;
            videodata->filter_time = xevent.xkey.time;

            if (orig_event_type == KeyPress) {
                SDL_SendKeyboardKey(SDL_PRESSED, scancode, 0, 0);
            } else {
                SDL_SendKeyboardKey(SDL_RELEASED, scancode, 0, 0);
            }
#endif
        }
        return;
    }

    /* Send a SDL_SYSWMEVENT if the application wants them */
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
            if(SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE){
                handled_by_ime = SDL_IME_ProcessKeyEvent(keysym, keycode);
            }
#endif
            if (!handled_by_ime) {
                /* Don't send the key if it looks like a duplicate of a filtered key sent by an IME */
                if (xevent.xkey.keycode != videodata->filter_code || xevent.xkey.time != videodata->filter_time) {
                    SDL_SendKeyboardKey(SDL_PRESSED, videodata->key_layout[keycode]);
                }
                if(*text) {
                    SDL_SendKeyboardText(text);
                }
            }

            X11_UpdateUserTime(data, xevent.xkey.time);







|







801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
            if(SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE){
                handled_by_ime = SDL_IME_ProcessKeyEvent(keysym, keycode);
            }
#endif
            if (!handled_by_ime) {
                /* Don't send the key if it looks like a duplicate of a filtered key sent by an IME */
                if (xevent.xkey.keycode != videodata->filter_code || xevent.xkey.time != videodata->filter_time) {
                    SDL_SendKeyboardKey(SDL_PRESSED, videodata->key_layout[keycode], 0, 0);
                }
                if(*text) {
                    SDL_SendKeyboardText(text);
                }
            }

            X11_UpdateUserTime(data, xevent.xkey.time);
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
#ifdef DEBUG_XEVENTS
            printf("window %p: KeyRelease (X11 keycode = 0x%X)\n", data, xevent.xkey.keycode);
#endif
            if (X11_KeyRepeat(display, &xevent)) {
                /* We're about to get a repeated key down, ignore the key up */
                break;
            }
            SDL_SendKeyboardKey(SDL_RELEASED, videodata->key_layout[keycode]);
        }
        break;

        /* Have we been iconified? */
    case UnmapNotify:{
#ifdef DEBUG_XEVENTS
            printf("window %p: UnmapNotify!\n", data);







|







823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
#ifdef DEBUG_XEVENTS
            printf("window %p: KeyRelease (X11 keycode = 0x%X)\n", data, xevent.xkey.keycode);
#endif
            if (X11_KeyRepeat(display, &xevent)) {
                /* We're about to get a repeated key down, ignore the key up */
                break;
            }
            SDL_SendKeyboardKey(SDL_RELEASED, videodata->key_layout[keycode], 0, 0);
        }
        break;

        /* Have we been iconified? */
    case UnmapNotify:{
#ifdef DEBUG_XEVENTS
            printf("window %p: UnmapNotify!\n", data);
Changes to jni/sdl2tk/sdl/SdlTkX.c.
5013
5014
5015
5016
5017
5018
5019













5020
5021
5022
5023
5024
5025
5026
    agg_custom_free = (void (*)(void *)) Tcl_Free;
#endif

    if (SdlTkX.arg_sdllog) {
	SDL_LogSetAllPriority(SdlTkX.arg_sdllog);
    }
#ifndef ANDROID













retryInit:
#endif
    if (SDL_Init(initMask) < 0) {
#ifdef ANDROID
	__android_log_print(ANDROID_LOG_ERROR, "libtk",
			    "Couldn't initialize SDL: %s", SDL_GetError());
#else







>
>
>
>
>
>
>
>
>
>
>
>
>







5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
    agg_custom_free = (void (*)(void *)) Tcl_Free;
#endif

    if (SdlTkX.arg_sdllog) {
	SDL_LogSetAllPriority(SdlTkX.arg_sdllog);
    }
#ifndef ANDROID
#ifdef linux
    /*
     * Wayland: if SDL_VIDEODRIVER is unset but WAYLAND_DISPLAY
     * is set, prefer the Wayland video driver.
     */
    if (getenv("SDL_VIDEODRIVER") == NULL) {
	char *p = getenv("WAYLAND_DISPLAY");

	if ((p != NULL) && p[0]) {
	    putenv("SDL_VIDEODRIVER=wayland");
	}
    }
#endif
retryInit:
#endif
    if (SDL_Init(initMask) < 0) {
#ifdef ANDROID
	__android_log_print(ANDROID_LOG_ERROR, "libtk",
			    "Couldn't initialize SDL: %s", SDL_GetError());
#else
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
    SDL_SetWindowMinimumSize(SdlTkX.sdlscreen, min_w, min_h);
#endif
    SDL_GetWindowSize(SdlTkX.sdlscreen, &width, &height);

    fmt = SDL_GetWindowPixelFormat(SdlTkX.sdlscreen);
    if (fmt == SDL_PIXELFORMAT_UNKNOWN) {
	/*
	 * This can happen with the wayland video driver,
	 * thus try to go on with 24 bit RGB.
	 */
	fmt = SDL_PIXELFORMAT_RGB888;
    }
    pfmt = SDL_AllocFormat(fmt);

    SdlTkX.sdlsurf = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height,







|







5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
    SDL_SetWindowMinimumSize(SdlTkX.sdlscreen, min_w, min_h);
#endif
    SDL_GetWindowSize(SdlTkX.sdlscreen, &width, &height);

    fmt = SDL_GetWindowPixelFormat(SdlTkX.sdlscreen);
    if (fmt == SDL_PIXELFORMAT_UNKNOWN) {
	/*
	 * This can happen with the Wayland video driver,
	 * thus try to go on with 24 bit RGB.
	 */
	fmt = SDL_PIXELFORMAT_RGB888;
    }
    pfmt = SDL_AllocFormat(fmt);

    SdlTkX.sdlsurf = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height,
5741
5742
5743
5744
5745
5746
5747








5748
5749
5750
5751
5752
5753
5754
static Tcl_ThreadCreateType
EventThread(ClientData clientData)
{
    SDL_Event sdl_event;
    XEvent event;
    SDL_TimerID timerId;
    int skipRefresh = 0, overrun, initSuccess;








    struct EventThreadStartup *evs = (struct EventThreadStartup *) clientData;

    EVLOG("EventThread start");
#ifdef ANDROID
    Android_JNI_SetupThread();
#endif
    SdlTkLock(NULL);







>
>
>
>
>
>
>
>







5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
static Tcl_ThreadCreateType
EventThread(ClientData clientData)
{
    SDL_Event sdl_event;
    XEvent event;
    SDL_TimerID timerId;
    int skipRefresh = 0, overrun, initSuccess;
#ifndef ANDROID
    /* Key repeat handling for Wayland. */
    SDL_Event key_event, txt_event;
    int key_rpt_state = 0, key_rpt_time;
    extern int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode,
				   Uint16 rate, Uint16 delay);
    extern int SDL_SendKeyboardText(const char *text);
#endif
    struct EventThreadStartup *evs = (struct EventThreadStartup *) clientData;

    EVLOG("EventThread start");
#ifdef ANDROID
    Android_JNI_SetupThread();
#endif
    SdlTkLock(NULL);
5771
5772
5773
5774
5775
5776
5777

5778


5779
5780
5781
5782
5783
5784
5785
    SDL_RenderCopy(SdlTkX.sdlrend, SdlTkX.sdltex, NULL, NULL);
#endif
    SdlTkUnlock(NULL);

    timerId = SDL_AddTimer(1000 / SDLTK_FRAMERATE, TimerCallback,
			   (void *) &SdlTkX.time_count);
    EVLOG("EventThread enter loop");

    /* Add all pending SDL events to the X event queues */


    while (1) {
	_XSQEvent *qevent;

	/* Enable timer messages. */
	timer_enabled = !SdlTkX.in_background;
	if (!SDL_WaitEvent(&sdl_event)) {
	    break;







>
|
>
>







5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
    SDL_RenderCopy(SdlTkX.sdlrend, SdlTkX.sdltex, NULL, NULL);
#endif
    SdlTkUnlock(NULL);

    timerId = SDL_AddTimer(1000 / SDLTK_FRAMERATE, TimerCallback,
			   (void *) &SdlTkX.time_count);
    EVLOG("EventThread enter loop");
    /*
     * Add all pending SDL events to the X event queues and
     * deal with screen refresh.
     */
    while (1) {
	_XSQEvent *qevent;

	/* Enable timer messages. */
	timer_enabled = !SdlTkX.in_background;
	if (!SDL_WaitEvent(&sdl_event)) {
	    break;
5797
5798
5799
5800
5801
5802
5803











5804























5805
5806
5807
5808
5809
5810
5811
	    if (!skipRefresh) {
		SdlTkScreenRefresh();
	    }
	    overrun = (SdlTkX.time_count - sdl_event.user.code) > 0;
	    skipRefresh = !skipRefresh && overrun;
	    /* Mark event to be skipped in SdlTkTranslateEvent() */
	    sdl_event.type = SDL_USEREVENT + 0x1000;











	}























	if ((sdl_event.type == SDL_USEREVENT) &&
	    (sdl_event.user.data1 == HandlePanZoom) &&
	    (sdl_event.user.data2 != NULL)) {
	    HandlePanZoom((struct PanZoomRequest *) sdl_event.user.data2);
	    /* Mark event to be skipped in SdlTkTranslateEvent() */
	    sdl_event.type = SDL_USEREVENT + 0x1001;
	}







>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
	    if (!skipRefresh) {
		SdlTkScreenRefresh();
	    }
	    overrun = (SdlTkX.time_count - sdl_event.user.code) > 0;
	    skipRefresh = !skipRefresh && overrun;
	    /* Mark event to be skipped in SdlTkTranslateEvent() */
	    sdl_event.type = SDL_USEREVENT + 0x1000;
#ifndef ANDROID
	    /* Key repeat handling for Wayland. */
	    if (key_rpt_state && (SdlTkX.time_count - key_rpt_time >= 0)) {
		if (key_event.key.rate) {
		    key_rpt_time = SdlTkX.time_count + 1000/key_event.key.rate;
		    if (key_rpt_state > 1) {
			SDL_SendKeyboardText(txt_event.text.text);
		    } else {
			SDL_SendKeyboardKey(SDL_PRESSED,
					    key_event.key.keysym.scancode,
					    key_event.key.rate, 0);
		    }
		} else {
		    key_rpt_state = 0;
		}
	    }
#endif
	}
#ifndef ANDROID
	/* Key repeat handling for Wayland. */
	if ((sdl_event.type == SDL_KEYDOWN) && sdl_event.key.rate &&
	    sdl_event.key.delay && !sdl_event.key.repeat) {
	    key_rpt_state = 1;
	    key_event = sdl_event;
	    key_rpt_time = SdlTkX.time_count + key_event.key.delay;
	    if (SDL_PeepEvents(&txt_event, 1, SDL_PEEKEVENT,
			       SDL_TEXTINPUT, SDL_TEXTINPUT) == 1) {
		key_rpt_state = 2;
	    }
	} else if (key_rpt_state && (sdl_event.type == SDL_KEYUP) &&
		   sdl_event.key.rate && sdl_event.key.delay &&
		   !sdl_event.key.repeat) {
	    key_rpt_state = 0;
	}
#endif
	if ((sdl_event.type == SDL_USEREVENT) &&
	    (sdl_event.user.data1 == HandlePanZoom) &&
	    (sdl_event.user.data2 != NULL)) {
	    HandlePanZoom((struct PanZoomRequest *) sdl_event.user.data2);
	    /* Mark event to be skipped in SdlTkTranslateEvent() */
	    sdl_event.type = SDL_USEREVENT + 0x1001;
	}
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
		Tcl_ConditionWait(&time_cond, &xlib_lock, NULL);
	    } while (wait_refr && (SdlTkX.frame_count == frame_count));
#else
	    Uint32 fmt = SDL_GetWindowPixelFormat(_w->gl_wind);

	    if (fmt == SDL_PIXELFORMAT_UNKNOWN) {
		/*
		 * This can happen with the wayland video driver,
		 * thus try to go on with 24 bit RGB.
		 */
		fmt = SDL_PIXELFORMAT_RGB888;
	    }
	    if (SDL_RenderReadPixels(rend, NULL, fmt, surf->pixels,
				     surf->pitch) == 0) {
		_Pixmap p;







|







7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
		Tcl_ConditionWait(&time_cond, &xlib_lock, NULL);
	    } while (wait_refr && (SdlTkX.frame_count == frame_count));
#else
	    Uint32 fmt = SDL_GetWindowPixelFormat(_w->gl_wind);

	    if (fmt == SDL_PIXELFORMAT_UNKNOWN) {
		/*
		 * This can happen with the Wayland video driver,
		 * thus try to go on with 24 bit RGB.
		 */
		fmt = SDL_PIXELFORMAT_RGB888;
	    }
	    if (SDL_RenderReadPixels(rend, NULL, fmt, surf->pixels,
				     surf->pitch) == 0) {
		_Pixmap p;
Changes to undroid/README.txt.
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
build-vanilla-generic.sh	vanilla{tclsh,wish} for generic linux (e.g. arm)

The undroidwish variant uses the SDL2 backend, the vanilla variant
the native one (i.e. X11 on Linux, Win32/GDI on Windows).

The experimental Wayland variant gets built with both an X11 and a Wayland
video driver. The former driver is the default. In order to run with the
Wayland driver, the environment must have this setting:

  SDL_VIDEODRIVER=wayland

The build is currently verified only on Fedora 25. The undroidwish root
window starts without decorations and can be moved and/or resized
(-sdlresizable required) with window manager hot keys (Alt-F7, Alt-F8).
The 3D canvas widget cannot be loaded currently, since normal OpenGL
support is not available in combination with the Wayland video driver.

Refer to the individual script for build requirements. The
general pattern for invocation is

  <full-name-of-script-within-AndroWish-source-tree> ?<action>?

where <action> (default is "build") carries out the following:







|
<
|
<



<
<







23
24
25
26
27
28
29
30

31

32
33
34


35
36
37
38
39
40
41
build-vanilla-generic.sh	vanilla{tclsh,wish} for generic linux (e.g. arm)

The undroidwish variant uses the SDL2 backend, the vanilla variant
the native one (i.e. X11 on Linux, Win32/GDI on Windows).

The experimental Wayland variant gets built with both an X11 and a Wayland
video driver. The former driver is the default. In order to run with the
Wayland driver, the environment must have the variable WAYLAND_DRIVER

to be defined or alternatively SDL_VIDEODRIVER set to "wayland".

The build is currently verified only on Fedora 25. The undroidwish root
window starts without decorations and can be moved and/or resized
(-sdlresizable required) with window manager hot keys (Alt-F7, Alt-F8).



Refer to the individual script for build requirements. The
general pattern for invocation is

  <full-name-of-script-within-AndroWish-source-tree> ?<action>?

where <action> (default is "build") carries out the following: