Search code examples
gnomegnome-shellgnome-shell-extensions

How to set a PNG file in a Gnome Shell extension for St.Icon


My Gnome Shell extension has a folder 'icons' and there is an icon file called 'MyIcon.png' inside. I want to take it as a parameter to an St.Icon object.

let icon = new St.Icon({ /* I need what to code here*/ });

Thanks for any help.

Selcuk.


Solution

  • Here is a solution for GnomeShell v3.8.4:

    const St = imports.gi.St;
    const Me = imports.misc.extensionUtils.getCurrentExtension();
    const Gio = imports.gi.Gio;
    let gicon = Gio.icon_new_for_string(Me.path + "/icons/my_icon.png");
    icon = new St.Icon({ gicon });