Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions files/usr/share/cinnamon/applets/power@cinnamon.org/applet.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const BrightnessBusName = "org.cinnamon.SettingsDaemon.Power.Screen";
const KeyboardBusName = "org.cinnamon.SettingsDaemon.Power.Keyboard";

const CSD_BACKLIGHT_NOT_SUPPORTED_CODE = 1;
const CSD_SCHEMA = "org.cinnamon.settings-daemon.plugins.power";

const PANEL_EDIT_MODE_KEY = "panel-edit-mode";

Expand Down Expand Up @@ -256,7 +257,33 @@ class CinnamonPowerApplet extends Applet.TextIconApplet {
this.brightness = new BrightnessSlider(this, _("Brightness"), "display-brightness", BrightnessBusName, 0);
this.keyboard = new BrightnessSlider(this, _("Keyboard backlight"), "keyboard-brightness", KeyboardBusName, 0);
this.menu.addMenuItem(this.brightness);

this._ambientItem = new PopupMenu.PopupSwitchMenuItem(_("Adjust automatically"), false);
this._ambientItem.actor.hide();
this.menu.addMenuItem(this._ambientItem);

this._brightnessSection = new PopupMenu.PopupSeparatorMenuItem();
this._brightnessSection.actor.hide();
this.menu.addMenuItem(this._brightnessSection);

this.menu.addMenuItem(this.keyboard);
this._csdSettings = new Gio.Settings({ schema_id: CSD_SCHEMA });
this._ambientItem.setToggleState(this._csdSettings.get_boolean("ambient-enabled"));
this._ambientItem.connect("toggled", (item) => {
this._csdSettings.set_boolean("ambient-enabled", item.state);
});
this._csdSettings.connect("changed::ambient-enabled", () => {
this._ambientItem.setToggleState(this._csdSettings.get_boolean("ambient-enabled"));
});

this.keyboard.actor.connect("notify::visible", () => this._updateBrightnessSeparator());

Interfaces.getDBusProxyAsync(BrightnessBusName, (proxy, error) => {
if (error) return;
this._screenProxy = proxy;
this._updateAmbientVisibility();
this._screenProxy.connect("g-properties-changed", () => this._updateAmbientVisibility());
});

try {
// Hadess interface
Expand Down Expand Up @@ -340,6 +367,23 @@ class CinnamonPowerApplet extends Applet.TextIconApplet {
this.set_show_label_in_vertical_panels(false);
}

_updateAmbientVisibility() {
if (this._screenProxy && this._screenProxy.AmbientLightSupported) {
this._ambientItem.actor.show();
} else {
this._ambientItem.actor.hide();
}
this._updateBrightnessSeparator();
}

_updateBrightnessSeparator() {
if (this._ambientItem.actor.visible && this.keyboard.actor.visible) {
this._brightnessSection.actor.show();
} else {
this._brightnessSection.actor.hide();
}
}

_onPanelEditModeChanged() {
if (global.settings.get_boolean(PANEL_EDIT_MODE_KEY)) {
if (!this.actor.visible) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,13 @@ def on_module_selected(self):
section = page.add_section(_("Screen brightness"))
section.add_row(BrightnessSlider(section, proxy, _("Screen brightness")))

try:
ambient_supported = proxy.get_cached_property("AmbientLightSupported")
if ambient_supported is not None and ambient_supported.unpack():
section.add_row(GSettingsSwitch(_("Adjust automatically"), CSD_SCHEMA, "ambient-enabled"))
except Exception as e:
print(f"Power module ambient light check failed: {e}")

section.add_row(GSettingsSwitch(_("On battery, dim screen when inactive"), CSD_SCHEMA, "idle-dim-battery"))

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")
Expand Down
1 change: 1 addition & 0 deletions js/misc/interfaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ xml['org.cinnamon.SettingsDaemon.Power.Screen'] =
<arg type='u' name='new_percentage' direction='out'/> \
</method> \
<signal name='Changed'/> \
<property name='AmbientLightSupported' type='b' access='read'/> \
</interface> \
</node>",
SETTINGS_DAEMON_POWER_NAME,
Expand Down
Loading