From cd8b2930050815420ae5e56669ecd40058cd14b5 Mon Sep 17 00:00:00 2001 From: clerie Date: Sat, 27 Sep 2025 21:15:56 +0200 Subject: [PATCH] Add toast overlay with signal --- src/application.vala | 2 ++ src/main.vala | 4 +++- src/window.ui | 54 ++++++++++++++++++++++++-------------------- src/window.vala | 15 +++++++++++- 4 files changed, 48 insertions(+), 27 deletions(-) diff --git a/src/application.vala b/src/application.vala index c905d12..fb29d57 100644 --- a/src/application.vala +++ b/src/application.vala @@ -19,6 +19,8 @@ */ public class Allesapp.Application : Adw.Application { + public signal void toast (string message, int timeout = 5); + public Application () { Object ( application_id: "de.clerie.allesapp", diff --git a/src/main.vala b/src/main.vala index 0348f8a..bb2c016 100644 --- a/src/main.vala +++ b/src/main.vala @@ -18,11 +18,13 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ +public static Allesapp.Application app; + int main (string[] args) { Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR); Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8"); Intl.textdomain (Config.GETTEXT_PACKAGE); - var app = new Allesapp.Application (); + app = new Allesapp.Application (); return app.run (args); } diff --git a/src/window.ui b/src/window.ui index 289c738..8d1821d 100644 --- a/src/window.ui +++ b/src/window.ui @@ -22,33 +22,37 @@ - - vertical + - - True - Meow meow meow - - - - - - - vertical - - - Meowwww - - - - - processes-symbolic - Fetch my IP address - - - + + vertical + + + True + Meow meow meow - + + + + + + vertical + + + Meowwww + + + + + processes-symbolic + Fetch my IP address + + + + + + + diff --git a/src/window.vala b/src/window.vala index 6eb11b2..6127d4c 100644 --- a/src/window.vala +++ b/src/window.vala @@ -23,10 +23,17 @@ public class Allesapp.Window : Adw.ApplicationWindow { [GtkChild] private unowned Gtk.Label my_ip_address_label; + [GtkChild] + private unowned Adw.ToastOverlay toast_overlay; + public Window (Gtk.Application app) { Object (application: app); } + construct { + app.toast.connect (add_toast); + } + [GtkCallback] private void on_fetch_my_ip_address () { @@ -36,7 +43,13 @@ public class Allesapp.Window : Adw.ApplicationWindow { var input_stream = session.send (msg); var data_input_stream = new DataInputStream (input_stream); - my_ip_address_label.set_label (data_input_stream.read_line_utf8()); + app.toast (data_input_stream.read_line_utf8()); } + + private void add_toast (string message, int timeout) { + toast_overlay.add_toast (new Adw.Toast (message) { + timeout = timeout + }); + } }