tabs->spaces

This commit is contained in:
John Mertz 2023-01-06 14:41:31 -05:00
parent ecd9920a37
commit 6d33d9446f
41 changed files with 1221 additions and 1203 deletions

View File

@ -9,10 +9,10 @@ use XML::Hash::XS; # CPAN or libxml-hash-xs-perl on Debian
# Feeds that should be used if no arguments are provided
my @default_feeds = (
# CBC FrontBurner
"https://www.cbc.ca/podcasting/includes/frontburner.xml",
# Majority Report AM Quickie
"https://feeds.fans.fm/5883fe04-e11e-4578-a018-3b93ddfb5723.xml"
# CBC FrontBurner
"https://www.cbc.ca/podcasting/includes/frontburner.xml",
# Majority Report AM Quickie
"https://feeds.fans.fm/5883fe04-e11e-4578-a018-3b93ddfb5723.xml"
);
# Player command (must accept stream as STDIN)
@ -28,14 +28,14 @@ my $player = "> /tmp/fifo.mp3 & omxplayer /tmp/fifo.mp3";
# Multiple feeds can be given as CLI arguments instead
my @feeds;
if (scalar @ARGV) {
foreach (@ARGV) {
push @feeds, $_;
}
foreach (@ARGV) {
push @feeds, $_;
}
}
# Only use default feeds if no CLI feeds were given
unless (scalar @feeds) {
@feeds = @default_feeds;
@feeds = @default_feeds;
}
# Local function to get date pattern provided as 'pubDate'
@ -48,36 +48,36 @@ my $xml = XML::Hash::XS->new(utf8 => 0, encoding => 'utf-8');
my @playlist;
# Go through each feed
foreach my $url (@feeds) {
# Ensure that it's actual an XML link
next unless $url =~ m#^https?://.*\.xml$#;
# Ensure it is fetched okay
my $raw = $ua->get("$url")->content() || next;
# Ensure it is parsed okay
my $xml_hash = $xml->xml2hash($raw) || next;
# Ensure that it's actual an XML link
next unless $url =~ m#^https?://.*\.xml$#;
# Ensure it is fetched okay
my $raw = $ua->get("$url")->content() || next;
# Ensure it is parsed okay
my $xml_hash = $xml->xml2hash($raw) || next;
# Collect all episodes published today
foreach my $item (@{$xml_hash->{'channel'}->{'item'}}) {
if ($item->{'pubDate'} =~ m/$today/) {
# Add any found to playlist
push @playlist, $item->{'enclosure'}->{'url'};
}
# Collect all episodes published today
foreach my $item (@{$xml_hash->{'channel'}->{'item'}}) {
if ($item->{'pubDate'} =~ m/$today/) {
# Add any found to playlist
push @playlist, $item->{'enclosure'}->{'url'};
}
}
}
# Fetch each item and pass it to player via STDIN
foreach (@playlist) {
# Uncomment the following to print the media URL
print $_ . "\n";
system("curl -NL $_ $player");
# Uncomment the following to print the media URL
print $_ . "\n";
system("curl -NL $_ $player");
}
unlink("/tmp/fifo.mp3");
sub get_date
{
my ($second, $minute, $hour, $day, $month, $year) = localtime(time);
my @months = (
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
);
return $day . ' ' . $months[$month] . ' ' . ($year+1900);
my ($second, $minute, $hour, $day, $month, $year) = localtime(time);
my @months = (
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
);
return $day . ' ' . $months[$month] . ' ' . ($year+1900);
}

View File

@ -13,41 +13,41 @@ my $lat_lon = fetch_lat_lon($location);
my $pid = fork;
unless ($pid) {
open(my $fh, ">", $ENV{HOME}."/.spool/gammastep.pid");
print $fh $$;
close($fh);
open($fh, ">", $ENV{HOME}."/.spool/gammastep.status");
print $fh 1;
close($fh);
open(my $fh, ">", $ENV{HOME}."/.spool/gammastep.pid");
print $fh $$;
close($fh);
open($fh, ">", $ENV{HOME}."/.spool/gammastep.status");
print $fh 1;
close($fh);
open STDIN, '/dev/null';
open STDOUT, '>>/dev/null';
open STDERR, '>>/dev/null';
open STDIN, '/dev/null';
open STDOUT, '>>/dev/null';
open STDERR, '>>/dev/null';
if (! -e "/run/.containerenv" && ! -e "/.dockerenv" ) {
exec "exec /bin/distrobox-enter -n debian12 -- gammastep -l $lat_lon -b 0.7:0.3";
} else {
exec "exec gammastep -l $lat_lon -b 0.7:0.3";
}
if (! -e "/run/.containerenv" && ! -e "/.dockerenv" ) {
exec "exec /bin/distrobox-enter -n debian12 -- gammastep -l $lat_lon -b 0.7:0.3";
} else {
exec "exec gammastep -l $lat_lon -b 0.7:0.3";
}
}
sub fetch_lat_lon
{
my ($location) = shift;
my ($location) = shift;
my $ua = LWP::UserAgent->new();
my $json = JSON::XS->new();
my $ua = LWP::UserAgent->new();
my $json = JSON::XS->new();
my $raw = $ua->get($location)->content();
my $raw = $ua->get($location)->content();
if (defined $raw) {
my $decoded = $json->decode($raw);
if (defined $decoded->{lat} && defined $decoded->{lon}) {
return "$decoded->{lat}:$decoded->{lon}";
}
if (defined $raw) {
my $decoded = $json->decode($raw);
if (defined $decoded->{lat} && defined $decoded->{lon}) {
return "$decoded->{lat}:$decoded->{lon}";
}
sleep 5;
return fetch_lat_lon($ua, $json, $location);
}
sleep 5;
return fetch_lat_lon($ua, $json, $location);
}
exit;

View File

@ -6,8 +6,8 @@ echo "Available Distrobox sessions, with matching gnome-terminal profiles, are:"
echo ""
distrobox list | grep -v 'IMAGE' | cut -d '|' -f 2
for i in 10 9 8 7 6 5 4 3 2 1; do
printf "\rExitting in $i ..."
sleep 1
printf "\rExitting in $i ..."
sleep 1
done
echo ""
exit

View File

@ -4,25 +4,25 @@ LAYOUT=`cat ~/.config/screenlayout/i3.current`
MIDDLE="eDP-1"
if [[ $LAYOUT == 'home' ]]; then
RIGHT="DP-2-2"
LEFT="DP-2-1"
RIGHT="DP-2-2"
LEFT="DP-2-1"
elif [[ $LAYOUT == 'work' ]]; then
RIGHT="DP-2-2"
LEFT="DP-2-1"
RIGHT="DP-2-2"
LEFT="DP-2-1"
elif [[ $LAYOUT == '3' ]]; then
MIDDLE="DP-2-2"
LEFT="DP-2-1"
RIGHT="eDP-1"
MIDDLE="DP-2-2"
LEFT="DP-2-1"
RIGHT="eDP-1"
else
echo "No external displays connected"
echo "No external displays connected"
fi
if [[ $1 == 'right' ]]; then
i3 move workspace to output $RIGHT
i3 move workspace to output $RIGHT
elif [[ $1 == 'middle' ]]; then
i3 move workspace to output $MIDDLE
i3 move workspace to output $MIDDLE
elif [[ $1 == 'left' ]]; then
i3 move workspace to output $LEFT
i3 move workspace to output $LEFT
else
echo "Invalid direction. Requires either 'up', 'left', or 'middle'"
echo "Invalid direction. Requires either 'up', 'left', or 'middle'"
fi

View File

@ -4,7 +4,7 @@ ROFI=$(pgrep -xc rofi | cut -b 1)
echo $ROFI
if [[ "$ROFI" -eq "0" ]]; then
rofi -config /home/jpm/.config/rofi/config.rasi -theme /home/jpm/.config/rofi/sidebar.rasi -show drun -lines 20
rofi -config /home/jpm/.config/rofi/config.rasi -theme /home/jpm/.config/rofi/sidebar.rasi -show drun -lines 20
else
killall rofi 2&>1 /dev/null
killall rofi 2&>1 /dev/null
fi

View File

@ -5,25 +5,25 @@
res=$(echo "Connection|John.Me.tz|MailCleaner|Disconnect|Restart" | rofi -sep "|" -dmenu -i -p 'P ' "" -columns 9 -width 45 -l 1 -config /home/jpm/.config/rofi/config.rasi -theme /home/jpm/.config/rofi/sidebar -hide-scrollbar -eh 1 -location 0 -auto-select -no-fullscreen)
if [ $res = "Connection" ]; then
/usr/bin/uxterm -e 'sudo /usr/bin/nmtui'
/usr/bin/uxterm -e 'sudo /usr/bin/nmtui'
elif [ $res = "John.Me.tz" ]; then
sudo /usr/bin/systemctl stop openvpn-client@mailcleaner
sudo /usr/bin/systemctl restart wg-quick@wg0
sudo /usr/bin/systemctl stop openvpn-client@mailcleaner
sudo /usr/bin/systemctl restart wg-quick@wg0
elif [ $res = "MailCleaner" ]; then
sudo /usr/bin/systemctl stop wg-quick@wg0
sudo /usr/bin/systemctl restart openvpn-client@mailcleaner
sudo /usr/bin/systemctl stop wg-quick@wg0
sudo /usr/bin/systemctl restart openvpn-client@mailcleaner
elif [ $res = "Disconnect" ]; then
sudo /usr/bin/systemctl stop openvpn-client@mailcleaner
sudo /usr/bin/systemctl stop wg-quick@wg0
sudo /usr/bin/systemctl stop openvpn-client@mailcleaner
sudo /usr/bin/systemctl stop wg-quick@wg0
elif [ $res = "Restart" ]; then
if [ "`ip addr show wg0 2> /dev/null`" != "" ]; then
sudo /usr/bin/systemctl restart wg-quick@wg0
fi
if [ "`ip addr show tun0 2> /dev/null`" != "" ]; then
sudo /usr/bin/systemctl restart openvpn-client@mailcleaner
fi
if [ "`ip addr show wg0 2> /dev/null`" != "" ]; then
sudo /usr/bin/systemctl restart wg-quick@wg0
fi
if [ "`ip addr show tun0 2> /dev/null`" != "" ]; then
sudo /usr/bin/systemctl restart openvpn-client@mailcleaner
fi
else
exit
exit
fi
# Waybar sometimes doesn't update with the VPN IP, for whatever reason. Restart it.

View File

@ -1,7 +1,7 @@
#!/bin/bash
INPUT="$(rofi -dmenu -i -p 'Kodi:' "" -columns 1 -rows 7 -width 32 -l 1 \
-theme /home/jpm/.config/rofi/sidebar.rasi -hide-scrollbar -eh 1 -location \
0 -padding 12 -opacity 100)"
-theme /home/jpm/.config/rofi/sidebar.rasi -hide-scrollbar -eh 1 -location \
0 -padding 12 -opacity 100)"
/home/jpm/scripts/send-to-kodi.sh $INPUT 2>&1 /dev/null

View File

@ -10,32 +10,32 @@ rofi -sep "|" -dmenu -i -p 'P ' "" -columns 1 -rows 1 -width 45 -l 1 -config \
echo $res > /home/jpm/.last_ssh_shortcut
if [ $res = "john.me.tz" ]; then
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs w'
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs w'
elif [ $res = "root@john.me.tz" ]; then
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs r'
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs r'
elif [ $res = "shb.ng" ]; then
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs s'
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs s'
elif [ $res = "kipary.fastnet.ch" ]; then
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs d'
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs d'
elif [ $res = "camera.lan.john.me.tz" ]; then
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs c'
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs c'
elif [ $res = "hud.lan.john.me.tz" ]; then
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs h'
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs h'
elif [ $res = "media.lan.john.me.tz" ]; then
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs m'
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs m'
elif [ $res = "programmer.lan.john.me.tz" ]; then
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs p'
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs p'
elif [ $res = "t470s.lan.john.me.tz" ]; then
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs l'
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs l'
elif [ $res = "therm.lan.john.me.tz" ]; then
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs t'
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs t'
elif [ $res = "vm.lan.john.me.tz" ]; then
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs v'
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs v'
elif [ $res = "light.lan.john.me.tz" ]; then
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs light'
/usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs light'
elif [ $res = "mac.lan.john.me.tz" ]; then
/usr/bin/gvncviewer 192.168.2.10 >> /home/jpm/macos
/usr/bin/gvncviewer 192.168.2.10 >> /home/jpm/macos
elif [ $res = "AndroidUSB" ]; then
/usr/bin/scrcpy
/usr/bin/scrcpy
fi
exit 0

View File

@ -4,13 +4,13 @@
res=$(echo "Rotate 0 (Normal)|Rotate 90 (Keyboard right)|Rotate 180 (Upside-down)|Rotate 270 (Keyborad left)" | rofi -sep "|" -dmenu -i -p 'P ' "" -columns 9 -width 45 -l 1 -config /home/jpm/.config/rofi/config.rasi -theme /home/jpm/.config/rofi/sidebar.rasi -hide-scrollbar -eh 1 -location 0 -auto-select -no-fullscreen)
if [[ $res == "Rotate 0 (Normal)" ]]; then
swaymsg output eDP-1 transform 0
swaymsg output eDP-1 transform 0
elif [[ $res == "Rotate 90 (Keyboard right)" ]]; then
swaymsg output eDP-1 transform 90
swaymsg output eDP-1 transform 90
elif [[ $res == "Rotate 180 (Upside-down)" ]]; then
swaymsg output eDP-1 transform 180
swaymsg output eDP-1 transform 180
elif [[ $res == "Rotate 270 (Keyboard left)" ]]; then
swaymsg output eDP-1 transform 270
swaymsg output eDP-1 transform 270
else
exit
exit
fi

View File

@ -3,10 +3,10 @@
RUNNING=$(pgrep yubioath-deskto)
if [ "$RUNNING" ]; then
kill $RUNNING
sudo systemctl stop pcscd.socket
sudo systemctl restart pcscd.service
sudo systemctl start pcscd.socket
kill $RUNNING
sudo systemctl stop pcscd.socket
sudo systemctl restart pcscd.service
sudo systemctl start pcscd.socket
fi
QT_QPA_PLATFORMTHEME=qt5ct QT_QPA_PLATFORM=wayland QT_PLUGIN_PATH=/usr/lib/qt/plugins /usr/bin/yubioath-desktop &

View File

@ -9,10 +9,10 @@ sed -e 's/^\([0-9]*\)\t*\(.*\)/\2 \1/' |
rofi -dmenu -config ~/.config/rofi/sidebar.rasi | {
read -r
read -r
id=`echo $REPLY | rev | cut -d' ' -f1 | rev`
id=`echo $REPLY | rev | cut -d' ' -f1 | rev`
swaymsg "[con_id=$id]" focus
swaymsg "[con_id=$id]" focus
}

View File

@ -12,74 +12,74 @@ SUSPEND_TIMEOUT=3600 # one hour
function usage()
{
echo "usage: $0 <option>
start - Initialize 'swayidle' script. This should be declared in Sway config.
stop - Kill 'swayidle' script. Consider idle-inhibitor instead.
fade - First idle action. Fades all windows to show background.
unfade - Restore opacity for faded windows.
dim - Reduce display brightness to minimum.
undim - Restore brightness to level prior to 'dim'.
lock - Mark as inactive and start 'swaylock'.
unlock - (Run upon unlock) Mark as active again.
sleep - Disable displays, but continue background processes.
wake - Re-enable displays.
hibernate - Hibernate.
help - This message."
exit
echo "usage: $0 <option>
start - Initialize 'swayidle' script. This should be declared in Sway config.
stop - Kill 'swayidle' script. Consider idle-inhibitor instead.
fade - First idle action. Fades all windows to show background.
unfade - Restore opacity for faded windows.
dim - Reduce display brightness to minimum.
undim - Restore brightness to level prior to 'dim'.
lock - Mark as inactive and start 'swaylock'.
unlock - (Run upon unlock) Mark as active again.
sleep - Disable displays, but continue background processes.
wake - Re-enable displays.
hibernate - Hibernate.
help - This message."
exit
}
if [ -z $1 ]; then
echo "Missing argument"
usage
echo "Missing argument"
usage
elif [ $1 == "-h" ] || [ $1 == "--help" ] || [ $1 == "help" ]; then
usage
usage
elif [ $1 == "start" ]; then
swayidle -w \
timeout $FADE_TIMEOUT "$0 fade" \
resume "$0 unfade" \
timeout $DIM_TIMEOUT "$0 dim" \
resume "$0 undim" \
timeout $LOCK_TIMEOUT "$0 lock" \
resume "$0 unlock" \
timeout $DPMS_TIMEOUT "$0 sleep" \
resume "$0 wake" \
timeout $SUSPEND_TIMEOUT "$0 hibernate"
swayidle -w \
timeout $FADE_TIMEOUT "$0 fade" \
resume "$0 unfade" \
timeout $DIM_TIMEOUT "$0 dim" \
resume "$0 undim" \
timeout $LOCK_TIMEOUT "$0 lock" \
resume "$0 unlock" \
timeout $DPMS_TIMEOUT "$0 sleep" \
resume "$0 wake" \
timeout $SUSPEND_TIMEOUT "$0 hibernate"
elif [ $1 == "stop" ]; then
pkill swayidle
pkill swayidle
elif [ $1 == "fade" ]; then
if [ ! -e $HOME/.spool/sway-hidden ]; then
kill -USR2 `cat $HOME/.spool/sway-transparency`
fi
if [ ! -e $HOME/.spool/sway-hidden ]; then
kill -USR2 `cat $HOME/.spool/sway-transparency`
fi
elif [ $1 == "unfade" ]; then
if [ -e $HOME/.spool/sway-hidden ]; then
kill -USR2 `cat $HOME/.spool/sway-transparency`
fi
if [ -e $HOME/.spool/sway-hidden ]; then
kill -USR2 `cat $HOME/.spool/sway-transparency`
fi
elif [ $1 == "dim" ]; then
echo $($HOME/scripts/thinkpad/blc.pl %) > $BLFILE
$HOME/scripts/thinkpad/blc.pl = 1 &>-
echo $($HOME/scripts/thinkpad/blc.pl %) > $BLFILE
$HOME/scripts/thinkpad/blc.pl = 1 &>-
elif [ $1 == "undim" ]; then
$HOME/scripts/thinkpad/blc.pl = `cat $BLFILE` &>-
$HOME/scripts/thinkpad/blc.pl = `cat $BLFILE` &>-
elif [ $1 == "lock" ]; then
# Change nick to AFK
#ssh jpm@john.me.tz -i /home/jpm/.ssh/no_pass -t \
#'screen -S irssi -X stuff "/nick jpmAFK^M"'
:
# Change nick to AFK
#ssh jpm@john.me.tz -i /home/jpm/.ssh/no_pass -t \
#'screen -S irssi -X stuff "/nick jpmAFK^M"'
:
elif [ $1 == "unlock" ]; then
# Change nick to AFK
#ssh jpm@john.me.tz -i /home/jpm/.ssh/no_pass -t \
#'screen -S irssi -X stuff "/nick jpm^M"'
:
# Change nick to AFK
#ssh jpm@john.me.tz -i /home/jpm/.ssh/no_pass -t \
#'screen -S irssi -X stuff "/nick jpm^M"'
:
elif [ $1 == "sleep" ]; then
for i in `cat $OPFILE`; do swaymsg "output $i dpms off"; done
for i in `cat $OPFILE`; do swaymsg "output $i dpms off"; done
elif [ $1 == "wake" ]; then
/home/jpm/scripts/sway/displays.pl
/home/jpm/scripts/sway/displays.pl
elif [ $1 == "hibernate" ]; then
if [ -e $NOHIBERNATE ]; then
::
else
sudo systemctl start hibernate.target
fi
if [ -e $NOHIBERNATE ]; then
::
else
sudo systemctl start hibernate.target
fi
else
echo "Invalid argument: $1"
usage
echo "Invalid argument: $1"
usage
fi

View File

@ -11,15 +11,15 @@ my $now = sprintf("%.0f",($start->[0]*1000) + ($start->[1]/1000));
my $end = $now + 30000;
while ($now < $end) {
my $remaining = ($end - $now);
my $notification = Gtk2::Notify::new('Idle', sprintf("%.0f",($remaining/1000)), '', "status_lock");
$notification->set_hint_string('x-canonical-private-synchronous','idle');
$notification->set_urgency('NOTIFY_URGENCY_LOW');
$notification->set_hint_int32('value',($remaining/300));
$notification->set_timeout(150);
$notification->show();
usleep(100);
$now = utime( undef, undef );
$start = [gettimeofday];
$now = sprintf("%.0f",($start->[0]*1000) + ($start->[1]/1000));
my $remaining = ($end - $now);
my $notification = Gtk2::Notify::new('Idle', sprintf("%.0f",($remaining/1000)), '', "status_lock");
$notification->set_hint_string('x-canonical-private-synchronous','idle');
$notification->set_urgency('NOTIFY_URGENCY_LOW');
$notification->set_hint_int32('value',($remaining/300));
$notification->set_timeout(150);
$notification->show();
usleep(100);
$now = utime( undef, undef );
$start = [gettimeofday];
$now = sprintf("%.0f",($start->[0]*1000) + ($start->[1]/1000));
}

View File

@ -1,5 +1,5 @@
#!/bin/bash
for i in `seq 0 30`; do
notify-send -a 'swayidle' -t 999 "Sleeping" $(expr 30 - $i); sleep 1
notify-send -a 'swayidle' -t 999 "Sleeping" $(expr 30 - $i); sleep 1
done

View File

@ -19,63 +19,63 @@ my $root = $json->decode($raw);
my $display = $root->{focus}->[0];
my ($workspace, $term_id, $term_ws);
foreach my $d (@{$root->{nodes}}) {
# If both the current workspace and terminal have been found
# nothing else to look for
if (defined($workspace) && defined($term_id)) {
# If both the current workspace and terminal have been found
# nothing else to look for
if (defined($workspace) && defined($term_id)) {
last;
# If the display from this iteration of the loop is in focus
# look for the active workspace
} elsif ($d->{id} eq $display) {
foreach my $w (@{$d->{nodes}}) {
# Again, if both found, skip
if (defined($workspace) && defined($term_id)) {
last;
# If the display from this iteration of the loop is in focus
# look for the active workspace
} elsif ($d->{id} eq $display) {
foreach my $w (@{$d->{nodes}}) {
# Again, if both found, skip
if (defined($workspace) && defined($term_id)) {
last;
# Otherwise if the current workspace is active, mark it
} elsif ($w->{id} eq $d->{focus}->[0]) {
$workspace = $w->{name};
}
# In any case, look for the terminal app
foreach my $n (@{$w->{floating_nodes}}) {
if ($n->{name} eq $term) {
$term_id = $n->{id};
$term_ws = $w->{name};
last;
}
}
}
# All other displays only need to be quickly searched for the term_id
} else {
foreach my $w (@{$d->{nodes}}) {
if (defined($term_id)) {
last;
}
foreach my $n (@{$w->{floating_nodes}}) {
if ($n->{name} eq $term) {
$term_id = $n->{id};
$term_ws = $w->{name};
last;
}
}
# Otherwise if the current workspace is active, mark it
} elsif ($w->{id} eq $d->{focus}->[0]) {
$workspace = $w->{name};
}
# In any case, look for the terminal app
foreach my $n (@{$w->{floating_nodes}}) {
if ($n->{name} eq $term) {
$term_id = $n->{id};
$term_ws = $w->{name};
last;
}
}
}
# All other displays only need to be quickly searched for the term_id
} else {
foreach my $w (@{$d->{nodes}}) {
if (defined($term_id)) {
last;
}
foreach my $n (@{$w->{floating_nodes}}) {
if ($n->{name} eq $term) {
$term_id = $n->{id};
$term_ws = $w->{name};
last;
}
}
}
}
}
print "Active workspace = $workspace\n"
. "Terminal ID = $term_id\n"
. "Terminal WS = $term_ws\n";
. "Terminal ID = $term_id\n"
. "Terminal WS = $term_ws\n";
# If there is no terminal found, spawn one
if (!defined($term_id)) {
print "No term running, starting one\n";
exec $term
print "No term running, starting one\n";
exec $term
# If the current workspace is known and terminal isn't on it, bring and focus
} elsif ($workspace != $term_ws) {
print "Term not on current workspace, bringing it\n";
`swaymsg "[con_id=$term_id]" move workspace $workspace`;
`swaymsg "[con_id=$term_id]" focus`;
`swaymsg "[con_id=$term_id]" sticky enable`;
print "Term not on current workspace, bringing it\n";
`swaymsg "[con_id=$term_id]" move workspace $workspace`;
`swaymsg "[con_id=$term_id]" focus`;
`swaymsg "[con_id=$term_id]" sticky enable`;
# Otherwise hide it from whereever it is
} else {
print "Term is on current workspace or lost, moving to $hidden\n";
`swaymsg "[con_id=$term_id]" sticky disable`;
`swaymsg "[con_id=$term_id]" move workspace $hidden`;
print "Term is on current workspace or lost, moving to $hidden\n";
`swaymsg "[con_id=$term_id]" sticky disable`;
`swaymsg "[con_id=$term_id]" move workspace $hidden`;
}

View File

@ -4,45 +4,45 @@
# Determine if Sway or i3
if [ -z ${SWAYSOCK+x} ]; then
WM="i3"
WM="i3"
else
WM="sway"
WM="sway"
fi
if [[ $WM == 'i3' ]]; then
res=$(printf "⚿ Lock|↩ Logout|↻ Reload i3|↹ Restart i3|↯ Hibernate|🡙 Reboot|⏻ Shutdown" | rofi -sep "|" -dmenu -i -p 'Power: ' "" -columns 1 -rows 7 -width 32 -l 1 -theme /home/jpm/.config/rofi/sidebar.rasi -hide-scrollbar -eh 1 -location 0 -padding 12 -opacity 100 -auto-select -no-fullscreen)
res=$(printf "⚿ Lock|↩ Logout|↻ Reload i3|↹ Restart i3|↯ Hibernate|🡙 Reboot|⏻ Shutdown" | rofi -sep "|" -dmenu -i -p 'Power: ' "" -columns 1 -rows 7 -width 32 -l 1 -theme /home/jpm/.config/rofi/sidebar.rasi -hide-scrollbar -eh 1 -location 0 -padding 12 -opacity 100 -auto-select -no-fullscreen)
else
res=$(printf "⚿ Lock\n🖵 Toggle Displays\n⚿ Yubico Authenticator\n↻ Reload Sway\n↻ Reload Waybar\n↩ Logout\n↯ Hibernate\n🡙 Reboot\n⏻ Shutdown" | wofi -I -s $HOME/.dotfiles/wofi/style.css -c $HOME/.dotfiles/wofi/sidebar --show dmenu
)
res=$(printf "⚿ Lock\n🖵 Toggle Displays\n⚿ Yubico Authenticator\n↻ Reload Sway\n↻ Reload Waybar\n↩ Logout\n↯ Hibernate\n🡙 Reboot\n⏻ Shutdown" | wofi -I -s $HOME/.dotfiles/wofi/style.css -c $HOME/.dotfiles/wofi/sidebar --show dmenu
)
fi
if [ "$res" == "⚿ Lock" ]; then
${WM}lock -c 000000
${WM}lock -c 000000
elif [ "$res" == "↩ Logout" ]; then
# Prevent auto-login
rm /home/jpm/.config/last_login_gui
${WM} exit
# Prevent auto-login
rm /home/jpm/.config/last_login_gui
${WM} exit
elif [ "$res" == "🖵 Toggle Displays" ]; then
/home/jpm/scripts/sway/toggle_outputs.sh
/home/jpm/scripts/sway/toggle_outputs.sh
elif [ "$res" == "⚿ Yubico Authenticator" ]; then
/home/jpm/scripts/rofi/rofi-yubioath.sh
/home/jpm/scripts/rofi/rofi-yubioath.sh
elif [ "$res" == "↻ Reload i3" ]; then
i3 reload
i3 reload
elif [ "$res" == "↹ Restart i3" ]; then
i3 restart
i3 restart
elif [ "$res" == "↻ Reload Sway" ]; then
sway reload
/home/jpm/scripts/sway/displays.pl
sway reload
/home/jpm/scripts/sway/displays.pl
elif [ "$res" == "↻ Reload Waybar" ]; then
# Need to integrate with sway/displays.pl for alternative outputs
/home/jpm/scripts/sway/displays.pl -w
# Need to integrate with sway/displays.pl for alternative outputs
/home/jpm/scripts/sway/displays.pl -w
elif [ "$res" == "🡙 Reboot" ]; then
rm $SSH_AUTH_SOCK
sudo systemctl reboot -i
rm $SSH_AUTH_SOCK
sudo systemctl reboot -i
elif [ "$res" == "⏻ Shutdown" ]; then
rm $SSH_AUTH_SOCK
sudo systemctl poweroff -i
rm $SSH_AUTH_SOCK
sudo systemctl poweroff -i
elif [ "$res" == "↯ Hibernate" ]; then
sudo systemctl hibernate -i
sudo systemctl hibernate -i
fi
exit 0

View File

@ -3,7 +3,7 @@
PID=`cat /tmp/$USER-wallpaper.pid`
if [ $PID ]; then
kill -SIGUSR1 $PID
kill -SIGUSR1 $PID
else
systemctl --user restart wallpapers.service
systemctl --user restart wallpapers.service
fi

View File

@ -3,9 +3,9 @@
CURRENT=`cat /home/jpm/.config/last_display`
if [ "$CURRENT" == "detached" ]; then
/home/jpm/scripts/sway/displays.pl TV
/home/jpm/scripts/sway/displays.pl TV
else
/home/jpm/scripts/sway/displays.pl detached
/home/jpm/scripts/sway/displays.pl detached
fi
pkill mako
mako &

View File

@ -12,368 +12,314 @@ use lib "$ENV{HOME}/perl5/lib/perl5";
$ENV{PWD} = '/tmp' unless (defined($ENV{PWD}));
use constant ERROR => {
LOG_EMERG => 8,
LOG_ALERT => 7,
LOG_CRIT => 6,
LOG_ERR => 5,
LOG_WARNING => 4,
LOG_NOTICE => 3,
LOG_INFO => 2,
LOG_DEBUG => 1
LOG_EMERG => 8,
LOG_ALERT => 7,
LOG_CRIT => 6,
LOG_ERR => 5,
LOG_WARNING => 4,
LOG_NOTICE => 3,
LOG_INFO => 2,
LOG_DEBUG => 1
};
our @e;
sub usage()
{
my $self = shift;
print("$0 [output(s)] [-d|--daemon]\n
my $self = shift;
print("$0 [output(s)] [-d|--daemon]\n
Sets a wallpaper by cropping an appropriate sized section of a larger image.\n
All arguments other than the below are assumed to be output names, as defined
in my sway/displays.pl script. If no outputs are provided, all available that
are currently enabled will be set.\n
--path=<path> Path to wallpaper directory.
-p <path> Default: $ENV{HOME}/wallpapers\n
--daemon=N Configures the wallpaper to be periodically rotated for all
-d N of the given outputs. N indicates the number of seconds between
each rotation, if provided (default: 300).\n
--nocrop Don't crop a selection from the image. Instead, pass the whole
-n image to swaybg and let it handle the scaling\n
--path=<path> Path to wallpaper directory.
-p <path> Default: $ENV{HOME}/wallpapers\n
--daemon=N Configures the wallpaper to be periodically rotated for all
-d N of the given outputs. N indicates the number of seconds between
each rotation, if provided (default: 300).\n
--nocrop Don't crop a selection from the image. Instead, pass the whole
-n image to swaybg and let it handle the scaling\n
--verbose=N Define minimum log level. Counting from 1: LOG_DEBUG, LOG_INFO,
-v N LOG_NOTICE, LOG_WARNING, LOG_ERR, LOG_CRIT, LOG_ALERT, LOG_EMERG
Default: 5; If provided without a value for N then all (1).
-v N LOG_NOTICE, LOG_WARNING, LOG_ERR, LOG_CRIT, LOG_ALERT, LOG_EMERG
Default: 5; If provided without a value for N then all (1).
--recursive=N Enumerate images recursively through directories in the path.
-r N N indicates the directory depth, unlimited if no N is provided.
--help This menu
-r N N indicates the directory depth, unlimited if no N is provided.
--help This menu
-h\n
You can send SIGUSR1 to force the daemon to reload immediately. Rotation timer
will be reset.\n");
exit(0);
exit(0);
}
sub new
{
my ($class, %args) = @_;
my ($class, %args) = @_;
use AnyEvent::Sway;
$args{ipc} = AnyEvent::Sway->new();
use Image::Magick;
$args{im} = Image::Magick->new();
$args{error} = ();
use AnyEvent::Sway;
$args{ipc} = AnyEvent::Sway->new();
use Image::Magick;
$args{im} = Image::Magick->new();
$args{error} = ();
$args{pidfile} = "/tmp/$ENV{USER}-wallpaper.pid";
$args{pidfile} = "/tmp/$ENV{USER}-wallpaper.pid";
return bless { %args };
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
{
my $self = shift;
my $o = $self->{ipc}->get_outputs->recv() || $self->do_log('LOG_WARNING',"Failed to query 'get_outputs'");
die "No outputs detected.\n" unless (scalar(@$o) > 0);
return $o;
my $self = shift;
my $o = $self->{ipc}->get_outputs->recv() || $self->do_log('LOG_WARNING',"Failed to query 'get_outputs'");
die "No outputs detected.\n" unless (scalar(@$o) > 0);
return $o;
}
# returns the same as above but with the 'name' as a hash key for easier lookup
sub get_active
{
my $self = shift;
if (defined($self->{outputs}) && scalar($self->{outputs})) {
my %active = ();
foreach my $o (@{$self->{outputs}}) {
my $name;
my %details;
next unless ($o->{active});
$active{$o->{name}} = ();
foreach (keys(%$o)) {
$active{$o->{name}}->{$_} = $o->{$_} unless ($_ eq 'name');
}
}
$self->do_log('LOG_WARNING',"No outputs detected.") unless (scalar(keys(%active)));
return \%active;
} else {
print "You haven't initialized get_outputs";
$self->do_log('LOG_WARNING',"Output list not defined yet. Try 'get_outputs()' first");
return \{};
my $self = shift;
if (defined($self->{outputs}) && scalar($self->{outputs})) {
my %active = ();
foreach my $o (@{$self->{outputs}}) {
my $name;
my %details;
next unless ($o->{active});
$active{$o->{name}} = ();
foreach (keys(%$o)) {
$active{$o->{name}}->{$_} = $o->{$_} unless ($_ eq 'name');
}
}
$self->do_log('LOG_WARNING',"No outputs detected.") unless (scalar(keys(%active)));
return \%active;
} else {
print "You haven't initialized get_outputs";
$self->do_log('LOG_WARNING',"Output list not defined yet. Try 'get_outputs()' first");
return \{};
}
}
sub clean
{
my $self = shift;
if (-e $self->{pidfile}) {
open (my $fh, '<', $self->{pidfile});
my $p = <$fh>;
close($fh);
chomp $p;
kill($p);
unlink($self->{pidfile});
}
my $self = shift;
if (-e $self->{pidfile}) {
open (my $fh, '<', $self->{pidfile});
my $p = <$fh>;
close($fh);
chomp $p;
kill($p);
unlink($self->{pidfile});
}
}
sub dig_dirs
{
my $self = shift;
my $paths_ref = shift;
my $path = shift;
my $depth = shift || 0;
unless (-e $path) {
return(undef);
}
my $self = shift;
my $paths_ref = shift;
my $path = shift;
my $depth = shift || 0;
unless (-e $path) {
return(undef);
}
if ($path =~ m/\/\.\.?$/) {
return;
}
foreach (glob("$path/*"), glob("$path/.*")) {
if ($path =~ m/\/\.\.?$/) {
return;
}
foreach (glob("$path/*"), glob("$path/.*")) {
if ($path =~ m/\/\.\.?$/) {
next();
} elsif (-l $_) {
push(@$paths_ref, $_);
} elsif (-d $_ && ($self->{recursive} == '-1' || $depth < $self->{recursive})) {
$self->dig_dirs($paths_ref,$_,$depth+1);
} else {
push(@$paths_ref, $_);
}
next();
} elsif (-l $_) {
push(@$paths_ref, $_);
} elsif (-d $_ && ($self->{recursive} == '-1' || $depth < $self->{recursive})) {
$self->dig_dirs($paths_ref,$_,$depth+1);
} else {
push(@$paths_ref, $_);
}
}
}
sub choose_image
{
my $self = shift;
my $self = shift;
my @i;
my $depth = 0;
my @w;
$self->dig_dirs(\@w,$self->{path});
return undef unless (scalar(@w));
$self->do_log("LOG_DEBUG", "Found ".scalar(@w)." files in $self->{path} up to depth $self->{recursive}");
foreach (@w) {
if (-d $_) {
$self->do_log("LOG_DEBUG", "Ignoring sub-directory $_");
next;
}
if ($_ =~ m/\.(png|jpg)$/) {
push(@i,$_);
}
my @i;
my $depth = 0;
my @w;
$self->dig_dirs(\@w,$self->{path});
return undef unless (scalar(@w));
$self->do_log("LOG_DEBUG", "Found ".scalar(@w)." files in $self->{path} up to depth $self->{recursive}");
foreach (@w) {
if (-d $_) {
$self->do_log("LOG_DEBUG", "Ignoring sub-directory $_");
next;
}
if ($_ =~ m/\.(png|jpg)$/) {
push(@i,$_);
}
}
return $i[rand(scalar(@i))] || return undef;
return $i[rand(scalar(@i))] || return undef;
}
sub crop
{
my $self = shift;
my $image = shift;
my $ow = shift;
my $oh = shift;
my $self = shift;
my $image = shift;
my $ow = shift;
my $oh = shift;
my $cropped = $image;
$cropped =~ s#^.*/([^/]*)\.([^\.]+)$#$self->{'path'}$1-cropped.$2#;
my $cropped = $image;
$cropped =~ s#^.*/([^/]*)\.([^\.]+)$#$self->{'path'}$1-cropped.$2#;
#$image = "/tmp/Pharma-out.png.jpg";
use Image::Magick;
my $im = Image::Magick->new();
die "$image is not readable" unless (-r $image);
my $ret = $im->Read($image);
return 0 if ($ret);
my ($iw, $ih) = $im->Get("columns", "rows");
$self->do_log("LOG_DEBUG", "Image has dimensions ${iw}x${ih}");
#$image = "/tmp/Pharma-out.png.jpg";
use Image::Magick;
my $im = Image::Magick->new();
die "$image is not readable" unless (-r $image);
my $ret = $im->Read($image);
return 0 if ($ret);
my ($iw, $ih) = $im->Get("columns", "rows");
$self->do_log("LOG_DEBUG", "Image has dimensions ${iw}x${ih}");
# Return full size if it is smaller in either dimension then the output
if ($iw <= $ow || $ih <= $oh) {
$self->do_log("LOG_DEBUG", "Not cropping because ${iw}x${ih} is smaller or equal to the output (${ow}x${oh}) in at least 1 dimension.");
return undef;
}
# Return full size if it is smaller in either dimension then the output
if ($iw <= $ow || $ih <= $oh) {
$self->do_log("LOG_DEBUG", "Not cropping because ${iw}x${ih} is smaller or equal to the output (${ow}x${oh}) in at least 1 dimension.");
return undef;
}
my ($x, $y);
$x = int(rand($iw-$ow));
$y = int(rand($ih-$oh));
my ($x, $y);
$x = int(rand($iw-$ow));
$y = int(rand($ih-$oh));
my $err = $im->Crop(geometry=>"${ow}x${oh}+${x}+${y}");
die "$err" if ($err);
$err = $im->Write($cropped);
die "$err" if ($err);
return $cropped if ( -e $cropped );
my $err = $im->Crop(geometry=>"${ow}x${oh}+${x}+${y}");
die "$err" if ($err);
$err = $im->Write($cropped);
die "$err" if ($err);
return $cropped if ( -e $cropped );
}
sub set_background
{
my $self = shift;
my $target = shift || return "No target or image provided";
my $cropped = shift || return "No image provided";
# TODO get fallback from javascript
my $cmd = "output $target background $cropped fill #000000";
$self->do_log("LOG_DEBUG", "Running $cmd\n");
my $ret = $self->{ipc}->message(0,$cmd)->recv;
if ($ret->[0]->{success}) {
$self->do_log("LOG_DEBUG", "Success!");
return undef;
}
return "Failed to run Sway IPC command '$cmd'";
my $self = shift;
my $target = shift || return "No target or image provided";
my $cropped = shift || return "No image provided";
# TODO get fallback from javascript
my $cmd = "output $target background $cropped fill #000000";
$self->do_log("LOG_DEBUG", "Running $cmd\n");
my $ret = $self->{ipc}->message(0,$cmd)->recv;
if ($ret->[0]->{success}) {
$self->do_log("LOG_DEBUG", "Success!");
return undef;
}
return "Failed to run Sway IPC command '$cmd'";
}
sub do_log
{
my $self = shift;
my $level = shift;
my $msg = shift;
my $die = shift || 0;
my $min = $self->{verbose} || 5;
my $self = shift;
my $level = shift;
my $msg = shift;
my $die = shift || 0;
my $min = $self->{verbose} || 5;
# 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): $!";
if ($die) {
$msg = '(FATAL) ' . $msg;
exit(1);
}
} else {
if (ERROR->{$level} >= $min) {
printf("%11s %s\n", $level, $msg);
}
}
# 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): $!";
if ($die) {
$self->clean();
exit(1);
$msg = '(FATAL) ' . $msg;
exit(1);
}
} else {
if (ERROR->{$level} >= $min) {
printf("%11s %s\n", $level, $msg);
}
}
if ($die) {
$self->clean();
exit(1);
}
}
sub run
{
my $self = shift;
$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
my @t = @{$self->{targets}} if (scalar(@{$self->{targets}}));
$self->do_log("LOG_DEBUG", "Removing inactive ouputs");
my $active = $self->get_active();
# If specific targets were not defined, use all active
unless (scalar(@t)) {
@t = keys(%$active);
push(@{$self->{error}}, "No target outputs") unless (scalar(@t));
my $self = shift;
$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();
# If specific targets were not defined, use all active
unless (scalar(@t)) {
@t = keys(%$active);
push(@{$self->{error}}, "No target outputs") unless (scalar(@t));
}
$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");
next;
}
$self->do_log("LOG_DEBUG", "Looping desired ouputs");
foreach my $target (@t) {
$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");
next;
}
$self->do_log("LOG_DEBUG", "Selecting image for $target");
my $image = $self->choose_image();
if (defined($image)) {
$self->do_log('LOG_DEBUG', "Selected $image");
if ( -r "$image" ) {
my $cropped;
if ($self->{crop}) {
$self->do_log('LOG_DEBUG',"Cropping image for '$target' using '$image'");
$cropped = $self->crop(
$image,
$active->{$target}->{rect}->{width},
$active->{$target}->{rect}->{height}
);
if ($cropped) {
} else {
# Create a tmp copy since it will be deleted later
# If PWD is the wallpaper path, make the tmp in /tmp
if ($self->{path} eq $ENV{PWD}) {
$cropped = $image;
$cropped =~ s%$ENV{PWD}%/tmp%;
# Else make the tmp in PWD
} else {
$cropped = '/'.$image;
$cropped =~ s%.*/([^/+])%$ENV{PWD}/$1%;
}
$self->do_log('LOG_DEBUG',"Creating copy of original: $cropped");
File::Copy::copy($image,$cropped) || $self->do_log('LOG_WARNING',"Failed to copy to $cropped: $!");
}
} else {
$self->do_log('LOG_DEBUG', "Cropping is disabled");
$cropped = $image;
}
$self->set_background($target,$cropped);
if ($self->{crop}) {
# Give swaybg a second, otherwise the file will be missing before it ends
sleep(1);
$self->do_log('LOG_DEBUG', "Deleting $cropped");
unlink($cropped) || $self->do_log("LOG_WARNING", "Failed to delete $cropped after setting: $!");
}
$self->do_log("LOG_DEBUG", "Selecting image for $target");
my $image = $self->choose_image();
if (defined($image)) {
$self->do_log('LOG_DEBUG', "Selected $image");
if ( -r "$image" ) {
my $cropped;
if ($self->{crop}) {
$self->do_log('LOG_DEBUG',"Cropping image for '$target' using '$image'");
$cropped = $self->crop(
$image,
$active->{$target}->{rect}->{width},
$active->{$target}->{rect}->{height}
);
if ($cropped) {
} else {
# Create a tmp copy since it will be deleted later
# If PWD is the wallpaper path, make the tmp in /tmp
if ($self->{path} eq $ENV{PWD}) {
$cropped = $image;
$cropped =~ s%$ENV{PWD}%/tmp%;
# Else make the tmp in PWD
} else {
$self->do_log("LOG_WARNING", "Failed to read $image");
$cropped = '/'.$image;
$cropped =~ s%.*/([^/+])%$ENV{PWD}/$1%;
}
$self->do_log('LOG_DEBUG',"Creating copy of original: $cropped");
File::Copy::copy($image,$cropped) || $self->do_log('LOG_WARNING',"Failed to copy to $cropped: $!");
}
} else {
$self->do_log("LOG_WARNING", "Failed to select image from $self->{path}");
$self->do_log('LOG_DEBUG', "Cropping is disabled");
$cropped = $image;
}
$self->set_background($target,$cropped);
if ($self->{crop}) {
# Give swaybg a second, otherwise the file will be missing before it ends
sleep(1);
$self->do_log('LOG_DEBUG', "Deleting $cropped");
unlink($cropped) || $self->do_log("LOG_WARNING", "Failed to delete $cropped after setting: $!");
}
} else {
$self->do_log("LOG_WARNING", "Failed to read $image");
}
} else {
$self->do_log("LOG_WARNING", "Failed to select image from $self->{path}");
}
}
}
################################################################################
# Collect arguments
################################################################################
my $wp = new("Wallpapers");