Compare commits

...

3 Commits

Author SHA1 Message Date
John Mertz 0abcd17f22 Log current state to file (non-idle means that the state file does not exist)
Use existence of state file in new script to know whether to fade or unfade windows/notifications
2024-04-19 18:08:30 -06:00
John Mertz c0cb1ed8a7 (Un)hide mako notifications during (un)fade 2024-04-19 18:07:12 -06:00
John Mertz 0cfe8d4079 Offload wallpaper script to systemd 2024-04-19 18:05:12 -06:00
3 changed files with 36 additions and 12 deletions

View File

@ -393,7 +393,7 @@ my $t = Proc::ProcessTable->new();
foreach my $p ( @{ $t->table } ) {
my $cmndline = $p->{'cmndline'};
$cmndline =~ s/\s*$//g;
if ($cmndline =~ /^(waybar|wallpaper\.pl).*/) {
if ($cmndline =~ /^waybar.*/) {
# Never kill this process
if ($p->{'pid'} == $$) {
next;
@ -546,13 +546,5 @@ unless ($pid) {
`WAYLAND_DISPLAY=$waydisplay nohup $waybar_bin -b waybar0 --config=$waybar_config >> $ENV{'HOME'}/.waybar.log`;
}
# Start wallpapers script as fork
if ($w) {
$pid = fork;
unless ($pid) {
open STDIN, '/dev/null';
open STDOUT, '>>/dev/null';
open STDERR, '>>/dev/null';
`/usr/bin/perl $ENV{'HOME'}/scripts/sway/wallpaper.pl -d $w`;
}
}
# Restart wallpaper daemon
`systemctl --user restart wallpapers.service`;

View File

@ -8,6 +8,7 @@ HIBERNATE_TIMEOUT=3600 # one hour
BLFILE="$HOME/.local/state/idle.dim"
OPFILE="$HOME/.local/state/active_outputs"
STATEFILE="$HOME/.local/state/idle.state"
IDLEMODE=$(cat $HOME/.local/state/idle_mode)
if [[ -n $2 ]]; then
if [[ $2 == '--ignore_mode' ]]; then
@ -89,14 +90,22 @@ elif [[ $1 == "start" ]]; then
resume "$0 unsleep" \
timeout $HIBERNATE_TIMEOUT "$0 hibernate" \
resume "$0 unhibernate"
if [[ -e $STATEFILE ]]; then
rm $STATEFILE
fi
elif [[ $1 == "daemon" ]]; then
nohup $0 start 2>/dev/null &
elif [[ $1 == "stop" ]]; then
pkill swayidle
if [[ -e $STATEFILE ]]; then
rm $STATEFILE
fi
elif [[ $1 == "fade" ]]; then
if [[ $IDLEMODE -gt 0 ]]; then
echo 'hide' > $STATEFILE
if [[ ! -e $HOME/.local/state/sway-hidden ]]; then
kill -USR2 $(cat $HOME/.local/state/sway-transparency)
makoctl mode -a hide
fi
fi
elif [[ $1 == "unfade" ]]; then
@ -104,25 +113,37 @@ elif [[ $1 == "unfade" ]]; then
kill -USR2 $(cat $HOME/.local/state/sway-transparency)
# TODO: This is a hack. There's no reason that waybar should be dead.
#$HOME/scripts/sway/displays.pl -w
makoctl mode -r hide
fi
if [[ -e $STATEFILE ]]; then
rm $STATEFILE
fi
elif [[ $1 == "dim" ]]; then
if [[ $IDLEMODE -gt 1 ]]; then
echo 'dim' > $STATEFILE
# I don't currently have any dimable monitors, so fade was created instead
makoctl set-mode away
echo $($HOME/scripts/thinkpad/blc.pl %) >$BLFILE
$HOME/scripts/thinkpad/blc.pl = 1 &>-
fi
elif [[ $1 == "undim" ]]; then
makoctl set-mode default
$HOME/scripts/thinkpad/blc.pl = $(cat $BLFILE) &>-
if [[ -e $STATEFILE ]]; then
rm $STATEFILE
fi
elif [[ $1 == "lock" ]]; then
if [[ $IDLEMODE -gt 2 ]]; then
echo 'lock' > $STATEFILE
swaylock -f -c 00000000
fi
elif [[ $1 == "unlock" ]]; then
kill -USR1 $(pgrep swaylock)
if [[ -e $STATEFILE ]]; then
rm $STATEFILE
fi
elif [[ $1 == "sleep" ]]; then
if [[ $IDLEMODE -gt 3 ]]; then
echo 'sleep' > $STATEFILE
for i in $(cat $OPFILE); do swaymsg "output $i dpms off"; done
fi
elif [[ $1 == "unsleep" ]]; then
@ -131,8 +152,12 @@ elif [[ $1 == "unsleep" ]]; then
cd $HOME/scripts/sway
source $HOME/.dotfiles/bash/plenv-path.sh
$HOME/scripts/sway/displays.pl 2>&1 >$HOME/.local/state/display_unsleep
if [[ -e $STATEFILE ]]; then
rm $STATEFILE
fi
elif [[ $1 == "hibernate" ]]; then
if [[ $IDLEMODE -gt 4 ]]; then
echo 'hibernate' > $STATEFILE
sudo systemctl suspend-then-hibernate.target
fi
else

7
sway/toggle_fade.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
if [[ -e ${HOME}/.local/state/idle.state ]]; then
${HOME}/scripts/sway/idle.sh unfade
else
${HOME}/scripts/sway/idle.sh fade
fi