diff options
-rw-r--r-- | NEWS | 1 | ||||
-rwxr-xr-x | monitor-parse-edid | 72 |
2 files changed, 52 insertions, 21 deletions
@@ -1,5 +1,6 @@ - monitor-parse-edid: o compute and display the "dpi" of the preferred modelines + o handle parsing of EDIDs found in "xrandr --prop" or Xorg.log Version 2.0 - 8 April 2008 diff --git a/monitor-parse-edid b/monitor-parse-edid index e976814..c6e158c 100755 --- a/monitor-parse-edid +++ b/monitor-parse-edid @@ -457,8 +457,31 @@ sub print_edid { } } +sub edid_from_lines { + my (@l) = @_; + my $edid_str = join('', map { /\s+([0-9a-f]{32})$/ && $1 } @l); + length($edid_str) == 256 or return (); + pack("C*", map { hex($_) } $edid_str =~ /(..)/g); +} + +sub find_edid_in_string { + my ($input) = @_; + + my @edids; + while ($input =~ /(?:EDID_DATA|: EDID \(in hex\)):\n((.*\n){8})/g) { + push @edids, edid_from_lines(split '\n', $1); + } + if (!@edids) { + @edids = edid_from_lines(split '\n', $input); + } + @edids; +} + sub usage() { - die "usage: monitor-parse-edid [-v] [--perl] [<edid file>]\n"; + die <<'EOF'; +usage: monitor-parse-edid [-v] [--perl] [<edid file>] +You can also do "xrandr --prop | monitor-parse-edid" +EOF } use Getopt::Long; @@ -477,7 +500,7 @@ if (@ARGV == 0) { usage(); } -my $raw_edid = join('', <$F>); +my $input = join('', <$F>); sub error { my ($msg) = @_; @@ -485,26 +508,33 @@ sub error { exit 1; } -length($raw_edid) == 128 || length($raw_edid) == 256 or error("bad edid"); - -my $edid = parse_edid($raw_edid, $verbose); -if (my $err = check_parsed_edid($edid)) { - die "$err\n"; -} -$edid->{file} = $file if $file; - -if ($raw_perl) { - use Data::Dumper; - $Data::Dumper::Sortkeys = 1; - my $s = Dumper($edid); - $s =~ s/.*? = {/+{/; # remove variable name we don't want - $s =~ s/};$/}/m; - print $s; -} elsif ($MonitorsDB) { - my $s = to_MonitorsDB($edid); - print "$s\n" if $s; +my @raw_edids; +if (length($input) == 128 || length($input) == 256) { + @raw_edids = $input; } else { - print_edid($edid, $verbose); + @raw_edids = find_edid_in_string($input) or error("bad edid"); +} + +foreach my $raw_edid (@raw_edids) { + my $edid = parse_edid($raw_edid, $verbose); + if (my $err = check_parsed_edid($edid)) { + die "$err\n"; + } + $edid->{file} = $file if $file; + + if ($raw_perl) { + use Data::Dumper; + $Data::Dumper::Sortkeys = 1; + my $s = Dumper($edid); + $s =~ s/.*? = {/+{/; # remove variable name we don't want + $s =~ s/};$/}/m; + print $s; + } elsif ($MonitorsDB) { + my $s = to_MonitorsDB($edid); + print "$s\n" if $s; + } else { + print_edid($edid, $verbose); + } } |