mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 08:46:08 +03:00
apprt: couple more easy callbacks
This commit is contained in:
@ -394,8 +394,6 @@ pub fn create(alloc: Allocator, app: *App, config: *const Config) !*Window {
|
||||
// }, .{ .width = null, .height = null });
|
||||
|
||||
// Setup our callbacks and user data
|
||||
winsys.window.setFocusCallback(focusCallback);
|
||||
winsys.window.setRefreshCallback(refreshCallback);
|
||||
winsys.window.setScrollCallback(scrollCallback);
|
||||
winsys.window.setCursorPosCallback(cursorPosCallback);
|
||||
winsys.window.setMouseButtonCallback(mouseButtonCallback);
|
||||
@ -1036,29 +1034,19 @@ pub fn keyCallback(
|
||||
}
|
||||
}
|
||||
|
||||
fn focusCallback(window: glfw.Window, focused: bool) void {
|
||||
const tracy = trace(@src());
|
||||
defer tracy.end();
|
||||
|
||||
const win = window.getUserPointer(Window) orelse return;
|
||||
|
||||
pub fn focusCallback(self: *Window, focused: bool) !void {
|
||||
// Notify our render thread of the new state
|
||||
_ = win.renderer_thread.mailbox.push(.{
|
||||
_ = self.renderer_thread.mailbox.push(.{
|
||||
.focus = focused,
|
||||
}, .{ .forever = {} });
|
||||
|
||||
// Schedule render which also drains our mailbox
|
||||
win.queueRender() catch unreachable;
|
||||
try self.queueRender();
|
||||
}
|
||||
|
||||
fn refreshCallback(window: glfw.Window) void {
|
||||
const tracy = trace(@src());
|
||||
defer tracy.end();
|
||||
|
||||
const win = window.getUserPointer(Window) orelse return;
|
||||
|
||||
pub fn refreshCallback(self: *Window) !void {
|
||||
// The point of this callback is to schedule a render, so do that.
|
||||
win.queueRender() catch unreachable;
|
||||
try self.queueRender();
|
||||
}
|
||||
|
||||
fn scrollCallback(window: glfw.Window, xoff: f64, yoff: f64) void {
|
||||
|
@ -89,6 +89,8 @@ pub const Window = struct {
|
||||
win.setSizeCallback(sizeCallback);
|
||||
win.setCharCallback(charCallback);
|
||||
win.setKeyCallback(keyCallback);
|
||||
win.setFocusCallback(focusCallback);
|
||||
win.setRefreshCallback(refreshCallback);
|
||||
|
||||
// Build our result
|
||||
return Window{
|
||||
@ -350,4 +352,26 @@ pub const Window = struct {
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
fn focusCallback(window: glfw.Window, focused: bool) void {
|
||||
const tracy = trace(@src());
|
||||
defer tracy.end();
|
||||
|
||||
const core_win = window.getUserPointer(CoreWindow) orelse return;
|
||||
core_win.focusCallback(focused) catch |err| {
|
||||
log.err("error in focus callback err={}", .{err});
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
fn refreshCallback(window: glfw.Window) void {
|
||||
const tracy = trace(@src());
|
||||
defer tracy.end();
|
||||
|
||||
const core_win = window.getUserPointer(CoreWindow) orelse return;
|
||||
core_win.refreshCallback() catch |err| {
|
||||
log.err("error in refresh callback err={}", .{err});
|
||||
return;
|
||||
};
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user