Thread: GtkStatusIcon not showing icon in the tray !

  1. #1
    Registered User Ravi Raj's Avatar
    Join Date
    May 2012
    Location
    INDIA
    Posts
    43

    Exclamation GtkStatusIcon not showing icon in the tray !

    Hello friends,

    I am using GtkStatusIcon with libgtk+-3.0 to show status icon in the tray. Here is the code:

    Code:
    GtkStatusIcon *status_icon;status_icon = GTK_STATUS_ICON(gtk_builder_get_object(builder, "status_icon"));
        
    gtk_status_icon_set_from_pixbuf(status_icon, create_pixbuf(PATH_IMG_PACKAGE));
    gtk_status_icon_set_tooltip_text(status_icon, MSG_PKG_NAME);
    gtk_status_icon_set_visible(status_icon, TRUE);
    This code is compiling as normal, but no tray icon.
    Please help.

  2. #2
    Registered User Ravi Raj's Avatar
    Join Date
    May 2012
    Location
    INDIA
    Posts
    43
    bump...

  3. #3
    Registered User Annonymous's Avatar
    Join Date
    Apr 2011
    Location
    Jackson, New Jersey, United States
    Posts
    302
    @Ravi, If you are coding everything properly, then you most likely have to enable the notification area. I think the notification area might come whitelisted by default(If your using Ubuntu.)

    You can check by using the gtk_status_icon_is_embedded function. If it returns no then go here and follow the steps.

    Here is an example piece of code i threw together. Took me little bit but I learned some stuff in the process.

    Code:
    #include <gtk/gtk.h>
    
    static void destroy_event(GtkWidget *widget, gpointer data) {
    gtk_main_quit();
    }
    
    static gboolean delete_event(GtkWidget *widget, GdkEvent *event, gpointer data) {
    gtk_main_quit();
    return FALSE;
    }
    
    static void activate (GtkStatusIcon* status_icon, gpointer user_data) {
    g_debug("'activate' signal triggered");
    }
    
    
    //To compile append `pkg-config --cflags --libs gtk+-2.0`
    int main( int argc, char *argv[])
    {
    
      GtkWidget *window;
      GtkWidget *image;
      GtkWidget *table;
      GdkPixbuf *pixbuf;
      GtkStatusIcon *status_icon;
    
      gtk_init(&argc, &argv);
    
      window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
      gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
      gtk_window_set_default_size(GTK_WINDOW(window), 230, 150);
      gtk_window_set_title(GTK_WINDOW(window), "Pixbuf Example");
      gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
    
      table = gtk_table_new(10, 10, TRUE);
      gtk_container_add(GTK_CONTAINER(window), table);
      gtk_widget_show(table);
    
      pixbuf = gdk_pixbuf_new_from_file("/home/annonymous/Pictures/icon.png", NULL);
      image = gtk_image_new_from_pixbuf(pixbuf);
      //gtk_table_attach_defaults(GTK_TABLE(table), image, 1, 3, 1, 3);
      gtk_widget_show(image);
    
      status_icon = gtk_status_icon_new_from_pixbuf(pixbuf);
      gtk_status_icon_set_tooltip_text(GTK_STATUS_ICON(status_icon), "This is a tool tip");
      gtk_status_icon_set_visible(status_icon, TRUE);
      //gtk_widget_show(status_icon);
      g_debug("embedded: %s", gtk_status_icon_is_embedded(status_icon) ? "yes" : "no");
    
      g_signal_connect_swapped(G_OBJECT(window), "destroy-event",
          G_CALLBACK(destroy_event), G_OBJECT(window));
    
      g_signal_connect_swapped(G_OBJECT(window), "delete-event",
          G_CALLBACK(delete_event), NULL);
    
      g_signal_connect (G_OBJECT (status_icon), "activate",
          G_CALLBACK (activate), NULL);
    
      gtk_widget_show_all(window);
    
      gtk_main();
    
      return 0;
    }
    Hope this helps.
    Last edited by Annonymous; 05-20-2012 at 09:52 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Tray icon (taskbar) questions
    By maxorator in forum Windows Programming
    Replies: 3
    Last Post: 09-29-2006, 12:03 PM
  2. Tray icon
    By Scarvenger in forum Windows Programming
    Replies: 1
    Last Post: 09-11-2006, 06:24 PM
  3. KDE (Qt?) Tray Icon
    By Mokkan in forum C++ Programming
    Replies: 2
    Last Post: 07-25-2005, 12:21 AM
  4. Creating system tray icon popups
    By Archie77 in forum Windows Programming
    Replies: 1
    Last Post: 05-24-2004, 10:20 PM
  5. Getting coordinates of tray icon click
    By bennyandthejets in forum Windows Programming
    Replies: 8
    Last Post: 04-21-2004, 06:33 AM

Tags for this Thread