mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
embedded wakeup calls callback
This commit is contained in:
@ -67,8 +67,8 @@ class GhosttyState: ObservableObject {
|
||||
// Create our "runtime" config. The "runtime" is the configuration that ghostty
|
||||
// uses to interface with the application runtime environment.
|
||||
var runtime_cfg = ghostty_runtime_config_s(
|
||||
userdata: nil,
|
||||
wakeup_cb: { userdata in GhosttyState.wakeup() })
|
||||
userdata: Unmanaged.passUnretained(self).toOpaque(),
|
||||
wakeup_cb: { userdata in GhosttyState.wakeup(userdata) })
|
||||
|
||||
// Create the ghostty app.
|
||||
guard let app = ghostty_app_new(&runtime_cfg, cfg) else {
|
||||
@ -81,8 +81,19 @@ class GhosttyState: ObservableObject {
|
||||
self.readiness = .ready
|
||||
}
|
||||
|
||||
static func wakeup() {
|
||||
// TODO
|
||||
func appTick() {
|
||||
guard let app = self.app else { return }
|
||||
ghostty_app_tick(app)
|
||||
}
|
||||
|
||||
static func wakeup(_ userdata: UnsafeMutableRawPointer?) {
|
||||
let state = Unmanaged<GhosttyState>.fromOpaque(userdata!).takeUnretainedValue()
|
||||
|
||||
// Wakeup can be called from any thread so we schedule the app tick
|
||||
// from the main thread. There is probably some improvements we can make
|
||||
// to coalesce multiple ticks but I don't think it matters from a performance
|
||||
// standpoint since we don't do this much.
|
||||
DispatchQueue.main.async { state.appTick() }
|
||||
}
|
||||
|
||||
deinit {
|
||||
|
@ -31,8 +31,10 @@ pub const App = struct {
|
||||
wakeup: *const fn (?*anyopaque) callconv(.C) void,
|
||||
};
|
||||
|
||||
pub fn init(_: Options) !App {
|
||||
return .{};
|
||||
opts: Options,
|
||||
|
||||
pub fn init(opts: Options) !App {
|
||||
return .{ .opts = opts };
|
||||
}
|
||||
|
||||
pub fn terminate(self: App) void {
|
||||
@ -40,7 +42,7 @@ pub const App = struct {
|
||||
}
|
||||
|
||||
pub fn wakeup(self: App) !void {
|
||||
_ = self;
|
||||
self.opts.wakeup(self.opts.userdata);
|
||||
}
|
||||
|
||||
pub fn wait(self: App) !void {
|
||||
|
Reference in New Issue
Block a user