Swayscript : Add vpn toggle.

This commit is contained in:
Dmitry Voronin 2024-07-27 03:35:59 +03:00
parent eeb3f670a2
commit fb328fa4cb
Signed by: voronind
SSH key fingerprint: SHA256:3kBb4iV2ahufEBNq+vFbUe4QYfHt98DHQjN7QaptY9k
5 changed files with 49 additions and 20 deletions

View file

@ -3,10 +3,11 @@
in {
text = ''
bindsym ${mod}+c exec 'systemctl reboot -i'
bindsym ${mod}+g exec 'swayscript gamingtoggle'
bindsym ${mod}+l exec 'powerlimit toggle'
bindsym ${mod}+m exec 'swayscript montoggle'
bindsym ${mod}+p exec 'powersave toggle'
bindsym ${mod}+v exec 'swayscript vrrtoggle'
bindsym ${mod}+v exec 'swayscript vpntoggle'
bindsym ${mod}+x exec 'systemctl poweroff -i'
bindsym ${mod}+z exec 'systemctl suspend -i'
'';

View file

@ -134,7 +134,7 @@ in {
exec = "swayscript monbar";
interval = refreshInterval;
on-click = "sleep 0.1 && swayscript montoggle"; # FIXME: remove sleep when resolved: https://github.com/Alexays/Waybar/issues/216
on-click-right = "sleep 0.1 && swayscript vrrtoggle";
on-click-right = "sleep 0.1 && swayscript gamingtoggle";
return-type = "json";
};
};

View file

@ -1,44 +1,43 @@
# TODO: Add different modes for different screens.
{ ... }: {
text = ''
# Enable VRR.
function vrron() {
# Enable Gaming.
function gamingon() {
on() {
swaymsg "output \"Huawei Technologies Co., Inc. ZQE-CBA 0xC080F622\" adaptive_sync on"
swaymsg "output \"Huawei Technologies Co., Inc. ZQE-CBA 0xC080F622\" mode 3440x1440@164.999Hz"
swaymsg "output \"AOC 24G2W1G4 ATNL61A129625\" adaptive_sync on"
swaymsg "output \"AOC 24G2W1G4 ATNL61A129625\" mode 1920x1080@144.000Hz"
_vrrstate on
_gamingstate on
}
_sway_iterate_sockets on
}
# Disable VRR.
function vrroff() {
# Disable Gaming.
function gamingoff() {
off() {
swaymsg "output \"Huawei Technologies Co., Inc. ZQE-CBA 0xC080F622\" adaptive_sync off"
swaymsg "output \"Huawei Technologies Co., Inc. ZQE-CBA 0xC080F622\" mode 3440x1440@59.973Hz"
swaymsg "output \"AOC 24G2W1G4 ATNL61A129625\" adaptive_sync off"
swaymsg "output \"AOC 24G2W1G4 ATNL61A129625\" mode 1920x1080@60.000Hz"
_vrrstate off
_gamingstate off
}
_sway_iterate_sockets off
}
# Toggle VRR.
function vrrtoggle() {
if [[ "$(_vrrstate)" = "on" ]]; then
vrroff
# Toggle gaming.
function gamingtoggle() {
if [[ "$(_gamingstate)" = "on" ]]; then
gamingoff
else
vrron
gamingon
fi
}
function _vrrstate() {
function _gamingstate() {
if [[ "''${1}" = "" ]]; then
cat /tmp/.vrrstate 2> /dev/null || echo off
cat /tmp/.gamingstate 2> /dev/null || echo off
else
echo "''${*}" > /tmp/.vrrstate
echo "''${*}" > /tmp/.gamingstate
fi
}
'';

View file

@ -33,14 +33,14 @@
function monbar() {
local __monstate=$(_monstate)
local __vrrstate=$(_vrrstate)
local __gamingstate=$(_gamingstate)
local class=""
if [[ "''${__monstate}" = "off" ]] || [[ "''${__vrrstate}" = "on" ]]; then
if [[ "''${__monstate}" = "off" ]] || [[ "''${__gamingstate}" = "on" ]]; then
class="modified"
fi
printf "{\"text\": \"󰍹\", \"tooltip\": \"Mon: ''${__monstate^} / Vrr: ''${__vrrstate^}\", \"class\": \"''${class}\"}\n"
printf "{\"text\": \"󰍹\", \"tooltip\": \"Monitor: ''${__monstate^} / Gaming: ''${__gamingstate^}\", \"class\": \"''${class}\"}\n"
}
function _monstate() {

View file

@ -0,0 +1,29 @@
{ ... }: {
text = ''
# Enable VPN.
function vpnon() {
nmcli connection up vpn
_vpnstate on
}
# Disable vpn.
function vpnoff() {
nmcli connection down vpn
_vpnstate off
}
# Toggle vpn.
function vpntoggle() {
if [[ "$(_vpnstate)" = "on" ]]; then
vpnoff
else
vpnon
fi
}
function _vpnstate() {
local state=$(nmcli connection show vpn | rg -i state.*activated)
[ "''${state}" != "" ] && printf on || printf off
}
'';
}