From d1858c51b53e3ebcd841416490c17f7b22334e6a Mon Sep 17 00:00:00 2001 From: Arpit Chakladar Date: Wed, 26 Aug 2026 04:26:19 +0530 Subject: desktop: replaced waybar with eww - added some basic configuration options for eww - removed waybar --- modules/desktop/default.nix | 2 +- modules/desktop/eww/default.nix | 27 +++++++++ modules/desktop/eww/eww.scss.mustache | 56 +++++++++++++++++ modules/desktop/eww/scss.nix | 7 +++ modules/desktop/eww/yuck.nix | 69 +++++++++++++++++++++ modules/desktop/niri/default.nix | 14 +---- modules/desktop/waybar/bar/default.nix | 4 -- modules/desktop/waybar/bar/main.nix | 22 ------- modules/desktop/waybar/default.nix | 35 ----------- modules/desktop/waybar/lib.nix | 33 ---------- modules/desktop/waybar/module/battery.nix | 23 ------- modules/desktop/waybar/module/cpu.nix | 9 --- modules/desktop/waybar/module/date.nix | 10 ---- modules/desktop/waybar/module/default.nix | 27 --------- modules/desktop/waybar/module/memory.nix | 9 --- modules/desktop/waybar/module/network.nix | 25 -------- modules/desktop/waybar/module/time.nix | 10 ---- modules/desktop/waybar/module/usque.nix | 17 ------ modules/desktop/waybar/module/volume.nix | 17 ------ modules/desktop/waybar/module/window.nix | 25 -------- modules/desktop/waybar/module/workspaces.nix | 35 ----------- modules/desktop/waybar/style.mustache.css | 59 ------------------ modules/scripts/activate-windows/default.nix | 23 +++++++ modules/scripts/activate-windows/script.sh | 90 ++++++++++++++++++++++++++++ modules/scripts/default.nix | 2 + modules/scripts/workspaces/default.nix | 23 +++++++ modules/scripts/workspaces/script.sh | 3 + 27 files changed, 304 insertions(+), 372 deletions(-) create mode 100644 modules/desktop/eww/default.nix create mode 100644 modules/desktop/eww/eww.scss.mustache create mode 100644 modules/desktop/eww/scss.nix create mode 100644 modules/desktop/eww/yuck.nix delete mode 100644 modules/desktop/waybar/bar/default.nix delete mode 100644 modules/desktop/waybar/bar/main.nix delete mode 100644 modules/desktop/waybar/default.nix delete mode 100644 modules/desktop/waybar/lib.nix delete mode 100644 modules/desktop/waybar/module/battery.nix delete mode 100644 modules/desktop/waybar/module/cpu.nix delete mode 100644 modules/desktop/waybar/module/date.nix delete mode 100644 modules/desktop/waybar/module/default.nix delete mode 100644 modules/desktop/waybar/module/memory.nix delete mode 100644 modules/desktop/waybar/module/network.nix delete mode 100644 modules/desktop/waybar/module/time.nix delete mode 100644 modules/desktop/waybar/module/usque.nix delete mode 100644 modules/desktop/waybar/module/volume.nix delete mode 100644 modules/desktop/waybar/module/window.nix delete mode 100644 modules/desktop/waybar/module/workspaces.nix delete mode 100644 modules/desktop/waybar/style.mustache.css create mode 100644 modules/scripts/activate-windows/default.nix create mode 100644 modules/scripts/activate-windows/script.sh create mode 100644 modules/scripts/workspaces/default.nix create mode 100644 modules/scripts/workspaces/script.sh (limited to 'modules') diff --git a/modules/desktop/default.nix b/modules/desktop/default.nix index 70011b8..fa4ef5f 100644 --- a/modules/desktop/default.nix +++ b/modules/desktop/default.nix @@ -10,7 +10,7 @@ ./wl-clipboard ./xdg ./niri - ./waybar + ./eww ]; options.desktop = { diff --git a/modules/desktop/eww/default.nix b/modules/desktop/eww/default.nix new file mode 100644 index 0000000..e22f8c6 --- /dev/null +++ b/modules/desktop/eww/default.nix @@ -0,0 +1,27 @@ +{ + config, + lib, + ... +}: +{ + imports = [ + ./yuck.nix + ]; + + options.desktop.eww = { + package = lib.mkOption { + type = lib.types.package; + readOnly = true; + default = config.programs.eww.package; + description = "The eww package to use."; + }; + }; + + config = { + programs.eww = { + enable = true; + systemd.enable = true; + scssConfig = builtins.readFile (import ./scss.nix { inherit config; }); + }; + }; +} diff --git a/modules/desktop/eww/eww.scss.mustache b/modules/desktop/eww/eww.scss.mustache new file mode 100644 index 0000000..a791633 --- /dev/null +++ b/modules/desktop/eww/eww.scss.mustache @@ -0,0 +1,56 @@ +* { + font-family: "Fira Code Nerd Font"; + font-size: 18px; + min-height: 0; +} + +window#eww-bar { + background: transparent; +} + +.bar-container { + background: #{{base00}}; + border: 1px solid #{{base07}}; + padding: 5px 0; + margin: 5px; +} + +.workspaces { + background: transparent; + padding: 0; + margin: 0; +} + +.workspaces button { + background-image: none; + box-shadow: none; + text-shadow: none; + outline: none; + border: none; + padding: 5px 10px; + color: #{{base07}}; + border: 1px solid #{{base07}}; + border-color: #{{base07}}; + border-radius: 0; + min-width: 0; + min-height: 0; + margin: 0 5px; + font-size: 24px; + background: transparent; +} + +.workspaces button:hover { + background: #{{base00}}; + border: 1px solid #{{base07}}; + box-shadow: none; +} + +.workspaces button:active { + background-image: none; + box-shadow: none; +} + +.workspaces button:hover { + background: #{{base00}}; + border-color: #{{base07}}; +} diff --git a/modules/desktop/eww/scss.nix b/modules/desktop/eww/scss.nix new file mode 100644 index 0000000..b535c3a --- /dev/null +++ b/modules/desktop/eww/scss.nix @@ -0,0 +1,7 @@ +{ + config, + ... +}: +config.scheme { + template = builtins.readFile ./eww.scss.mustache; +} diff --git a/modules/desktop/eww/yuck.nix b/modules/desktop/eww/yuck.nix new file mode 100644 index 0000000..d61f70a --- /dev/null +++ b/modules/desktop/eww/yuck.nix @@ -0,0 +1,69 @@ +{ + config, + lib, + pkgs, + ... +}: +{ + config = lib.mkIf config.desktop.enable { + home.file.".config/eww/icons/fallback.svg".text = '' + + + + ''; + + programs.eww.yuckConfig = + let + workspaces = pkgs.writeShellApplication { + name = "eww-workspaces"; + # This automatically adds these packages to the script's PATH + runtimeInputs = with pkgs; [ + niri + jq + ]; + + text = '' + #!/usr/bin/env bash + # Outputs JSON array of workspaces for eww bar + niri msg -j workspaces | jq -c 'sort_by(.idx)' + ''; + }; + in + '' + (defpoll time :interval "10s" "date '+%H:%M'") + (defpoll date :interval "60s" "date '+%d/%m'") + (defpoll workspaces :interval "1s" :initial "[]" "${lib.getExe workspaces}") + (defpoll active-windows :interval "1s" "${lib.getExe config.scripts.eww-active-windows.package}") + + (defwindow bar + :monitor 0 + :geometry (geometry + :x "0px" + :y "0px" + :width "50px" + :height "100%" + :anchor "top right") + :stacking "fg" + :focusable "none" + :reserve (struts :distance "50px" :side "right") + (bar-content)) + + (defwidget bar-content [] + (box :orientation "v" :space-evenly false :class "bar-container" + (box :orientation "v" :space-evenly false :valign "start" :class "top-section" + (workspaces-widget) + (windows-widget)))) + + (defwidget workspaces-widget [] + (box :orientation "v" :space-evenly false :spacing 4 :halign "center" :class "workspaces" + (for ws in workspaces + (button :class {ws.is_active ? "ws-active" : "ws-inactive"} + :onclick "niri msg action focus-workspace ''${ws.idx}" + (label :text "''${ws.idx}"))))) + + (defwidget windows-widget [] + (box :orientation "v" :space-evenly false :spacing 4 :halign "center" :class "windows" + (image :class "win-icon" :path "/tmp/test-icon.svg" :image-width 20 :image-height 20))) + ''; + }; +} diff --git a/modules/desktop/niri/default.nix b/modules/desktop/niri/default.nix index bfa361f..fbcb812 100644 --- a/modules/desktop/niri/default.nix +++ b/modules/desktop/niri/default.nix @@ -69,6 +69,9 @@ }; layout = { gaps = 5; + struts = { + right = 60; + }; center-focused-column = "on-overflow"; default-column-width = { proportion = 1.0; @@ -91,17 +94,6 @@ "-m" "fill" ]; - - # only create upto workspace 9, niri creates a trailing workspace - "workspace \"1\"" = { }; - "workspace \"2\"" = { }; - "workspace \"3\"" = { }; - "workspace \"4\"" = { }; - "workspace \"5\"" = { }; - "workspace \"6\"" = { }; - "workspace \"7\"" = { }; - "workspace \"8\"" = { }; - "workspace \"9\"" = { }; }; }; } diff --git a/modules/desktop/waybar/bar/default.nix b/modules/desktop/waybar/bar/default.nix deleted file mode 100644 index dee84e4..0000000 --- a/modules/desktop/waybar/bar/default.nix +++ /dev/null @@ -1,4 +0,0 @@ -{ config }: -{ - mainBar = import ./main.nix { inherit config; }; -} diff --git a/modules/desktop/waybar/bar/main.nix b/modules/desktop/waybar/bar/main.nix deleted file mode 100644 index 08d816e..0000000 --- a/modules/desktop/waybar/bar/main.nix +++ /dev/null @@ -1,22 +0,0 @@ -{ ... }: -{ - layer = "top"; - position = "top"; - height = 30; - - fixed-center = false; - expand-center = true; - - modules-left = [ "niri/workspaces" ]; - modules-center = [ "niri/window" ]; - modules-right = [ - "pulseaudio" - "battery" - "network" - "custom/usque" - "memory" - "cpu" - "clock#time" - "clock#date" - ]; -} diff --git a/modules/desktop/waybar/default.nix b/modules/desktop/waybar/default.nix deleted file mode 100644 index 927d76f..0000000 --- a/modules/desktop/waybar/default.nix +++ /dev/null @@ -1,35 +0,0 @@ -{ - config, - lib, - pkgs, - ... -}: -{ - options.desktop.waybar = { - package = lib.mkOption { - type = lib.types.package; - readOnly = true; - default = config.programs.waybar.package; - description = "The waybar package to use."; - }; - }; - - config = lib.mkIf config.desktop.enable { - programs.waybar = { - enable = true; - systemd.enable = true; - - settings = lib.mkMerge [ - (import ./bar { inherit config; }) - (import ./module { inherit config lib pkgs; }) - ]; - - style = builtins.readFile ( - config.scheme { - template = builtins.readFile ./style.mustache.css; - extension = ".css"; - } - ); - }; - }; -} diff --git a/modules/desktop/waybar/lib.nix b/modules/desktop/waybar/lib.nix deleted file mode 100644 index ca7a5a8..0000000 --- a/modules/desktop/waybar/lib.nix +++ /dev/null @@ -1,33 +0,0 @@ -{ config, ... }: -with config.scheme.withHashtag; -let - mkIcon = color: icon: "${icon}"; - icons = { - "Default" = mkIcon base07 ""; - "Chromium" = mkIcon "#4285F4" ""; - "Kitty" = mkIcon "#F5A97F" "󰄛"; - "VLC" = mkIcon "#FF8800" "󰕼"; - "Swayimg" = mkIcon "#7EC699" "󰋩"; - "Zathura" = mkIcon "#E06C75" ""; - "Heroic" = mkIcon "#4B93FF" "󱎓"; - "Steam" = mkIcon "#1B2838" "󰓓"; - "Bruno" = mkIcon "#F97316" "󰩃"; - "VSCodium" = mkIcon "#3993EE" ""; - "VirtManager" = mkIcon "#AD8AFF" "󰟀"; - "Opencode" = mkIcon "#98C379" "󰘦"; - "Yazi" = mkIcon "#56B6C2" "󰉋"; - "Chawan" = mkIcon "#8BE9FD" "󰖟"; - "bluetui" = mkIcon "#BD93F9" ""; - "impala" = mkIcon "#50FA7B" "󰤢"; - "neomutt" = mkIcon "#FFB86C" "󰇮"; - "Rofi" = mkIcon "#BD93F9" ""; - "Aria2" = mkIcon "#8BE9FD" ""; - "screen-recording" = mkIcon "#FF5555" ""; - "system-monitor" = mkIcon "#50FA7B" "󰄨"; - "neovim" = mkIcon "#005900" ""; - "gopass" = mkIcon "#FFD700" ""; - }; -in -{ - inherit mkIcon icons; -} diff --git a/modules/desktop/waybar/module/battery.nix b/modules/desktop/waybar/module/battery.nix deleted file mode 100644 index e17d7ea..0000000 --- a/modules/desktop/waybar/module/battery.nix +++ /dev/null @@ -1,23 +0,0 @@ -{ config, mkIcon, ... }: -with config.scheme.withHashtag; -let - iconColor = base09; -in -{ - format = "${mkIcon iconColor "{icon}"} {capacity}%"; - format-charging = "${mkIcon iconColor "󰂄"} {capacity}%"; - format-plugged = "${mkIcon iconColor "󰂅"} {capacity}%"; - format-alt = "{time} {icon}"; - format-icons = [ - "󰁺" - "󰁻" - "󰁼" - "󰁽" - "󰁾" - "󰁿" - "󰂀" - "󰂁" - "󰂂" - "󰁹" - ]; -} diff --git a/modules/desktop/waybar/module/cpu.nix b/modules/desktop/waybar/module/cpu.nix deleted file mode 100644 index e153b32..0000000 --- a/modules/desktop/waybar/module/cpu.nix +++ /dev/null @@ -1,9 +0,0 @@ -{ config, mkIcon, ... }: -with config.scheme.withHashtag; -let - iconColor = base0D; -in -{ - format = "${mkIcon iconColor ""} {usage}%"; - interval = 2; -} diff --git a/modules/desktop/waybar/module/date.nix b/modules/desktop/waybar/module/date.nix deleted file mode 100644 index 9f54514..0000000 --- a/modules/desktop/waybar/module/date.nix +++ /dev/null @@ -1,10 +0,0 @@ -{ config, mkIcon, ... }: -with config.scheme.withHashtag; -let - iconColor = base0E; -in -{ - format = "${mkIcon iconColor ""} {:%d/%m/%Y}"; - tooltip-format = "{:%A, %d/%m/%Y}"; - interval = 60; -} diff --git a/modules/desktop/waybar/module/default.nix b/modules/desktop/waybar/module/default.nix deleted file mode 100644 index b504387..0000000 --- a/modules/desktop/waybar/module/default.nix +++ /dev/null @@ -1,27 +0,0 @@ -{ - lib, - ... -}@input: -let - inherit (import ../lib.nix input) mkIcon icons; - - args = input // { - inherit mkIcon icons; - }; - - modules = { - "battery" = ./battery.nix; - "cpu" = ./cpu.nix; - "clock#date" = ./date.nix; - "memory" = ./memory.nix; - "network" = ./network.nix; - "clock#time" = ./time.nix; - "custom/usque" = ./usque.nix; - "pulseaudio" = ./volume.nix; - "niri/window" = ./window.nix; - "niri/workspaces" = ./workspaces.nix; - }; -in -{ - mainBar = lib.mapAttrs (_name: path: import path args) modules; -} diff --git a/modules/desktop/waybar/module/memory.nix b/modules/desktop/waybar/module/memory.nix deleted file mode 100644 index 53174c2..0000000 --- a/modules/desktop/waybar/module/memory.nix +++ /dev/null @@ -1,9 +0,0 @@ -{ config, mkIcon, ... }: -with config.scheme.withHashtag; -let - iconColor = base0F; -in -{ - format = "${mkIcon iconColor ""} {percentage}%"; - interval = 2; -} diff --git a/modules/desktop/waybar/module/network.nix b/modules/desktop/waybar/module/network.nix deleted file mode 100644 index 48cd6f3..0000000 --- a/modules/desktop/waybar/module/network.nix +++ /dev/null @@ -1,25 +0,0 @@ -{ config, mkIcon, ... }: -with config.scheme.withHashtag; -let - iconColor = base0B; - downloadIcon = mkIcon base0F "󰁅"; - uploadIcon = mkIcon base0F "󰁝"; -in -{ - interval = 2; - - format-wifi = "${mkIcon iconColor "{icon}"} ${downloadIcon}{bandwidthDownBytes} ${uploadIcon}{bandwidthUpBytes}"; - format-ethernet = "${mkIcon iconColor ""} ${downloadIcon}{bandwidthDownBytes} ${uploadIcon}{bandwidthUpBytes}"; - format-disconnected = "${mkIcon iconColor "󰤮"} Disconnected"; - - tooltip-format = "{ifname}"; - tooltip-format-wifi = "{essid} ({signalStrength}%)"; - tooltip-format-ethernet = "Wired: {ipaddr}"; - tooltip-format-disconnected = "Disconnected"; - - format-icons = [ - "󰢼" - "󰢽" - "󰢾" - ]; -} diff --git a/modules/desktop/waybar/module/time.nix b/modules/desktop/waybar/module/time.nix deleted file mode 100644 index adc8632..0000000 --- a/modules/desktop/waybar/module/time.nix +++ /dev/null @@ -1,10 +0,0 @@ -{ config, mkIcon, ... }: -with config.scheme.withHashtag; -let - iconColor = base08; -in -{ - format = "${mkIcon iconColor ""} {:%I:%M %p}"; - tooltip-format = "{:%H:%M:%S}"; - interval = 30; -} diff --git a/modules/desktop/waybar/module/usque.nix b/modules/desktop/waybar/module/usque.nix deleted file mode 100644 index bbcce17..0000000 --- a/modules/desktop/waybar/module/usque.nix +++ /dev/null @@ -1,17 +0,0 @@ -{ - config, - lib, - mkIcon, - ... -}: -with config.scheme.withHashtag; -let - iconColor = base08; -in -{ - exec = "${lib.getExe config.scripts.usque-warp.package} status"; - interval = 5; - return-type = "json"; - hide-empty-text = true; - format = "${mkIcon iconColor "󰒃"} {}"; -} diff --git a/modules/desktop/waybar/module/volume.nix b/modules/desktop/waybar/module/volume.nix deleted file mode 100644 index afb8d4e..0000000 --- a/modules/desktop/waybar/module/volume.nix +++ /dev/null @@ -1,17 +0,0 @@ -{ config, mkIcon, ... }: -with config.scheme.withHashtag; -let - iconColor = base0A; -in -{ - format = "${mkIcon iconColor "{icon}"} {volume}%"; - format-muted = mkIcon iconColor " "; - format-icons = [ - "" - "" - "" - ]; - on-click = "pamixer -t"; - on-scroll-up = "pamixer -i 5"; - on-scroll-down = "pamixer -d 5"; -} diff --git a/modules/desktop/waybar/module/window.nix b/modules/desktop/waybar/module/window.nix deleted file mode 100644 index 0727662..0000000 --- a/modules/desktop/waybar/module/window.nix +++ /dev/null @@ -1,25 +0,0 @@ -{ icons, ... }: -{ - expand = true; - format = "{}"; - rewrite = { - "(.*) - Chromium" = "${icons."Chromium"} $1"; - "(.*?)(?: - )?VLC Media Player" = "${icons."VLC"} $1"; - "(.*)heroic(.*)" = "${icons."Heroic"} $1$2"; - "(.*)Steam(.*)" = "${icons."Steam"} $1$2"; - "bruno" = "${icons."Bruno"} Bruno"; - "(.*) - VSCodium" = "${icons."VSCodium"} $1"; - "Virtual Machine Manager" = "${icons."VirtManager"} Virtual Machine Manager"; - "OC \\|(.*)" = "${icons."Opencode"} $1"; - "OpenCode" = "${icons."Opencode"} OpenCode"; - "Yazi:(.*)" = "${icons."Yazi"} $1"; - "Swayimg:(.*)" = "${icons."Swayimg"} $1"; - "bluetui" = "${icons."bluetui"} bluetui"; - "impala" = "${icons."impala"} impala"; - "neomutt" = "${icons."neomutt"} NeoMutt"; - "screen-recording" = "${icons."screen-recording"} Screen Recording"; - "system-monitor" = "${icons."system-monitor"} System Monitor"; - "nvim(.*)" = "${icons."neovim"} $1"; - "gopass" = "${icons."gopass"} gopass"; - }; -} diff --git a/modules/desktop/waybar/module/workspaces.nix b/modules/desktop/waybar/module/workspaces.nix deleted file mode 100644 index 45e31ec..0000000 --- a/modules/desktop/waybar/module/workspaces.nix +++ /dev/null @@ -1,35 +0,0 @@ -{ - config, - lib, - icons, - ... -}: -{ - format = "{value}"; - # window-rewrite-default = icons."Default"; - # window-rewrite = { - # "app_id" = lib.mkIf config.web.chromium.enable icons."Chromium"; - # "app_id" = lib.mkIf config.terminal.kitty.enable icons."Kitty"; - # "app_id" = lib.mkIf config.media.vlc.enable icons."VLC"; - # "app_id" = lib.mkIf config.office.zathura.enable icons."Zathura"; - # "app_id" = lib.mkIf config.gaming.heroic.enable icons."Heroic"; - # "app_id" = lib.mkIf config.gaming.steam.enable icons."Steam"; - # "app_id" = lib.mkIf config.development.bruno.enable icons."Bruno"; - # "app_id" = lib.mkIf config.development.vscodium.enable icons."VSCodium"; - # - # "title" = lib.mkIf config.development.qemu.enable icons."VirtManager"; - # "title" = lib.mkIf config.development.opencode.enable icons."Opencode"; - # "title" = lib.mkIf config.development.opencode.enable icons."Opencode"; - # "title" = lib.mkIf config.media.swayimg.enable icons."Swayimg"; - # "title" = lib.mkIf config.file-management.yazi.enable icons."Yazi"; - # "title" = lib.mkIf config.networking.bluetui.enable icons."bluetui"; - # "title" = lib.mkIf config.networking.impala.enable icons."impala"; - # "title" = lib.mkIf config.communication.neomutt.enable icons."neomutt"; - # "title" = - # lib.mkIf config.scripts.screen-recording.enable - # icons."screen-recording"; - # "title" = lib.mkIf config.scripts.system-monitor.enable icons."system-monitor"; - # "title" = lib.mkIf config.development.nixvim.enable icons."neovim"; - # "title" = lib.mkIf config.development.nixvim.enable icons."gopass"; - # }; -} diff --git a/modules/desktop/waybar/style.mustache.css b/modules/desktop/waybar/style.mustache.css deleted file mode 100644 index dfb70fa..0000000 --- a/modules/desktop/waybar/style.mustache.css +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Waybar style based on the Base16 OneDark Dark theme, rendered from a mustache template - */ - -* { - border: none; - border-radius: 0; - font-family: "Fira Code Nerd Font"; - font-size: 18px; - min-height: 0; - margin: 0; - padding: 0; -} - -window#waybar { - background: transparent; -} - -#window, #pulseaudio, #battery, #network, -#clock.time, #custom-usque, #memory, #cpu, #clock.date { - background: #{{base00}}; - margin: 0 5px; - border: 1px solid #{{base07}}; - color: #{{base07}}; - padding: 0 10px; -} - -#workspaces { - border: none; - background: #{{base00}}; -} - -#workspaces button { - padding: 0px 10px; - color: #{{base07}}; - border: 1px solid #{{base03}}; - border-radius: 0; - min-width: 0px; - min-height: 0px; - margin: 0 5px; - font-size: 24px; -} - -#workspaces button:hover { - background: #{{base00}}; - border-color: #{{base05}}; -} - -#workspaces button.active { - border-color: #{{base07}}; -} - -#workspaces button.empty { - color: #{{base03}}; -} - -#workspaces button.urgent { - color: #{{base08}}; -} diff --git a/modules/scripts/activate-windows/default.nix b/modules/scripts/activate-windows/default.nix new file mode 100644 index 0000000..441410f --- /dev/null +++ b/modules/scripts/activate-windows/default.nix @@ -0,0 +1,23 @@ +{ + config, + lib, + pkgs, + ... +}: +let + inherit ((import ../lib.nix { inherit lib pkgs; })) mkScriptModule; + base = mkScriptModule { + name = "eww-active-windows"; + path = ./script.sh; + description = "Outputs JSON array of active windows for eww bar\nUsed by eww to display window icons in the sidebar"; + deps = [ + pkgs.bash + pkgs.jq + ]; + inherit config; + }; +in +{ + options = base.options; + config = base.moduleConfig; +} diff --git a/modules/scripts/activate-windows/script.sh b/modules/scripts/activate-windows/script.sh new file mode 100644 index 0000000..2abe394 --- /dev/null +++ b/modules/scripts/activate-windows/script.sh @@ -0,0 +1,90 @@ +#!/usr/bin/env bash + +CACHE_FILE="${XDG_CACHE_HOME:-$HOME/.cache}/eww-icon-cache.tsv" +mkdir -p "$(dirname "$CACHE_FILE")" +touch "$CACHE_FILE" + +APP_DIRS=( + "$HOME/.local/share/applications" + "$HOME/.nix-profile/share/applications" + "/etc/profiles/per-user/$USER/share/applications" + "/run/current-system/sw/share/applications" + "$HOME/.local/share/flatpak/exports/share/applications" + "/var/lib/flatpak/exports/share/applications" +) + +ICON_DIRS=( + "$HOME/.local/share/icons" + "$HOME/.icons" + "$HOME/.nix-profile/share/icons" + "/etc/profiles/per-user/$USER/share/icons" + "/run/current-system/sw/share/icons" + "$HOME/.nix-profile/share/pixmaps" + "/run/current-system/sw/share/pixmaps" +) + +find_desktop_file() { + local id="$1" + for dir in "${APP_DIRS[@]}"; do + [ -d "$dir" ] || continue + local match + match=$(find "$dir" -maxdepth 1 -iname "${id}.desktop" 2>/dev/null | head -1) + [ -n "$match" ] && { echo "$match"; return; } + done + for dir in "${APP_DIRS[@]}"; do + [ -d "$dir" ] || continue + local match + match=$(grep -ilE "StartupWMClass=${id}$|^Name=${id}$" "$dir"/*.desktop 2>/dev/null | head -1) + [ -n "$match" ] && { echo "$match"; return; } + done +} + +find_icon_path() { + local icon_name="$1" + [ -z "$icon_name" ] && return + if [[ "$icon_name" == /* ]]; then + echo "$icon_name" + return + fi + for dir in "${ICON_DIRS[@]}"; do + [ -d "$dir" ] || continue + local match + match=$(find "$dir" -type f \( -iname "${icon_name}.svg" -o -iname "${icon_name}.png" -o -iname "${icon_name}.xpm" \) 2>/dev/null | sort -r | head -1) + [ -n "$match" ] && { echo "$match"; return; } + done +} + +resolve_icon() { + local app_id="$1" + local cached + cached=$(awk -F'\t' -v k="$app_id" '$1==k{print $2}' "$CACHE_FILE") + if [ -n "$cached" ]; then + echo "$cached" + return + fi + + local desktop_file icon_name icon_path + desktop_file=$(find_desktop_file "$app_id") + if [ -n "$desktop_file" ]; then + icon_name=$(grep -m1 '^Icon=' "$desktop_file" | cut -d= -f2-) + fi + icon_path=$(find_icon_path "$icon_name") + [ -z "$icon_path" ] && icon_path="$HOME/.config/eww/icons/fallback.svg" + + printf '%s\t%s\n' "$app_id" "$icon_path" >> "$CACHE_FILE" + echo "$icon_path" +} + +ws=$(niri msg -j workspaces) +active_id=$(echo "$ws" | jq '[.[] | select(.is_focused==true)][0].id') + +niri msg -j windows | jq -c --argjson wsid "$active_id" \ + '[.[] | select(.workspace_id == $wsid) | {app_id: (.app_id // "unknown"), title: (.title // "")}]' \ + | jq -c '.[]' \ + | while read -r win; do + app_id=$(jq -r '.app_id' <<< "$win") + title=$(jq -r '.title' <<< "$win") + icon=$(resolve_icon "$app_id") + jq -nc --arg app_id "$app_id" --arg title "$title" --arg icon "$icon" \ + '{app_id: $app_id, title: $title, icon: $icon}' + done | jq -sc '.' diff --git a/modules/scripts/default.nix b/modules/scripts/default.nix index ae18329..d225726 100644 --- a/modules/scripts/default.nix +++ b/modules/scripts/default.nix @@ -5,6 +5,7 @@ }: { imports = [ + ./activate-windows ./deep-clean ./gopass-ssh-load ./gpg-backup @@ -13,6 +14,7 @@ ./screen-recording ./system-monitor ./usque-warp + ./workspaces ./yazi-file-chooser ]; diff --git a/modules/scripts/workspaces/default.nix b/modules/scripts/workspaces/default.nix new file mode 100644 index 0000000..e856c2b --- /dev/null +++ b/modules/scripts/workspaces/default.nix @@ -0,0 +1,23 @@ +{ + config, + lib, + pkgs, + ... +}: +let + inherit ((import ../lib.nix { inherit lib pkgs; })) mkScriptModule; + base = mkScriptModule { + name = "eww-workspaces"; + path = ./script.sh; + description = "Outputs JSON array of workspaces for eww bar\nUsed by eww to display workspace indicators in the sidebar"; + deps = [ + pkgs.bash + pkgs.jq + ]; + inherit config; + }; +in +{ + options = base.options; + config = base.moduleConfig; +} diff --git a/modules/scripts/workspaces/script.sh b/modules/scripts/workspaces/script.sh new file mode 100644 index 0000000..061d0f7 --- /dev/null +++ b/modules/scripts/workspaces/script.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -euo pipefail +niri msg -j workspaces | jq -c 'sort_by(.idx)' -- cgit v1.2.3