Add MouseMotionRaw and normal mouse motion

This commit is contained in:
vlo
2026-11-22 19:50:18 +01:00
parent 25f584c10e
commit ec920f10dd
+11 -6
View File
@@ -38,10 +38,14 @@ pub const KeyScanCode = enum(i32) {
}; };
pub const Event = union(EventType) { pub const Event = union(EventType) {
mouse_motion: struct { mouse_motion_raw: struct {
x: f32, x: f32,
y: f32, y: f32,
}, },
mouse_motion: struct {
x: u32,
u: u32,
},
key_down: struct { key_down: struct {
scancode: KeyScanCode, scancode: KeyScanCode,
}, },
@@ -58,6 +62,7 @@ pub const WindowOptions = struct {
height: usize, height: usize,
resizable: bool = true, resizable: bool = true,
raw_mouse_input: bool = true, raw_mouse_input: bool = true,
warpmouse: bool = false,
}; };
display: ?*xlib.struct__XDisplay, display: ?*xlib.struct__XDisplay,
@@ -235,19 +240,19 @@ pub fn pollEvent(self: *Self) ?Event {
if (xlib.XIMaskIsSet(raw.?.valuators.mask, 1) != 0) if (xlib.XIMaskIsSet(raw.?.valuators.mask, 1) != 0)
ydelta += @floatCast(raw.?.raw_values[1] * 1); ydelta += @floatCast(raw.?.raw_values[1] * 1);
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)); _ = 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 = .{
return .{ .mouse_motion_raw = .{
.x = xdelta, .x = xdelta,
.y = ydelta, .y = ydelta,
} }; } };
} }
}, },
xlib.MotionNotify => { 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 = .{ return .{ .mouse_motion = .{
.x = 0, .x = e.xmotion.x,
.y = 0, .y = e.xmotion.y,
} }; } };
//std.debug.print("Motion : {d} {d}\n", .{ e.xmotion.x, e.xmotion.y }); //std.debug.print("Motion : {d} {d}\n", .{ e.xmotion.x, e.xmotion.y });
}, },