From c143c065a2308a50814a5615815440165dc44d0b Mon Sep 17 00:00:00 2001 From: Donovan Glover Date: Thu, 29 Jun 2023 09:58:23 -0400 Subject: [PATCH] waybar: Move modules to separate attribute set Makes it possible to use the same modules in multiple bars. --- home/waybar.nix | 155 ++++++++++++++++++++++++------------------------ 1 file changed, 78 insertions(+), 77 deletions(-) diff --git a/home/waybar.nix b/home/waybar.nix index 7ea8c01..e562f51 100644 --- a/home/waybar.nix +++ b/home/waybar.nix @@ -6,13 +6,90 @@ let position = "top"; opposite = builtins.replaceStrings ["left" "right" "top" "bottom"] ["right" "left" "bottom" "top"] position; isVertical = position == "left" || position == "right"; + modules = { + tray = { + icon-size = 24; + spacing = 8; + }; + + "wlr/taskbar" = { + icon-size = 32; + on-click = "activate"; + on-click-middle = "activate"; + on-click-right = "activate"; + }; + + "hyprland/window" = { + rotate = if isVertical then 90 else 0; + }; + + "wlr/workspaces" = { + on-click = "activate"; + sort-by-number = true; + format = "{icon}"; + format-icons = { + "1" = "一"; + "2" = "二"; + "3" = "三"; + "4" = "四"; + "5" = "五"; + "6" = "六"; + "7" = "七"; + "8" = "八"; + "9" = "九"; + "10" = "十"; + }; + }; + + wireplumber = { + format = "{icon}"; + tooltip-format = "{volume}% {node_name}"; + format-muted = ""; + format-icons = [ "" "" ]; + }; + + battery = { + format = "{icon}"; + tooltip-format = "{capacity}% {timeTo}"; + format-icons = [ "" "" "" "" "" ]; + }; + + clock = { + format = if isVertical then "{:%H\n%M}" else "{:%H:%M}"; + tooltip-format = "{calendar}"; + calendar = { + mode = "month"; + weeks-pos = "right"; + format = { + months = "{}"; + days = "{}"; + weeks = "W{}"; + weekdays = "{}"; + today = "{}"; + }; + }; + }; + + backlight = { + format = "{icon}"; + format-icons = [ "" "" ]; + }; + + "custom/new-workspace" = { + format = "+"; + on-click = "hyprctl dispatch workspace empty && sleep 0.1 && rofi -show drun"; + on-click-right = "sleep 0.1 && rofi -show drun"; + on-click-middle = "hyprctl dispatch workspace empty"; + tooltip = false; + }; + }; in { programs.waybar = { enable = true; settings = { - mainBar = { + mainBar = modules // { layer = "top"; position = position; width = if isVertical then 45 else null; @@ -25,82 +102,6 @@ in modules-left = if icons then [ "wlr/taskbar" ] else [ "wlr/workspaces" "custom/new-workspace" ]; modules-right = [ "tray" "wireplumber" "backlight" "battery" "clock" ]; - - tray = { - icon-size = 24; - spacing = 8; - }; - - "wlr/taskbar" = { - icon-size = 32; - on-click = "activate"; - on-click-middle = "activate"; - on-click-right = "activate"; - }; - - "hyprland/window" = { - rotate = if isVertical then 90 else 0; - }; - - "wlr/workspaces" = { - on-click = "activate"; - sort-by-number = true; - format = "{icon}"; - format-icons = { - "1" = "一"; - "2" = "二"; - "3" = "三"; - "4" = "四"; - "5" = "五"; - "6" = "六"; - "7" = "七"; - "8" = "八"; - "9" = "九"; - "10" = "十"; - }; - }; - - wireplumber = { - format = "{icon}"; - tooltip-format = "{volume}% {node_name}"; - format-muted = ""; - format-icons = [ "" "" ]; - }; - - battery = { - format = "{icon}"; - tooltip-format = "{capacity}% {timeTo}"; - format-icons = [ "" "" "" "" "" ]; - }; - - clock = { - format = if isVertical then "{:%H\n%M}" else "{:%H:%M}"; - tooltip-format = "{calendar}"; - calendar = { - mode = "month"; - weeks-pos = "right"; - format = { - months = "{}"; - days = "{}"; - weeks = "W{}"; - weekdays = "{}"; - today = "{}"; - }; - }; - }; - - backlight = { - format = "{icon}"; - format-icons = [ "" "" ]; - }; - - "custom/new-workspace" = { - format = "+"; - on-click = "hyprctl dispatch workspace empty && sleep 0.1 && rofi -show drun"; - on-click-right = "sleep 0.1 && rofi -show drun"; - on-click-middle = "hyprctl dispatch workspace empty"; - tooltip = false; - }; }; };