diff --git a/examples/pause_tui.zig b/examples/pause_tui.zig index 1d29460..61ca79c 100644 --- a/examples/pause_tui.zig +++ b/examples/pause_tui.zig @@ -58,7 +58,7 @@ pub fn main() !void { // _always_ be called, but is left to the application to decide when try vx.queryTerminal(); - try vx.setMouseMode(true); + try vx.setMouseMode(.cells); // The main event loop. Vaxis provides a thread safe, blocking, buffered // queue which can serve as the primary event queue for an application diff --git a/examples/text_input.zig b/examples/text_input.zig index f4a756d..36fcdef 100644 --- a/examples/text_input.zig +++ b/examples/text_input.zig @@ -60,7 +60,7 @@ pub fn main() !void { // _always_ be called, but is left to the application to decide when try vx.queryTerminal(); - try vx.setMouseMode(true); + try vx.setMouseMode(.pixels); // The main event loop. Vaxis provides a thread safe, blocking, buffered // queue which can serve as the primary event queue for an application diff --git a/src/Mouse.zig b/src/Mouse.zig index 2129835..192637f 100644 --- a/src/Mouse.zig +++ b/src/Mouse.zig @@ -1,6 +1,12 @@ /// A mouse event pub const Mouse = @This(); +pub const ReportingMode = enum { + off, + cells, + pixels, +}; + pub const Shape = enum { default, text, diff --git a/src/Vaxis.zig b/src/Vaxis.zig index 6ead4e9..6e2cc87 100644 --- a/src/Vaxis.zig +++ b/src/Vaxis.zig @@ -698,17 +698,23 @@ pub fn setMouseShape(self: *Vaxis, shape: Shape) void { self.screen.mouse_shape = shape; } -/// turn mouse reporting on or off -pub fn setMouseMode(self: *Vaxis, enable: bool) !void { +/// Change the mouse reporting mode +pub fn setMouseMode(self: *Vaxis, mode: Mouse.ReportingMode) !void { if (self.tty) |*tty| { - tty.state.mouse = enable; - if (enable) { - _ = try tty.write(ctlseqs.mouse_set); - try tty.flush(); - } else { - _ = try tty.write(ctlseqs.mouse_reset); - try tty.flush(); + switch (mode) { + .off => { + _ = try tty.write(ctlseqs.mouse_reset); + }, + .cells => { + tty.state.mouse = true; + _ = try tty.write(ctlseqs.mouse_set); + }, + .pixels => { + tty.state.mouse = true; + _ = try tty.write(ctlseqs.mouse_set_pixels); + }, } + try tty.flush(); } } diff --git a/src/ctlseqs.zig b/src/ctlseqs.zig index c0ecb43..04b9a61 100644 --- a/src/ctlseqs.zig +++ b/src/ctlseqs.zig @@ -13,7 +13,8 @@ pub const sixel_geometry_query = "\x1b[?2;1;0S"; // mouse pub const mouse_set = "\x1b[?1003;1004;1006h"; -pub const mouse_reset = "\x1b[?1003;1004;1006l"; +pub const mouse_set_pixels = "\x1b[?1003;1004;1016h"; +pub const mouse_reset = "\x1b[?1003;1004;1006;1016l"; // sync pub const sync_set = "\x1b[?2026h";