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, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 * Mark McLoughlin <mark@skynet.ie>
32 static TestStatus status = TEST_STATUS_INFO;
33 static gint timeout = 0;
34 static GSList *icons = NULL;
37 size_changed_cb (GtkStatusIcon *icon,
40 g_print ("status icon %p size-changed size = %d\n", icon, size);
44 embedded_changed_cb (GtkStatusIcon *icon)
46 g_print ("status icon %p embedded changed to %d\n", icon,
47 gtk_status_icon_is_embedded (icon));
51 orientation_changed_cb (GtkStatusIcon *icon)
53 GtkOrientation orientation;
55 g_object_get (icon, "orientation", &orientation, NULL);
56 g_print ("status icon %p orientation changed to %d\n", icon, orientation);
66 if (status == TEST_STATUS_INFO)
68 icon_name = GTK_STOCK_DIALOG_INFO;
69 tooltip = "Some Infromation ...";
73 icon_name = GTK_STOCK_DIALOG_QUESTION;
74 tooltip = "Some Question ...";
77 for (l = icons; l; l = l->next)
79 GtkStatusIcon *status_icon = l->data;
81 gtk_status_icon_set_from_icon_name (status_icon, icon_name);
82 gtk_status_icon_set_tooltip (status_icon, tooltip);
87 timeout_handler (gpointer data)
89 if (status == TEST_STATUS_INFO)
90 status = TEST_STATUS_QUESTION;
92 status = TEST_STATUS_INFO;
100 blink_toggle_toggled (GtkToggleButton *toggle)
104 for (l = icons; l; l = l->next)
105 gtk_status_icon_set_blinking (GTK_STATUS_ICON (l->data),
106 gtk_toggle_button_get_active (toggle));
110 visible_toggle_toggled (GtkToggleButton *toggle)
114 for (l = icons; l; l = l->next)
115 gtk_status_icon_set_visible (GTK_STATUS_ICON (l->data),
116 gtk_toggle_button_get_active (toggle));
120 timeout_toggle_toggled (GtkToggleButton *toggle)
124 g_source_remove (timeout);
129 timeout = g_timeout_add (2000, timeout_handler, NULL);
134 icon_activated (GtkStatusIcon *icon)
139 dialog = g_object_get_data (G_OBJECT (icon), "test-status-icon-dialog");
142 dialog = gtk_message_dialog_new (NULL, 0,
143 GTK_MESSAGE_QUESTION,
145 "You wanna test the status icon ?");
147 gtk_window_set_screen (GTK_WINDOW (dialog), gtk_status_icon_get_screen (icon));
148 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
150 g_object_set_data_full (G_OBJECT (icon), "test-status-icon-dialog",
151 dialog, (GDestroyNotify) gtk_widget_destroy);
153 g_signal_connect (dialog, "response",
154 G_CALLBACK (gtk_widget_hide), NULL);
155 g_signal_connect (dialog, "delete_event",
156 G_CALLBACK (gtk_widget_hide_on_delete), NULL);
158 toggle = gtk_toggle_button_new_with_mnemonic ("_Show the icon");
159 gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dialog)->vbox), toggle, TRUE, TRUE, 6);
160 gtk_widget_show (toggle);
162 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
163 gtk_status_icon_get_visible (icon));
164 g_signal_connect (toggle, "toggled",
165 G_CALLBACK (visible_toggle_toggled), NULL);
167 toggle = gtk_toggle_button_new_with_mnemonic ("_Blink the icon");
168 gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dialog)->vbox), toggle, TRUE, TRUE, 6);
169 gtk_widget_show (toggle);
171 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
172 gtk_status_icon_get_blinking (icon));
173 g_signal_connect (toggle, "toggled",
174 G_CALLBACK (blink_toggle_toggled), NULL);
176 toggle = gtk_toggle_button_new_with_mnemonic ("_Change images");
177 gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dialog)->vbox), toggle, TRUE, TRUE, 6);
178 gtk_widget_show (toggle);
180 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
182 g_signal_connect (toggle, "toggled",
183 G_CALLBACK (timeout_toggle_toggled), NULL);
186 gtk_window_present (GTK_WINDOW (dialog));
190 check_activated (GtkCheckMenuItem *item)
197 for (l = icons; l; l = l->next)
199 GtkStatusIcon *icon = l->data;
200 GdkScreen *orig_screen;
202 orig_screen = gtk_status_icon_get_screen (icon);
205 gtk_status_icon_set_screen (icon, screen);
207 screen = orig_screen;
209 gtk_status_icon_set_blinking (icon,
210 gtk_check_menu_item_get_active (item));
213 g_assert (screen != NULL);
215 gtk_status_icon_set_screen (GTK_STATUS_ICON (icons->data), screen);
219 do_quit (GtkMenuItem *item)
223 for (l = icons; l; l = l->next)
225 GtkStatusIcon *icon = l->data;
227 gtk_status_icon_set_visible (icon, FALSE);
228 g_object_unref (icon);
231 g_slist_free (icons);
238 popup_menu (GtkStatusIcon *icon,
240 guint32 activate_time)
242 GtkWidget *menu, *menuitem;
244 menu = gtk_menu_new ();
246 gtk_menu_set_screen (GTK_MENU (menu),
247 gtk_status_icon_get_screen (icon));
249 menuitem = gtk_check_menu_item_new_with_label ("Blink");
250 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem),
251 gtk_status_icon_get_blinking (icon));
252 g_signal_connect (menuitem, "activate", G_CALLBACK (check_activated), NULL);
254 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
256 gtk_widget_show (menuitem);
258 menuitem = gtk_menu_item_new_with_label ("Quit");
259 g_signal_connect (menuitem, "activate", G_CALLBACK (do_quit), NULL);
261 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
263 gtk_widget_show (menuitem);
265 gtk_menu_popup (GTK_MENU (menu),
266 NULL, NULL, NULL, NULL,
267 button, activate_time);
271 main (int argc, char **argv)
276 gtk_init (&argc, &argv);
278 display = gdk_display_get_default ();
280 n_screens = gdk_display_get_n_screens (display);
282 for (i = 0; i < n_screens; i++)
286 icon = gtk_status_icon_new ();
287 gtk_status_icon_set_screen (icon, gdk_display_get_screen (display, i));
290 g_signal_connect (icon, "size-changed", G_CALLBACK (size_changed_cb), NULL);
291 g_signal_connect (icon, "notify::embedded", G_CALLBACK (embedded_changed_cb), NULL);
292 g_signal_connect (icon, "notify::orientation", G_CALLBACK (orientation_changed_cb), NULL);
293 g_print ("icon size %d\n", gtk_status_icon_get_size (icon));
294 gtk_status_icon_set_blinking (GTK_STATUS_ICON (icon), FALSE);
296 g_signal_connect (icon, "activate",
297 G_CALLBACK (icon_activated), NULL);
299 g_signal_connect (icon, "popup-menu",
300 G_CALLBACK (popup_menu), NULL);
302 icons = g_slist_append (icons, icon);
304 timeout = g_timeout_add (2000, timeout_handler, icon);