Skip to content

Commit

Permalink
modularize hidpi config (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
gvolpe authored Jan 4, 2025
1 parent 13f9f21 commit b0101af
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 59 deletions.
14 changes: 0 additions & 14 deletions home/modules/browser.nix

This file was deleted.

4 changes: 2 additions & 2 deletions home/modules/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
./browser.nix
./dotfiles.nix
./changes-report.nix
./dotfiles.nix
./hidpi.nix
./megasync.nix
./signal.nix
]
45 changes: 45 additions & 0 deletions home/modules/hidpi.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{ config, lib, ... }:

with lib;

{
meta.maintainers = [ hm.maintainers.gvolpe ];

options = {
hidpi = lib.mkEnableOption "HiDPI displays";

programs = {
alacritty.fontSize = mkOption {
type = types.int;
default = if config.hidpi then 10 else 8;
};

browser.settings.dpi = mkOption {
type = types.str;
default = "0";
};

foot.fontSize = mkOption {
type = types.str;
default = if config.hidpi then "14" else "10";
};

signal.scaleFactor = mkOption {
type = types.str;
default = if config.hidpi then "2" else "1.5";
};
};

services = {
hypridle.dpms = mkOption {
type = types.attrs;
default = if config.hidpi then { } else
{
timeout = 1200;
on-timeout = "hyprctl dispatch dpms off";
on-resume = "hyprctl dispatch dpms on";
};
};
};
};
}
4 changes: 2 additions & 2 deletions home/modules/megasync.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ config, lib, pkgs, specialArgs, ... }:
{ config, lib, pkgs, ... }:

with lib;

Expand All @@ -23,7 +23,7 @@ in

package = mkOption {
type = types.package;
default = if specialArgs.hidpi then hidpiPackage else pkgs.megasync;
default = if config.hidpi then hidpiPackage else pkgs.megasync;
};
};

Expand Down
8 changes: 3 additions & 5 deletions home/modules/signal.nix
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
{ config, lib, pkgs, specialArgs, ... }:
{ config, lib, pkgs, ... }:

with lib;

let
cfg = config.programs.signal;

scaleFactor = if specialArgs.hidpi then "2" else "1.5";

signal = pkgs.signal-desktop.overrideAttrs (old: {
preFixup = old.preFixup + ''
substituteInPlace $out/share/applications/signal-desktop.desktop \
--replace "--no-sandbox" "--use-tray-icon --force-device-scale-factor=${scaleFactor}"
--replace "--no-sandbox" "--use-tray-icon --force-device-scale-factor=${cfg.scaleFactor}"
'';
});

Expand All @@ -22,7 +20,7 @@ let
postBuild = ''
wrapProgram $out/bin/signal-desktop \
--add-flags "--use-tray-icon" \
--add-flags "--force-device-scale-factor=${scaleFactor}"
--add-flags "--force-device-scale-factor=${cfg.scaleFactor}"
'';
};

Expand Down
7 changes: 2 additions & 5 deletions home/programs/alacritty/default.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{ pkgs, specialArgs, ... }:
{ config, pkgs, ... }:

let
fontSize = if specialArgs.hidpi then 10 else 8;
in
{
programs.alacritty = {
enable = true;
Expand All @@ -23,7 +20,7 @@ in
family = "JetBrainsMono Nerd Font";
style = "Medium";
};
size = fontSize;
size = config.programs.alacritty.fontSize;
};
keyboard.bindings = [
{ key = 53; mods = "Shift"; mode = "Vi"; action = "SearchBackward"; }
Expand Down
8 changes: 2 additions & 6 deletions home/programs/foot/default.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{ pkgs, specialArgs, ... }:
{ config, pkgs, ... }:

let
inherit (specialArgs) hidpi;
fontSize = if hidpi then "14" else "10";
in
{
# lightweight wayland terminal emulator
programs.foot = {
Expand All @@ -12,7 +8,7 @@ in
settings = {
main = {
shell = "${pkgs.fish}/bin/fish";
font = "JetBrainsMono Nerdfont:size=${fontSize}";
font = "JetBrainsMono Nerdfont:size=${config.programs.foot.fontSize}";
pad = "12x12";
dpi-aware = "yes";
selection-target = "both";
Expand Down
13 changes: 2 additions & 11 deletions home/services/hypridle/default.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
{ specialArgs, ... }:
{ config, ... }:

let
dpmsSettings =
if specialArgs.hidpi then { } else
{
timeout = 1200;
on-timeout = "hyprctl dispatch dpms off";
on-resume = "hyprctl dispatch dpms on";
};
in
{
services.hypridle = {
enable = true;
Expand All @@ -24,7 +15,7 @@ in
timeout = 900;
on-timeout = "hyprlock";
}
dpmsSettings
config.services.hypridle.dpms
];
};
};
Expand Down
4 changes: 2 additions & 2 deletions home/services/polybar/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ config, lib, pkgs, specialArgs, ... }:
{ config, lib, pkgs, ... }:

let
openCalendar = "${pkgs.xfce.orage}/bin/orage";
Expand All @@ -14,7 +14,7 @@ let
font5 = 10;
};

mainBar = if specialArgs.hidpi then hdmiBar else laptopBar;
mainBar = if config.hidpi then hdmiBar else laptopBar;

openGithub = "${lib.exe pkgs.firefox-beta-bin} -new-tab https\\://github.com/notifications";

Expand Down
3 changes: 1 addition & 2 deletions lib/overlays.nix
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ let
};

xargsOverlay = f: p: {
xargs = { hidpi }: {
inherit hidpi;
xargs = {
inherit (inputs) gh-md-toc penguin-fox;
inherit (inputs.rycee-nurpkgs.lib.${system}) buildFirefoxXpiAddon;
addons = f.nur.repos.rycee.firefox-addons;
Expand Down
19 changes: 10 additions & 9 deletions outputs/hm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,26 @@ let
({ nix.registry.nixpkgs.flake = inputs.nixpkgs; })
];

hyprlandDpiSettings = { hidpi }: {
programs.browser.settings.dpi = if hidpi then "0" else "1.7";
hyprlandDpiSettings = { config, ... }: {
programs.browser.settings.dpi = if config.hidpi then "0" else "1.7";
};

xmonadDpiSettings = { hidpi }: {
programs.browser.settings.dpi = if hidpi then "-1.0" else "0.7";
xmonadDpiSettings = { config, ... }: {
programs.browser.settings.dpi = if config.hidpi then "-1.0" else "0.7";
};

mkXmonadHome = { hidpi }:
let
imports = sharedImports ++ [
../home/wm/xmonad/home.nix
(xmonadDpiSettings { inherit hidpi; })
({ inherit hidpi; })
xmonadDpiSettings
];
in
(
home-manager.lib.homeManagerConfiguration {
inherit pkgs;
extraSpecialArgs = pkgs.xargs { inherit hidpi; };
extraSpecialArgs = pkgs.xargs;
modules = [{ inherit imports; }];
}
);
Expand All @@ -38,14 +39,14 @@ let
imports = sharedImports ++ [
inputs.hypr-binds-flake.homeManagerModules.${system}.default
../home/wm/hyprland/home.nix
(hyprlandDpiSettings { inherit hidpi; })
({ dotfiles.mutable = mutableDotFiles; })
({ inherit hidpi; dotfiles.mutable = mutableDotFiles; })
hyprlandDpiSettings
];
in
(
home-manager.lib.homeManagerConfiguration {
inherit pkgs;
extraSpecialArgs = pkgs.xargs { inherit hidpi; };
extraSpecialArgs = pkgs.xargs;
modules = [{ inherit imports; }];
}
);
Expand Down
2 changes: 1 addition & 1 deletion outputs/os.nix
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ in
home-manager.nixosModules.home-manager
(import ./mod.nix {
inherit inputs system;
extraSpecialArgs = pkgs.xargs { hidpi = false; };
extraSpecialArgs = pkgs.xargs;
})
# FIXME: zfs-kernel-2.2.3-6.8.9 is marked as broken
# iso image modules
Expand Down

0 comments on commit b0101af

Please sign in to comment.