summaryrefslogtreecommitdiff
path: root/src/gui/gui.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/gui.zig')
-rw-r--r--src/gui/gui.zig41
1 files changed, 40 insertions, 1 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index a4cc7672..989f6b25 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -2876,6 +2876,43 @@ const StdinFeed = struct {
var seq_start: usize = 0;
while (seq_start < len) {
+ // ESC]777;mouse;<down|up|motion>;<SDL button, 0 for none>;<x>;<y>BEL
+ // A mouse event at window pixels, built as SDL would and run
+ // through dispatch, so a driver exercises the real pointer path
+ // (pixel to cell, tag and body hits). SGR mouse carries only cells.
+ const mouse_prefix = "\x1b]777;mouse;";
+ if (std.mem.startsWith(u8, f.buf[seq_start..len], mouse_prefix)) {
+ const body = f.buf[seq_start + mouse_prefix.len .. len];
+ const end = std.mem.indexOfScalar(u8, body, 0x07) orelse {
+ std.mem.copyForwards(u8, f.buf[0 .. len - seq_start], f.buf[seq_start..len]);
+ f.fill = len - seq_start;
+ break;
+ };
+ if (g) |gp| {
+ var parts = std.mem.splitScalar(u8, body[0..end], ';');
+ const kind = parts.next() orelse "";
+ const button = std.fmt.parseInt(u8, parts.next() orelse "", 10) catch 0;
+ const x = std.fmt.parseFloat(f32, parts.next() orelse "") catch 0;
+ const y = std.fmt.parseFloat(f32, parts.next() orelse "") catch 0;
+ var sev = std.mem.zeroes(c.SDL_Event);
+ if (std.mem.eql(u8, kind, "motion")) {
+ sev.type = c.SDL_EVENT_MOUSE_MOTION;
+ sev.motion.x = x;
+ sev.motion.y = y;
+ sev.motion.state = if (button == 0 or button > 5) 0 else @as(u32, 1) << @intCast(button - 1);
+ } else {
+ sev.type = if (std.mem.eql(u8, kind, "down")) c.SDL_EVENT_MOUSE_BUTTON_DOWN else c.SDL_EVENT_MOUSE_BUTTON_UP;
+ sev.button.button = button;
+ sev.button.down = std.mem.eql(u8, kind, "down");
+ sev.button.x = x;
+ sev.button.y = y;
+ }
+ dispatch(gp, in, &sev);
+ out.n_events += 1;
+ }
+ seq_start += mouse_prefix.len + end + 1;
+ continue;
+ }
const prefix = "\x1b]777;finger;";
if (std.mem.startsWith(u8, f.buf[seq_start..len], prefix)) {
const body = f.buf[seq_start + prefix.len .. len];
@@ -2909,7 +2946,9 @@ const StdinFeed = struct {
seq_start += prefix.len + end + 1;
continue;
}
- if (len - seq_start < prefix.len and std.mem.startsWith(u8, prefix, f.buf[seq_start..len])) {
+ if ((len - seq_start < prefix.len and std.mem.startsWith(u8, prefix, f.buf[seq_start..len])) or
+ (len - seq_start < mouse_prefix.len and std.mem.startsWith(u8, mouse_prefix, f.buf[seq_start..len])))
+ {
std.mem.copyForwards(u8, f.buf[0 .. len - seq_start], f.buf[seq_start..len]);
f.fill = len - seq_start;
break;