diff --git a/bin/i3-companion b/bin/i3-companion
index 7182aea..d931f3d 100755
--- a/bin/i3-companion
+++ b/bin/i3-companion
@@ -823,27 +823,33 @@ async def network_manager_status(i3, event, *args):
if state == NM_DEVICE_STATE_UNMANAGED:
continue
if kind == NM_DEVICE_TYPE_WIFI:
+
+ def wrap(s):
+ rofi = os.path.expanduser("~/.config/i3/bin/rofi-wifi")
+ return "%%{A1:%s:}%s%%{A}" % (rofi, s)
+
if state != NM_DEVICE_STATE_ACTIVATED:
- status.append(icons["nowifi"])
+ status.append(wrap(icons["nowifi"]))
continue
nmw = await conn[device].get_async_interface(f"{ofnm}.Device.Wireless")
ap = await nmw.ActiveAccessPoint
if not ap:
- status.append(icons["nowifi"])
+ status.append(wrap(icons["nowifi"]))
continue
network_manager_status.active_ap = ap
nmap = await conn[ap].get_async_interface(f"{ofnm}.AccessPoint")
name = await nmap.Ssid
strength = int(await nmap.Strength)
status.append(
- [
- icons["wifi-low"],
- icons["wifi-medium"],
- icons["wifi-high"],
- ][strength // 34]
- )
- status.append(
- bytes(name).decode("utf-8", errors="replace").replace("%", "%%")
+ wrap(
+ [
+ icons["wifi-low"],
+ icons["wifi-medium"],
+ icons["wifi-high"],
+ ][strength // 34]
+ + " "
+ + bytes(name).decode("utf-8", errors="replace").replace("%", "%%")
+ )
)
elif kind == NM_DEVICE_TYPE_ETHERNET and state == NM_DEVICE_STATE_ACTIVATED:
status.append(icons["wired"])
diff --git a/bin/rofi-wifi b/bin/rofi-wifi
new file mode 100755
index 0000000..5054ca2
--- /dev/null
+++ b/bin/rofi-wifi
@@ -0,0 +1,70 @@
+#!/bin/sh
+
+# Wifi selection menu with rofi
+
+if [ -z "${ROFI_OUTSIDE}" ]; then
+ yoffset=$(( $(xrdb -query | sed -n 's/^Xft.dpi:\t\([0-9]*\)$/\1/p')*20/96 ))
+ exec rofi -show-icons -no-custom -modi m:$0 -show m -location 3 -yoffset $yoffset
+fi
+
+case $ROFI_RETV in
+ 0)
+ # Prompt
+ printf "\00prompt\037wifi\n"
+ printf "\00markup-rows\037true\n"
+
+ case $(nmcli radio wifi) in
+ enabled)
+ printf "Turn wifi off\00info\037off\n"
+ printf "Scan wifi networks\00info\037rescan\n"
+ ;;
+ disabled)
+ printf "Turn wifi on\00info\037on\n"
+ ;;
+ esac
+
+ nmcli -f IN-USE,SSID,BSSID,SECURITY,FREQ,SIGNAL -m multiline device wifi list --rescan no \
+ | awk -F': *' '{
+ property=$1;
+ value=gensub(property ": *", "", 1);
+ p[property]=gensub("<", "<", "g", value);
+ }
+ ($1 == "SIGNAL") {
+ if (p["IN-USE"] == "*") {
+ printf("\00message\x1fConnected to %s (%s)\n", p["SSID"], p["FREQ"]);
+ } else {
+ printf("%s (%s, %s)",
+ p["SSID"], p["FREQ"], p["SECURITY"]);
+ signal=p["SIGNAL"]
+ printf("\00info\x1f%s\x1ficon\x1fnm-signal-%s%s\n",
+ p["BSSID"],
+ (signal > 75)?"100":\
+ (signal > 50)?"75":\
+ (signal > 25)?"50":\
+ "00",
+ (p["SECURITY"] == "--")?"":"-secure");
+ }
+ }'
+
+ ;;
+ 1)
+ case ${ROFI_INFO} in
+ rescan)
+ >/dev/null nmcli device wifi list --rescan yes
+ ;;
+ on)
+ >&2 nmcli radio wifi on
+ >/dev/null nmcli device wifi list --rescan yes
+ ;;
+ off)
+ >&2 nmcli radio wifi off
+ ;;
+ *)
+ >&2 nmcli device wifi connect ${ROFI_INFO}
+ exit 0
+ ;;
+ esac
+ export ROFI_RETV=0
+ exec $0
+ ;;
+esac
diff --git a/dotfiles/rofi.conf b/dotfiles/rofi.conf
index 1f287ef..c66d2ab 100644
--- a/dotfiles/rofi.conf
+++ b/dotfiles/rofi.conf
@@ -36,6 +36,7 @@ configuration {
window {
transparency: "real";
+ background-color: #00000055;
}
inputbar {
@@ -92,7 +93,7 @@ element active, element selected active {
}
message, error-message {
- margin: 0.6em 0 1.2em;
+ margin: 0 0 0.6em;
padding: 1%;
border-radius: 5px;
background-color: @emphasis;