I want to change the panel icon to reflect changes in state.
This means I have two svg icons, and I want to change between them.
When the panel is being constructed, I create two st.Icon objects and save a global reference to them on the extension object, as well as the button object. Based on the state, I set the icon, which works when the shell starts. I always get the correct icon.
This is what I do when constructing the panel:
// ext is the extension object
this.button = new Button(0.0, _("an extension"));
ext.button = this.button;
ext.button_icon_auto_on = new St.Icon({
gicon: Gio.icon_new_for_string(`${Me.path}/icons/auto-on-symbolic.svg`),
style_class: "system-status-icon",
});
ext.button_icon_auto_off = new St.Icon({
gicon: Gio.icon_new_for_string(`${Me.path}/icons/auto-off-symbolic.svg`),
style_class: "system-status-icon",
});
then a few lines later based on the state, I do
this.button.icon = ext.button_icon_auto_on;
or the other one.
This is definitely working: I always get the correct icon when the shell starts.
Later, in an extension method to handle the keyboard shortcut for state toggling, I try again:
this.button.icon = this.button_icon_auto_off; //here, 'this' is the extension object
but this time, I don’t see any change to the panel icon.
Button is an extension of st.Widget but I can’t see any method that looks like it is a better way of updating the icon than assigning to it, but I don’t understand how this would trigger the shell to refresh the icon.
this sounds like it may be related, but it didn’t help me: