nix/package/swayscript/script/DisplayWidget.nix

102 lines
2.3 KiB
Nix
Raw Normal View History

{ ... }: {
text = ''
2024-09-13 04:16:08 +03:00
function monitor() {
2024-09-08 03:49:29 +03:00
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-13 04:16:08 +03:00
function gaming() {
2024-09-08 03:49:29 +03:00
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-13 04:16:08 +03:00
function dnd() {
toggle() {
local state=$(makoctl mode)
if [[ "''${state}" = "dnd" ]]; then
makoctl mode -s default
else
makoctl mode -s dnd
fi
pkill -RTMIN+4 waybar
}
_sway_iterate_sockets toggle
}
2024-09-08 03:49:29 +03:00
# Waybar output.
2024-09-13 04:16:08 +03:00
function displaywidget() {
local __monitor=$(_monitor)
local __gaming=$(_gaming)
2024-08-22 19:13:40 +03:00
local __recording=$(_recording)
2024-09-13 04:16:08 +03:00
local __dnd=$(_dnd)
2024-05-24 03:43:20 +03:00
local class=""
2024-09-13 04:16:08 +03:00
if [[ "''${__monitor}" = "on" ]] || [[ "''${__gaming}" = "on" ]] || [[ "''${__recording}" = "on" ]] || [[ "''${__dnd}" = "on" ]]; then
2024-05-24 03:43:20 +03:00
class="modified"
fi
2024-09-13 04:16:08 +03:00
printf "{\"text\": \"󰍹\", \"tooltip\": \"DND: ''${__dnd^} / Monitor: ''${__monitor^} / Gaming: ''${__gaming^} / Recording: ''${__recording^}\", \"class\": \"''${class}\"}\n"
2024-05-08 21:12:48 +03:00
}
2024-09-13 04:16:08 +03:00
function _monitor() {
local outputs=($(swaymsg -t get_outputs | jq -r '.[] | .power'))
for state in "''${outputs[@]}"; do
''${state} || {
2024-09-13 04:16:08 +03:00
printf on
return 1
}
done
2024-09-13 04:16:08 +03:00
printf off
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
}
2024-09-13 04:16:08 +03:00
function _dnd() {
[[ "$(makoctl mode)" = "dnd" ]] && printf on || printf off
}
function _gaming() {
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
}
'';
}