summaryrefslogtreecommitdiffstats
path: root/perl-install/Xconfig.pm
blob: af03b4019787e5269fb548a30818d341f76af0a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package Xconfig;

use diagnostics;
use strict;

use common qw(:common :file :system);
use mouse;
use devices;
use Xconfigurator;

# otherwise uses the rule substr($keymap, 0, 2)
my %keymap_translate = (
    cf => "ca_enhanced",
    uk => "gb",
);


1;

sub keymap_translate {
    $keymap_translate{$_[0]} || substr($_[0], 0, 2);
}


sub getinfo {
    my $o = {};
#    getinfoFromXF86Config($o);
    getinfoFromDDC($o);
    getinfoFromSysconfig($o);

    add2hash($o->{mouse}, mouse::detect()) unless $o->{mouse}{XMOUSETYPE};

    $o->{mouse}{device} ||= "mouse" if -e "/dev/mouse";
    $o;
}

sub getinfoFromXF86Config {
    my $o = shift || {};
    my $prefix = shift || "";
    my (%c, $depth, $driver);

    $o->{card}{server} ||= $1 if readlink("$prefix/etc/X11/X") =~ /XF86_ (\w+)$/x; #- /x for perl2fcalls

    local *F;
    open F, "$prefix/etc/X11/XF86Config" or return {};
    foreach (<F>) {
	if (/^Section "Keyboard"/ .. /^EndSection/) {
	    $o->{keyboard}{altmeta} ||= ($1 eq "ModeShift" ? 1 : 0) if /^\s*RightAlt\s+"(.*?)"/;
	    $o->{keyboard}{xkb_keymap} ||= $1 if /^\s*XkbLayout\s+"(.*?)"/;
	} elsif (/^Section "Pointer"/ .. /^EndSection/) {
	    $o->{mouse}{XMOUSETYPE} ||= $1 if /^\s*Protocol\s+"(.*?)"/;
	    $o->{mouse}{device} ||= $1 if m|^\s*Device\s+"/dev/(.*?)"|;
	    $o->{mouse}{XEMU3} ||= 1 if m/^\s*Emulate3Buttons\s+/;
	    $o->{mouse}{cleardtrrts} ||= 1 if m/^\s*ClearDTR\s+/;
	    $o->{mouse}{cleardtrrts} ||= 1 if m/^\s*ClearRTS\s+/;
	} elsif (my $i = /^Section "Device"/ .. /^EndSection/) {
	    %c = () if $i == 1;

	    $c{type} ||= $1 if /^\s*Identifier\s+"(.*?)"/;
	    $c{memory} ||= $1 if /VideoRam\s+(\d+)/;
	    $c{flags}{needVideoRam} ||= 1 if /^\s*VideoRam\s+/;
	    $c{vendor} ||= $1 if /^\s*VendorName\s+"(.*?)"/;
	    $c{board} ||= $1 if /^\s*BoardName\s+"(.*?)"/;
	    $c{options}{$1} ||= 1 if /^\s*Option\s+"(.*?)"/;
	    $c{options}{$1} ||= 0 if /^\s*#\s*Option\s+"(.*?)"/;

	    #- clockchip, ramdac, dacspeed read with following line.
	    push @{$c{lines}}, $_ unless /(Section|Identifier|VideoRam|VendorName|BoardName|Option)/;

	    add2hash($o->{card} ||= {}, \%c) if ($i =~ /E0/ && $c{type} && $c{type} ne "Generic VGA");
	} elsif (/^Section "Monitor"/ .. /^EndSection/) {
	    $o->{monitor}{type} ||= $1 if /^\s*Identifier\s+"(.*?)"/;
	    $o->{monitor}{hsyncrange} ||= $1 if /^\s*HorizSync\s+(.*)/;
	    $o->{monitor}{vsyncrange} ||= $1 if /^\s*VertRefresh\s+(.*)/;
	    $o->{monitor}{vendor} ||= $1 if /^\s*VendorName\s+"(.*?)"/;
	    $o->{monitor}{model} ||= $1 if /^\s*ModelName\s+"(.*?)"/;
	    $o->{monitor}{modelines} .= $_ if /^\s*Mode[lL]ine\s+/;
	} elsif (my $s = /^Section "Screen"/ .. /^EndSection/) {
	    undef $driver if $s == 1;
	    $driver = $1 if /^\s*Driver\s+"(.*?)"/;
	    #- print "($driver eq $Xconfigurator::serversdriver{$o->{card}{server}})";
	    if ($driver eq $Xconfigurator::serversdriver{$o->{card}{server}}) { #- take into account the right screen section for the server.
		$o->{card}{default_depth} ||= $1 if /^\s*DefaultColorDepth\s+(\d+)/;
		if (my $i = /^\s*Subsection\s+"Display"/ .. /^\s*EndSubsection/) {
		    undef $depth if $i == 1;
		    $depth = $1 if /^\s*Depth\s+(\d*)/;
		    if (/^\s*Modes\s+(.*)/) {
			my $a = 0;
			push @{$o->{card}{depth}{$depth || 8}},
		            grep { $_->[0] >= 640 } map { [ /"(\d+)x(\d+)"/ ] } split ' ', $1;
		    }
		}
	    }
	}
    }
    #- get the default resolution.
    my @depth = keys %{$o->{card}{depth}};
    $o->{resolution_wanted} ||=
      $o->{card}{depth}{$o->{card}{default_depth} || $depth[0]}[0][0] . "x" .
	$o->{card}{depth}{$o->{card}{default_depth} || $depth[0]}[0][1];
    $o;
}

sub getinfoFromSysconfig {
    my $o = shift || {};
    my $prefix = shift || "";

    add2hash($o->{mouse} ||= {}, { getVarsFromSh("$prefix/etc/sysconfig/mouse") });

    if (my %keyboard = getVarsFromSh "$prefix/etc/sysconfig/keyboard") {
	$keyboard{KEYTABLE} or last;
	$o->{keyboard}{xkb_keymap} ||= keymap_translate($keyboard{KEYTABLE});
    }
    $o;
}

sub getinfoFromDDC {
    my $o = shift || {};
    my $O = $o->{monitor} ||= {};
    #- return $o if $O->{hsyncrange} && $O->{vsyncrange} && $O->{modelines};
    devices::make("/dev/zero"); #- needed by ddcxinfos
    my ($m, @l) = `ddcxinfos`;
    $? == 0 or return $o;

    $o->{card}{memory} ||= to_int($m);
    while (($_ = shift @l) ne "\n") {
	my ($depth, $x, $y) = split;
	$depth = int(log($depth) / log(2));
	if ($depth >= 8 && $x >= 640) {
	    push @{$o->{card}{depth}{$depth}}, [ $x, $y ] unless scalar grep { $_->[0] == $x && $_->[1] == $y } @{$o->{card}{depth}{$depth}};
	    push @{$o->{card}{depth}{32}}, [ $x, $y ] if $depth == 24 && ! scalar grep { $_->[0] == $x && $_->[1] == $y } @{$o->{card}{depth}{32}};
	}
    }
    my ($h, $v, $size, @m) = @l;

    chop $h; chop $v;
    $O->{hsyncrange} ||= $h;
    $O->{vsyncrange} ||= $v;
    $O->{size} ||= to_float($size);
    $O->{modelines} ||= join '', @m;
    $o;
}
"accel", 'Mono' => "vga2", 'VGA16' => "vga16", 'FBDev' => "fbdev", ); @svgaservers = grep { $serversdriver{$_} eq "svga" } keys(%serversdriver); @accelservers = grep { $serversdriver{$_} eq "accel" } keys(%serversdriver); @allbutfbservers = grep { $serversdriver{$_} ne "fbdev" } keys(%serversdriver); @allservers = keys(%serversdriver); %vgamodes = ( '640xx8' => 769, '640x480x8' => 769, '800xx8' => 771, '800x600x8' => 771, '1024xx8' => 773, '1024x768x8' => 773, '1280xx8' => 775, '1280x1024x8' => 775, '640xx15' => 784, '640x480x15' => 784, '800xx15' => 787, '800x600x15' => 787, '1024xx15' => 790, '1024x768x15' => 790, '1280xx15' => 793, '1280x1024x15' => 793, '640xx16' => 785, '640x480x16' => 785, '800xx16' => 788, '800x600x16' => 788, '1024xx16' => 791, '1024x768x16' => 791, '1280xx16' => 794, '1280x1024x16' => 794, #- '640xx24' => 786, #- there is a problem with these resolutions since the BIOS may take 24 or 32 planes. #- '640x480x24' => 786, #- '800xx24' => 789, #- '800x600x24' => 789, #- '1024xx24' => 792, #- '1024x768x24' => 792, #- '1280xx24' => 795, #- '1280x1024x24' => 795, ); { #- @monitorSize2resolution my %l = my @l = ( #- size in inch 13 => "640x480", 14 => "800x600", 15 => "800x600", 16 => "1024x768", 17 => "1152x864", 18 => "1280x1024", 19 => "1280x1024", 20 => "1600x1200", ); for (my $i = 0; $i < $l[0]; $i++) { $monitorSize2resolution[$i] = $l[1]; } while (my ($s, $r) = each %l) { $monitorSize2resolution[$s] = $r; } } %videomemory = ( __("256 kB") => 256, __("512 kB") => 512, __("1 MB") => 1024, __("2 MB") => 2048, __("4 MB") => 4096, __("8 MB") => 8192, __("16 MB or more") => 16384, ); %standard_monitors = ( __("Standard VGA, 640x480 at 60 Hz") => [ '640x480@60', "31.5" , "60" ], __("Standard VGA, 640x480 at 60 Hz") => [ '640x480@60', "31.5" , "60" ], __("Super VGA, 800x600 at 56 Hz") => [ '800x600@56', "31.5-35.1" , "55-60" ], __("8514 Compatible, 1024x768 at 87 Hz interlaced (no 800x600)") => [ '8514 compatible', "31.5,35.5" , "60,70,87" ], __("Super VGA, 1024x768 at 87 Hz interlaced, 800x600 at 56 Hz") => [ '1024x768@87i', "31.5,35.15,35.5" , "55-90" ], __("Extended Super VGA, 800x600 at 60 Hz, 640x480 at 72 Hz") => [ '800x600@60', "31.5-37.9" , "55-90" ], __("Non-Interlaced SVGA, 1024x768 at 60 Hz, 800x600 at 72 Hz") => [ '1024x768@60', "31.5-48.5" , "55-90" ], __("High Frequency SVGA, 1024x768 at 70 Hz") => [ '1024x768@70', "31.5-57.0" , "50-90" ], __("Multi-frequency that can do 1280x1024 at 60 Hz") => [ '1280x1024@60', "31.5-64.3" , "50-90" ], __("Multi-frequency that can do 1280x1024 at 74 Hz") => [ '1280x1024@74', "31.5-79.0" , "50-100" ], __("Multi-frequency that can do 1280x1024 at 76 Hz") => [ '1280x1024@76', "31.5-82.0" , "40-100" ], __("Monitor that can do 1600x1200 at 70 Hz") => [ '1600x1200@70', "31.5-88.0" , "50-120" ], __("Monitor that can do 1600x1200 at 76 Hz") => [ '1600x1200@76', "31.5-94.0" , "50-160" ], ); @vsyncranges = ("50-70", "50-90", "50-100", "40-150"); @hsyncranges = ( "31.5", "31.5-35.1", "31.5, 35.5", "31.5, 35.15, 35.5", "31.5-37.9", "31.5-48.5", "31.5-57.0", "31.5-64.3", "31.5-79.0", "31.5-82.0", "31.5-88.0", "31.5-94.0", ); %min_hsync4wres = ( 640 => 31.5, 800 => 35.1, 1024 => 35.5, 1152 => 44.0, 1280 => 51.0, 1600 => 75.0, ); %lines = ( #- 'Cirrus Logic|GD 5446' => [ ' Option "no_bitblt"' ], ); #- most usefull server options have to be accessible at the beginning, since #- no more than a small set of options will be available for the user, maybe ? @options = ( [ 'power_saver', 'Mono', '.*' ], [ 'hibit_low', 'VGA16', 'Tseng.*ET4000' ], [ 'hibit_high', 'VGA16', 'Tseng.*ET4000' ], [ 'power_saver', 'VGA16', '.*' ], [ 'noaccel', 'SVGA', 'Cirrus|C&T|SiS|Oak|Western Digital|Alliance|Trident|Tseng' ], [ 'no_accel', 'SVGA', 'ARK|MGA|i740|Oak|ET6000|W32|Media.*GX|Neomagic' ], [ 'linear', 'SVGA', 'Cirrus|ET6000|ET4000/W32p rev [CD]|Oak|Neomagic|Triden|Tseng' ], [ 'nolinear', 'SVGA', 'Cirrus|C&T|Trident' ], [ 'no_linear', 'SVGA', 'ARK|SiS|Neomagic|Tseng' ], [ 'no_bitblt', 'SVGA', 'Cirrus|C&T|SiS' ], [ 'no_imageblt', 'SVGA', 'Cirrus|C&T|SiS' ], [ 'sw_cursor', 'SVGA', '.*' ], [ 'slow_dram', 'SVGA', 'Cirrus|Trident|ET6000|W32|Western Digital|Tseng' ], [ 'mga_sdram', 'SVGA', 'MGA' ], [ 'no_pixmap_cache', 'SVGA', 'ARK|Cirrus|C&T|MGA|SiS|Trident.*9440|Trident.*9680|Tseng' ], [ 'no_mmio', 'SVGA', 'Cirrus|Neomagic|Trident' ], [ 'pci_burst_off', 'SVGA', 'ET6000|W32|Trident|Tseng' ], [ 'hw_clocks', 'SVGA', 'SiS|C&T' ], [ 'use_modeline', 'SVGA', 'C&T' ], [ 'enable_bitblt', 'SVGA', 'Oak' ], [ 'w32_interleave_off', 'SVGA', 'ET6000|W32|Tseng' ], [ 'fifo_conservative', 'SVGA', 'Cirrus|ARK|SiS|Oak' ], [ 'fifo_moderate', 'SVGA', 'Cirrus|ARK|SiS' ], [ 'all_wait', 'SVGA', 'Oak' ], [ 'one_wait', 'SVGA', 'Oak' ], [ 'first_wait', 'SVGA', 'Oak' ], [ 'first_wwait', 'SVGA', 'Oak' ], [ 'write_wait', 'SVGA', 'Oak' ], [ 'read_wait', 'SVGA', 'Oak' ], [ 'clgd6225_lcd', 'SVGA', 'Cirrus' ], [ 'fix_panel_size', 'SVGA', 'C&T' ], [ 'lcd_center', 'SVGA', 'C&T|Neomagic|Trident' ], [ 'cyber_shadow', 'SVGA', 'Trident' ], [ 'STN', 'SVGA', 'C&T' ], [ 'no_stretch', 'SVGA', 'C&T|Cirrus|Neomagic|Trident' ], [ 'no_prog_lcd_mode_regs', 'SVGA', 'Neomagic' ], [ 'prog_lcd_mode_stretch', 'SVGA', 'Neomagic' ], [ 'suspend_hack', 'SVGA', 'C&T' ], [ 'use_18bit_bus', 'SVGA', 'C&T' ], [ 'hibit_low', 'SVGA', 'Tseng.*ET4000' ], [ 'hibit_high', 'SVGA', 'Tseng.*ET4000' ], [ 'probe_clocks', 'SVGA', 'Cirrus' ], [ 'power_saver', 'SVGA', '.*' ], [ 'use_vlck1', 'SVGA', 'C&T' ], [ 'sgram', 'SVGA', 'i740' ], [ 'sdram', 'SVGA', 'i740' ], [ 'no_2mb_banksel', 'SVGA', 'Cirrus' ], [ 'tgui_pci_read_on', 'SVGA', 'Trident' ], [ 'tgui_pci_write_on', 'SVGA', 'Trident' ], [ 'no_program_clocks', 'SVGA', 'Trident' ], [ 'mmio', 'SVGA', 'Cirrus|C&T|Neomagic' ], [ 'sync_on_green', 'SVGA', 'C&T|MGA' ], [ 'pci_retry', 'SVGA', 'Tseng|MGA|Cirrus' ], [ 'hw_cursor', 'SVGA', 'C&T|SiS|ARK|ET6000|i740|Tseng' ], [ 'xaa_no_color_exp', 'SVGA', 'C&T|Cirrus|Trident|Tseng' ], [ 'xaa_benchmarks', 'SVGA', 'C&T' ], [ 'pci_burst_on', 'SVGA', 'Trident|Tseng' ], [ 'prog_lcd_mode_regs', 'SVGA', 'Neomagic' ], [ 'no_prog_lcd_mode_stretch', 'SVGA', 'Neomagic' ], [ 'no_wait', 'SVGA', 'Oak' ], #- [ 'med_dram', 'SVGA', 'Cirrus|Trident|Western Digital' ], #- WARNING, MAY DAMAGE CARD #- [ 'fast_dram', 'SVGA', 'C&T|Cirrus|ET[46]000|Trident|Western Digital' ], #- WARNING, MAY DAMAGE CARD #- [ 'fast_vram', 'SVGA', 'SiS' ], #- WARNING, MAY DAMAGE CARD #- [ 'clock_50', 'SVGA', 'Oak' ], #- WARNING, MAY DAMAGE CARD #- [ 'clock_66', 'SVGA', 'Oak' ], #- WARNING, MAY DAMAGE CARD #- [ 'fifo_aggressive', 'SVGA', 'Cirrus|ARK|SiS|Oak' ], #- WARNING, MAY DAMAGE CARD #- [ 'override_validate_mode', 'SVGA', 'Neomagic' ], #- WARNING, MAY DAMAGE CARD