From bbc0be5a61ebf3c86b20e78aeb9c58b1db5f1334 Mon Sep 17 00:00:00 2001 From: Aly Raffauf Date: Fri, 9 Aug 2024 20:23:44 -0400 Subject: [PATCH] desktop: add swayosd module with custom style (#80) * desktop: add swayosd theme style * home: add swayosd module options * desktop: enable libinput --- .../desktop/wayland/default.nix | 15 +--- homeManagerModules/options.nix | 1 + homeManagerModules/services/default.nix | 1 + .../services/swayosd/default.nix | 78 +++++++++++++++++++ nixosModules/desktop/default.nix | 1 + 5 files changed, 83 insertions(+), 13 deletions(-) create mode 100644 homeManagerModules/services/swayosd/default.nix diff --git a/homeManagerModules/desktop/wayland/default.nix b/homeManagerModules/desktop/wayland/default.nix index 1e6ec750..4d5c6473 100644 --- a/homeManagerModules/desktop/wayland/default.nix +++ b/homeManagerModules/desktop/wayland/default.nix @@ -16,6 +16,7 @@ mako.enable = lib.mkDefault true; pipewire-inhibit.enable = lib.mkDefault true; swayidle.enable = lib.mkDefault true; + swayosd.enable = lib.mkDefault true; waybar.enable = lib.mkDefault true; }; }; @@ -33,21 +34,9 @@ gnome.file-roller libnotify networkmanagerapplet - swayosd ]; - services = { - playerctld.enable = lib.mkDefault true; - swayosd.enable = lib.mkDefault true; - }; - - systemd.user.services.swayosd = { - Install.WantedBy = lib.mkForce ["hyprland-session.target" "sway-session.target"]; - Service = { - Restart = lib.mkForce "on-failure"; - RestartSec = 5; - }; - }; + services.playerctld.enable = lib.mkDefault true; xdg.portal = { enable = true; diff --git a/homeManagerModules/options.nix b/homeManagerModules/options.nix index fdcb0995..3d171357 100644 --- a/homeManagerModules/options.nix +++ b/homeManagerModules/options.nix @@ -194,6 +194,7 @@ in { pipewire-inhibit.enable = lib.mkEnableOption "Inhibit idle when audio is playing with Pipewire."; randomWallpaper.enable = lib.mkEnableOption "Lightweight swaybg-based random wallpaper daemon."; swayidle.enable = lib.mkEnableOption "Swayidle idle daemon."; + swayosd.enable = lib.mkEnableOption "OSD for brightness and volume keys."; waybar.enable = lib.mkEnableOption "Waybar wayland panel."; }; diff --git a/homeManagerModules/services/default.nix b/homeManagerModules/services/default.nix index 37ad9050..15e8c979 100644 --- a/homeManagerModules/services/default.nix +++ b/homeManagerModules/services/default.nix @@ -7,6 +7,7 @@ ./pipewire-inhibit ./randomWallpaper ./swayidle + ./swayosd ./waybar ]; } diff --git a/homeManagerModules/services/swayosd/default.nix b/homeManagerModules/services/swayosd/default.nix new file mode 100644 index 00000000..84dd88ca --- /dev/null +++ b/homeManagerModules/services/swayosd/default.nix @@ -0,0 +1,78 @@ +{ + config, + lib, + pkgs, + ... +}: let + cfg = config.ar.home; +in { + config = lib.mkIf cfg.services.swayosd.enable { + home.packages = with pkgs; [ + swayosd + ]; + + services.swayosd = { + enable = lib.mkDefault true; + stylePath = "${config.xdg.configHome}/swayosd/style.css"; + }; + + systemd.user.services.swayosd = { + Install.WantedBy = lib.mkForce ["hyprland-session.target" "sway-session.target"]; + + Service = { + Restart = lib.mkForce "on-failure"; + RestartSec = 5; + }; + }; + + xdg.configFile."swayosd/style.css" = { + text = '' + window#osd { + padding: 12px 20px; + border-radius: ${toString cfg.theme.borderRadius}px; + border: 4px solid alpha(${cfg.theme.colors.primary}, 0.8); + background: alpha(${cfg.theme.colors.background}, 0.8); + } + + window#osd #container { + margin: 16px; + } + + window#osd image, + window#osd label { + color: ${cfg.theme.colors.secondary}; + } + + window#osd progressbar:disabled, + window#osd image:disabled { + opacity: 0.5; + } + + window#osd progressbar { + min-height: 6px; + border-radius: 999px; + background: transparent; + border: none; + } + + window#osd trough { + min-height: inherit; + border-radius: inherit; + border: none; + background: alpha(${cfg.theme.colors.secondary}, 0.5); + } + + window#osd progress { + min-height: inherit; + border-radius: inherit; + border: none; + background: ${cfg.theme.colors.secondary}; + } + ''; + + onChange = '' + ${lib.getExe' pkgs.systemd "systemctl"} restart --user swayosd + ''; + }; + }; +} diff --git a/nixosModules/desktop/default.nix b/nixosModules/desktop/default.nix index 36bda86a..5a504fac 100644 --- a/nixosModules/desktop/default.nix +++ b/nixosModules/desktop/default.nix @@ -52,6 +52,7 @@ xserver = { enable = true; excludePackages = with pkgs; [xterm]; + libinput.enable = true; }; }; };