diff --git a/home/config/sway/module/System.nix b/home/config/sway/module/System.nix index c7bb5735..fa54d92b 100644 --- a/home/config/sway/module/System.nix +++ b/home/config/sway/module/System.nix @@ -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' ''; diff --git a/home/config/waybar/config/default.nix b/home/config/waybar/config/default.nix index 76daea45..4f4076b8 100644 --- a/home/config/waybar/config/default.nix +++ b/home/config/waybar/config/default.nix @@ -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"; }; }; diff --git a/package/swayscript/script/Vrr.nix b/package/swayscript/script/Gaming.nix similarity index 70% rename from package/swayscript/script/Vrr.nix rename to package/swayscript/script/Gaming.nix index 1d8cb1f6..33090749 100644 --- a/package/swayscript/script/Vrr.nix +++ b/package/swayscript/script/Gaming.nix @@ -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 } ''; diff --git a/package/swayscript/script/Monitor.nix b/package/swayscript/script/Monitor.nix index e291e584..d65370a6 100644 --- a/package/swayscript/script/Monitor.nix +++ b/package/swayscript/script/Monitor.nix @@ -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() { diff --git a/package/swayscript/script/Vpn.nix b/package/swayscript/script/Vpn.nix new file mode 100644 index 00000000..6f06973f --- /dev/null +++ b/package/swayscript/script/Vpn.nix @@ -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 + } + ''; +}