status/powerProfiles: Port to quick settings
With menu support in place, this is now a straight-forward port: Just add the existing profiles section to a QuickToggleMenu instead of a submenu item. The toggle itself now switches between 'balanced' and the last used non-default profile. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2393>
This commit is contained in:
parent
c2e8f41bdf
commit
1f178e83d3
@ -378,7 +378,6 @@ class AggregateMenu extends PanelMenu.Button {
|
|||||||
else
|
else
|
||||||
this._network = null;
|
this._network = null;
|
||||||
|
|
||||||
this._powerProfiles = new imports.ui.status.powerProfiles.Indicator();
|
|
||||||
this._volume = new imports.ui.status.volume.Indicator();
|
this._volume = new imports.ui.status.volume.Indicator();
|
||||||
this._brightness = new imports.ui.status.brightness.Indicator();
|
this._brightness = new imports.ui.status.brightness.Indicator();
|
||||||
this._system = new imports.ui.status.system.Indicator();
|
this._system = new imports.ui.status.system.Indicator();
|
||||||
@ -386,7 +385,6 @@ class AggregateMenu extends PanelMenu.Button {
|
|||||||
if (this._network)
|
if (this._network)
|
||||||
this._indicators.add_child(this._network);
|
this._indicators.add_child(this._network);
|
||||||
this._indicators.add_child(this._volume);
|
this._indicators.add_child(this._volume);
|
||||||
this._indicators.add_child(this._powerProfiles);
|
|
||||||
|
|
||||||
this.menu.addMenuItem(this._volume.menu);
|
this.menu.addMenuItem(this._volume.menu);
|
||||||
this.menu.addMenuItem(this._brightness.menu);
|
this.menu.addMenuItem(this._brightness.menu);
|
||||||
@ -394,11 +392,9 @@ class AggregateMenu extends PanelMenu.Button {
|
|||||||
if (this._network)
|
if (this._network)
|
||||||
this.menu.addMenuItem(this._network.menu);
|
this.menu.addMenuItem(this._network.menu);
|
||||||
|
|
||||||
this.menu.addMenuItem(this._powerProfiles.menu);
|
|
||||||
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
||||||
this.menu.addMenuItem(this._system.menu);
|
this.menu.addMenuItem(this._system.menu);
|
||||||
|
|
||||||
menuLayout.addSizeChild(this._powerProfiles.menu.actor);
|
|
||||||
menuLayout.addSizeChild(this._system.menu.actor);
|
menuLayout.addSizeChild(this._system.menu.actor);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -425,6 +421,7 @@ class QuickSettings extends PanelMenu.Button {
|
|||||||
this._thunderbolt = new imports.ui.status.thunderbolt.Indicator();
|
this._thunderbolt = new imports.ui.status.thunderbolt.Indicator();
|
||||||
this._nightLight = new imports.ui.status.nightLight.Indicator();
|
this._nightLight = new imports.ui.status.nightLight.Indicator();
|
||||||
this._darkMode = new imports.ui.status.darkMode.Indicator();
|
this._darkMode = new imports.ui.status.darkMode.Indicator();
|
||||||
|
this._powerProfiles = new imports.ui.status.powerProfiles.Indicator();
|
||||||
this._rfkill = new imports.ui.status.rfkill.Indicator();
|
this._rfkill = new imports.ui.status.rfkill.Indicator();
|
||||||
this._autoRotate = new imports.ui.status.autoRotate.Indicator();
|
this._autoRotate = new imports.ui.status.autoRotate.Indicator();
|
||||||
this._unsafeMode = new UnsafeModeIndicator();
|
this._unsafeMode = new UnsafeModeIndicator();
|
||||||
@ -435,6 +432,7 @@ class QuickSettings extends PanelMenu.Button {
|
|||||||
this._indicators.add_child(this._location);
|
this._indicators.add_child(this._location);
|
||||||
this._indicators.add_child(this._nightLight);
|
this._indicators.add_child(this._nightLight);
|
||||||
this._indicators.add_child(this._darkMode);
|
this._indicators.add_child(this._darkMode);
|
||||||
|
this._indicators.add_child(this._powerProfiles);
|
||||||
if (this._bluetooth)
|
if (this._bluetooth)
|
||||||
this._indicators.add_child(this._bluetooth);
|
this._indicators.add_child(this._bluetooth);
|
||||||
this._indicators.add_child(this._rfkill);
|
this._indicators.add_child(this._rfkill);
|
||||||
@ -447,6 +445,7 @@ class QuickSettings extends PanelMenu.Button {
|
|||||||
this._addItems(this._location.quickSettingsItems);
|
this._addItems(this._location.quickSettingsItems);
|
||||||
if (this._bluetooth)
|
if (this._bluetooth)
|
||||||
this._addItems(this._bluetooth.quickSettingsItems);
|
this._addItems(this._bluetooth.quickSettingsItems);
|
||||||
|
this._addItems(this._powerProfiles.quickSettingsItems);
|
||||||
this._addItems(this._nightLight.quickSettingsItems);
|
this._addItems(this._nightLight.quickSettingsItems);
|
||||||
this._addItems(this._darkMode.quickSettingsItems);
|
this._addItems(this._darkMode.quickSettingsItems);
|
||||||
this._addItems(this._rfkill.quickSettingsItems);
|
this._addItems(this._rfkill.quickSettingsItems);
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
||||||
/* exported Indicator */
|
/* exported Indicator */
|
||||||
|
|
||||||
const { Gio, GObject } = imports.gi;
|
const {Gio, GObject} = imports.gi;
|
||||||
|
|
||||||
|
const {QuickMenuToggle, SystemIndicator} = imports.ui.quickSettings;
|
||||||
|
|
||||||
const Main = imports.ui.main;
|
|
||||||
const PanelMenu = imports.ui.panelMenu;
|
|
||||||
const PopupMenu = imports.ui.popupMenu;
|
const PopupMenu = imports.ui.popupMenu;
|
||||||
|
|
||||||
const { loadInterfaceXML } = imports.misc.fileUtils;
|
const {loadInterfaceXML} = imports.misc.fileUtils;
|
||||||
|
|
||||||
const BUS_NAME = 'net.hadess.PowerProfiles';
|
const BUS_NAME = 'net.hadess.PowerProfiles';
|
||||||
const OBJECT_PATH = '/net/hadess/PowerProfiles';
|
const OBJECT_PATH = '/net/hadess/PowerProfiles';
|
||||||
@ -34,13 +34,19 @@ const PROFILE_PARAMS = {
|
|||||||
|
|
||||||
const LAST_PROFILE_KEY = 'last-selected-power-profile';
|
const LAST_PROFILE_KEY = 'last-selected-power-profile';
|
||||||
|
|
||||||
var Indicator = GObject.registerClass(
|
const PowerProfilesToggle = GObject.registerClass(
|
||||||
class Indicator extends PanelMenu.SystemIndicator {
|
class PowerProfilesToggle extends QuickMenuToggle {
|
||||||
_init() {
|
_init() {
|
||||||
super._init();
|
super._init();
|
||||||
|
|
||||||
this._profileItems = new Map();
|
this._profileItems = new Map();
|
||||||
|
|
||||||
|
this.connect('clicked', () => {
|
||||||
|
this._proxy.ActiveProfile = this.checked
|
||||||
|
? 'balanced'
|
||||||
|
: global.settings.get_string(LAST_PROFILE_KEY);
|
||||||
|
});
|
||||||
|
|
||||||
this._proxy = new PowerProfilesProxy(Gio.DBus.system, BUS_NAME, OBJECT_PATH,
|
this._proxy = new PowerProfilesProxy(Gio.DBus.system, BUS_NAME, OBJECT_PATH,
|
||||||
(proxy, error) => {
|
(proxy, error) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
@ -58,25 +64,13 @@ class Indicator extends PanelMenu.SystemIndicator {
|
|||||||
this._sync();
|
this._sync();
|
||||||
});
|
});
|
||||||
|
|
||||||
this._item = new PopupMenu.PopupSubMenuMenuItem('', true);
|
|
||||||
|
|
||||||
this._profileSection = new PopupMenu.PopupMenuSection();
|
this._profileSection = new PopupMenu.PopupMenuSection();
|
||||||
this._item.menu.addMenuItem(this._profileSection);
|
this.menu.addMenuItem(this._profileSection);
|
||||||
this._item.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
this.menu.setHeader('power-profile-balanced-symbolic', _('Power Profiles'));
|
||||||
this._item.menu.addSettingsAction(_('Power Settings'),
|
|
||||||
'gnome-power-panel.desktop');
|
|
||||||
this.menu.addMenuItem(this._item);
|
|
||||||
|
|
||||||
Main.sessionMode.connect('updated', this._sessionUpdated.bind(this));
|
|
||||||
this._sessionUpdated();
|
|
||||||
this._sync();
|
this._sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
_sessionUpdated() {
|
|
||||||
const sensitive = !Main.sessionMode.isLocked && !Main.sessionMode.isGreeter;
|
|
||||||
this.menu.setSensitive(sensitive);
|
|
||||||
}
|
|
||||||
|
|
||||||
_syncProfiles() {
|
_syncProfiles() {
|
||||||
this._profileSection.removeAll();
|
this._profileSection.removeAll();
|
||||||
this._profileItems.clear();
|
this._profileItems.clear();
|
||||||
@ -95,12 +89,14 @@ class Indicator extends PanelMenu.SystemIndicator {
|
|||||||
this._profileItems.set(profile, item);
|
this._profileItems.set(profile, item);
|
||||||
this._profileSection.addMenuItem(item);
|
this._profileSection.addMenuItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.menuEnabled = this._profileItems.size > 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
_sync() {
|
_sync() {
|
||||||
this._item.visible = this._proxy.g_name_owner !== null;
|
this.visible = this._proxy.g_name_owner !== null;
|
||||||
|
|
||||||
if (!this._item.visible)
|
if (!this.visible)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const {ActiveProfile: activeProfile} = this._proxy;
|
const {ActiveProfile: activeProfile} = this._proxy;
|
||||||
@ -111,11 +107,19 @@ class Indicator extends PanelMenu.SystemIndicator {
|
|||||||
: PopupMenu.Ornament.NONE);
|
: PopupMenu.Ornament.NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
const {label, iconName} = PROFILE_PARAMS[activeProfile];
|
this.set(PROFILE_PARAMS[activeProfile]);
|
||||||
this._item.label.text = label;
|
this.checked = activeProfile !== 'balanced';
|
||||||
this._item.icon.icon_name = iconName;
|
|
||||||
|
|
||||||
if (activeProfile !== 'balanced')
|
if (this.checked)
|
||||||
global.settings.set_string(LAST_PROFILE_KEY, activeProfile);
|
global.settings.set_string(LAST_PROFILE_KEY, activeProfile);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var Indicator = GObject.registerClass(
|
||||||
|
class Indicator extends SystemIndicator {
|
||||||
|
_init() {
|
||||||
|
super._init();
|
||||||
|
|
||||||
|
this.quickSettingsItems.push(new PowerProfilesToggle());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user