mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-18 13:30:29 +00:00
start input, its broken but we're getting there
This commit is contained in:
11
src/App.zig
11
src/App.zig
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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] });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user