mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
Introduce reset_window_size
keybinding and apprt action
Related to #6035 This implements the keybind/action portion of #5974 so that this can have a binding and so that other apprts can respond to this and implement it this way.
This commit is contained in:
@ -580,6 +580,7 @@ typedef enum {
|
|||||||
GHOSTTY_ACTION_TOGGLE_SPLIT_ZOOM,
|
GHOSTTY_ACTION_TOGGLE_SPLIT_ZOOM,
|
||||||
GHOSTTY_ACTION_PRESENT_TERMINAL,
|
GHOSTTY_ACTION_PRESENT_TERMINAL,
|
||||||
GHOSTTY_ACTION_SIZE_LIMIT,
|
GHOSTTY_ACTION_SIZE_LIMIT,
|
||||||
|
GHOSTTY_ACTION_RESET_WINDOW_SIZE,
|
||||||
GHOSTTY_ACTION_INITIAL_SIZE,
|
GHOSTTY_ACTION_INITIAL_SIZE,
|
||||||
GHOSTTY_ACTION_CELL_SIZE,
|
GHOSTTY_ACTION_CELL_SIZE,
|
||||||
GHOSTTY_ACTION_INSPECTOR,
|
GHOSTTY_ACTION_INSPECTOR,
|
||||||
|
@ -51,6 +51,7 @@ class AppDelegate: NSObject,
|
|||||||
@IBOutlet private var menuSelectSplitBelow: NSMenuItem?
|
@IBOutlet private var menuSelectSplitBelow: NSMenuItem?
|
||||||
@IBOutlet private var menuSelectSplitLeft: NSMenuItem?
|
@IBOutlet private var menuSelectSplitLeft: NSMenuItem?
|
||||||
@IBOutlet private var menuSelectSplitRight: NSMenuItem?
|
@IBOutlet private var menuSelectSplitRight: NSMenuItem?
|
||||||
|
@IBOutlet private var menuReturnToDefaultSize: NSMenuItem?
|
||||||
|
|
||||||
@IBOutlet private var menuIncreaseFontSize: NSMenuItem?
|
@IBOutlet private var menuIncreaseFontSize: NSMenuItem?
|
||||||
@IBOutlet private var menuDecreaseFontSize: NSMenuItem?
|
@IBOutlet private var menuDecreaseFontSize: NSMenuItem?
|
||||||
@ -386,6 +387,7 @@ class AppDelegate: NSObject,
|
|||||||
syncMenuShortcut(config, action: "resize_split:right,10", menuItem: self.menuMoveSplitDividerRight)
|
syncMenuShortcut(config, action: "resize_split:right,10", menuItem: self.menuMoveSplitDividerRight)
|
||||||
syncMenuShortcut(config, action: "resize_split:left,10", menuItem: self.menuMoveSplitDividerLeft)
|
syncMenuShortcut(config, action: "resize_split:left,10", menuItem: self.menuMoveSplitDividerLeft)
|
||||||
syncMenuShortcut(config, action: "equalize_splits", menuItem: self.menuEqualizeSplits)
|
syncMenuShortcut(config, action: "equalize_splits", menuItem: self.menuEqualizeSplits)
|
||||||
|
syncMenuShortcut(config, action: "reset_window_size", menuItem: self.menuReturnToDefaultSize)
|
||||||
|
|
||||||
syncMenuShortcut(config, action: "increase_font_size:1", menuItem: self.menuIncreaseFontSize)
|
syncMenuShortcut(config, action: "increase_font_size:1", menuItem: self.menuIncreaseFontSize)
|
||||||
syncMenuShortcut(config, action: "decrease_font_size:1", menuItem: self.menuDecreaseFontSize)
|
syncMenuShortcut(config, action: "decrease_font_size:1", menuItem: self.menuDecreaseFontSize)
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
<outlet property="menuQuit" destination="4sb-4s-VLi" id="qYN-S1-6UW"/>
|
<outlet property="menuQuit" destination="4sb-4s-VLi" id="qYN-S1-6UW"/>
|
||||||
<outlet property="menuReloadConfig" destination="KKH-XX-5py" id="Wvp-7J-wqX"/>
|
<outlet property="menuReloadConfig" destination="KKH-XX-5py" id="Wvp-7J-wqX"/>
|
||||||
<outlet property="menuResetFontSize" destination="Jah-MY-aLX" id="ger-qM-wrm"/>
|
<outlet property="menuResetFontSize" destination="Jah-MY-aLX" id="ger-qM-wrm"/>
|
||||||
|
<outlet property="menuReturnToDefaultSize" destination="Gbx-Vi-OGC" id="po9-qC-Iz6"/>
|
||||||
<outlet property="menuSecureInput" destination="oC6-w4-qI7" id="PCc-pe-Mda"/>
|
<outlet property="menuSecureInput" destination="oC6-w4-qI7" id="PCc-pe-Mda"/>
|
||||||
<outlet property="menuSelectAll" destination="q2h-lq-e4r" id="s98-r1-Jcv"/>
|
<outlet property="menuSelectAll" destination="q2h-lq-e4r" id="s98-r1-Jcv"/>
|
||||||
<outlet property="menuSelectSplitAbove" destination="0yU-hC-8xF" id="aPc-lS-own"/>
|
<outlet property="menuSelectSplitAbove" destination="0yU-hC-8xF" id="aPc-lS-own"/>
|
||||||
|
@ -68,6 +68,12 @@ class TerminalController: BaseTerminalController {
|
|||||||
selector: #selector(onCloseTab),
|
selector: #selector(onCloseTab),
|
||||||
name: .ghosttyCloseTab,
|
name: .ghosttyCloseTab,
|
||||||
object: nil)
|
object: nil)
|
||||||
|
center.addObserver(
|
||||||
|
self,
|
||||||
|
selector: #selector(onResetWindowSize),
|
||||||
|
name: .ghosttyResetWindowSize,
|
||||||
|
object: nil
|
||||||
|
)
|
||||||
center.addObserver(
|
center.addObserver(
|
||||||
self,
|
self,
|
||||||
selector: #selector(ghosttyConfigDidChange(_:)),
|
selector: #selector(ghosttyConfigDidChange(_:)),
|
||||||
@ -612,7 +618,7 @@ class TerminalController: BaseTerminalController {
|
|||||||
window.close()
|
window.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func returnToDefaultSize(_ sender: Any) {
|
@IBAction func returnToDefaultSize(_ sender: Any?) {
|
||||||
guard let defaultSize else { return }
|
guard let defaultSize else { return }
|
||||||
window?.setFrame(defaultSize, display: true)
|
window?.setFrame(defaultSize, display: true)
|
||||||
}
|
}
|
||||||
@ -830,6 +836,12 @@ class TerminalController: BaseTerminalController {
|
|||||||
closeTab(self)
|
closeTab(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc private func onResetWindowSize(notification: SwiftUI.Notification) {
|
||||||
|
guard let target = notification.object as? Ghostty.SurfaceView else { return }
|
||||||
|
guard surfaceTree?.contains(view: target) ?? false else { return }
|
||||||
|
returnToDefaultSize(nil)
|
||||||
|
}
|
||||||
|
|
||||||
@objc private func onToggleFullscreen(notification: SwiftUI.Notification) {
|
@objc private func onToggleFullscreen(notification: SwiftUI.Notification) {
|
||||||
guard let target = notification.object as? Ghostty.SurfaceView else { return }
|
guard let target = notification.object as? Ghostty.SurfaceView else { return }
|
||||||
guard target == self.focusedSurface else { return }
|
guard target == self.focusedSurface else { return }
|
||||||
|
@ -508,6 +508,9 @@ extension Ghostty {
|
|||||||
case GHOSTTY_ACTION_INITIAL_SIZE:
|
case GHOSTTY_ACTION_INITIAL_SIZE:
|
||||||
setInitialSize(app, target: target, v: action.action.initial_size)
|
setInitialSize(app, target: target, v: action.action.initial_size)
|
||||||
|
|
||||||
|
case GHOSTTY_ACTION_RESET_WINDOW_SIZE:
|
||||||
|
resetWindowSize(app, target: target)
|
||||||
|
|
||||||
case GHOSTTY_ACTION_CELL_SIZE:
|
case GHOSTTY_ACTION_CELL_SIZE:
|
||||||
setCellSize(app, target: target, v: action.action.cell_size)
|
setCellSize(app, target: target, v: action.action.cell_size)
|
||||||
|
|
||||||
@ -1131,7 +1134,7 @@ extension Ghostty {
|
|||||||
v: ghostty_action_initial_size_s) {
|
v: ghostty_action_initial_size_s) {
|
||||||
switch (target.tag) {
|
switch (target.tag) {
|
||||||
case GHOSTTY_TARGET_APP:
|
case GHOSTTY_TARGET_APP:
|
||||||
Ghostty.logger.warning("mouse over link does nothing with an app target")
|
Ghostty.logger.warning("initial size does nothing with an app target")
|
||||||
return
|
return
|
||||||
|
|
||||||
case GHOSTTY_TARGET_SURFACE:
|
case GHOSTTY_TARGET_SURFACE:
|
||||||
@ -1145,6 +1148,28 @@ extension Ghostty {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static func resetWindowSize(
|
||||||
|
_ app: ghostty_app_t,
|
||||||
|
target: ghostty_target_s) {
|
||||||
|
switch (target.tag) {
|
||||||
|
case GHOSTTY_TARGET_APP:
|
||||||
|
Ghostty.logger.warning("reset window size does nothing with an app target")
|
||||||
|
return
|
||||||
|
|
||||||
|
case GHOSTTY_TARGET_SURFACE:
|
||||||
|
guard let surface = target.target.surface else { return }
|
||||||
|
guard let surfaceView = self.surfaceView(from: surface) else { return }
|
||||||
|
NotificationCenter.default.post(
|
||||||
|
name: .ghosttyResetWindowSize,
|
||||||
|
object: surfaceView
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
default:
|
||||||
|
assertionFailure()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static func setCellSize(
|
private static func setCellSize(
|
||||||
_ app: ghostty_app_t,
|
_ app: ghostty_app_t,
|
||||||
target: ghostty_target_s,
|
target: ghostty_target_s,
|
||||||
|
@ -247,6 +247,9 @@ extension Notification.Name {
|
|||||||
|
|
||||||
/// Close tab
|
/// Close tab
|
||||||
static let ghosttyCloseTab = Notification.Name("com.mitchellh.ghostty.closeTab")
|
static let ghosttyCloseTab = Notification.Name("com.mitchellh.ghostty.closeTab")
|
||||||
|
|
||||||
|
/// Resize the window to a default size.
|
||||||
|
static let ghosttyResetWindowSize = Notification.Name("com.mitchellh.ghostty.resetWindowSize")
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: I am moving all of these to Notification.Name extensions over time. This
|
// NOTE: I am moving all of these to Notification.Name extensions over time. This
|
||||||
|
@ -4228,6 +4228,12 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool
|
|||||||
{},
|
{},
|
||||||
),
|
),
|
||||||
|
|
||||||
|
.reset_window_size => return try self.rt_app.performAction(
|
||||||
|
.{ .surface = self },
|
||||||
|
.reset_window_size,
|
||||||
|
{},
|
||||||
|
),
|
||||||
|
|
||||||
.toggle_maximize => return try self.rt_app.performAction(
|
.toggle_maximize => return try self.rt_app.performAction(
|
||||||
.{ .surface = self },
|
.{ .surface = self },
|
||||||
.toggle_maximize,
|
.toggle_maximize,
|
||||||
|
@ -140,6 +140,10 @@ pub const Action = union(Key) {
|
|||||||
/// Sets a size limit (in pixels) for the target terminal.
|
/// Sets a size limit (in pixels) for the target terminal.
|
||||||
size_limit: SizeLimit,
|
size_limit: SizeLimit,
|
||||||
|
|
||||||
|
/// Resets the window size to the default size. See the
|
||||||
|
/// `reset_window_size` keybinding for more information.
|
||||||
|
reset_window_size,
|
||||||
|
|
||||||
/// Specifies the initial size of the target terminal.
|
/// Specifies the initial size of the target terminal.
|
||||||
///
|
///
|
||||||
/// This may be sent once during the initialization of a surface
|
/// This may be sent once during the initialization of a surface
|
||||||
@ -259,6 +263,7 @@ pub const Action = union(Key) {
|
|||||||
toggle_split_zoom,
|
toggle_split_zoom,
|
||||||
present_terminal,
|
present_terminal,
|
||||||
size_limit,
|
size_limit,
|
||||||
|
reset_window_size,
|
||||||
initial_size,
|
initial_size,
|
||||||
cell_size,
|
cell_size,
|
||||||
inspector,
|
inspector,
|
||||||
|
@ -240,6 +240,7 @@ pub const App = struct {
|
|||||||
.config_change,
|
.config_change,
|
||||||
.toggle_maximize,
|
.toggle_maximize,
|
||||||
.prompt_title,
|
.prompt_title,
|
||||||
|
.reset_window_size,
|
||||||
=> {
|
=> {
|
||||||
log.info("unimplemented action={}", .{action});
|
log.info("unimplemented action={}", .{action});
|
||||||
return false;
|
return false;
|
||||||
|
@ -512,6 +512,7 @@ pub fn performAction(
|
|||||||
.render_inspector,
|
.render_inspector,
|
||||||
.renderer_health,
|
.renderer_health,
|
||||||
.color_change,
|
.color_change,
|
||||||
|
.reset_window_size,
|
||||||
=> {
|
=> {
|
||||||
log.warn("unimplemented action={}", .{action});
|
log.warn("unimplemented action={}", .{action});
|
||||||
return false;
|
return false;
|
||||||
|
@ -380,6 +380,11 @@ pub const Action = union(enum) {
|
|||||||
/// Equalize all splits in the current window
|
/// Equalize all splits in the current window
|
||||||
equalize_splits: void,
|
equalize_splits: void,
|
||||||
|
|
||||||
|
/// Reset the window to the default size. The "default size" is the
|
||||||
|
/// size that a new window would be created with. This has no effect
|
||||||
|
/// if the window is fullscreen.
|
||||||
|
reset_window_size: void,
|
||||||
|
|
||||||
/// Control the terminal inspector visibility.
|
/// Control the terminal inspector visibility.
|
||||||
///
|
///
|
||||||
/// Arguments:
|
/// Arguments:
|
||||||
@ -772,6 +777,7 @@ pub const Action = union(enum) {
|
|||||||
.toggle_fullscreen,
|
.toggle_fullscreen,
|
||||||
.toggle_window_decorations,
|
.toggle_window_decorations,
|
||||||
.toggle_secure_input,
|
.toggle_secure_input,
|
||||||
|
.reset_window_size,
|
||||||
.crash,
|
.crash,
|
||||||
=> .surface,
|
=> .surface,
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user