apprt/gtk: handle pwd action

Use it as a tooltip for the tab.

Signed-off-by: Tristan Partin <tristan@partin.io>
This commit is contained in:
Tristan Partin
2024-11-15 23:22:00 -06:00
parent 4a71812352
commit 9c25811576
4 changed files with 34 additions and 1 deletions

View File

@ -465,6 +465,7 @@ pub fn performAction(
.inspector => self.controlInspector(target, value), .inspector => self.controlInspector(target, value),
.desktop_notification => self.showDesktopNotification(target, value), .desktop_notification => self.showDesktopNotification(target, value),
.set_title => try self.setTitle(target, value), .set_title => try self.setTitle(target, value),
.pwd => try self.setPwd(target, value),
.present_terminal => self.presentTerminal(target), .present_terminal => self.presentTerminal(target),
.initial_size => try self.setInitialSize(target, value), .initial_size => try self.setInitialSize(target, value),
.mouse_visibility => self.setMouseVisibility(target, value), .mouse_visibility => self.setMouseVisibility(target, value),
@ -486,7 +487,6 @@ pub fn performAction(
.render_inspector, .render_inspector,
.renderer_health, .renderer_health,
.color_change, .color_change,
.pwd,
=> log.warn("unimplemented action={}", .{action}), => log.warn("unimplemented action={}", .{action}),
} }
} }
@ -717,6 +717,17 @@ fn setTitle(
} }
} }
fn setPwd(
_: *App,
target: apprt.Target,
pwd: apprt.action.Pwd,
) !void {
switch (target) {
.app => {},
.surface => |v| try v.rt_surface.setPwd(pwd.pwd),
}
}
fn setMouseVisibility( fn setMouseVisibility(
_: *App, _: *App,
target: apprt.Target, target: apprt.Target,

View File

@ -868,6 +868,13 @@ pub fn getTitle(self: *Surface) ?[:0]const u8 {
return null; return null;
} }
pub fn setPwd(self: *Surface, pwd: [:0]const u8) !void {
// If we have a tab and are the focused child, then we have to update the tab
if (self.container.tab()) |tab| {
tab.setTooltipText(pwd);
}
}
pub fn setMouseShape( pub fn setMouseShape(
self: *Surface, self: *Surface,
shape: terminal.MouseShape, shape: terminal.MouseShape,

View File

@ -112,6 +112,10 @@ pub fn setLabelText(self: *Tab, title: [:0]const u8) void {
self.window.notebook.setTabLabel(self, title); self.window.notebook.setTabLabel(self, title);
} }
pub fn setTooltipText(self: *Tab, tooltip: [:0]const u8) void {
self.window.notebook.setTabTooltip(self, tooltip);
}
/// Remove this tab from the window. /// Remove this tab from the window.
pub fn remove(self: *Tab) void { pub fn remove(self: *Tab) void {
self.window.closeTab(self); self.window.closeTab(self);

View File

@ -223,6 +223,17 @@ pub const Notebook = union(enum) {
} }
} }
pub fn setTabTooltip(self: Notebook, tab: *Tab, tooltip: [:0]const u8) void {
switch (self) {
.adw_tab_view => |tab_view| {
if (comptime !adwaita.versionAtLeast(0, 0, 0)) unreachable;
const page = c.adw_tab_view_get_page(tab_view, @ptrCast(tab.box));
c.adw_tab_page_set_tooltip(page, tooltip.ptr);
},
.gtk_notebook => c.gtk_widget_set_tooltip_text(@ptrCast(@alignCast(tab.label_text)), tooltip.ptr),
}
}
fn newTabInsertPosition(self: Notebook, tab: *Tab) c_int { fn newTabInsertPosition(self: Notebook, tab: *Tab) c_int {
const numPages = self.nPages(); const numPages = self.nPages();
return switch (tab.window.app.config.@"window-new-tab-position") { return switch (tab.window.app.config.@"window-new-tab-position") {