Switch to 'model' instead of 'serial', clean display list

This commit is contained in:
John Mertz 2022-07-21 17:15:21 -04:00
parent 24da885f89
commit 6a75a61af8
1 changed files with 84 additions and 198 deletions

View File

@ -45,18 +45,13 @@ my $active_outputs = "$ENV{'HOME'}/.spool/active_outputs";
# Display Serials and Names
########################################################################
# Hash to match display Serial with a friendly name.
# You can get the serial from (quoted with *):
# $ swaymsg -t get_outputs
# Output eDP-1 'Unknown 0x057D *0x00000000*'
# Hash to match display model name to internal name
# You can get the model from (quoted with *):
# $ swaymsg -t get_outputs --raw
my %outputs = (
#'0x00000101' => 'Sam',
'HTNCB00059' => 'Sam',
#'3CQ4342S6W' => 'HP-1',
'0x00000101' => 'HP-1',
'3CQ3310Q1Q' => 'HP-2',
'0x00000000' => 'LVDS',
'0x00000101' => 'TV',
'LG TV SSCR2' => 'TV',
'Paperlike253' => 'eInk',
'0x4140' => 'yoga'
);
########################################################################
@ -67,14 +62,76 @@ my %outputs = (
# Second-level keys are the display friendly-names, above
# Third-level are the actual settings for that display
my %configs = (
'Both' => {
'yoga' => {
'on' => 0
},
'eInk' => {
'on' => 1,
'width' => 3200,
'height' => 1800,
'x' => 0,
'y' => 0,
'rotate' => 90,
'scale' => 2,
'waybar' => 'top',
'fallback' => '#fefefe',
},
'TV' => {
'HP-1' => {
'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
},
'HP-2' => {
'TV' => {
'on' => 0
}
},
'eInk' => {
'yoga' => {
'on' => 0
},
'Sam' => {
'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' => {
@ -84,185 +141,14 @@ my %configs = (
'x' => 0,
'y' => 0,
'rotate' => 0,
'scale' => 1.333333333,
'scale' => 1.33333,
'waybar' => 'top',
'fallback' => '#282828'
'fallback' => '#010101',
'bg' => "$ENV{HOME}/wallpapers/wallpaper.png"
},
'eDP-1' => {
'on' => 1,
'width' => 1920,
'height' => 1080,
'x' => 3079,
'y' => 0,
'rotate' => 0,
'waybar' => 'bottom',
'fallback' => '#282828'
}
},
'detached' => {
'HP-1' => {
'on' => 0
},
'HP-2' => {
'on' => 0
},
'Sam' => {
'on' => 0
},
'TV' => {
'on' => 0
},
'eDP-1' => {
'on' => 1,
'width' => 1920,
'height' => 1080,
'x' => 0,
'y' => 0,
'rotate' => 0,
'waybar' => 'bottom',
'fallback' => '#282828'
}
},
'stacked-laptop' => {
'Sam' => {
'on' => 1,
'width' => 1920,
'height' => 1200,
'x' => 960,
'y' => 0,
'rotate' => 0,
'waybar' => 'bottom',
'fallback' => '#282828'
},
'HP-1' => {
'on' => 1,
'width' => 1920,
'height' => 1080,
'x' => 1920,
'y' => 1200,
'rotate' => 0,
'waybar' => 'top',
'fallback' => '#282828'
},
'HP-2' => {
'on' => 0
},
'TV' => {
'on' => 0
},
'eDP-1' => {
'on' => 1,
'width' => 1920,
'height' => 1080,
'x' => 0,
'y' => 1200,
'rotate' => 0,
'waybar' => 'bottom',
'fallback' => '#282828'
}
},
'stacked' => {
'Sam' => {
'on' => 1,
'width' => 1920,
'height' => 1200,
'x' => 960,
'y' => 0,
'rotate' => 0,
'waybar' => 'bottom',
'fallback' => '#282828'
},
'HP-1' => {
'on' => 1,
'width' => 1920,
'height' => 1080,
'x' => 1920,
'y' => 1200,
'rotate' => 0,
'waybar' => 'top',
'fallback' => '#282828'
},
'HP-2' => {
'on' => 1,
'width' => 1920,
'height' => 1080,
'x' => 0,
'y' => 1200,
'rotate' => 0,
'waybar' => 'top',
'fallback' => '#282828'
},
'TV' => {
'on' => 0
},
'eDP-1' => {
'on' => 0
}
},
'sidebyside' => {
'HP-1' => {
'on' => 1,
'width' => 1080,
'height' => 1920,
'x' => 0,
'y' => 225,
'rotate' => 270,
'waybar' => 'top',
'fallback' => '#282828'
},
'Sam' => {
'on' => 1,
'width' => 1200,
'height' => 1920,
'x' => 1080,
'y' => 0,
'rotate' => 90,
'waybar' => 'top',
'fallback' => '#282828'
},
'HP-2' => {
'on' => 1,
'width' => 1080,
'height' => 1920,
'x' => 2280,
'y' => 225,
'rotate' => 90,
'waybar' => 'top',
'fallback' => '#282828'
},
'TV' => {
'on' => 0
},
'eDP-1' => {
'on' => 0,
}
}
);
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.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)
########################################################################
@ -330,19 +216,19 @@ my @off;
for (my $i = 0; $i < scalar(@$displays); $i++) {
# If a display is found without any settings print error and turn it off
unless (defined $configs{$config}{$outputs{$displays->[$i]->{serial}}}){
unless (defined $configs{$config}{$outputs{$displays->[$i]->{model}}}){
print STDERR "Output $displays->[$i]->{name} ("
. $displays->[$i]->{serial}
. $displays->[$i]->{model}
. ") found without defined function. Disabling.\n";
push @off, $displays->[$i]->{name};
next;
}
# If display is enabled, copy all of the desired settings
if ($configs{$config}{$outputs{$displays->[$i]->{serial}}}{on}) {
$on->{$outputs{$displays->[$i]->{serial}}} =
$configs{$config}{$outputs{$displays->[$i]->{serial}}};
$on->{$outputs{$displays->[$i]->{serial}}}{output} =
if ($configs{$config}{$outputs{$displays->[$i]->{model}}}{on}) {
$on->{$outputs{$displays->[$i]->{model}}} =
$configs{$config}{$outputs{$displays->[$i]->{model}}};
$on->{$outputs{$displays->[$i]->{model}}}{output} =
$displays->[$i]->{name};
# Otherwise simply list it for disabling
} else {