From 5e10d2d37beee8ea32265282a61255bcddb064ab Mon Sep 17 00:00:00 2001 From: Jet Date: Sat, 16 May 2026 21:24:43 -0700 Subject: [PATCH] feat: reduce motion gnome extension --- .../reduced-motion-toggle/extension.js | 96 +++++++++++++++++++ .../reduced-motion-toggle/metadata.json | 6 ++ home-modules/desktop.nix | 1 + home-modules/packages.nix | 18 ++++ 4 files changed, 121 insertions(+) create mode 100644 gnome-extensions/reduced-motion-toggle/extension.js create mode 100644 gnome-extensions/reduced-motion-toggle/metadata.json diff --git a/gnome-extensions/reduced-motion-toggle/extension.js b/gnome-extensions/reduced-motion-toggle/extension.js new file mode 100644 index 0000000..8125f19 --- /dev/null +++ b/gnome-extensions/reduced-motion-toggle/extension.js @@ -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; + } +} diff --git a/gnome-extensions/reduced-motion-toggle/metadata.json b/gnome-extensions/reduced-motion-toggle/metadata.json new file mode 100644 index 0000000..02bfee0 --- /dev/null +++ b/gnome-extensions/reduced-motion-toggle/metadata.json @@ -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"] +} diff --git a/home-modules/desktop.nix b/home-modules/desktop.nix index 0d30de6..e84261c 100644 --- a/home-modules/desktop.nix +++ b/home-modules/desktop.nix @@ -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; }; diff --git a/home-modules/packages.nix b/home-modules/packages.nix index e1b2d35..72200c2 100644 --- a/home-modules/packages.nix +++ b/home-modules/packages.nix @@ -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 ];