home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-2 / Inter.Net 55-2.iso / Mandrake / mdkinst / usr / bin / perl-install / Xconfig.pm < prev    next >
Encoding:
Perl POD Document  |  2000-01-12  |  4.4 KB  |  140 lines

  1. package Xconfig;
  2.  
  3.  
  4.  
  5.  
  6. use common qw(:common :file :system);
  7. use mouse;
  8. use devices;
  9. use Xconfigurator;
  10.  
  11. # otherwise uses the rule substr($keymap, 0, 2)
  12. my %keymap_translate = (
  13.     cf => "ca_enhanced",
  14.     uk => "gb",
  15. );
  16.  
  17.  
  18. 1;
  19.  
  20. sub keymap_translate {
  21.     $keymap_translate{$_[0]} || substr($_[0], 0, 2);
  22. }
  23.  
  24.  
  25. sub getinfo {
  26.     my $o = shift || {};
  27.     getinfoFromDDC($o);
  28.     getinfoFromSysconfig($o);
  29.  
  30.     add2hash($o->{mouse}, mouse::detect()) unless $o->{mouse}{XMOUSETYPE};
  31.  
  32.     $o->{mouse}{device} ||= "mouse" if -e "/dev/mouse";
  33.     $o;
  34. }
  35.  
  36. sub getinfoFromXF86Config {
  37.     my $o = shift || {};
  38.     my $prefix = shift || "";
  39.     my (%c, $depth, $driver);
  40.  
  41.     $o->{card}{server} ||= $1 if readlink("$prefix/etc/X11/X") =~ /XF86_ (\w+)$/x; 
  42.  
  43.     local *F;
  44.     open F, "$prefix/etc/X11/XF86Config" or return {};
  45.     foreach (<F>) {
  46.     if (/^Section "Keyboard"/ .. /^EndSection/) {
  47.         $o->{keyboard}{altmeta} ||= ($1 eq "ModeShift" ? 1 : 0) if /^\s*RightAlt\s+"(.*?)"/;
  48.         $o->{keyboard}{xkb_keymap} ||= $1 if /^\s*XkbLayout\s+"(.*?)"/;
  49.     } elsif (/^Section "Pointer"/ .. /^EndSection/) {
  50.         $o->{mouse}{XMOUSETYPE} ||= $1 if /^\s*Protocol\s+"(.*?)"/;
  51.         $o->{mouse}{device} ||= $1 if m|^\s*Device\s+"/dev/(.*?)"|;
  52.         $o->{mouse}{XEMU3} ||= 1 if m/^\s*Emulate3Buttons\s+/;
  53.         $o->{mouse}{cleardtrrts} ||= 1 if m/^\s*ClearDTR\s+/;
  54.         $o->{mouse}{cleardtrrts} ||= 1 if m/^\s*ClearRTS\s+/;
  55.     } elsif (my $i = /^Section "Device"/ .. /^EndSection/) {
  56.         %c = () if $i == 1;
  57.  
  58.         $c{type} ||= $1 if /^\s*Identifier\s+"(.*?)"/;
  59.         $c{memory} ||= $1 if /VideoRam\s+(\d+)/;
  60.         $c{flags}{needVideoRam} ||= 1 if /^\s*VideoRam\s+/;
  61.         $c{vendor} ||= $1 if /^\s*VendorName\s+"(.*?)"/;
  62.         $c{board} ||= $1 if /^\s*BoardName\s+"(.*?)"/;
  63.         $c{options}{$1} ||= 1 if /^\s*Option\s+"(.*?)"/;
  64.         $c{options}{$1} ||= 0 if /^\s*#\s*Option\s+"(.*?)"/;
  65.  
  66.         
  67.         push @{$c{lines}}, $_ unless /(Section|Identifier|VideoRam|VendorName|BoardName|Option)/;
  68.  
  69.         add2hash($o->{card} ||= {}, \%c) if ($i =~ /E0/ && $c{type} && $c{type} ne "Generic VGA");
  70.     } elsif (/^Section "Monitor"/ .. /^EndSection/) {
  71.         $o->{monitor}{type} ||= $1 if /^\s*Identifier\s+"(.*?)"/;
  72.         $o->{monitor}{hsyncrange} ||= $1 if /^\s*HorizSync\s+(.*)/;
  73.         $o->{monitor}{vsyncrange} ||= $1 if /^\s*VertRefresh\s+(.*)/;
  74.         $o->{monitor}{vendor} ||= $1 if /^\s*VendorName\s+"(.*?)"/;
  75.         $o->{monitor}{model} ||= $1 if /^\s*ModelName\s+"(.*?)"/;
  76.         $o->{monitor}{modelines} .= $_ if /^\s*Mode[lL]ine\s+/;
  77.     } elsif (my $s = /^Section "Screen"/ .. /^EndSection/) {
  78.         undef $driver if $s == 1;
  79.         $driver = $1 if /^\s*Driver\s+"(.*?)"/;
  80.         if ($driver eq $Xconfigurator::serversdriver{$o->{card}{server}}) {
  81.         $o->{card}{default_depth} ||= $1 if /^\s*DefaultColorDepth\s+(\d+)/;
  82.         if (my $i = /^\s*Subsection\s+"Display"/ .. /^\s*EndSubsection/) {
  83.             undef $depth if $i == 1;
  84.             $depth = $1 if /^\s*Depth\s+(\d*)/;
  85.             if (/^\s*Modes\s+(.*)/) {
  86.             my $a = 0;
  87.             unshift @{$o->{card}{depth}{$depth || 8} ||= []}, 
  88.                     grep { $_->[0] >= 640 } map { [ /"(\d+)x(\d+)"/ ] } split ' ', $1;
  89.             }
  90.         }
  91.         }
  92.     }
  93.     }
  94.     
  95.     my @depth = keys %{$o->{card}{depth}};
  96.     $o->{resolution_wanted} ||=
  97.       ($o->{card}{depth}{$o->{card}{default_depth} || $depth[0]}[0][0]) . "x" .
  98.     ($o->{card}{depth}{$o->{card}{default_depth} || $depth[0]}[0][1]);
  99.     $o;
  100. }
  101.  
  102. sub getinfoFromSysconfig {
  103.     my $o = shift || {};
  104.     my $prefix = shift || "";
  105.  
  106.     add2hash($o->{mouse} ||= {}, { getVarsFromSh("$prefix/etc/sysconfig/mouse") });
  107.  
  108.     if (my %keyboard = getVarsFromSh "$prefix/etc/sysconfig/keyboard") {
  109.     $o->{keyboard}{xkb_keymap} ||= keymap_translate($keyboard{KEYTABLE}) if $keyboard{KEYTABLE};
  110.     }
  111.     $o;
  112. }
  113.  
  114. sub getinfoFromDDC {
  115.     my $o = shift || {};
  116.     my $O = $o->{monitor} ||= {};
  117.     
  118.     devices::make("/dev/zero"); 
  119.     my ($m, @l) = `ddcxinfos`;
  120.     $? == 0 or return $o;
  121.  
  122.     $o->{card}{memory} ||= to_int($m);
  123.     while (($_ = shift @l) ne "\n") {
  124.     my ($depth, $x, $y) = split;
  125.     $depth = int(log($depth) / log(2));
  126.     if ($depth >= 8 && $x >= 640) {
  127.         push @{$o->{card}{depth}{$depth}}, [ $x, $y ] unless scalar grep { $_->[0] == $x && $_->[1] == $y } @{$o->{card}{depth}{$depth}};
  128.         push @{$o->{card}{depth}{32}}, [ $x, $y ] if $depth == 24 && ! scalar grep { $_->[0] == $x && $_->[1] == $y } @{$o->{card}{depth}{32}};
  129.     }
  130.     }
  131.     my ($h, $v, $size, @m) = @l;
  132.  
  133.     chop $h; chop $v;
  134.     $O->{hsyncrange} ||= $h;
  135.     $O->{vsyncrange} ||= $v;
  136.     $O->{size} ||= to_float($size);
  137.     $O->{modelines} ||= join '', @m;
  138.     $o;
  139. }
  140.