~mil/fbp

5f7f62b5ad4a15a191c4d94f026cd4449d20aa04 — Miles Alan 4 months ago a0ede3c
s/pending_touch/touch_pending/g
1 files changed, 12 insertions(+), 12 deletions(-)

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


@@ 152,11 152,11 @@ fn event_touch_handle(runtime: *@This(), evt_data: linput.input_event) !void {

    var run : enum { FingerUp, FingerDown, Invalid } = run: {
        if (evt_data.code == linput.ABS_MT_POSITION_X or evt_data.code == linput.ABS_MT_POSITION_Y) {
            if (runtime.pending_touch == null) runtime.pending_touch = .{ .x = 0, .y = 0 };
            if (evt_data.code == linput.ABS_MT_POSITION_X) runtime.pending_touch.?.x = evt_data.value;
            if (evt_data.code == linput.ABS_MT_POSITION_Y) runtime.pending_touch.?.y = evt_data.value;
            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;
        } else if (evt_data.code == linput.ABS_MT_TRACKING_ID and evt_data.value == -1 and runtime.pending_touch != null) {
        } 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;


@@ 164,7 164,7 @@ fn event_touch_handle(runtime: *@This(), evt_data: linput.input_event) !void {

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

        // Select item on grid
        try utilgrid.grid_calculate(runtime.grid(), runtime.dims_cols(), runtime.dims_rows(), 0, config.status_height, w, h, grid_calculate_callback_register_click, runtime);


@@ 173,7 173,7 @@ fn event_touch_handle(runtime: *@This(), evt_data: linput.input_event) !void {
        if (run == .FingerUp) {
            runtime.grid_select();
            if (runtime.grid_current_index()) |current_index| runtime.grid()[current_index].touched = false;
            runtime.pending_touch = null;
            runtime.touch_pending = null;
            runtime.redraw = true;
        }
    }


@@ 212,11 212,11 @@ fn event_key_handle(runtime: *@This(), evt_data: ?linput.input_event) !void {
fn grid_calculate_callback_register_click(x: u32, y: u32, w: u32, h: u32, _: types.GridItem, item_i: usize, runtime: anytype) !bool {
    const y_off = @floatToInt(u32, @intToFloat(f64, framebuffer.fb_vinfo.yres) * (1.0 - config.height_proportion));
    if (runtime.grid_current_index() != null and
        runtime.pending_touch != null and
        runtime.pending_touch.?.x > x and
        runtime.pending_touch.?.x < x + w and
        runtime.pending_touch.?.y > y_off + y and
        runtime.pending_touch.?.y < y_off + y + h)
        runtime.touch_pending != null and
        runtime.touch_pending.?.x > x and
        runtime.touch_pending.?.x < x + w and
        runtime.touch_pending.?.y > y_off + y and
        runtime.touch_pending.?.y < y_off + y + h)
    {
        if (item_i != runtime.grid_current_index().? or !runtime.grid()[runtime.grid_current_index().?].touched) {
            runtime.redraw = true;