fix(tui): prevent button active state from sticking
This commit is contained in:
parent
34bbfd49ad
commit
701107253f
3 changed files with 10 additions and 12 deletions
|
@ -35,7 +35,7 @@ bracketed_paste_buffer: std.ArrayList(u8),
|
||||||
handler_ctx: *anyopaque,
|
handler_ctx: *anyopaque,
|
||||||
dispatch_input: ?*const fn (ctx: *anyopaque, cbor_msg: []const u8) void = null,
|
dispatch_input: ?*const fn (ctx: *anyopaque, cbor_msg: []const u8) void = null,
|
||||||
dispatch_mouse: ?*const fn (ctx: *anyopaque, y: c_int, x: c_int, cbor_msg: []const u8) void = null,
|
dispatch_mouse: ?*const fn (ctx: *anyopaque, y: c_int, x: c_int, cbor_msg: []const u8) void = null,
|
||||||
dispatch_mouse_drag: ?*const fn (ctx: *anyopaque, y: c_int, x: c_int, dragging: bool, cbor_msg: []const u8) void = null,
|
dispatch_mouse_drag: ?*const fn (ctx: *anyopaque, y: c_int, x: c_int, cbor_msg: []const u8) void = null,
|
||||||
dispatch_event: ?*const fn (ctx: *anyopaque, cbor_msg: []const u8) void = null,
|
dispatch_event: ?*const fn (ctx: *anyopaque, cbor_msg: []const u8) void = null,
|
||||||
|
|
||||||
logger: log.Logger,
|
logger: log.Logger,
|
||||||
|
@ -207,7 +207,7 @@ pub fn process_input_event(self: *Self, input_: []const u8) !void {
|
||||||
mouse.yoffset,
|
mouse.yoffset,
|
||||||
})),
|
})),
|
||||||
.drag => if (self.dispatch_mouse_drag) |f_|
|
.drag => if (self.dispatch_mouse_drag) |f_|
|
||||||
f_(self.handler_ctx, @intCast(mouse.row), @intCast(mouse.col), true, try self.fmtmsg(.{
|
f_(self.handler_ctx, @intCast(mouse.row), @intCast(mouse.col), try self.fmtmsg(.{
|
||||||
"D",
|
"D",
|
||||||
event_type.PRESS,
|
event_type.PRESS,
|
||||||
@intFromEnum(mouse.button),
|
@intFromEnum(mouse.button),
|
||||||
|
|
|
@ -91,17 +91,15 @@ pub fn State(ctx_type: type) type {
|
||||||
pub fn receive(self: *Self, from: tp.pid_ref, m: tp.message) error{Exit}!bool {
|
pub fn receive(self: *Self, from: tp.pid_ref, m: tp.message) error{Exit}!bool {
|
||||||
var btn: u32 = 0;
|
var btn: u32 = 0;
|
||||||
if (try m.match(.{ "B", event_type.PRESS, tp.extract(&btn), tp.any, tp.any, tp.any, tp.any, tp.any })) {
|
if (try m.match(.{ "B", event_type.PRESS, tp.extract(&btn), tp.any, tp.any, tp.any, tp.any, tp.any })) {
|
||||||
self.active = true;
|
if (btn == key.BUTTON1) self.active = true;
|
||||||
tui.need_render();
|
tui.need_render();
|
||||||
return true;
|
return true;
|
||||||
} else if (try m.match(.{ "B", event_type.RELEASE, tp.extract(&btn), tp.any, tp.any, tp.any, tp.any, tp.any })) {
|
} else if (try m.match(.{ "B", event_type.RELEASE, tp.extract(&btn), tp.any, tp.any, tp.any, tp.any, tp.any })) {
|
||||||
self.call_click_handler(btn);
|
self.call_click_handler(btn);
|
||||||
self.active = false;
|
|
||||||
tui.need_render();
|
tui.need_render();
|
||||||
return true;
|
return true;
|
||||||
} else if (try m.match(.{ "D", event_type.RELEASE, tp.extract(&btn), tp.any, tp.any, tp.any, tp.any, tp.any })) {
|
} else if (try m.match(.{ "D", event_type.RELEASE, tp.extract(&btn), tp.any, tp.any, tp.any, tp.any, tp.any })) {
|
||||||
self.call_click_handler(btn);
|
self.call_click_handler(btn);
|
||||||
self.active = false;
|
|
||||||
tui.need_render();
|
tui.need_render();
|
||||||
return true;
|
return true;
|
||||||
} else if (try m.match(.{ "H", tp.extract(&self.hover) })) {
|
} else if (try m.match(.{ "H", tp.extract(&self.hover) })) {
|
||||||
|
@ -113,6 +111,7 @@ pub fn State(ctx_type: type) type {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call_click_handler(self: *Self, btn: u32) void {
|
fn call_click_handler(self: *Self, btn: u32) void {
|
||||||
|
if (btn == key.BUTTON1) self.active = false;
|
||||||
if (!self.hover) return;
|
if (!self.hover) return;
|
||||||
switch (btn) {
|
switch (btn) {
|
||||||
key.BUTTON1 => self.opts.on_click(&self.opts.ctx, self),
|
key.BUTTON1 => self.opts.on_click(&self.opts.ctx, self),
|
||||||
|
|
|
@ -367,20 +367,19 @@ fn dispatch_mouse(ctx: *anyopaque, y: c_int, x: c_int, cbor_msg: []const u8) voi
|
||||||
const m: tp.message = .{ .buf = cbor_msg };
|
const m: tp.message = .{ .buf = cbor_msg };
|
||||||
const from = tp.self_pid();
|
const from = tp.self_pid();
|
||||||
self.unrendered_input_events_count += 1;
|
self.unrendered_input_events_count += 1;
|
||||||
self.send_mouse(y, x, from, m) catch |e| self.logger.err("dispatch mouse", e);
|
if (self.drag_source) |_|
|
||||||
|
self.send_mouse_drag(y, x, from, m) catch |e| self.logger.err("dispatch mouse", e)
|
||||||
|
else
|
||||||
|
self.send_mouse(y, x, from, m) catch |e| self.logger.err("dispatch mouse", e);
|
||||||
self.drag_source = null;
|
self.drag_source = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_mouse_drag(ctx: *anyopaque, y: c_int, x: c_int, dragging: bool, cbor_msg: []const u8) void {
|
fn dispatch_mouse_drag(ctx: *anyopaque, y: c_int, x: c_int, cbor_msg: []const u8) void {
|
||||||
const self: *Self = @ptrCast(@alignCast(ctx));
|
const self: *Self = @ptrCast(@alignCast(ctx));
|
||||||
const m: tp.message = .{ .buf = cbor_msg };
|
const m: tp.message = .{ .buf = cbor_msg };
|
||||||
const from = tp.self_pid();
|
const from = tp.self_pid();
|
||||||
self.unrendered_input_events_count += 1;
|
self.unrendered_input_events_count += 1;
|
||||||
if (dragging) {
|
if (self.drag_source == null) self.drag_source = self.find_coord_widget(@intCast(y), @intCast(x));
|
||||||
if (self.drag_source == null) self.drag_source = self.find_coord_widget(@intCast(y), @intCast(x));
|
|
||||||
} else {
|
|
||||||
self.drag_source = null;
|
|
||||||
}
|
|
||||||
self.send_mouse_drag(y, x, from, m) catch |e| self.logger.err("dispatch mouse", e);
|
self.send_mouse_drag(y, x, from, m) catch |e| self.logger.err("dispatch mouse", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue