mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
Merge pull request #838 from gpanders/equalize-splits
macos: add key binding for equalizing split sizes
This commit is contained in:
@ -341,6 +341,7 @@ typedef void (*ghostty_runtime_control_inspector_cb)(void *, ghostty_inspector_m
|
|||||||
typedef void (*ghostty_runtime_close_surface_cb)(void *, bool);
|
typedef void (*ghostty_runtime_close_surface_cb)(void *, bool);
|
||||||
typedef void (*ghostty_runtime_focus_split_cb)(void *, ghostty_split_focus_direction_e);
|
typedef void (*ghostty_runtime_focus_split_cb)(void *, ghostty_split_focus_direction_e);
|
||||||
typedef void (*ghostty_runtime_resize_split_cb)(void *, ghostty_split_resize_direction_e, uint16_t);
|
typedef void (*ghostty_runtime_resize_split_cb)(void *, ghostty_split_resize_direction_e, uint16_t);
|
||||||
|
typedef void (*ghostty_runtime_equalize_splits_cb)(void *);
|
||||||
typedef void (*ghostty_runtime_toggle_split_zoom_cb)(void *);
|
typedef void (*ghostty_runtime_toggle_split_zoom_cb)(void *);
|
||||||
typedef void (*ghostty_runtime_goto_tab_cb)(void *, int32_t);
|
typedef void (*ghostty_runtime_goto_tab_cb)(void *, int32_t);
|
||||||
typedef void (*ghostty_runtime_toggle_fullscreen_cb)(void *, ghostty_non_native_fullscreen_e);
|
typedef void (*ghostty_runtime_toggle_fullscreen_cb)(void *, ghostty_non_native_fullscreen_e);
|
||||||
@ -366,6 +367,7 @@ typedef struct {
|
|||||||
ghostty_runtime_close_surface_cb close_surface_cb;
|
ghostty_runtime_close_surface_cb close_surface_cb;
|
||||||
ghostty_runtime_focus_split_cb focus_split_cb;
|
ghostty_runtime_focus_split_cb focus_split_cb;
|
||||||
ghostty_runtime_resize_split_cb resize_split_cb;
|
ghostty_runtime_resize_split_cb resize_split_cb;
|
||||||
|
ghostty_runtime_equalize_splits_cb equalize_splits_cb;
|
||||||
ghostty_runtime_toggle_split_zoom_cb toggle_split_zoom_cb;
|
ghostty_runtime_toggle_split_zoom_cb toggle_split_zoom_cb;
|
||||||
ghostty_runtime_goto_tab_cb goto_tab_cb;
|
ghostty_runtime_goto_tab_cb goto_tab_cb;
|
||||||
ghostty_runtime_toggle_fullscreen_cb toggle_fullscreen_cb;
|
ghostty_runtime_toggle_fullscreen_cb toggle_fullscreen_cb;
|
||||||
@ -422,6 +424,7 @@ void ghostty_surface_request_close(ghostty_surface_t);
|
|||||||
void ghostty_surface_split(ghostty_surface_t, ghostty_split_direction_e);
|
void ghostty_surface_split(ghostty_surface_t, ghostty_split_direction_e);
|
||||||
void ghostty_surface_split_focus(ghostty_surface_t, ghostty_split_focus_direction_e);
|
void ghostty_surface_split_focus(ghostty_surface_t, ghostty_split_focus_direction_e);
|
||||||
void ghostty_surface_split_resize(ghostty_surface_t, ghostty_split_resize_direction_e, uint16_t);
|
void ghostty_surface_split_resize(ghostty_surface_t, ghostty_split_resize_direction_e, uint16_t);
|
||||||
|
void ghostty_surface_split_equalize(ghostty_surface_t);
|
||||||
bool ghostty_surface_binding_action(ghostty_surface_t, const char *, uintptr_t);
|
bool ghostty_surface_binding_action(ghostty_surface_t, const char *, uintptr_t);
|
||||||
void ghostty_surface_complete_clipboard_request(ghostty_surface_t, const char *, void *, bool);
|
void ghostty_surface_complete_clipboard_request(ghostty_surface_t, const char *, void *, bool);
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ class AppDelegate: NSObject, ObservableObject, NSApplicationDelegate, GhosttyApp
|
|||||||
@IBOutlet private var menuResetFontSize: NSMenuItem?
|
@IBOutlet private var menuResetFontSize: NSMenuItem?
|
||||||
@IBOutlet private var menuTerminalInspector: NSMenuItem?
|
@IBOutlet private var menuTerminalInspector: NSMenuItem?
|
||||||
|
|
||||||
|
@IBOutlet private var menuEqualizeSplits: NSMenuItem?
|
||||||
@IBOutlet private var menuMoveSplitDividerUp: NSMenuItem?
|
@IBOutlet private var menuMoveSplitDividerUp: NSMenuItem?
|
||||||
@IBOutlet private var menuMoveSplitDividerDown: NSMenuItem?
|
@IBOutlet private var menuMoveSplitDividerDown: NSMenuItem?
|
||||||
@IBOutlet private var menuMoveSplitDividerLeft: NSMenuItem?
|
@IBOutlet private var menuMoveSplitDividerLeft: NSMenuItem?
|
||||||
@ -215,6 +216,7 @@ class AppDelegate: NSObject, ObservableObject, NSApplicationDelegate, GhosttyApp
|
|||||||
syncMenuShortcut(action: "resize_split:down,10", menuItem: self.menuMoveSplitDividerDown)
|
syncMenuShortcut(action: "resize_split:down,10", menuItem: self.menuMoveSplitDividerDown)
|
||||||
syncMenuShortcut(action: "resize_split:right,10", menuItem: self.menuMoveSplitDividerRight)
|
syncMenuShortcut(action: "resize_split:right,10", menuItem: self.menuMoveSplitDividerRight)
|
||||||
syncMenuShortcut(action: "resize_split:left,10", menuItem: self.menuMoveSplitDividerLeft)
|
syncMenuShortcut(action: "resize_split:left,10", menuItem: self.menuMoveSplitDividerLeft)
|
||||||
|
syncMenuShortcut(action: "equalize_splits", menuItem: self.menuEqualizeSplits)
|
||||||
|
|
||||||
syncMenuShortcut(action: "increase_font_size:1", menuItem: self.menuIncreaseFontSize)
|
syncMenuShortcut(action: "increase_font_size:1", menuItem: self.menuIncreaseFontSize)
|
||||||
syncMenuShortcut(action: "decrease_font_size:1", menuItem: self.menuDecreaseFontSize)
|
syncMenuShortcut(action: "decrease_font_size:1", menuItem: self.menuDecreaseFontSize)
|
||||||
|
@ -271,6 +271,11 @@ class TerminalController: NSWindowController, NSWindowDelegate,
|
|||||||
splitMoveFocus(direction: .right)
|
splitMoveFocus(direction: .right)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@IBAction func equalizeSplits(_ sender: Any) {
|
||||||
|
guard let surface = focusedSurface?.surface else { return }
|
||||||
|
ghostty.splitEqualize(surface: surface)
|
||||||
|
}
|
||||||
|
|
||||||
@IBAction func moveSplitDividerUp(_ sender: Any) {
|
@IBAction func moveSplitDividerUp(_ sender: Any) {
|
||||||
guard let surface = focusedSurface?.surface else { return }
|
guard let surface = focusedSurface?.surface else { return }
|
||||||
ghostty.splitResize(surface: surface, direction: .up, amount: 10)
|
ghostty.splitResize(surface: surface, direction: .up, amount: 10)
|
||||||
|
@ -160,6 +160,8 @@ extension Ghostty {
|
|||||||
focus_split_cb: { userdata, direction in AppState.focusSplit(userdata, direction: direction) },
|
focus_split_cb: { userdata, direction in AppState.focusSplit(userdata, direction: direction) },
|
||||||
resize_split_cb: { userdata, direction, amount in
|
resize_split_cb: { userdata, direction, amount in
|
||||||
AppState.resizeSplit(userdata, direction: direction, amount: amount) },
|
AppState.resizeSplit(userdata, direction: direction, amount: amount) },
|
||||||
|
equalize_splits_cb: { userdata in
|
||||||
|
AppState.equalizeSplits(userdata) },
|
||||||
toggle_split_zoom_cb: { userdata in AppState.toggleSplitZoom(userdata) },
|
toggle_split_zoom_cb: { userdata in AppState.toggleSplitZoom(userdata) },
|
||||||
goto_tab_cb: { userdata, n in AppState.gotoTab(userdata, n: n) },
|
goto_tab_cb: { userdata, n in AppState.gotoTab(userdata, n: n) },
|
||||||
toggle_fullscreen_cb: { userdata, nonNativeFullscreen in AppState.toggleFullscreen(userdata, nonNativeFullscreen: nonNativeFullscreen) },
|
toggle_fullscreen_cb: { userdata, nonNativeFullscreen in AppState.toggleFullscreen(userdata, nonNativeFullscreen: nonNativeFullscreen) },
|
||||||
@ -298,6 +300,10 @@ extension Ghostty {
|
|||||||
ghostty_surface_split_resize(surface, direction.toNative(), amount)
|
ghostty_surface_split_resize(surface, direction.toNative(), amount)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func splitEqualize(surface: ghostty_surface_t) {
|
||||||
|
ghostty_surface_split_equalize(surface)
|
||||||
|
}
|
||||||
|
|
||||||
func splitToggleZoom(surface: ghostty_surface_t) {
|
func splitToggleZoom(surface: ghostty_surface_t) {
|
||||||
let action = "toggle_split_zoom"
|
let action = "toggle_split_zoom"
|
||||||
if (!ghostty_surface_binding_action(surface, action, UInt(action.count))) {
|
if (!ghostty_surface_binding_action(surface, action, UInt(action.count))) {
|
||||||
@ -383,6 +389,11 @@ extension Ghostty {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static func equalizeSplits(_ userdata: UnsafeMutableRawPointer?) {
|
||||||
|
guard let surface = self.surfaceUserdata(from: userdata) else { return }
|
||||||
|
NotificationCenter.default.post(name: Notification.didEqualizeSplits, object: surface)
|
||||||
|
}
|
||||||
|
|
||||||
static func toggleSplitZoom(_ userdata: UnsafeMutableRawPointer?) {
|
static func toggleSplitZoom(_ userdata: UnsafeMutableRawPointer?) {
|
||||||
guard let surface = self.surfaceUserdata(from: userdata) else { return }
|
guard let surface = self.surfaceUserdata(from: userdata) else { return }
|
||||||
|
|
||||||
|
@ -171,7 +171,31 @@ extension Ghostty {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Equalize the splits in this container. Each split is equalized
|
||||||
|
/// based on its weight, i.e. the number of leaves it contains.
|
||||||
|
/// This function returns the weight of this container.
|
||||||
|
func equalize() -> UInt {
|
||||||
|
let topLeftWeight: UInt
|
||||||
|
switch (topLeft) {
|
||||||
|
case .leaf:
|
||||||
|
topLeftWeight = 1
|
||||||
|
case .split(let c):
|
||||||
|
topLeftWeight = c.equalize()
|
||||||
|
}
|
||||||
|
|
||||||
|
let bottomRightWeight: UInt
|
||||||
|
switch (bottomRight) {
|
||||||
|
case .leaf:
|
||||||
|
bottomRightWeight = 1
|
||||||
|
case .split(let c):
|
||||||
|
bottomRightWeight = c.equalize()
|
||||||
|
}
|
||||||
|
|
||||||
|
let weight = topLeftWeight + bottomRightWeight
|
||||||
|
split = Double(topLeftWeight) / Double(weight)
|
||||||
|
return weight
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Hashable
|
// MARK: - Hashable
|
||||||
|
|
||||||
func hash(into hasher: inout Hasher) {
|
func hash(into hasher: inout Hasher) {
|
||||||
|
@ -50,6 +50,7 @@ extension Ghostty {
|
|||||||
var body: some View {
|
var body: some View {
|
||||||
let center = NotificationCenter.default
|
let center = NotificationCenter.default
|
||||||
let pubZoom = center.publisher(for: Notification.didToggleSplitZoom)
|
let pubZoom = center.publisher(for: Notification.didToggleSplitZoom)
|
||||||
|
let pubEqualize = center.publisher(for: Notification.didEqualizeSplits)
|
||||||
|
|
||||||
// If we're zoomed, we don't render anything, we are transparent. This
|
// If we're zoomed, we don't render anything, we are transparent. This
|
||||||
// ensures that the View stays around so we don't lose our state, but
|
// ensures that the View stays around so we don't lose our state, but
|
||||||
@ -75,6 +76,7 @@ extension Ghostty {
|
|||||||
container: container
|
container: container
|
||||||
)
|
)
|
||||||
.onReceive(pubZoom) { onZoom(notification: $0) }
|
.onReceive(pubZoom) { onZoom(notification: $0) }
|
||||||
|
.onReceive(pubEqualize) { onEqualize(notification: $0) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.navigationTitle(surfaceTitle ?? "Ghostty")
|
.navigationTitle(surfaceTitle ?? "Ghostty")
|
||||||
@ -135,8 +137,13 @@ extension Ghostty {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func onEqualize(notification: SwiftUI.Notification) {
|
||||||
|
guard case .split(let c) = node else { return }
|
||||||
|
_ = c.equalize()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A noSplit leaf node of a split tree.
|
/// A noSplit leaf node of a split tree.
|
||||||
private struct TerminalSplitLeaf: View {
|
private struct TerminalSplitLeaf: View {
|
||||||
/// The leaf to draw the surface for.
|
/// The leaf to draw the surface for.
|
||||||
|
@ -150,6 +150,9 @@ extension Ghostty.Notification {
|
|||||||
static let didResizeSplit = Notification.Name("com.mitchellh.ghostty.didResizeSplit")
|
static let didResizeSplit = Notification.Name("com.mitchellh.ghostty.didResizeSplit")
|
||||||
static let ResizeSplitDirectionKey = didResizeSplit.rawValue + ".direction"
|
static let ResizeSplitDirectionKey = didResizeSplit.rawValue + ".direction"
|
||||||
static let ResizeSplitAmountKey = didResizeSplit.rawValue + ".amount"
|
static let ResizeSplitAmountKey = didResizeSplit.rawValue + ".amount"
|
||||||
|
|
||||||
|
/// Notification sent to the split root to equalize split sizes
|
||||||
|
static let didEqualizeSplits = Notification.Name("com.mitchellh.ghostty.didEqualizeSplits")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make the input enum hashable.
|
// Make the input enum hashable.
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22155" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22154" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<deployment identifier="macosx"/>
|
<deployment identifier="macosx"/>
|
||||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22155"/>
|
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22154"/>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<objects>
|
<objects>
|
||||||
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
|
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
|
||||||
@ -18,6 +18,7 @@
|
|||||||
<outlet property="menuCloseWindow" destination="W5w-UZ-crk" id="6ff-BT-ENV"/>
|
<outlet property="menuCloseWindow" destination="W5w-UZ-crk" id="6ff-BT-ENV"/>
|
||||||
<outlet property="menuCopy" destination="Jqf-pv-Zcu" id="bKd-1C-oy9"/>
|
<outlet property="menuCopy" destination="Jqf-pv-Zcu" id="bKd-1C-oy9"/>
|
||||||
<outlet property="menuDecreaseFontSize" destination="kzb-SZ-dOA" id="Y1B-Vh-6Z2"/>
|
<outlet property="menuDecreaseFontSize" destination="kzb-SZ-dOA" id="Y1B-Vh-6Z2"/>
|
||||||
|
<outlet property="menuEqualizeSplits" destination="3gH-VD-vL9" id="SiZ-ce-FOF"/>
|
||||||
<outlet property="menuIncreaseFontSize" destination="CIH-ey-Z6x" id="hkc-9C-80E"/>
|
<outlet property="menuIncreaseFontSize" destination="CIH-ey-Z6x" id="hkc-9C-80E"/>
|
||||||
<outlet property="menuMoveSplitDividerDown" destination="Zj7-2W-fdF" id="997-LL-nlN"/>
|
<outlet property="menuMoveSplitDividerDown" destination="Zj7-2W-fdF" id="997-LL-nlN"/>
|
||||||
<outlet property="menuMoveSplitDividerLeft" destination="wSR-ny-j1a" id="HCZ-CI-2ob"/>
|
<outlet property="menuMoveSplitDividerLeft" destination="wSR-ny-j1a" id="HCZ-CI-2ob"/>
|
||||||
@ -270,6 +271,13 @@
|
|||||||
<modifierMask key="keyEquivalentModifierMask"/>
|
<modifierMask key="keyEquivalentModifierMask"/>
|
||||||
<menu key="submenu" title="Resize Split" id="t7T-Ti-0im">
|
<menu key="submenu" title="Resize Split" id="t7T-Ti-0im">
|
||||||
<items>
|
<items>
|
||||||
|
<menuItem title="Equalize Splits" id="3gH-VD-vL9">
|
||||||
|
<modifierMask key="keyEquivalentModifierMask"/>
|
||||||
|
<connections>
|
||||||
|
<action selector="equalizeSplits:" target="-1" id="RE0-hS-YLf"/>
|
||||||
|
</connections>
|
||||||
|
</menuItem>
|
||||||
|
<menuItem isSeparatorItem="YES" id="XKA-Jd-h9t"/>
|
||||||
<menuItem title="Move Divider Up" id="h9Y-40-3oo">
|
<menuItem title="Move Divider Up" id="h9Y-40-3oo">
|
||||||
<modifierMask key="keyEquivalentModifierMask"/>
|
<modifierMask key="keyEquivalentModifierMask"/>
|
||||||
<connections>
|
<connections>
|
||||||
|
@ -2458,6 +2458,12 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool
|
|||||||
} else log.warn("runtime doesn't implement resizeSplit", .{});
|
} else log.warn("runtime doesn't implement resizeSplit", .{});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
.equalize_splits => {
|
||||||
|
if (@hasDecl(apprt.Surface, "equalizeSplits")) {
|
||||||
|
self.rt_surface.equalizeSplits();
|
||||||
|
} else log.warn("runtime doesn't implement equalizeSplits", .{});
|
||||||
|
},
|
||||||
|
|
||||||
.toggle_split_zoom => {
|
.toggle_split_zoom => {
|
||||||
if (@hasDecl(apprt.Surface, "toggleSplitZoom")) {
|
if (@hasDecl(apprt.Surface, "toggleSplitZoom")) {
|
||||||
self.rt_surface.toggleSplitZoom();
|
self.rt_surface.toggleSplitZoom();
|
||||||
|
@ -95,6 +95,9 @@ pub const App = struct {
|
|||||||
/// Resize the current split.
|
/// Resize the current split.
|
||||||
resize_split: ?*const fn (SurfaceUD, input.SplitResizeDirection, u16) callconv(.C) void = null,
|
resize_split: ?*const fn (SurfaceUD, input.SplitResizeDirection, u16) callconv(.C) void = null,
|
||||||
|
|
||||||
|
/// Equalize all splits in the current window
|
||||||
|
equalize_splits: ?*const fn (SurfaceUD) callconv(.C) void = null,
|
||||||
|
|
||||||
/// Zoom the current split.
|
/// Zoom the current split.
|
||||||
toggle_split_zoom: ?*const fn (SurfaceUD) callconv(.C) void = null,
|
toggle_split_zoom: ?*const fn (SurfaceUD) callconv(.C) void = null,
|
||||||
|
|
||||||
@ -396,6 +399,15 @@ pub const Surface = struct {
|
|||||||
func(self.opts.userdata, direction, amount);
|
func(self.opts.userdata, direction, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn equalizeSplits(self: *const Surface) void {
|
||||||
|
const func = self.app.opts.equalize_splits orelse {
|
||||||
|
log.info("runtime embedder does not support equalize splits", .{});
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
func(self.opts.userdata);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn toggleSplitZoom(self: *const Surface) void {
|
pub fn toggleSplitZoom(self: *const Surface) void {
|
||||||
const func = self.app.opts.toggle_split_zoom orelse {
|
const func = self.app.opts.toggle_split_zoom orelse {
|
||||||
log.info("runtime embedder does not support split zoom", .{});
|
log.info("runtime embedder does not support split zoom", .{});
|
||||||
@ -1388,6 +1400,11 @@ pub const CAPI = struct {
|
|||||||
ptr.resizeSplit(direction, amount);
|
ptr.resizeSplit(direction, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Equalize the size of all splits in the current window.
|
||||||
|
export fn ghostty_surface_split_equalize(ptr: *Surface) void {
|
||||||
|
ptr.equalizeSplits();
|
||||||
|
}
|
||||||
|
|
||||||
/// Invoke an action on the surface.
|
/// Invoke an action on the surface.
|
||||||
export fn ghostty_surface_binding_action(
|
export fn ghostty_surface_binding_action(
|
||||||
ptr: *Surface,
|
ptr: *Surface,
|
||||||
|
@ -1016,6 +1016,11 @@ pub fn default(alloc_gpa: Allocator) Allocator.Error!Config {
|
|||||||
.{ .key = .right, .mods = .{ .super = true, .ctrl = true } },
|
.{ .key = .right, .mods = .{ .super = true, .ctrl = true } },
|
||||||
.{ .resize_split = .{ .right, 10 } },
|
.{ .resize_split = .{ .right, 10 } },
|
||||||
);
|
);
|
||||||
|
try result.keybind.set.put(
|
||||||
|
alloc,
|
||||||
|
.{ .key = .equal, .mods = .{ .shift = true, .alt = true } },
|
||||||
|
.{ .equalize_splits = {} },
|
||||||
|
);
|
||||||
|
|
||||||
// Inspector, matching Chromium
|
// Inspector, matching Chromium
|
||||||
try result.keybind.set.put(
|
try result.keybind.set.put(
|
||||||
|
@ -197,6 +197,9 @@ pub const Action = union(enum) {
|
|||||||
/// direction
|
/// direction
|
||||||
resize_split: SplitResizeParameter,
|
resize_split: SplitResizeParameter,
|
||||||
|
|
||||||
|
/// Equalize all splits in the current window
|
||||||
|
equalize_splits: void,
|
||||||
|
|
||||||
/// Show, hide, or toggle the terminal inspector for the currently
|
/// Show, hide, or toggle the terminal inspector for the currently
|
||||||
/// focused terminal.
|
/// focused terminal.
|
||||||
inspector: InspectorMode,
|
inspector: InspectorMode,
|
||||||
|
Reference in New Issue
Block a user