1 /* gtkstatusicon-x11.c:
3 * Copyright (C) 2003 Sun Microsystems, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 * Mark McLoughlin <mark@skynet.ie>
25 #include "prop-editor.h"
33 static TestStatus status = TEST_STATUS_INFO;
34 static gint timeout = 0;
35 static GSList *icons = NULL;
38 size_changed_cb (GtkStatusIcon *icon,
41 g_print ("status icon %p size-changed size = %d\n", icon, size);
45 embedded_changed_cb (GtkStatusIcon *icon)
47 g_print ("status icon %p embedded changed to %d\n", icon,
48 gtk_status_icon_is_embedded (icon));
52 orientation_changed_cb (GtkStatusIcon *icon)
54 GtkOrientation orientation;
56 g_object_get (icon, "orientation", &orientation, NULL);
57 g_print ("status icon %p orientation changed to %d\n", icon, orientation);
61 screen_changed_cb (GtkStatusIcon *icon)
63 g_print ("status icon %p screen changed to %p\n", icon,
64 gtk_status_icon_get_screen (icon));
74 if (status == TEST_STATUS_INFO)
76 icon_name = "dialog-information";
77 tooltip = "Some Information ...";
81 icon_name = "dialog-question";
82 tooltip = "Some Question ...";
85 for (l = icons; l; l = l->next)
87 GtkStatusIcon *status_icon = l->data;
89 gtk_status_icon_set_from_icon_name (status_icon, icon_name);
90 gtk_status_icon_set_tooltip_text (status_icon, tooltip);
95 timeout_handler (gpointer data)
97 if (status == TEST_STATUS_INFO)
98 status = TEST_STATUS_QUESTION;
100 status = TEST_STATUS_INFO;
108 visible_toggle_toggled (GtkToggleButton *toggle)
112 for (l = icons; l; l = l->next)
113 gtk_status_icon_set_visible (GTK_STATUS_ICON (l->data),
114 gtk_toggle_button_get_active (toggle));
118 timeout_toggle_toggled (GtkToggleButton *toggle)
122 g_source_remove (timeout);
127 timeout = gdk_threads_add_timeout (2000, timeout_handler, NULL);
132 icon_activated (GtkStatusIcon *icon)
134 GtkWidget *content_area;
138 dialog = g_object_get_data (G_OBJECT (icon), "test-status-icon-dialog");
141 dialog = gtk_message_dialog_new (NULL, 0,
142 GTK_MESSAGE_QUESTION,
144 "You wanna test the status icon ?");
146 gtk_window_set_screen (GTK_WINDOW (dialog), gtk_status_icon_get_screen (icon));
147 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
149 g_object_set_data_full (G_OBJECT (icon), "test-status-icon-dialog",
150 dialog, (GDestroyNotify) gtk_widget_destroy);
152 g_signal_connect (dialog, "response",
153 G_CALLBACK (gtk_widget_hide), NULL);
154 g_signal_connect (dialog, "delete_event",
155 G_CALLBACK (gtk_widget_hide_on_delete), NULL);
157 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
159 toggle = gtk_toggle_button_new_with_mnemonic ("_Show the icon");
160 gtk_box_pack_end (GTK_BOX (content_area), toggle, TRUE, TRUE, 6);
161 gtk_widget_show (toggle);
163 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
164 gtk_status_icon_get_visible (icon));
165 g_signal_connect (toggle, "toggled",
166 G_CALLBACK (visible_toggle_toggled), NULL);
168 toggle = gtk_toggle_button_new_with_mnemonic ("_Change images");
169 gtk_box_pack_end (GTK_BOX (content_area), toggle, TRUE, TRUE, 6);
170 gtk_widget_show (toggle);
172 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
174 g_signal_connect (toggle, "toggled",
175 G_CALLBACK (timeout_toggle_toggled), NULL);
178 gtk_window_present (GTK_WINDOW (dialog));
182 do_properties (GtkMenuItem *item,
185 static GtkWidget *editor = NULL;
187 if (editor == NULL) {
188 editor = create_prop_editor (G_OBJECT (icon), GTK_TYPE_STATUS_ICON);
189 g_signal_connect (editor, "destroy", G_CALLBACK (gtk_widget_destroyed), &editor);
192 gtk_window_present (GTK_WINDOW (editor));
196 do_quit (GtkMenuItem *item)
200 for (l = icons; l; l = l->next)
202 GtkStatusIcon *icon = l->data;
204 gtk_status_icon_set_visible (icon, FALSE);
205 g_object_unref (icon);
208 g_slist_free (icons);
215 do_exit (GtkMenuItem *item)
221 popup_menu (GtkStatusIcon *icon,
223 guint32 activate_time)
225 GtkWidget *menu, *menuitem;
227 menu = gtk_menu_new ();
229 gtk_menu_set_screen (GTK_MENU (menu),
230 gtk_status_icon_get_screen (icon));
232 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_PROPERTIES, NULL);
233 g_signal_connect (menuitem, "activate", G_CALLBACK (do_properties), icon);
235 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
237 gtk_widget_show (menuitem);
239 menuitem = gtk_menu_item_new_with_label ("Quit");
240 g_signal_connect (menuitem, "activate", G_CALLBACK (do_quit), NULL);
242 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
244 gtk_widget_show (menuitem);
246 menuitem = gtk_menu_item_new_with_label ("Exit abruptly");
247 g_signal_connect (menuitem, "activate", G_CALLBACK (do_exit), NULL);
249 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
251 gtk_widget_show (menuitem);
253 gtk_menu_popup (GTK_MENU (menu),
255 gtk_status_icon_position_menu, icon,
256 button, activate_time);
260 main (int argc, char **argv)
265 gtk_init (&argc, &argv);
267 display = gdk_display_get_default ();
269 n_screens = gdk_display_get_n_screens (display);
271 for (i = 0; i < n_screens; i++)
275 icon = gtk_status_icon_new ();
276 gtk_status_icon_set_screen (icon, gdk_display_get_screen (display, i));
279 g_signal_connect (icon, "size-changed", G_CALLBACK (size_changed_cb), NULL);
280 g_signal_connect (icon, "notify::embedded", G_CALLBACK (embedded_changed_cb), NULL);
281 g_signal_connect (icon, "notify::orientation", G_CALLBACK (orientation_changed_cb), NULL);
282 g_signal_connect (icon, "notify::screen", G_CALLBACK (screen_changed_cb), NULL);
283 g_print ("icon size %d\n", gtk_status_icon_get_size (icon));
285 g_signal_connect (icon, "activate",
286 G_CALLBACK (icon_activated), NULL);
288 g_signal_connect (icon, "popup-menu",
289 G_CALLBACK (popup_menu), NULL);
291 icons = g_slist_append (icons, icon);
295 timeout = gdk_threads_add_timeout (2000, timeout_handler, icon);