mouse: enable pixel tracking

This commit is contained in:
Tim Culverhouse 2024-05-21 14:59:06 -05:00
parent 1dc90bd764
commit a1263b1baa
5 changed files with 25 additions and 12 deletions

View file

@ -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

View file

@ -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

View file

@ -1,6 +1,12 @@
/// A mouse event
pub const Mouse = @This();
pub const ReportingMode = enum {
off,
cells,
pixels,
};
pub const Shape = enum {
default,
text,

View file

@ -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();
}
}

View file

@ -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";