mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
app keeps track of last focused surface
This commit is contained in:
17
src/App.zig
17
src/App.zig
@ -29,6 +29,10 @@ alloc: Allocator,
|
||||
/// The list of surfaces that are currently active.
|
||||
surfaces: SurfaceList,
|
||||
|
||||
/// The last focused surface. This surface may not be valid;
|
||||
/// you must always call hasSurface to validate it.
|
||||
focused_surface: ?*Surface = null,
|
||||
|
||||
/// The mailbox that can be used to send this thread messages. Note
|
||||
/// this is a blocking queue so if it is full you will get errors (or block).
|
||||
mailbox: Mailbox.Queue,
|
||||
@ -131,6 +135,7 @@ fn drainMailbox(self: *App, rt_app: *apprt.App) !void {
|
||||
.reload_config => try self.reloadConfig(rt_app),
|
||||
.new_window => |msg| try self.newWindow(rt_app, msg),
|
||||
.close => |surface| try self.closeSurface(rt_app, surface),
|
||||
.focus => |surface| try self.focusSurface(rt_app, surface),
|
||||
.quit => try self.setQuit(),
|
||||
.surface_message => |msg| try self.surfaceMessage(msg.surface, msg.message),
|
||||
.redraw_surface => |surface| try self.redrawSurface(rt_app, surface),
|
||||
@ -153,6 +158,13 @@ fn closeSurface(self: *App, rt_app: *apprt.App, surface: *Surface) !void {
|
||||
surface.close();
|
||||
}
|
||||
|
||||
fn focusSurface(self: *App, rt_app: *apprt.App, surface: *Surface) !void {
|
||||
_ = rt_app;
|
||||
|
||||
if (!self.hasSurface(surface)) return;
|
||||
self.focused_surface = surface;
|
||||
}
|
||||
|
||||
fn redrawSurface(self: *App, rt_app: *apprt.App, surface: *apprt.Surface) !void {
|
||||
if (!self.hasSurface(&surface.core_surface)) return;
|
||||
rt_app.redrawSurface(surface);
|
||||
@ -215,6 +227,11 @@ pub const Message = union(enum) {
|
||||
/// should close.
|
||||
close: *Surface,
|
||||
|
||||
/// The last focused surface. The app keeps track of this to
|
||||
/// enable "inheriting" various configurations from the last
|
||||
/// surface.
|
||||
focus: *Surface,
|
||||
|
||||
/// Quit
|
||||
quit: void,
|
||||
|
||||
|
@ -1224,6 +1224,13 @@ pub fn focusCallback(self: *Surface, focused: bool) !void {
|
||||
.focus = focused,
|
||||
}, .{ .forever = {} });
|
||||
|
||||
// Notify our app if we gained focus.
|
||||
if (focused) {
|
||||
_ = self.app_mailbox.push(.{
|
||||
.focus = self,
|
||||
}, .{ .forever = {} });
|
||||
}
|
||||
|
||||
// Schedule render which also drains our mailbox
|
||||
try self.queueRender();
|
||||
|
||||
|
Reference in New Issue
Block a user