Compare commits

...

2 Commits

Author SHA1 Message Date
John Mertz ecd9920a37 Standardize and expand tab to 4 2022-12-29 12:37:33 -05:00
John Mertz c4bbf89f52 Increase scale for new terminal font size.
Maximum possible to fit 108 columns when vertically split 50/50, enough for 100 columns plus 8 for line numbers/git status
2022-12-29 12:36:53 -05:00
1 changed files with 254 additions and 254 deletions

View File

@ -49,9 +49,9 @@ my $active_outputs = "$ENV{'HOME'}/.spool/active_outputs";
# You can get the model from (quoted with *): # You can get the model from (quoted with *):
# $ swaymsg -t get_outputs --raw # $ swaymsg -t get_outputs --raw
my %outputs = ( my %outputs = (
'DENON-AVAMP' => 'TV', 'DENON-AVAMP' => 'TV',
'Paperlike253' => 'eInk', 'Paperlike253' => 'eInk',
'0x4140' => 'yoga' '0x4140' => 'yoga'
); );
######################################################################## ########################################################################
@ -62,91 +62,91 @@ my %outputs = (
# Second-level keys are the display friendly-names, above # Second-level keys are the display friendly-names, above
# Third-level are the actual settings for that display # Third-level are the actual settings for that display
my %configs = ( my %configs = (
'Both' => { 'Both' => {
'yoga' => { 'yoga' => {
'on' => 0 'on' => 0
},
'eInk' => {
'on' => 1,
'width' => 3200,
'height' => 1800,
'x' => 0,
'y' => 0,
'rotate' => 90,
'scale' => 2,
'waybar' => 'top',
'fallback' => '#fefefe',
},
'TV' => {
'on' => 1,
'width' => 3840,
'height' => 2160,
'x' => 900,
'y' => 0,
'rotate' => 0,
'scale' => 1.33333,
'waybar' => 'top',
'fallback' => '#010101',
'bg' => "$ENV{HOME}/wallpapers/wallpaper.png"
},
},
'detached' => {
'yoga' => {
'on' => 1,
'width' => 2560,
'height' => 1440,
'x' => 0,
'y' => 0,
'rotate' => 0,
'scale' => 1.33333,
'waybar' => 'bottom',
'fallback' => '#010101',
'bg' => "$ENV{HOME}/wallpapers/wallpaper.png"
},
'eInk' => {
'on' => 0
},
'TV' => {
'on' => 0
}
}, },
'eInk' => { 'eInk' => {
'yoga' => { 'on' => 1,
'on' => 0 'width' => 3200,
}, 'height' => 1800,
'eInk' => { 'x' => 0,
'on' => 1, 'y' => 0,
'width' => 3840, 'rotate' => 90,
'height' => 2160, 'scale' => 2,
'x' => 0, 'waybar' => 'top',
'y' => 0, 'fallback' => '#fefefe',
'rotate' => 0,
'scale' => 1.33333,
'waybar' => 'top',
'fallback' => '#010101',
'bg' => "$ENV{HOME}/wallpapers/wallpaper.png"
},
'TV' => {
'on' => 0
},
}, },
'TV' => { 'TV' => {
'yoga' => { 'on' => 1,
'on' => 0 'width' => 3840,
}, 'height' => 2160,
'TV' => { 'x' => 900,
'on' => 1, 'y' => 0,
'width' => 3840, 'rotate' => 0,
'height' => 2160, 'scale' => 1.33333,
'x' => 0, 'waybar' => 'top',
'y' => 0, 'fallback' => '#010101',
'rotate' => 0, 'bg' => "$ENV{HOME}/wallpapers/wallpaper.png"
'scale' => 1.33333, },
'waybar' => 'top', },
'fallback' => '#010101', 'detached' => {
'bg' => "$ENV{HOME}/wallpapers/wallpaper.png" 'yoga' => {
}, 'on' => 1,
'width' => 2560,
'height' => 1440,
'x' => 0,
'y' => 0,
'rotate' => 0,
'scale' => 1.43,
'waybar' => 'bottom',
'fallback' => '#010101',
'bg' => "$ENV{HOME}/wallpapers/wallpaper.png"
},
'eInk' => {
'on' => 0
},
'TV' => {
'on' => 0
} }
},
'eInk' => {
'yoga' => {
'on' => 0
},
'eInk' => {
'on' => 1,
'width' => 3840,
'height' => 2160,
'x' => 0,
'y' => 0,
'rotate' => 0,
'scale' => 1.33333,
'waybar' => 'top',
'fallback' => '#010101',
'bg' => "$ENV{HOME}/wallpapers/wallpaper.png"
},
'TV' => {
'on' => 0
},
},
'TV' => {
'yoga' => {
'on' => 0
},
'TV' => {
'on' => 1,
'width' => 3840,
'height' => 2160,
'x' => 0,
'y' => 0,
'rotate' => 0,
'scale' => 1.33333,
'waybar' => 'top',
'fallback' => '#010101',
'bg' => "$ENV{HOME}/wallpapers/wallpaper.png"
},
}
); );
######################################################################## ########################################################################
@ -161,46 +161,46 @@ my $restore = 0; # Set if no config is provided. Requires validation.
my $config; my $config;
if (scalar(@ARGV)) { if (scalar(@ARGV)) {
while (@ARGV) { while (@ARGV) {
my $arg = shift; my $arg = shift;
if ($arg eq "-w") { if ($arg eq "-w") {
$waybar_only = 1; $waybar_only = 1;
} else { } else {
if (defined $config) { if (defined $config) {
die "Too many arguments.\n"; die "Too many arguments.\n";
} }
$config = $arg; $config = $arg;
}
} }
}
} }
# Get previous config if one is not provided # Get previous config if one is not provided
unless (defined $config) { unless (defined $config) {
open(my $fh, '<', $last) || open(my $fh, '<', $last) ||
die "Config name not provided and failed to open $last\n"; die "Config name not provided and failed to open $last\n";
$config = <$fh>; $config = <$fh>;
close($fh); close($fh);
chomp $config; chomp $config;
$restore = 1; $restore = 1;
} }
# Bail if requested config doesn't exist # Bail if requested config doesn't exist
if (!defined($configs{$config})) { if (!defined($configs{$config})) {
if ($restore) { if ($restore) {
# If restoration is attempted with invalid config, just enable eDP-1 # If restoration is attempted with invalid config, just enable eDP-1
$config = 'detached'; $config = 'detached';
} else { } else {
die "$config is not a defined configuration: " die "$config is not a defined configuration: "
. join(', ', keys %configs) . "\n"; . join(', ', keys %configs) . "\n";
} }
} }
# 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
if (open(my $fh, '>', $last)) { if (open(my $fh, '>', $last)) {
print $fh $config; print $fh $config;
close($fh); close($fh);
} else { } else {
print STDERR "Config name cannot be logged to: $last\n"; print STDERR "Config name cannot be logged to: $last\n";
} }
# Fetch connected displays # Fetch connected displays
@ -215,92 +215,92 @@ my $on;
my @off; my @off;
for (my $i = 0; $i < scalar(@$displays); $i++) { for (my $i = 0; $i < scalar(@$displays); $i++) {
# If a display is found without any settings print error and turn it off # If a display is found without any settings print error and turn it off
unless (defined $configs{$config}{$outputs{$displays->[$i]->{model}}}){ unless (defined $configs{$config}{$outputs{$displays->[$i]->{model}}}){
print STDERR "Output $displays->[$i]->{name} (" print STDERR "Output $displays->[$i]->{name} ("
. $displays->[$i]->{model} . $displays->[$i]->{model}
. ") found without defined function. Disabling.\n"; . ") found without defined function. Disabling.\n";
push @off, $displays->[$i]->{name}; push @off, $displays->[$i]->{name};
next; next;
} }
# If display is enabled, copy all of the desired settings # If display is enabled, copy all of the desired settings
if ($configs{$config}{$outputs{$displays->[$i]->{model}}}{on}) { if ($configs{$config}{$outputs{$displays->[$i]->{model}}}{on}) {
$on->{$outputs{$displays->[$i]->{model}}} = $on->{$outputs{$displays->[$i]->{model}}} =
$configs{$config}{$outputs{$displays->[$i]->{model}}}; $configs{$config}{$outputs{$displays->[$i]->{model}}};
$on->{$outputs{$displays->[$i]->{model}}}{output} = $on->{$outputs{$displays->[$i]->{model}}}{output} =
$displays->[$i]->{name}; $displays->[$i]->{name};
# Otherwise simply list it for disabling # Otherwise simply list it for disabling
} else { } else {
push @off, $displays->[$i]->{name}; push @off, $displays->[$i]->{name};
} }
} }
# Verify that all requested displays are actually available # Verify that all requested displays are actually available
my @unavailable; my @unavailable;
foreach my $output (keys %$on) { foreach my $output (keys %$on) {
my $found = 0; my $found = 0;
foreach my $o (keys %outputs) { foreach my $o (keys %outputs) {
if ($outputs{$o} eq $output) { if ($outputs{$o} eq $output) {
$found = 1; $found = 1;
last; last;
} }
} }
unless ($found) { unless ($found) {
push @unavailable, $output; push @unavailable, $output;
} }
} }
if (scalar(@unavailable)) { if (scalar(@unavailable)) {
die "Config requires unavailable output(s) " . join(', ', @unavailable) die "Config requires unavailable output(s) " . join(', ', @unavailable)
. "\n"; . "\n";
} }
# Skip enabling/disabling displays if only running waybar (re)start # Skip enabling/disabling displays if only running waybar (re)start
unless ($waybar_only) { unless ($waybar_only) {
# Number of simultaneous outputs is limited by gpu, so disabled displays # Number of simultaneous outputs is limited by gpu, so disabled displays
# first # first
foreach (@off) { foreach (@off) {
# Sway returns status as JSON # Sway returns status as JSON
my $res_raw = `swaymsg -s $swaysock output $_ disable`; my $res_raw = `swaymsg -s $swaysock output $_ disable`;
my $res = $json->decode($res_raw)->[0]; my $res = $json->decode($res_raw)->[0];
# If failed, print to STDERR
unless ($res->{success}) {
print STDERR "Error ($res->{error}) in command 'swaymsg"
. " -s $swaysock output $_ disable'\n";
}
# If failed, print to STDERR
unless ($res->{success}) {
print STDERR "Error ($res->{error}) in command 'swaymsg"
. " -s $swaysock output $_ disable'\n";
} }
}
} }
# Kill existing Waybars # Kill existing Waybars
require Proc::ProcessTable; require Proc::ProcessTable;
my $t = new Proc::ProcessTable; my $t = new Proc::ProcessTable;
foreach my $p ( @{ $t->table } ) { foreach my $p ( @{ $t->table } ) {
my $cmndline = $p->{'cmndline'}; my $cmndline = $p->{'cmndline'};
$cmndline =~ s/\s*$//g; $cmndline =~ s/\s*$//g;
if ($cmndline =~ /^waybar.*/) { if ($cmndline =~ /^waybar.*/) {
# Never kill this process # Never kill this process
if ($p->{'pid'} == $$) { if ($p->{'pid'} == $$) {
next; next;
} else { } else {
$p->kill(9); $p->kill(9);
}
} }
}
} }
# Load in config template # Load in config template
my $template; my $template;
if (open (my $fh, '<', $waybar_template)) { if (open (my $fh, '<', $waybar_template)) {
while (<$fh>) { while (<$fh>) {
$template .= $_; $template .= $_;
} }
close $fh; close $fh;
chomp $template; chomp $template;
} else { } else {
print STDERR "Failed to load template $waybar_template\n"; print STDERR "Failed to load template $waybar_template\n";
} }
# If template is already set up as an array, remove the square brackets so that # If template is already set up as an array, remove the square brackets so that
@ -314,91 +314,91 @@ my $waybar = '';
my @active; my @active;
foreach my $out (keys %$on) { foreach my $out (keys %$on) {
push @active, $on->{$out}->{output}; push @active, $on->{$out}->{output};
unless ($waybar_only) { unless ($waybar_only) {
# Build command, starting by enabling and powering on # Build command, starting by enabling and powering on
my $cmd = "swaymsg -s $swaysock output $on->{$out}->{output}" . my $cmd = "swaymsg -s $swaysock output $on->{$out}->{output}" .
" enable dpms on"; " enable dpms on";
# If additional options are provided, add them to command # If additional options are provided, add them to command
if (defined $on->{$out}->{scale}) { if (defined $on->{$out}->{scale}) {
$cmd .= " scale $on->{$out}->{scale}"; $cmd .= " scale $on->{$out}->{scale}";
} else { } else {
$cmd .= " scale 1"; $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}";
}
if (defined $on->{$out}->{width} &&
defined $on->{$out}->{height} )
{
$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
unless ($res->{success}) {
print STDERR "Error ($res->{error}) in command " .
"'$cmd'\n";
}
} }
if (defined $on->{$out}->{rotate}) {
# Skip waybar setup if template failed to be loaded $cmd .= " transform $on->{$out}->{rotate}";
if ( (defined $template) && } else {
(defined $on->{$out}->{waybar}) && $cmd .= " transform 0";
($on->{$out}->{waybar} =~ m/(top|bottom|left|right)/) ) }
if (defined $on->{$out}->{x} && defined $on->{$out}->{y}) {
$cmd .= " position $on->{$out}->{x} $on->{$out}->{y}";
}
if (defined $on->{$out}->{width} &&
defined $on->{$out}->{height} )
{ {
$cmd .= " mode $on->{$out}->{width}x" .
# If there's already a display set up, add a comma "$on->{$out}->{height}";
unless ($waybar eq '') {
$waybar .= ',';
}
$waybar .= $template;
# Replace basic preferences
$waybar =~ s/__OUTPUT__/"$on->{$out}->{output}"/gg;
$waybar =~ s/__POSITION__/"$on->{$out}->{waybar}"/gg;
if (defined $on->{$out}->{width}) {
my $x = $on->{$out}->{width};
if (defined $on->{$out}->{scale}) {
$x = sprintf("%.0d", $x / $on->{$out}->{scale});
}
$waybar =~ s/__WIDTH__/$x/gg;
# If width is not set, comment that line out to use default
} else {
$waybar =~ s/([^\s]*\s*)__WIDTH__/\/\/ $1__WIDTH__/gg;
}
} }
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
unless ($res->{success}) {
print STDERR "Error ($res->{error}) in command " .
"'$cmd'\n";
}
}
# Skip waybar setup if template failed to be loaded
if ( (defined $template) &&
(defined $on->{$out}->{waybar}) &&
($on->{$out}->{waybar} =~ m/(top|bottom|left|right)/) )
{
# If there's already a display set up, add a comma
unless ($waybar eq '') {
$waybar .= ',';
}
$waybar .= $template;
# Replace basic preferences
$waybar =~ s/__OUTPUT__/"$on->{$out}->{output}"/gg;
$waybar =~ s/__POSITION__/"$on->{$out}->{waybar}"/gg;
if (defined $on->{$out}->{width}) {
my $x = $on->{$out}->{width};
if (defined $on->{$out}->{scale}) {
$x = sprintf("%.0d", $x / $on->{$out}->{scale});
}
$waybar =~ s/__WIDTH__/$x/gg;
# If width is not set, comment that line out to use default
} else {
$waybar =~ s/([^\s]*\s*)__WIDTH__/\/\/ $1__WIDTH__/gg;
}
}
} }
# Log active outputs for recovery after crash/reboot # Log active outputs for recovery after crash/reboot
if (open(my $fh, '>', $active_outputs)) { if (open(my $fh, '>', $active_outputs)) {
print $fh join(' ', @active); print $fh join(' ', @active);
close($fh); close($fh);
} else { } else {
print STDERR "Cannot write active outputs to: $active_outputs\n"; print STDERR "Cannot write active outputs to: $active_outputs\n";
} }
# Restore array formatting # Restore array formatting
@ -407,16 +407,16 @@ $waybar = '[' . $waybar . ']';
# Start Waybar as fork # Start Waybar as fork
my $pid = fork; my $pid = fork;
unless ($pid) { unless ($pid) {
open STDIN, '/dev/null'; open STDIN, '/dev/null';
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
if (open (my $fh, '>', $waybar_config)) { if (open (my $fh, '>', $waybar_config)) {
print $fh $waybar; print $fh $waybar;
close $fh; close $fh;
} else { } else {
die "Failed to write configuration file: $waybar_config\n"; 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 >> $ENV{'HOME'}/.waybar.log`; `WAYLAND_DISPLAY=$waydisplay nohup waybar -b waybar0 --config=$waybar_config >> $ENV{'HOME'}/.waybar.log`;
} }