Browse Source

network widget finished

Johan Rong 3 tháng trước cách đây
mục cha
commit
ae01df6ba6

+ 3 - 3
flake.lock

@@ -39,11 +39,11 @@
     },
     "nixpkgs": {
       "locked": {
-        "lastModified": 1778003029,
-        "narHash": "sha256-q/nkKLDtHIyLjZpKhWk3cSK5IYsFqtMd6UtXF3ddjgA=",
+        "lastModified": 1778430510,
+        "narHash": "sha256-Ti+ZBvW6yrWWAg2szExVTwCd4qOJ3KlVr1tFHfyfi8Q=",
         "owner": "NixOS",
         "repo": "nixpkgs",
-        "rev": "0c88e1f2bdb93d5999019e99cb0e61e1fe2af4c5",
+        "rev": "8fd9daa3db09ced9700431c5b7ad0e8ba199b575",
         "type": "github"
       },
       "original": {

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

@@ -13,7 +13,7 @@
       eww_yuck = {
         target = ".config/eww/eww.yuck";
         text = ''
-          (include "./widgets/network/network.yuck")
+          (include "./widgets/network/network.yuck")'
         '';
       };
       eww_scss = {

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

@@ -37,14 +37,14 @@ in
       "${scripts}/device_up.sh" = {
         text = ''
           #!/usr/bin/env bash
-          nmcli device up "$1"
+          nmcli device connect $1
         '';
         executable = true;
       };
       "${scripts}/device_down.sh" = {
         text = ''
           #!/usr/bin/env bash
-          nmcli device down "$1"
+          nmcli device disconnect $1
         '';
         executable = true;
       };

+ 18 - 6
home/features/desktop/sway/ui/eww/network/network.scss

@@ -51,12 +51,6 @@ button:hover {
     background: #450707;
 }
 
-.network-header {
-}
-
-.network-info {
-}
-
 .network-name {
     font-size: 13px;
     font-weight: 600;
@@ -91,4 +85,22 @@ button:hover {
 .device-subtext {
     font-size: 11px;
     color: #999999;
+}
+
+scrollbar.vertical slider {
+    min-width: 2px;
+    background-color: #090603;
+    border-radius: 10px;
+
+    border: 8px solid transparent; 
+    background-clip: padding-box; 
+}
+
+scrollbar.vertical slider {
+    min-width: 2px;
+    background-color: #090603;
+    border-radius: 10px;
+
+    border: 8px solid transparent; 
+    background-clip: padding-box; 
 }

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

@@ -8,6 +8,11 @@
     "~/.config/eww/widgets/network/scripts/devices.py"
 )
 
+(defpoll wifi_enabled
+    :interval "5s"
+    "nmcli radio wifi"
+)
+
 (defwindow network
     :monitor 0
     :geometry (geometry
@@ -16,7 +21,9 @@
         :anchor "bottom right"
     )
     :stacking "fg"
-    (network-menu)
+    (eventbox :onhoverlost "eww close network"
+        (network-menu)
+    )
 )
 
 (defwidget network-menu []
@@ -25,13 +32,6 @@
         :class "network-menu"
         :space-evenly false
 
-        (label
-            :class "title"
-            :text "Internet"
-            :xalign 0.5
-            :yalign 0.2
-        )
-
         (literal :content devices)
 
         (scroll

+ 27 - 0
home/features/desktop/sway/ui/eww/network/scripts/devices.py

@@ -60,9 +60,36 @@ def devices() -> list:
         })
     return devices
 
+def wifi_enabled() -> bool:
+    result = subprocess.run(
+        ["nmcli", "radio", "wifi"],
+        text=True,
+        capture_output=True,
+        check=True,
+    )
+    return result.stdout.strip() == "enabled"
+
 def yuck() -> str:
     ret = r"""(box :orientation "v" :spacing 8"""
 
+    ret += rf"""
+    (box :orientation "h" :space-evenly false :spacing 16 :class "device-item"
+        (label
+            :class "device-icon"
+            :text "{"airplanemode_inactive" if wifi_enabled() else "flight"}"
+        )
+        (box :orientation "v" :space-evenly true :spacing 2
+            (label :class "device-name" :text "Airplane mode" :xalign 0)
+        )
+        (box :hexpand true)
+        (checkbox
+            :checked {str(not wifi_enabled()).lower()}
+            :onunchecked "nmcli radio wifi on"
+            :onchecked "nmcli radio wifi off"
+        )
+    )
+    """
+
     for device in devices():
         safe_name = device["device"].replace('"', r'\"')
         signal_icon = "settings_input_antenna" if device["type"] == "wifi" else "lan"

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

@@ -86,9 +86,9 @@
           ];
           format-ethernet = "lan";
           format-disconnected = "signal_wifi_off";
-          format-disabled = "signal_wifi_off";
+          format-disabled = "flight";
           tooltip-format = "{essid}\n{ipaddr}";
-          on-click = "eww open --toggle network";
+          on-click = "eww open network --toggle --screen $(swaymsg -t get_outputs | jq 'map(.focused) | index(true)')";
         };
 
         pulseaudio = {

+ 1 - 1
nixos/flavors/desktop/sway/greeter-default.nix

@@ -14,7 +14,7 @@ in
     enable = true;
     settings.default_session = {
       command = ''
-        ${pkgs.tuigreet}/bin/tuigreet --time --cmd "sway --unsupported-gpu"
+        ${pkgs.tuigreet}/bin/tuigreet --time --cmd "WLR_RENDERER=vulkan sway --unsupported-gpu"
       '';
       user = users.default;
     };