start input, its broken but we're getting there

This commit is contained in:
Mitchell Hashimoto
2023-02-17 22:12:03 -08:00
parent 074664398a
commit 573b163636
6 changed files with 199 additions and 5 deletions

View File

@@ -11,6 +11,7 @@ const build_config = @import("build_config.zig");
const apprt = @import("apprt.zig");
const Window = @import("Window.zig");
const tracy = @import("tracy");
const input = @import("input.zig");
const Config = @import("config.zig").Config;
const BlockingQueue = @import("./blocking_queue.zig").BlockingQueue;
const renderer = @import("renderer.zig");
@@ -412,4 +413,14 @@ pub const CAPI = struct {
export fn ghostty_surface_set_content_scale(win: *Window, x: f64, y: f64) void {
win.window.updateContentScale(x, y);
}
/// Tell the surface that it needs to schedule a render
export fn ghostty_surface_key(
win: *Window,
action: input.Action,
key: input.Key,
mods: input.Mods,
) void {
win.window.keyCallback(action, key, mods);
}
};

View File

@@ -10,6 +10,7 @@ const assert = std.debug.assert;
const Allocator = std.mem.Allocator;
const objc = @import("objc");
const apprt = @import("../apprt.zig");
const input = @import("../input.zig");
const CoreApp = @import("../App.zig");
const CoreWindow = @import("../Window.zig");
@@ -143,4 +144,16 @@ pub const Window = struct {
return;
};
}
pub fn keyCallback(
self: *const Window,
action: input.Action,
key: input.Key,
mods: input.Mods,
) void {
self.core_win.keyCallback(action, key, mods) catch |err| {
log.err("error in key callback err={}", .{err});
return;
};
}
};

View File

@@ -3,7 +3,7 @@ const Allocator = std.mem.Allocator;
/// A bitmask for all key modifiers. This is taken directly from the
/// GLFW representation, but we use this generically.
pub const Mods = packed struct {
pub const Mods = packed struct(u8) {
shift: bool = false,
ctrl: bool = false,
alt: bool = false,
@@ -11,10 +11,21 @@ pub const Mods = packed struct {
caps_lock: bool = false,
num_lock: bool = false,
_padding: u2 = 0,
// For our own understanding
test {
const testing = std.testing;
try testing.expectEqual(@bitCast(u8, Mods{}), @as(u8, 0b0));
try testing.expectEqual(
@bitCast(u8, Mods{ .shift = true }),
@as(u8, 0b0000_0001),
);
}
};
/// The action associated with an input event.
pub const Action = enum {
/// The action associated with an input event. This is backed by a c_int
/// so that we can use the enum as-is for our embedding API.
pub const Action = enum(c_int) {
release,
press,
repeat,
@@ -25,7 +36,9 @@ pub const Action = enum {
/// this only needs to accomodate what maps to a key. If a key is not bound
/// to anything and the key can be mapped to a printable character, then that
/// unicode character is sent directly to the pty.
pub const Key = enum {
///
/// This is backed by a c_int so we can use this as-is for our embedding API.
pub const Key = enum(c_int) {
invalid,
// a-z

View File

@@ -529,7 +529,7 @@ const ReadThread = struct {
return;
};
// log.info("DATA: {d}", .{n});
log.info("DATA: {d}", .{n});
@call(.always_inline, process, .{ ev, buf[0..n] });
}
}