Re: GtkStatusIcon and popup menu
- From: "Chris tophe" <cohika gmail com>
- To: "Peter Lund" <firefly vax64 dk>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: GtkStatusIcon and popup menu
- Date: Tue, 7 Nov 2006 02:27:42 +0100
2006/11/7, Peter Lund <firefly vax64 dk>:
The program I wrote earlier this year just uses the "button-press-event"
signal. In the handler I create a menu and connect a deactivation function
to its "deactive" signal.
Seems to work fine.
-Peter
Thanks for your answer. I can't do this :
event_box = gtk_event_box_new();
gtk_container_add(GTK_CONTAINER(tray_icon), event_box);
Because GtkStatusIcon is not a widget.
Here is some example code that shows my problem :
int button_press_event_callback(GtkWidget* widget, GdkEvent* event)
{
GdkEventButton* event_button;
if(event->type == GDK_BUTTON_PRESS)
{
event_button = (GdkEventButton*)event;
if(event_button->button == 3)
{
/* this menu behaves normally */
gtk_menu_popup(GTK_MENU(widget), NULL, NULL, NULL, NULL,
event_button->button, event_button->time);
return TRUE;
}
}
return FALSE;
}
void popup_callback(GtkStatusIcon* icon, guint button, guint activate_time,
gpointer data)
{
/* this menu won't go away */
gtk_menu_popup(GTK_MENU(data), NULL, NULL, NULL, NULL, button,
activate_time);
}
int main(int argc, char* argv[])
{
GtkWidget* window;
GtkWidget* button;
GtkStatusIcon* trayicon;
GtkWidget* menu;
GtkWidget* menuitem;
gtk_init(&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
button = gtk_button_new_with_label("button");
gtk_container_add(GTK_CONTAINER(window), button);
trayicon = gtk_status_icon_new_from_file("some-nice-pic");
menu = gtk_menu_new();
menuitem = gtk_menu_item_new_with_label("hello");
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
gtk_widget_show(menuitem);
g_signal_connect(G_OBJECT(trayicon), "popup-menu",
G_CALLBACK(popup_callback), G_OBJECT(menu));
g_signal_connect_swapped(G_OBJECT(button), "button-press-event",
G_CALLBACK(button_press_event_callback), G_OBJECT(menu));
gtk_widget_show_all(window);
gtk_main();
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]