From ac3df09b6bdac70bf64131a73674a380c567fb8c Mon Sep 17 00:00:00 2001 From: Schrottkatze Date: Wed, 28 Aug 2024 09:12:28 +0200 Subject: [PATCH] replace top bar with eww bar --- .../home/panels/eww/configDir/eww.yuck | 86 +--------------- .../home/panels/eww/configDir/scripts/bat.nu | 55 +++++++++++ .../panels/eww/configDir/topBar/sysinfo.yuck | 27 +++++ .../panels/eww/configDir/topBar/time.yuck | 10 ++ .../panels/eww/configDir/topBar/topBar.yuck | 56 +++++++++++ .../home/panels/eww/configDir/util.yuck | 11 +++ .../home/panels/eww/scripts/bat.nu | 23 ----- .../desktop-environment/home/sway/default.nix | 98 +++---------------- 8 files changed, 172 insertions(+), 194 deletions(-) create mode 100755 modules/desktop-environment/home/panels/eww/configDir/scripts/bat.nu create mode 100644 modules/desktop-environment/home/panels/eww/configDir/topBar/sysinfo.yuck create mode 100644 modules/desktop-environment/home/panels/eww/configDir/topBar/time.yuck create mode 100644 modules/desktop-environment/home/panels/eww/configDir/topBar/topBar.yuck create mode 100644 modules/desktop-environment/home/panels/eww/configDir/util.yuck delete mode 100644 modules/desktop-environment/home/panels/eww/scripts/bat.nu diff --git a/modules/desktop-environment/home/panels/eww/configDir/eww.yuck b/modules/desktop-environment/home/panels/eww/configDir/eww.yuck index e986e0b..d17d0f0 100644 --- a/modules/desktop-environment/home/panels/eww/configDir/eww.yuck +++ b/modules/desktop-environment/home/panels/eww/configDir/eww.yuck @@ -1,85 +1 @@ -(defwindow topBar - :monitor 0 - :stacking "fg" - :windowtype "normal" - :wm-ignore true - :exclusive true - :geometry (geometry - :width "100%" - :height "32px" - :anchor "top center") - (topBar)) - -(defwidget topBar [] - (overlay - :class "topBar" - (centerbox - (box - :halign "start" - :spacing 12 - :space-evenly false - (label :text " ") - (cpu) - (sep) - (mem) - ) - (box - :halign "center" - (label :text "Hi, jade! :3") - ) - (box - :halign "end" - (time) - ) - ) - (box - :class "transFlag" - :height 1 - ( flagEl :color "#5BCEFA") - ( flagEl :color "#F5A9B8") - ( flagEl :color "#FFFFFF") - ( flagEl :color "#F5A9B8") - ( flagEl :color "#5BCEFA") - ) - ) -) - -(defwidget sep [] - (label :text "|") -) - -(defwidget time [] - (label - :markup { - formattime( - EWW_TIME, - " %Y-%m-%d %H:%M:%S " - ) - } - ) -) - -(defwidget cpu [] - (box - :class "cpuIndicator" - (label - :markup " ${strlength(round(EWW_CPU.avg, 0)) == 1 ? " ${round(EWW_CPU.avg, 0)}" : round(EWW_CPU.avg, 0)}%" - ) - ) -) - -(defwidget mem [] - (box - :class "memIndicator" - (label - :markup " ${round(EWW_RAM.used_mem_perc, 0)}%" - ) - ) -) - -(defwidget flagEl [color] - (box - :style "border-bottom: 2px solid ${color}" - :halign "fill" - ) -) +(include "topBar/topBar.yuck") diff --git a/modules/desktop-environment/home/panels/eww/configDir/scripts/bat.nu b/modules/desktop-environment/home/panels/eww/configDir/scripts/bat.nu new file mode 100755 index 0000000..4136585 --- /dev/null +++ b/modules/desktop-environment/home/panels/eww/configDir/scripts/bat.nu @@ -0,0 +1,55 @@ +#!/usr/bin/env nu + +const ICONS = [ + [ normal charging]; + [ 󰂎 󰢟 ] + [ 󰁺 󰢜 ] + [ 󰁻 󰂆 ] + [ 󰁼 󰂇 ] + [ 󰁽 󰂈 ] + [ 󰁾 󰢝 ] + [ 󰁿 󰂉 ] + [ 󰂀 󰢞 ] + [ 󰂁 󰂊 ] + [ 󰂂 󰂋 ] + [ 󰁹 󰂅 ] +]; + +def main [ path: string ] { + loop { + let fract = get_bat_charge_fraction $path; + let is_charging = get_bat_charging_status $path; + let percent = ($fract * 100) | math round; + + print $"(get_bat_icon $fract $is_charging) ($percent)%"; + sleep 2sec; + } +} + +def get_bat_charge_fraction [ + path: string +] { + let energy_full = open $"/sys/class/power_supply/($path)/energy_full" | into float; + let energy_now = open $"/sys/class/power_supply/($path)/energy_now" | into float; + + $energy_now / $energy_full +} + +def get_bat_charging_status [ + path: string +] { + let status = open $"/sys/class/power_supply/($path)/status"; + + if ($status == Charging) { + true + } else { + false + } +} + +def get_bat_icon [ + frac: float + is_charging = false +] { + $ICONS | get (($frac * 10) | math round) | get (if ($is_charging) { "charging" } else { "normal" }) +} diff --git a/modules/desktop-environment/home/panels/eww/configDir/topBar/sysinfo.yuck b/modules/desktop-environment/home/panels/eww/configDir/topBar/sysinfo.yuck new file mode 100644 index 0000000..3cf8e2c --- /dev/null +++ b/modules/desktop-environment/home/panels/eww/configDir/topBar/sysinfo.yuck @@ -0,0 +1,27 @@ +(deflisten bat0 + :initial "BAT0 ERR" + { "~/.config/eww/scripts/bat.nu BAT0"} +) +(deflisten bat1 + :initial "BAT1 ERR" + { "~/.config/eww/scripts/bat.nu BAT1"} +) + +(defwidget cpu [] + (box + :class "cpuIndicator" + (label + :markup " ${strlength(round(EWW_CPU.avg, 0)) == 1 ? " ${round(EWW_CPU.avg, 0)}" : round(EWW_CPU.avg, 0)}%" + ) + ) +) + +(defwidget mem [] + (box + :class "memIndicator" + (label + :markup " ${round(EWW_RAM.used_mem_perc, 0)}%" + ) + ) +) + diff --git a/modules/desktop-environment/home/panels/eww/configDir/topBar/time.yuck b/modules/desktop-environment/home/panels/eww/configDir/topBar/time.yuck new file mode 100644 index 0000000..48b58de --- /dev/null +++ b/modules/desktop-environment/home/panels/eww/configDir/topBar/time.yuck @@ -0,0 +1,10 @@ +(defwidget time [] + (label + :markup { + formattime( + EWW_TIME, + " %Y-%m-%d %H:%M:%S " + ) + } + ) +) diff --git a/modules/desktop-environment/home/panels/eww/configDir/topBar/topBar.yuck b/modules/desktop-environment/home/panels/eww/configDir/topBar/topBar.yuck new file mode 100644 index 0000000..8963e5a --- /dev/null +++ b/modules/desktop-environment/home/panels/eww/configDir/topBar/topBar.yuck @@ -0,0 +1,56 @@ +(include "topBar/time.yuck") +(include "topBar/sysinfo.yuck") +(include "util.yuck") + +(defwindow topBar + :monitor 0 + :stacking "fg" + :windowtype "normal" + :wm-ignore true + :exclusive true + :geometry (geometry + :width "100%" + :height "32px" + :anchor "top center") + (topBar)) + +(defwidget topBar [] + (overlay + :class "topBar" + (centerbox + (box + :halign "start" + :spacing 12 + :space-evenly false + (label :text " ") + (cpu) + (sep) + (mem) + (sep) + (label :markup bat0) + (sep) + (label :markup bat1) + ) + (box + :halign "center" + (systray + :icon-size 18 + :spacing 3 + ) + ) + (box + :halign "end" + (time) + ) + ) + (box + :class "transFlag" + :height 1 + ( flagEl :color "#5BCEFA") + ( flagEl :color "#F5A9B8") + ( flagEl :color "#FFFFFF") + ( flagEl :color "#F5A9B8") + ( flagEl :color "#5BCEFA") + ) + ) +) diff --git a/modules/desktop-environment/home/panels/eww/configDir/util.yuck b/modules/desktop-environment/home/panels/eww/configDir/util.yuck new file mode 100644 index 0000000..53b9be5 --- /dev/null +++ b/modules/desktop-environment/home/panels/eww/configDir/util.yuck @@ -0,0 +1,11 @@ +(defwidget flagEl [color] + (box + :style "border-bottom: 3px solid ${color}" + :halign "fill" + ) +) + +(defwidget sep [] + (label :text "|") +) + diff --git a/modules/desktop-environment/home/panels/eww/scripts/bat.nu b/modules/desktop-environment/home/panels/eww/scripts/bat.nu deleted file mode 100644 index 01a043d..0000000 --- a/modules/desktop-environment/home/panels/eww/scripts/bat.nu +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env nu - -const ICONS = [ - [ 󰂎 󰢟 ] - [ 󰁺 󰢜 ] - [ 󰁻 󰂆 ] - [ 󰁼 󰂇 ] - [ 󰁽 󰂈 ] - [ 󰁾 󰢝 ] - [ 󰁿 󰂉 ] - [ 󰂀 󰢞 ] - [ 󰂁 󰂊 ] - [ 󰂂 󰂋 ] - [ 󰁹 󰂅 ] -]; - -def get_bat_percent [path: string] { - let energy_full = open $"/sys/class/power_supply/($path)/energy_full" | into float; - let energy_now = open $"/sys/class/power_supply/($path)/energy_now" | into float; - - ($energy_now / $energy_full) * 100 -} - diff --git a/modules/desktop-environment/home/sway/default.nix b/modules/desktop-environment/home/sway/default.nix index 3edfb31..75f4bf5 100644 --- a/modules/desktop-environment/home/sway/default.nix +++ b/modules/desktop-environment/home/sway/default.nix @@ -32,98 +32,12 @@ target = "sway-session.target"; }; settings = { - infobar = { - layer = "top"; - position = "top"; - modules-left = ["memory" "cpu" "network" "group/bats"]; - modules-center = ["sway/window"]; - modules-right = ["clock"]; - "group/bats" = { - orientation = "inherit"; - modules = ["battery#bat0" "battery#bat1" "upower#headphones"]; - }; - "battery#bat0" = { - adapter = "AC"; - bat = "BAT0"; - interval = 2; - format = "{icon} {capacity}% {time}"; - format-charging = "󱐋 {icon} {capacity}% {time}"; - format-time = "{h}:{m}"; - format-icons = [ - "󰁺" - "󰁻" - "󰁼" - "󰁽" - "󰁾" - "󰁿" - "󰂀" - "󰂁" - "󰂂" - "󰁹" - ]; - tooltip = true; - tooltip-format = "BAT0: {cycles} cycles"; - }; - "battery#bat1" = { - adapter = "AC"; - bat = "BAT1"; - interval = 2; - format = "󱐋 {icon} {capacity}% {time}"; - format-time = "{H}:{M}"; - format-icons = [ - "󰁺" - "󰁻" - "󰁼" - "󰁽" - "󰁾" - "󰁿" - "󰂀" - "󰂁" - "󰂂" - "󰁹" - ]; - tooltip = true; - tooltip-format = "BAT1: {cycles} cycles"; - }; - "upower#headphones" = { - native-path = "/org/bluez/hci0/dev_4C_87_5D_29_B3_76"; - format = "󰋋 {percentage} {time}"; - hide-if-empty = true; - show-icon = false; - }; - }; interactiveBar = { layer = "top"; position = "bottom"; modules-left = ["sway/workspaces" "sway/mode"]; - modules-center = ["tray"]; modules-right = ["wlr/taskbar"]; }; - # mainBar = { - # layer = "top"; - # position = "top"; - # height = 30; - # output = [ - # "eDP-1" - # "HDMI-A-1" - # ]; - # modules-left = ["sway/workspaces" "sway/mode" "wlr/taskbar"]; - # modules-center = ["sway/window" "custom/hello-from-waybar"]; - # modules-right = ["mpd" "custom/mymodule#with-css-id" "temperature"]; - - # "sway/workspaces" = { - # disable-scroll = true; - # all-outputs = true; - # }; - # "custom/hello-from-waybar" = { - # format = "hello {}"; - # max-length = 40; - # interval = "once"; - # exec = pkgs.writeShellScript "hello-from-waybar" '' - # echo "from within waybar" - # ''; - # }; - # }; }; }; @@ -163,6 +77,18 @@ xkb_variant = "altgr-intl"; }; }; + startup = [ + { + command = "eww open topBar"; + } + { + command = "pkill nm-applet; sleep 1 && nm-applet"; + always = true; + } + { + command = "sleep 1 && mullvad-gui"; + } + ]; bars = []; menu = "wofi -d"; modifier = "Mod4";