gtk: implement quick-terminal-autohide

This commit is contained in:
Leah Amelia Chen
2025-03-05 21:51:35 +01:00
parent 58b0434092
commit 44d4990eb2
2 changed files with 17 additions and 2 deletions

View File

@ -80,6 +80,7 @@ pub const DerivedConfig = struct {
gtk_toolbar_style: configpkg.Config.GtkToolbarStyle,
quick_terminal_position: configpkg.Config.QuickTerminalPosition,
quick_terminal_autohide: bool,
maximize: bool,
fullscreen: bool,
@ -97,6 +98,7 @@ pub const DerivedConfig = struct {
.gtk_toolbar_style = config.@"gtk-toolbar-style",
.quick_terminal_position = config.@"quick-terminal-position",
.quick_terminal_autohide = config.@"quick-terminal-autohide",
.maximize = config.maximize,
.fullscreen = config.fullscreen,
@ -246,6 +248,7 @@ pub fn init(self: *Window, app: *App) !void {
_ = c.g_signal_connect_data(self.window, "notify::maximized", c.G_CALLBACK(&gtkWindowNotifyMaximized), self, null, c.G_CONNECT_DEFAULT);
_ = c.g_signal_connect_data(self.window, "notify::fullscreened", c.G_CALLBACK(&gtkWindowNotifyFullscreened), self, null, c.G_CONNECT_DEFAULT);
_ = c.g_signal_connect_data(self.window, "notify::is-active", c.G_CALLBACK(&gtkWindowNotifyIsActive), self, null, c.G_CONNECT_DEFAULT);
// If Adwaita is enabled and is older than 1.4.0 we don't have the tab overview and so we
// need to stick the headerbar into the content box.
@ -728,6 +731,20 @@ fn gtkWindowNotifyFullscreened(
};
}
fn gtkWindowNotifyIsActive(
_: *c.GObject,
_: *c.GParamSpec,
ud: ?*anyopaque,
) callconv(.C) void {
const self = userdataSelf(ud orelse return);
if (!self.isQuickTerminal()) return;
// Hide when we're unfocused
if (self.config.quick_terminal_autohide and c.gtk_window_is_active(self.window) == 0) {
self.toggleVisibility();
}
}
// Note: we MUST NOT use the GtkButton parameter because gtkActionNewTab
// sends an undefined value.
fn gtkTabNewClick(_: *c.GtkButton, ud: ?*anyopaque) callconv(.C) void {

View File

@ -1677,8 +1677,6 @@ keybind: Keybinds = .{},
/// Automatically hide the quick terminal when focus shifts to another window.
/// Set it to false for the quick terminal to remain open even when it loses focus.
///
/// Only implemented on macOS.
@"quick-terminal-autohide": bool = true,
/// This configuration option determines the behavior of the quick terminal