From 0dea4c51b7c1a18a863ca320c3e16e6f5b1d0e7d Mon Sep 17 00:00:00 2001 From: sjorsdonkers <72333389+sjorsdonkers@users.noreply.github.com> Date: Tue, 6 May 2025 12:32:47 +0200 Subject: [PATCH 1/3] Subpixel mouse events --- src/cdp/domains/input.zig | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/cdp/domains/input.zig b/src/cdp/domains/input.zig index e4f79ce6..f4384385 100644 --- a/src/cdp/domains/input.zig +++ b/src/cdp/domains/input.zig @@ -32,9 +32,10 @@ pub fn processMessage(cmd: anytype) !void { // https://chromedevtools.github.io/devtools-protocol/tot/Input/#method-dispatchMouseEvent fn dispatchMouseEvent(cmd: anytype) !void { const params = (try cmd.params(struct { - x: i32, - y: i32, - type: Type, + type: Type, // Type of the mouse event. + x: f32, // X coordinate of the event relative to the main frame's viewport. + y: f32, // Y coordinate of the event relative to the main frame's viewport. 0 refers to the top of the viewport and Y increases as it proceeds towards the bottom of the viewport. + // Many optional parameters are not implemented yet, see documentation url. const Type = enum { mousePressed, @@ -56,8 +57,8 @@ fn dispatchMouseEvent(cmd: anytype) !void { const page = bc.session.currentPage() orelse return; const mouse_event = Page.MouseEvent{ - .x = params.x, - .y = params.y, + .x = @intFromFloat(params.x), // Decimal pixel values are not understood by netsurf or out rendered + .y = @intFromFloat(params.y), // So we convert them once at intake here .type = switch (params.type) { .mousePressed => .pressed, .mouseReleased => .released, From 2b7a7c0054e6514a42df67c6930dc4f5032d921f Mon Sep 17 00:00:00 2001 From: sjorsdonkers <72333389+sjorsdonkers@users.noreply.github.com> Date: Tue, 6 May 2025 12:43:40 +0200 Subject: [PATCH 2/3] floor the pixels --- src/cdp/domains/input.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cdp/domains/input.zig b/src/cdp/domains/input.zig index f4384385..25766a69 100644 --- a/src/cdp/domains/input.zig +++ b/src/cdp/domains/input.zig @@ -57,8 +57,8 @@ fn dispatchMouseEvent(cmd: anytype) !void { const page = bc.session.currentPage() orelse return; const mouse_event = Page.MouseEvent{ - .x = @intFromFloat(params.x), // Decimal pixel values are not understood by netsurf or out rendered - .y = @intFromFloat(params.y), // So we convert them once at intake here + .x = @intFromFloat(@floor(params.x)), // Decimal pixel values are not understood by netsurf or our rendered + .y = @intFromFloat(@floor(params.y)), // So we convert them once at intake here. Using floor such that -0.5 becomes -1 and 0.5 becomes 0. .type = switch (params.type) { .mousePressed => .pressed, .mouseReleased => .released, From 505ad0380e5bd26124e73b1f98799eebe4ca6371 Mon Sep 17 00:00:00 2001 From: sjorsdonkers <72333389+sjorsdonkers@users.noreply.github.com> Date: Tue, 6 May 2025 12:52:08 +0200 Subject: [PATCH 3/3] typo --- src/cdp/domains/input.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cdp/domains/input.zig b/src/cdp/domains/input.zig index 25766a69..2aaee495 100644 --- a/src/cdp/domains/input.zig +++ b/src/cdp/domains/input.zig @@ -57,7 +57,7 @@ fn dispatchMouseEvent(cmd: anytype) !void { const page = bc.session.currentPage() orelse return; const mouse_event = Page.MouseEvent{ - .x = @intFromFloat(@floor(params.x)), // Decimal pixel values are not understood by netsurf or our rendered + .x = @intFromFloat(@floor(params.x)), // Decimal pixel values are not understood by netsurf or our renderer .y = @intFromFloat(@floor(params.y)), // So we convert them once at intake here. Using floor such that -0.5 becomes -1 and 0.5 becomes 0. .type = switch (params.type) { .mousePressed => .pressed,