【发布时间】:2020-07-29 06:42:27
【问题描述】:
我尝试为我的 GNOME shell 扩展使用自定义 SVG 作为顶部面板中的状态图标。但自定义图标永远不会显示,只是小部件的标签文本。而且我在日志输出中没有发现错误。
当我尝试设置像“system-search-symbolic”这样的内置图标时,它会起作用,会显示这个图标。
这是我的代码 sn-p(SVG 位于我的扩展程序的“图标”目录中:/home/myusername/.local/share/gnome-shell/extensions/my-widget@my-widgets/icons/timeclock-16x16.svg):
// ...
let widgetBoxLayout = new St.BoxLayout();
let iconPath = `${Me.path}/icons/timeclock-16x16.svg`;
// just for debug if path is correct
log(`${Me.metadata.name}: Icon path=${iconPath}`);
let gicon = Gio.icon_new_for_string(`${iconPath}`);
let icon = new St.Icon({ gicon: gicon, style_class: 'system-status-icon', icon_size: 16 });
// this works for build-in icon:
//let icon = new St.Icon({ icon_name: 'system-search-symbolic', style_class: 'system-status-icon'});
widgetBoxLayout.add(icon);
widgetBoxLayout.add(this.widgetText);
//...
也许是图标路径中有一个“@”字符的问题? 但是为什么没有记录错误呢?
在状态面板中使用自定义图标的正确代码是什么?
(我有 GNOME Shell 3.30.2)
【问题讨论】:
标签: gio gnome-shell-extensions gjs