1

Hyprland: Use HM module for waybar config instead of own files

This commit is contained in:
2024-10-13 14:32:19 +02:00
parent d34196f06f
commit 4e4dd67185
7 changed files with 104 additions and 158 deletions

View File

@ -1 +0,0 @@

View File

@ -1,86 +0,0 @@
[
{
"include": [
"~/.config/waybar/monitor.json"
],
"layer": "top",
"position": "top",
"height": 40,
"spacing": 4,
"modules-left": [
"custom/launcher",
"user",
"hyprland/window"
],
"modules-center": [
"hyprland/workspaces"
],
"modules-right": [
"pulseaudio",
"network",
"cpu",
"memory",
"temperature",
"clock",
"tray"
],
"custom/launcher": {
"format": "<span font=\"FontAwesome\"></span> ",
"interval": "once",
"tooltip": false
},
"hyprland/workspaces": {
"all-outputs": false,
"format": "{name}",
"on-click": "activate",
"sort-by-coordinates": false,
"sort-by-name": true,
"sort-by-number": false
},
"pulseaudio": {
"format": "<span font=\"FontAwesome\"></span> {volume}%",
"format-muted": "<span font=\"FontAwesome\"></span> ",
// "on-click": "alacritty -o font.size=12 -e ncpamixer -t o"
"on-click": "kitty ncpamixer -t o"
},
"network": {
"format": "<span font=\"FontAwesome\"></span> {ipaddr}",
"format-disconnected": "<span font=\"FontAwesome\"></span> ",
"interface": "enp8s0",
"tooltip-format": "{ifname} via {gwaddr}"
},
"cpu": {
"format": "<span font=\"FontAwesome\"></span> {load}%"
},
"memory": {
"format": "<span font=\"FontAwesome\"></span> {percentage}%"
},
"temperature": {
"format": "<span font=\"FontAwesome\"></span> {temperatureC}°C",
"thermal-zone": 3
},
"clock": {
"format": "<span font=\"FontAwesome\"></span> {:%H:%M}",
"timezone": "Europe/Berlin",
"tooltip-format": "<tt><small>{calendar}</small></tt>"
},
"tray": {
"icon-size": 20,
"show-passive-items": true,
"spacing": 5
}
}
]

View File

@ -62,6 +62,7 @@ with mylib.modules; {
"kitty"
]
'';
default = [];
};
delayed = mkOption {

View File

@ -1,5 +1,3 @@
# TODO: Generate the config modularly, like with hyprland
# - It should especially be possible to set styling programatically, for themes
{
config,
lib,
@ -10,70 +8,83 @@
with lib;
with mylib.modules; let
cfg = config.modules.waybar;
hyprcfg = config.modules.hyprland;
in {
options.modules.waybar = import ./options.nix {inherit lib mylib;};
/*
config = let
# Taken from https://github.com/Ruixi-rebirth/flakes/blob/main/modules/programs/wayland/waybar/workspace-patch.nix
hyprctl = "${pkgs.hyprland}/bin/hyprctl";
workspaces-patch = pkgs.writeTextFile {
name = "waybar-hyprctl.diff";
text = ''
diff --git a/src/modules/wlr/workspace_manager.cpp b/src/modules/wlr/workspace_manager.cpp
index 6a496e6..a689be0 100644
--- a/src/modules/wlr/workspace_manager.cpp
+++ b/src/modules/wlr/workspace_manager.cpp
@@ -511,7 +511,9 @@ auto Workspace::handle_clicked(GdkEventButton *bt) -> bool {
if (action.empty())
return true;
else if (action == "activate") {
- zext_workspace_handle_v1_activate(workspace_handle_);
+ // zext_workspace_handle_v1_activate(workspace_handle_);
+ const std::string command = "${hyprctl} dispatch workspace " + name_;
+ system(command.c_str());
} else if (action == "close") {
zext_workspace_handle_v1_remove(workspace_handle_);
} else {
'';
};
waybar-hyprland = pkgs.waybar.overrideAttrs (oldAttrs: {
mesonFlags = oldAttrs.mesonFlags ++ ["-Dexperimental=true"];
patches = (oldAttrs.patches or []) ++ [workspaces-patch];
});
in
*/
config = mkIf cfg.enable {
programs.waybar = {
enable = true;
# package = waybar-hyprland;
package = pkgs.waybar;
systemd.enable = true;
systemd = {
enable = false; # Gets started by hyprland
settings = {
mainBar = {
layer = "top";
position = "top";
height = 40;
spacing = 4;
output = ["${cfg.monitor}"];
modules-left = ["custom/launcher" "user" "hyprland/window"];
modules-center = ["hyprland/workspaces"];
modules-right = ["pulseaudio" "network" "cpu" "memory" "temperature" "clock" "tray"];
"custom/launcher" = {
format = "<span font='FontAwesome'></span> ";
interval = "once";
tooltip = false;
};
"hyprland/workspaces" = {
all-outputs = false;
format = "{name}";
on-click = "activate";
sort-by-coordinates = false;
sort-by-name = true;
sort-by-number = false;
};
"pulseaudio" = {
format = "<span font='FontAwesome'></span> {volume}%";
format-muted = "<span font='FontAwesome'></span> ";
on-click = "kitty ncpamixer -t o";
};
"network" = {
format = "<span font='FontAwesome'></span> {ipaddr}";
format-disconnected = "<span font='FontAwesome'></span> ";
interface = "enp8s0";
tooltip-format = "{ifname} via {gwaddr}";
};
cpu = {
format = "<span font='FontAwesome'></span> {load}%";
};
memory = {
format = "<span font='FontAwesome'></span> {percentage}%";
};
temperature = {
format = "<span font='FontAwesome'></span> {temperatureC}°C";
thermal-zone = 3;
};
clock = {
format = "<span font='FontAwesome'></span> {:%H:%M}";
timezone = "Europe/Berlin";
tooltip-format = "<tt><small>{calendar}</small></tt>";
};
tray = {
icon-size = 20;
show-passive-items = true;
spacing = 5;
};
};
};
style = "@import url('colors/${hyprcfg.theme}.css')" + builtins.readFile ./style.css;
};
modules.hyprland.autostart.immediate = let
waybar-reload = pkgs.writeScript "waybar-reload" ''
#! ${pkgs.bash}/bin/bash
trap "${pkgs.procps}/bin/pkill waybar" EXIT
while true; do
${pkgs.waybar}/bin/waybar -c $HOME/NixFlake/config/waybar/config.json -s $HOME/NixFlake/config/waybar/style.css &
${pkgs.inotifyTools}/bin/inotifywait -e create,modify $HOME/NixFlake/config/waybar/config.json $HOME/NixFlake/config/waybar/style.css
${pkgs.procps}/bin/pkill waybar
done
'';
in [
"${waybar-reload}"
];
home.file.".config/waybar/monitor.json".text = ''
{
"output": "${cfg.monitor}"
}
'';
};
}

View File

@ -1,4 +1,3 @@
/*TODO: Set this through nixos module programatically*/
/*@import url("colors/three-bears.css");*/
@import url("colors/foggy-lake.css");
@ -8,7 +7,7 @@ window#waybar {
font-family: JetBrainsMono Nerd Font Mono;
font-weight: bold;
color: @base;
background-color: rgba(239,241,245,0.6);
background-color: rgba(239, 241, 245, 0.6);
}
/*Square Widgets*/
@ -46,14 +45,36 @@ window#waybar {
}
/*Colors*/
#custom-launcher { background-color: @flamingo; }
#user { background-color: @pink; }
#window { background-color: @mauve; }
#workspaces button { background-color: @red; }
#pulseaudio { background-color: @maroon; }
#network { background-color: @peach; }
#cpu { background-color: @yellow; }
#memory { background-color: @green; }
#temperature { background-color: @teal; }
#clock { background-color: @sky; }
#tray { background-color: @sapphire; }
#custom-launcher {
background-color: @flamingo;
}
#user {
background-color: @pink;
}
#window {
background-color: @mauve;
}
#workspaces button {
background-color: @red;
}
#pulseaudio {
background-color: @maroon;
}
#network {
background-color: @peach;
}
#cpu {
background-color: @yellow;
}
#memory {
background-color: @green;
}
#temperature {
background-color: @teal;
}
#clock {
background-color: @sky;
}
#tray {
background-color: @sapphire;
}