macos: jump to last_tab

This commit is contained in:
Eduardo Dominguez
2024-08-19 12:19:00 -06:00
parent 1fd9cf2d08
commit 262902a28d
7 changed files with 47 additions and 0 deletions

View File

@ -143,6 +143,7 @@ typedef enum {
typedef enum { typedef enum {
GHOSTTY_TAB_PREVIOUS = -1, GHOSTTY_TAB_PREVIOUS = -1,
GHOSTTY_TAB_NEXT = -2, GHOSTTY_TAB_NEXT = -2,
GHOSTTY_TAB_LAST = -3,
} ghostty_tab_e; } ghostty_tab_e;
typedef enum { typedef enum {

View File

@ -724,6 +724,8 @@ class TerminalController: NSWindowController, NSWindowDelegate,
} else { } else {
finalIndex = selectedIndex + 1 finalIndex = selectedIndex + 1
} }
} else if (tabIndex == GHOSTTY_TAB_LAST.rawValue) {
finalIndex = tabbedWindows.count - 1
} else { } else {
return return
} }

View File

@ -379,6 +379,14 @@ extension Ghostty {
) )
} }
static func gotoLastTab(_ userdata: UnsafeMutableRawPointer?) {
let surface = self.surfaceUserdata(from: userdata)
NotificationCenter.default.post(
name: Notification.ghosttyGotoTab,
object: surface
)
}
static func readClipboard(_ userdata: UnsafeMutableRawPointer?, location: ghostty_clipboard_e, state: UnsafeMutableRawPointer?) { static func readClipboard(_ userdata: UnsafeMutableRawPointer?, location: ghostty_clipboard_e, state: UnsafeMutableRawPointer?) {
// If we don't even have a surface, something went terrible wrong so we have // If we don't even have a surface, something went terrible wrong so we have
// to leak "state". // to leak "state".

View File

@ -3429,6 +3429,19 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool
} else log.warn("runtime doesn't implement gotoNextTab", .{}); } else log.warn("runtime doesn't implement gotoNextTab", .{});
}, },
.last_tab => {
if (@hasDecl(apprt.Surface, "hasTabs")) {
if (!self.rt_surface.hasTabs()) {
log.debug("surface has no tabs, ignoring last_tab binding", .{});
return false;
}
}
if (@hasDecl(apprt.Surface, "gotoLastTab")) {
self.rt_surface.gotoLastTab();
} else log.warn("runtime doesn't implement gotoLastTab", .{});
},
.goto_tab => |n| { .goto_tab => |n| {
if (@hasDecl(apprt.Surface, "gotoTab")) { if (@hasDecl(apprt.Surface, "gotoTab")) {
self.rt_surface.gotoTab(n); self.rt_surface.gotoTab(n);

View File

@ -139,6 +139,7 @@ pub const App = struct {
const GotoTab = enum(i32) { const GotoTab = enum(i32) {
previous = -1, previous = -1,
next = -2, next = -2,
last = -3,
_, _,
}; };
@ -1008,6 +1009,15 @@ pub const Surface = struct {
func(self.userdata, @enumFromInt(idx)); func(self.userdata, @enumFromInt(idx));
} }
pub fn gotoLastTab(self: *Surface) void {
const func = self.app.opts.goto_tab orelse {
log.info("runtime embedder does not goto_tab", .{});
return;
};
func(self.userdata, .last);
}
pub fn gotoPreviousTab(self: *Surface) void { pub fn gotoPreviousTab(self: *Surface) void {
const func = self.app.opts.goto_tab orelse { const func = self.app.opts.goto_tab orelse {
log.info("runtime embedder does not goto_tab", .{}); log.info("runtime embedder does not goto_tab", .{});

View File

@ -1582,6 +1582,11 @@ pub fn default(alloc_gpa: Allocator) Allocator.Error!Config {
.{ .key = .{ .translated = .right }, .mods = .{ .ctrl = true, .shift = true } }, .{ .key = .{ .translated = .right }, .mods = .{ .ctrl = true, .shift = true } },
.{ .next_tab = {} }, .{ .next_tab = {} },
); );
try result.keybind.set.put(
alloc,
.{ .key = .{ .physical = inputpkg.Key.zero }, .mods = .{ .super = true } },
.{ .last_tab = {} },
);
try result.keybind.set.put( try result.keybind.set.put(
alloc, alloc,
.{ .key = .{ .translated = .page_up }, .mods = .{ .ctrl = true } }, .{ .key = .{ .translated = .page_up }, .mods = .{ .ctrl = true } },
@ -1850,6 +1855,11 @@ pub fn default(alloc_gpa: Allocator) Allocator.Error!Config {
.{ .key = .{ .translated = .right_bracket }, .mods = .{ .super = true, .shift = true } }, .{ .key = .{ .translated = .right_bracket }, .mods = .{ .super = true, .shift = true } },
.{ .next_tab = {} }, .{ .next_tab = {} },
); );
try result.keybind.set.put(
alloc,
.{ .key = .{ .physical = inputpkg.Key.zero }, .mods = .{ .super = true } },
.{ .last_tab = {} },
);
try result.keybind.set.put( try result.keybind.set.put(
alloc, alloc,
.{ .key = .{ .translated = .d }, .mods = .{ .super = true } }, .{ .key = .{ .translated = .d }, .mods = .{ .super = true } },

View File

@ -257,6 +257,9 @@ pub const Action = union(enum) {
/// Go to the next tab. /// Go to the next tab.
next_tab: void, next_tab: void,
/// Go to the last tab (the one with the highest index)
last_tab: void,
/// Go to the tab with the specific number, 1-indexed. /// Go to the tab with the specific number, 1-indexed.
goto_tab: usize, goto_tab: usize,