Toast

A helper object for class@ToastOverlay.

Toasts are meant to be passed into adw.toast_overlay.ToastOverlay.addToast as follows:

adw_toast_overlay_add_toast (overlay, adw_toast_new (_("Simple Toast")));

<picture> <source srcset="toast-simple-dark.png" media="(prefers-color-scheme: dark)"> <img src="toast-simple.png" alt="toast-simple"> </picture>

Toasts always have a close button. They emit the signal@Toast::dismissed signal when disappearing.

property@Toast:timeout determines how long the toast stays on screen, while property@Toast:priority determines how it behaves if another toast is already being displayed.

Toast titles use Pango markup by default, set property@Toast:use-markup to FALSE if this is unwanted.

property@Toast:custom-title can be used to replace the title label with a custom widget.

Actions

Toasts can have one button on them, with a label and an attached gio.action.Action.

AdwToast *toast = adw_toast_new (_("Toast with Action"));

adw_toast_set_button_label (toast, _("_Example"));
adw_toast_set_action_name (toast, "win.example");

adw_toast_overlay_add_toast (overlay, toast);

<picture> <source srcset="toast-action-dark.png" media="(prefers-color-scheme: dark)"> <img src="toast-action.png" alt="toast-action"> </picture>

Modifying toasts

Toasts can be modified after they have been shown. For this, an adw.toast.Toast reference must be kept around while the toast is visible.

A common use case for this is using toasts as undo prompts that stack with each other, allowing to batch undo the last deleted items:

1 
2 static void
3 toast_undo_cb (GtkWidget  *sender,
4                const char *action,
5                GVariant   *param)
6 {
7   // Undo the deletion
8 }
9 
10 static void
11 dismissed_cb (MyWindow *self)
12 {
13   self->undo_toast = NULL;
14 
15   // Permanently delete the items
16 }
17 
18 static void
19 delete_item (MyWindow *self,
20              MyItem   *item)
21 {
22   g_autofree char *title = NULL;
23   int n_items;
24 
25   // Mark the item as waiting for deletion
26   n_items = ... // The number of waiting items
27 
28   if (!self->undo_toast) {
29     self->undo_toast = adw_toast_new_format (_("‘%s’ deleted"), ...);
30 
31     adw_toast_set_priority (self->undo_toast, ADW_TOAST_PRIORITY_HIGH);
32     adw_toast_set_button_label (self->undo_toast, _("_Undo"));
33     adw_toast_set_action_name (self->undo_toast, "toast.undo");
34 
35     g_signal_connect_swapped (self->undo_toast, "dismissed",
36                               G_CALLBACK (dismissed_cb), self);
37 
38     adw_toast_overlay_add_toast (self->toast_overlay, self->undo_toast);
39 
40     return;
41   }
42 
43   title =
44     g_strdup_printf (ngettext ("<span font_features='tnum=1'>%d</span> item deleted",
45                                "<span font_features='tnum=1'>%d</span> items deleted",
46                                n_items), n_items);
47 
48   adw_toast_set_title (self->undo_toast, title);
49 
50   // Bump the toast timeout
51   adw_toast_overlay_add_toast (self->toast_overlay, g_object_ref (self->undo_toast));
52 }
53 
54 static void
55 my_window_class_init (MyWindowClass *klass)
56 {
57   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
58 
59   gtk_widget_class_install_action (widget_class, "toast.undo", NULL, toast_undo_cb);
60 }

<picture> <source srcset="toast-undo-dark.png" media="(prefers-color-scheme: dark)"> <img src="toast-undo.png" alt="toast-undo"> </picture>

Constructors

this
this(string title)

Creates a new adw.toast.Toast.

Members

Functions

connectButtonClicked
ulong connectButtonClicked(T callback, Flag!"After" after)

Connect to ButtonClicked signal.

connectDismissed
ulong connectDismissed(T callback, Flag!"After" after)

Connect to Dismissed signal.

dismiss
void dismiss()

Dismisses self.

getActionName
string getActionName()

Gets the name of the associated action.

getActionTargetValue
glib.variant.VariantG getActionTargetValue()

Gets the parameter for action invocations.

getButtonLabel
string getButtonLabel()

Gets the label to show on the button.

getCustomTitle
gtk.widget.Widget getCustomTitle()

Gets the custom title widget of self.

getPriority
adw.types.ToastPriority getPriority()

Gets priority for self.

getTimeout
uint getTimeout()

Gets timeout for self.

getTitle
string getTitle()

Gets the title that will be displayed on the toast.

getUseMarkup
bool getUseMarkup()

Gets whether to use Pango markup for the toast title.

setActionName
void setActionName(string actionName)

Sets the name of the associated action.

setActionTargetValue
void setActionTargetValue(glib.variant.VariantG actionTarget)

Sets the parameter for action invocations.

setButtonLabel
void setButtonLabel(string buttonLabel)

Sets the label to show on the button.

setCustomTitle
void setCustomTitle(gtk.widget.Widget widget)

Sets the custom title widget of self.

setDetailedActionName
void setDetailedActionName(string detailedActionName)

Sets the action name and its parameter.

setPriority
void setPriority(adw.types.ToastPriority priority)

Sets priority for self.

setTimeout
void setTimeout(uint timeout)

Sets timeout for self.

setTitle
void setTitle(string title)

Sets the title that will be displayed on the toast.

setUseMarkup
void setUseMarkup(bool useMarkup)

Whether to use Pango markup for the toast title.

Inherited Members

From ObjectG

setGObject
void setGObject(void* cObj, Flag!"Take" take)

Set the GObject of a D ObjectG wrapper.

cPtr
void* cPtr(Flag!"Dup" dup)

Get a pointer to the underlying C object.

ref_
void* ref_(void* gObj)

Calls g_object_ref() on a GObject.

unref
unref(void* gObj)

Calls g_object_unref() on a GObject.

getType
GType getType()

Get the GType of an object.

gType
GType gType [@property getter]

GObject GType property.

self
ObjectG self()

Convenience method to return this cast to a type. For use in D with statements.

getDObject
T getDObject(void* cptr, Flag!"Take" take)

Template to get the D object from a C GObject and cast it to the given D object type.

connectSignalClosure
ulong connectSignalClosure(string signalDetail, DClosure closure, Flag!"After" after)

Connect a D closure to an object signal.

setProperty
void setProperty(string propertyName, T val)

Template for setting a GObject property.

getProperty
T getProperty(string propertyName)

Template for getting a GObject property.

compatControl
size_t compatControl(size_t what, void* data)
bindProperty
gobject.binding.Binding bindProperty(string sourceProperty, gobject.object.ObjectG target, string targetProperty, gobject.types.BindingFlags flags)

Creates a binding between source_property on source and target_property on target.

bindPropertyFull
gobject.binding.Binding bindPropertyFull(string sourceProperty, gobject.object.ObjectG target, string targetProperty, gobject.types.BindingFlags flags, gobject.closure.Closure transformTo, gobject.closure.Closure transformFrom)

Creates a binding between source_property on source and target_property on target, allowing you to set the transformation functions to be used by the binding.

forceFloating
void forceFloating()

This function is intended for #GObject implementations to re-enforce a floating[floating-ref] object reference. Doing this is seldom required: all #GInitiallyUnowneds are created with a floating reference which usually just needs to be sunken by calling gobject.object.ObjectG.refSink.

freezeNotify
void freezeNotify()

Increases the freeze count on object. If the freeze count is non-zero, the emission of "notify" signals on object is stopped. The signals are queued until the freeze count is decreased to zero. Duplicate notifications are squashed so that at most one #GObject::notify signal is emitted for each property modified while the object is frozen.

getData
void* getData(string key)

Gets a named field from the objects table of associations (see gobject.object.ObjectG.setData).

getProperty
void getProperty(string propertyName, gobject.value.Value value)

Gets a property of an object.

getQdata
void* getQdata(glib.types.Quark quark)

This function gets back user data pointers stored via gobject.object.ObjectG.setQdata.

getv
void getv(string[] names, gobject.value.Value[] values)

Gets n_properties properties for an object. Obtained properties will be set to values. All properties must be valid. Warnings will be emitted and undefined behaviour may result if invalid properties are passed in.

isFloating
bool isFloating()

Checks whether object has a floating[floating-ref] reference.

notify
void notify(string propertyName)

Emits a "notify" signal for the property property_name on object.

notifyByPspec
void notifyByPspec(gobject.param_spec.ParamSpec pspec)

Emits a "notify" signal for the property specified by pspec on object.

refSink
gobject.object.ObjectG refSink()

Increase the reference count of object, and possibly remove the floating[floating-ref] reference, if object has a floating reference.

runDispose
void runDispose()

Releases all references to other objects. This can be used to break reference cycles.

setData
void setData(string key, void* data)

Each object carries around a table of associations from strings to pointers. This function lets you set an association.

setProperty
void setProperty(string propertyName, gobject.value.Value value)

Sets a property on an object.

stealData
void* stealData(string key)

Remove a specified datum from the object's data associations, without invoking the association's destroy handler.

stealQdata
void* stealQdata(glib.types.Quark quark)

This function gets back user data pointers stored via gobject.object.ObjectG.setQdata and removes the data from object without invoking its destroy() function (if any was set). Usually, calling this function is only required to update user data pointers with a destroy notifier, for example:

thawNotify
void thawNotify()

Reverts the effect of a previous call to gobject.object.ObjectG.freezeNotify. The freeze count is decreased on object and when it reaches zero, queued "notify" signals are emitted.

watchClosure
void watchClosure(gobject.closure.Closure closure)

This function essentially limits the life time of the closure to the life time of the object. That is, when the object is finalized, the closure is invalidated by calling gobject.closure.Closure.invalidate on it, in order to prevent invocations of the closure with a finalized (nonexisting) object. Also, gobject.object.ObjectG.ref_ and gobject.object.ObjectG.unref are added as marshal guards to the closure, to ensure that an extra reference count is held on object during invocation of the closure. Usually, this function will be called on closures that use this object as closure data.

connectNotify
ulong connectNotify(string detail, T callback, Flag!"After" after)

Connect to Notify signal.