nix/package/swayscript/script/Monitor.nix

97 lines
2.3 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-09-08 03:39:26 +03:00
local state=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .power')
''${state} && monoff || monon
}
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() {
local output=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name')
swaymsg "output \"''${output}\" adaptive_sync on"
}
_sway_iterate_sockets on
}
# Disable Gaming.
function gamingoff() {
off() {
local output=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name')
swaymsg "output \"''${output}\" adaptive_sync off"
}
_sway_iterate_sockets off
}
# Toggle gaming.
function gamingtoggle() {
2024-09-08 03:39:26 +03:00
local state=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .adaptive_sync_status')
[[ "''${state}" = "disabled" ]] && gamingon || gamingoff
}
function _gamingstate() {
local outputs=($(swaymsg -t get_outputs | jq -r '.[] | .adaptive_sync_status'))
for state in "''${outputs[@]}"; do
[[ "''${state}" = "disabled" ]] || {
echo on
return 1
}
done
echo off
return 0
}
'';
}