nix/package/swayscript/script/Monitor.nix

84 lines
2 KiB
Nix
Raw Normal View History

{ ... }: {
text = ''
2024-09-08 03:49:29 +03:00
# Toggle monitors.
function montoggle() {
toggle() {
local output=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name')
2024-09-08 03:49:29 +03:00
local state=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .power')
if ''${state}; then
swaymsg "output \"''${output}\" power off"
else
swaymsg "output \"''${output}\" power on"
fi
pkill -RTMIN+4 waybar
}
2024-09-08 03:49:29 +03:00
_sway_iterate_sockets toggle
}
2024-09-08 03:49:29 +03:00
# Toggle gaming.
function gamingtoggle() {
toggle() {
local output=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name')
2024-09-08 03:49:29 +03:00
local state=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .adaptive_sync_status')
2024-09-08 03:49:29 +03:00
if [[ "''${state}" = "disabled" ]]; then
swaymsg "output \"''${output}\" adaptive_sync on"
else
swaymsg "output \"''${output}\" adaptive_sync off"
fi
pkill -RTMIN+4 waybar
2024-09-08 03:49:29 +03:00
}
_sway_iterate_sockets toggle
}
2024-09-08 03:49:29 +03:00
# Waybar output.
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} || {
2024-09-08 03:49:29 +03:00
printf off
return 1
}
done
2024-09-08 03:49:29 +03:00
printf on
return 0
}
2024-08-22 19:13:40 +03:00
function _recording() {
2024-09-08 03:49:29 +03:00
[[ "$(ps cax | rg wf-recorder)" = "" ]] && printf off || printf on
}
function _gamingstate() {
local outputs=($(swaymsg -t get_outputs | jq -r '.[] | .adaptive_sync_status'))
for state in "''${outputs[@]}"; do
[[ "''${state}" = "disabled" ]] || {
2024-09-08 03:49:29 +03:00
printf on
return 1
}
done
2024-09-08 03:49:29 +03:00
printf off
return 0
}
'';
}