Skip to content

Commit e6c7332

Browse files
committed
powee applet, settings: Add support for ambient light sensor.
Detects support via csd-power's dbus proxy, and adds switches to toggle auto-brightness. ref: linuxmint/cinnamon-settings-daemon#444
1 parent 9bc41ec commit e6c7332

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

files/usr/share/cinnamon/applets/[email protected]/applet.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const BrightnessBusName = "org.cinnamon.SettingsDaemon.Power.Screen";
1515
const KeyboardBusName = "org.cinnamon.SettingsDaemon.Power.Keyboard";
1616

1717
const CSD_BACKLIGHT_NOT_SUPPORTED_CODE = 1;
18+
const CSD_SCHEMA = "org.cinnamon.settings-daemon.plugins.power";
1819

1920
const PANEL_EDIT_MODE_KEY = "panel-edit-mode";
2021

@@ -256,7 +257,33 @@ class CinnamonPowerApplet extends Applet.TextIconApplet {
256257
this.brightness = new BrightnessSlider(this, _("Brightness"), "display-brightness", BrightnessBusName, 0);
257258
this.keyboard = new BrightnessSlider(this, _("Keyboard backlight"), "keyboard-brightness", KeyboardBusName, 0);
258259
this.menu.addMenuItem(this.brightness);
260+
261+
this._ambientItem = new PopupMenu.PopupSwitchMenuItem(_("Adjust automatically"), false);
262+
this._ambientItem.actor.hide();
263+
this.menu.addMenuItem(this._ambientItem);
264+
265+
this._brightnessSection = new PopupMenu.PopupSeparatorMenuItem();
266+
this._brightnessSection.actor.hide();
267+
this.menu.addMenuItem(this._brightnessSection);
268+
259269
this.menu.addMenuItem(this.keyboard);
270+
this._csdSettings = new Gio.Settings({ schema_id: CSD_SCHEMA });
271+
this._ambientItem.setToggleState(this._csdSettings.get_boolean("ambient-enabled"));
272+
this._ambientItem.connect("toggled", (item) => {
273+
this._csdSettings.set_boolean("ambient-enabled", item.state);
274+
});
275+
this._csdSettings.connect("changed::ambient-enabled", () => {
276+
this._ambientItem.setToggleState(this._csdSettings.get_boolean("ambient-enabled"));
277+
});
278+
279+
this.keyboard.actor.connect("notify::visible", () => this._updateBrightnessSeparator());
280+
281+
Interfaces.getDBusProxyAsync(BrightnessBusName, (proxy, error) => {
282+
if (error) return;
283+
this._screenProxy = proxy;
284+
this._updateAmbientVisibility();
285+
this._screenProxy.connect("g-properties-changed", () => this._updateAmbientVisibility());
286+
});
260287

261288
try {
262289
// Hadess interface
@@ -340,6 +367,23 @@ class CinnamonPowerApplet extends Applet.TextIconApplet {
340367
this.set_show_label_in_vertical_panels(false);
341368
}
342369

370+
_updateAmbientVisibility() {
371+
if (this._screenProxy && this._screenProxy.AmbientLightSupported) {
372+
this._ambientItem.actor.show();
373+
} else {
374+
this._ambientItem.actor.hide();
375+
}
376+
this._updateBrightnessSeparator();
377+
}
378+
379+
_updateBrightnessSeparator() {
380+
if (this._ambientItem.actor.visible && this.keyboard.actor.visible) {
381+
this._brightnessSection.actor.show();
382+
} else {
383+
this._brightnessSection.actor.hide();
384+
}
385+
}
386+
343387
_onPanelEditModeChanged() {
344388
if (global.settings.get_boolean(PANEL_EDIT_MODE_KEY)) {
345389
if (!this.actor.visible) {

files/usr/share/cinnamon/cinnamon-settings/modules/cs_power.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,13 @@ def on_module_selected(self):
267267
section = page.add_section(_("Screen brightness"))
268268
section.add_row(BrightnessSlider(section, proxy, _("Screen brightness")))
269269

270+
try:
271+
ambient_supported = proxy.get_cached_property("AmbientLightSupported")
272+
if ambient_supported is not None and ambient_supported.unpack():
273+
section.add_row(GSettingsSwitch(_("Adjust automatically"), CSD_SCHEMA, "ambient-enabled"))
274+
except Exception as e:
275+
print(f"Power module ambient light check failed: {e}")
276+
270277
section.add_row(GSettingsSwitch(_("On battery, dim screen when inactive"), CSD_SCHEMA, "idle-dim-battery"))
271278

272279
section.add_reveal_row(GSettingsComboBox(_("Brightness level when inactive"), CSD_SCHEMA, "idle-brightness", IDLE_BRIGHTNESS_OPTIONS, valtype=int, size_group=size_group), CSD_SCHEMA, "idle-dim-battery")

js/misc/interfaces.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ xml['org.cinnamon.SettingsDaemon.Power.Screen'] =
129129
<arg type='u' name='new_percentage' direction='out'/> \
130130
</method> \
131131
<signal name='Changed'/> \
132+
<property name='AmbientLightSupported' type='b' access='read'/> \
132133
</interface> \
133134
</node>",
134135
SETTINGS_DAEMON_POWER_NAME,

0 commit comments

Comments
 (0)