Merge branch 'master' of ssh://git@git.john.me.tz:223/jpm/scripts.git

This commit is contained in:
John Mertz 2023-01-08 22:53:51 -05:00
commit d1fbad9b82
14 changed files with 374 additions and 362 deletions

View File

@ -53,6 +53,7 @@ elif [ $1 == "fade" ]; then
elif [ $1 == "unfade" ]; then elif [ $1 == "unfade" ]; then
if [ -e $HOME/.spool/sway-hidden ]; then if [ -e $HOME/.spool/sway-hidden ]; then
kill -USR2 `cat $HOME/.spool/sway-transparency` kill -USR2 `cat $HOME/.spool/sway-transparency`
/home/jpm/scripts/sway/displays.pl -w
fi fi
elif [ $1 == "dim" ]; then elif [ $1 == "dim" ]; then
echo $($HOME/scripts/thinkpad/blc.pl %) > $BLFILE echo $($HOME/scripts/thinkpad/blc.pl %) > $BLFILE

View File

@ -32,10 +32,10 @@ elif [ "$res" == "↹ Restart i3" ]; then
i3 restart i3 restart
elif [ "$res" == "↻ Reload Sway" ]; then elif [ "$res" == "↻ Reload Sway" ]; then
sway reload sway reload
/home/jpm/scripts/sway/displays.pl /home/jpm/scripts/distrobox/debian12/displays.sh
elif [ "$res" == "↻ Reload Waybar" ]; then elif [ "$res" == "↻ Reload Waybar" ]; then
# Need to integrate with sway/displays.pl for alternative outputs # Need to integrate with sway/displays.pl for alternative outputs
/home/jpm/scripts/sway/displays.pl -w /home/jpm/scripts/distrobox/debian12/displays.sh -w
elif [ "$res" == "🡙 Reboot" ]; then elif [ "$res" == "🡙 Reboot" ]; then
rm $SSH_AUTH_SOCK rm $SSH_AUTH_SOCK
sudo systemctl reboot -i sudo systemctl reboot -i

View File

@ -20,7 +20,7 @@ export FLATPAK_IDE_LOG_LEVEL="0"
export "$( gnome-keyring-daemon --start )" export "$( gnome-keyring-daemon --start )"
#WLR_RENDERER=vulkan sway --debug 2>> $HOME/.swaylog >> $HOME/.swaylog #WLR_RENDERER=vulkan sway --debug 2>> $HOME/.swaylog >> $HOME/.swaylog
WLR_RENDERER=gles2 sway --debug 2>> $HOME/.swaylog >> $HOME/.swaylog; export SWAYSOCK=`sway --get-socketpath` WLR_RENDERER=gles2 sway --debug 2>> $HOME/.swaylog >> $HOME/.swaylog
#WLR_RENDERER=vulkan sway --debug 2>> $HOME/.swaylog >> $HOME/.swaylog #WLR_RENDERER=vulkan sway --debug 2>> $HOME/.swaylog >> $HOME/.swaylog
#WLR_RENDERER=gles2 $HOME/build/sway/build/sway/sway --debug 2>> $HOME/.swaylog >> $HOME/.swaylog #WLR_RENDERER=gles2 $HOME/build/sway/build/sway/sway --debug 2>> $HOME/.swaylog >> $HOME/.swaylog
export SWAYSOCK=`sway --get-socketpath` export SWAYSOCK=`sway --get-socketpath`

View File

@ -66,6 +66,64 @@ sub new
return bless { %args }; return bless { %args };
} }
$args{pidfile} = "/tmp/$ENV{USER}-wallpaper.pid";
if (-e $wp->{pidfile}) {
if (-r $wp->{pidfile}) {
if (open(my $fh, '<', $wp->{pidfile})) {
my $pid = <$fh>;
chomp($pid);
use Proc::ProcessTable;
my $pt = Proc::ProcessTable->new();
foreach my $p ( @{ $pt->table() } ) {
if ($p->{pid} eq $pid) {
my $name = $0;
$name =~ s/$ENV{PWD}//;
if ($p->{'cmndline'} =~ m#$name#) {
$wp->do_log("LOG_CRIT", "Another process is already running with PID: $pid (running and listed in $wp->{pidfile})");
# Die locally because do_log will remove pidfile that this iteration does not belong to
exit(1);
} else {
$wp->do_log("LOG_CRIT", "Found matching $pid with different cmdline: $p->{cmndline} (not $0)",1);
# PID in pidfile doesn't look like it is another wallpaper
unlink($wp->{pidfile});
last;
}
return $p->{'pid'};
}
}
} else {
$wp->do_log("LOG_CRIT", "Pidfile $wp->{pidfile} exists, but cannot be opened. Assuming it is running already.");
# Die locally because do_log will remove pidfile that this iteration does not belong to
exit(1);
}
} else {
$wp->do_log("LOG_CRIT", "Pidfile $wp->{pidfile} exists, but is not readable. Assuming it is running already.");
# Die locally because do_log will remove pidfile that this iteration does not belong to
exit(1);
}
}
# SIGUSR reset the timer, force immediate reload, continue looping
$SIG{USR1} = sub {
alarm 0;
$wp->do_log("LOG_INFO", "Reloading due to SIGUSR1");
};
# SIGTERM reset the timer, clean pid, and allow for the main loop to finish run
$SIG{TERM} = sub {
$wp->do_log("LOG_INFO", "Going down clean due to SIGTERM");
clean($wp);
$wp->{daemon} = 0;
};
# SIGKILL clean pid then exit immediately
$SIG{KILL} = sub {
$wp->do_log("LOG_INFO", "Hard kill with SIGKILL, attempting to remove pidfile");
clean($wp);
exit(0);
};
# simply returns the array of hashes provided by swaymsg # simply returns the array of hashes provided by swaymsg
sub get_outputs sub get_outputs
{ {
@ -223,12 +281,12 @@ sub do_log
# Journald is borked. Just don't bother logging # Journald is borked. Just don't bother logging
return 0; return 0;
if ($self->{daemon}) { if ($self->{daemon}) {
#use Log::Journald qw(send); use Log::Journald qw(send);
#send( send(
#PRIORITY => ERROR->{$level}, PRIORITY => ERROR->{$level},
#MESSAGE => $msg, MESSAGE => $msg,
#PERL_PACKAGE => 'Sway Wallpapers' PERL_PACKAGE => 'Sway Wallpapers'
#) || warn "Could not send log ($level $msg): $!"; ) || warn "Could not send log ($level $msg): $!";
if ($die) { if ($die) {
$msg = '(FATAL) ' . $msg; $msg = '(FATAL) ' . $msg;
exit(1); exit(1);
@ -250,7 +308,6 @@ sub run
$self->do_log("LOG_DEBUG", "Fetching outputs from IPC"); $self->do_log("LOG_DEBUG", "Fetching outputs from IPC");
$self->{outputs} = $self->get_outputs(); $self->{outputs} = $self->get_outputs();
# Local copy of targets so that it will re-check active every time # Local copy of targets so that it will re-check active every time
print "Changing $_\n" foreach(@{$self->{targets}});
my @t = @{$self->{targets}} if (scalar(@{$self->{targets}})); my @t = @{$self->{targets}} if (scalar(@{$self->{targets}}));
$self->do_log("LOG_DEBUG", "Removing inactive ouputs"); $self->do_log("LOG_DEBUG", "Removing inactive ouputs");
my $active = $self->get_active(); my $active = $self->get_active();
@ -261,7 +318,6 @@ sub run
} }
$self->do_log("LOG_DEBUG", "Looping desired ouputs"); $self->do_log("LOG_DEBUG", "Looping desired ouputs");
foreach my $target (@t) { foreach my $target (@t) {
print $target."\n";
$self->do_log("LOG_DEBUG", "Ensuring that desired output is active"); $self->do_log("LOG_DEBUG", "Ensuring that desired output is active");
unless (defined($active->{$target})) { unless (defined($active->{$target})) {
$self->do_log('LOG_DEBUG', "Target $target is not an active output"); $self->do_log('LOG_DEBUG', "Target $target is not an active output");
@ -371,47 +427,7 @@ while (my $arg = shift(@ARGV)) {
} elsif ($arg =~ m/^-/) { } elsif ($arg =~ m/^-/) {
die "Unrecognized argument: $arg\n"; die "Unrecognized argument: $arg\n";
} else { } else {
print "Adding $arg to targets\n";
push(@targets,$arg); push(@targets,$arg);
print "Setting $_\n" foreach(@targets);
$wp->{targets} = \@targets || undef;
print "Set $_\n" foreach(@{$wp->{targets}});
}
}
if (-e $wp->{pidfile}) {
if (-r $wp->{pidfile}) {
if (open(my $fh, '<', $wp->{pidfile})) {
my $pid = <$fh>;
chomp($pid);
use Proc::ProcessTable;
my $pt = Proc::ProcessTable->new();
foreach my $p ( @{ $pt->table() } ) {
if ($p->{pid} eq $pid) {
my $name = $0;
$name =~ s/$ENV{PWD}//;
if ($p->{'cmndline'} =~ m#$name#) {
$wp->do_log("LOG_CRIT", "Another process is already running with PID: $pid (running and listed in $wp->{pidfile})");
# Die locally because do_log will remove pidfile that this iteration does not belong to
exit(1);
} else {
$wp->do_log("LOG_CRIT", "Found matching $pid with different cmdline: $p->{cmndline} (not $0)",1);
# PID in pidfile doesn't look like it is another wallpaper
unlink($wp->{pidfile});
last;
}
return $p->{'pid'};
}
}
} else {
$wp->do_log("LOG_CRIT", "Pidfile $wp->{pidfile} exists, but cannot be opened. Assuming it is running already.");
# Die locally because do_log will remove pidfile that this iteration does not belong to
exit(1);
}
} else {
$wp->do_log("LOG_CRIT", "Pidfile $wp->{pidfile} exists, but is not readable. Assuming it is running already.");
# Die locally because do_log will remove pidfile that this iteration does not belong to
exit(1);
} }
} }

View File

@ -47,7 +47,6 @@ foreach (@devices) {
close $t; close $t;
$output .= '"Type":"' . $type . '"'; $output .= '"Type":"' . $type . '"';
if ($name =~ /BAT[0-9]+/) { if ($name =~ /BAT[0-9]+/) {
$nobat = 0;
open(my $s,'<',"$_/status"); open(my $s,'<',"$_/status");
my $status = <$s>; my $status = <$s>;
chomp $status; chomp $status;
@ -86,10 +85,6 @@ foreach (@devices) {
} }
$output .= "},"; $output .= "},";
} }
unless ($nobat) {
print('{"AC":{"Type":"AC","Status":"Plugged-In"}}');
exit();
}
$battery_total{'percentage'} = sprintf("%0d", $battery_total{'percentage'} = sprintf("%0d",
$battery_total{'current'} / $battery_total{'max'} * 100 $battery_total{'current'} / $battery_total{'max'} * 100