[libnma/lr/gtk-4.0: 11/23] tests/run-vpn: make window closure work with Gtk4




commit 5238cfb1e0ab345ce3e8f38a389f4fcc8edbf539
Author: Lubomir Rintel <lkundrak v3 sk>
Date:   Thu Oct 7 12:18:28 2021 +0200

    tests/run-vpn: make window closure work with Gtk4

 src/tests/run-vpn.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
---
diff --git a/src/tests/run-vpn.c b/src/tests/run-vpn.c
index 40ec610b..12d295c2 100644
--- a/src/tests/run-vpn.c
+++ b/src/tests/run-vpn.c
@@ -14,13 +14,10 @@
 #include <stdlib.h>
 
 static gboolean
-window_deleted (GtkWidget *widget,
-                GdkEvent *event,
-                gpointer user_data)
+window_deleted (GMainLoop *main_loop)
 {
-       GMainLoop *main_loop = user_data;
        g_main_loop_quit (main_loop);
-       return TRUE;
+       return FALSE;
 }
 
 int
@@ -66,19 +63,24 @@ main (int argc, char *argv[])
        main_loop = g_main_loop_new (NULL, FALSE);
        window = gtk_window_new ();
        gtk_widget_show (window);
-       g_signal_connect (G_OBJECT (window), "delete-event", G_CALLBACK (window_deleted), main_loop);
+
+#if GTK_CHECK_VERSION(4,0,0)
+       g_signal_connect_swapped (window, "close-request", G_CALLBACK (window_deleted), main_loop);
+#else
+       g_signal_connect_swapped (window, "delete-event", G_CALLBACK (window_deleted), main_loop);
+#endif
 
        widget = GTK_WIDGET (nm_vpn_editor_get_widget (editor));
        gtk_widget_show (widget);
-       gtk_container_add (GTK_CONTAINER (window), widget);
+       gtk_window_set_child (GTK_WINDOW (window), widget);
        g_main_loop_run (main_loop);
+       g_main_loop_unref (main_loop);
 
        if (!nm_vpn_editor_update_connection (editor, connection, &error)) {
                g_printerr ("Error: %s\n", error->message);
                return EXIT_FAILURE;
        }
 
-       gtk_widget_destroy (widget);
        nm_connection_dump (connection);
 
        return EXIT_SUCCESS;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]