[gnome-shell] status/autoRotate: Port to quick settings



commit 4d931c2c41c71248f3cd05d9bb8183bfcb0b9451
Author: Florian Müllner <fmuellner gnome org>
Date:   Wed Jul 27 03:46:43 2022 +0200

    status/autoRotate: Port to quick settings
    
    On devices where auto-rotation is supported, (un)locking the
    orientation is a common enough action to not bury it in a menu.
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2392>

 js/js-resources.gresource.xml |  1 +
 js/ui/panel.js                |  3 +++
 js/ui/status/autoRotate.js    | 45 +++++++++++++++++++++++++++++++++++++++++++
 js/ui/status/system.js        | 21 --------------------
 po/POTFILES.in                |  1 +
 5 files changed, 50 insertions(+), 21 deletions(-)
---
diff --git a/js/js-resources.gresource.xml b/js/js-resources.gresource.xml
index 87adfd1403..71d3d492f3 100644
--- a/js/js-resources.gresource.xml
+++ b/js/js-resources.gresource.xml
@@ -133,6 +133,7 @@
     <file>ui/components/keyring.js</file>
 
     <file>ui/status/accessibility.js</file>
+    <file>ui/status/autoRotate.js</file>
     <file>ui/status/brightness.js</file>
     <file>ui/status/dwellClick.js</file>
     <file>ui/status/location.js</file>
diff --git a/js/ui/panel.js b/js/ui/panel.js
index 0b0c50153c..95e9740ff7 100644
--- a/js/ui/panel.js
+++ b/js/ui/panel.js
@@ -425,6 +425,7 @@ class QuickSettings extends PanelMenu.Button {
         this._thunderbolt = new imports.ui.status.thunderbolt.Indicator();
         this._nightLight = new imports.ui.status.nightLight.Indicator();
         this._rfkill = new imports.ui.status.rfkill.Indicator();
+        this._autoRotate = new imports.ui.status.autoRotate.Indicator();
         this._unsafeMode = new UnsafeModeIndicator();
         this._power = new imports.ui.status.power.Indicator();
 
@@ -435,6 +436,7 @@ class QuickSettings extends PanelMenu.Button {
         if (this._bluetooth)
             this._indicators.add_child(this._bluetooth);
         this._indicators.add_child(this._rfkill);
+        this._indicators.add_child(this._autoRotate);
         this._indicators.add_child(this._unsafeMode);
         this._indicators.add_child(this._power);
 
@@ -445,6 +447,7 @@ class QuickSettings extends PanelMenu.Button {
             this._addItems(this._bluetooth.quickSettingsItems);
         this._addItems(this._nightLight.quickSettingsItems);
         this._addItems(this._rfkill.quickSettingsItems);
+        this._addItems(this._autoRotate.quickSettingsItems);
         this._addItems(this._unsafeMode.quickSettingsItems);
         this._addItems(this._power.quickSettingsItems);
     }
diff --git a/js/ui/status/autoRotate.js b/js/ui/status/autoRotate.js
new file mode 100644
index 0000000000..bde3b80fc5
--- /dev/null
+++ b/js/ui/status/autoRotate.js
@@ -0,0 +1,45 @@
+/* exported Indicator */
+const {Gio, GObject} = imports.gi;
+
+const SystemActions = imports.misc.systemActions;
+
+const {QuickToggle, SystemIndicator} = imports.ui.quickSettings;
+
+const RotationToggle = GObject.registerClass(
+class RotationToggle extends QuickToggle {
+    _init() {
+        this._systemActions = new SystemActions.getDefault();
+
+        super._init({
+            label: _('Auto Rotate'),
+        });
+
+        this._systemActions.bind_property('can-lock-orientation',
+            this, 'visible',
+            GObject.BindingFlags.DEFAULT |
+            GObject.BindingFlags.SYNC_CREATE);
+        this._systemActions.bind_property('orientation-lock-icon',
+            this, 'icon-name',
+            GObject.BindingFlags.DEFAULT |
+            GObject.BindingFlags.SYNC_CREATE);
+
+        this._settings = new Gio.Settings({
+            schema_id: 'org.gnome.settings-daemon.peripherals.touchscreen',
+        });
+        this._settings.bind('orientation-lock',
+            this, 'checked',
+            Gio.SettingsBindFlags.INVERT_BOOLEAN);
+
+        this.connect('clicked',
+            () => this._systemActions.activateLockOrientation());
+    }
+});
+
+var Indicator = GObject.registerClass(
+class Indicator extends SystemIndicator {
+    _init() {
+        super._init();
+
+        this.quickSettingsItems.push(new RotationToggle());
+    }
+});
diff --git a/js/ui/status/system.js b/js/ui/status/system.js
index 32320ab829..b218e3e541 100644
--- a/js/ui/status/system.js
+++ b/js/ui/status/system.js
@@ -62,27 +62,6 @@ class Indicator extends PanelMenu.SystemIndicator {
         let bindFlags = GObject.BindingFlags.DEFAULT | GObject.BindingFlags.SYNC_CREATE;
         let item;
 
-        item = new PopupMenu.PopupImageMenuItem(
-            this._systemActions.getName('lock-orientation'),
-            this._systemActions.orientation_lock_icon);
-
-        item.connect('activate', () => {
-            this.menu.itemActivated(BoxPointer.PopupAnimation.NONE);
-            this._systemActions.activateLockOrientation();
-        });
-        this.menu.addMenuItem(item);
-        this._orientationLockItem = item;
-        this._systemActions.bind_property('can-lock-orientation',
-            this._orientationLockItem, 'visible',
-            bindFlags);
-        this._systemActions.connect('notify::orientation-lock-icon', () => {
-            let iconName = this._systemActions.orientation_lock_icon;
-            let labelText = this._systemActions.getName("lock-orientation");
-
-            this._orientationLockItem.setIcon(iconName);
-            this._orientationLockItem.label.text = labelText;
-        });
-
         let app = this._settingsApp = Shell.AppSystem.get_default().lookup_app(
             'org.gnome.Settings.desktop');
         if (app) {
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 2f6bd0ae76..a47bd8adba 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -56,6 +56,7 @@ js/ui/searchController.js
 js/ui/shellEntry.js
 js/ui/shellMountOperation.js
 js/ui/status/accessibility.js
+js/ui/status/autoRotate.js
 js/ui/status/bluetooth.js
 js/ui/status/brightness.js
 js/ui/status/dwellClick.js


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]