Net window

This commit is contained in:
soraefir
2026-06-12 23:29:01 +02:00
parent 535c8a3154
commit c724c853f5
7 changed files with 200 additions and 6 deletions

View File

@@ -0,0 +1,82 @@
(defpoll netinfo
:interval "5s"
:initial '{"wifi":{"ssid":"","ip":"","freq":0,"band":"","gen":"","signal":0},"ethernet":{"state":"down","ip":"","speed":"","interface":""}}'
"scripts/net/netinfo")
(deflisten bt-devices
:initial "[]"
"scripts/net/bt-devices")
; --- Shared row widget ---
(defwidget netinfo-row [label value]
(box :orientation "h" :space-evenly false :class "netinfo-row"
(label :class "netinfo-label" :halign "start" :text label)
(label :class "netinfo-value" :halign "end" :hexpand true :text value)))
; --- WiFi ---
(defwidget wifi-net-section []
(box :orientation "v" :space-evenly false :class "sys-section"
(section-header :title "WiFi" :accent "wifi-accent")
(box :orientation "v" :space-evenly false
:visible {net.wifi.connected}
(netinfo-row :label "SSID" :value {netinfo.wifi.ssid})
(netinfo-row :label "IP" :value {netinfo.wifi.ip})
(netinfo-row :label "Signal" :value "${net.wifi.icon} ${netinfo.wifi.signal} dBm")
(netinfo-row :label "Freq" :value "${netinfo.wifi.freq} MHz · ${netinfo.wifi.band} · ${netinfo.wifi.gen}"))
(label :class "netinfo-dim" :halign "start"
:visible {!net.wifi.connected}
:text "Not connected")))
; --- Ethernet ---
(defwidget ethernet-net-section []
(box :orientation "v" :space-evenly false :class "sys-section"
(section-header :title "Ethernet" :accent "eth-accent")
(box :orientation "v" :space-evenly false
:visible {net.ethernet.connected}
(netinfo-row :label "Interface" :value {netinfo.ethernet.interface})
(netinfo-row :label "IP" :value {netinfo.ethernet.ip})
(netinfo-row :label "Speed" :value {netinfo.ethernet.speed}))
(label :class "netinfo-dim" :halign "start"
:visible {!net.ethernet.connected}
:text "No carrier")))
; --- Bluetooth ---
(defwidget bt-device-row [device]
(box :orientation "h" :space-evenly false :class "bt-device-row" :valign "center"
(label :class "bt-device-name" :hexpand true :halign "start" :text {device.name})
(button
:class "bt-device-btn ${device.connected ? 'bt-btn-on' : 'bt-btn-off'}"
:onclick "scripts/net/bt-toggle ${device.mac}"
:tooltip {device.connected ? "Disconnect" : "Connect"}
(label :text {device.connected ? "󰂱" : "󰂯"}))))
(defwidget bluetooth-net-section []
(box :orientation "v" :space-evenly false :class "sys-section"
(section-header :title "Bluetooth" :accent "blt-accent")
(box :orientation "v" :space-evenly false
(for device in {bt-devices}
(bt-device-row :device {device})))))
; --- Root ---
(defwidget net-win []
(box :class "sys-win" :space-evenly false :orientation "v"
(wifi-net-section)
(box :class "section-sep")
(ethernet-net-section)
(box :class "section-sep")
(bluetooth-net-section)))
(defwindow net
:monitor 0
:stacking "overlay"
:geometry (geometry
:x "0%" :y "0%"
:anchor "bottom right"
:width "300px" :height "0px")
(window (net-win)))