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.
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.
Stumbled upon the very same problem yesterday.
You have to do two things:
Step 1: add this code to you "stylesheet.css"
.your-icon-name {
background-image: url("icons/MyIcon.png");
background-size: 20px;
height: 20px;
width: 20px;
}
'background-size', 'height' and 'width' are just there to prescale the image, they can be left out to keep the original size.
Step 2: Write this in your .js file:
let icon = new St.Icon({style_class: 'your-icon-name'});
For anyone wanting to add their extension's icon/ (or images/, etc.) sub directory to the search path in order to use CSS styles here is what is working for me:
function init(metadata) {
// ...
let theme = imports.gi.Gtk.IconTheme.get_default();
theme.append_search_path(metadata.path + "/icons");
// ...
}
Here is a solution for GnomeShell v3.8.4: