fdf33bbc12b2430d4985de4e464710d10a8b47ee — Miles Alan 2 years ago 5d966c2 keydown-textinput-rework
Remove sucessive enabling/disabling of textinput system on keymap change

Keyinput / defaults now are sucessfully working on both Phosh, Sxmo, and

- Sxmo quirks: wtype produces keydown events with esc as the keycode
  thus we need to use the textinput system which holds the actual
  right text
- Phosh quirks: OSK doesn't actually close after shellpipe, so shellpipe
  manually calls textipnut stop (which hides the OSK.. but we just don't
  use textinput subsystem at all on OSK supported enviroments). This
  is kind of confusing somewhat of a hack.. for now; but it should
  be more or less clear what's happening in that
  sdl.SDL_HasScreenKeyboardSupport() is essentially just a check for Phosh
  to nop the textinput subsystem and also allows us to abritrarly close
  the OSK as an override.
1 files changed, 7 insertions(+), 9 deletions(-)

M src/Mepo.zig
M src/Mepo.zig => src/Mepo.zig +7 -9
@@ 580,7 580,6 @@ fn event_fingerup(mepo: *@This(), e: sdl.SDL_Event) types.Pending {

fn event_textinput(mepo: *@This(), e: sdl.SDL_Event) types.Pending {
    defer sdl.SDL_StopTextInput();
    var idx : usize = 0;
    var pending : types.Pending = .None;
    const text = e.text.text;

@@ 711,11 710,6 @@ fn event_mousewheel(mepo: *@This(), e: sdl.SDL_Event) types.Pending {
    return .Redraw;

fn event_keymapchanged(mepo: *@This(), e: sdl.SDL_Event) types.Pending {
    return .None;

fn event_keyup(mepo: *@This(), e: sdl.SDL_Event) types.Pending {
    if (
        sdl.SDL_bool.SDL_TRUE == sdl.SDL_IsTextInputActive() and

@@ 724,6 718,7 @@ fn event_keyup(mepo: *@This(), e: sdl.SDL_Event) types.Pending {

    const key = sdl.SDL_GetScancodeName(e.key.keysym.scancode);
    std.debug.warn("Key in keyup: {s} and sen {d}\n", .{key, std.mem.indexOfSentinel(u8, 0, key)});

    if (std.mem.indexOfSentinel(u8, 0, key) != 1) return .None;

    if (mepo.table_keybindings.get(.{

@@ 865,7 860,6 @@ pub fn sdl_event_loop(mepo: *@This()) !void {
                .SDL_FINGERDOWN => event_fingerdown,
                .SDL_FINGERUP => event_fingerup,
                .SDL_KEYUP => event_keyup,
                .SDL_KEYMAPCHANGED => event_keymapchanged,
                .SDL_MOUSEBUTTONDOWN => event_mousebuttondown,
                .SDL_MOUSEBUTTONUP => event_mousebuttonup,
                .SDL_MOUSEMOTION => event_mousemotion,

@@ 1170,6 1164,7 @@ pub fn init(allocator: *std.mem.Allocator, tile_cache: *TileCache, use_sw_render
    utildbg.log("Successfully initialized SDL with videodriver: {s}\n", .{sdl.SDL_GetCurrentVideoDriver()});

    // Initialize window
    const window = window: {
        const w = try utilsdl.errorcheck_ptr(sdl.SDL_Window, sdl.SDL_CreateWindow(

@@ 1184,8 1179,11 @@ pub fn init(allocator: *std.mem.Allocator, tile_cache: *TileCache, use_sw_render
        break :window w;

    // Disable textinput method - we use keyup in all instances
    // E.g. on non OSK enviroments (like desktop, Sxmo, etc.) we enable
    // the textinput system; textinput events are more reliable then
    // keyevents for wtype (used by Sxmo); meanwhile on OSK-like enviroments
    // like Phosh, we can just use keydown/up events directly
    defer if (sdl.SDL_bool.SDL_FALSE == sdl.SDL_HasScreenKeyboardSupport()) sdl.SDL_StartTextInput();

    // Initialize TTF, load fonts
    try utilsdl.errorcheck(sdl.TTF_Init());