mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-23 20:26:09 +03:00
Merge pull request #2235 from tristan957/toast
apprt/gtk: use toast UX from Adwaita if available
This commit is contained in:
@ -353,6 +353,13 @@ pub fn reloadConfig(self: *App) !?*const Config {
|
||||
log.warn("error handling configuration changes err={}", .{err});
|
||||
};
|
||||
|
||||
if (adwaita.enabled(&self.config)) {
|
||||
if (self.core_app.focusedSurface()) |core_surface| {
|
||||
const surface = core_surface.rt_surface;
|
||||
if (surface.container.window()) |window| window.onConfigReloaded();
|
||||
}
|
||||
}
|
||||
|
||||
return &self.config;
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,10 @@ notebook: Notebook,
|
||||
|
||||
context_menu: *c.GtkWidget,
|
||||
|
||||
/// The libadwaita widget for receiving toast send requests. If libadwaita is
|
||||
/// not used, this is null and unused.
|
||||
toast_overlay: ?*c.GtkWidget,
|
||||
|
||||
pub fn create(alloc: Allocator, app: *App) !*Window {
|
||||
// Allocate a fixed pointer for our window. We try to minimize
|
||||
// allocations but windows and other GUI requirements are so minimal
|
||||
@ -63,6 +67,7 @@ pub fn init(self: *Window, app: *App) !void {
|
||||
.header = null,
|
||||
.notebook = undefined,
|
||||
.context_menu = undefined,
|
||||
.toast_overlay = undefined,
|
||||
};
|
||||
|
||||
// Create the window
|
||||
@ -203,7 +208,17 @@ pub fn init(self: *Window, app: *App) !void {
|
||||
|
||||
// Setup our notebook
|
||||
self.notebook = Notebook.create(self);
|
||||
c.gtk_box_append(@ptrCast(box), self.notebook.asWidget());
|
||||
|
||||
// Setup our toast overlay if we have one
|
||||
self.toast_overlay = if (self.isAdwWindow()) toast: {
|
||||
const toast_overlay = c.adw_toast_overlay_new();
|
||||
c.adw_toast_overlay_set_child(
|
||||
@ptrCast(toast_overlay),
|
||||
@ptrCast(@alignCast(self.notebook.asWidget())),
|
||||
);
|
||||
c.gtk_box_append(@ptrCast(box), toast_overlay);
|
||||
break :toast toast_overlay;
|
||||
} else null;
|
||||
|
||||
// If we have a tab overview then we can set it on our notebook.
|
||||
if (tab_overview_) |tab_overview| {
|
||||
@ -462,6 +477,17 @@ pub fn focusCurrentTab(self: *Window) void {
|
||||
_ = c.gtk_widget_grab_focus(gl_area);
|
||||
}
|
||||
|
||||
pub fn onConfigReloaded(self: *Window) void {
|
||||
self.sendToast("Reloaded the configuration");
|
||||
}
|
||||
|
||||
fn sendToast(self: *Window, title: [:0]const u8) void {
|
||||
const toast_overlay = self.toast_overlay orelse return;
|
||||
const toast = c.adw_toast_new(title);
|
||||
c.adw_toast_set_timeout(toast, 3);
|
||||
c.adw_toast_overlay_add_toast(@ptrCast(toast_overlay), toast);
|
||||
}
|
||||
|
||||
// Note: we MUST NOT use the GtkButton parameter because gtkActionNewTab
|
||||
// sends an undefined value.
|
||||
fn gtkTabNewClick(_: *c.GtkButton, ud: ?*anyopaque) callconv(.C) void {
|
||||
@ -697,6 +723,10 @@ fn gtkActionCopy(
|
||||
log.warn("error performing binding action error={}", .{err});
|
||||
return;
|
||||
};
|
||||
|
||||
if (self.isAdwWindow()) {
|
||||
self.sendToast("Copied to clipboard");
|
||||
}
|
||||
}
|
||||
|
||||
fn gtkActionPaste(
|
||||
|
Reference in New Issue
Block a user