Waybar : Refactor config.

This commit is contained in:
Dmitry Voronin 2024-06-23 00:14:13 +03:00
parent a4c027fbb3
commit 2ed0b8ba85
Signed by: voronind
SSH key fingerprint: SHA256:3kBb4iV2ahufEBNq+vFbUe4QYfHt98DHQjN7QaptY9k
5 changed files with 143 additions and 142 deletions

View file

@ -22,7 +22,7 @@
experimental-features = nix-command flakes experimental-features = nix-command flakes
keep-derivations = true keep-derivations = true
keep-outputs = true keep-outputs = true
min-free = ${toString 50 * 1000 * 1000 * 1000} min-free = ${toString (50 * 1000 * 1000 * 1000)}
''; '';
# NOTE: Currently I run GC completely, but this setting (put above near min-free) # NOTE: Currently I run GC completely, but this setting (put above near min-free)

View file

@ -4,7 +4,7 @@ in {
programs.waybar.enable = true; programs.waybar.enable = true;
environment.variables = { environment.variables = {
WAYBAR_CONFIG = pkgs.writeText "waybarConfig" waybar.config; WAYBAR_CONFIG = waybar.config;
WAYBAR_STYLE = pkgs.writeText "waybarStyle" waybar.style; WAYBAR_STYLE = waybar.style;
}; };
} }

View file

@ -1,137 +1,137 @@
{ setting, style, ... }: let { setting, style, pkgs, ... }: let
refreshInterval = 2; refreshInterval = 2;
in { in {
text = '' file = (pkgs.formats.json {}).generate "WaybarConfig" {
// -*- mode: jsonc -*- height = 30;
{ layer = "top";
"layer": "top", margin-left = style.window.gap;
"position": "top", margin-right = style.window.gap;
"height": 30, margin-top = style.window.gap;
"spacing": 4, mode = "dock";
"margin-top": ${toString style.window.gap}, position = "top";
"margin-left": ${toString style.window.gap}, spacing = 4;
"margin-right": ${toString style.window.gap}, start_hidden = false;
"mode": "dock", # exclusive = false;
// "exclusive": false, modules-left = [
"start_hidden": false, "sway/workspaces"
"modules-left": [ "sway/scratchpad"
"sway/workspaces", ];
"sway/scratchpad", modules-center = [
], "clock"
"modules-center": [
"clock",
"mpris" "mpris"
], ];
"modules-right": [ modules-right = [
"sway/language", "sway/language"
"pulseaudio", "pulseaudio"
"battery", "battery"
"custom/powerlimit", "custom/powerlimit"
"cpu", "cpu"
// "temperature", # "temperature"
"memory", "memory"
"custom/powersave", "custom/powersave"
"custom/display", "custom/display"
"tray" "tray"
], ];
"sway/language": { "sway/language" = {
"tooltip": false, tooltip = false;
"on-click": "swaymsg 'input * xkb_switch_layout next'" on-click = "swaymsg 'input * xkb_switch_layout next'";
}, };
"sway/scratchpad": { "sway/scratchpad" = {
"format": "{icon} {count}", format = "{icon} {count}";
"show-empty": false, show-empty = false;
"format-icons": ["", ""], format-icons = [ "" "" ];
"tooltip": true, tooltip = true;
"tooltip-format": "{app}: {title}", tooltip-format = "{app}: {title}";
"on-click": "swaymsg 'scratchpad show'", on-click = "swaymsg 'scratchpad show'";
"on-click-right": "swayscript scratchpad_kill" on-click-right = "swayscript scratchpad_kill";
}, };
"tray": { tray = {
// "icon-size": 21, # icon-size = 21;
"spacing": 10 spacing = 1;
}, };
"clock": { clock = {
// "timezone": "America/New_York", # timezone = "America/New_York";
"tooltip-format": "<big><tt>{calendar}</tt></big>", tooltip-format = "<big><tt>{calendar}</tt></big>";
"format-alt": "{:%d %a %H:%M}", format-alt = "{:%d %a %H:%M}";
}, calendar = {
"battery": { mode-mon-col = 3;
"states": { };
"good": 60, };
"warning": 40, battery = {
"critical": 20 states = {
}, good = 60;
"format": "{capacity}% {icon}", warning = 40;
"format-charging": "{capacity}% ", critical = 2;
"format-plugged": "{capacity}% ", };
"format-alt": "{time} {icon}", format = "{capacity}% {icon}";
"format-icons": ["󰂎", "󱊡", "󱊢", "󱊣", "󱊣"], format-charging = "{capacity}% ";
"on-click-right": "powerlimit toggle", format-plugged = "{capacity}% ";
"interval": ${toString refreshInterval}, format-alt = "{time} {icon}";
}, format-icons = ["󰂎" "󱊡" "󱊢" "󱊣" "󱊣"];
"custom/powerlimit": { on-click-right = "powerlimit toggle";
"exec": "powerlimit waybar", interval = refreshInterval;
"interval": ${toString refreshInterval}, };
"on-click-right": "powerlimit toggle" "custom/powerlimit" = {
}, exec = "powerlimit waybar";
"pulseaudio": { interval = refreshInterval;
"scroll-step": ${toString setting.volume.step}, on-click-right = "powerlimit toggle";
"format": "{volume}% {icon}", };
"format-muted": "󰸈", pulseaudio = {
"format-icons": { scroll-step = setting.volume.step;
"default": ["", "", ""] format = "{volume}% {icon}";
}, format-muted = "󰸈";
"on-click-right": "pactl set-sink-mute @DEFAULT_SINK@ toggle", format-icons = {
"on-click-middle": "swayscript sound_output_cycle", default = [ "" "" "" ];
"on-click": "pavucontrol" };
}, on-click-right = "pactl set-sink-mute @DEFAULT_SINK@ toggle";
"mpris": { on-click-middle = "swayscript sound_output_cycle";
"format": "{player_icon} {title} - {artist}", on-click = "pavucontrol";
"format-paused": "{status_icon} {title} - {artist}", };
"player-icons": { mpris = {
"default": "", format = "{player_icon} {title} - {artist}";
"firefox": "󰈹", format-paused = "{status_icon} {title} - {artist}";
"mpv": "" player-icons = {
}, "default" = "";
"status-icons": { "firefox" = "󰈹";
"paused": "" "mpv" = "";
}, };
"on-click-middle": "playerctl stop" status-icons = {
// "ignored-players": ["firefox"] "paused" = "";
}, };
"cpu": { on-click-middle = "playerctl stop";
"format": "{usage}% ({load})", # ignored-players = [ "firefox" ];
"tooltip": false, };
"on-click": "foot -e bash -c btop", cpu = {
"on-click-right": "powersave toggle", format = "{usage}% ({load})";
"interval": ${toString refreshInterval}, interval = refreshInterval;
}, on-click = "foot -e bash -c btop";
"memory": { on-click-right = "powersave toggle";
"format": "{percentage}%", tooltip = false;
"on-click": "foot -e bash -c btop", };
"on-click-right": "powersave toggle", memory = {
"interval": ${toString refreshInterval}, format = "{percentage}%";
}, interval = refreshInterval;
"temperature": { on-click = "foot -e bash -c btop";
"format": "{temperatureC}°C", on-click-right = "powersave toggle";
"on-click": "foot -e bash -c btop", };
"on-click-right": "powersave toggle", temperature = {
"interval": ${toString refreshInterval}, format = "{temperatureC}°C";
}, interval = refreshInterval;
"custom/powersave": { on-click = "foot -e bash -c btop";
"exec": "powersave waybar", on-click-right = "powersave toggle";
"interval": ${toString refreshInterval}, };
"on-click": "foot -e bash -c btop", "custom/powersave" = {
"on-click-right": "powersave toggle" exec = "powersave waybar";
}, interval = refreshInterval;
"custom/display": { on-click = "foot -e bash -c btop";
"exec": "swayscript monbar", on-click-right = "powersave toggle";
"interval": ${toString refreshInterval}, };
"return-type": "json", "custom/display" = {
"on-click": "sleep 0.1 && swayscript montoggle", // FIXME: remove sleep when resolved: https://github.com/Alexays/Waybar/issues/2166 exec = "swayscript monbar";
"on-click-right": "sleep 0.1 && swayscript vrrtoggle" interval = refreshInterval;
} on-click = "sleep 0.1 && swayscript montoggle"; # FIXME: remove sleep when resolved: https://github.com/Alexays/Waybar/issues/216
} on-click-right = "sleep 0.1 && swayscript vrrtoggle";
''; return-type = "json";
};
};
} }

View file

@ -1,4 +1,4 @@
{ util, ... } @args: { { util, pkgs, ... } @args: {
config = (import ./config args).text; config = (import ./config args).file;
style = util.catText (util.ls ./style) args; style = pkgs.writeText "WaybarStyle" (util.catText (util.ls ./style) args);
} }

View file

@ -77,10 +77,11 @@
mime = "audio/*"; mime = "audio/*";
use = "audio"; use = "audio";
} { } {
name = "*.json"; mime = "application/json";
use = "text"; use = "text";
} { } {
name = "*.html"; # name = "*.html";
mime = "text/html";
use = [ "browser" "text" ]; use = [ "browser" "text" ];
} }
]; ];