In Elementary OS Luna (or Ubuntu), how do I add an application Icon to the WingPanel (the top bar on the desktop that displays status icons like Wi-Fi connection status, Sound properties, and the Date and Time, for example?
I am using the Vala programming language.
There used to be an example on the https://wiki.gnome.org/Projects/Vala/Examples page dealing with adding a tray icon, which might solve this. I wasn't able to find the link to that, so I'll provide the source code and compile command here.
using Gtk;
public class Main {
class AppStatusIcon : Window {
private StatusIcon trayicon;
private Gtk.Menu menuSystem;
public AppStatusIcon() {
/* Create tray icon */
trayicon = new StatusIcon.from_stock(Stock.HOME);
trayicon.set_tooltip_text ("Tray");
trayicon.set_visible(true);
trayicon.activate.connect(about_clicked);
create_menuSystem();
trayicon.popup_menu.connect(menuSystem_popup);
}
/* Create menu for right button */
public void create_menuSystem() {
menuSystem = new Gtk.Menu();
var menuAbout = new ImageMenuItem.from_stock(Stock.ABOUT, null);
menuAbout.activate.connect(about_clicked);
menuSystem.append(menuAbout);
var menuQuit = new ImageMenuItem.from_stock(Stock.QUIT, null);
menuQuit.activate.connect(Gtk.main_quit);
menuSystem.append(menuQuit);
menuSystem.show_all();
}
/* Show popup menu on right button */
private void menuSystem_popup(uint button, uint time) {
menuSystem.popup(null, null, null, button, time);
}
private void about_clicked() {
var about = new AboutDialog();
about.set_version("0.0.0");
about.set_program_name("Tray");
about.set_comments("Tray utility");
about.set_copyright("vala");
about.run();
about.hide();
}
}
public static int main (string[] args) {
Gtk.init(ref args);
var App = new AppStatusIcon();
App.hide();
Gtk.main();
return 0;
}
}
The compile command that runs this is: valac icon_test.vala -o build_test --pkg gtk+-3.0
I'm not certain that this will add it to the panel the way that you want, but it does create traditional tray icons. Good luck. Hope this helps.