feat: reduce motion gnome extension
This commit is contained in:
parent
5a6fb9619b
commit
5e10d2d37b
4 changed files with 121 additions and 0 deletions
96
gnome-extensions/reduced-motion-toggle/extension.js
Normal file
96
gnome-extensions/reduced-motion-toggle/extension.js
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
import Gio from 'gi://Gio';
|
||||
import GObject from 'gi://GObject';
|
||||
|
||||
import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js';
|
||||
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
|
||||
import * as QuickSettings from 'resource:///org/gnome/shell/ui/quickSettings.js';
|
||||
|
||||
const INTERFACE_SCHEMA = 'org.gnome.desktop.interface';
|
||||
const ENABLE_ANIMATIONS_KEY = 'enable-animations';
|
||||
|
||||
const ReducedMotionToggle = GObject.registerClass(
|
||||
class ReducedMotionToggle extends QuickSettings.QuickToggle {
|
||||
constructor() {
|
||||
super({
|
||||
title: 'Reduced Motion',
|
||||
subtitle: 'Prefer fewer animations',
|
||||
iconName: 'preferences-desktop-accessibility-symbolic',
|
||||
toggleMode: true,
|
||||
});
|
||||
|
||||
this._settings = new Gio.Settings({schema_id: INTERFACE_SCHEMA});
|
||||
this._syncing = false;
|
||||
this._changedId = this._settings.connect(
|
||||
`changed::${ENABLE_ANIMATIONS_KEY}`,
|
||||
() => this._sync()
|
||||
);
|
||||
this._checkedId = this.connect('notify::checked', () => {
|
||||
if (!this._syncing)
|
||||
this._settings.set_boolean(ENABLE_ANIMATIONS_KEY, !this.checked);
|
||||
});
|
||||
|
||||
this._sync();
|
||||
}
|
||||
|
||||
_sync() {
|
||||
const reducedMotionEnabled = !this._settings.get_boolean(ENABLE_ANIMATIONS_KEY);
|
||||
|
||||
if (this.checked === reducedMotionEnabled)
|
||||
return;
|
||||
|
||||
this._syncing = true;
|
||||
this.checked = reducedMotionEnabled;
|
||||
this._syncing = false;
|
||||
}
|
||||
|
||||
destroy() {
|
||||
if (this._changedId) {
|
||||
this._settings.disconnect(this._changedId);
|
||||
this._changedId = null;
|
||||
}
|
||||
|
||||
if (this._checkedId) {
|
||||
this.disconnect(this._checkedId);
|
||||
this._checkedId = null;
|
||||
}
|
||||
|
||||
super.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
const ReducedMotionIndicator = GObject.registerClass(
|
||||
class ReducedMotionIndicator extends QuickSettings.SystemIndicator {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this._indicator = this._addIndicator();
|
||||
this._indicator.icon_name = 'preferences-desktop-accessibility-symbolic';
|
||||
|
||||
this._toggle = new ReducedMotionToggle();
|
||||
this._indicator.visible = this._toggle.checked;
|
||||
this._toggle.connect('notify::checked', () => {
|
||||
this._indicator.visible = this._toggle.checked;
|
||||
});
|
||||
|
||||
this.quickSettingsItems.push(this._toggle);
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.quickSettingsItems.forEach(item => item.destroy());
|
||||
this._toggle = null;
|
||||
|
||||
super.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
export default class ReducedMotionToggleExtension extends Extension {
|
||||
enable() {
|
||||
this._indicator = new ReducedMotionIndicator();
|
||||
Main.panel.statusArea.quickSettings.addExternalIndicator(this._indicator);
|
||||
}
|
||||
|
||||
disable() {
|
||||
this._indicator.destroy();
|
||||
this._indicator = null;
|
||||
}
|
||||
}
|
||||
6
gnome-extensions/reduced-motion-toggle/metadata.json
Normal file
6
gnome-extensions/reduced-motion-toggle/metadata.json
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"uuid": "reduced-motion-toggle@jetpham.github.com",
|
||||
"name": "Reduced Motion Toggle",
|
||||
"description": "Adds a Quick Settings toggle for GNOME's reduced motion preference.",
|
||||
"shell-version": ["49"]
|
||||
}
|
||||
|
|
@ -182,6 +182,7 @@ in
|
|||
"appindicatorsupport@rgcjonas.gmail.com"
|
||||
"gnome-shell-extension-maximized-by-default@stiggimy.github.com"
|
||||
"no-titlebar-when-maximized@alec.ninja"
|
||||
"reduced-motion-toggle@jetpham.github.com"
|
||||
];
|
||||
favorite-apps = favoriteApps;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -5,6 +5,23 @@
|
|||
...
|
||||
}:
|
||||
|
||||
let
|
||||
reducedMotionToggleExtension = pkgs.stdenvNoCC.mkDerivation {
|
||||
pname = "gnome-shell-extension-reduced-motion-toggle";
|
||||
version = "1";
|
||||
src = ../gnome-extensions/reduced-motion-toggle;
|
||||
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
|
||||
mkdir -p "$out/share/gnome-shell/extensions/reduced-motion-toggle@jetpham.github.com"
|
||||
cp -r . "$out/share/gnome-shell/extensions/reduced-motion-toggle@jetpham.github.com"
|
||||
|
||||
runHook postInstall
|
||||
'';
|
||||
};
|
||||
in
|
||||
|
||||
{
|
||||
home.packages = with pkgs; [
|
||||
bat
|
||||
|
|
@ -88,6 +105,7 @@
|
|||
gnomeExtensions.system-monitor-next
|
||||
gnomeExtensions.tailscale-qs
|
||||
gnomeExtensions.wifi-qrcode
|
||||
reducedMotionToggleExtension
|
||||
|
||||
nerd-fonts.commit-mono
|
||||
];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue