Swayscript : Refactor DisplayWidget.

This commit is contained in:
Dmitry Voronin 2024-09-13 04:16:08 +03:00
parent 1a32e04bb2
commit b902544093
Signed by: voronind
SSH key fingerprint: SHA256:3kBb4iV2ahufEBNq+vFbUe4QYfHt98DHQjN7QaptY9k
8 changed files with 56 additions and 30 deletions

View file

@ -14,5 +14,11 @@ in {
text-color = "#${config.style.color.fg.light}"; text-color = "#${config.style.color.fg.light}";
width = 480; width = 480;
}; };
sections = {
"mode=dnd" = {
invisible = 1;
};
};
}; };
} }

View file

@ -1,9 +1,9 @@
{ ... }: { { ... }: {
text = '' text = ''
# Show last notification. # Show last notification.
bindsym --to-code $mod+n exec makoctl restore bindsym --to-code $mod+shift+n exec makoctl restore
# Hide all notifications. # Hide all notifications.
bindsym --to-code $mod+shift+N exec makoctl dismiss --all bindsym --to-code $mod+n exec makoctl dismiss --all
''; '';
} }

View file

@ -5,12 +5,13 @@ in {
text = '' text = ''
bindsym ${mod} input * xkb_switch_layout 0 bindsym ${mod} input * xkb_switch_layout 0
bindsym --to-code ${mod}+c exec 'systemctl reboot -i' bindsym --to-code ${mod}+c exec 'systemctl reboot -i'
bindsym --to-code ${mod}+g exec 'swayscript gamingtoggle' bindsym --to-code ${mod}+g exec 'swayscript gaming'
bindsym --to-code ${mod}+l exec 'powerlimit toggle' bindsym --to-code ${mod}+l exec 'powerlimit toggle'
bindsym --to-code ${mod}+m exec 'swayscript montoggle' bindsym --to-code ${mod}+m exec 'swayscript monitor'
bindsym --to-code ${mod}+n exec 'swayscript dnd'
bindsym --to-code ${mod}+p exec 'powersave toggle' bindsym --to-code ${mod}+p exec 'powersave toggle'
bindsym --to-code ${mod}+r exec 'swayscript reload' bindsym --to-code ${mod}+r exec 'swayscript reload'
bindsym --to-code ${mod}+v exec 'swayscript vpntoggle' bindsym --to-code ${mod}+v exec 'swayscript vpn'
bindsym --to-code ${mod}+x exec 'systemctl poweroff -i' bindsym --to-code ${mod}+x exec 'systemctl poweroff -i'
bindsym --to-code ${mod}+z exec 'systemctl suspend -i' bindsym --to-code ${mod}+z exec 'systemctl suspend -i'

View file

@ -128,20 +128,21 @@ in {
tooltip = false; tooltip = false;
}; };
"custom/display" = { "custom/display" = {
exec = "swayscript monbar"; exec = "swayscript displaywidget";
on-click = "sleep 0.1 && swayscript montoggle"; # FIXME: remove sleep when resolved: https://github.com/Alexays/Waybar/issues/216 on-click = "swayscript dnd";
on-click-right = "sleep 0.1 && swayscript gamingtoggle"; on-click-right = "swayscript monitor";
on-click-middle = "swayscript gaming";
return-type = "json"; return-type = "json";
signal = 4; signal = 4;
}; };
"custom/powersave" = { "custom/powersave" = {
exec = "powersave waybar"; exec = "powersave widget";
on-click = "foot -e bash -c btop"; on-click = "foot -e bash -c btop";
on-click-right = "powersave toggle"; on-click-right = "powersave toggle";
signal = 5; signal = 5;
}; };
"custom/powerlimit" = { "custom/powerlimit" = {
exec = "powerlimit waybar"; exec = "powerlimit widget";
on-click-right = "powerlimit toggle"; on-click-right = "powerlimit toggle";
signal = 6; signal = 6;
}; };

View file

@ -19,7 +19,7 @@
true true
} }
function waybar() { function widget() {
status || echo -n "" status || echo -n ""
} }

View file

@ -13,7 +13,7 @@
true true
} }
function waybar() { function widget() {
status || echo -n "󰓅" status || echo -n "󰓅"
} }

View file

@ -1,7 +1,6 @@
{ ... }: { { ... }: {
text = '' text = ''
# Toggle monitors. function monitor() {
function montoggle() {
toggle() { toggle() {
local output=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name') local output=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name')
local state=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .power') local state=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .power')
@ -17,8 +16,7 @@
_sway_iterate_sockets toggle _sway_iterate_sockets toggle
} }
# Toggle gaming. function gaming() {
function gamingtoggle() {
toggle() { toggle() {
local output=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name') local output=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name')
local state=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .adaptive_sync_status') local state=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .adaptive_sync_status')
@ -34,31 +32,47 @@
_sway_iterate_sockets toggle _sway_iterate_sockets toggle
} }
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
}
# Waybar output. # Waybar output.
function monbar() { function displaywidget() {
local __monstate=$(_monstate) local __monitor=$(_monitor)
local __gamingstate=$(_gamingstate) local __gaming=$(_gaming)
local __recording=$(_recording) local __recording=$(_recording)
local __dnd=$(_dnd)
local class="" local class=""
if [[ "''${__monstate}" = "off" ]] || [[ "''${__gamingstate}" = "on" ]] || [[ "''${__recording}" = "on" ]]; then if [[ "''${__monitor}" = "on" ]] || [[ "''${__gaming}" = "on" ]] || [[ "''${__recording}" = "on" ]] || [[ "''${__dnd}" = "on" ]]; then
class="modified" class="modified"
fi fi
printf "{\"text\": \"󰍹\", \"tooltip\": \"Monitor: ''${__monstate^} / Gaming: ''${__gamingstate^} / Recording: ''${__recording^}\", \"class\": \"''${class}\"}\n" printf "{\"text\": \"󰍹\", \"tooltip\": \"DND: ''${__dnd^} / Monitor: ''${__monitor^} / Gaming: ''${__gaming^} / Recording: ''${__recording^}\", \"class\": \"''${class}\"}\n"
} }
function _monstate() { function _monitor() {
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
''${state} || { ''${state} || {
printf off printf on
return 1 return 1
} }
done done
printf on printf off
return 0 return 0
} }
@ -66,7 +80,11 @@
[[ "$(ps cax | rg wf-recorder)" = "" ]] && printf off || printf on [[ "$(ps cax | rg wf-recorder)" = "" ]] && printf off || printf on
} }
function _gamingstate() { function _dnd() {
[[ "$(makoctl mode)" = "dnd" ]] && printf on || printf off
}
function _gaming() {
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

@ -1,15 +1,15 @@
{ ... }: { { ... }: {
text = '' text = ''
# Toggle vpn. # Toggle vpn.
function vpntoggle() { function vpn() {
if [[ "$(_vpnstate)" = "on" ]]; then if [[ "$(_vpn)" = "on" ]]; then
nmcli connection down vpn nmcli connection down vpn
else else
nmcli connection up vpn nmcli connection up vpn
fi fi
} }
function _vpnstate() { function _vpn() {
local state=$(nmcli connection show vpn | rg -i state.*activated) local state=$(nmcli connection show vpn | rg -i state.*activated)
[ "''${state}" != "" ] && printf on || printf off [ "''${state}" != "" ] && printf on || printf off
} }