3 static GtkWidget *inhibit_entry;
4 static GtkWidget *inhibit_logout;
5 static GtkWidget *inhibit_switch;
6 static GtkWidget *inhibit_suspend;
7 static GtkWidget *inhibit_idle;
8 static GtkWidget *inhibit_label;
9 static GtkWidget *end_combo;
10 static GtkWidget *end_confirm;
13 end_session (GtkButton *button, GtkApplication *app)
16 GtkApplicationEndStyle style;
19 id = gtk_combo_box_get_active_id (GTK_COMBO_BOX (end_combo));
20 if (g_strcmp0 (id, "logout") == 0)
21 style = GTK_APPLICATION_LOGOUT;
22 else if (g_strcmp0 (id, "reboot") == 0)
23 style = GTK_APPLICATION_REBOOT;
24 else if (g_strcmp0 (id, "shutdown") == 0)
25 style = GTK_APPLICATION_SHUTDOWN;
27 style = GTK_APPLICATION_LOGOUT;
29 confirm = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (end_confirm));
31 g_print ("Calling gtk_application_end_session: %d, %d\n", style, confirm);
33 gtk_application_end_session (app, style, confirm);
37 inhibitor_toggled (GtkToggleButton *button, GtkApplication *app)
41 GtkApplicationInhibitFlags flags;
45 active = gtk_toggle_button_get_active (button);
46 reason = gtk_entry_get_text (GTK_ENTRY (inhibit_entry));
49 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (inhibit_logout)))
50 flags |= GTK_APPLICATION_INHIBIT_LOGOUT;
51 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (inhibit_switch)))
52 flags |= GTK_APPLICATION_INHIBIT_SWITCH;
53 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (inhibit_suspend)))
54 flags |= GTK_APPLICATION_INHIBIT_SUSPEND;
55 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (inhibit_idle)))
56 flags |= GTK_APPLICATION_INHIBIT_IDLE;
58 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (button));
64 g_print ("Calling gtk_application_inhibit: %d, '%s'\n", flags, reason);
66 cookie = gtk_application_inhibit (app, GTK_WINDOW (toplevel), flags, reason);
67 g_object_set_data (G_OBJECT (button), "cookie", GUINT_TO_POINTER (cookie));
70 g_signal_handlers_block_by_func (button, inhibitor_toggled, app);
71 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), FALSE);
72 g_signal_handlers_unblock_by_func (button, inhibitor_toggled, app);
77 text = g_strdup_printf ("%#x", cookie);
78 gtk_label_set_label (GTK_LABEL (inhibit_label), text);
84 cookie = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (button), "cookie"));
85 g_print ("Calling gtk_application_uninhibit: %#x\n", cookie);
86 gtk_application_uninhibit (app, cookie);
87 gtk_label_set_label (GTK_LABEL (inhibit_label), "");
90 gtk_widget_set_sensitive (inhibit_entry, !active);
91 gtk_widget_set_sensitive (inhibit_logout, !active);
92 gtk_widget_set_sensitive (inhibit_switch, !active);
93 gtk_widget_set_sensitive (inhibit_suspend, !active);
94 gtk_widget_set_sensitive (inhibit_idle, !active);
98 activate (GtkApplication *app,
103 GtkWidget *separator;
108 win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
110 box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
111 g_object_set (box, "margin", 12, NULL);
112 gtk_container_add (GTK_CONTAINER (win), box);
114 grid = gtk_grid_new ();
115 gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
116 gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
118 gtk_container_add (GTK_CONTAINER (box), grid);
120 label = gtk_label_new ("Inhibitor");
121 gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
123 inhibit_label = gtk_label_new ("");
124 gtk_grid_attach (GTK_GRID (grid), inhibit_label, 1, 0, 1, 1);
126 inhibit_logout = gtk_check_button_new_with_label ("Logout");
127 gtk_grid_attach (GTK_GRID (grid), inhibit_logout, 1, 1, 1, 1);
129 inhibit_switch = gtk_check_button_new_with_label ("User switching");
130 gtk_grid_attach (GTK_GRID (grid), inhibit_switch, 1, 2, 1, 1);
132 inhibit_suspend = gtk_check_button_new_with_label ("Suspend");
133 gtk_grid_attach (GTK_GRID (grid), inhibit_suspend, 1, 4, 1, 1);
135 inhibit_idle = gtk_check_button_new_with_label ("Idle");
136 gtk_grid_attach (GTK_GRID (grid), inhibit_idle, 1, 5, 1, 1);
138 inhibit_entry = gtk_entry_new ();
139 gtk_grid_attach (GTK_GRID (grid), inhibit_entry, 1, 6, 1, 1);
141 button = gtk_toggle_button_new_with_label ("Inhibit");
142 g_signal_connect (button, "toggled",
143 G_CALLBACK (inhibitor_toggled), app);
144 gtk_grid_attach (GTK_GRID (grid), button, 2, 6, 1, 1);
146 separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
147 gtk_container_add (GTK_CONTAINER (box), separator);
149 grid = gtk_grid_new ();
150 gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
151 gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
153 gtk_container_add (GTK_CONTAINER (box), grid);
155 end_combo = gtk_combo_box_text_new ();
156 gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (end_combo), "logout", "Logout");
157 gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (end_combo), "reboot", "Reboot");
158 gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (end_combo), "shutdown", "Shutdown");
159 gtk_combo_box_set_active_id (GTK_COMBO_BOX (end_combo), "logout");
160 gtk_grid_attach (GTK_GRID (grid), end_combo, 0, 0, 1, 1);
162 end_confirm = gtk_check_button_new_with_label ("Confirm");
163 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (end_confirm), TRUE);
164 gtk_grid_attach (GTK_GRID (grid), end_confirm, 1, 0, 1, 1);
166 button = gtk_button_new_with_label ("Go");
167 g_signal_connect (button, "clicked",
168 G_CALLBACK (end_session), app);
170 gtk_grid_attach (GTK_GRID (grid), button, 2, 0, 1, 1);
172 gtk_widget_show_all (win);
174 gtk_application_add_window (app, GTK_WINDOW (win));
178 quit (GtkApplication *app,
181 g_print ("Received quit\n");
185 main (int argc, char *argv[])
189 app = gtk_application_new ("org.gtk.Test.session", 0);
190 g_object_set (app, "register-session", TRUE, NULL);
192 g_signal_connect (app, "activate",
193 G_CALLBACK (activate), NULL);
194 g_signal_connect (app, "quit",
195 G_CALLBACK (quit), NULL);
197 g_application_run (G_APPLICATION (app), argc, argv);