fix: merge vaxis and win32 event handling interfaces
This commit is contained in:
parent
1fdb5f240b
commit
9047439315
3 changed files with 11 additions and 19 deletions
|
@ -146,7 +146,12 @@ pub fn leave_alternate_screen(self: *Self) void {
|
|||
self.vx.exitAltScreen() catch {};
|
||||
}
|
||||
|
||||
pub fn process_input_event(self: *Self, input_: []const u8, text: ?[]const u8) !void {
|
||||
pub fn process_renderer_event(self: *Self, msg: []const u8) !void {
|
||||
var input_: []const u8 = undefined;
|
||||
var text_: []const u8 = undefined;
|
||||
if (!try cbor.match(msg, .{ "RDR", cbor.extract(&input_), cbor.extract(&text_) }))
|
||||
return error.InvalidRendererEvent;
|
||||
const text = if (text_.len > 0) text_ else null;
|
||||
const event = std.mem.bytesAsValue(vaxis.Event, input_);
|
||||
switch (event.*) {
|
||||
.key_press => |key__| {
|
||||
|
@ -493,7 +498,7 @@ const Loop = struct {
|
|||
},
|
||||
else => {},
|
||||
}
|
||||
self.pid.send(.{ "VXS", std.mem.asBytes(&event), text }) catch @panic("send VXS event failed");
|
||||
self.pid.send(.{ "RDR", std.mem.asBytes(&event), text }) catch @panic("send RDR event failed");
|
||||
if (free_text)
|
||||
self.vaxis.opts.system_clipboard_allocator.?.free(text);
|
||||
}
|
||||
|
|
|
@ -149,7 +149,7 @@ pub fn leave_alternate_screen(self: *Self) void {
|
|||
_ = self;
|
||||
@panic("todo");
|
||||
}
|
||||
pub fn process_gui_event(self: *Self, m: thespian.message) !void {
|
||||
pub fn process_renderer_event(self: *Self, m: thespian.message) !void {
|
||||
const Input = struct {
|
||||
kind: u8,
|
||||
codepoint: u21,
|
||||
|
@ -356,8 +356,3 @@ pub fn cursor_disable(self: *Self) void {
|
|||
_ = self;
|
||||
//@panic("todo");
|
||||
}
|
||||
pub fn ucs32_to_utf8(ucs32: []const u32, utf8: []u8) !usize {
|
||||
_ = ucs32;
|
||||
_ = utf8;
|
||||
@panic("todo");
|
||||
}
|
||||
|
|
|
@ -248,23 +248,14 @@ fn receive(self: *Self, from: tp.pid_ref, m: tp.message) tp.result {
|
|||
}
|
||||
|
||||
fn receive_safe(self: *Self, from: tp.pid_ref, m: tp.message) !void {
|
||||
var input: []const u8 = undefined;
|
||||
var text: []const u8 = undefined;
|
||||
if (try m.match(.{ "VXS", tp.extract(&input), tp.extract(&text) })) {
|
||||
try self.rdr.process_input_event(input, if (text.len > 0) text else null);
|
||||
if (try m.match(.{ "RDR", tp.more })) {
|
||||
try self.rdr.process_renderer_event(m.buf);
|
||||
try self.dispatch_flush_input_event();
|
||||
if (self.unrendered_input_events_count > 0 and !self.frame_clock_running)
|
||||
need_render();
|
||||
return;
|
||||
}
|
||||
|
||||
if (build_options.gui) {
|
||||
if (try m.match(.{ "GUI", tp.more })) {
|
||||
try self.rdr.process_gui_event(m);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (self.message_filters.filter(from, m) catch |e| return self.logger.err("filter", e))
|
||||
return;
|
||||
|
||||
|
@ -313,6 +304,7 @@ fn receive_safe(self: *Self, from: tp.pid_ref, m: tp.message) !void {
|
|||
return;
|
||||
}
|
||||
|
||||
var text: []const u8 = undefined;
|
||||
if (try m.match(.{ "system_clipboard", tp.extract(&text) })) {
|
||||
try self.dispatch_flush_input_event();
|
||||
return if (command.get_id("mini_mode_paste")) |id|
|
||||
|
|
Loading…
Add table
Reference in a new issue