nix/package/swayscript/script/Monitor.nix

103 lines
2.5 KiB
Nix
Raw Normal View History

{ ... }: {
text = ''
# Enable monitors.
function monon() {
on() {
local output=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name')
swaymsg "output \"''${output}\" power on"
}
_sway_iterate_sockets on
}
# Disable monitors.
function monoff() {
off() {
local output=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name')
swaymsg "output \"''${output}\" power off"
}
_sway_iterate_sockets off
}
# Toggle monitors.
function montoggle() {
2024-05-08 21:12:48 +03:00
if [[ "$(_monstate)" = "on" ]]; then
monoff
2024-05-08 21:12:48 +03:00
else
monon
fi
}
2024-05-08 21:12:48 +03:00
function monbar() {
2024-05-24 03:43:20 +03:00
local __monstate=$(_monstate)
2024-07-27 03:35:59 +03:00
local __gamingstate=$(_gamingstate)
2024-08-22 19:13:40 +03:00
local __recording=$(_recording)
2024-05-24 03:43:20 +03:00
local class=""
2024-08-22 19:13:40 +03:00
if [[ "''${__monstate}" = "off" ]] || [[ "''${__gamingstate}" = "on" ]] || [[ "''${__recording}" = "on" ]]; then
2024-05-24 03:43:20 +03:00
class="modified"
fi
2024-08-22 19:13:40 +03:00
printf "{\"text\": \"󰍹\", \"tooltip\": \"Monitor: ''${__monstate^} / Gaming: ''${__gamingstate^} / Recording: ''${__recording^}\", \"class\": \"''${class}\"}\n"
2024-05-08 21:12:48 +03:00
}
function _monstate() {
local outputs=($(swaymsg -t get_outputs | jq -r '.[] | .power'))
for state in "''${outputs[@]}"; do
''${state} || {
echo off
return 1
}
done
echo on
return 0
}
2024-08-22 19:13:40 +03:00
function _recording() {
[[ "$(ps cax | rg wf-recorder)" = "" ]] && echo off || echo on
}
# 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"
_gamingstate on
}
_sway_iterate_sockets on
}
# 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"
_gamingstate off
}
_sway_iterate_sockets off
}
# Toggle gaming.
function gamingtoggle() {
if [[ "$(_gamingstate)" = "on" ]]; then
gamingoff
else
gamingon
fi
}
function _gamingstate() {
if [[ "''${1}" = "" ]]; then
cat /tmp/.gamingstate 2> /dev/null || echo off
else
echo "''${*}" > /tmp/.gamingstate
fi
}
'';
}