diff --git a/js/js-resources.gresource.xml b/js/js-resources.gresource.xml index 87adfd140..71d3d492f 100644 --- a/js/js-resources.gresource.xml +++ b/js/js-resources.gresource.xml @@ -133,6 +133,7 @@ ui/components/keyring.js ui/status/accessibility.js + ui/status/autoRotate.js ui/status/brightness.js ui/status/dwellClick.js ui/status/location.js diff --git a/js/ui/panel.js b/js/ui/panel.js index 0b0c50153..95e9740ff 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 000000000..bde3b80fc --- /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 32320ab82..b218e3e54 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 2f6bd0ae7..a47bd8adb 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