tabs->spaces
This commit is contained in:
parent
ecd9920a37
commit
6d33d9446f
|
@ -66,64 +66,6 @@ sub new
|
|||
return bless { %args };
|
||||
}
|
||||
|
||||
my $wp = new("Wallpapers");
|
||||
|
||||
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
|
||||
sub get_outputs
|
||||
{
|
||||
|
@ -281,12 +223,12 @@ sub do_log
|
|||
# Journald is borked. Just don't bother logging
|
||||
return 0;
|
||||
if ($self->{daemon}) {
|
||||
use Log::Journald qw(send);
|
||||
send(
|
||||
PRIORITY => ERROR->{$level},
|
||||
MESSAGE => $msg,
|
||||
PERL_PACKAGE => 'Sway Wallpapers'
|
||||
) || warn "Could not send log ($level $msg): $!";
|
||||
#use Log::Journald qw(send);
|
||||
#send(
|
||||
#PRIORITY => ERROR->{$level},
|
||||
#MESSAGE => $msg,
|
||||
#PERL_PACKAGE => 'Sway Wallpapers'
|
||||
#) || warn "Could not send log ($level $msg): $!";
|
||||
if ($die) {
|
||||
$msg = '(FATAL) ' . $msg;
|
||||
exit(1);
|
||||
|
@ -308,6 +250,7 @@ sub run
|
|||
$self->do_log("LOG_DEBUG", "Fetching outputs from IPC");
|
||||
$self->{outputs} = $self->get_outputs();
|
||||
# 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}}));
|
||||
$self->do_log("LOG_DEBUG", "Removing inactive ouputs");
|
||||
my $active = $self->get_active();
|
||||
|
@ -318,6 +261,7 @@ sub run
|
|||
}
|
||||
$self->do_log("LOG_DEBUG", "Looping desired ouputs");
|
||||
foreach my $target (@t) {
|
||||
print $target."\n";
|
||||
$self->do_log("LOG_DEBUG", "Ensuring that desired output is active");
|
||||
unless (defined($active->{$target})) {
|
||||
$self->do_log('LOG_DEBUG', "Target $target is not an active output");
|
||||
|
@ -374,6 +318,8 @@ sub run
|
|||
################################################################################
|
||||
# Collect arguments
|
||||
################################################################################
|
||||
|
||||
my $wp = new("Wallpapers");
|
||||
my @targets;
|
||||
my $daemon;
|
||||
my $delay;
|
||||
|
@ -381,6 +327,7 @@ my $crop;
|
|||
my $path;
|
||||
my $verbose;
|
||||
my $recursive = 0;
|
||||
|
||||
while (my $arg = shift(@ARGV)) {
|
||||
if ($arg eq '-h' || $arg eq '--help') {
|
||||
$wp->usage();
|
||||
|
@ -424,7 +371,47 @@ while (my $arg = shift(@ARGV)) {
|
|||
} elsif ($arg =~ m/^-/) {
|
||||
die "Unrecognized argument: $arg\n";
|
||||
} else {
|
||||
print "Adding $arg to targets\n";
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -438,7 +425,6 @@ die "Invalid wallpaper path '$path'. Not a directory." if (defined($path) && !-d
|
|||
die "Invalid verbosity level: '$verbose'\n" if (defined($verbose) && $verbose !~ m/^[1-8]$/);
|
||||
|
||||
$wp->do_log("LOG_DEBUG", "Configuring object");
|
||||
$wp->{targets} = \@targets || undef;
|
||||
$wp->{daemon} = $daemon || 0;
|
||||
$wp->{path} = $path || "$ENV{HOME}/wallpapers";
|
||||
$wp->{crop} = $crop || 1;
|
||||
|
@ -495,4 +481,28 @@ do {
|
|||
# If we made it to here, it was not daemonized. Output errors and exit
|
||||
$wp->do_log("LOG_DEBUG", "Finishing") unless ($wp->{daemon});
|
||||
|
||||
################################################################################
|
||||
# Signals
|
||||
################################################################################
|
||||
|
||||
# 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);
|
||||
};
|
||||
|
||||
exit(0);
|
||||
|
|
|
@ -30,6 +30,11 @@ my %battery_total = (
|
|||
);
|
||||
|
||||
my @devices = <"/sys/class/power_supply/*">;
|
||||
unless (scalar(@devices)) {
|
||||
print('{"AC":{"Type":"AC","Status":"Plugged-In"}}');
|
||||
exit();
|
||||
}
|
||||
my $nobat = 1;
|
||||
$output .= "{";
|
||||
foreach (@devices) {
|
||||
my $path = $_;
|
||||
|
@ -42,6 +47,7 @@ foreach (@devices) {
|
|||
close $t;
|
||||
$output .= '"Type":"' . $type . '"';
|
||||
if ($name =~ /BAT[0-9]+/) {
|
||||
$nobat = 0;
|
||||
open(my $s,'<',"$_/status");
|
||||
my $status = <$s>;
|
||||
chomp $status;
|
||||
|
@ -80,6 +86,10 @@ foreach (@devices) {
|
|||
}
|
||||
$output .= "},";
|
||||
}
|
||||
unless ($nobat) {
|
||||
print('{"AC":{"Type":"AC","Status":"Plugged-In"}}');
|
||||
exit();
|
||||
}
|
||||
|
||||
$battery_total{'percentage'} = sprintf("%0d",
|
||||
$battery_total{'current'} / $battery_total{'max'} * 100
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
#!/bin/bash
|
||||
|
||||
PID=$(pgrep gammastep)
|
||||
RUNNING=`cat $HOME/.spool/gammastep.status`
|
||||
RUNNING=0
|
||||
if [ -e $HOME/.spool/gammastep.status ]; then
|
||||
RUNNING=`cat $HOME/.spool/gammastep.status`
|
||||
fi
|
||||
|
||||
ACTION=$1
|
||||
if [[ "$1" == '' ]]; then
|
||||
|
@ -52,7 +55,10 @@ else
|
|||
echo "Invalid argument '$ACTION'. Use 'bar', 'toggle', 'start', 'stop', 'enable', 'disable'."
|
||||
fi
|
||||
|
||||
RUNNING=`cat $HOME/.spool/gammastep.status`
|
||||
RUNNING=0
|
||||
if [ -e $HOME/.spool/gammastep.status ]; then
|
||||
RUNNING=`cat $HOME/.spool/gammastep.status`
|
||||
fi
|
||||
if [ "$RUNNING" ]; then
|
||||
echo '{"text":"ɣ","icon":"ɣ","tooltip":"Disable Gammastep","class":"enabled"}'
|
||||
else
|
||||
|
|
|
@ -5,7 +5,6 @@ swaymsg -t get_tree |
|
|||
sed -e 's/^.*\-\- \(.*\)$/\1/' |
|
||||
sed -e 's/^\(.*\) [—-] .*$/\1/'|
|
||||
sed -e 's/^\([0-9]*\)\t*\(.*\)/\2 \1/' |
|
||||
<<<<<<< HEAD
|
||||
wofi -s $HOME/.dotfiles/wofi/style.css -c \
|
||||
$HOME/.dotfiles/wofi/sidebar -d | {
|
||||
read -r
|
||||
|
@ -13,10 +12,3 @@ swaymsg -t get_tree |
|
|||
swaymsg "[con_id=$id]" focus
|
||||
}
|
||||
echo $id $REPLY
|
||||
=======
|
||||
wofi -I -s /home/jpm/.dotfiles/wofi/style.css -c \
|
||||
$HOME/.dotfiles/wofi/sidebar --show dmenu | {
|
||||
read -r id name
|
||||
swaymsg "[con_id=$id]" focus
|
||||
}
|
||||
>>>>>>> master
|
||||
|
|
Loading…
Reference in New Issue