Cleanup and update paths

This commit is contained in:
John Mertz 2022-06-06 13:56:59 -04:00 committed by John Mertz
parent cd362eea6f
commit 5c3a10ce76
Signed by: jpm
GPG Key ID: E9C5EA2D867501AB
1 changed files with 37 additions and 31 deletions

View File

@ -28,20 +28,18 @@
# "output": __OUTPUT__ # "output": __OUTPUT__
# "position": __POSITION__ # "position": __POSITION__
# "width": __WIDTH__ (optional) # "width": __WIDTH__ (optional)
my $waybar_template = "$ENV{'HOME'}/.config/waybar/config.template"; my $waybar_template = "$ENV{'HOME'}/.dotfiles/waybar/config.template";
#my $swaysock = "/home/jpm/.config/sway-ipc.sock"; my $swaysock = $ENV{'SWAYSOCK'} || $ENV{'HOME'} . "/.spool/sway-ipc.sock";
my $swaysock = `ls /run/user/1000/sway-ipc.1000*`;
chomp($swaysock);
# Path to actual config file generated from template # Path to actual config file generated from template
my $waybar_config = "$ENV{'HOME'}/.config/waybar/config"; my $waybar_config = "$ENV{'HOME'}/.config/waybar/config";
# File to log and recover last used layout name # File to log and recover last used layout name
my $last = "$ENV{'HOME'}/.config/last_display"; my $last = "$ENV{'HOME'}/.spool/last_display";
# File to log active outputs (used by swayidle, and to attempt to restore # File to log active outputs (used by swayidle, and to attempt to restore
my $active_outputs = "$ENV{'HOME'}/.config/active_outputs"; my $active_outputs = "$ENV{'HOME'}/.spool/active_outputs";
######################################################################## ########################################################################
# Display Serials and Names # Display Serials and Names
@ -88,7 +86,7 @@ my %configs = (
'rotate' => 0, 'rotate' => 0,
'scale' => 1.333333333, 'scale' => 1.333333333,
'waybar' => 'top', 'waybar' => 'top',
'fallback' => '#000000' 'fallback' => '#282828'
}, },
'eDP-1' => { 'eDP-1' => {
'on' => 1, 'on' => 1,
@ -98,7 +96,7 @@ my %configs = (
'y' => 0, 'y' => 0,
'rotate' => 0, 'rotate' => 0,
'waybar' => 'bottom', 'waybar' => 'bottom',
'fallback' => '#000000' 'fallback' => '#282828'
} }
}, },
'detached' => { 'detached' => {
@ -122,7 +120,7 @@ my %configs = (
'y' => 0, 'y' => 0,
'rotate' => 0, 'rotate' => 0,
'waybar' => 'bottom', 'waybar' => 'bottom',
'fallback' => '#000000' 'fallback' => '#282828'
} }
}, },
'stacked-laptop' => { 'stacked-laptop' => {
@ -134,7 +132,7 @@ my %configs = (
'y' => 0, 'y' => 0,
'rotate' => 0, 'rotate' => 0,
'waybar' => 'bottom', 'waybar' => 'bottom',
'fallback' => '#000000' 'fallback' => '#282828'
}, },
'HP-1' => { 'HP-1' => {
'on' => 1, 'on' => 1,
@ -144,7 +142,7 @@ my %configs = (
'y' => 1200, 'y' => 1200,
'rotate' => 0, 'rotate' => 0,
'waybar' => 'top', 'waybar' => 'top',
'fallback' => '#000000' 'fallback' => '#282828'
}, },
'HP-2' => { 'HP-2' => {
'on' => 0 'on' => 0
@ -160,7 +158,7 @@ my %configs = (
'y' => 1200, 'y' => 1200,
'rotate' => 0, 'rotate' => 0,
'waybar' => 'bottom', 'waybar' => 'bottom',
'fallback' => '#000000' 'fallback' => '#282828'
} }
}, },
'stacked' => { 'stacked' => {
@ -172,7 +170,7 @@ my %configs = (
'y' => 0, 'y' => 0,
'rotate' => 0, 'rotate' => 0,
'waybar' => 'bottom', 'waybar' => 'bottom',
'fallback' => '#000000' 'fallback' => '#282828'
}, },
'HP-1' => { 'HP-1' => {
'on' => 1, 'on' => 1,
@ -182,7 +180,7 @@ my %configs = (
'y' => 1200, 'y' => 1200,
'rotate' => 0, 'rotate' => 0,
'waybar' => 'top', 'waybar' => 'top',
'fallback' => '#000000' 'fallback' => '#282828'
}, },
'HP-2' => { 'HP-2' => {
'on' => 1, 'on' => 1,
@ -192,7 +190,7 @@ my %configs = (
'y' => 1200, 'y' => 1200,
'rotate' => 0, 'rotate' => 0,
'waybar' => 'top', 'waybar' => 'top',
'fallback' => '#000000' 'fallback' => '#282828'
}, },
'TV' => { 'TV' => {
'on' => 0 'on' => 0
@ -210,7 +208,7 @@ my %configs = (
'y' => 225, 'y' => 225,
'rotate' => 270, 'rotate' => 270,
'waybar' => 'top', 'waybar' => 'top',
'fallback' => '#000000' 'fallback' => '#282828'
}, },
'Sam' => { 'Sam' => {
'on' => 1, 'on' => 1,
@ -220,7 +218,7 @@ my %configs = (
'y' => 0, 'y' => 0,
'rotate' => 90, 'rotate' => 90,
'waybar' => 'top', 'waybar' => 'top',
'fallback' => '#000000' 'fallback' => '#282828'
}, },
'HP-2' => { 'HP-2' => {
'on' => 1, 'on' => 1,
@ -230,7 +228,7 @@ my %configs = (
'y' => 225, 'y' => 225,
'rotate' => 90, 'rotate' => 90,
'waybar' => 'top', 'waybar' => 'top',
'fallback' => '#000000' 'fallback' => '#282828'
}, },
'TV' => { 'TV' => {
'on' => 0 'on' => 0
@ -312,11 +310,12 @@ if (!defined($configs{$config})) {
} }
# Write config that is to be used so that it can be recovered as default # Write config that is to be used so that it can be recovered as default
open(my $fh, '>', $last) || if (open(my $fh, '>', $last)) {
print STDERR "Config name cannot be written to $last\n"; print $fh $config;
print $fh $config; close($fh);
close($fh); } else {
print STDERR "Config name cannot be logged to: $last\n";
}
# Fetch connected displays # Fetch connected displays
use JSON::XS; use JSON::XS;
@ -468,7 +467,7 @@ foreach my $out (keys %$on) {
# Sway returns status as JSON # Sway returns status as JSON
my $res_raw = `$cmd`; my $res_raw = `$cmd`;
print $res_raw . "\n"; #print $res_raw . "\n";
my $res = $json->decode($res_raw)->[0]; my $res = $json->decode($res_raw)->[0];
# If failed, print to STDERR # If failed, print to STDERR
@ -508,9 +507,13 @@ foreach my $out (keys %$on) {
} }
} }
open($fh, '>', $active_outputs); # Log active outputs for recovery after crash/reboot
print $fh join(' ', @active); if (open(my $fh, '>', $active_outputs)) {
close($fh); print $fh join(' ', @active);
close($fh);
} else {
print STDERR "Cannot write active outputs to: $active_outputs\n";
}
# Restore array formatting # Restore array formatting
$waybar = '[' . $waybar . ']'; $waybar = '[' . $waybar . ']';
@ -522,9 +525,12 @@ unless ($pid) {
open STDOUT, '>>/dev/null'; open STDOUT, '>>/dev/null';
open STDERR, '>>/dev/null'; open STDERR, '>>/dev/null';
# Write config to a temporary file # Write config to a temporary file
open ($fh, '>', $waybar_config); if (open (my $fh, '>', $waybar_config)) {
print $fh $waybar; print $fh $waybar;
close $fh; close $fh;
} else {
die "Failed to write configuration file: $waybar_config\n";
}
my $waydisplay = $ENV{'WAYLAND_DISPLAY'} || 'wayland-0'; my $waydisplay = $ENV{'WAYLAND_DISPLAY'} || 'wayland-0';
`WAYLAND_DISPLAY=$waydisplay nohup waybar -b waybar0 --config=$waybar_config >> waybar.log; /home/jpm/scripts/waybar/toggle.sh invert`; `WAYLAND_DISPLAY=$waydisplay nohup waybar -b waybar0 --config=$waybar_config >> $ENV{'HOME'}/.waybar.log`;
} }