normal events can now track scroll

This commit is contained in:
Mitchell Hashimoto
2022-08-26 12:24:24 -07:00
parent 3096b32f13
commit a4bab6592d
2 changed files with 30 additions and 9 deletions

View File

@ -754,6 +754,27 @@ fn scrollCallback(window: glfw.Window, xoff: f64, yoff: f64) void {
const win = window.getUserPointer(Window) orelse return; const win = window.getUserPointer(Window) orelse return;
// If we're scrolling up or down, then send a mouse event
if (yoff != 0) {
const pos = window.getCursorPos() catch |err| {
log.err("error reading cursor position: {}", .{err});
return;
};
// NOTE: a limitation of glfw (perhaps) is that we can't detect
// scroll buttons (mouse four/five) WITH modifier state. So we always
// report this as a "press" followed immediately by a release with no
// modifiers.
win.mouseReport(if (yoff < 0) .four else .five, .press, .{}, pos) catch |err| {
log.err("error reporting mouse event: {}", .{err});
return;
};
win.mouseReport(if (yoff < 0) .four else .five, .release, .{}, pos) catch |err| {
log.err("error reporting mouse event: {}", .{err});
return;
};
}
//log.info("SCROLL: {} {}", .{ xoff, yoff }); //log.info("SCROLL: {} {}", .{ xoff, yoff });
_ = xoff; _ = xoff;
@ -779,12 +800,10 @@ fn mouseReport(
// TODO: posToViewport currently clamps to the window boundary, // TODO: posToViewport currently clamps to the window boundary,
// do we want to not report mouse events at all outside the window? // do we want to not report mouse events at all outside the window?
assert(self.terminal.modes.mouse_event != .none);
_ = mods;
// Depending on the event, we may do nothing at all. // Depending on the event, we may do nothing at all.
switch (self.terminal.modes.mouse_event) { switch (self.terminal.modes.mouse_event) {
.none => return,
// X10 only reports clicks with mouse button 1, 2, 3. We verify // X10 only reports clicks with mouse button 1, 2, 3. We verify
// the button later. // the button later.
.x10 => if (action != .press or .x10 => if (action != .press or
@ -794,20 +813,21 @@ fn mouseReport(
// Everything // Everything
.normal => {}, .normal => {},
else => {}, else => {},
} }
switch (self.terminal.modes.mouse_format) { switch (self.terminal.modes.mouse_format) {
.x10 => { .x10 => {
const button_code: u8 = code: { const button_code: u8 = code: {
var acc: u8 = if (action == .press) switch (button) { var acc: u8 = if (action == .press) @as(u8, switch (button) {
.left => 0, .left => 0,
.right => 1, .right => 1,
.middle => 2, .middle => 2,
.four => 64, .four => 64,
.five => 65, .five => 65,
else => return, // unsupported else => return, // unsupported
} else 3; // release is always 3 }) else 3; // release is always 3
// Normal mode adds in modifiers // Normal mode adds in modifiers
if (self.terminal.modes.mouse_event == .normal) { if (self.terminal.modes.mouse_event == .normal) {

View File

@ -83,10 +83,10 @@ modes: packed struct {
/// These are all mutually exclusive (hence in a single enum). /// These are all mutually exclusive (hence in a single enum).
pub const MouseEvents = enum(u3) { pub const MouseEvents = enum(u3) {
none = 0, none = 0,
// TODO:
x10 = 1, // 9 x10 = 1, // 9
normal = 2, // 1000 normal = 2, // 1000
// TODO:
button = 3, // 1002 button = 3, // 1002
any = 4, // 1003 any = 4, // 1003
}; };
@ -94,8 +94,9 @@ pub const MouseEvents = enum(u3) {
/// The format of mouse events when enabled. /// The format of mouse events when enabled.
/// These are all mutually exclusive (hence in a single enum). /// These are all mutually exclusive (hence in a single enum).
pub const MouseFormat = enum(u3) { pub const MouseFormat = enum(u3) {
// TODO:
x10 = 0, x10 = 0,
// TODO:
utf8 = 1, // 1005 utf8 = 1, // 1005
sgr = 2, // 1006 sgr = 2, // 1006
urxvt = 3, // 1015 urxvt = 3, // 1015