From 734da366392bfb2e1ba970f45b255cc4f55045f8 Mon Sep 17 00:00:00 2001 From: Colin Date: Fri, 14 Jun 2024 08:38:53 +0000 Subject: [PATCH] nwg-panel: make configurable through nix --- hosts/common/programs/nwg-panel/config | 12 ++--- hosts/common/programs/nwg-panel/default.nix | 51 +++++++++++++++++-- .../nwg-panel/playerctl-no-prev-next.diff | 36 +++++++++++++ hosts/common/programs/nwg-panel/style.css | 2 +- hosts/modules/roles/handheld.nix | 8 +++ 5 files changed, 99 insertions(+), 10 deletions(-) create mode 100644 hosts/common/programs/nwg-panel/playerctl-no-prev-next.diff diff --git a/hosts/common/programs/nwg-panel/config b/hosts/common/programs/nwg-panel/config index 0db2576d..135539b0 100644 --- a/hosts/common/programs/nwg-panel/config +++ b/hosts/common/programs/nwg-panel/config @@ -6,7 +6,7 @@ "position": "top", "controls": "right", "width": "auto", - "height": 40, + "height": @height@, "homogeneous": true, "margin-top": 0, "margin-bottom": 0, @@ -84,8 +84,8 @@ "image-size": 16, "workspaces-spacing": 0, "task-padding": 0, - "show-app-icon": true, - "show-app-name": true, + "show-app-icon": @windowIcon@, + "show-app-name": @windowTitle@, "show-layout": false, "workspace-buttons": false, "all-workspaces": true, @@ -109,9 +109,9 @@ ], "custom-labels": [], "focused-labels": [], - "show-icon": true, + "show-icon": @windowIcon@, "image-size": 16, - "show-name": true, + "show-name": @windowTitle@, "name-length": 40, "mark-autotiling": true, "mark-content": false, @@ -144,7 +144,7 @@ "playerctl": { "buttons-position": "left", "icon-size": 16, - "chars": 30, + "chars": @playerctlChars@, "scroll": false, "button-css-name": "playerctl-button", "label-css-name": "playerctl-label", diff --git a/hosts/common/programs/nwg-panel/default.nix b/hosts/common/programs/nwg-panel/default.nix index 1bf18811..5d83d77d 100644 --- a/hosts/common/programs/nwg-panel/default.nix +++ b/hosts/common/programs/nwg-panel/default.nix @@ -4,11 +4,56 @@ # # interactively configure with: `nwg-panel-config` # ^ note that this may interfere with the `nwg-panel` service -{ ... }: +{ config, lib, pkgs, ... }: +let + cfg = config.sane.programs.nwg-panel; + mkEnableOption' = default: description: lib.mkOption { + type = lib.types.bool; + inherit default description; + }; +in { sane.programs.nwg-panel = { - fs.".config/nwg-panel/config".symlink.target = ./config; - fs.".config/nwg-panel/style.css".symlink.target = ./style.css; + configOption = with lib; mkOption { + default = {}; + type = types.submodule { + options = { + fontSize = mkOption { + type = types.int; + default = 16; + }; + height = mkOption { + type = types.int; + default = 40; + description = '' + height of the top bar in px. + ''; + }; + mediaTitle = mkEnableOption' true "display title of current song/media"; + mediaPrevNext = mkEnableOption' true "display prev/next button in media"; + windowIcon = mkEnableOption' true "display icon of active window"; + windowTitle = mkEnableOption' true "display title of active window"; + }; + }; + }; + + packageUnwrapped = pkgs.nwg-panel.overrideAttrs (base: { + patches = (base.patches or []) ++ lib.optionals (!cfg.config.mediaPrevNext) [ + ./playerctl-no-prev-next.diff + ]; + }); + + # fs.".config/nwg-panel/config".symlink.target = ./config; + # fs.".config/nwg-panel/style.css".symlink.target = ./style.css; + fs.".config/nwg-panel/config".symlink.target = pkgs.substituteAll { + src = ./config; + inherit (cfg.config) height windowIcon windowTitle; + playerctlChars = if cfg.config.mediaTitle then 30 else 0; + }; + fs.".config/nwg-panel/style.css".symlink.target = pkgs.substituteAll { + src = ./style.css; + inherit (cfg.config) fontSize; + }; services.nwg-panel = { description = "nwg-panel status/topbar for wayland"; diff --git a/hosts/common/programs/nwg-panel/playerctl-no-prev-next.diff b/hosts/common/programs/nwg-panel/playerctl-no-prev-next.diff new file mode 100644 index 00000000..095e480b --- /dev/null +++ b/hosts/common/programs/nwg-panel/playerctl-no-prev-next.diff @@ -0,0 +1,36 @@ +diff --git a/nwg_panel/modules/playerctl.py b/nwg_panel/modules/playerctl.py +index 9b53b4b..c4d96ae 100644 +--- a/nwg_panel/modules/playerctl.py ++++ b/nwg_panel/modules/playerctl.py +@@ -180,15 +180,6 @@ class Playerctl(Gtk.EventBox): + if self.settings["angle"] != 0.0: + button_box.set_orientation(Gtk.Orientation.VERTICAL) + +- img = Gtk.Image() +- update_image(img, "media-skip-backward-symbolic", self.settings["icon-size"], icons_path=self.icons_path) +- btn = Gtk.Button() +- btn.set_image(img) +- if self.settings["button-css-name"]: +- btn.set_property("name", self.settings["button-css-name"]) +- btn.connect("clicked", self.launch, self.PlayerOps.PREVIOUS) +- button_box.pack_start(btn, False, False, 1) +- + self.play_pause_btn = Gtk.Button() + if self.settings["button-css-name"]: + self.play_pause_btn.set_property("name", self.settings["button-css-name"]) +@@ -198,15 +189,6 @@ class Playerctl(Gtk.EventBox): + self.play_pause_btn.connect("clicked", self.launch, self.PlayerOps.PLAY_PAUSE) + button_box.pack_start(self.play_pause_btn, False, False, 1) + +- img = Gtk.Image() +- update_image(img, "media-skip-forward-symbolic", self.settings["icon-size"], icons_path=self.icons_path) +- btn = Gtk.Button() +- btn.set_image(img) +- if self.settings["button-css-name"]: +- btn.set_property("name", self.settings["button-css-name"]) +- btn.connect("clicked", self.launch, self.PlayerOps.NEXT) +- button_box.pack_start(btn, False, False, 1) +- + self.label = AutoScrollLabel(self.settings["scroll"], + self.settings["chars"], + self.settings["interval"]) diff --git a/hosts/common/programs/nwg-panel/style.css b/hosts/common/programs/nwg-panel/style.css index abe0e0d6..d17818d9 100644 --- a/hosts/common/programs/nwg-panel/style.css +++ b/hosts/common/programs/nwg-panel/style.css @@ -17,7 +17,7 @@ * { - font-size: 16px; + font-size: @fontSize@px; } button { diff --git a/hosts/modules/roles/handheld.nix b/hosts/modules/roles/handheld.nix index 54ca2975..53ebf8d8 100644 --- a/hosts/modules/roles/handheld.nix +++ b/hosts/modules/roles/handheld.nix @@ -56,6 +56,14 @@ modules.windowTitle = false; # TODO: show modem state }; + sane.programs.nwg-panel.config = { + fontSize = 14; + height = 26; + windowIcon = false; + windowTitle = false; + mediaPrevNext = false; + mediaTitle = false; + }; sane.programs.zsh.config.showDeadlines = false; # unlikely to act on them when in shell };