From d06ed5266f047b28faac530e477de28c5e23a634 Mon Sep 17 00:00:00 2001 From: John Mertz Date: Fri, 31 Dec 2021 11:57:58 -0500 Subject: [PATCH] Add fallback bg, fix missing args, hide waybar If no background arguement exists, use a fallback colour. If no scale or transform argument exists use 1 and 0. Toggle off waybar on start (I don't think this works properly) --- sway/displays.pl | 52 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/sway/displays.pl b/sway/displays.pl index 8a86095..5ddf8d4 100755 --- a/sway/displays.pl +++ b/sway/displays.pl @@ -86,6 +86,7 @@ my %configs = ( 'y' => 0, 'rotate' => 0, 'waybar' => 'bottom', + 'fallback' => '#000000' } }, 'stacked-laptop' => { @@ -96,7 +97,8 @@ my %configs = ( 'x' => 960, 'y' => 0, 'rotate' => 0, - 'waybar' => 'bottom' + 'waybar' => 'bottom', + 'fallback' => '#000000' }, 'HP-1' => { 'on' => 1, @@ -105,7 +107,8 @@ my %configs = ( 'x' => 1920, 'y' => 1200, 'rotate' => 0, - 'waybar' => 'top' + 'waybar' => 'top', + 'fallback' => '#000000' }, 'HP-2' => { 'on' => 0 @@ -117,7 +120,8 @@ my %configs = ( 'x' => 0, 'y' => 1200, 'rotate' => 0, - 'waybar' => 'bottom' + 'waybar' => 'bottom', + 'fallback' => '#000000' } }, 'stacked' => { @@ -128,7 +132,8 @@ my %configs = ( 'x' => 960, 'y' => 0, 'rotate' => 0, - 'waybar' => 'bottom' + 'waybar' => 'bottom', + 'fallback' => '#000000' }, 'HP-1' => { 'on' => 1, @@ -137,7 +142,8 @@ my %configs = ( 'x' => 1920, 'y' => 1200, 'rotate' => 0, - 'waybar' => 'top' + 'waybar' => 'top', + 'fallback' => '#000000' }, 'HP-2' => { 'on' => 1, @@ -146,7 +152,8 @@ my %configs = ( 'x' => 0, 'y' => 1200, 'rotate' => 0, - 'waybar' => 'top' + 'waybar' => 'top', + 'fallback' => '#000000' }, 'eDP-1' => { 'on' => 0 @@ -160,7 +167,8 @@ my %configs = ( 'x' => 0, 'y' => 225, 'rotate' => 270, - 'waybar' => 'top' + 'waybar' => 'top', + 'fallback' => '#000000' }, 'Sam' => { 'on' => 1, @@ -169,7 +177,8 @@ my %configs = ( 'x' => 1080, 'y' => 0, 'rotate' => 90, - 'waybar' => 'top' + 'waybar' => 'top', + 'fallback' => '#000000' }, 'HP-2' => { 'on' => 1, @@ -178,7 +187,8 @@ my %configs = ( 'x' => 2280, 'y' => 225, 'rotate' => 90, - 'waybar' => 'top' + 'waybar' => 'top', + 'fallback' => '#000000' }, 'LVDS' => { 'on' => 0, @@ -199,7 +209,7 @@ if ($hostname eq "yoga.lan.john.me.tz") { # Disable display from other laptop ######################################################################## -if ($ENV{'SSH_AUTH_SOCK'} eq '/home/jpm/.ssh/ssh-agent.yoga.lan.john.me.tz.sock') { +if ($ENV{'SSH_AUTH_SOCK'} eq '/home/jpm/.ssh/ssh-agent.sock') { foreach my $layout (keys %configs) { delete($configs{$layout}{'LVDS'}); } @@ -383,10 +393,14 @@ foreach my $out (keys %$on) { # If additional options are provided, add them to command if (defined $on->{$out}->{scale}) { $cmd .= " scale $on->{$out}->{scale}"; - } + } else { + $cmd .= " scale 1"; + } if (defined $on->{$out}->{rotate}) { $cmd .= " transform $on->{$out}->{rotate}"; - } + } else { + $cmd .= " transform 0"; + } if (defined $on->{$out}->{x} && defined $on->{$out}->{y}) { $cmd .= " position $on->{$out}->{x} $on->{$out}->{y}"; } @@ -396,9 +410,20 @@ foreach my $out (keys %$on) { $cmd .= " mode $on->{$out}->{width}x" . "$on->{$out}->{height}"; } + if (defined $on->{$out}->{bg} && + -f $on->{$out}->{bg}) + { + $cmd .= " bg $on->{$out}->{bg} fit"; + if (defined $on->{$out}->{fallback}) { + $cmd .= " $on->{$out}->{fallback}"; + } + } elsif (defined $on->{$out}->{fallback}) { + $cmd .= " bg $on->{$out}->{fallback} solid_color"; + } # Sway returns status as JSON my $res_raw = `$cmd`; + print $res_raw . "\n"; my $res = $json->decode($res_raw)->[0]; # If failed, print to STDERR @@ -428,7 +453,6 @@ foreach my $out (keys %$on) { my $x = $on->{$out}->{width}; if (defined $on->{$out}->{scale}) { $x = sprintf("%.0d", $x / $on->{$out}->{scale}); - print "width: $x\n"; } $waybar =~ s/__WIDTH__/$x/; # If width is not set, comment that line out to use default @@ -457,5 +481,5 @@ unless ($pid) { print $fh $waybar; close $fh; my $waydisplay = $ENV{'WAYLAND_DISPLAY'} || 'wayland-0'; - `WAYLAND_DISPLAY=$waydisplay nohup waybar --config=$waybar_config >> waybar.log`; + `WAYLAND_DISPLAY=$waydisplay nohup waybar -b waybar0 --config=$waybar_config >> waybar.log; /home/jpm/scripts/waybar/toggle.sh invert`; }