diff options
author | davidovski <david@davidovski.xyz> | 2023-11-20 23:33:59 +0000 |
---|---|---|
committer | davidovski <david@davidovski.xyz> | 2023-11-20 23:33:59 +0000 |
commit | 2c23da611288c6415a363c07847c82481763908e (patch) | |
tree | 29cb278b64b9cea522a5db47ec15303a26f0dc45 /scripts | |
parent | 4c2194a7c5758637259d109df248c24a2fac62e6 (diff) |
Switch to compfy
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/dmenu-iwd | 96 | ||||
-rwxr-xr-x | scripts/tablet | 4 |
2 files changed, 98 insertions, 2 deletions
diff --git a/scripts/dmenu-iwd b/scripts/dmenu-iwd new file mode 100755 index 0000000..a3cc411 --- /dev/null +++ b/scripts/dmenu-iwd @@ -0,0 +1,96 @@ +#!/bin/bash + +STATION="wlan0" +FONT="Monospace" +NORMAL_BACKGROUND="#000000" +NORMAL_FOREGROUND="#8f8f8f" +SELECTED_BACKGROUND="#000000" +SELECTED_FOREGROUND="#00ff00" +FLAGS=( + "-i" + "-nb" "$NORMAL_BACKGROUND" + "-nf" "$NORMAL_FOREGROUND" + "-sb" "$SELECTED_BACKGROUND" + "-sf" "$SELECTED_FOREGROUND" + "-fn" "$FONT" +) + +remove_colors() { + sed -E 's/\x1B\[[0-9;]*[JKmsu]//g' +} + +connect() { + SSID="$1" + notify-send --urgency=low "Attempting to connect to network: $SSID" + if iwctl station "$STATION" connect "$SSID" --dont-ask; then + notify-send "Connected to network: $SSID" + exit 0 + fi + if ERROR=$( + iwctl station "$STATION" connect "$SSID" \ + --passphrase "$(dmenu "${FLAGS[@]}" -p Password: </dev/null)" \ + --dont-ask 2>&1 + ); then + notify-send "Connected to network: $SSID" + else + notify-send --urgency=critical \ + "Failed to connect to network: $SSID" "$(remove_colors <<<$ERROR)" + fi +} + +networks() { + iwctl station "$STATION" get-networks | awk ' +BEGIN { + i = -1 +} +{ + i++ + if (i < 4) next # skip header + + network = "" + strength = 0 + for (ix = 1; ix <= NF; ix++) { + if (ix == NF - 1) continue # skip protocol + + # calculate strength by reading *s until + # a color code is encountered + char = sprintf("%c", $ix) + if (char == "*") { + split($ix, chars, "") + for (c = 1; c <= length($ix); c++) { + char = sprintf("%c", chars[c]) + if (char == "\033") break + strength++ + } + continue + } + + if (char == "\033") continue # color codes + if ($ix == "") continue # whitespace + if ($ix == ">") continue # current network + + # ssids may contain spaces + if (network == "") { + network = $ix + continue + } + network = network " " $ix + } + if (network == "") next + networks[network] = strength +} +END { + for (s = 4; s >= 0; s--) { + for (network in networks) { + if (networks[network] == s) { + print network + delete networks[network] + } + } + } +} +' +} + +SELECTION=$(networks | dmenu "${FLAGS[@]}") || exit 1 +connect "$SELECTION" diff --git a/scripts/tablet b/scripts/tablet index 0cd6144..31c4871 100755 --- a/scripts/tablet +++ b/scripts/tablet @@ -69,11 +69,11 @@ for screen in screens: #Size of the tablet #Prioritize the width when scaling between aspect ratios -tw = target[2] +tw = target[2] th = tw / tablet_ratio if "-r" in sys.argv or "-l" in sys.argv: - th = target[2] + th = target[2] tw = th / tablet_ratio #make a variable that will try to make the scale the same over diferent resoultions |