Skip to content

Commit

Permalink
feat: add bring_all_to_front keybinding
Browse files Browse the repository at this point in the history
  • Loading branch information
dmehala committed Jan 12, 2025
1 parent caddf59 commit 75f2bd3
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/ghostty.h
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ typedef enum {
GHOSTTY_ACTION_COLOR_CHANGE,
GHOSTTY_ACTION_RELOAD_CONFIG,
GHOSTTY_ACTION_CONFIG_CHANGE,
GHOSTTY_ACTION_BRING_ALL_TO_FRONT,
} ghostty_action_tag_e;

typedef union {
Expand Down
12 changes: 12 additions & 0 deletions macos/Sources/App/macOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class AppDelegate: NSObject,

@IBOutlet private var menuToggleVisibility: NSMenuItem?
@IBOutlet private var menuToggleFullScreen: NSMenuItem?
@IBOutlet private var menuBringAllToFront: NSMenuItem?
@IBOutlet private var menuZoomSplit: NSMenuItem?
@IBOutlet private var menuPreviousSplit: NSMenuItem?
@IBOutlet private var menuNextSplit: NSMenuItem?
Expand Down Expand Up @@ -383,6 +384,7 @@ class AppDelegate: NSObject,
syncMenuShortcut(config, action: "inspector:toggle", menuItem: self.menuTerminalInspector)

syncMenuShortcut(config, action: "toggle_secure_input", menuItem: self.menuSecureInput)
syncMenuShortcut(config, action: "bring_all_to_front", menuItem: self.menuBringAllToFront)

// This menu item is NOT synced with the configuration because it disables macOS
// global fullscreen keyboard shortcut. The shortcut in the Ghostty config will continue
Expand Down Expand Up @@ -727,6 +729,16 @@ class AppDelegate: NSObject,
self.hiddenWindows.forEach { $0.value?.orderFrontRegardless() }
self.hiddenWindows = []
}

@IBAction func bringAllToFront(_ sender: Any) {
NSApp.activate(ignoringOtherApps: true)

for window in NSApp.windows.filter({ $0.windowController is BaseTerminalController }) {
if window.isVisible {
window.makeKeyAndOrderFront(nil)
}
}
}

private struct DerivedConfig {
let initialWindow: Bool
Expand Down
1 change: 1 addition & 0 deletions macos/Sources/App/macOS/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customObject id="bbz-4X-AYv" userLabel="AppDelegate" customClass="AppDelegate" customModule="Ghostty" customModuleProvider="target">
<connections>
<outlet property="menuBringAllToFront" destination="LE2-aR-0XJ" id="AP9-oK-60V"/>
<outlet property="menuCheckForUpdates" destination="GEA-5y-yzH" id="0nV-Tf-nJQ"/>
<outlet property="menuClose" destination="DVo-aG-piG" id="R3t-0C-aSU"/>
<outlet property="menuCloseAllWindows" destination="yKr-Vi-Yqw" id="Zet-Ir-zbm"/>
Expand Down
12 changes: 12 additions & 0 deletions macos/Sources/Ghostty/Ghostty.App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,9 @@ extension Ghostty {
fallthrough
case GHOSTTY_ACTION_QUIT_TIMER:
Ghostty.logger.info("known but unimplemented action action=\(action.tag.rawValue)")

case GHOSTTY_ACTION_BRING_ALL_TO_FRONT:
bringAllToFront(app, target: target)

default:
Ghostty.logger.warning("unknown action action=\(action.tag.rawValue)")
Expand Down Expand Up @@ -712,6 +715,15 @@ extension Ghostty {
guard let appDelegate = NSApplication.shared.delegate as? AppDelegate else { return }
appDelegate.toggleVisibility(self)
}

private static func bringAllToFront(
_ app: ghostty_app_t,
target: ghostty_target_s
) {
guard let appDelegate = NSApplication.shared.delegate as? AppDelegate else { return }
appDelegate.bringAllToFront(self)
}


private static func moveTab(
_ app: ghostty_app_t,
Expand Down
1 change: 1 addition & 0 deletions src/App.zig
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ pub fn performAction(
.close_all_windows => try rt_app.performAction(.app, .close_all_windows, {}),
.toggle_quick_terminal => try rt_app.performAction(.app, .toggle_quick_terminal, {}),
.toggle_visibility => try rt_app.performAction(.app, .toggle_visibility, {}),
.bring_all_to_front => try rt_app.performAction(.app, .bring_all_to_front, {}),
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/apprt/action.zig
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ pub const Action = union(Key) {
/// for changes.
config_change: ConfigChange,

/// Bring all ghostty windows in front of all other windows.
bring_all_to_front,

/// Sync with: ghostty_action_tag_e
pub const Key = enum(c_int) {
quit,
Expand Down Expand Up @@ -262,6 +265,7 @@ pub const Action = union(Key) {
color_change,
reload_config,
config_change,
bring_all_to_front,
};

/// Sync with: ghostty_action_u
Expand Down
1 change: 1 addition & 0 deletions src/apprt/glfw.zig
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ pub const App = struct {
.color_change,
.pwd,
.config_change,
.bring_all_to_front,
=> log.info("unimplemented action={}", .{action}),
}
}
Expand Down
1 change: 1 addition & 0 deletions src/apprt/gtk/App.zig
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ pub fn performAction(
.render_inspector,
.renderer_health,
.color_change,
.bring_all_to_front,
=> log.warn("unimplemented action={}", .{action}),
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/input/Binding.zig
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,9 @@ pub const Action = union(enum) {
///
crash: CrashThread,

/// Bring all ghostty windows in front of all other windows.
bring_all_to_front: void,

pub const Key = @typeInfo(Action).Union.tag_type.?;

pub const CrashThread = enum {
Expand Down Expand Up @@ -702,6 +705,7 @@ pub const Action = union(enum) {
.quit,
.toggle_quick_terminal,
.toggle_visibility,
.bring_all_to_front,
=> .app,

// These are app but can be special-cased in a surface context.
Expand Down

0 comments on commit 75f2bd3

Please sign in to comment.