[gnome-shell] status/nightLight: Port to quick settings
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] status/nightLight: Port to quick settings
- Date: Tue, 2 Aug 2022 16:09:07 +0000 (UTC)
commit 1459173bc9969d799addd6cc3c0c48d9f669758c
Author: Florian Müllner <fmuellner gnome org>
Date: Sun Jul 24 20:18:55 2022 +0200
status/nightLight: Port to quick settings
Night-light is now a simple, always visible toggle that directly
controls the underlying setting. No change to the top bar icon,
which is still only shown while night-light is active (read: at night).
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2392>
js/ui/panel.js | 6 ++---
js/ui/status/nightLight.js | 63 +++++++++++++++++++++-------------------------
2 files changed, 31 insertions(+), 38 deletions(-)
---
diff --git a/js/ui/panel.js b/js/ui/panel.js
index e487f4518e..0700044fc9 100644
--- a/js/ui/panel.js
+++ b/js/ui/panel.js
@@ -389,9 +389,7 @@ class AggregateMenu extends PanelMenu.Button {
this._volume = new imports.ui.status.volume.Indicator();
this._brightness = new imports.ui.status.brightness.Indicator();
this._system = new imports.ui.status.system.Indicator();
- this._nightLight = new imports.ui.status.nightLight.Indicator();
- this._indicators.add_child(this._nightLight);
if (this._network)
this._indicators.add_child(this._network);
if (this._bluetooth)
@@ -413,7 +411,6 @@ class AggregateMenu extends PanelMenu.Button {
this.menu.addMenuItem(this._rfkill.menu);
this.menu.addMenuItem(this._power.menu);
this.menu.addMenuItem(this._powerProfiles.menu);
- this.menu.addMenuItem(this._nightLight.menu);
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
this.menu.addMenuItem(this._system.menu);
@@ -439,16 +436,19 @@ class QuickSettings extends PanelMenu.Button {
this._remoteAccess = new imports.ui.status.remoteAccess.RemoteAccessApplet();
this._location = new imports.ui.status.location.Indicator();
this._thunderbolt = new imports.ui.status.thunderbolt.Indicator();
+ this._nightLight = new imports.ui.status.nightLight.Indicator();
this._unsafeMode = new UnsafeModeIndicator();
this._indicators.add_child(this._remoteAccess);
this._indicators.add_child(this._thunderbolt);
this._indicators.add_child(this._location);
+ this._indicators.add_child(this._nightLight);
this._indicators.add_child(this._unsafeMode);
this._addItems(this._remoteAccess.quickSettingsItems);
this._addItems(this._thunderbolt.quickSettingsItems);
this._addItems(this._location.quickSettingsItems);
+ this._addItems(this._nightLight.quickSettingsItems);
this._addItems(this._unsafeMode.quickSettingsItems);
}
diff --git a/js/ui/status/nightLight.js b/js/ui/status/nightLight.js
index 109fe67912..a7fa92a3fc 100644
--- a/js/ui/status/nightLight.js
+++ b/js/ui/status/nightLight.js
@@ -3,11 +3,9 @@
const {Gio, GLib, GObject} = imports.gi;
-const Main = imports.ui.main;
-const PanelMenu = imports.ui.panelMenu;
-const PopupMenu = imports.ui.popupMenu;
+const {QuickToggle, SystemIndicator} = imports.ui.quickSettings;
-const { loadInterfaceXML } = imports.misc.fileUtils;
+const {loadInterfaceXML} = imports.misc.fileUtils;
const BUS_NAME = 'org.gnome.SettingsDaemon.Color';
const OBJECT_PATH = '/org/gnome/SettingsDaemon/Color';
@@ -15,14 +13,34 @@ const OBJECT_PATH = '/org/gnome/SettingsDaemon/Color';
const ColorInterface = loadInterfaceXML('org.gnome.SettingsDaemon.Color');
const colorInfo = Gio.DBusInterfaceInfo.new_for_xml(ColorInterface);
+const NightLightToggle = GObject.registerClass(
+class NightLightToggle extends QuickToggle {
+ _init() {
+ super._init({
+ label: _('Night Light'),
+ iconName: 'night-light-symbolic',
+ toggleMode: true,
+ });
+
+ this._settings = new Gio.Settings({
+ schema_id: 'org.gnome.settings-daemon.plugins.color',
+ });
+ this._settings.bind('night-light-enabled',
+ this, 'checked',
+ Gio.SettingsBindFlags.DEFAULT);
+ }
+});
+
var Indicator = GObject.registerClass(
-class Indicator extends PanelMenu.SystemIndicator {
+class Indicator extends SystemIndicator {
_init() {
super._init();
this._indicator = this._addIndicator();
this._indicator.icon_name = 'night-light-symbolic';
+ this.quickSettingsItems.push(new NightLightToggle());
+
this._proxy = new Gio.DBusProxy({
g_connection: Gio.DBus.session,
g_name: BUS_NAME,
@@ -30,42 +48,17 @@ class Indicator extends PanelMenu.SystemIndicator {
g_interface_name: colorInfo.name,
g_interface_info: colorInfo,
});
- this._proxy.connect('g-properties-changed', () => this._sync());
+ this._proxy.connect('g-properties-changed', (p, properties) => {
+ if ('NightLightActive' in properties.deep_unpack())
+ this._sync();
+ });
this._proxy.init_async(GLib.PRIORITY_DEFAULT, null)
.catch(e => console.error(e.message));
- this._item = new PopupMenu.PopupSubMenuMenuItem("", true);
- this._item.icon.icon_name = 'night-light-symbolic';
- this._disableItem = this._item.menu.addAction('', () => {
- this._proxy.DisabledUntilTomorrow = !this._proxy.DisabledUntilTomorrow;
- });
- this._item.menu.addAction(_("Turn Off"), () => {
- let settings = new Gio.Settings({ schema_id: 'org.gnome.settings-daemon.plugins.color' });
- settings.set_boolean('night-light-enabled', false);
- });
- this._item.menu.addSettingsAction(_("Display Settings"), 'gnome-display-panel.desktop');
- this.menu.addMenuItem(this._item);
-
- Main.sessionMode.connect('updated', this._sessionUpdated.bind(this));
- this._sessionUpdated();
this._sync();
}
- _sessionUpdated() {
- let sensitive = !Main.sessionMode.isLocked && !Main.sessionMode.isGreeter;
- this.menu.setSensitive(sensitive);
- }
-
_sync() {
- let visible = this._proxy.NightLightActive;
- let disabled = this._proxy.DisabledUntilTomorrow;
-
- this._item.label.text = disabled
- ? _("Night Light Disabled")
- : _("Night Light On");
- this._disableItem.label.text = disabled
- ? _("Resume")
- : _("Disable Until Tomorrow");
- this._item.visible = this._indicator.visible = visible;
+ this._indicator.visible = this._proxy.NightLightActive;
}
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]