Skip to content

Commit

Permalink
gtk: add apprt action and keybinding for toggling top menu
Browse files Browse the repository at this point in the history
  • Loading branch information
jcollie committed Jan 15, 2025
1 parent a560098 commit 66e73c8
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/ghostty.h
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ typedef enum {
GHOSTTY_ACTION_TOGGLE_WINDOW_DECORATIONS,
GHOSTTY_ACTION_TOGGLE_QUICK_TERMINAL,
GHOSTTY_ACTION_TOGGLE_VISIBILITY,
GHOSTTY_ACTION_TOGGLE_TOP_MENU,
GHOSTTY_ACTION_MOVE_TAB,
GHOSTTY_ACTION_GOTO_TAB,
GHOSTTY_ACTION_GOTO_SPLIT,
Expand Down
6 changes: 6 additions & 0 deletions src/Surface.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4211,6 +4211,12 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool
.toggle,
),

.toggle_top_menu => try self.rt_app.performAction(
.{ .surface = self },
.toggle_top_menu,
{},
),

.select_all => {
const sel = self.io.terminal.screen.selectAll();
if (sel) |s| {
Expand Down
4 changes: 4 additions & 0 deletions src/apprt/action.zig
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ pub const Action = union(Key) {
/// Toggle the visibility of all Ghostty terminal windows.
toggle_visibility,

/// Toggle whether the top menu is shown.
toggle_top_menu,

/// Moves a tab by a relative offset.
///
/// Adjusts the tab position based on `offset` (e.g., -1 for left, +1
Expand Down Expand Up @@ -240,6 +243,7 @@ pub const Action = union(Key) {
toggle_window_decorations,
toggle_quick_terminal,
toggle_visibility,
toggle_top_menu,
move_tab,
goto_tab,
goto_split,
Expand Down
1 change: 1 addition & 0 deletions src/apprt/glfw.zig
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ pub const App = struct {
.toggle_window_decorations,
.toggle_quick_terminal,
.toggle_visibility,
.toggle_top_menu,
.goto_tab,
.move_tab,
.inspector,
Expand Down
16 changes: 16 additions & 0 deletions src/apprt/gtk/App.zig
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ pub fn performAction(
}),
.toggle_maximize => self.toggleMaximize(target),
.toggle_fullscreen => self.toggleFullscreen(target, value),
.toggle_top_menu => self.toggleTopMenu(target),

.new_tab => try self.newTab(target),
.close_tab => try self.closeTab(target),
Expand Down Expand Up @@ -783,6 +784,21 @@ fn toggleWindowDecorations(
}
}

fn toggleTopMenu(_: *App, target: apprt.Target) void {
switch (target) {
.app => {},
.surface => |v| {
const window = v.rt_surface.container.window() orelse {
log.info(
"toggleTopMenu invalid for container={s}",
.{@tagName(v.rt_surface.container)},
);
return;
};
window.toggleTopMenu();
},
}
}
fn quitTimer(self: *App, mode: apprt.action.QuitTimer) void {
switch (mode) {
.start => self.startQuitTimer(),
Expand Down
7 changes: 6 additions & 1 deletion src/apprt/gtk/Window.zig
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ pub fn init(self: *Window, app: *App) !void {
self.top_menu_revealer = @ptrCast(@alignCast(c.gtk_revealer_new()));
c.gtk_revealer_set_child(self.top_menu_revealer, self.top_menu.asWidget());
c.gtk_revealer_set_transition_type(self.top_menu_revealer, c.GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN);
c.gtk_revealer_set_reveal_child(self.top_menu_revealer, 1);

// Setup our notebook
self.notebook.init();
Expand Down Expand Up @@ -643,6 +642,12 @@ pub fn toggleWindowDecorations(self: *Window) void {
self.updateConfig(&self.app.config) catch {};
}

/// Toggle top menu.
pub fn toggleTopMenu(self: *Window) void {
const is_revealed = c.gtk_revealer_get_reveal_child(self.top_menu_revealer) != 0;
c.gtk_revealer_set_reveal_child(self.top_menu_revealer, @intFromBool(!is_revealed));
}

/// Grabs focus on the currently selected tab.
pub fn focusCurrentTab(self: *Window) void {
const tab = self.notebook.currentTab() orelse return;
Expand Down
5 changes: 5 additions & 0 deletions src/input/Binding.zig
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,10 @@ pub const Action = union(enum) {
/// This currently only works on macOS.
toggle_visibility: void,

/// Show/hide the application menu that appears below the titlebar and above
/// the tab bar.
toggle_top_menu: void,

/// Quit ghostty.
quit: void,

Expand Down Expand Up @@ -758,6 +762,7 @@ pub const Action = union(enum) {
.goto_tab,
.move_tab,
.toggle_tab_overview,
.toggle_top_menu,
.new_split,
.goto_split,
.toggle_split_zoom,
Expand Down

0 comments on commit 66e73c8

Please sign in to comment.