summaryrefslogtreecommitdiffstats
path: root/.local/bin/setwp
diff options
context:
space:
mode:
Diffstat (limited to '.local/bin/setwp')
-rwxr-xr-x.local/bin/setwp91
1 files changed, 44 insertions, 47 deletions
diff --git a/.local/bin/setwp b/.local/bin/setwp
index e5fce65..fa0d255 100755
--- a/.local/bin/setwp
+++ b/.local/bin/setwp
@@ -37,70 +37,67 @@ sub choose_wp
sub set_wp
{
my ($wp) = @_;
+ my $pid;
+ my $old_pid;
return 1 if !(-r $wp) || !(-f $wp);
- system(
- FEH_PATH,
- '--no-fehbg',
- '--image-bg',
- '#1d2021',
- '--bg-fill',
- $wp,
- '--bg-fill',
- $wp,
- '--bg-fill',
- $wp
- );
- return 0;
-}
-sub notify
-{
- system(
- 'notify-send',
- '-u',
- 'low',
- '-t',
- '2000',
- 'setwp',
- ' wp set'
- );
- return;
-}
-
-sub notify_error
-{
- system(
- 'notify-send',
- '-u',
- 'critical',
- '-t',
- '4000',
- 'setwp',
- ' Wallpaper does not exist or is not a valid file'
- );
- return;
+ if (defined $ENV{WAYLAND_DISPLAY}) {
+ $old_pid = `pidof wbg`;
+ chomp $old_pid;
+ $pid = fork();
+ if (not $pid) {
+ setsid();
+ exec("wbg", $wp);
+ } else {
+ sleep(1);
+ exec("kill", $old_pid);
+ }
+ }
+ else {
+ system(
+ FEH_PATH,
+ '--no-fehbg',
+ '--image-bg',
+ '#1d2021',
+ '--bg-fill',
+ $wp,
+ '--bg-fill',
+ $wp,
+ '--bg-fill',
+ $wp
+ );
+ }
+ return 0;
}
sub main
{
my $wp;
my $ret;
+ my $arg;
- if (@ARGV != 0 && -f $ARGV[0]) {
- $ret = set_wp($ARGV[0]);
+ $arg = 0;
+ if (@ARGV != 0 && $ARGV[0] eq '-nw') {
+ $arg = 1;
+ }
+ if (@ARGV != 0 && -f $ARGV[$arg]) {
+ $ret = set_wp($ARGV[$arg]);
}
- elsif (@ARGV != 0 && -d $ARGV[0]) {
- $wp = choose_wp(get_pool_files($ARGV[0]));
+ elsif (@ARGV != 0 && -d $ARGV[$arg]) {
+ $wp = choose_wp(get_pool_files($ARGV[$arg]));
$ret = set_wp($wp);
}
else {
$wp = choose_wp(get_pool_files(WP_POOL));
$ret = set_wp($wp);
}
- if (@ARGV == 0 || (@ARGV != 0 && $ARGV[0] ne "-nw")) {
- notify() if ($ret == 0);
- notify_error() if ($ret != 0);
+ if (@ARGV == 0 || (@ARGV != 0 && $ARGV[0] ne '-nw')) {
+ my $arg = fork();
+ if (not $arg) {
+ exec('herbe', 'wp set') if ($ret == 0);
+ exec('herbe', 'wp is not a valid file') if ($ret != 0);
+ }
}
return;
}