mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
apprt/gtk-ng: toasts
This commit is contained in:
@ -275,7 +275,10 @@ pub const Surface = extern struct {
|
|||||||
const impl = gobject.ext.defineSignal(
|
const impl = gobject.ext.defineSignal(
|
||||||
name,
|
name,
|
||||||
Self,
|
Self,
|
||||||
&.{},
|
&.{
|
||||||
|
apprt.Clipboard,
|
||||||
|
[*:0]const u8,
|
||||||
|
},
|
||||||
void,
|
void,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@ -2236,7 +2239,7 @@ const Clipboard = struct {
|
|||||||
Surface.signals.@"clipboard-write".impl.emit(
|
Surface.signals.@"clipboard-write".impl.emit(
|
||||||
self,
|
self,
|
||||||
null,
|
null,
|
||||||
.{},
|
.{ clipboard_type, val.ptr },
|
||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ const gobject = @import("gobject");
|
|||||||
const gtk = @import("gtk");
|
const gtk = @import("gtk");
|
||||||
|
|
||||||
const i18n = @import("../../../os/main.zig").i18n;
|
const i18n = @import("../../../os/main.zig").i18n;
|
||||||
|
const apprt = @import("../../../apprt.zig");
|
||||||
const input = @import("../../../input.zig");
|
const input = @import("../../../input.zig");
|
||||||
const CoreSurface = @import("../../../Surface.zig");
|
const CoreSurface = @import("../../../Surface.zig");
|
||||||
const gtk_version = @import("../gtk_version.zig");
|
const gtk_version = @import("../gtk_version.zig");
|
||||||
@ -122,7 +123,8 @@ pub const Window = extern struct {
|
|||||||
config: ?*Config = null,
|
config: ?*Config = null,
|
||||||
|
|
||||||
// Template bindings
|
// Template bindings
|
||||||
surface: *Surface = undefined,
|
surface: *Surface,
|
||||||
|
toast_overlay: *adw.ToastOverlay,
|
||||||
|
|
||||||
pub var offset: c_int = 0;
|
pub var offset: c_int = 0;
|
||||||
};
|
};
|
||||||
@ -227,6 +229,18 @@ pub const Window = extern struct {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Queue a simple text-based toast. All text-based toasts share the
|
||||||
|
/// same timeout for consistency.
|
||||||
|
///
|
||||||
|
// This is not `pub` because we should be using signals emitted by
|
||||||
|
// other widgets to trigger our toasts. Other objects should not
|
||||||
|
// trigger toasts directly.
|
||||||
|
fn addToast(self: *Window, title: [*:0]const u8) void {
|
||||||
|
const toast = adw.Toast.new(title);
|
||||||
|
toast.setTimeout(3);
|
||||||
|
self.private().toast_overlay.addToast(toast);
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------
|
//---------------------------------------------------------------
|
||||||
// Properties
|
// Properties
|
||||||
|
|
||||||
@ -264,6 +278,7 @@ pub const Window = extern struct {
|
|||||||
_: *gobject.ParamSpec,
|
_: *gobject.ParamSpec,
|
||||||
self: *Self,
|
self: *Self,
|
||||||
) callconv(.c) void {
|
) callconv(.c) void {
|
||||||
|
self.addToast(i18n._("Reloaded the configuration"));
|
||||||
self.syncAppearance();
|
self.syncAppearance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -377,6 +392,29 @@ pub const Window = extern struct {
|
|||||||
self.as(gtk.Window).destroy();
|
self.as(gtk.Window).destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn surfaceClipboardWrite(
|
||||||
|
_: *Surface,
|
||||||
|
clipboard_type: apprt.Clipboard,
|
||||||
|
text: [*:0]const u8,
|
||||||
|
self: *Self,
|
||||||
|
) callconv(.c) void {
|
||||||
|
// We only toast for the standard clipboard.
|
||||||
|
if (clipboard_type != .standard) return;
|
||||||
|
|
||||||
|
// We only toast if configured to
|
||||||
|
const priv = self.private();
|
||||||
|
const config_obj = priv.config orelse return;
|
||||||
|
const config = config_obj.get();
|
||||||
|
if (!config.@"app-notifications".@"clipboard-copy") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (text[0] != 0)
|
||||||
|
self.addToast(i18n._("Copied to clipboard"))
|
||||||
|
else
|
||||||
|
self.addToast(i18n._("Cleared clipboard"));
|
||||||
|
}
|
||||||
|
|
||||||
fn surfaceCloseRequest(
|
fn surfaceCloseRequest(
|
||||||
surface: *Surface,
|
surface: *Surface,
|
||||||
scope: *const Surface.CloseScope,
|
scope: *const Surface.CloseScope,
|
||||||
@ -542,9 +580,11 @@ pub const Window = extern struct {
|
|||||||
|
|
||||||
// Bindings
|
// Bindings
|
||||||
class.bindTemplateChildPrivate("surface", .{});
|
class.bindTemplateChildPrivate("surface", .{});
|
||||||
|
class.bindTemplateChildPrivate("toast_overlay", .{});
|
||||||
|
|
||||||
// Template Callbacks
|
// Template Callbacks
|
||||||
class.bindTemplateCallback("close_request", &windowCloseRequest);
|
class.bindTemplateCallback("close_request", &windowCloseRequest);
|
||||||
|
class.bindTemplateCallback("surface_clipboard_write", &surfaceClipboardWrite);
|
||||||
class.bindTemplateCallback("surface_close_request", &surfaceCloseRequest);
|
class.bindTemplateCallback("surface_close_request", &surfaceCloseRequest);
|
||||||
class.bindTemplateCallback("surface_toggle_fullscreen", &surfaceToggleFullscreen);
|
class.bindTemplateCallback("surface_toggle_fullscreen", &surfaceToggleFullscreen);
|
||||||
class.bindTemplateCallback("surface_toggle_maximize", &surfaceToggleMaximize);
|
class.bindTemplateCallback("surface_toggle_maximize", &surfaceToggleMaximize);
|
||||||
|
@ -43,10 +43,13 @@ template $GhosttyWindow: Adw.ApplicationWindow {
|
|||||||
visible: bind template.debug;
|
visible: bind template.debug;
|
||||||
}
|
}
|
||||||
|
|
||||||
$GhosttySurface surface {
|
Adw.ToastOverlay toast_overlay {
|
||||||
close-request => $surface_close_request();
|
$GhosttySurface surface {
|
||||||
toggle-fullscreen => $surface_toggle_fullscreen();
|
close-request => $surface_close_request();
|
||||||
toggle-maximize => $surface_toggle_maximize();
|
clipboard-write => $surface_clipboard_write();
|
||||||
|
toggle-fullscreen => $surface_toggle_fullscreen();
|
||||||
|
toggle-maximize => $surface_toggle_maximize();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -29,10 +29,27 @@ pub const IMEPos = struct {
|
|||||||
/// The clipboard type.
|
/// The clipboard type.
|
||||||
///
|
///
|
||||||
/// If this is changed, you must also update ghostty.h
|
/// If this is changed, you must also update ghostty.h
|
||||||
pub const Clipboard = enum(u2) {
|
pub const Clipboard = enum(Backing) {
|
||||||
standard = 0, // ctrl+c/v
|
standard = 0, // ctrl+c/v
|
||||||
selection = 1,
|
selection = 1,
|
||||||
primary = 2,
|
primary = 2,
|
||||||
|
|
||||||
|
// Our backing isn't is as small as we can in Zig, but a full
|
||||||
|
// C int if we're binding to C APIs.
|
||||||
|
const Backing = switch (build_config.app_runtime) {
|
||||||
|
.gtk, .@"gtk-ng" => c_int,
|
||||||
|
else => u2,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Make this a valid gobject if we're in a GTK environment.
|
||||||
|
pub const getGObjectType = switch (build_config.app_runtime) {
|
||||||
|
.gtk, .@"gtk-ng" => @import("gobject").ext.defineEnum(
|
||||||
|
Clipboard,
|
||||||
|
.{ .name = "GhosttyApprtClipboard" },
|
||||||
|
),
|
||||||
|
|
||||||
|
.none => void,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const ClipboardRequestType = enum(u8) {
|
pub const ClipboardRequestType = enum(u8) {
|
||||||
|
Reference in New Issue
Block a user