Add MouseMotionRaw and normal mouse motion

This commit is contained in:
vlo
2026-11-22 19:50:18 +01:00
parent 25f584c10e
commit ec920f10dd
+12 -7
View File
@@ -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 });
},