mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 07:46:12 +03:00
apprt: make gotoTab handle all tab movements
This commit is contained in:
@ -3411,9 +3411,9 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool
|
||||
}
|
||||
}
|
||||
|
||||
if (@hasDecl(apprt.Surface, "gotoPreviousTab")) {
|
||||
self.rt_surface.gotoPreviousTab();
|
||||
} else log.warn("runtime doesn't implement gotoPreviousTab", .{});
|
||||
if (@hasDecl(apprt.Surface, "gotoTab")) {
|
||||
self.rt_surface.gotoTab(.previous);
|
||||
} else log.warn("runtime doesn't implement gotoTab", .{});
|
||||
},
|
||||
|
||||
.next_tab => {
|
||||
@ -3424,9 +3424,9 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool
|
||||
}
|
||||
}
|
||||
|
||||
if (@hasDecl(apprt.Surface, "gotoNextTab")) {
|
||||
self.rt_surface.gotoNextTab();
|
||||
} else log.warn("runtime doesn't implement gotoNextTab", .{});
|
||||
if (@hasDecl(apprt.Surface, "gotoTab")) {
|
||||
self.rt_surface.gotoTab(.next);
|
||||
} else log.warn("runtime doesn't implement gotoTab", .{});
|
||||
},
|
||||
|
||||
.last_tab => {
|
||||
@ -3437,14 +3437,14 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool
|
||||
}
|
||||
}
|
||||
|
||||
if (@hasDecl(apprt.Surface, "gotoLastTab")) {
|
||||
self.rt_surface.gotoLastTab();
|
||||
} else log.warn("runtime doesn't implement gotoLastTab", .{});
|
||||
if (@hasDecl(apprt.Surface, "gotoTab")) {
|
||||
self.rt_surface.gotoTab(.last);
|
||||
} else log.warn("runtime doesn't implement gotoTab", .{});
|
||||
},
|
||||
|
||||
.goto_tab => |n| {
|
||||
if (@hasDecl(apprt.Surface, "gotoTab")) {
|
||||
self.rt_surface.gotoTab(n);
|
||||
self.rt_surface.gotoTab(@enumFromInt(n));
|
||||
} else log.warn("runtime doesn't implement gotoTab", .{});
|
||||
},
|
||||
|
||||
|
@ -28,6 +28,7 @@ pub const ClipboardRequestType = structs.ClipboardRequestType;
|
||||
pub const ColorScheme = structs.ColorScheme;
|
||||
pub const CursorPos = structs.CursorPos;
|
||||
pub const DesktopNotification = structs.DesktopNotification;
|
||||
pub const GotoTab = structs.GotoTab;
|
||||
pub const IMEPos = structs.IMEPos;
|
||||
pub const Selection = structs.Selection;
|
||||
pub const SplitDirection = structs.SplitDirection;
|
||||
|
@ -108,7 +108,7 @@ pub const App = struct {
|
||||
toggle_split_zoom: ?*const fn (SurfaceUD) callconv(.C) void = null,
|
||||
|
||||
/// Goto tab
|
||||
goto_tab: ?*const fn (SurfaceUD, GotoTab) callconv(.C) void = null,
|
||||
goto_tab: ?*const fn (SurfaceUD, apprt.GotoTab) callconv(.C) void = null,
|
||||
|
||||
/// Toggle fullscreen for current window.
|
||||
toggle_fullscreen: ?*const fn (SurfaceUD, configpkg.NonNativeFullscreen) callconv(.C) void = null,
|
||||
@ -135,14 +135,6 @@ pub const App = struct {
|
||||
mouse_over_link: ?*const fn (SurfaceUD, ?[*]const u8, usize) void = null,
|
||||
};
|
||||
|
||||
/// Special values for the goto_tab callback.
|
||||
const GotoTab = enum(i32) {
|
||||
previous = -1,
|
||||
next = -2,
|
||||
last = -3,
|
||||
_,
|
||||
};
|
||||
|
||||
core_app: *CoreApp,
|
||||
config: *const Config,
|
||||
opts: Options,
|
||||
@ -995,45 +987,13 @@ pub const Surface = struct {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn gotoTab(self: *Surface, n: usize) void {
|
||||
pub fn gotoTab(self: *Surface, tab: apprt.GotoTab) void {
|
||||
const func = self.app.opts.goto_tab orelse {
|
||||
log.info("runtime embedder does not goto_tab", .{});
|
||||
return;
|
||||
};
|
||||
|
||||
const idx = std.math.cast(i32, n) orelse {
|
||||
log.warn("cannot cast tab index to i32 n={}", .{n});
|
||||
return;
|
||||
};
|
||||
|
||||
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 {
|
||||
const func = self.app.opts.goto_tab orelse {
|
||||
log.info("runtime embedder does not goto_tab", .{});
|
||||
return;
|
||||
};
|
||||
|
||||
func(self.userdata, .previous);
|
||||
}
|
||||
|
||||
pub fn gotoNextTab(self: *Surface) void {
|
||||
const func = self.app.opts.goto_tab orelse {
|
||||
log.info("runtime embedder does not goto_tab", .{});
|
||||
return;
|
||||
};
|
||||
|
||||
func(self.userdata, .next);
|
||||
func(self.userdata, tab);
|
||||
}
|
||||
|
||||
pub fn toggleFullscreen(self: *Surface, nonNativeFullscreen: configpkg.NonNativeFullscreen) void {
|
||||
|
@ -62,6 +62,16 @@ pub const DesktopNotification = struct {
|
||||
body: []const u8,
|
||||
};
|
||||
|
||||
/// The tab to jump to. This is non-exhaustive so that integer values represent
|
||||
/// the index (zero-based) of the tab to jump to. Negative values are special
|
||||
/// values.
|
||||
pub const GotoTab = enum(c_int) {
|
||||
previous = -1,
|
||||
next = -2,
|
||||
last = -3,
|
||||
_,
|
||||
};
|
||||
|
||||
// This is made extern (c_int) to make interop easier with our embedded
|
||||
// runtime. The small size cost doesn't make a difference in our union.
|
||||
pub const SplitDirection = enum(c_int) {
|
||||
|
Reference in New Issue
Block a user