~mil/fbp

6db125ae1480eb0d59d795d298b2f1835dcd5ffe — Miles Alan 2 months ago 5f7f62b
Disambiguate between finger down/drag/up for touch processing
2 files changed, 23 insertions(+), 7 deletions(-)

M src/Runtime.zig
M src/types.zig
M src/Runtime.zig => src/Runtime.zig +18 -7
@@ 38,7 38,8 @@ keyboard_selected_index: usize,
keyhandler: Keyhandler,
uinputkb: Uinputkb,
mode: types.Mode = .Normal,
touch_pending: ?struct { x: c_int = 0, y: c_int = 0 } = .{ .x = 0, .y = 0 },
touch_start: ?struct{ start_time: time.timeval, coordinates: types.TouchCoordinates } = null,
touch_pending: ?types.TouchCoordinates = null,
redraw: bool,
status: []const u8,
status_last_update: ?time.timeval,


@@ 150,19 151,29 @@ fn event_touch_handle(runtime: *@This(), evt_data: linput.input_event) !void {
    const h = @floatToInt(u32, @intToFloat(f64, framebuffer.fb_vinfo.yres) * config.height_proportion) - config.status_height;
    const w = framebuffer.fb_vinfo.xres;

    var run : enum { FingerUp, FingerDown, Invalid } = run: {
    var run : enum { FingerUp, FingerDown, FingerDrag, Invalid } = run: {
        if (evt_data.code == linput.ABS_MT_POSITION_X or evt_data.code == linput.ABS_MT_POSITION_Y) {
            if (runtime.touch_pending == null) runtime.touch_pending = .{ .x = 0, .y = 0 };
            if (evt_data.code == linput.ABS_MT_POSITION_X) runtime.touch_pending.?.x = evt_data.value;
            if (evt_data.code == linput.ABS_MT_POSITION_Y) runtime.touch_pending.?.y = evt_data.value;
            break :run .FingerDown;
            if (runtime.touch_pending == null) {
                runtime.touch_pending = .{ .x = 0, .y = 0 };
                if (evt_data.code == linput.ABS_MT_POSITION_X) runtime.touch_pending.?.x = evt_data.value;
                if (evt_data.code == linput.ABS_MT_POSITION_Y) runtime.touch_pending.?.y = evt_data.value;
                break :run .Invalid;
            } else if (evt_data.code == linput.ABS_MT_POSITION_X) {
                const is_drag = runtime.touch_pending.?.x != 0;
                runtime.touch_pending.?.x = evt_data.value;
                if (is_drag) break :run .FingerDrag else break :run .FingerDown;
            } else if (evt_data.code == linput.ABS_MT_POSITION_Y) {
                const is_drag = runtime.touch_pending.?.y != 0;
                runtime.touch_pending.?.y = evt_data.value;
                if (is_drag) break :run .FingerDrag else break :run .FingerDown;
            }
        } else if (evt_data.code == linput.ABS_MT_TRACKING_ID and evt_data.value == -1 and runtime.touch_pending != null) {
            break :run .FingerUp;
        }
        break :run .Invalid;
    };

    if (run == .FingerDown or run == .FingerUp) {
    if (run == .FingerDrag or run == .FingerDown or run == .FingerUp) {
        // Invalidate out of bound events
        if (runtime.touch_pending.?.y < framebuffer.fb_vinfo.yres - h or runtime.touch_pending.?.y > framebuffer.fb_vinfo.yres) return;


M src/types.zig => src/types.zig +5 -0
@@ 14,6 14,11 @@ pub const Pixel = packed struct {

pub const Key = enum(u2) { Up, Down, Select };

pub const TouchCoordinates = struct {
    x: c_int = 0,
    y: c_int = 0,
};

pub const Keybinding = packed struct {
    key: Key,
    // TODO: below should be in packed union, but currently zig fails with