diff --git a/src/renderer/win32/renderer.zig b/src/renderer/win32/renderer.zig index 42bf501..719eebf 100644 --- a/src/renderer/win32/renderer.zig +++ b/src/renderer/win32/renderer.zig @@ -274,6 +274,39 @@ pub fn process_renderer_event(self: *Self, msg: []const u8) !void { return; } } + { + 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), + })) { + var buf: [200]u8 = undefined; + if (self.dispatch_mouse_drag) |f| f( + self.handler_ctx, + @intCast(args.pos.row), + @intCast(args.pos.col), + fmtmsg(&buf, .{ + "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; + } + } return error.UnexpectedRendererEvent; } diff --git a/src/win32/gui.zig b/src/win32/gui.zig index 3e35345..0040289 100644 --- a/src/win32/gui.zig +++ b/src/win32/gui.zig @@ -588,6 +588,16 @@ pub fn fmtmsg(buf: []u8, value: anytype) []const u8 { return buf[0..fbs.pos]; } +const MouseFlags = packed struct(u8) { + left_down: bool, + right_down: bool, + shift_down: bool, + control_down: bool, + middle_down: bool, + xbutton1_down: bool, + xbutton2_down: bool, + _: bool, +}; fn sendMouse( hwnd: win32.HWND, kind: enum { @@ -597,6 +607,7 @@ fn sendMouse( right_down, right_up, }, + wparam: win32.WPARAM, lparam: win32.LPARAM, ) void { const point = ddui.pointFromLparam(lparam); @@ -607,14 +618,25 @@ fn sendMouse( }; const cell = CellPos.init(cell_size, point.x, point.y); switch (kind) { - .move => state.pid.send(.{ - "RDR", - "M", - cell.cell.x, - cell.cell.y, - cell.offset.x, - cell.offset.y, - }) catch |e| onexit(e), + .move => { + const flags: MouseFlags = @bitCast(@as(u8, @intCast(0xff & wparam))); + if (flags.left_down) state.pid.send(.{ + "RDR", + "D", + @intFromEnum(input.mouse.BUTTON1), + cell.cell.x, + cell.cell.y, + cell.offset.x, + cell.offset.y, + }) catch |e| onexit(e) else state.pid.send(.{ + "RDR", + "M", + cell.cell.x, + cell.cell.y, + cell.offset.x, + cell.offset.y, + }) catch |e| onexit(e); + }, else => |b| state.pid.send(.{ "RDR", "B", @@ -953,23 +975,23 @@ fn WndProc( switch (msg) { win32.WM_MOUSEMOVE => { - sendMouse(hwnd, .move, lparam); + sendMouse(hwnd, .move, wparam, lparam); return 0; }, win32.WM_LBUTTONDOWN => { - sendMouse(hwnd, .left_down, lparam); + sendMouse(hwnd, .left_down, wparam, lparam); return 0; }, win32.WM_LBUTTONUP => { - sendMouse(hwnd, .left_up, lparam); + sendMouse(hwnd, .left_up, wparam, lparam); return 0; }, win32.WM_RBUTTONDOWN => { - sendMouse(hwnd, .right_down, lparam); + sendMouse(hwnd, .right_down, wparam, lparam); return 0; }, win32.WM_RBUTTONUP => { - sendMouse(hwnd, .right_up, lparam); + sendMouse(hwnd, .right_up, wparam, lparam); return 0; }, win32.WM_MOUSEWHEEL => {