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.
## 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.

View file

@ -176,7 +176,7 @@ in
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-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";
signal = 4;
};

View file

@ -17,6 +17,11 @@
_sway_iterate_sockets toggle
}
function monitorreset() {
swaymsg 'output * power on'
pkill -RTMIN+4 waybar
}
function gaming() {
toggle() {
local output=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name')
@ -33,6 +38,11 @@
_sway_iterate_sockets toggle
}
function gamingreset() {
swaymsg 'output * adaptive_sync off'
pkill -RTMIN+4 waybar
}
function dnd() {
toggle() {
local state=$(makoctl mode)
@ -48,22 +58,31 @@
_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.
function displaywidget() {
local __monitor=$(_monitor)
local __gaming=$(_gaming)
local __recording=$(_recording)
local __dnd=$(_dnd)
local _monitorstate=$(monitorstate)
local _gamingstate=$(gamingstate)
local _recordingstate=$(recordingstate)
local _dndstate=$(dndstate)
local class=""
if [[ "''${__monitor}" = "Y" ]] || [[ "''${__gaming}" = "Y" ]] || [[ "''${__recording}" = "Y" ]] || [[ "''${__dnd}" = "Y" ]]; then
if [[ "''${_monitorstate}" = "Y" ]] || [[ "''${_gamingstate}" = "Y" ]] || [[ "''${_recordingstate}" = "Y" ]] || [[ "''${_dndstate}" = "Y" ]]; then
class="modified"
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'))
for state in "''${outputs[@]}"; do
@ -77,15 +96,15 @@
return 0
}
function _recording() {
function recordingstate() {
[[ "$(ps cax | rg wf-recorder)" = "" ]] && printf n || printf Y
}
function _dnd() {
function dndstate() {
[[ "$(makoctl mode)" = "dnd" ]] && printf Y || printf n
}
function _gaming() {
function gamingstate() {
local outputs=($(swaymsg -t get_outputs | jq -r '.[] | .adaptive_sync_status'))
for state in "''${outputs[@]}"; do

View file

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