mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
Add custom size splits in macOS
This commit is contained in:
@ -348,7 +348,7 @@ typedef struct {
|
|||||||
ghostty_target_u target;
|
ghostty_target_u target;
|
||||||
} ghostty_target_s;
|
} ghostty_target_s;
|
||||||
|
|
||||||
// apprt.action.SplitDirection
|
// apprt.action.SplitDirection.direction
|
||||||
typedef enum {
|
typedef enum {
|
||||||
GHOSTTY_SPLIT_DIRECTION_RIGHT,
|
GHOSTTY_SPLIT_DIRECTION_RIGHT,
|
||||||
GHOSTTY_SPLIT_DIRECTION_DOWN,
|
GHOSTTY_SPLIT_DIRECTION_DOWN,
|
||||||
@ -356,6 +356,12 @@ typedef enum {
|
|||||||
GHOSTTY_SPLIT_DIRECTION_UP,
|
GHOSTTY_SPLIT_DIRECTION_UP,
|
||||||
} ghostty_action_split_direction_e;
|
} ghostty_action_split_direction_e;
|
||||||
|
|
||||||
|
// apprt.action.SplitDirection
|
||||||
|
typedef struct {
|
||||||
|
float percent;
|
||||||
|
ghostty_action_split_direction_e direction;
|
||||||
|
} ghostty_action_split_s;
|
||||||
|
|
||||||
// apprt.action.GotoSplit
|
// apprt.action.GotoSplit
|
||||||
typedef enum {
|
typedef enum {
|
||||||
GHOSTTY_GOTO_SPLIT_PREVIOUS,
|
GHOSTTY_GOTO_SPLIT_PREVIOUS,
|
||||||
@ -564,7 +570,7 @@ typedef enum {
|
|||||||
} ghostty_action_tag_e;
|
} ghostty_action_tag_e;
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
ghostty_action_split_direction_e new_split;
|
ghostty_action_split_s new_split;
|
||||||
ghostty_action_fullscreen_e toggle_fullscreen;
|
ghostty_action_fullscreen_e toggle_fullscreen;
|
||||||
ghostty_action_move_tab_s move_tab;
|
ghostty_action_move_tab_s move_tab;
|
||||||
ghostty_action_goto_tab_e goto_tab;
|
ghostty_action_goto_tab_e goto_tab;
|
||||||
@ -693,7 +699,9 @@ void ghostty_surface_mouse_scroll(ghostty_surface_t,
|
|||||||
void ghostty_surface_mouse_pressure(ghostty_surface_t, uint32_t, double);
|
void ghostty_surface_mouse_pressure(ghostty_surface_t, uint32_t, double);
|
||||||
void ghostty_surface_ime_point(ghostty_surface_t, double*, double*);
|
void ghostty_surface_ime_point(ghostty_surface_t, double*, double*);
|
||||||
void ghostty_surface_request_close(ghostty_surface_t);
|
void ghostty_surface_request_close(ghostty_surface_t);
|
||||||
void ghostty_surface_split(ghostty_surface_t, ghostty_action_split_direction_e);
|
void ghostty_surface_split(ghostty_surface_t,
|
||||||
|
ghostty_action_split_direction_e,
|
||||||
|
float);
|
||||||
void ghostty_surface_split_focus(ghostty_surface_t,
|
void ghostty_surface_split_focus(ghostty_surface_t,
|
||||||
ghostty_action_goto_split_e);
|
ghostty_action_goto_split_e);
|
||||||
void ghostty_surface_split_resize(ghostty_surface_t,
|
void ghostty_surface_split_resize(ghostty_surface_t,
|
||||||
|
@ -476,12 +476,12 @@ class BaseTerminalController: NSWindowController,
|
|||||||
|
|
||||||
@IBAction func splitRight(_ sender: Any) {
|
@IBAction func splitRight(_ sender: Any) {
|
||||||
guard let surface = focusedSurface?.surface else { return }
|
guard let surface = focusedSurface?.surface else { return }
|
||||||
ghostty.split(surface: surface, direction: GHOSTTY_SPLIT_DIRECTION_RIGHT)
|
ghostty.split(surface: surface, direction: GHOSTTY_SPLIT_DIRECTION_RIGHT, percent: 0.5)
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func splitDown(_ sender: Any) {
|
@IBAction func splitDown(_ sender: Any) {
|
||||||
guard let surface = focusedSurface?.surface else { return }
|
guard let surface = focusedSurface?.surface else { return }
|
||||||
ghostty.split(surface: surface, direction: GHOSTTY_SPLIT_DIRECTION_DOWN)
|
ghostty.split(surface: surface, direction: GHOSTTY_SPLIT_DIRECTION_DOWN, percent: 0.5)
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func splitZoom(_ sender: Any) {
|
@IBAction func splitZoom(_ sender: Any) {
|
||||||
|
@ -170,8 +170,8 @@ extension Ghostty {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func split(surface: ghostty_surface_t, direction: ghostty_action_split_direction_e) {
|
func split(surface: ghostty_surface_t, direction: ghostty_action_split_direction_e, percent: Float) {
|
||||||
ghostty_surface_split(surface, direction)
|
ghostty_surface_split(surface, direction, percent)
|
||||||
}
|
}
|
||||||
|
|
||||||
func splitMoveFocus(surface: ghostty_surface_t, direction: SplitFocusDirection) {
|
func splitMoveFocus(surface: ghostty_surface_t, direction: SplitFocusDirection) {
|
||||||
@ -453,7 +453,7 @@ extension Ghostty {
|
|||||||
newTab(app, target: target)
|
newTab(app, target: target)
|
||||||
|
|
||||||
case GHOSTTY_ACTION_NEW_SPLIT:
|
case GHOSTTY_ACTION_NEW_SPLIT:
|
||||||
newSplit(app, target: target, direction: action.action.new_split)
|
newSplit(app, target: target, split: action.action.new_split)
|
||||||
|
|
||||||
case GHOSTTY_ACTION_TOGGLE_FULLSCREEN:
|
case GHOSTTY_ACTION_TOGGLE_FULLSCREEN:
|
||||||
toggleFullscreen(app, target: target, mode: action.action.toggle_fullscreen)
|
toggleFullscreen(app, target: target, mode: action.action.toggle_fullscreen)
|
||||||
@ -607,7 +607,7 @@ extension Ghostty {
|
|||||||
private static func newSplit(
|
private static func newSplit(
|
||||||
_ app: ghostty_app_t,
|
_ app: ghostty_app_t,
|
||||||
target: ghostty_target_s,
|
target: ghostty_target_s,
|
||||||
direction: ghostty_action_split_direction_e) {
|
split: ghostty_action_split_s) {
|
||||||
switch (target.tag) {
|
switch (target.tag) {
|
||||||
case GHOSTTY_TARGET_APP:
|
case GHOSTTY_TARGET_APP:
|
||||||
// New split does nothing with an app target
|
// New split does nothing with an app target
|
||||||
@ -622,7 +622,8 @@ extension Ghostty {
|
|||||||
name: Notification.ghosttyNewSplit,
|
name: Notification.ghosttyNewSplit,
|
||||||
object: surfaceView,
|
object: surfaceView,
|
||||||
userInfo: [
|
userInfo: [
|
||||||
"direction": direction,
|
"direction": split.direction,
|
||||||
|
"percent": split.percent,
|
||||||
Notification.NewSurfaceConfigKey: SurfaceConfiguration(from: ghostty_surface_inherited_config(surface)),
|
Notification.NewSurfaceConfigKey: SurfaceConfiguration(from: ghostty_surface_inherited_config(surface)),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
@ -217,9 +217,11 @@ extension Ghostty {
|
|||||||
let configAny = notification.userInfo?[Ghostty.Notification.NewSurfaceConfigKey]
|
let configAny = notification.userInfo?[Ghostty.Notification.NewSurfaceConfigKey]
|
||||||
let config = configAny as? SurfaceConfiguration
|
let config = configAny as? SurfaceConfiguration
|
||||||
|
|
||||||
// Determine our desired direction
|
// Determine our desired direction and percent
|
||||||
guard let directionAny = notification.userInfo?["direction"] else { return }
|
guard let directionAny = notification.userInfo?["direction"] else { return }
|
||||||
guard let direction = directionAny as? ghostty_action_split_direction_e else { return }
|
guard let direction = directionAny as? ghostty_action_split_direction_e else { return }
|
||||||
|
guard let percentAny = notification.userInfo?["percent"] else { return }
|
||||||
|
guard let percent = percentAny as? Float else { return }
|
||||||
let splitDirection: SplitViewDirection
|
let splitDirection: SplitViewDirection
|
||||||
let swap: Bool
|
let swap: Bool
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
@ -243,6 +245,9 @@ extension Ghostty {
|
|||||||
// Setup our new container since we are now split
|
// Setup our new container since we are now split
|
||||||
let container = SplitNode.Container(from: leaf, direction: splitDirection, baseConfig: config)
|
let container = SplitNode.Container(from: leaf, direction: splitDirection, baseConfig: config)
|
||||||
|
|
||||||
|
// Set the split ratio
|
||||||
|
container.split = 1.0 - CGFloat(percent)
|
||||||
|
|
||||||
// Change the parent node. This will trigger the parent to relayout our views.
|
// Change the parent node. This will trigger the parent to relayout our views.
|
||||||
node = .split(container)
|
node = .split(container)
|
||||||
|
|
||||||
|
@ -963,12 +963,12 @@ extension Ghostty {
|
|||||||
|
|
||||||
@IBAction func splitRight(_ sender: Any) {
|
@IBAction func splitRight(_ sender: Any) {
|
||||||
guard let surface = self.surface else { return }
|
guard let surface = self.surface else { return }
|
||||||
ghostty_surface_split(surface, GHOSTTY_SPLIT_DIRECTION_RIGHT)
|
ghostty_surface_split(surface, GHOSTTY_SPLIT_DIRECTION_RIGHT, 0.5)
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func splitDown(_ sender: Any) {
|
@IBAction func splitDown(_ sender: Any) {
|
||||||
guard let surface = self.surface else { return }
|
guard let surface = self.surface else { return }
|
||||||
ghostty_surface_split(surface, GHOSTTY_SPLIT_DIRECTION_DOWN)
|
ghostty_surface_split(surface, GHOSTTY_SPLIT_DIRECTION_DOWN, 0.5)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func resetTerminal(_ sender: Any) {
|
@objc func resetTerminal(_ sender: Any) {
|
||||||
|
@ -1634,11 +1634,16 @@ pub const CAPI = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Request that the surface split in the given direction.
|
/// Request that the surface split in the given direction.
|
||||||
export fn ghostty_surface_split(ptr: *Surface, direction: apprt.action.SplitDirection) void {
|
export fn ghostty_surface_split(ptr: *Surface, direction: apprt.action.SplitDirection.Direction, percent: f32) void {
|
||||||
|
const split_direction = apprt.action.SplitDirection{
|
||||||
|
.direction = direction,
|
||||||
|
.percent = percent,
|
||||||
|
};
|
||||||
|
|
||||||
ptr.app.performAction(
|
ptr.app.performAction(
|
||||||
.{ .surface = &ptr.core_surface },
|
.{ .surface = &ptr.core_surface },
|
||||||
.new_split,
|
.new_split,
|
||||||
direction,
|
split_direction,
|
||||||
) catch |err| {
|
) catch |err| {
|
||||||
log.err("error creating new split err={}", .{err});
|
log.err("error creating new split err={}", .{err});
|
||||||
return;
|
return;
|
||||||
|
Reference in New Issue
Block a user