module(waybar): Refactor waybar module

This commit is contained in:
ulic-youthlic 2025-07-13 06:04:55 +08:00
parent 90a5b36616
commit 6c4546df9c
Signed by: youthlic
GPG key ID: 63E86C3C14A0D721
4 changed files with 181 additions and 129 deletions

View file

@ -1,7 +1,14 @@
{inputs, ...}: let
{
config,
inputs,
...
}: let
inherit (inputs.niri-flake.lib.kdl) node leaf flag;
in {
david.programs.niri = {
waybar.settings = let
cfg = config.david.programs.niri.waybar;
in [(cfg.template // (cfg.mkBacklight "intel_backlight") // {output = "eDP-1";})];
wluma.extraSettings = {
output = {
backlight = [

View file

@ -1,7 +1,17 @@
{inputs, ...}: let
{
config,
inputs,
...
}: let
inherit (inputs.niri-flake.lib.kdl) node leaf flag;
in {
david.programs.niri = {
waybar.settings = let
cfg = config.david.programs.niri.waybar;
in [
(cfg.template // (cfg.helper.mkBacklight "ddcci13") // {output = "DP-3";})
(cfg.template // (cfg.helper.mkBacklight "nvidia_0") // {output = "eDP-1";})
];
wluma.extraSettings = {
output = {
backlight = [
@ -12,7 +22,7 @@ in {
}
{
name = "DP-3";
path = "/sys/class/backlight/ddcci15";
path = "/sys/class/backlight/ddcci13";
capturer = "wayland";
}
];

View file

@ -19,6 +19,21 @@ in {
wluma.extraSettings = lib.mkOption {
inherit (options.david.programs.wluma.extraSettings) type;
};
waybar = {
template = lib.mkOption {
readOnly = true;
type = lib.types.anything;
default = config.david.programs.waybar.template;
};
helper = lib.mkOption {
readOnly = true;
type = lib.types.anything;
default = config.david.programs.waybar.helper;
};
settings = lib.mkOption {
inherit (options.david.programs.waybar.settings) type;
};
};
};
};
config = lib.mkMerge [
@ -65,7 +80,10 @@ in {
};
david.programs = {
fuzzel.enable = true;
waybar.enable = true;
waybar = {
enable = true;
inherit (cfg.waybar) settings;
};
wluma = {
enable = true;
inherit (cfg.wluma) extraSettings;

View file

@ -2,6 +2,7 @@
pkgs,
config,
lib,
options,
...
}: let
cfg = config.david.programs.waybar;
@ -9,15 +10,13 @@ in {
options = {
david.programs.waybar = {
enable = lib.mkEnableOption "waybar";
settings = lib.mkOption {
type = options.programs.waybar.settings.type;
};
};
config = lib.mkMerge [
(lib.mkIf cfg.enable {
programs.waybar = {
enable = true;
systemd.enable = false;
settings = [
{
template = lib.mkOption {
readOnly = true;
type = lib.types.anything;
default = {
layer = "top";
position = "top";
modules-left = [
@ -29,7 +28,7 @@ in {
"tray"
"idle_inhibitor"
"memory"
"backlight"
"custom/backlight"
"pulseaudio"
"battery"
"custom/notification"
@ -61,12 +60,6 @@ in {
format = " {percentage}%";
on-click = lib.getExe pkgs.resources;
};
backlight = {
format = "{icon}{percent}%";
format-icons = " ";
on-scroll-up = "${lib.getExe pkgs.brightnessctl} set +1%";
on-scroll-down = "${lib.getExe pkgs.brightnessctl} set 1%-";
};
pulseaudio = {
format = "{icon}{volume}%";
@ -138,8 +131,32 @@ in {
"on-click-right" = "swaync-client -d -sw";
"escape" = true;
};
}
];
};
};
helper = lib.mkOption {
type = lib.types.anything;
readOnly = true;
default = {
mkBacklight = device: {
"custom/backlight" = {
format = "{icon}{}%";
interval = 2;
exec = "cat /sys/class/backlight/${device}/actual_brightness";
format-icons = " ";
on-scroll-up = "${lib.getExe pkgs.brightnessctl} -d ${device} set +1%";
on-scroll-down = "${lib.getExe pkgs.brightnessctl} -d ${device} set 1%-";
};
};
};
};
};
};
config = lib.mkMerge [
(lib.mkIf cfg.enable {
programs.waybar = {
enable = true;
systemd.enable = false;
settings = cfg.settings;
style = ''
* {
font-family: Libertinus Serif, Source Han Serif;
@ -160,7 +177,7 @@ in {
#tray,
#mpris,
#idle_inhibitor,
#backlight,
#custom-backlight,
#cpu,
#memory,
#pulseaudio,