Dynamic scale for Yoga

This is a big-ol hack. I should ideally just have an external file for
the configs which differs for each device.
This commit is contained in:
John Mertz 2021-11-11 22:01:07 -05:00 committed by John Mertz
parent 4e388030f8
commit 93125c95ee
Signed by: jpm
GPG Key ID: E9C5EA2D867501AB
1 changed files with 73 additions and 6 deletions

View File

@ -30,7 +30,9 @@
# "width": __WIDTH__ (optional)
my $waybar_template = "$ENV{'HOME'}/.config/waybar/config.template";
my $swaysock = "/home/jpm/.config/sway-ipc.sock";
#my $swaysock = "/home/jpm/.config/sway-ipc.sock";
my $swaysock = `ls /run/user/1000/sway-ipc.1000*`;
chomp($swaysock);
# Path to actual config file generated from template
my $waybar_config = "$ENV{'HOME'}/.config/waybar/config";
@ -76,13 +78,45 @@ my %configs = (
'Sam' => {
'on' => 0
},
'LVDS' => {
'eDP-1' => {
'on' => 1,
'width' => 1920,
'height' => 1080,
'x' => 0,
'y' => 0,
'rotate' => 0,
'waybar' => 'bottom',
}
},
'stacked-laptop' => {
'Sam' => {
'on' => 1,
'width' => 1920,
'height' => 1200,
'x' => 960,
'y' => 0,
'rotate' => 0,
'waybar' => 'bottom'
},
'HP-1' => {
'on' => 1,
'width' => 1920,
'height' => 1080,
'x' => 1920,
'y' => 1200,
'rotate' => 0,
'waybar' => 'top'
},
'HP-2' => {
'on' => 0
},
'eDP-1' => {
'on' => 1,
'width' => 1920,
'height' => 1080,
'x' => 0,
'y' => 1200,
'rotate' => 0,
'waybar' => 'bottom'
}
},
@ -90,7 +124,7 @@ my %configs = (
'Sam' => {
'on' => 1,
'width' => 1920,
'height' => 1280,
'height' => 1200,
'x' => 960,
'y' => 0,
'rotate' => 0,
@ -114,7 +148,7 @@ my %configs = (
'rotate' => 0,
'waybar' => 'top'
},
'LVDS' => {
'eDP-1' => {
'on' => 0
}
},
@ -152,6 +186,30 @@ my %configs = (
}
);
my $hostname = `hostname`;
chomp($hostname);
if ($hostname eq "yoga.lan.john.me.tz") {
$configs{'detached'}->{'eDP-1'}->{'width'} = 2560;
$configs{'detached'}->{'eDP-1'}->{'height'} = 1440;
$configs{'detached'}->{'eDP-1'}->{'scale'} = 1.333333;
}
########################################################################
# Disable display from other laptop
########################################################################
if ($ENV{'SSH_AUTH_SOCK'} eq '/home/jpm/.ssh/ssh-agent.yoga.lan.john.me.tz.sock') {
foreach my $layout (keys %configs) {
delete($configs{$layout}{'LVDS'});
}
$outputs{'0x00000000'} = 'eDP-1';
} else {
foreach my $layout (keys %configs) {
delete($configs{$layout}{'eDP-1'});
}
}
########################################################################
# Program (do not edit below)
########################################################################
@ -323,6 +381,9 @@ foreach my $out (keys %$on) {
" enable dpms on";
# If additional options are provided, add them to command
if (defined $on->{$out}->{scale}) {
$cmd .= " scale $on->{$out}->{scale}";
}
if (defined $on->{$out}->{rotate}) {
$cmd .= " transform $on->{$out}->{rotate}";
}
@ -364,7 +425,12 @@ foreach my $out (keys %$on) {
$waybar =~ s/__OUTPUT__/"$on->{$out}->{output}"/;
$waybar =~ s/__POSITION__/"$on->{$out}->{waybar}"/;
if (defined $on->{$out}->{width}) {
$waybar =~ s/__WIDTH__/$on->{$out}->{width}/;
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
} else {
$waybar =~ s/([^\s]*\s*)__WIDTH__/\/\/ $1__WIDTH__/gg;
@ -390,5 +456,6 @@ unless ($pid) {
open ($fh, '>', $waybar_config);
print $fh $waybar;
close $fh;
`WAYLAND_DISPLAY=wayland-1 nohup waybar --config=$waybar_config >> waybar.log`;
my $waydisplay = $ENV{'WAYLAND_DISPLAY'} || 'wayland-0';
`WAYLAND_DISPLAY=$waydisplay nohup waybar --config=$waybar_config >> waybar.log`;
}