[gnome-shell] status/bluetooth: Port to quick settings
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] status/bluetooth: Port to quick settings
- Date: Tue, 2 Aug 2022 16:09:07 +0000 (UTC)
commit 2ebdb6e318c4fc3e1a55617af693bf8e239dda49
Author: Florian Müllner <fmuellner gnome org>
Date: Tue Jul 26 10:45:35 2022 +0200
status/bluetooth: Port to quick settings
For now, this is another simple toggle. The icon, state and
visibility reflect what the old menu did, and the top bar
icon is still only shown when devices are currently connected.
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2392>
js/ui/panel.js | 19 ++++++-------
js/ui/status/bluetooth.js | 72 ++++++++++++++++++++---------------------------
2 files changed, 40 insertions(+), 51 deletions(-)
---
diff --git a/js/ui/panel.js b/js/ui/panel.js
index bdcd8f9f81..614f71606b 100644
--- a/js/ui/panel.js
+++ b/js/ui/panel.js
@@ -378,11 +378,6 @@ class AggregateMenu extends PanelMenu.Button {
else
this._network = null;
- if (Config.HAVE_BLUETOOTH)
- this._bluetooth = new imports.ui.status.bluetooth.Indicator();
- else
- this._bluetooth = null;
-
this._power = new imports.ui.status.power.Indicator();
this._powerProfiles = new imports.ui.status.powerProfiles.Indicator();
this._volume = new imports.ui.status.volume.Indicator();
@@ -391,8 +386,6 @@ class AggregateMenu extends PanelMenu.Button {
if (this._network)
this._indicators.add_child(this._network);
- if (this._bluetooth)
- this._indicators.add_child(this._bluetooth);
this._indicators.add_child(this._volume);
this._indicators.add_child(this._power);
this._indicators.add_child(this._powerProfiles);
@@ -403,9 +396,6 @@ class AggregateMenu extends PanelMenu.Button {
if (this._network)
this.menu.addMenuItem(this._network.menu);
- if (this._bluetooth)
- this.menu.addMenuItem(this._bluetooth.menu);
-
this.menu.addMenuItem(this._power.menu);
this.menu.addMenuItem(this._powerProfiles.menu);
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
@@ -429,6 +419,11 @@ class QuickSettings extends PanelMenu.Button {
this.setMenu(new QuickSettingsMenu(this, N_QUICK_SETTINGS_COLUMNS));
+ if (Config.HAVE_BLUETOOTH)
+ this._bluetooth = new imports.ui.status.bluetooth.Indicator();
+ else
+ this._bluetooth = null;
+
this._remoteAccess = new imports.ui.status.remoteAccess.RemoteAccessApplet();
this._location = new imports.ui.status.location.Indicator();
this._thunderbolt = new imports.ui.status.thunderbolt.Indicator();
@@ -440,12 +435,16 @@ class QuickSettings extends PanelMenu.Button {
this._indicators.add_child(this._thunderbolt);
this._indicators.add_child(this._location);
this._indicators.add_child(this._nightLight);
+ if (this._bluetooth)
+ this._indicators.add_child(this._bluetooth);
this._indicators.add_child(this._rfkill);
this._indicators.add_child(this._unsafeMode);
this._addItems(this._remoteAccess.quickSettingsItems);
this._addItems(this._thunderbolt.quickSettingsItems);
this._addItems(this._location.quickSettingsItems);
+ if (this._bluetooth)
+ this._addItems(this._bluetooth.quickSettingsItems);
this._addItems(this._nightLight.quickSettingsItems);
this._addItems(this._rfkill.quickSettingsItems);
this._addItems(this._unsafeMode.quickSettingsItems);
diff --git a/js/ui/status/bluetooth.js b/js/ui/status/bluetooth.js
index fe5956c001..aed017a477 100644
--- a/js/ui/status/bluetooth.js
+++ b/js/ui/status/bluetooth.js
@@ -1,13 +1,11 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
/* exported Indicator */
-const { Gio, GLib, GnomeBluetooth, GObject } = imports.gi;
+const {Gio, GLib, GnomeBluetooth, 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.Rfkill';
const OBJECT_PATH = '/org/gnome/SettingsDaemon/Rfkill';
@@ -149,32 +147,42 @@ const BtClient = GObject.registerClass({
}
});
+const BluetoothToggle = GObject.registerClass(
+class BluetoothToggle extends QuickToggle {
+ _init(client) {
+ super._init({label: _('Bluetooth')});
+
+ this._client = client;
+
+ this._client.bind_property('available',
+ this, 'visible',
+ GObject.BindingFlags.SYNC_CREATE);
+ this._client.bind_property('active',
+ this, 'checked',
+ GObject.BindingFlags.SYNC_CREATE);
+ this._client.bind_property_full('active',
+ this, 'icon-name',
+ GObject.BindingFlags.SYNC_CREATE,
+ (bind, source) => [true, source ? 'bluetooth-active-symbolic' : 'bluetooth-disabled-symbolic'],
+ null);
+
+ this.connect('clicked', () => this._client.toggleActive());
+ }
+});
+
var Indicator = GObject.registerClass(
-class Indicator extends PanelMenu.SystemIndicator {
+class Indicator extends SystemIndicator {
_init() {
super._init();
- this._indicator = this._addIndicator();
- this._indicator.icon_name = 'bluetooth-active-symbolic';
-
this._client = new BtClient();
- this._client.connectObject(
- 'notify::active', () => this._sync(),
- 'devices-changed', () => this._sync(), this);
+ this._client.connect('devices-changed', () => this._sync());
- this._item = new PopupMenu.PopupSubMenuMenuItem(_('Bluetooth'), true);
- this._client.bind_property('available',
- this._item, 'visible',
- GObject.BindingFlags.SYNC_CREATE);
-
- this._toggleItem = new PopupMenu.PopupMenuItem('');
- this._toggleItem.connect('activate', () => this._client.toggleActive());
- this._item.menu.addMenuItem(this._toggleItem);
+ this._indicator = this._addIndicator();
+ this._indicator.icon_name = 'bluetooth-active-symbolic';
- this._item.menu.addSettingsAction(_('Bluetooth Settings'), 'gnome-bluetooth-panel.desktop');
- this.menu.addMenuItem(this._item);
+ this.quickSettingsItems.push(new BluetoothToggle(this._client));
- Main.sessionMode.connect('updated', this._sync.bind(this));
this._sync();
}
@@ -183,24 +191,6 @@ class Indicator extends PanelMenu.SystemIndicator {
const connectedDevices = devices.filter(dev => dev.connected);
const nConnectedDevices = connectedDevices.length;
- let sensitive = !Main.sessionMode.isLocked && !Main.sessionMode.isGreeter;
-
- this.menu.setSensitive(sensitive);
this._indicator.visible = nConnectedDevices > 0;
-
- this._item.icon.icon_name = this._client.active
- ? 'bluetooth-active-symbolic' : 'bluetooth-disabled-symbolic';
-
- if (nConnectedDevices > 1)
- /* Translators: this is the number of connected bluetooth devices */
- this._item.label.text = ngettext('%d Connected', '%d Connected',
nConnectedDevices).format(nConnectedDevices);
- else if (nConnectedDevices === 1)
- this._item.label.text = connectedDevices[0].alias;
- else if (this._client.active)
- this._item.label.text = _('Bluetooth On');
- else
- this._item.label.text = _('Bluetooth Off');
-
- this._toggleItem.label.text = this._client.active ? _('Turn Off') : _('Turn On');
}
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]