diff --git a/hosts/common/programs/firefox/addons.nix b/hosts/common/programs/firefox/addons.nix index 3add0b5c5..84fda44d1 100644 --- a/hosts/common/programs/firefox/addons.nix +++ b/hosts/common/programs/firefox/addons.nix @@ -27,6 +27,9 @@ in # package = pkgs.firefox-extensions.ctrl-shift-c-should-copy; # enable = lib.mkDefault false; # prefer patching firefox source code, so it works in more places # }; + default-zoom = { + enable = lib.mkDefault true; + }; # ether-metamask = { # enable = lib.mkDefault false; # until i can disable the first-run notification # }; diff --git a/hosts/common/programs/firefox/default.nix b/hosts/common/programs/firefox/default.nix index ce35e5dcb..e3dd156b9 100644 --- a/hosts/common/programs/firefox/default.nix +++ b/hosts/common/programs/firefox/default.nix @@ -248,6 +248,8 @@ in // uidensity=2 gives more padding around UI elements. // source: defaultPref("browser.uidensity", 2); + // layout.css.devPixelsPerPx: acts as a global scale (even for the chrome) + // defaultPref("layout.css.devPixelsPerPx", 1.5); // open external URIs/files via xdg-desktop-portal. defaultPref("widget.use-xdg-desktop-portal.mime-handler", 1); diff --git a/pkgs/by-name/firefox-extensions/default-zoom/background.js b/pkgs/by-name/firefox-extensions/default-zoom/background.js new file mode 100644 index 000000000..11c164986 --- /dev/null +++ b/pkgs/by-name/firefox-extensions/default-zoom/background.js @@ -0,0 +1,24 @@ +// simplified implementation of +// +// XXX(2024-12-01): this implementation works for any tabs loaded with ctrl+t, and ctrl+l. +// it works for the homepage too, except for a first-run edge case wherein the homepage is loaded +// before any extensions are loaded +// +let defaultZoom = 2.0; + +function setZoom(tabId, changeInfo) { + if (changeInfo.status) { + const gettingZoom = browser.tabs.getZoom(tabId); + gettingZoom.then((currentZoom) => { + if (defaultZoom !== 1 && currentZoom === 1) { + browser.tabs.setZoom(tabId, defaultZoom); + } + }); + } +} + +browser.tabs.onCreated.addListener((tab) => { + browser.tabs.setZoom(tab.id, defaultZoom); +}); + +browser.tabs.onUpdated.addListener(setZoom); diff --git a/pkgs/by-name/firefox-extensions/default-zoom/default.nix b/pkgs/by-name/firefox-extensions/default-zoom/default.nix new file mode 100644 index 000000000..9f275efa5 --- /dev/null +++ b/pkgs/by-name/firefox-extensions/default-zoom/default.nix @@ -0,0 +1,27 @@ +# inlined/simplified version of +{ + stdenvNoCC, + zip, +}: +stdenvNoCC.mkDerivation { + pname = "default-zoom"; + version = "0.1"; + src = ./.; + + nativeBuildInputs = [ zip ]; + + buildPhase = '' + runHook preBuild + zip -j firefox.zip \ + background.html background.js manifest.json + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + install firefox.zip $out + runHook postInstall + ''; + + passthru.extid = "@default-zoom"; +} diff --git a/pkgs/by-name/firefox-extensions/default-zoom/manifest.json b/pkgs/by-name/firefox-extensions/default-zoom/manifest.json new file mode 100644 index 000000000..f324acda2 --- /dev/null +++ b/pkgs/by-name/firefox-extensions/default-zoom/manifest.json @@ -0,0 +1,17 @@ +{ + "manifest_version": 2, + "browser_specific_settings": { + "gecko": { + "id": "@default-zoom" + } + }, + "name": "Default zoom", + "description": "statically configure a default zoom value for new tabs", + "version": "0.1.0", + "background": { + "scripts": [ + "background.js" + ] + }, + "permissions": [] +} diff --git a/pkgs/by-name/firefox-extensions/package.nix b/pkgs/by-name/firefox-extensions/package.nix index 91e5bb9f8..87dafd425 100644 --- a/pkgs/by-name/firefox-extensions/package.nix +++ b/pkgs/by-name/firefox-extensions/package.nix @@ -119,6 +119,7 @@ let browserpass-extension = callPackage ./browserpass-extension { }; bypass-paywalls-clean = callPackage ./bypass-paywalls-clean { }; ctrl-shift-c-should-copy = callPackage ./ctrl-shift-c-should-copy { }; + default-zoom = callPackage ./default-zoom { }; firefox-xdg-open = callPackage ./firefox-xdg-open { }; i-still-dont-care-about-cookies = callPackage ./i-still-dont-care-about-cookies { }; # open-in-mpv = callPackage ./open-in-mpv { };