diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2007-09-26 09:44:33 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2007-09-26 09:44:33 +0000 |
commit | 61ad01fab2ccb41f310f09d74823827778c34e55 (patch) | |
tree | 5a8cee8a805d5d2ff28cdfc891c2cc5e935808f1 /monitor-probe-using-X | |
parent | b7453fef44cd178e54d331a9609a488f295eed1d (diff) | |
download | monitor-edid-61ad01fab2ccb41f310f09d74823827778c34e55.tar monitor-edid-61ad01fab2ccb41f310f09d74823827778c34e55.tar.gz monitor-edid-61ad01fab2ccb41f310f09d74823827778c34e55.tar.bz2 monitor-edid-61ad01fab2ccb41f310f09d74823827778c34e55.tar.xz monitor-edid-61ad01fab2ccb41f310f09d74823827778c34e55.zip |
- monitor-probe-using-X:
o when an EDID is found in Xorg.log, pass it to monitor-parse-edid
o handle --perl option (passed to monitor-parse-edid)
Diffstat (limited to 'monitor-probe-using-X')
-rwxr-xr-x | monitor-probe-using-X | 53 |
1 files changed, 51 insertions, 2 deletions
diff --git a/monitor-probe-using-X b/monitor-probe-using-X index 11d7812..70b0252 100755 --- a/monitor-probe-using-X +++ b/monitor-probe-using-X @@ -1,7 +1,11 @@ #!/usr/bin/perl +use Getopt::Long; + +GetOptions_('verbose', 'MonitorsDB', 'perl') && @ARGV == 1 + or die "usage: monitor-probe-using-X [-v] [--perl] <X driver>\n"; + my ($arg) = @ARGV; -@ARGV == 1 && $arg !~ /^-/ or die "usage: monitor-probe-using-X <X driver>\n"; my $log; if (-e $arg) { @@ -26,8 +30,23 @@ if (-e $arg) { } +sub GetOptions_ { + my (@l) = @_; + GetOptions('v' => \$opt{verbose}, map { $_ => \$opt{/([^=]*)/ && $1} } @l); +} + +sub propagate_options { + my (@l) = @_; + map { $_ eq 'verbose' ? '-v' : "--$_" } grep { $opt{$_} } @l; +} + +sub parse_edid() { + join(' ', 'monitor-parse-edid', propagate_options('verbose', 'MonitorsDB', 'perl')); +} + sub cat_ { open(my $F, $_[0]) or return; my @l = <$F>; wantarray() ? @l : join '', @l } sub output { my $f = shift; open(my $F, ">$f") or die "output in file $f failed: $!\n"; print $F $_ foreach @_; 1 } +sub uniq { my %l; $l{$_} = 1 foreach @_; grep { delete $l{$_} } @_ } sub tmpfile() { chomp(my $s = `mktemp /tmp/tmp.XXXXXXXXXX`); #- we could use simply mktemp with new mktemp eval "END { unlink '$s' }"; @@ -85,9 +104,37 @@ EOF } } +sub parse_X_log_edids { + my ($log) = @_; + + my @edids; + while ($log =~ /: EDID \(in hex\):\n((.*\n){8})/g) { + my @lines = split '\n', $1; + my $edid = join('', map { /:\s+([0-9a-f]{32})$/ && $1 } @lines); + if (length $edid == 256) { + @edids = uniq(@edids, $edid); + } else { + warn "bad EDID found\n"; + } + } + if (@edids) { + print "[\n" if $opt{perl}; + foreach my $edid (@edids) { + open(my $F, '| ' . parse_edid()); + print $F pack("C*", map { hex($_) } $edid =~ /(..)/g); + close $F; + print ",\n" if $opt{perl}; + } + print "]\n" if $opt{perl}; + } + @edids; +} + sub parse_X_log { my ($log) = @_; + parse_X_log_edids($log) and return 1; + 0 # i810 format: "Size of device %s is %d x %d\n" (i810/i830_driver.c) # with one of "CRT", "TV", "DFP (digital flat panel)", "LFP (local flat panel)", "CRT2 (second CRT)", "TV2 (second TV)", "DFP2 (second digital flat panel)", "LFP2 (second local flat panel)", @@ -132,6 +179,8 @@ sub parse_X_log { or return; - print $1, 'x', $2, "\n"; + my ($X, $Y) = ($1, $2); + + print $opt{perl} ? "[ { preferred_resolution => { X => $X, Y => $Y } } ]" : "${X}x${Y}", "\n"; 1; } |