微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何为只有_init{}的gnome-shell写函数

如何解决如何为只有_init{}的gnome-shell写函数

通过此链接https://wiki.gnome.org/Projects/GnomeShell/Extensions/StepByStepTutorial,如果我们搜索注入,则会注意到“原型”

但是我希望扩展/覆盖这一部分,在这种情况下,我无法提供用户原型,以上链接/指南中已提及。那么如何实现呢?

例如,我想用DEFAULT_BACKGROUND_COLOR覆盖clutter.Color.from_string('#00ff00')

let _systemBackground;

var SystemBackground = GObject.registerClass({
    Signals: { 'loaded': {} },},class SystemBackground extends Meta.BackgroundActor {
    _init() {
        if (_systemBackground == null) {
            _systemBackground = new Meta.Background({ Meta_display: global.display });
            _systemBackground.set_color(DEFAULT_BACKGROUND_COLOR);
        }

        super._init({
            Meta_display: global.display,monitor: 0,});
        this.content.background = _systemBackground;

        let id = GLib.idle_add(GLib.PRIORITY_DEFAULT,() => {
            this.emit('loaded');
            return GLib.soURCE_REMOVE;
        });
        GLib.source.set_name_by_id(id,'[gnome-shell] SystemBackground.loaded');
    }
});

OS Arch Linux,gnome-shell --version 3.38.1

编辑:

我的目标是能够忽略上述问题而更改DEFAULT_BACKGROUND_COLOR可用的解决方案。

解决方法

_init()和其他函数一样,可以用相同的方法在类的原型上覆盖:

const Background = imports.ui.background;

Background.SystemBackground.prototype._init = function() {
    // Chaining-up to the super-class
    super._init({
        meta_display: global.display,monitor: 0,});

    // Whatever custom code you want to exectute
};

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。