2

On my system for some reason the brightness indicator would not work to change the brightness. Although xbacklight did work to change the brightness.

I wrote an extension to run xbacklight whenever it changes the brightness. It works. Although it does not disable (not that I need it to, but I would like to have good code). I am not sure how to properly disable the extension. Here is all the code.

const Main = imports.ui.main;
const Lang = imports.lang;
const Util = imports.misc.util;
const Brightness = imports.ui.status.brightness;

const BrightnessIndicator = new Lang.Class({
    Name : 'BrightnessIndicator',
    Extends : Brightness.Indicator,
    _sync : function () {
        let visible = this._proxy.Brightness >= 0;
        this._item.actor.visible = visible;
        if (visible) {
            this._slider.setValue(this._proxy.Brightness / 100.0);
        }
        let percent = this._proxy.Brightness.toString();
        Util.spawn(['xbacklight', '-set', percent]);
    }
});

function init() {
}

function enable() {
    var indicator = new BrightnessIndicator();
    Main.panel.statusArea.aggregateMenu._brightness = indicator;
}

function disable() {
    delete indicator;
    Main.panel.statusArea.aggregateMenu._brightness = null;
}

I have also tried adding a variable from enable() to hold the old _brightness and then reseting _brightness to that in the disable() code.

Neither approach has worked for me so any help would be appreciated.

1 Answers1

0

First place I always check for GS extension questions is code in GitHub. In this case BrightnessIndicator extends panelMenu.SystemIndicator which doesn't offer you anything, so from there go up the inheritance until you find, for example, ClutterActor.destroy(). Then I guess just instantiate a new BrightnessIndicator just like how it's done in panel.js.

One thing to note is that disable() is also called when the desktop is locked.

andy.holmes
  • 3,383
  • 17
  • 28