Score:0

App status icon not showing on 20.04

mx flag

I have a test app built on Ubuntu 22.04 using gtk3 that basically does this to create a status icon with an attached menu:

#include <gtk/gtk.h>
//#include <glib/glib.h>


static void trayExit(GtkMenuItem *item,
                     gpointer user_data)
{
    printf("Quit\n");
    gtk_main_quit();
}


static void trayIconOnClick(GtkStatusIcon* statusIcon,
                            gpointer trayMenu)
{
    printf("Clicked on tray icon\n");
    gtk_menu_popup_at_pointer(GTK_MENU(trayMenu), nullptr);
}


static void trayIconOnMenu(GtkStatusIcon* statusIcon,
                           guint button, 
                           guint activateTime,
                           gpointer trayMenu)
{
    printf("Popup menu\n");
    gtk_menu_popup(GTK_MENU(trayMenu), nullptr, nullptr,
                   gtk_status_icon_position_menu, statusIcon,
                   button, activateTime);
}


static GtkWidget* createTrayMenu()
{
    auto* menu         = gtk_menu_new();
    auto* menuItemExit = gtk_menu_item_new_with_label ("Exit");

    g_signal_connect(G_OBJECT(menuItemExit), "activate", G_CALLBACK(trayExit), nullptr);
    gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuItemExit);
    gtk_widget_show_all(menu);
    return menu;
}


static GtkStatusIcon *createTrayIcon()
{
        auto* trayMenu = createTrayMenu();
        auto* trayIcon = gtk_status_icon_new();

        g_signal_connect(G_OBJECT(trayIcon), "activate", 
                         G_CALLBACK(trayIconOnClick), trayMenu);
        g_signal_connect(G_OBJECT(trayIcon), 
                         "popup-menu",
                         G_CALLBACK(trayIconOnMenu), trayMenu);
        gtk_status_icon_set_from_file(trayIcon, "/tmp/icon.png");
        gtk_status_icon_set_visible(trayIcon, TRUE);
        return trayIcon;
}

int main(int argc, char **argv)
{
        gtk_init(0, nullptr);
        auto trayIcon = createTrayIcon();
        gtk_main();
        return 0;
}

More info:

ubuntu: libgtk-3-dev
centos: gtk3-devel

g++ `pkg-config --cflags gtk+-3.0` -o main main.cpp `pkg-config --libs gtk+-3.0`
`pkg-config --cflags glib-2.0` `pkg-config --libs glib-2.0`

It works fine on 22.04. However, when I copy the app to 20.04, the status icon doesn't display. The app is running, ldd shows it's linking to the proper libraries, etc.

Does Ubuntu 20.04 treat status icons differently? I've installed some apps on 20.04 that use them, but I don't think they're written in C.

Levente avatar
cn flag
I have no idea, plus I am also unsure, but here is one thing I would look at: I know that stock Ubuntu **20.04** has a **Gnome 3** desktop. However I seem to believe that stock Ubuntu **22.04** may have a **Gnome 4** desktop. That's plenty of room for compatibility issues to pop up, I suspect.
us flag
Can you share the source/github project of the app?
complexmath avatar
mx flag
I've updated the post with a full sample program. GTK3 is on Ubuntu 20 and 22 but this behaves differently on each. I know there's been some contention about whether status icons should exist at all, and I thought maybe there was a policy difference between 20 and 22.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.