TransWikia.com

How to over write a function for gnome-shell which has only _init() {}

Stack Overflow Asked by UnKNOWn on January 9, 2021

from this link https://wiki.gnome.org/Projects/GnomeShell/Extensions/StepByStepTutorial if we search for inject, we notice "prototype"

But I am looking to extend/ overwrite this part, I cant user prototype in this case which is mentioned in above link/guide. So how to achieve this?

for example, I want to overwrite DEFAULT_BACKGROUND_COLOR with 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

One Answer

_init() is a function like any other, and can be overridden on the prototype of a class the same way:

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
};

Answered by andy.holmes on January 9, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP