refactor: move input types to new module and use directly use libvaxis types
This commit is contained in:
parent
e08c2aa3ba
commit
18f321bf41
36 changed files with 1224 additions and 1363 deletions
|
@ -3,8 +3,7 @@ const tp = @import("thespian");
|
|||
|
||||
const EventHandler = @import("EventHandler");
|
||||
const Plane = @import("renderer").Plane;
|
||||
const key = @import("renderer").input.key;
|
||||
const event_type = @import("renderer").input.event_type;
|
||||
const input = @import("input");
|
||||
|
||||
const Widget = @import("Widget.zig");
|
||||
const tui = @import("tui.zig");
|
||||
|
@ -92,36 +91,37 @@ pub fn State(ctx_type: type) type {
|
|||
}
|
||||
|
||||
pub fn receive(self: *Self, from: tp.pid_ref, m: tp.message) error{Exit}!bool {
|
||||
var btn: u32 = 0;
|
||||
if (try m.match(.{ "B", event_type.PRESS, tp.extract(&btn), tp.more })) {
|
||||
switch (btn) {
|
||||
key.BUTTON1 => {
|
||||
var btn: input.MouseType = 0;
|
||||
if (try m.match(.{ "B", input.event.press, tp.extract(&btn), tp.more })) {
|
||||
const btn_enum: input.Mouse = @enumFromInt(btn);
|
||||
switch (btn_enum) {
|
||||
input.mouse.BUTTON1 => {
|
||||
self.active = true;
|
||||
tui.need_render();
|
||||
},
|
||||
key.BUTTON4, key.BUTTON5 => {
|
||||
self.call_click_handler(btn);
|
||||
input.mouse.BUTTON4, input.mouse.BUTTON5 => {
|
||||
self.call_click_handler(btn_enum);
|
||||
return true;
|
||||
},
|
||||
else => {},
|
||||
}
|
||||
return true;
|
||||
} else if (try m.match(.{ "B", event_type.RELEASE, tp.extract(&btn), tp.more })) {
|
||||
self.call_click_handler(btn);
|
||||
} else if (try m.match(.{ "B", input.event.release, tp.extract(&btn), tp.more })) {
|
||||
self.call_click_handler(@enumFromInt(btn));
|
||||
tui.need_render();
|
||||
return true;
|
||||
} else if (try m.match(.{ "D", event_type.PRESS, tp.extract(&btn), tp.more })) {
|
||||
} else if (try m.match(.{ "D", input.event.press, tp.extract(&btn), tp.more })) {
|
||||
if (self.opts.on_event) |h| {
|
||||
self.active = false;
|
||||
h.send(from, m) catch {};
|
||||
}
|
||||
return true;
|
||||
} else if (try m.match(.{ "D", event_type.RELEASE, tp.extract(&btn), tp.more })) {
|
||||
} else if (try m.match(.{ "D", input.event.release, tp.extract(&btn), tp.more })) {
|
||||
if (self.opts.on_event) |h| {
|
||||
self.active = false;
|
||||
h.send(from, m) catch {};
|
||||
}
|
||||
self.call_click_handler(btn);
|
||||
self.call_click_handler(@enumFromInt(btn));
|
||||
tui.need_render();
|
||||
return true;
|
||||
} else if (try m.match(.{ "H", tp.extract(&self.hover) })) {
|
||||
|
@ -132,18 +132,18 @@ pub fn State(ctx_type: type) type {
|
|||
return self.opts.on_receive(&self.opts.ctx, self, from, m);
|
||||
}
|
||||
|
||||
fn call_click_handler(self: *Self, btn: u32) void {
|
||||
if (btn == key.BUTTON1) {
|
||||
fn call_click_handler(self: *Self, btn: input.Mouse) void {
|
||||
if (btn == input.mouse.BUTTON1) {
|
||||
if (!self.active) return;
|
||||
self.active = false;
|
||||
}
|
||||
if (!self.hover) return;
|
||||
switch (btn) {
|
||||
key.BUTTON1 => self.opts.on_click(&self.opts.ctx, self),
|
||||
key.BUTTON2 => self.opts.on_click2(&self.opts.ctx, self),
|
||||
key.BUTTON3 => self.opts.on_click3(&self.opts.ctx, self),
|
||||
key.BUTTON4 => self.opts.on_click4(&self.opts.ctx, self),
|
||||
key.BUTTON5 => self.opts.on_click5(&self.opts.ctx, self),
|
||||
input.mouse.BUTTON1 => self.opts.on_click(&self.opts.ctx, self),
|
||||
input.mouse.BUTTON2 => self.opts.on_click2(&self.opts.ctx, self),
|
||||
input.mouse.BUTTON3 => self.opts.on_click3(&self.opts.ctx, self),
|
||||
input.mouse.BUTTON4 => self.opts.on_click4(&self.opts.ctx, self),
|
||||
input.mouse.BUTTON5 => self.opts.on_click5(&self.opts.ctx, self),
|
||||
else => {},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,7 @@ const std = @import("std");
|
|||
const tp = @import("thespian");
|
||||
|
||||
const Plane = @import("renderer").Plane;
|
||||
const key = @import("renderer").input.key;
|
||||
const event_type = @import("renderer").input.event_type;
|
||||
const input = @import("input");
|
||||
|
||||
const Widget = @import("Widget.zig");
|
||||
const tui = @import("tui.zig");
|
||||
|
@ -99,16 +98,16 @@ pub fn State(ctx_type: type) type {
|
|||
}
|
||||
|
||||
pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {
|
||||
if (try m.match(.{ "B", event_type.PRESS, key.BUTTON1, tp.any, tp.any, tp.any, tp.any, tp.any })) {
|
||||
if (try m.match(.{ "B", input.event.press, @intFromEnum(input.mouse.BUTTON1), tp.any, tp.any, tp.any, tp.any, tp.any })) {
|
||||
self.active = true;
|
||||
tui.need_render();
|
||||
return true;
|
||||
} else if (try m.match(.{ "B", event_type.RELEASE, key.BUTTON1, tp.any, tp.any, tp.any, tp.any, tp.any })) {
|
||||
} else if (try m.match(.{ "B", input.event.release, @intFromEnum(input.mouse.BUTTON1), tp.any, tp.any, tp.any, tp.any, tp.any })) {
|
||||
self.opts.on_click(self.opts.ctx, self);
|
||||
self.active = false;
|
||||
tui.need_render();
|
||||
return true;
|
||||
} else if (try m.match(.{ "D", event_type.RELEASE, key.BUTTON1, tp.any, tp.any, tp.any, tp.any, tp.any })) {
|
||||
} else if (try m.match(.{ "D", input.event.release, @intFromEnum(input.mouse.BUTTON1), tp.any, tp.any, tp.any, tp.any, tp.any })) {
|
||||
self.opts.on_click(self.opts.ctx, self);
|
||||
self.active = false;
|
||||
tui.need_render();
|
||||
|
|
|
@ -5,8 +5,7 @@ const EventHandler = @import("EventHandler");
|
|||
const tui = @import("tui.zig");
|
||||
const Widget = @import("Widget.zig");
|
||||
const Plane = @import("renderer").Plane;
|
||||
const key = @import("renderer").input.key;
|
||||
const event_type = @import("renderer").input.event_type;
|
||||
const input = @import("input");
|
||||
|
||||
pub fn Options(context: type) type {
|
||||
return struct {
|
||||
|
@ -95,16 +94,16 @@ pub fn State(ctx_type: type) type {
|
|||
}
|
||||
|
||||
pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {
|
||||
var btn: u32 = 0;
|
||||
if (try m.match(.{ "B", event_type.PRESS, tp.more })) {
|
||||
var btn: input.MouseType = 0;
|
||||
if (try m.match(.{ "B", input.event.press, tp.more })) {
|
||||
return true;
|
||||
} else if (try m.match(.{ "B", event_type.RELEASE, tp.extract(&btn), tp.more })) {
|
||||
self.call_click_handler(btn);
|
||||
} else if (try m.match(.{ "B", input.event.release, tp.extract(&btn), tp.more })) {
|
||||
self.call_click_handler(@enumFromInt(btn));
|
||||
return true;
|
||||
} else if (try m.match(.{ "D", event_type.PRESS, tp.extract(&btn), tp.more })) {
|
||||
} else if (try m.match(.{ "D", input.event.press, tp.extract(&btn), tp.more })) {
|
||||
return true;
|
||||
} else if (try m.match(.{ "D", event_type.RELEASE, tp.extract(&btn), tp.more })) {
|
||||
self.call_click_handler(btn);
|
||||
} else if (try m.match(.{ "D", input.event.release, tp.extract(&btn), tp.more })) {
|
||||
self.call_click_handler(@enumFromInt(btn));
|
||||
return true;
|
||||
} else if (try m.match(.{ "H", tp.extract(&self.hover) })) {
|
||||
tui.current().rdr.request_mouse_cursor_default(self.hover);
|
||||
|
@ -113,14 +112,14 @@ pub fn State(ctx_type: type) type {
|
|||
return false;
|
||||
}
|
||||
|
||||
fn call_click_handler(self: *Self, btn: u32) void {
|
||||
fn call_click_handler(self: *Self, btn: input.Mouse) void {
|
||||
if (!self.hover) return;
|
||||
switch (btn) {
|
||||
key.BUTTON1 => self.opts.on_click(self.opts.ctx, self),
|
||||
key.BUTTON2 => self.opts.on_click2(self.opts.ctx, self),
|
||||
key.BUTTON3 => self.opts.on_click3(self.opts.ctx, self),
|
||||
key.BUTTON4 => self.opts.on_click4(self.opts.ctx, self),
|
||||
key.BUTTON5 => self.opts.on_click5(self.opts.ctx, self),
|
||||
input.mouse.BUTTON1 => self.opts.on_click(self.opts.ctx, self),
|
||||
input.mouse.BUTTON2 => self.opts.on_click2(self.opts.ctx, self),
|
||||
input.mouse.BUTTON3 => self.opts.on_click3(self.opts.ctx, self),
|
||||
input.mouse.BUTTON4 => self.opts.on_click4(self.opts.ctx, self),
|
||||
input.mouse.BUTTON5 => self.opts.on_click5(self.opts.ctx, self),
|
||||
else => {},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,8 +14,7 @@ const root_mod = @import("root");
|
|||
|
||||
const Plane = @import("renderer").Plane;
|
||||
const Cell = @import("renderer").Cell;
|
||||
const key = @import("renderer").input.key;
|
||||
const event_type = @import("renderer").input.event_type;
|
||||
const input = @import("input");
|
||||
const command = @import("command");
|
||||
const EventHandler = @import("EventHandler");
|
||||
|
||||
|
@ -834,7 +833,7 @@ pub const Editor = struct {
|
|||
mode.cursor_shape
|
||||
else
|
||||
.block;
|
||||
tui.current().rdr.cursor_enable(y, x, shape) catch {};
|
||||
tui.current().rdr.cursor_enable(y, x, tui.translate_cursor_shape(shape)) catch {};
|
||||
} else {
|
||||
tui.current().rdr.cursor_disable();
|
||||
}
|
||||
|
@ -4104,7 +4103,7 @@ pub const EditorWidget = struct {
|
|||
editor: Editor,
|
||||
commands: Commands = undefined,
|
||||
|
||||
last_btn: c_int = -1,
|
||||
last_btn: input.Mouse = .none,
|
||||
last_btn_time_ms: i64 = 0,
|
||||
last_btn_count: usize = 0,
|
||||
|
||||
|
@ -4163,8 +4162,8 @@ pub const EditorWidget = struct {
|
|||
}
|
||||
|
||||
fn receive_safe(self: *Self, m: tp.message) !bool {
|
||||
var evtype: c_int = undefined;
|
||||
var btn: c_int = undefined;
|
||||
var event: input.Event = undefined;
|
||||
var btn: input.MouseType = undefined;
|
||||
var x: c_int = undefined;
|
||||
var y: c_int = undefined;
|
||||
var xpx: c_int = undefined;
|
||||
|
@ -4179,10 +4178,10 @@ pub const EditorWidget = struct {
|
|||
if (self.editor.jump_mode)
|
||||
self.update_hover_timer(.init);
|
||||
}
|
||||
} else if (try m.match(.{ "B", tp.extract(&evtype), tp.extract(&btn), tp.any, tp.extract(&x), tp.extract(&y), tp.extract(&xpx), tp.extract(&ypx) })) {
|
||||
try self.mouse_click_event(evtype, btn, y, x, ypx, xpx);
|
||||
} else if (try m.match(.{ "D", tp.extract(&evtype), tp.extract(&btn), tp.any, tp.extract(&x), tp.extract(&y), tp.extract(&xpx), tp.extract(&ypx) })) {
|
||||
try self.mouse_drag_event(evtype, btn, y, x, ypx, xpx);
|
||||
} else if (try m.match(.{ "B", tp.extract(&event), tp.extract(&btn), tp.any, tp.extract(&x), tp.extract(&y), tp.extract(&xpx), tp.extract(&ypx) })) {
|
||||
try self.mouse_click_event(event, @enumFromInt(btn), y, x, ypx, xpx);
|
||||
} else if (try m.match(.{ "D", tp.extract(&event), tp.extract(&btn), tp.any, tp.extract(&x), tp.extract(&y), tp.extract(&xpx), tp.extract(&ypx) })) {
|
||||
try self.mouse_drag_event(event, @enumFromInt(btn), y, x, ypx, xpx);
|
||||
} else if (try m.match(.{ "scroll_to", tp.extract(&pos) })) {
|
||||
self.editor.scroll_to(pos);
|
||||
} else if (try m.match(.{ "filter", "stdout", tp.extract(&bytes) })) {
|
||||
|
@ -4227,16 +4226,16 @@ pub const EditorWidget = struct {
|
|||
|
||||
const Result = command.Result;
|
||||
|
||||
fn mouse_click_event(self: *Self, evtype: c_int, btn: c_int, y: c_int, x: c_int, ypx: c_int, xpx: c_int) Result {
|
||||
if (evtype != event_type.PRESS) return;
|
||||
fn mouse_click_event(self: *Self, event: input.Event, btn: input.Mouse, y: c_int, x: c_int, ypx: c_int, xpx: c_int) Result {
|
||||
if (event != input.event.press) return;
|
||||
const ret = (switch (btn) {
|
||||
key.BUTTON1 => &mouse_click_button1,
|
||||
key.BUTTON2 => &mouse_click_button2,
|
||||
key.BUTTON3 => &mouse_click_button3,
|
||||
key.BUTTON4 => &mouse_click_button4,
|
||||
key.BUTTON5 => &mouse_click_button5,
|
||||
key.BUTTON8 => &mouse_click_button8, //back
|
||||
key.BUTTON9 => &mouse_click_button9, //forward
|
||||
input.mouse.BUTTON1 => &mouse_click_button1,
|
||||
input.mouse.BUTTON2 => &mouse_click_button2,
|
||||
input.mouse.BUTTON3 => &mouse_click_button3,
|
||||
input.mouse.BUTTON4 => &mouse_click_button4,
|
||||
input.mouse.BUTTON5 => &mouse_click_button5,
|
||||
input.mouse.BUTTON8 => &mouse_click_button8, //back
|
||||
input.mouse.BUTTON9 => &mouse_click_button9, //forward
|
||||
else => return,
|
||||
})(self, y, x, ypx, xpx);
|
||||
self.last_btn = btn;
|
||||
|
@ -4244,19 +4243,19 @@ pub const EditorWidget = struct {
|
|||
return ret;
|
||||
}
|
||||
|
||||
fn mouse_drag_event(self: *Self, evtype: c_int, btn: c_int, y: c_int, x: c_int, ypx: c_int, xpx: c_int) Result {
|
||||
if (evtype != event_type.PRESS) return;
|
||||
fn mouse_drag_event(self: *Self, event: input.Event, btn: input.Mouse, y: c_int, x: c_int, ypx: c_int, xpx: c_int) Result {
|
||||
if (event != input.event.press) return;
|
||||
return (switch (btn) {
|
||||
key.BUTTON1 => &mouse_drag_button1,
|
||||
key.BUTTON2 => &mouse_drag_button2,
|
||||
key.BUTTON3 => &mouse_drag_button3,
|
||||
input.mouse.BUTTON1 => &mouse_drag_button1,
|
||||
input.mouse.BUTTON2 => &mouse_drag_button2,
|
||||
input.mouse.BUTTON3 => &mouse_drag_button3,
|
||||
else => return,
|
||||
})(self, y, x, ypx, xpx);
|
||||
}
|
||||
|
||||
fn mouse_click_button1(self: *Self, y: c_int, x: c_int, _: c_int, _: c_int) Result {
|
||||
const y_, const x_ = self.editor.plane.abs_yx_to_rel(y, x);
|
||||
if (self.last_btn == key.BUTTON1) {
|
||||
if (self.last_btn == input.mouse.BUTTON1) {
|
||||
const click_time_ms = time.milliTimestamp() - self.last_btn_time_ms;
|
||||
if (click_time_ms <= double_click_time_ms) {
|
||||
if (self.last_btn_count == 2) {
|
||||
|
|
|
@ -8,8 +8,7 @@ const root = @import("root");
|
|||
|
||||
const Plane = @import("renderer").Plane;
|
||||
const style = @import("renderer").style;
|
||||
const key = @import("renderer").input.key;
|
||||
const event_type = @import("renderer").input.event_type;
|
||||
const input = @import("input");
|
||||
const command = @import("command");
|
||||
const EventHandler = @import("EventHandler");
|
||||
|
||||
|
@ -90,15 +89,15 @@ pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {
|
|||
var y: i32 = undefined;
|
||||
var ypx: i32 = undefined;
|
||||
|
||||
if (try m.match(.{ "B", event_type.PRESS, key.BUTTON1, tp.any, tp.any, tp.extract(&y), tp.any, tp.extract(&ypx) }))
|
||||
if (try m.match(.{ "B", input.event.press, @intFromEnum(input.mouse.BUTTON1), tp.any, tp.any, tp.extract(&y), tp.any, tp.extract(&ypx) }))
|
||||
return self.primary_click(y);
|
||||
if (try m.match(.{ "B", event_type.PRESS, key.BUTTON3, tp.any, tp.any, tp.extract(&y), tp.any, tp.extract(&ypx) }))
|
||||
if (try m.match(.{ "B", input.event.press, @intFromEnum(input.mouse.BUTTON3), tp.any, tp.any, tp.extract(&y), tp.any, tp.extract(&ypx) }))
|
||||
return self.secondary_click();
|
||||
if (try m.match(.{ "D", event_type.PRESS, key.BUTTON1, tp.any, tp.any, tp.extract(&y), tp.any, tp.extract(&ypx) }))
|
||||
if (try m.match(.{ "D", input.event.press, @intFromEnum(input.mouse.BUTTON1), tp.any, tp.any, tp.extract(&y), tp.any, tp.extract(&ypx) }))
|
||||
return self.primary_drag(y);
|
||||
if (try m.match(.{ "B", event_type.PRESS, key.BUTTON4, tp.more }))
|
||||
if (try m.match(.{ "B", input.event.press, @intFromEnum(input.mouse.BUTTON4), tp.more }))
|
||||
return self.mouse_click_button4();
|
||||
if (try m.match(.{ "B", event_type.PRESS, key.BUTTON5, tp.more }))
|
||||
if (try m.match(.{ "B", input.event.press, @intFromEnum(input.mouse.BUTTON5), tp.more }))
|
||||
return self.mouse_click_button5();
|
||||
|
||||
return false;
|
||||
|
|
|
@ -9,8 +9,7 @@ const project_manager = @import("project_manager");
|
|||
const log = @import("log");
|
||||
|
||||
const Plane = @import("renderer").Plane;
|
||||
const key = @import("renderer").input.key;
|
||||
const event_type = @import("renderer").input.event_type;
|
||||
const input = @import("input");
|
||||
const command = @import("command");
|
||||
|
||||
const tui = @import("tui.zig");
|
||||
|
@ -150,7 +149,7 @@ pub fn box(self: *const Self) Box {
|
|||
|
||||
fn handle_bottom_bar_event(self: *Self, _: tp.pid_ref, m: tp.message) tp.result {
|
||||
var y: usize = undefined;
|
||||
if (try m.match(.{ "D", event_type.PRESS, key.BUTTON1, tp.any, tp.any, tp.extract(&y), tp.any, tp.any }))
|
||||
if (try m.match(.{ "D", input.event.press, @intFromEnum(input.mouse.BUTTON1), tp.any, tp.any, tp.extract(&y), tp.any, tp.any }))
|
||||
return self.bottom_bar_primary_drag(y);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,11 +4,8 @@ const cbor = @import("cbor");
|
|||
const log = @import("log");
|
||||
const root = @import("root");
|
||||
|
||||
const key = @import("renderer").input.key;
|
||||
const mod = @import("renderer").input.modifier;
|
||||
const event_type = @import("renderer").input.event_type;
|
||||
const input = @import("input");
|
||||
const keybind = @import("keybind");
|
||||
const ucs32_to_utf8 = @import("renderer").ucs32_to_utf8;
|
||||
const project_manager = @import("project_manager");
|
||||
const command = @import("command");
|
||||
const EventHandler = @import("EventHandler");
|
||||
|
@ -310,7 +307,7 @@ pub fn Create(options: type) type {
|
|||
return error.InvalidArgument;
|
||||
self.complete_trigger_count = 0;
|
||||
var buf: [32]u8 = undefined;
|
||||
const bytes = try ucs32_to_utf8(&[_]u32{egc}, &buf);
|
||||
const bytes = try input.ucs32_to_utf8(&[_]u32{egc}, &buf);
|
||||
try self.file_path.appendSlice(buf[0..bytes]);
|
||||
self.update_mini_mode_text();
|
||||
}
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
const tp = @import("thespian");
|
||||
|
||||
const key = @import("renderer").input.key;
|
||||
const mod = @import("renderer").input.modifier;
|
||||
const event_type = @import("renderer").input.event_type;
|
||||
const input = @import("input");
|
||||
const keybind = @import("keybind");
|
||||
const ucs32_to_utf8 = @import("renderer").ucs32_to_utf8;
|
||||
const command = @import("command");
|
||||
const EventHandler = @import("EventHandler");
|
||||
|
||||
|
@ -82,7 +79,7 @@ pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {
|
|||
|
||||
fn insert_code_point(self: *Self, c: u32) !void {
|
||||
var buf: [16]u8 = undefined;
|
||||
const bytes = ucs32_to_utf8(&[_]u32{c}, &buf) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
||||
const bytes = input.ucs32_to_utf8(&[_]u32{c}, &buf) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
||||
try self.input.appendSlice(buf[0..bytes]);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
const tp = @import("thespian");
|
||||
|
||||
const key = @import("renderer").input.key;
|
||||
const mod = @import("renderer").input.modifier;
|
||||
const event_type = @import("renderer").input.event_type;
|
||||
const input = @import("input");
|
||||
const keybind = @import("keybind");
|
||||
const ucs32_to_utf8 = @import("renderer").ucs32_to_utf8;
|
||||
const command = @import("command");
|
||||
const EventHandler = @import("EventHandler");
|
||||
|
||||
|
@ -75,7 +72,7 @@ pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {
|
|||
fn insert_code_point(self: *Self, c: u32) !void {
|
||||
if (self.input.len + 16 > self.buf.len)
|
||||
try self.flush_input();
|
||||
const bytes = try ucs32_to_utf8(&[_]u32{c}, self.buf[self.input.len..]);
|
||||
const bytes = try input.ucs32_to_utf8(&[_]u32{c}, self.buf[self.input.len..]);
|
||||
self.input = self.buf[0 .. self.input.len + bytes];
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
const tp = @import("thespian");
|
||||
|
||||
const key = @import("renderer").input.key;
|
||||
const mod = @import("renderer").input.modifier;
|
||||
const event_type = @import("renderer").input.event_type;
|
||||
const ucs32_to_utf8 = @import("renderer").ucs32_to_utf8;
|
||||
const input = @import("input");
|
||||
const keybind = @import("keybind");
|
||||
const command = @import("command");
|
||||
const EventHandler = @import("EventHandler");
|
||||
|
@ -89,7 +86,7 @@ fn execute_operation(self: *Self, c: u32) void {
|
|||
},
|
||||
};
|
||||
var buf: [6]u8 = undefined;
|
||||
const bytes = ucs32_to_utf8(&[_]u32{c}, &buf) catch return;
|
||||
const bytes = input.ucs32_to_utf8(&[_]u32{c}, &buf) catch return;
|
||||
command.executeName(cmd, command.fmt(.{buf[0..bytes]})) catch {};
|
||||
command.executeName("exit_mini_mode", .{}) catch {};
|
||||
}
|
||||
|
@ -104,7 +101,7 @@ const cmds = struct {
|
|||
if (!try ctx.args.match(.{tp.extract(&code_point)}))
|
||||
return error.InvalidArgument;
|
||||
var buf: [6]u8 = undefined;
|
||||
const bytes = ucs32_to_utf8(&[_]u32{code_point}, &buf) catch return error.InvalidArgument;
|
||||
const bytes = input.ucs32_to_utf8(&[_]u32{code_point}, &buf) catch return error.InvalidArgument;
|
||||
const cmd = switch (self.direction) {
|
||||
.left => switch (self.operation) {
|
||||
.move => "move_to_char_left",
|
||||
|
|
|
@ -5,11 +5,8 @@ const cbor = @import("cbor");
|
|||
const root = @import("root");
|
||||
|
||||
const Plane = @import("renderer").Plane;
|
||||
const key = @import("renderer").input.key;
|
||||
const mod = @import("renderer").input.modifier;
|
||||
const event_type = @import("renderer").input.event_type;
|
||||
const input = @import("input");
|
||||
const keybind = @import("keybind");
|
||||
const ucs32_to_utf8 = @import("renderer").ucs32_to_utf8;
|
||||
const project_manager = @import("project_manager");
|
||||
const command = @import("command");
|
||||
const EventHandler = @import("EventHandler");
|
||||
|
@ -243,7 +240,7 @@ fn delete_code_point(self: *Self) !void {
|
|||
|
||||
fn insert_code_point(self: *Self, c: u32) !void {
|
||||
var buf: [6]u8 = undefined;
|
||||
const bytes = try ucs32_to_utf8(&[_]u32{c}, &buf);
|
||||
const bytes = try input.ucs32_to_utf8(&[_]u32{c}, &buf);
|
||||
try self.inputbox.text.appendSlice(buf[0..bytes]);
|
||||
self.inputbox.cursor = self.inputbox.text.items.len;
|
||||
return self.start_query();
|
||||
|
|
|
@ -5,11 +5,8 @@ const cbor = @import("cbor");
|
|||
const fuzzig = @import("fuzzig");
|
||||
|
||||
const Plane = @import("renderer").Plane;
|
||||
const key = @import("renderer").input.key;
|
||||
const mod = @import("renderer").input.modifier;
|
||||
const event_type = @import("renderer").input.event_type;
|
||||
const input = @import("input");
|
||||
const keybind = @import("keybind");
|
||||
const ucs32_to_utf8 = @import("renderer").ucs32_to_utf8;
|
||||
const command = @import("command");
|
||||
const EventHandler = @import("EventHandler");
|
||||
|
||||
|
@ -315,7 +312,7 @@ pub fn Create(options: type) type {
|
|||
|
||||
fn insert_code_point(self: *Self, c: u32) !void {
|
||||
var buf: [6]u8 = undefined;
|
||||
const bytes = try ucs32_to_utf8(&[_]u32{c}, &buf);
|
||||
const bytes = try input.ucs32_to_utf8(&[_]u32{c}, &buf);
|
||||
try self.inputbox.text.appendSlice(buf[0..bytes]);
|
||||
self.inputbox.cursor = self.inputbox.text.items.len;
|
||||
self.view_pos = 0;
|
||||
|
|
|
@ -3,8 +3,7 @@ const tp = @import("thespian");
|
|||
const tracy = @import("tracy");
|
||||
|
||||
const Plane = @import("renderer").Plane;
|
||||
const key = @import("renderer").input.key;
|
||||
const event_type = @import("renderer").input.event_type;
|
||||
const input = @import("input");
|
||||
const EventHandler = @import("EventHandler");
|
||||
|
||||
const Widget = @import("Widget.zig");
|
||||
|
@ -64,21 +63,21 @@ pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {
|
|||
var y: i32 = undefined;
|
||||
var ypx: i32 = undefined;
|
||||
|
||||
if (try m.match(.{ "B", event_type.PRESS, key.BUTTON1, tp.any, tp.any, tp.extract(&y), tp.any, tp.extract(&ypx) })) {
|
||||
if (try m.match(.{ "B", input.event.press, @intFromEnum(input.mouse.BUTTON1), tp.any, tp.any, tp.extract(&y), tp.any, tp.extract(&ypx) })) {
|
||||
self.active = true;
|
||||
self.move_to(y, ypx);
|
||||
return true;
|
||||
} else if (try m.match(.{ "B", event_type.RELEASE, tp.more })) {
|
||||
} else if (try m.match(.{ "B", input.event.release, tp.more })) {
|
||||
self.active = false;
|
||||
return true;
|
||||
} else if (try m.match(.{ "D", event_type.PRESS, key.BUTTON1, tp.any, tp.any, tp.extract(&y), tp.any, tp.extract(&ypx) })) {
|
||||
} else if (try m.match(.{ "D", input.event.press, @intFromEnum(input.mouse.BUTTON1), tp.any, tp.any, tp.extract(&y), tp.any, tp.extract(&ypx) })) {
|
||||
self.active = true;
|
||||
self.move_to(y, ypx);
|
||||
return true;
|
||||
} else if (try m.match(.{ "B", event_type.RELEASE, tp.more })) {
|
||||
} else if (try m.match(.{ "B", input.event.release, tp.more })) {
|
||||
self.active = false;
|
||||
return true;
|
||||
} else if (try m.match(.{ "D", event_type.RELEASE, tp.more })) {
|
||||
} else if (try m.match(.{ "D", input.event.release, tp.more })) {
|
||||
self.active = false;
|
||||
return true;
|
||||
} else if (try m.match(.{ "H", tp.extract(&self.hover) })) {
|
||||
|
|
|
@ -4,9 +4,7 @@ const tp = @import("thespian");
|
|||
const tracy = @import("tracy");
|
||||
|
||||
const Plane = @import("renderer").Plane;
|
||||
const utils = @import("renderer").input.utils;
|
||||
const key_ = @import("renderer").input.key;
|
||||
const event_type = @import("renderer").input.event_type;
|
||||
const input = @import("input");
|
||||
const command = @import("command");
|
||||
const EventHandler = @import("EventHandler");
|
||||
|
||||
|
@ -24,7 +22,7 @@ hover: bool = false,
|
|||
|
||||
keys: [history]Key = [_]Key{.{}} ** history,
|
||||
|
||||
const Key = struct { id: u32 = 0, mod: u32 = 0 };
|
||||
const Key = struct { id: input.Key = 0, mod: input.ModSet = .{} };
|
||||
|
||||
const Self = @This();
|
||||
|
||||
|
@ -63,15 +61,15 @@ fn render_active(self: *Self) bool {
|
|||
return true;
|
||||
if (c > 0)
|
||||
_ = self.plane.putstr(" ") catch {};
|
||||
if (utils.isSuper(k.mod))
|
||||
if (k.mod.super)
|
||||
_ = self.plane.putstr("H-") catch {};
|
||||
if (utils.isCtrl(k.mod))
|
||||
if (k.mod.ctrl)
|
||||
_ = self.plane.putstr("C-") catch {};
|
||||
if (utils.isShift(k.mod))
|
||||
if (k.mod.shift)
|
||||
_ = self.plane.putstr("S-") catch {};
|
||||
if (utils.isAlt(k.mod))
|
||||
if (k.mod.alt)
|
||||
_ = self.plane.putstr("A-") catch {};
|
||||
_ = self.plane.print("{s}", .{utils.key_id_string(k.id)}) catch {};
|
||||
_ = self.plane.print("{s}", .{input.utils.key_id_string(k.id)}) catch {};
|
||||
c += 1;
|
||||
}
|
||||
return true;
|
||||
|
@ -144,7 +142,7 @@ fn unset_nkey(self: *Self, key: Key) void {
|
|||
fn unset_key_all(self: *Self) void {
|
||||
for (0..self.keys.len) |i| {
|
||||
self.keys[i].id = 0;
|
||||
self.keys[i].mod = 0;
|
||||
self.keys[i].mod = .{};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,17 +153,17 @@ fn set_key(self: *Self, key: Key, val: bool) void {
|
|||
}
|
||||
|
||||
pub fn listen(self: *Self, _: tp.pid_ref, m: tp.message) tp.result {
|
||||
var key: u32 = 0;
|
||||
var mod: u32 = 0;
|
||||
if (try m.match(.{ "I", event_type.PRESS, tp.extract(&key), tp.any, tp.any, tp.extract(&mod), tp.more })) {
|
||||
self.set_key(.{ .id = key, .mod = mod }, true);
|
||||
} else if (try m.match(.{ "I", event_type.RELEASE, tp.extract(&key), tp.any, tp.any, tp.extract(&mod), tp.more })) {
|
||||
self.set_key(.{ .id = key, .mod = mod }, false);
|
||||
var key: input.Key = 0;
|
||||
var mod: input.Mods = 0;
|
||||
if (try m.match(.{ "I", input.event.press, tp.extract(&key), tp.any, tp.any, tp.extract(&mod), tp.more })) {
|
||||
self.set_key(.{ .id = key, .mod = @bitCast(mod) }, true);
|
||||
} else if (try m.match(.{ "I", input.event.release, tp.extract(&key), tp.any, tp.any, tp.extract(&mod), tp.more })) {
|
||||
self.set_key(.{ .id = key, .mod = @bitCast(mod) }, false);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {
|
||||
if (try m.match(.{ "B", event_type.PRESS, key_.BUTTON1, tp.any, tp.any, tp.any, tp.any, tp.any })) {
|
||||
if (try m.match(.{ "B", input.event.press, @intFromEnum(input.mouse.BUTTON1), tp.any, tp.any, tp.any, tp.any, tp.any })) {
|
||||
command.executeName("toggle_inputview", .{}) catch {};
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -4,9 +4,7 @@ const tp = @import("thespian");
|
|||
const tracy = @import("tracy");
|
||||
|
||||
const Plane = @import("renderer").Plane;
|
||||
const key = @import("renderer").input.key;
|
||||
const event_type = @import("renderer").input.event_type;
|
||||
const utils = @import("renderer").input.utils;
|
||||
const input = @import("input");
|
||||
const command = @import("command");
|
||||
const EventHandler = @import("EventHandler");
|
||||
|
||||
|
@ -14,9 +12,7 @@ const Widget = @import("../Widget.zig");
|
|||
const tui = @import("../tui.zig");
|
||||
|
||||
plane: Plane,
|
||||
ctrl: bool = false,
|
||||
shift: bool = false,
|
||||
alt: bool = false,
|
||||
mods: input.ModSet = .{},
|
||||
hover: bool = false,
|
||||
|
||||
const Self = @This();
|
||||
|
@ -54,9 +50,9 @@ pub fn render(self: *Self, theme: *const Widget.Theme) bool {
|
|||
self.plane.home();
|
||||
|
||||
_ = self.plane.print(" {s}{s}{s} ", .{
|
||||
mode(self.ctrl, "Ⓒ ", "🅒 "),
|
||||
mode(self.shift, "Ⓢ ", "🅢 "),
|
||||
mode(self.alt, "Ⓐ ", "🅐 "),
|
||||
mode(self.mods.ctrl, "Ⓒ ", "🅒 "),
|
||||
mode(self.mods.shift, "Ⓢ ", "🅢 "),
|
||||
mode(self.mods.alt, "Ⓐ ", "🅐 "),
|
||||
}) catch {};
|
||||
return false;
|
||||
}
|
||||
|
@ -70,16 +66,14 @@ fn render_modifier(self: *Self, state: bool, off: [:0]const u8, on: [:0]const u8
|
|||
}
|
||||
|
||||
pub fn listen(self: *Self, _: tp.pid_ref, m: tp.message) tp.result {
|
||||
var mod: u32 = 0;
|
||||
if (try m.match(.{ "I", tp.any, tp.any, tp.any, tp.any, tp.extract(&mod), tp.more })) {
|
||||
self.ctrl = utils.isCtrl(mod);
|
||||
self.shift = utils.isShift(mod);
|
||||
self.alt = utils.isAlt(mod);
|
||||
var mods: input.Mods = 0;
|
||||
if (try m.match(.{ "I", tp.any, tp.any, tp.any, tp.any, tp.extract(&mods), tp.more })) {
|
||||
self.mods = @bitCast(mods);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {
|
||||
if (try m.match(.{ "B", event_type.PRESS, key.BUTTON1, tp.any, tp.any, tp.any, tp.any, tp.any })) {
|
||||
if (try m.match(.{ "B", input.event.press, @intFromEnum(input.mouse.BUTTON1), tp.any, tp.any, tp.any, tp.any, tp.any })) {
|
||||
command.executeName("toggle_inputview", .{}) catch {};
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -971,3 +971,15 @@ fn set_terminal_style(self: *Self) void {
|
|||
self.rdr.set_terminal_cursor_color(self.theme.editor_cursor.bg.?);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn translate_cursor_shape(in: keybind.CursorShape) renderer.CursorShape {
|
||||
return switch (in) {
|
||||
.default => .default,
|
||||
.block_blink => .block_blink,
|
||||
.block => .block,
|
||||
.underline_blink => .underline_blink,
|
||||
.underline => .underline,
|
||||
.beam_blink => .beam_blink,
|
||||
.beam => .beam,
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue