4 static GtkWidget *inhibit_entry;
5 static GtkWidget *inhibit_logout;
6 static GtkWidget *inhibit_switch;
7 static GtkWidget *inhibit_suspend;
8 static GtkWidget *inhibit_idle;
9 static GtkWidget *inhibit_label;
12 inhibitor_toggled (GtkToggleButton *button, GtkApplication *app)
16 GtkApplicationInhibitFlags flags;
20 active = gtk_toggle_button_get_active (button);
21 reason = gtk_entry_get_text (GTK_ENTRY (inhibit_entry));
24 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (inhibit_logout)))
25 flags |= GTK_APPLICATION_INHIBIT_LOGOUT;
26 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (inhibit_switch)))
27 flags |= GTK_APPLICATION_INHIBIT_SWITCH;
28 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (inhibit_suspend)))
29 flags |= GTK_APPLICATION_INHIBIT_SUSPEND;
30 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (inhibit_idle)))
31 flags |= GTK_APPLICATION_INHIBIT_IDLE;
33 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (button));
39 g_print ("Calling gtk_application_inhibit: %d, '%s'\n", flags, reason);
41 cookie = gtk_application_inhibit (app, GTK_WINDOW (toplevel), flags, reason);
42 g_object_set_data (G_OBJECT (button), "cookie", GUINT_TO_POINTER (cookie));
45 g_signal_handlers_block_by_func (button, inhibitor_toggled, app);
46 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), FALSE);
47 g_signal_handlers_unblock_by_func (button, inhibitor_toggled, app);
52 text = g_strdup_printf ("%#x", cookie);
53 gtk_label_set_label (GTK_LABEL (inhibit_label), text);
59 cookie = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (button), "cookie"));
60 g_print ("Calling gtk_application_uninhibit: %#x\n", cookie);
61 gtk_application_uninhibit (app, cookie);
62 gtk_label_set_label (GTK_LABEL (inhibit_label), "");
65 gtk_widget_set_sensitive (inhibit_entry, !active);
66 gtk_widget_set_sensitive (inhibit_logout, !active);
67 gtk_widget_set_sensitive (inhibit_switch, !active);
68 gtk_widget_set_sensitive (inhibit_suspend, !active);
69 gtk_widget_set_sensitive (inhibit_idle, !active);
73 activate (GtkApplication *app,
82 win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
84 box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
85 g_object_set (box, "margin", 12, NULL);
86 gtk_container_add (GTK_CONTAINER (win), box);
88 grid = gtk_grid_new ();
89 gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
90 gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
92 gtk_container_add (GTK_CONTAINER (box), grid);
94 label = gtk_label_new ("Inhibitor");
95 gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
97 inhibit_label = gtk_label_new ("");
98 gtk_grid_attach (GTK_GRID (grid), inhibit_label, 1, 0, 1, 1);
100 inhibit_logout = gtk_check_button_new_with_label ("Logout");
101 gtk_grid_attach (GTK_GRID (grid), inhibit_logout, 1, 1, 1, 1);
103 inhibit_switch = gtk_check_button_new_with_label ("User switching");
104 gtk_grid_attach (GTK_GRID (grid), inhibit_switch, 1, 2, 1, 1);
106 inhibit_suspend = gtk_check_button_new_with_label ("Suspend");
107 gtk_grid_attach (GTK_GRID (grid), inhibit_suspend, 1, 4, 1, 1);
109 inhibit_idle = gtk_check_button_new_with_label ("Idle");
110 gtk_grid_attach (GTK_GRID (grid), inhibit_idle, 1, 5, 1, 1);
112 inhibit_entry = gtk_entry_new ();
113 gtk_grid_attach (GTK_GRID (grid), inhibit_entry, 1, 6, 1, 1);
115 button = gtk_toggle_button_new_with_label ("Inhibit");
116 g_signal_connect (button, "toggled",
117 G_CALLBACK (inhibitor_toggled), app);
118 gtk_grid_attach (GTK_GRID (grid), button, 2, 6, 1, 1);
120 separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
121 gtk_container_add (GTK_CONTAINER (box), separator);
123 grid = gtk_grid_new ();
124 gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
125 gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
127 gtk_widget_show_all (win);
129 gtk_application_add_window (app, GTK_WINDOW (win));
133 quit (GtkApplication *app,
136 g_print ("Received quit\n");
137 gtk_widget_destroy (win);
141 main (int argc, char *argv[])
145 app = gtk_application_new ("org.gtk.Test.session", 0);
146 g_object_set (app, "register-session", TRUE, NULL);
148 g_signal_connect (app, "activate",
149 G_CALLBACK (activate), NULL);
150 g_signal_connect (app, "quit",
151 G_CALLBACK (quit), NULL);
153 g_application_run (G_APPLICATION (app), argc, argv);