Swayscript : Refactor DisplayWidget.
This commit is contained in:
parent
1a32e04bb2
commit
b902544093
|
@ -14,5 +14,11 @@ in {
|
|||
text-color = "#${config.style.color.fg.light}";
|
||||
width = 480;
|
||||
};
|
||||
|
||||
sections = {
|
||||
"mode=dnd" = {
|
||||
invisible = 1;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
{ ... }: {
|
||||
text = ''
|
||||
# Show last notification.
|
||||
bindsym --to-code $mod+n exec makoctl restore
|
||||
bindsym --to-code $mod+shift+n exec makoctl restore
|
||||
|
||||
# Hide all notifications.
|
||||
bindsym --to-code $mod+shift+N exec makoctl dismiss --all
|
||||
bindsym --to-code $mod+n exec makoctl dismiss --all
|
||||
'';
|
||||
}
|
||||
|
|
|
@ -5,12 +5,13 @@ in {
|
|||
text = ''
|
||||
bindsym ${mod} input * xkb_switch_layout 0
|
||||
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}+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}+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}+z exec 'systemctl suspend -i'
|
||||
|
||||
|
|
|
@ -128,20 +128,21 @@ in {
|
|||
tooltip = false;
|
||||
};
|
||||
"custom/display" = {
|
||||
exec = "swayscript monbar";
|
||||
on-click = "sleep 0.1 && swayscript montoggle"; # FIXME: remove sleep when resolved: https://github.com/Alexays/Waybar/issues/216
|
||||
on-click-right = "sleep 0.1 && swayscript gamingtoggle";
|
||||
exec = "swayscript displaywidget";
|
||||
on-click = "swayscript dnd";
|
||||
on-click-right = "swayscript monitor";
|
||||
on-click-middle = "swayscript gaming";
|
||||
return-type = "json";
|
||||
signal = 4;
|
||||
};
|
||||
"custom/powersave" = {
|
||||
exec = "powersave waybar";
|
||||
exec = "powersave widget";
|
||||
on-click = "foot -e bash -c btop";
|
||||
on-click-right = "powersave toggle";
|
||||
signal = 5;
|
||||
};
|
||||
"custom/powerlimit" = {
|
||||
exec = "powerlimit waybar";
|
||||
exec = "powerlimit widget";
|
||||
on-click-right = "powerlimit toggle";
|
||||
signal = 6;
|
||||
};
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
true
|
||||
}
|
||||
|
||||
function waybar() {
|
||||
function widget() {
|
||||
status || echo -n ""
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
true
|
||||
}
|
||||
|
||||
function waybar() {
|
||||
function widget() {
|
||||
status || echo -n ""
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
{ ... }: {
|
||||
text = ''
|
||||
# Toggle monitors.
|
||||
function montoggle() {
|
||||
function monitor() {
|
||||
toggle() {
|
||||
local output=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name')
|
||||
local state=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .power')
|
||||
|
@ -17,8 +16,7 @@
|
|||
_sway_iterate_sockets toggle
|
||||
}
|
||||
|
||||
# Toggle gaming.
|
||||
function gamingtoggle() {
|
||||
function gaming() {
|
||||
toggle() {
|
||||
local output=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name')
|
||||
local state=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .adaptive_sync_status')
|
||||
|
@ -34,31 +32,47 @@
|
|||
_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.
|
||||
function monbar() {
|
||||
local __monstate=$(_monstate)
|
||||
local __gamingstate=$(_gamingstate)
|
||||
function displaywidget() {
|
||||
local __monitor=$(_monitor)
|
||||
local __gaming=$(_gaming)
|
||||
local __recording=$(_recording)
|
||||
local __dnd=$(_dnd)
|
||||
local class=""
|
||||
|
||||
if [[ "''${__monstate}" = "off" ]] || [[ "''${__gamingstate}" = "on" ]] || [[ "''${__recording}" = "on" ]]; then
|
||||
if [[ "''${__monitor}" = "on" ]] || [[ "''${__gaming}" = "on" ]] || [[ "''${__recording}" = "on" ]] || [[ "''${__dnd}" = "on" ]]; then
|
||||
class="modified"
|
||||
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'))
|
||||
|
||||
for state in "''${outputs[@]}"; do
|
||||
''${state} || {
|
||||
printf off
|
||||
printf on
|
||||
return 1
|
||||
}
|
||||
done
|
||||
|
||||
printf on
|
||||
printf off
|
||||
return 0
|
||||
}
|
||||
|
||||
|
@ -66,7 +80,11 @@
|
|||
[[ "$(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'))
|
||||
|
||||
for state in "''${outputs[@]}"; do
|
|
@ -1,15 +1,15 @@
|
|||
{ ... }: {
|
||||
text = ''
|
||||
# Toggle vpn.
|
||||
function vpntoggle() {
|
||||
if [[ "$(_vpnstate)" = "on" ]]; then
|
||||
function vpn() {
|
||||
if [[ "$(_vpn)" = "on" ]]; then
|
||||
nmcli connection down vpn
|
||||
else
|
||||
nmcli connection up vpn
|
||||
fi
|
||||
}
|
||||
|
||||
function _vpnstate() {
|
||||
function _vpn() {
|
||||
local state=$(nmcli connection show vpn | rg -i state.*activated)
|
||||
[ "''${state}" != "" ] && printf on || printf off
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue