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>
27 #include "prop-editor.h"
35 static TestStatus status = TEST_STATUS_INFO;
36 static gint timeout = 0;
37 static GSList *icons = NULL;
40 size_changed_cb (GtkStatusIcon *icon,
43 g_print ("status icon %p size-changed size = %d\n", icon, size);
47 embedded_changed_cb (GtkStatusIcon *icon)
49 g_print ("status icon %p embedded changed to %d\n", icon,
50 gtk_status_icon_is_embedded (icon));
54 orientation_changed_cb (GtkStatusIcon *icon)
56 GtkOrientation orientation;
58 g_object_get (icon, "orientation", &orientation, NULL);
59 g_print ("status icon %p orientation changed to %d\n", icon, orientation);
63 screen_changed_cb (GtkStatusIcon *icon)
65 g_print ("status icon %p screen changed to %p\n", icon,
66 gtk_status_icon_get_screen (icon));
76 if (status == TEST_STATUS_INFO)
78 icon_name = "dialog-information";
79 tooltip = "Some Information ...";
83 icon_name = "dialog-question";
84 tooltip = "Some Question ...";
87 for (l = icons; l; l = l->next)
89 GtkStatusIcon *status_icon = l->data;
91 gtk_status_icon_set_from_icon_name (status_icon, icon_name);
92 gtk_status_icon_set_tooltip_text (status_icon, tooltip);
97 timeout_handler (gpointer data)
99 if (status == TEST_STATUS_INFO)
100 status = TEST_STATUS_QUESTION;
102 status = TEST_STATUS_INFO;
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 = gdk_threads_add_timeout (2000, timeout_handler, NULL);
134 icon_activated (GtkStatusIcon *icon)
136 GtkWidget *content_area;
140 dialog = g_object_get_data (G_OBJECT (icon), "test-status-icon-dialog");
143 dialog = gtk_message_dialog_new (NULL, 0,
144 GTK_MESSAGE_QUESTION,
146 "You wanna test the status icon ?");
148 gtk_window_set_screen (GTK_WINDOW (dialog), gtk_status_icon_get_screen (icon));
149 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
151 g_object_set_data_full (G_OBJECT (icon), "test-status-icon-dialog",
152 dialog, (GDestroyNotify) gtk_widget_destroy);
154 g_signal_connect (dialog, "response",
155 G_CALLBACK (gtk_widget_hide), NULL);
156 g_signal_connect (dialog, "delete_event",
157 G_CALLBACK (gtk_widget_hide_on_delete), NULL);
159 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
161 toggle = gtk_toggle_button_new_with_mnemonic ("_Show the icon");
162 gtk_box_pack_end (GTK_BOX (content_area), toggle, TRUE, TRUE, 6);
163 gtk_widget_show (toggle);
165 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
166 gtk_status_icon_get_visible (icon));
167 g_signal_connect (toggle, "toggled",
168 G_CALLBACK (visible_toggle_toggled), NULL);
170 toggle = gtk_toggle_button_new_with_mnemonic ("_Change images");
171 gtk_box_pack_end (GTK_BOX (content_area), toggle, TRUE, TRUE, 6);
172 gtk_widget_show (toggle);
174 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
176 g_signal_connect (toggle, "toggled",
177 G_CALLBACK (timeout_toggle_toggled), NULL);
180 gtk_window_present (GTK_WINDOW (dialog));
184 do_properties (GtkMenuItem *item,
187 static GtkWidget *editor = NULL;
189 if (editor == NULL) {
190 editor = create_prop_editor (G_OBJECT (icon), GTK_TYPE_STATUS_ICON);
191 g_signal_connect (editor, "destroy", G_CALLBACK (gtk_widget_destroyed), &editor);
194 gtk_window_present (GTK_WINDOW (editor));
198 do_quit (GtkMenuItem *item)
202 for (l = icons; l; l = l->next)
204 GtkStatusIcon *icon = l->data;
206 gtk_status_icon_set_visible (icon, FALSE);
207 g_object_unref (icon);
210 g_slist_free (icons);
217 do_exit (GtkMenuItem *item)
223 popup_menu (GtkStatusIcon *icon,
225 guint32 activate_time)
227 GtkWidget *menu, *menuitem;
229 menu = gtk_menu_new ();
231 gtk_menu_set_screen (GTK_MENU (menu),
232 gtk_status_icon_get_screen (icon));
234 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_PROPERTIES, NULL);
235 g_signal_connect (menuitem, "activate", G_CALLBACK (do_properties), icon);
237 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
239 gtk_widget_show (menuitem);
241 menuitem = gtk_menu_item_new_with_label ("Quit");
242 g_signal_connect (menuitem, "activate", G_CALLBACK (do_quit), NULL);
244 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
246 gtk_widget_show (menuitem);
248 menuitem = gtk_menu_item_new_with_label ("Exit abruptly");
249 g_signal_connect (menuitem, "activate", G_CALLBACK (do_exit), NULL);
251 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
253 gtk_widget_show (menuitem);
255 gtk_menu_popup (GTK_MENU (menu),
257 gtk_status_icon_position_menu, icon,
258 button, activate_time);
262 main (int argc, char **argv)
267 gtk_init (&argc, &argv);
269 display = gdk_display_get_default ();
271 n_screens = gdk_display_get_n_screens (display);
273 for (i = 0; i < n_screens; i++)
277 icon = gtk_status_icon_new ();
278 gtk_status_icon_set_screen (icon, gdk_display_get_screen (display, i));
281 g_signal_connect (icon, "size-changed", G_CALLBACK (size_changed_cb), NULL);
282 g_signal_connect (icon, "notify::embedded", G_CALLBACK (embedded_changed_cb), NULL);
283 g_signal_connect (icon, "notify::orientation", G_CALLBACK (orientation_changed_cb), NULL);
284 g_signal_connect (icon, "notify::screen", G_CALLBACK (screen_changed_cb), NULL);
285 g_print ("icon size %d\n", gtk_status_icon_get_size (icon));
287 g_signal_connect (icon, "activate",
288 G_CALLBACK (icon_activated), NULL);
290 g_signal_connect (icon, "popup-menu",
291 G_CALLBACK (popup_menu), NULL);
293 icons = g_slist_append (icons, icon);
297 timeout = gdk_threads_add_timeout (2000, timeout_handler, icon);