From 44d4990eb21f8858454c365ddf87cb28d068d552 Mon Sep 17 00:00:00 2001 From: Leah Amelia Chen Date: Wed, 5 Mar 2025 21:51:35 +0100 Subject: [PATCH] gtk: implement quick-terminal-autohide --- src/apprt/gtk/Window.zig | 17 +++++++++++++++++ src/config/Config.zig | 2 -- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/apprt/gtk/Window.zig b/src/apprt/gtk/Window.zig index c77a15e03..6119e40dc 100644 --- a/src/apprt/gtk/Window.zig +++ b/src/apprt/gtk/Window.zig @@ -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(>kWindowNotifyMaximized), self, null, c.G_CONNECT_DEFAULT); _ = c.g_signal_connect_data(self.window, "notify::fullscreened", c.G_CALLBACK(>kWindowNotifyFullscreened), self, null, c.G_CONNECT_DEFAULT); + _ = c.g_signal_connect_data(self.window, "notify::is-active", c.G_CALLBACK(>kWindowNotifyIsActive), 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 { diff --git a/src/config/Config.zig b/src/config/Config.zig index d7539b971..2a76de1e8 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -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