mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-17 01:06:08 +03:00
apprt/gtk: use toast UX from Adwaita if available
Notify the user with in-app notifications if libadwaita is available. Co-authored-by: Paul Berg <paul@ber.gp> Signed-off-by: Tristan Partin <tristan@partin.io>
This commit is contained in:
@ -353,6 +353,13 @@ pub fn reloadConfig(self: *App) !?*const Config {
|
|||||||
log.warn("error handling configuration changes err={}", .{err});
|
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;
|
return &self.config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +41,10 @@ notebook: Notebook,
|
|||||||
|
|
||||||
context_menu: *c.GtkWidget,
|
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 {
|
pub fn create(alloc: Allocator, app: *App) !*Window {
|
||||||
// Allocate a fixed pointer for our window. We try to minimize
|
// Allocate a fixed pointer for our window. We try to minimize
|
||||||
// allocations but windows and other GUI requirements are so minimal
|
// allocations but windows and other GUI requirements are so minimal
|
||||||
@ -63,6 +67,7 @@ pub fn init(self: *Window, app: *App) !void {
|
|||||||
.header = null,
|
.header = null,
|
||||||
.notebook = undefined,
|
.notebook = undefined,
|
||||||
.context_menu = undefined,
|
.context_menu = undefined,
|
||||||
|
.toast_overlay = undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create the window
|
// Create the window
|
||||||
@ -201,9 +206,15 @@ pub fn init(self: *Window, app: *App) !void {
|
|||||||
c.gtk_box_append(@ptrCast(box), warning_box);
|
c.gtk_box_append(@ptrCast(box), warning_box);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.toast_overlay = if (self.isAdwWindow())
|
||||||
|
c.adw_toast_overlay_new()
|
||||||
|
else
|
||||||
|
null;
|
||||||
|
|
||||||
// Setup our notebook
|
// Setup our notebook
|
||||||
self.notebook = Notebook.create(self);
|
self.notebook = Notebook.create(self);
|
||||||
c.gtk_box_append(@ptrCast(box), self.notebook.asWidget());
|
c.adw_toast_overlay_set_child(@ptrCast(self.toast_overlay), @ptrCast(@alignCast(self.notebook.asWidget())));
|
||||||
|
c.gtk_box_append(@ptrCast(box), self.toast_overlay);
|
||||||
|
|
||||||
// If we have a tab overview then we can set it on our notebook.
|
// If we have a tab overview then we can set it on our notebook.
|
||||||
if (tab_overview_) |tab_overview| {
|
if (tab_overview_) |tab_overview| {
|
||||||
@ -462,6 +473,18 @@ pub fn focusCurrentTab(self: *Window) void {
|
|||||||
_ = c.gtk_widget_grab_focus(gl_area);
|
_ = 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 {
|
||||||
|
if (self.toast_overlay) |toast_overlay| {
|
||||||
|
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
|
// Note: we MUST NOT use the GtkButton parameter because gtkActionNewTab
|
||||||
// sends an undefined value.
|
// sends an undefined value.
|
||||||
fn gtkTabNewClick(_: *c.GtkButton, ud: ?*anyopaque) callconv(.C) void {
|
fn gtkTabNewClick(_: *c.GtkButton, ud: ?*anyopaque) callconv(.C) void {
|
||||||
@ -697,6 +720,10 @@ fn gtkActionCopy(
|
|||||||
log.warn("error performing binding action error={}", .{err});
|
log.warn("error performing binding action error={}", .{err});
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (self.isAdwWindow()) {
|
||||||
|
self.sendToast("Copied to clipboard");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gtkActionPaste(
|
fn gtkActionPaste(
|
||||||
|
Reference in New Issue
Block a user