2024-05-08 18:26:33 +03:00
|
|
|
{ ... }: {
|
|
|
|
text = ''
|
2024-09-08 03:49:29 +03:00
|
|
|
# Toggle monitors.
|
|
|
|
function montoggle() {
|
|
|
|
toggle() {
|
2024-09-08 03:12:13 +03:00
|
|
|
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
|
2024-05-08 18:26:33 +03:00
|
|
|
}
|
2024-09-08 03:49:29 +03:00
|
|
|
_sway_iterate_sockets toggle
|
2024-05-08 18:26:33 +03:00
|
|
|
}
|
|
|
|
|
2024-09-08 03:49:29 +03:00
|
|
|
# Toggle gaming.
|
|
|
|
function gamingtoggle() {
|
|
|
|
toggle() {
|
2024-09-08 03:12:13 +03:00
|
|
|
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-05-08 18:26:33 +03:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
_sway_iterate_sockets toggle
|
2024-05-08 18:26:33 +03:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2024-05-08 18:26:33 +03:00
|
|
|
function _monstate() {
|
2024-09-08 03:12:13 +03:00
|
|
|
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
|
2024-09-08 03:12:13 +03:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
done
|
|
|
|
|
2024-09-08 03:49:29 +03:00
|
|
|
printf on
|
2024-09-08 03:12:13 +03:00
|
|
|
return 0
|
2024-05-08 18:26:33 +03:00
|
|
|
}
|
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
|
2024-09-08 03:12:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function _gamingstate() {
|
2024-09-08 03:18:25 +03:00
|
|
|
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
|
2024-09-08 03:18:25 +03:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
done
|
|
|
|
|
2024-09-08 03:49:29 +03:00
|
|
|
printf off
|
2024-09-08 03:18:25 +03:00
|
|
|
return 0
|
2024-09-08 03:12:13 +03:00
|
|
|
}
|
2024-05-08 18:26:33 +03:00
|
|
|
'';
|
|
|
|
}
|