From ec920f10dd108e57061a2d90dc37dfd65052672e Mon Sep 17 00:00:00 2001 From: vlo Date: Sun, 22 Nov 2026 19:50:18 +0100 Subject: [PATCH] Add MouseMotionRaw and normal mouse motion --- src/Window.zig | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Window.zig b/src/Window.zig index fcafd47..24cf763 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -38,10 +38,14 @@ pub const KeyScanCode = enum(i32) { }; pub const Event = union(EventType) { - mouse_motion: struct { + mouse_motion_raw: struct { x: f32, y: f32, }, + mouse_motion: struct { + x: u32, + u: u32, + }, key_down: struct { scancode: KeyScanCode, }, @@ -58,6 +62,7 @@ pub const WindowOptions = struct { height: usize, resizable: bool = true, raw_mouse_input: bool = true, + warpmouse: bool = false, }; display: ?*xlib.struct__XDisplay, @@ -235,19 +240,19 @@ pub fn pollEvent(self: *Self) ?Event { if (xlib.XIMaskIsSet(raw.?.valuators.mask, 1) != 0) ydelta += @floatCast(raw.?.raw_values[1] * 1); - _ = xlib.XWarpPointer(self.display, xlib.None, self.window, 0, 0, 0, 0, @intCast(self.options.width / 2), @intCast(self.options.height / 2)); - return .{ .mouse_motion = .{ + if (self.options.warpmouse) + _ = xlib.XWarpPointer(self.display, xlib.None, self.window, 0, 0, 0, 0, @intCast(self.options.width / 2), @intCast(self.options.height / 2)); + + return .{ .mouse_motion_raw = .{ .x = xdelta, .y = ydelta, } }; } }, xlib.MotionNotify => { - // TODO Xorg still receives normal mousemotion events when moving mouse in between. - // Just return fake mouse motion event when they occur return .{ .mouse_motion = .{ - .x = 0, - .y = 0, + .x = e.xmotion.x, + .y = e.xmotion.y, } }; //std.debug.print("Motion : {d} {d}\n", .{ e.xmotion.x, e.xmotion.y }); },