From 368a90c82a7b699c814b4d329f7fb30370d862c0 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Tue, 2 Aug 2011 16:25:41 -0400 Subject: [PATCH] test-attached: new program for testing attached dialogs https://bugzilla.gnome.org/show_bug.cgi?id=646761 --- .gitignore | 5 +- src/wm-tester/Makefile.am | 6 +- src/wm-tester/test-attached.c | 100 ++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 src/wm-tester/test-attached.c diff --git a/.gitignore b/.gitignore index 643535fa6..85853602d 100644 --- a/.gitignore +++ b/.gitignore @@ -56,10 +56,13 @@ mutter-mag mutter-message mutter-window-demo focus-window +test-attached test-gravity test-resizing test-size-hints -wm-tester +# We can't say just "wm-tester" here or it will ignore the directory +# rather than the binary +src/wm-tester/wm-tester INSTALL mkinstalldirs src/mutter-enum-types.[ch] diff --git a/src/wm-tester/Makefile.am b/src/wm-tester/Makefile.am index d1ab76187..1229f197b 100644 --- a/src/wm-tester/Makefile.am +++ b/src/wm-tester/Makefile.am @@ -16,10 +16,14 @@ test_resizing_SOURCES= \ test_size_hints_SOURCES= \ test-size-hints.c -noinst_PROGRAMS=wm-tester test-gravity test-resizing focus-window test-size-hints +test_attached_SOURCES= \ + test-attached.c + +noinst_PROGRAMS=wm-tester test-gravity test-resizing focus-window test-size-hints test-attached wm_tester_LDADD= @MUTTER_LIBS@ test_gravity_LDADD= @MUTTER_LIBS@ test_resizing_LDADD= @MUTTER_LIBS@ test_size_hints_LDADD= @MUTTER_LIBS@ focus_window_LDADD= @MUTTER_LIBS@ +test_attached_LDADD= @MUTTER_LIBS@ diff --git a/src/wm-tester/test-attached.c b/src/wm-tester/test-attached.c new file mode 100644 index 000000000..c27036b55 --- /dev/null +++ b/src/wm-tester/test-attached.c @@ -0,0 +1,100 @@ +#include + +enum { + DESTROY_PARENT, + DETACH, + ATTACH_1, + ATTACH_2 +}; + +GtkWidget *window1, *window2; + +static void +dialog_response (GtkDialog *dialog, int response, gpointer user_data) +{ + if (response == DESTROY_PARENT) + { + GtkWidget *window = GTK_WIDGET (gtk_window_get_transient_for (GTK_WINDOW (dialog))); + + if (window == window1) + { + gtk_dialog_set_response_sensitive (dialog, ATTACH_1, FALSE); + window1 = NULL; + } + else + { + gtk_dialog_set_response_sensitive (dialog, ATTACH_2, FALSE); + window2 = NULL; + } + + gtk_dialog_set_response_sensitive (dialog, DESTROY_PARENT, FALSE); + gtk_dialog_set_response_sensitive (dialog, DETACH, FALSE); + gtk_widget_destroy (window); + } + else if (response == DETACH) + { + gtk_window_set_transient_for (GTK_WINDOW (dialog), NULL); + gtk_dialog_set_response_sensitive (dialog, DESTROY_PARENT, FALSE); + gtk_dialog_set_response_sensitive (dialog, DETACH, FALSE); + gtk_dialog_set_response_sensitive (dialog, ATTACH_1, window1 != NULL); + gtk_dialog_set_response_sensitive (dialog, ATTACH_2, window2 != NULL); + } + else if (response == ATTACH_1) + { + gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window1)); + gtk_dialog_set_response_sensitive (dialog, DESTROY_PARENT, TRUE); + gtk_dialog_set_response_sensitive (dialog, DETACH, TRUE); + gtk_dialog_set_response_sensitive (dialog, ATTACH_1, FALSE); + gtk_dialog_set_response_sensitive (dialog, ATTACH_2, window2 != NULL); + } + else if (response == ATTACH_2) + { + gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window2)); + gtk_dialog_set_response_sensitive (dialog, DESTROY_PARENT, TRUE); + gtk_dialog_set_response_sensitive (dialog, DETACH, TRUE); + gtk_dialog_set_response_sensitive (dialog, ATTACH_1, window1 != NULL); + gtk_dialog_set_response_sensitive (dialog, ATTACH_2, FALSE); + } + else if (response == GTK_RESPONSE_CLOSE) + gtk_main_quit (); +} + +int +main (int argc, char **argv) +{ + GtkWidget *dialog; + + gtk_init (&argc, &argv); + + window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_window_set_title (GTK_WINDOW (window1), "Parent 1"); + gtk_widget_show (window1); + + window2 = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_window_set_title (GTK_WINDOW (window2), "Parent 2"); + gtk_widget_show (window2); + + dialog = gtk_dialog_new_with_buttons ("Child", + NULL, + GTK_DIALOG_MODAL, + "Destroy Parent", + DESTROY_PARENT, + "Detach", + DETACH, + "Attach to 1", + ATTACH_1, + "Attach to 2", + ATTACH_2, + GTK_STOCK_QUIT, + GTK_RESPONSE_CLOSE, + NULL); + gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), DESTROY_PARENT, FALSE); + gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), DETACH, FALSE); + + g_signal_connect (dialog, "response", G_CALLBACK (dialog_response), NULL); + gtk_widget_show (dialog); + + gtk_main (); + + return 0; +}