Преглед изворни кода

start of implementing eww menus

Johan Rong пре 3 месеци
родитељ
комит
f3e0d3cd09

+ 1 - 0
home/features/desktop/sway/default.nix

@@ -5,6 +5,7 @@
     ./sway.nix
     ./scripts.nix
 
+    ./ui/eww
     ./ui/wofi
     ./ui/waybar
     ./ui/mako.nix

+ 27 - 0
home/features/desktop/sway/ui/eww/default.nix

@@ -0,0 +1,27 @@
+{ pkgs, lib, ... }:
+{
+  imports = [
+    ./network
+  ];
+
+  programs.eww = {
+    enable = true;
+  };
+
+  home = {
+    file = {
+      eww_yuck = {
+        target = ".config/eww/eww.yuck";
+        text = ''
+          (include "./widgets/network/network.yuck")
+        '';
+      };
+      eww_scss = {
+        target = ".config/eww/eww.scss";
+        text = ''
+          
+        '';
+      };
+    };
+  };
+}

+ 159 - 0
home/features/desktop/sway/ui/eww/network/default.nix

@@ -0,0 +1,159 @@
+{ pkgs, lib, ... }:
+
+let
+  folder = ".config/eww/widgets/network";
+  scripts = "${folder}/scripts";
+in 
+{
+  home = {
+    file = {
+      "${folder}/network.yuck".source = ./network.yuck;
+      network_scss = {
+        target = "${folder}/network.scss";
+        text = ''
+          .network-menu {
+            background: #1e1e2e;
+            border-radius: 14px;
+            padding: 16px;
+            min-width: 320px;
+          }
+
+          .title {
+            font-size: 22px;
+            margin-bottom: 12px;
+          }
+
+          button {
+            background: #313244;
+            border-radius: 10px;
+            padding: 10px;
+            margin: 4px 0;
+          }
+
+          button:hover {
+            background: #45475a;
+          }
+        '';
+      };
+      network_connections_sh = {
+        target = "${scripts}/connections.sh";
+        executable = true;
+        text = ''
+          #!/usr/bin/env bash
+
+          echo '(box :orientation "v" :spacing 12'
+
+          #
+          # ACTIVE CONNECTIONS
+          #
+
+          echo '(label :text "Connected")'
+
+          nmcli -t -f NAME,TYPE,DEVICE connection show --active | \
+          while IFS=: read -r name type device
+          do
+              icon="󰈀"
+
+              case "$type" in
+                  802-11-wireless)
+                      icon="󰤨"
+                      ;;
+                  802-3-ethernet)
+                      icon="󰈁"
+                      ;;
+                  vpn)
+                      icon="󰖂"
+                      ;;
+              esac
+
+              safe_name=$(printf '%s\n' "$name" | sed 's/"/\\"/g')
+
+              echo "(button
+                  :onclick \"~/.config/eww/widgets/network/scripts/disconnect.sh '$safe_name'\"
+                  (box :orientation \"h\" :spacing 12
+                      (label :text \"$icon\")
+                      (label :text \"$safe_name\")
+                      (label :text \"Connected\")
+                  )
+              )"
+          done
+
+          #
+          # WIFI NETWORKS
+          #
+
+          echo '(label :text "Wi-Fi")'
+
+          nmcli -t -f SSID,SIGNAL device wifi list | \
+          awk -F: '
+          {
+              ssid=$1
+              signal=$2
+
+              if (ssid == "")
+                  next
+
+              if (!(ssid in best) || signal > best[ssid]) {
+                  best[ssid]=signal
+              }
+          }
+          END {
+              for (ssid in best)
+                  print ssid ":" best[ssid]
+          }
+          ' | sort -t: -k2 -nr | \
+          while IFS=: read -r ssid signal
+          do
+              safe_ssid=$(printf '%s\n' "$ssid" | sed 's/"/\\"/g')
+
+              if [ "$signal" -ge 80 ]; then
+                  icon="󰤨"
+              elif [ "$signal" -ge 60 ]; then
+                  icon="󰤥"
+              elif [ "$signal" -ge 40 ]; then
+                  icon="󰤢"
+              else
+                  icon="󰤟"
+              fi
+
+              echo "(button
+                  :onclick \"~/.config/eww/widgets/network/scripts/connect.sh '$safe_ssid'\"
+                  (box :orientation \"h\" :spacing 12
+                      (label :text \"$icon\")
+                      (label :text \"$safe_ssid\")
+                      (label :text \"$signal%\")
+                  )
+              )"
+          done
+
+          echo ")"
+        '';
+      };
+      network_connect_sh = {
+        target = "${scripts}/connect.sh";
+        executable = true;
+        text = ''
+          #!/usr/bin/env bash
+
+          TARGET="$1"
+
+          if nmcli connection show "$TARGET" >/dev/null 2>&1; then
+              nmcli connection up "$TARGET"
+          else
+              PASSWORD=$(wofi --dmenu --password --prompt "Wi-Fi Password")
+              nmcli device wifi connect "$TARGET" password "$PASSWORD"
+          fi
+        '';
+      };
+      network_disconnect_sh = {
+        target = "${scripts}/disconnect.sh";
+        executable = true;
+        text = ''
+          #!/usr/bin/env bash
+
+          nmcli connection down "$1"
+        '';
+      };
+    };
+  };
+}

+ 27 - 0
home/features/desktop/sway/ui/eww/network/network.yuck

@@ -0,0 +1,27 @@
+(defpoll network_connections
+    :interval "5s"
+    "~/.config/eww/widgets/network/scripts/connections.sh")
+
+(defwindow network
+    :monitor 0
+    :geometry (geometry
+        :x "70%"
+        :y "40px"
+        :width "360px"
+        :height "600px")
+    :anchor "top left"
+    :stacking "fg"
+    (network-menu))
+
+(defwidget network-menu []
+    (box
+        :orientation "v"
+        :class "network-menu"
+
+    (label
+        :class "title"
+        :text "Internet")
+
+    (scroll
+        :vexpand true
+        (literal :content network_connections))))

+ 1 - 0
home/features/desktop/sway/ui/waybar/default.nix

@@ -85,6 +85,7 @@
           format-disconnected = "signal_wifi_off";
           format-disabled = "signal_wifi_off";
           tooltip-format = "{essid}\n{ipaddr}";
+          on-click = "eww open --toggle network";
         };
 
         pulseaudio = {