mouse: enable pixel tracking
This commit is contained in:
parent
1dc90bd764
commit
a1263b1baa
5 changed files with 25 additions and 12 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
/// A mouse event
|
||||
pub const Mouse = @This();
|
||||
|
||||
pub const ReportingMode = enum {
|
||||
off,
|
||||
cells,
|
||||
pixels,
|
||||
};
|
||||
|
||||
pub const Shape = enum {
|
||||
default,
|
||||
text,
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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";
|
||||
|
|
Loading…
Reference in a new issue