Swayscript : Add displayreset.

This commit is contained in:
Dmitry Voronin 2024-10-13 21:31:44 +03:00
parent 984b74fe27
commit 24a0cbec3a
Signed by: voronind
SSH key fingerprint: SHA256:3kBb4iV2ahufEBNq+vFbUe4QYfHt98DHQjN7QaptY9k
4 changed files with 36 additions and 12 deletions

View file

@ -1,6 +1,8 @@
# Dmitry 🌊 NixOS, Home Manager and Nix-on-Droid configurations. # Dmitry 🌊 NixOS, Home Manager and Nix-on-Droid configurations.
## Please, support tabs in Nix! [Discussion](https://github.com/NixOS/nix/pull/2911) ## Please, support tabs in Nix!
[Discussion](https://github.com/NixOS/nix/pull/2911) and [Open issue](https://github.com/NixOS/nix/issues/7834).
## Screenshots. ## Screenshots.

View file

@ -176,7 +176,7 @@ in
exec = "swayscript displaywidget"; exec = "swayscript displaywidget";
on-click = "sleep 0.1 && swayscript dnd"; # HACK: https://github.com/Alexays/Waybar/issues/2166 & https://github.com/Alexays/Waybar/issues/1968 on-click = "sleep 0.1 && swayscript dnd"; # HACK: https://github.com/Alexays/Waybar/issues/2166 & https://github.com/Alexays/Waybar/issues/1968
on-click-right = "sleep 0.1 && swayscript monitor"; on-click-right = "sleep 0.1 && swayscript monitor";
on-click-middle = "sleep 0.1 && swayscript gaming"; on-click-middle = "sleep 0.1 && swayscript displayreset";
return-type = "json"; return-type = "json";
signal = 4; signal = 4;
}; };

View file

@ -17,6 +17,11 @@
_sway_iterate_sockets toggle _sway_iterate_sockets toggle
} }
function monitorreset() {
swaymsg 'output * power on'
pkill -RTMIN+4 waybar
}
function gaming() { function gaming() {
toggle() { toggle() {
local output=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name') local output=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name')
@ -33,6 +38,11 @@
_sway_iterate_sockets toggle _sway_iterate_sockets toggle
} }
function gamingreset() {
swaymsg 'output * adaptive_sync off'
pkill -RTMIN+4 waybar
}
function dnd() { function dnd() {
toggle() { toggle() {
local state=$(makoctl mode) local state=$(makoctl mode)
@ -48,22 +58,31 @@
_sway_iterate_sockets toggle _sway_iterate_sockets toggle
} }
# Reset the state of everything.
function displayreset() {
[[ "''$(monitorstate)" = "Y" ]] && monitorreset
[[ "''$(gamingstate)" = "Y" ]] && gamingreset
[[ "''$(recordingstate)" = "Y" ]] && pkill wf-recorder
[[ "''$(dndstate)" = "Y" ]] && dnd
true
}
# Waybar output. # Waybar output.
function displaywidget() { function displaywidget() {
local __monitor=$(_monitor) local _monitorstate=$(monitorstate)
local __gaming=$(_gaming) local _gamingstate=$(gamingstate)
local __recording=$(_recording) local _recordingstate=$(recordingstate)
local __dnd=$(_dnd) local _dndstate=$(dndstate)
local class="" local class=""
if [[ "''${__monitor}" = "Y" ]] || [[ "''${__gaming}" = "Y" ]] || [[ "''${__recording}" = "Y" ]] || [[ "''${__dnd}" = "Y" ]]; then if [[ "''${_monitorstate}" = "Y" ]] || [[ "''${_gamingstate}" = "Y" ]] || [[ "''${_recordingstate}" = "Y" ]] || [[ "''${_dndstate}" = "Y" ]]; then
class="modified" class="modified"
fi fi
printf "{\"text\": \"󰍹\", \"tooltip\": \"DND: ''${__dnd} / Monitor: ''${__monitor} / Gaming: ''${__gaming} / Recording: ''${__recording}\", \"class\": \"''${class}\"}\n" printf "{\"text\": \"󰍹\", \"tooltip\": \"DND: ''${_dndstate} / Monitor: ''${_monitorstate} / Gaming: ''${_gamingstate} / Recording: ''${_recordingstate}\", \"class\": \"''${class}\"}\n"
} }
function _monitor() { function monitorstate() {
local outputs=($(swaymsg -t get_outputs | jq -r '.[] | .power')) local outputs=($(swaymsg -t get_outputs | jq -r '.[] | .power'))
for state in "''${outputs[@]}"; do for state in "''${outputs[@]}"; do
@ -77,15 +96,15 @@
return 0 return 0
} }
function _recording() { function recordingstate() {
[[ "$(ps cax | rg wf-recorder)" = "" ]] && printf n || printf Y [[ "$(ps cax | rg wf-recorder)" = "" ]] && printf n || printf Y
} }
function _dnd() { function dndstate() {
[[ "$(makoctl mode)" = "dnd" ]] && printf Y || printf n [[ "$(makoctl mode)" = "dnd" ]] && printf Y || printf n
} }
function _gaming() { function gamingstate() {
local outputs=($(swaymsg -t get_outputs | jq -r '.[] | .adaptive_sync_status')) local outputs=($(swaymsg -t get_outputs | jq -r '.[] | .adaptive_sync_status'))
for state in "''${outputs[@]}"; do for state in "''${outputs[@]}"; do

View file

@ -19,6 +19,9 @@
# Notifications. # Notifications.
makoctl reload makoctl reload
# Reset displays.
displayreset
} }
_sway_iterate_sockets re _sway_iterate_sockets re