[gnome] Update extensions for v46

This commit is contained in:
2024-04-03 12:59:14 -04:00
parent 3fb1ec63ae
commit 7421cdba8f
251 changed files with 15759 additions and 3153 deletions

View File

@ -1,5 +1,5 @@
/* extension.js
* Copyright (C) 2023 kosmospredanie, shyzus, Shinigaminai
* Copyright (C) 2024 kosmospredanie, shyzus, Shinigaminai
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -15,17 +15,22 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { Extension } from 'resource:///org/gnome/shell/extensions/extension.js';
import { Extension, gettext as _ } from 'resource:///org/gnome/shell/extensions/extension.js';
import Gio from 'gi://Gio';
import GObject from 'gi://GObject';
import GLib from 'gi://GLib';
import * as SystemActions from 'resource:///org/gnome/shell/misc/systemActions.js';
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import * as Rotator from './rotator.js'
import * as PopupMenu from 'resource:///org/gnome/shell/ui/popupMenu.js';
const ORIENTATION_LOCK_SCHEMA = 'org.gnome.settings-daemon.peripherals.touchscreen';
const ORIENTATION_LOCK_KEY = 'orientation-lock';
import { QuickMenuToggle, QuickSettingsMenu, SystemIndicator } from 'resource:///org/gnome/shell/ui/quickSettings.js';
// Orientation names must match those provided by net.hadess.SensorProxy
const Orientation = Object.freeze({
'normal': 0,
@ -34,6 +39,100 @@ const Orientation = Object.freeze({
'right-up': 3
});
const ManualOrientationIndicator = GObject.registerClass(
class ManualOrientationIndicator extends SystemIndicator {
_init(ext_ref) {
super._init();
this.toggle = new ManualOrientationMenuToggle(ext_ref);
this.quickSettingsItems.push(this.toggle);
}
destroy() {
this.quickSettingsItems.pop(this.toggle);
this.toggle.destroy();
}
});
const ManualOrientationMenuToggle = GObject.registerClass(
class ManualOrientationMenuToggle extends QuickMenuToggle {
_init(ext) {
super._init({
title: _('Rotate'),
iconName: 'object-rotate-left-symbolic',
menuEnabled: true,
toggleMode: true,
});
this.menu.setHeader('object-rotate-left-symbolic', _('Screen Rotate'));
this._section = new PopupMenu.PopupMenuSection();
this.menu.addMenuItem(this._section);
this.landscapeItem = new PopupMenu.PopupMenuItem('Landscape', {
reactive: true,
can_focus: true,
});
this.portraitLeftItem = new PopupMenu.PopupMenuItem('Portrait Left', {
reactive: true,
can_focus: true,
});
this.landscapeFlipItem = new PopupMenu.PopupMenuItem('Landscape Flipped', {
reactive: true,
can_focus: true,
});
this.portraitRightItem = new PopupMenu.PopupMenuItem('Portrait Right', {
reactive: true,
can_focus: true,
});
this.landscapeItem.connect('activate', () => {
this._onItemActivate(this.landscapeItem);
ext.rotate_to('normal');
});
this.portraitLeftItem.connect('activate', () => {
this._onItemActivate(this.portraitLeftItem);
ext.rotate_to('left-up');
});
this.landscapeFlipItem.connect('activate', () => {
this._onItemActivate(this.landscapeFlipItem);
ext.rotate_to('bottom-up');
});
this.portraitRightItem.connect('activate', () => {
this._onItemActivate(this.portraitRightItem);
ext.rotate_to('right-up');
});
this._section.addMenuItem(this.landscapeItem);
this._section.addMenuItem(this.portraitLeftItem);
this._section.addMenuItem(this.landscapeFlipItem);
this._section.addMenuItem(this.portraitRightItem);
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
this.menu.addSettingsAction(_('Extension Settings'),
'com.mattjakeman.ExtensionManager.desktop');
this.connect('clicked', () => {
if (this.checked == true) {
ext.rotate_to('right-up');
} else {
ext.rotate_to('normal');
}
});
}
_onItemActivate(item) {
this.landscapeItem.setOrnament(PopupMenu.Ornament.HIDDEN);
this.portraitLeftItem.setOrnament(PopupMenu.Ornament.HIDDEN);
this.landscapeFlipItem.setOrnament(PopupMenu.Ornament.HIDDEN);
this.portraitRightItem.setOrnament(PopupMenu.Ornament.HIDDEN);
item.setOrnament(PopupMenu.Ornament.CHECK);
}
});
class SensorProxy {
constructor(rotate_cb) {
this._rotate_cb = rotate_cb;
@ -207,17 +306,72 @@ export default class ScreenAutoRotateExtension extends Extension {
enable() {
this._settings = this.getSettings();
this._ext = new ScreenAutorotate(this._settings);
this._settings.connect('changed::manual-flip', (settings, key) => {
if (settings.get_boolean(key)) {
this._add_manual_flip();
} else {
this._remove_manual_flip();
}
});
this._settings.connect('changed::hide-lock-rotate', (settings, key) => {
this._set_hide_lock_rotate(settings.get_boolean(key));
});
if (this._settings.get_boolean('manual-flip')) {
this._add_manual_flip();
} else {
this._remove_manual_flip();
}
/* Timeout needed due to unknown race condition causing 'Auto Rotate'
* Quick Toggle to be undefined for a brief moment.
*/
this._timeoutId = setTimeout(() => {
this._set_hide_lock_rotate(this._settings.get_boolean('hide-lock-rotate'));
}, 1000);
}
_set_hide_lock_rotate(state) {
const autoRotateIndicator = Main.panel.statusArea.quickSettings._autoRotate;
if (state) {
Main.panel.statusArea.quickSettings._indicators.remove_child(autoRotateIndicator);
Main.panel.statusArea.quickSettings.menu._grid.remove_child(autoRotateIndicator.quickSettingsItems[0]);
} else {
Main.panel.statusArea.quickSettings._indicators.add_child(autoRotateIndicator);
Main.panel.statusArea.quickSettings._addItemsBefore(
autoRotateIndicator.quickSettingsItems,
Main.panel.statusArea.quickSettings._rfkill.quickSettingsItems[0]
);
}
}
_add_manual_flip() {
this.flipIndicator = new ManualOrientationIndicator(this._ext);
Main.panel.statusArea.quickSettings.addExternalIndicator(this.flipIndicator);
}
_remove_manual_flip() {
if (this.flipIndicator != null) {
this.flipIndicator.destroy();
this.flipIndicator = null;
}
}
disable() {
/*
Comment for unlock-dialog usage:
The unlock-dialog sesson-mode is usefull for this extension as it allows
The unlock-dialog session-mode is useful for this extension as it allows
the user to rotate their screen or lock rotation after their device may
have auto-locked. This provides the ability to log back in regardless of
the orientation of the device in tablet mode.
*/
this._settings = null;
clearTimeout(this._timeoutId);
this._timeoutId = null;
this._remove_manual_flip();
this._ext.destroy();
this._ext = null;
}

View File

@ -9,9 +9,10 @@
],
"settings-schema": "org.gnome.shell.extensions.screen-rotate",
"shell-version": [
"45"
"45",
"46"
],
"url": "https://github.com/shyzus/gnome-shell-extension-screen-autorotate",
"uuid": "screen-rotate@shyzus.github.io",
"version": 15
"version": 19
}

View File

@ -1,5 +1,5 @@
/* prefs.js
* Copyright (C) 2023 kosmospredanie, shyzus, Shinigaminai
* Copyright (C) 2024 kosmospredanie, shyzus, Shinigaminai
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -33,6 +33,10 @@ export default class MyExtensionPreferences extends ExtensionPreferences {
orientationGroup.set_title('Orientation Settings')
page.add(orientationGroup);
const shellMenuGroup = new Adw.PreferencesGroup();
shellMenuGroup.set_title('GNOME Shell Menu Settings');
page.add(shellMenuGroup);
const debugGroup = new Adw.PreferencesGroup();
debugGroup.set_title('Debug Settings');
page.add(debugGroup);
@ -62,6 +66,17 @@ export default class MyExtensionPreferences extends ExtensionPreferences {
orientationGroup.add(setOffsetRow);
const enableManualFlipRow = new Adw.ActionRow({
title: 'Enable manual flip',
subtitle: 'Enable a toggle in the GNOME Shell System Menu to manually flip between landscape and portrait.'
});
shellMenuGroup.add(enableManualFlipRow);
const hideLockRotateRow = new Adw.ActionRow({
title: 'Hide the "Auto Rotate" quick toggle'
});
shellMenuGroup.add(hideLockRotateRow);
const toggleLoggingRow = new Adw.ActionRow({
title: 'Enable debug logging',
subtitle: 'Use "journalctl /usr/bin/gnome-shell -f" to see log output.'
@ -86,6 +101,16 @@ export default class MyExtensionPreferences extends ExtensionPreferences {
const setOffsetSpinButton = Gtk.SpinButton.new_with_range(0, 3, 1);
setOffsetSpinButton.value = window._settings.get_int('orientation-offset');
const manualFlipSwitch = new Gtk.Switch({
active: window._settings.get_boolean('manual-flip'),
valign: Gtk.Align.CENTER,
});
const hideLockRotateSwitch = new Gtk.Switch({
active: window._settings.get_boolean('hide-lock-rotate'),
valign: Gtk.Align.CENTER,
});
const toggleLoggingSwitch = new Gtk.Switch({
active: window._settings.get_boolean('debug-logging'),
valign: Gtk.Align.CENTER
@ -103,6 +128,12 @@ export default class MyExtensionPreferences extends ExtensionPreferences {
window._settings.bind('orientation-offset',
setOffsetSpinButton, 'value', Gio.SettingsBindFlags.DEFAULT);
window._settings.bind('manual-flip',
manualFlipSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);
window._settings.bind('hide-lock-rotate',
hideLockRotateSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);
window._settings.bind('debug-logging',
toggleLoggingSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);
@ -118,7 +149,13 @@ export default class MyExtensionPreferences extends ExtensionPreferences {
setOffsetRow.add_suffix(setOffsetSpinButton);
setOffsetRow.activatable_widget = setOffsetSpinButton;
enableManualFlipRow.add_suffix(manualFlipSwitch);
enableManualFlipRow.activatable_widget = manualFlipSwitch;
hideLockRotateRow.add_suffix(hideLockRotateSwitch);
hideLockRotateRow.activatable_widget = hideLockRotateSwitch;
toggleLoggingRow.add_suffix(toggleLoggingSwitch);
toggleLoggingRow.activatable_widget = toggleLoggingSwitch;
}
}
}

View File

@ -64,8 +64,11 @@ export function get_state() {
export function rotate_to(transform) {
this.get_state().then(state => {
let builtin_monitor = state.builtin_monitor;
let logical_monitor = state.get_logical_monitor_for(builtin_monitor.connector);
let target_monitor = state.builtin_monitor;
if (target_monitor == undefined) {
target_monitor = state.monitors[0]
}
let logical_monitor = state.get_logical_monitor_for(target_monitor.connector);
logical_monitor.transform = transform;
let variant = state.pack_to_apply(BusUtils.Methods['temporary']);
call_dbus_method('ApplyMonitorsConfig', variant);

View File

@ -1,6 +1,6 @@
<!--
- org.gnome.shell.extensions.screen-rotate.gschema.xml
- Copyright (C) 2023 shyzus, Shinigaminai
- Copyright (C) 2024 shyzus, Shinigaminai
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
@ -37,6 +37,13 @@
<default>0</default>
<description>Experiment with this offset in case orientation is incorrect.</description>
</key>
<key type="b" name="manual-flip">
<default>false</default>
<description>Enable a toggle in the GNOME Shell System Menu to manually flip between landscape and portrait.</description>
</key><key type="b" name="hide-lock-rotate">
<default>false</default>
<description>Hide the 'Auto Rotate' quick toggle.</description>
</key>
<key type="b" name="debug-logging">
<default>false</default>
<description>Toggle debug logging.</description>