From 0a9842f34de7ba6ac05ee5952d1691f9c0ced504 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Mon, 30 Mar 2026 20:40:39 +0200 Subject: [PATCH] fix(gui): correct dispatching of mouse dragging events --- src/gui/wio/app.zig | 10 +++++----- src/gui/wio/input.zig | 8 ++++++++ src/renderer/gui/renderer.zig | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/gui/wio/app.zig b/src/gui/wio/app.zig index 9faa3f87..50de22fd 100644 --- a/src/gui/wio/app.zig +++ b/src/gui/wio/app.zig @@ -310,11 +310,11 @@ fn wioLoop() void { const row_cell: i32 = @intCast(@divTrunc(@as(i32, @intCast(pos.y)), wio_font.cell_size.y)); const xoff: i32 = @intCast(@mod(@as(i32, @intCast(pos.x)), wio_font.cell_size.x)); const yoff: i32 = @intCast(@mod(@as(i32, @intCast(pos.y)), wio_font.cell_size.y)); - tui_pid.send(.{ - "RDR", "M", - col_cell, row_cell, - xoff, yoff, - }) catch {}; + if (input_translate.heldMouseButtonId(held_buttons)) |mb_id| { + tui_pid.send(.{ "RDR", "D", mb_id, col_cell, row_cell, xoff, yoff }) catch {}; + } else { + tui_pid.send(.{ "RDR", "M", col_cell, row_cell, xoff, yoff }) catch {}; + } }, .scroll_vertical => |dy| { const btn_id: u8 = if (dy < 0) 64 else 65; // up / down scroll diff --git a/src/gui/wio/input.zig b/src/gui/wio/input.zig index fe3e0dd7..3d968b56 100644 --- a/src/gui/wio/input.zig +++ b/src/gui/wio/input.zig @@ -165,3 +165,11 @@ pub fn mouseButtonId(b: wio.Button) ?u8 { else => null, }; } + +pub fn heldMouseButtonId(held: ButtonSet) ?u8 { + const mouse_buttons = [_]wio.Button{ .mouse_left, .mouse_right, .mouse_middle, .mouse_back, .mouse_forward }; + for (mouse_buttons) |btn| { + if (held.has(btn)) return mouseButtonId(btn); + } + return null; +} diff --git a/src/renderer/gui/renderer.zig b/src/renderer/gui/renderer.zig index d0967898..fef116f7 100644 --- a/src/renderer/gui/renderer.zig +++ b/src/renderer/gui/renderer.zig @@ -245,6 +245,39 @@ pub fn process_renderer_event(self: *Self, msg: []const u8) Error!void { } } + { + var args: struct { + pos: MousePos, + button_id: u8, + } = undefined; + if (try cbor.match(msg, .{ + cbor.any, + "D", + cbor.extract(&args.button_id), + cbor.extract(&args.pos.col), + cbor.extract(&args.pos.row), + cbor.extract(&args.pos.xoffset), + cbor.extract(&args.pos.yoffset), + })) { + if (self.dispatch_mouse_drag) |f| f( + self.handler_ctx, + @intCast(args.pos.row), + @intCast(args.pos.col), + try self.fmtmsg(.{ + "D", + input.event.press, + args.button_id, + input.utils.button_id_string(@enumFromInt(args.button_id)), + args.pos.col, + args.pos.row, + args.pos.xoffset, + args.pos.yoffset, + }), + ); + return; + } + } + { var args: struct { pos: MousePos,