summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2007-04-25 10:04:32 +0000
committerPascal Rigaux <pixel@mandriva.com>2007-04-25 10:04:32 +0000
commit48524e2dc24bae1e80dc7a39e490fe37c089adf3 (patch)
tree65b80153beda525c57dfeafb6134ce56385cc8ab /lib
parent0f62ff37f66fe87ebdf474831e8bf38c61c44f43 (diff)
downloaddrakx-kbd-mouse-x11-48524e2dc24bae1e80dc7a39e490fe37c089adf3.tar
drakx-kbd-mouse-x11-48524e2dc24bae1e80dc7a39e490fe37c089adf3.tar.gz
drakx-kbd-mouse-x11-48524e2dc24bae1e80dc7a39e490fe37c089adf3.tar.bz2
drakx-kbd-mouse-x11-48524e2dc24bae1e80dc7a39e490fe37c089adf3.tar.xz
drakx-kbd-mouse-x11-48524e2dc24bae1e80dc7a39e490fe37c089adf3.zip
re-sync after the big svn loss
Diffstat (limited to 'lib')
-rw-r--r--lib/Xconfig/FILES6
-rw-r--r--lib/Xconfig/card.pm635
-rw-r--r--lib/Xconfig/default.pm45
-rw-r--r--lib/Xconfig/main.pm262
-rw-r--r--lib/Xconfig/monitor.pm275
-rw-r--r--lib/Xconfig/parse.pm205
-rw-r--r--lib/Xconfig/proprietary.pm35
-rw-r--r--lib/Xconfig/resolution_and_depth.pm386
-rw-r--r--lib/Xconfig/screen.pm29
-rw-r--r--lib/Xconfig/test.pm140
-rw-r--r--lib/Xconfig/various.pm178
-rw-r--r--lib/Xconfig/xfree.pm742
12 files changed, 2938 insertions, 0 deletions
diff --git a/lib/Xconfig/FILES b/lib/Xconfig/FILES
new file mode 100644
index 0000000..f6352de
--- /dev/null
+++ b/lib/Xconfig/FILES
@@ -0,0 +1,6 @@
+
+parse --- xfree ---- default ------------------ main
+ \--- card -------------------/ test
+ \-- monitor ---------------/ various
+ \- screen ---------------/ proprietary
+ \ resolution_and_depth-/
diff --git a/lib/Xconfig/card.pm b/lib/Xconfig/card.pm
new file mode 100644
index 0000000..686957d
--- /dev/null
+++ b/lib/Xconfig/card.pm
@@ -0,0 +1,635 @@
+package Xconfig::card; # $Id$
+
+use diagnostics;
+use strict;
+
+use detect_devices;
+use modules;
+use common;
+use log;
+
+
+my %VideoRams = (
+ 256 => N_("256 kB"),
+ 512 => N_("512 kB"),
+ 1024 => N_("1 MB"),
+ 2048 => N_("2 MB"),
+ 4096 => N_("4 MB"),
+ 8192 => N_("8 MB"),
+ 16384 => N_("16 MB"),
+ 32768 => N_("32 MB"),
+ 65536 => N_("64 MB or more"),
+);
+
+my $lib = arch() =~ /x86_64/ ? "lib64" : "lib";
+
+my @xfree4_Drivers = ((arch() =~ /^sparc/ ? qw(sunbw2 suncg14 suncg3 suncg6 sunffb sunleo suntcx) :
+ qw(apm ark chips cirrus cyrix glide i128 i740 i810 imstt
+ mga neomagic newport nv rendition r128 radeon vesa
+ s3 s3virge savage siliconmotion sis tdfx tga trident tseng vmware)),
+ qw(ati glint vga fbdev));
+
+sub from_raw_X {
+ my ($raw_X) = @_;
+
+ my $device = $raw_X->get_device or die "no card configured";
+
+ my $card = {
+ use_DRI_GLX => eval { any { /dri/ } $raw_X->get_modules },
+ %$device,
+ };
+ add_to_card__using_Cards($card, $card->{BoardName});
+ $card;
+}
+
+sub to_raw_X {
+ my ($card, $raw_X) = @_;
+
+ my @cards = ($card, @{$card->{cards} || []});
+
+ foreach (@cards) {
+ #- Specific ATI fglrx driver default options
+ if ($_->{Driver} eq 'fglrx') {
+ # $default_ATI_fglrx_config need to be move in proprietary ?
+ $_->{raw_LINES} ||= default_ATI_fglrx_config();
+ }
+ if (arch() =~ /ppc/ && ($_->{Driver} eq 'r128' || $_->{Driver} eq 'radeon')) {
+ $_->{UseFBDev} = 1;
+ }
+ }
+
+ $raw_X->set_devices(@cards);
+
+ $raw_X->get_ServerLayout->{Xinerama} = { commented => !$card->{Xinerama}, Option => 1 }
+ if defined $card->{Xinerama};
+
+ # cleanup previous special nvidia libglx
+ $raw_X->remove_load_module($_) foreach @{$card->{REMOVE_GLX} || []};
+
+ if ($card->{DRI_GLX_SPECIAL}) {
+ $raw_X->remove_load_module('glx'); # this doesn't duplicate the above glx line
+ # This loads the NVIDIA GLX extension module.
+ # IT IS IMPORTANT TO KEEP NAME AS FULL PATH TO libglx.so ELSE
+ # IT WILL LOAD XFree86 glx module and the server will crash.
+ $raw_X->add_load_module($card->{DRI_GLX_SPECIAL});
+ } else {
+ $raw_X->set_load_module('glx', $card->{Driver} ne 'fbdev'); #- glx for everyone, except proprietary nvidia and fbdev
+ $raw_X->set_load_module('dri', $card->{use_DRI_GLX});
+ }
+
+ $raw_X->remove_Section('DRI');
+
+ $raw_X->remove_load_module('v4l') if $card->{use_DRI_GLX} && $card->{Driver} eq 'r128';
+}
+
+sub default_ATI_fglrx_config() { our $default_ATI_fglrx_config }
+
+sub probe() {
+#-for Pixel tests
+#- my @c = { driver => 'Card:Matrox Millennium G400 DualHead', description => 'Matrox|Millennium G400 Dual HeadCard' };
+ my @c = detect_devices::matching_driver__regexp('^(Card|Server|Driver):');
+
+ my @cards = map {
+ my @l = $_->{description} =~ /(.*?)\|(.*)/;
+ my $card = {
+ description => $_->{description},
+ VendorName => $l[0], BoardName => $l[1],
+ BusID => "PCI:$_->{pci_bus}:$_->{pci_device}:$_->{pci_function}",
+ };
+ if ($_->{driver} =~ /Card:(.*)/) { $card->{BoardName} = $1; add_to_card__using_Cards($card, $1) }
+ elsif ($_->{driver} =~ /Driver:(.*)/) { $card->{Driver} = $1 }
+ else { internal_error() }
+
+ $card;
+ } @c;
+
+ if (@cards >= 2 && $cards[0]{card_name} eq $cards[1]{card_name} && $cards[0]{card_name} eq 'Intel 830') {
+ shift @cards;
+ }
+ #- take a default on sparc if nothing has been found.
+ if (arch() =~ /^sparc/ && !@cards) {
+ log::l("Using probe with /proc/fb as nothing has been found!");
+ my $s = cat_("/proc/fb");
+ @cards = { server => $s =~ /Mach64/ ? "Mach64" : $s =~ /Permedia2/ ? "3DLabs" : "Sun24" };
+ }
+
+ #- disabling MULTI_HEAD when not available
+ foreach (@cards) {
+ $_->{MULTI_HEAD} && $_->{card_name} =~ /G[24]00/ or next;
+ if ($ENV{MATROX_HAL}) {
+ $_->{need_MATROX_HAL} = 1;
+ } else {
+ delete $_->{MULTI_HEAD};
+ }
+ }
+
+ #- in case of only one cards, remove all BusID reference, this will avoid
+ #- need of change of it if the card is moved.
+ #- on many PPC machines, card is on-board, BusID is important, leave?
+ if (@cards == 1 && !$cards[0]{MULTI_HEAD} && arch() !~ /ppc/) {
+ delete $cards[0]{BusID};
+ }
+
+ @cards;
+}
+
+sub card_config__not_listed {
+ my ($in, $card, $options) = @_;
+
+ my $vendors_regexp = join '|', map { quotemeta } (
+ '3Dlabs',
+ 'AOpen', 'ASUS', 'ATI', 'Ark Logic', 'Avance Logic',
+ 'Cardex', 'Chaintech', 'Chips & Technologies', 'Cirrus Logic', 'Compaq', 'Creative Labs',
+ 'Dell', 'Diamond', 'Digital',
+ 'ET', 'Elsa',
+ 'Genoa', 'Guillemot', 'Hercules', 'Intel', 'Leadtek',
+ 'Matrox', 'Miro', 'NVIDIA', 'NeoMagic', 'Number Nine',
+ 'Oak', 'Orchid',
+ 'RIVA', 'Rendition Verite',
+ 'S3', 'Silicon Motion', 'STB', 'SiS', 'Sun',
+ 'Toshiba', 'Trident',
+ 'VideoLogic',
+ );
+ my $cards = readCardsDB("$ENV{SHARE_PATH}/ldetect-lst/Cards+");
+
+ my @xf4 = grep { $options->{allowFB} || $::isStandalone || $_ ne 'fbdev' } @xfree4_Drivers;
+ my @list = (
+ (map { 'Vendor|' . $_ } keys %$cards),
+ (map { 'Xorg|' . $_ } @xf4),
+ );
+
+ my $r = exists $cards->{$card->{BoardName}} ? "Vendor|$card->{BoardName}" : 'Xorg|vesa';
+ $in->ask_from_({ title => N("X server"),
+ messages => N("Choose an X server"),
+ interactive_help_id => 'configureX_card_list',
+ },
+ [ { val => \$r, separator => '|', list => \@list, sort => 1,
+ format => sub { $_[0] =~ /^Vendor\|($vendors_regexp)\s*-?(.*)/ ? "Vendor|$1|$2" :
+ $_[0] =~ /^Vendor\|(.*)/ ? "Vendor|Other|$1" : $_[0] } } ]) or return;
+
+ log::explanations("Xconfig::card: $r manually chosen");
+
+ $r eq "Vendor|$card->{BoardName}" and return 1; #- it is unchanged, do not modify $card
+
+ my ($kind, $s) = $r =~ /(.*?)\|(.*)/;
+
+ %$card = ();
+ if ($kind eq 'Vendor') {
+ add_to_card__using_Cards($card, $s);
+ } else {
+ $card->{Driver} = $s;
+ }
+ $card->{manually_chosen} = 1;
+ 1;
+}
+
+sub multi_head_choose {
+ my ($in, $auto, @cards) = @_;
+
+ my @choices = multi_head_choices('', @cards);
+
+ my $tc = $choices[0];
+ if ($auto) {
+ @choices == 1 or return;
+ } else {
+ $tc = $in->ask_from_listf(N("Multi-head configuration"),
+ N("Your system supports multiple head configuration.
+What do you want to do?"), sub { $_[0]{text} }, \@choices) or return;
+ }
+ $tc->{code} or die internal_error();
+ return $tc->{code}();
+}
+
+sub configure_auto_install {
+ my ($raw_X, $do_pkgs, $old_X, $options) = @_;
+
+ my $card = $old_X->{card} || {};
+
+ if ($card->{card_name}) {
+ #- try to get info from given card_name
+ add_to_card__using_Cards($card, $card->{card_name});
+ if (!$card->{Driver}) {
+ log::l("bad card_name $card->{card_name}, using probe");
+ undef $card->{card_name};
+ }
+ }
+
+ if (!$card->{Driver}) {
+ my @cards = probe();
+ my ($choice) = multi_head_choices($old_X->{Xinerama}, @cards);
+ $card = $choice ? $choice->{code}() : do {
+ log::explanations('no graphic card probed, try providing one using $o->{card}{Driver} or $o->{card}{card_name}. Defaulting...');
+ { Driver => $options->{allowFB} ? 'fbdev' : 'vesa' };
+ };
+ }
+
+ my ($glx_choice) = xfree_and_glx_choices($card);
+ log::explanations("Using $glx_choice->{text}");
+ $glx_choice->{code}();
+ set_glx_restrictions($card);
+
+ install_server($card, $options, $do_pkgs);
+ if ($card->{needVideoRam} && !$card->{VideoRam}) {
+ $card->{VideoRam} = $options->{VideoRam_probed} || 4096;
+ log::explanations("argh, I need to know VideoRam! Taking " . ($options->{probed_VideoRam} ? "the probed" : "a default") . " value: VideoRam = $card->{VideoRam}");
+ }
+ to_raw_X($card, $raw_X);
+ $card;
+}
+
+sub configure {
+ my ($in, $raw_X, $do_pkgs, $auto, $options) = @_;
+
+ my @cards = probe();
+ @cards or @cards = {};
+
+ if (!$cards[0]{Driver}) {
+ if ($options->{allowFB}) {
+ $cards[0]{Driver} = 'fbdev';
+ } elsif ($auto) {
+ log::explanations("Xconfig::card: auto failed (unknown card and no allowFB)");
+ return 0;
+ }
+ }
+ if (!$auto) {
+ card_config__not_listed:
+ card_config__not_listed($in, $cards[0], $options) or return;
+ }
+
+ my $card = multi_head_choose($in, $auto, @cards) or return;
+
+ xfree_and_glx_choose($in, $card, $auto) or return;
+
+ eval { install_server($card, $options, $do_pkgs) };
+ if ($@) {
+ $in->ask_warn('', N("Can not install Xorg package: %s", $@));
+ goto card_config__not_listed;
+ }
+
+ if ($card->{needVideoRam} && !$card->{VideoRam}) {
+ if ($auto) {
+ log::explanations("Xconfig::card: auto failed (needVideoRam)");
+ return;
+ }
+ $card->{VideoRam} = (find { $_ <= $options->{VideoRam_probed} } reverse ikeys %VideoRams) || 4096;
+ $in->ask_from('', N("Select the memory size of your graphics card"),
+ [ { val => \$card->{VideoRam},
+ type => 'list',
+ list => [ ikeys %VideoRams ],
+ format => sub { translate($VideoRams{$_[0]}) },
+ not_edit => !$::expert } ]) or return;
+ }
+
+ to_raw_X($card, $raw_X);
+ $card;
+}
+
+sub install_server {
+ my ($card, $options, $do_pkgs) = @_;
+
+ my $prog = "$::prefix/usr/X11R6/bin/Xorg";
+
+ my @packages;
+ push @packages, 'xorg-x11-server' if ! -x $prog;
+
+ #- additional packages to install according available card.
+ #- add XFree86-libs-DRI here if using DRI (future split of XFree86 TODO)
+ if ($card->{use_DRI_GLX}) {
+ push @packages, 'Glide_V5' if $card->{card_name} eq 'Voodoo5 (generic)';
+ push @packages, 'Glide_V3-DRI' if member($card->{card_name}, 'Voodoo3 (generic)', 'Voodoo Banshee (generic)');
+ push @packages, 'xorg-x11-glide-module' if $card->{card_name} =~ /Voodoo/;
+ }
+
+ if ($options->{freedriver}) {
+ delete $card->{Driver2};
+ }
+
+ my %nvidia_packages = (
+ #- using NVIDIA Legacy driver for old NVIDIA cards (TNT, TNT2, Vanta, Quadro, Quadro2, GeForce and GeForce2):
+ legacy => [ qw(nvidia_legacy-kernel nvidia_legacy) ],
+ #- using current NVIDIA driver for recent NVIDIA cards (Geforce/Quadro 3/4/FX/6x00/NVS):
+ new => [ qw(nvidia-kernel nvidia) ],
+ );
+
+ my %proprietary_Driver2 = (
+ nvidia => $nvidia_packages{ $card->{NVIDIA_LEGACY} ? 'legacy' : 'new' },
+ fglrx => [ 'ati-kernel', 'ati' ], #- using ATI fglrx driver (Radeon, Fire GL cards only).
+ );
+ if (my $rpms_needed = $proprietary_Driver2{$card->{Driver2}}) {
+ if (my $proprietary_packages = $do_pkgs->check_kernel_module_packages($rpms_needed->[0], $rpms_needed->[1])) {
+ push @packages, @$proprietary_packages;
+ # prevent having both nvidia & nvidia_legacy driver installed due to incompatibility:
+ if ($card->{Driver2} eq 'nvidia') {
+ $do_pkgs->remove($_) foreach @{$do_pkgs->check_kernel_module_packages(@{$nvidia_packages{ $card->{NVIDIA_LEGACY} ? 'new' : 'legacy' }})};
+ }
+ }
+ }
+
+ $do_pkgs->install(@packages) if @packages;
+ -x $prog or die "server not available (should be in $prog)";
+
+ my $modules_dir = "/usr/X11R6/$lib/modules";
+ my $new_nvidia_libglx = "$modules_dir/extensions/nvidia/libglx.so";
+ my $old_nvidia_libglx = "$modules_dir/extensions/libglx.so";
+ #- make sure everything is correct at this point, packages have really been installed
+ #- and driver and GLX extension is present.
+ if ($card->{Driver2} eq 'nvidia' &&
+ (-e "$::prefix$modules_dir/drivers/nvidia_drv.o" || -e "$::prefix$modules_dir/drivers/nvidia_drv.so")) {
+ #- when there is extensions/libglx.a, it means extensions/libglx.so is not xorg's libglx, so it may be nvidia's
+ #- new nvidia packages have libglx.so in extensions/nvidia instead of simply extensions/
+ my $libglx_a = -e "$::prefix$modules_dir/extensions/libglx.a";
+ my $libglx = find { -l "$::prefix$_" } $new_nvidia_libglx, if_($libglx_a, $old_nvidia_libglx);
+ if ($libglx) {
+ log::explanations("Using specific NVIDIA driver and GLX extensions");
+ $card->{Driver} = 'nvidia';
+ $card->{DRI_GLX_SPECIAL} = $libglx;
+ }
+ }
+ if ($card->{Driver2} eq 'fglrx' &&
+ -e "$::prefix$modules_dir/dri/fglrx_dri.so" &&
+ (-e "$::prefix$modules_dir/drivers/fglrx_drv.o" || -e "$::prefix$modules_dir/drivers/fglrx_drv.so")) {
+ log::explanations("Using specific ATI fglrx and DRI drivers");
+ $card->{Driver} = 'fglrx';
+ }
+ $card->{REMOVE_GLX} = [ $old_nvidia_libglx, $new_nvidia_libglx ];
+
+ libgl_config($card);
+
+ if ($card->{need_MATROX_HAL}) {
+ require Xconfig::proprietary;
+ Xconfig::proprietary::install_matrox_hal($::prefix);
+ }
+}
+
+sub xfree_and_glx_choose {
+ my ($in, $card, $auto) = @_;
+
+ my @choices = xfree_and_glx_choices($card);
+
+ my $tc =
+ $auto ? $choices[0] :
+ $in->ask_from_listf_raw({ title => N("Xorg configuration"),
+ messages => formatAlaTeX(join("\n\n\n", (grep { $_ } map { $_->{more_messages} } @choices),
+ N("Which configuration of Xorg do you want to have?"))),
+ interactive_help_id => 'configureX_xfree_and_glx',
+ },
+ sub { $_[0]{text} }, \@choices) or return;
+ log::explanations("Using $tc->{text}");
+ $tc->{code}();
+ set_glx_restrictions($card);
+ 1;
+}
+
+sub multi_head_choices {
+ my ($want_Xinerama, @cards) = @_;
+ my @choices;
+
+ my $has_multi_head = @cards > 1 || @cards && $cards[0]{MULTI_HEAD} > 1;
+ my $disable_multi_head = any {
+ $_->{Driver} or log::explanations("found card $_->{description} not supported by XF4, disabling multi-head support");
+ !$_->{Driver};
+ } @cards;
+
+ if ($has_multi_head && !$disable_multi_head) {
+ my $configure_multi_head = sub {
+
+ #- special case for multi head card using only one BusID.
+ @cards = map {
+ map_index { { Screen => $::i, %$_ } } ($_) x ($_->{MULTI_HEAD} || 1);
+ } @cards;
+
+ my $card = shift @cards; #- assume good default.
+ $card->{cards} = \@cards;
+ $card->{Xinerama} = $_[0];
+ $card;
+ };
+ my $independent = { text => N("Configure all heads independently"), code => sub { $configure_multi_head->('') } };
+ my $xinerama = { text => N("Use Xinerama extension"), code => sub { $configure_multi_head->(1) } };
+ push @choices, $want_Xinerama ? ($xinerama, $independent) : ($independent, $xinerama);
+ }
+
+ foreach my $c (@cards) {
+ push @choices, { text => N("Configure only card \"%s\"%s", $c->{description}, $c->{BusID} && " ($c->{BusID})"),
+ code => sub { $c } };
+ }
+ @choices;
+}
+
+#- Xorg version available, it would be better to parse available package and get version from it.
+sub xorg_version() { '6.9' }
+
+sub xfree_and_glx_choices {
+ my ($card) = @_;
+
+ my @choices = if_($card->{Driver}, { text => N("Xorg %s", xorg_version()), code => sub {} });
+
+ #- no GLX with Xinerama
+ return @choices if $card->{Xinerama};
+
+ #- ask the expert or any user on second pass user to enable or not hardware acceleration support.
+ if ($card->{DRI_GLX}) {
+ unshift @choices, { text => N("Xorg %s with 3D hardware acceleration", xorg_version()),
+ code => sub { $card->{use_DRI_GLX} = 1 },
+ more_messages => N("Your card can have 3D hardware acceleration support with Xorg %s.", xorg_version()),
+ };
+ }
+
+ #- an expert user may want to try to use an EXPERIMENTAL 3D acceleration.
+ if ($card->{DRI_GLX_EXPERIMENTAL} && $::expert) {
+ push @choices, { text => N("Xorg %s with EXPERIMENTAL 3D hardware acceleration", xorg_version()),
+ code => sub { $card->{use_DRI_GLX} = 1 },
+ more_messages => N("Your card can have 3D hardware acceleration support with Xorg %s,
+NOTE THIS IS EXPERIMENTAL SUPPORT AND MAY FREEZE YOUR COMPUTER.", xorg_version()),
+ };
+ }
+ @choices;
+}
+
+sub set_glx_restrictions {
+ my ($card) = @_;
+
+ #- 3D acceleration configuration for XFree 4 using DRI, this is enabled by default
+ #- but for some there is a need to specify VideoRam (else it will not run).
+ if ($card->{use_DRI_GLX}) {
+ $card->{needVideoRam} = 1 if $card->{description} =~ /Matrox.* G[245][05]0/;
+ ($card->{needVideoRam}, $card->{VideoRam}) = (1, 16384)
+ if member($card->{card_name}, 'Intel 810', 'Intel 815');
+
+ #- hack for ATI Rage 128 card using a bttv or peripheral with PCI bus mastering exchange
+ #- AND using DRI at the same time.
+ if (member($card->{card_name}, 'ATI Rage 128', 'ATI Rage 128 TVout', 'ATI Rage 128 Mobility')) {
+ $card->{Options}{UseCCEFor2D} = bool2text(modules::probe_category('multimedia/tv'));
+ }
+ }
+
+ #- check for Matrox G200 PCI cards, disable AGP in such cases, causes black screen else.
+ if (member($card->{card_name}, 'Matrox Millennium 200', 'Matrox Millennium 200', 'Matrox Mystique') && $card->{description} !~ /AGP/) {
+ log::explanations("disabling AGP mode for Matrox card, as it seems to be a PCI card");
+ log::explanations("this is only used for XFree 3.3.6, see /etc/X11/glx.conf");
+ substInFile { s/^\s*#*\s*mga_dma\s*=\s*\d+\s*$/mga_dma = 0\n/ } "$::prefix/etc/X11/glx.conf";
+ }
+}
+
+sub libgl_config {
+ my ($card) = @_;
+
+ my $dir = "$::prefix/etc/ld.so.conf.d";
+ my $comment = '# commented-by-DrakX ';
+
+ my %driver_to_libgl_config = (
+ nvidia => $card->{NVIDIA_LEGACY} ? 'nvidia_legacy.conf' : 'nvidia.conf',
+ nvidia_other => !$card->{NVIDIA_LEGACY} ? 'nvidia_legacy.conf' : 'nvidia.conf',
+ fglrx => 'ati.conf',
+ );
+ my $need_to_run_ldconfig;
+ my $wanted = $driver_to_libgl_config{$card->{Driver}};
+ foreach my $file (values %driver_to_libgl_config) {
+ substInFile {
+ my ($commented, $s) = /^(\Q$comment\E)?(.*)/;
+ if ($file eq $wanted) {
+ $_ = "$s\n";
+ $need_to_run_ldconfig ||= $commented;
+ } else {
+ $_ = "$comment$s\n";
+ $need_to_run_ldconfig ||= !$commented;
+ }
+ } "$dir/$file" if -e "$dir/$file";
+ }
+ if ($::isStandalone && $need_to_run_ldconfig) {
+ log::explanations("ldconfig will be run because the GL library was " . ($wanted ? 'enabled' : 'disabled'));
+ system("/sbin/ldconfig");
+ }
+}
+
+sub add_to_card__using_Cards {
+ my ($card, $name) = @_;
+ my $cards = readCardsDB("$ENV{SHARE_PATH}/ldetect-lst/Cards+");
+ add2hash($card, $cards->{$name});
+ $card->{BoardName} = $card->{card_name};
+
+ $card;
+}
+
+#- needed for bad cards not restoring cleanly framebuffer, according to which version of Xorg are used.
+sub check_bad_card {
+ my ($card) = @_;
+ my $bad_card = $card->{BAD_FB_RESTORE};
+ $bad_card ||= $card->{Driver} eq 'i810' || $card->{Driver} eq 'fbdev';
+ $bad_card ||= member($card->{Driver}, 'nvidia', 'vmware') if !$::isStandalone; #- avoid testing during install at any price.
+
+ log::explanations("the graphics card does not like X in framebuffer") if $bad_card;
+
+ !$bad_card;
+}
+
+sub readCardsDB {
+ my ($file) = @_;
+ my ($card, %cards);
+
+ my $F = openFileMaybeCompressed($file);
+
+ my $lineno = 0;
+ my ($cmd, $val);
+ my $fs = {
+ NAME => sub {
+ $cards{$card->{card_name}} = $card if $card;
+ $card = { card_name => $val };
+ },
+ SEE => sub {
+ my $c = $cards{$val} or die "Error in database, invalid reference $val at line $lineno";
+ add2hash($card, $c);
+ },
+ LINE => sub { $val =~ s/^\s*//; $card->{raw_LINES} .= "$val\n" },
+ CHIPSET => sub { $card->{Chipset} = $val },
+ DRIVER => sub { $card->{Driver} = $val },
+ DRIVER2 => sub { $card->{Driver2} = $val },
+ NEEDVIDEORAM => sub { $card->{needVideoRam} = 1 },
+ DRI_GLX => sub { $card->{DRI_GLX} = 1 if $card->{Driver} },
+ DRI_GLX_EXPERIMENTAL => sub { $card->{DRI_GLX_EXPERIMENTAL} = 1 if $card->{Driver} },
+ MULTI_HEAD => sub { $card->{MULTI_HEAD} = $val if $card->{Driver} },
+ BAD_FB_RESTORE => sub { $card->{BAD_FB_RESTORE} = 1 },
+ FB_TVOUT => sub { $card->{FB_TVOUT} = 1 },
+ UNSUPPORTED => sub { delete $card->{Driver} },
+ NVIDIA_LEGACY => sub { $card->{NVIDIA_LEGACY} = 1 },
+
+ COMMENT => sub {},
+ };
+
+ local $_;
+ while (<$F>) { $lineno++;
+ s/\s+$//;
+ /^#/ and next;
+ /^$/ and next;
+ /^END/ and do { $cards{$card->{card_name}} = $card if $card; last };
+
+ ($cmd, $val) = /(\S+)\s*(.*)/ or next;
+
+ my $f = $fs->{$cmd};
+
+ $f ? $f->() : log::l("unknown line $lineno ($_)");
+ }
+ \%cards;
+}
+
+our $default_ATI_fglrx_config = <<'END';
+# === disable PnP Monitor ===
+#Option "NoDDC"
+# === disable/enable XAA/DRI ===
+Option "no_accel" "no"
+Option "no_dri" "no"
+# === FireGL DDX driver module specific settings ===
+# === Screen Management ===
+Option "DesktopSetup" "0x00000000"
+Option "MonitorLayout" "AUTO, AUTO"
+Option "IgnoreEDID" "off"
+Option "HSync2" "unspecified"
+Option "VRefresh2" "unspecified"
+Option "ScreenOverlap" "0"
+# === TV-out Management ===
+Option "NoTV" "yes"
+Option "TVStandard" "NTSC-M"
+Option "TVHSizeAdj" "0"
+Option "TVVSizeAdj" "0"
+Option "TVHPosAdj" "0"
+Option "TVVPosAdj" "0"
+Option "TVHStartAdj" "0"
+Option "TVColorAdj" "0"
+Option "GammaCorrectionI" "0x00000000"
+Option "GammaCorrectionII" "0x00000000"
+# === OpenGL specific profiles/settings ===
+Option "Capabilities" "0x00000000"
+# === Video Overlay for the Xv extension ===
+Option "VideoOverlay" "on"
+# === OpenGL Overlay ===
+# Note: When OpenGL Overlay is enabled, Video Overlay
+# will be disabled automatically
+Option "OpenGLOverlay" "off"
+Option "CenterMode" "off"
+# === QBS Support ===
+Option "Stereo" "off"
+Option "StereoSyncEnable" "1"
+# === Misc Options ===
+Option "UseFastTLS" "0"
+Option "BlockSignalsOnLock" "on"
+Option "UseInternalAGPGART" "no"
+Option "ForceGenericCPU" "no"
+# === FSAA ===
+Option "FSAAScale" "1"
+Option "FSAADisableGamma" "no"
+Option "FSAACustomizeMSPos" "no"
+Option "FSAAMSPosX0" "0.000000"
+Option "FSAAMSPosY0" "0.000000"
+Option "FSAAMSPosX1" "0.000000"
+Option "FSAAMSPosY1" "0.000000"
+Option "FSAAMSPosX2" "0.000000"
+Option "FSAAMSPosY2" "0.000000"
+Option "FSAAMSPosX3" "0.000000"
+Option "FSAAMSPosY3" "0.000000"
+Option "FSAAMSPosX4" "0.000000"
+Option "FSAAMSPosY4" "0.000000"
+Option "FSAAMSPosX5" "0.000000"
+Option "FSAAMSPosY5" "0.000000"
+END
+
+1;
+
diff --git a/lib/Xconfig/default.pm b/lib/Xconfig/default.pm
new file mode 100644
index 0000000..d2fb0f7
--- /dev/null
+++ b/lib/Xconfig/default.pm
@@ -0,0 +1,45 @@
+package Xconfig::default; # $Id$
+
+use diagnostics;
+use strict;
+
+use Xconfig::xfree;
+use keyboard;
+use common;
+use mouse;
+use modules::any_conf;
+
+
+sub configure {
+ my ($do_pkgs, $o_keyboard, $o_mouse) = @_;
+
+ my $keyboard = $o_keyboard || keyboard::read_or_default();
+ my $mouse = $o_mouse || do {
+ my $mouse = mouse::read();
+ add2hash($mouse, mouse::detect(modules::any_conf->read)) if !$::noauto;
+ $mouse;
+ };
+
+ my $raw_X = Xconfig::xfree->empty_config;
+
+ $raw_X->add_load_module($_) foreach qw(dbe v4l extmod type1 freetype);
+
+ config_keyboard($raw_X, $keyboard);
+ config_mouse($raw_X, $do_pkgs, $mouse);
+
+ $raw_X;
+}
+
+sub config_mouse {
+ my ($raw_X, $do_pkgs, $mouse) = @_;
+ mouse::set_xfree_conf($mouse, $raw_X);
+ mouse::various_xfree_conf($do_pkgs, $mouse);
+}
+
+sub config_keyboard {
+ my ($raw_X, $keyboard) = @_;
+ $raw_X->set_keyboard(keyboard::keyboard2full_xkb($keyboard));
+}
+
+1;
+
diff --git a/lib/Xconfig/main.pm b/lib/Xconfig/main.pm
new file mode 100644
index 0000000..bdb4cbf
--- /dev/null
+++ b/lib/Xconfig/main.pm
@@ -0,0 +1,262 @@
+package Xconfig::main; # $Id$
+
+use diagnostics;
+use strict;
+
+use Xconfig::monitor;
+use Xconfig::card;
+use Xconfig::resolution_and_depth;
+use Xconfig::various;
+use Xconfig::screen;
+use Xconfig::test;
+use Xconfig::xfree;
+use common;
+
+
+sub configure_monitor {
+ my ($in) = @_;
+
+ my ($raw_X, $before) = Xconfig::xfree->read_and_prepare_write;
+ Xconfig::monitor::configure($in, $raw_X, int($raw_X->get_devices)) or return;
+ if ($raw_X->prepare_write ne $before) {
+ $raw_X->write;
+ 'need_restart';
+ } else {
+ '';
+ }
+}
+
+sub configure_resolution {
+ my ($in) = @_;
+
+ my ($raw_X, $before) = Xconfig::xfree->read_and_prepare_write;
+ my $X = {
+ card => Xconfig::card::from_raw_X($raw_X),
+ monitors => [ $raw_X->get_monitors ],
+ };
+ $X->{resolution} = Xconfig::resolution_and_depth::configure($in, $raw_X, $X->{card}, $X->{monitors}) or return;
+ if ($raw_X->prepare_write ne $before) {
+ &write($raw_X, $X);
+ } else {
+ '';
+ }
+}
+
+
+sub configure_everything_auto_install {
+ my ($raw_X, $do_pkgs, $old_X, $options) = @_;
+ my $X = {};
+ $X->{monitors} = Xconfig::monitor::configure_auto_install($raw_X, $old_X) or return;
+ $options->{VideoRam_probed} = $X->{monitors}[0]{VideoRam_probed};
+ $X->{card} = Xconfig::card::configure_auto_install($raw_X, $do_pkgs, $old_X, $options) or return;
+ Xconfig::screen::configure($raw_X) or return;
+ $X->{resolution} = Xconfig::resolution_and_depth::configure_auto_install($raw_X, $X->{card}, $X->{monitors}, $old_X);
+
+ my $action = &write($raw_X, $X);
+
+ Xconfig::various::runlevel(exists $old_X->{xdm} && !$old_X->{xdm} ? 3 : 5);
+
+ $action;
+}
+
+sub configure_everything {
+ my ($in, $raw_X, $do_pkgs, $auto, $options) = @_;
+ my $X = {};
+ my $ok = 1;
+
+ my $probed_info = Xconfig::monitor::probe($raw_X->get_Driver);
+ $options->{VideoRam_probed} = $probed_info->{VideoRam_probed};
+ $ok &&= $X->{card} = Xconfig::card::configure($in, $raw_X, $do_pkgs, $auto, $options);
+ $ok &&= $X->{monitors} = Xconfig::monitor::configure($in, $raw_X, int($raw_X->get_devices), $probed_info, $auto);
+ $ok &&= Xconfig::screen::configure($raw_X);
+ $ok &&= $X->{resolution} = Xconfig::resolution_and_depth::configure($in, $raw_X, $X->{card}, $X->{monitors}, $auto);
+ $ok &&= Xconfig::test::test($in, $raw_X, $X->{card}, '', 'skip_badcard') if !$auto;
+
+ if (!$ok) {
+ return if $auto;
+ ($ok) = configure_chooser_raw($in, $raw_X, $do_pkgs, $options, $X, 1);
+ }
+ $X->{various} ||= Xconfig::various::various($in, $X->{card}, $options, $auto);
+
+ may_write($in, $raw_X, $X, $ok);
+}
+
+sub configure_chooser_raw {
+ my ($in, $raw_X, $do_pkgs, $options, $X, $b_modified) = @_;
+
+ my %texts;
+
+ my $update_texts = sub {
+ $texts{card} = $X->{card} && $X->{card}{BoardName} || N("Custom");
+ $texts{monitors} = $X->{monitors} && $X->{monitors}[0]{ModelName} || N("Custom");
+ $texts{resolution} = Xconfig::resolution_and_depth::to_string($X->{resolution});
+
+ $texts{$_} =~ s/(.{20}).*/$1.../ foreach keys %texts; #- ensure not too long
+ };
+ $update_texts->();
+
+ my $may_set;
+ my $prompt_for_resolution = sub {
+ $may_set->('resolution', Xconfig::resolution_and_depth::configure($in, $raw_X, $X->{card}, $X->{monitors}));
+ };
+ $may_set = sub {
+ my ($field, $val) = @_;
+ if ($val) {
+ $X->{$field} = $val;
+ $X->{"modified_$field"} = 1;
+ $b_modified = 1;
+ $update_texts->();
+
+ if (member($field, 'card', 'monitors')) {
+ my ($default_resolution) = Xconfig::resolution_and_depth::choices($raw_X, $X->{resolution}, $X->{card}, $X->{monitors});
+ if (find { $default_resolution->{$_} ne $X->{resolution}{$_} } 'X', 'Y', 'Depth') {
+ $prompt_for_resolution->();
+ } else {
+ if ($default_resolution->{bios} && !$X->{resolution}{bios}) {
+ $may_set->('resolution', $default_resolution);
+ }
+ Xconfig::screen::configure($raw_X);
+ $raw_X->set_resolution($X->{resolution}) if $X->{resolution};
+ }
+ }
+ }
+ };
+
+ my $ok;
+ $in->ask_from_({ interactive_help_id => 'configureX_chooser',
+ if_($::isStandalone, ok => N("Quit")) },
+ [
+ { label => N("Graphic Card"), val => \$texts{card}, clicked => sub {
+ $may_set->('card', Xconfig::card::configure($in, $raw_X, $do_pkgs, 0, $options));
+ } },
+ { label => N("Monitor"), val => \$texts{monitors}, clicked => sub {
+ $may_set->('monitors', Xconfig::monitor::configure($in, $raw_X, int($raw_X->get_devices)));
+ } },
+ { label => N("Resolution"), val => \$texts{resolution}, disabled => sub { !$X->{card} || !$X->{monitors} },
+ clicked => $prompt_for_resolution },
+ if_(Xconfig::card::check_bad_card($X->{card}) || $::isStandalone,
+ { val => N("Test"), disabled => sub { !$X->{card} || !$X->{monitors} },
+ clicked => sub {
+ $ok = Xconfig::test::test($in, $raw_X, $X->{card}, 'auto', 0);
+ } },
+ ),
+ { val => N("Options"), clicked => sub {
+ Xconfig::various::various($in, $X->{card}, $options);
+ $X->{various} = 'done';
+ } },
+ ]);
+ $ok, $b_modified;
+}
+
+sub configure_chooser {
+ my ($in, $raw_X, $do_pkgs, $options) = @_;
+
+ my $X = {
+ card => scalar eval { Xconfig::card::from_raw_X($raw_X) },
+ monitors => [ $raw_X->get_monitors ],
+ resolution => scalar eval { $raw_X->get_resolution },
+ };
+ my $before = $raw_X->prepare_write;
+ my ($ok) = configure_chooser_raw($in, $raw_X, $do_pkgs, $options, $X);
+
+ if ($raw_X->prepare_write ne $before) {
+ may_write($in, $raw_X, $X, $ok);
+ } else {
+ '';
+ }
+}
+
+sub configure_everything_or_configure_chooser {
+ my ($in, $options, $auto, $o_keyboard, $o_mouse) = @_;
+
+ my $raw_X = eval { Xconfig::xfree->read };
+ my $err = $@ && formatError($@);
+ $err ||= check_valid($raw_X) if $raw_X && @$raw_X; #- that's ok if config is empty
+ if ($err) {
+ log::l("ERROR: bad X config file (error: $err)");
+ $options->{ignore_bad_conf} or $in->ask_okcancel('',
+ N("Your Xorg configuration file is broken, we will ignore it.")) or return;
+ $raw_X = [];
+ }
+
+ my $rc = 'ok';
+ if (is_empty_array_ref($raw_X)) {
+ $raw_X = Xconfig::default::configure($in->do_pkgs, $o_keyboard, $o_mouse);
+ $rc = configure_everything($in, $raw_X, $in->do_pkgs, $auto, $options);
+ } elsif (!$auto) {
+ $rc = configure_chooser($in, $raw_X, $in->do_pkgs, $options);
+ }
+ $rc && $raw_X, $rc;
+}
+
+
+sub may_write {
+ my ($in, $raw_X, $X, $ok) = @_;
+
+ $ok ||= $in->ask_yesorno('', N("Keep the changes?
+The current configuration is:
+
+%s", Xconfig::various::info($raw_X, $X->{card})), 1);
+
+ $ok && &write($raw_X, $X);
+}
+
+sub write {
+ my ($raw_X, $X) = @_;
+ export_to_install_X($X) if $::isInstall;
+ $raw_X->write;
+ Xconfig::various::check_XF86Config_symlink();
+ symlinkf "../../usr/X11R6/bin/Xorg", "$::prefix/etc/X11/X";
+ if ($X->{resolution}{bios}) {
+ Xconfig::various::setupFB($X->{resolution}{bios});
+ 'need_reboot';
+ } else {
+ 'need_restart';
+ }
+}
+
+
+sub export_to_install_X {
+ my ($X) = @_;
+
+ $::o->{X}{resolution_wanted} = $X->{resolution}{X};
+ $::o->{X}{default_depth} = $X->{resolution}{Depth};
+ $::o->{X}{bios_vga_mode} = $X->{resolution}{bios};
+ $::o->{X}{monitors} = $X->{monitors} if $X->{monitors}[0]{manually_chosen} && $X->{monitors}[0]{vendor} ne "Plug'n Play";
+ $::o->{X}{card} = $X->{card} if $X->{card}{manually_chosen};
+ $::o->{X}{Xinerama} = 1 if $X->{card}{Xinerama};
+}
+
+sub check_valid {
+ my ($raw_X) = @_;
+
+ my %sections = map {
+ my @l = $raw_X->get_Sections($_) or return "missing section $_";
+ $_ => \@l;
+ } qw(Files InputDevice Monitor Device Screen ServerLayout);
+
+ $sections{Files}[0]{FontPath} or return "missing FontPath";
+
+ '';
+}
+
+#- most usefull XFree86-4.0.1 server options. Default values is the first ones.
+our @options_serverflags = (
+ 'DontZap' => [ "Off", "On" ],
+ 'DontZoom' => [ "Off", "On" ],
+ 'DisableVidModeExtension' => [ "Off", "On" ],
+ 'AllowNonLocalXvidtune' => [ "Off", "On" ],
+ 'DisableModInDev' => [ "Off", "On" ],
+ 'AllowNonLocalModInDev' => [ "Off", "On" ],
+ 'AllowMouseOpenFail' => [ "False", "True" ],
+ 'VTSysReq' => [ "Off", "On" ],
+ 'BlankTime' => [ "10", "5", "3", "15", "30" ],
+ 'StandByTime' => [ "20", "10", "6", "30", "60" ],
+ 'SuspendTime' => [ "30", "15", "9", "45", "90" ],
+ 'OffTime' => [ "40", "20", "12", "60", "120" ],
+ 'Pixmap' => [ "32", "24" ],
+ 'PC98' => [ "auto-detected", "False", "True" ],
+ 'NoPM' => [ "False", "True" ],
+);
+
+1;
diff --git a/lib/Xconfig/monitor.pm b/lib/Xconfig/monitor.pm
new file mode 100644
index 0000000..ba5360b
--- /dev/null
+++ b/lib/Xconfig/monitor.pm
@@ -0,0 +1,275 @@
+package Xconfig::monitor; #- $Id$
+
+use diagnostics;
+use strict;
+
+use Xconfig::xfree;
+use detect_devices;
+use common;
+use any;
+use log;
+
+
+sub good_default_monitor() {
+ detect_devices::is_xbox() ? 'Generic|640x480 @ 60 Hz' :
+ arch() =~ /ppc/ ?
+ (detect_devices::get_mac_model() =~ /^iBook/ ? 'Apple|iBook 800x600' : 'Apple|iMac/PowerBook 1024x768') :
+ (detect_devices::isLaptop() ? 'Generic|Flat Panel 1024x768' : 'Generic|1024x768 @ 60 Hz');
+}
+
+my @VertRefresh_ranges = ("50-70", "50-90", "50-100", "40-150");
+
+my @HorizSync_ranges = (
+ "31.5",
+ "31.5-35.1",
+ "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",
+);
+
+sub configure {
+ my ($in, $raw_X, $nb_monitors, $o_probed_info, $b_auto) = @_;
+
+ my $monitors = [ $raw_X->get_or_new_monitors($nb_monitors) ];
+ if ($o_probed_info) {
+ put_in_hash($monitors->[0], $o_probed_info);
+ }
+ my $head_nb = 1;
+ foreach my $monitor (@$monitors) {
+ choose($in, $monitor, @$monitors > 1 ? $head_nb++ : 0, $raw_X->get_Driver, $b_auto) or return;
+ }
+ $raw_X->set_monitors(@$monitors);
+ $monitors;
+}
+
+sub configure_auto_install {
+ my ($raw_X, $old_X) = @_;
+
+ if ($old_X->{monitor}) {
+ #- keep compatibility
+ $old_X->{monitor}{VertRefresh} = $old_X->{monitor}{vsyncrange};
+ $old_X->{monitor}{HorizSync} = $old_X->{monitor}{hsyncrange};
+
+ #- new name
+ $old_X->{monitors} = [ delete $old_X->{monitor} ];
+ }
+
+ my $monitors = [ $raw_X->get_or_new_monitors($old_X->{monitors} ? int @{$old_X->{monitors}} : 1) ];
+ mapn {
+ my ($monitor, $auto_install_monitor) = @_;
+ put_in_hash($monitor, $auto_install_monitor);
+ configure_automatic($monitor);
+ } $monitors, $old_X->{monitors} if $old_X->{monitors};
+
+ if (!is_valid($monitors->[0])) {
+ put_in_hash($monitors->[0], probe($old_X->{card}{Driver}));
+ }
+
+ foreach my $monitor (@$monitors) {
+ if (!is_valid($monitor)) {
+ good_default_monitor() =~ /(.*)\|(.*)/ or internal_error("bad good_default_monitor");
+ put_in_hash($monitor, { VendorName => $1, ModelName => $2 });
+ configure_automatic($monitor) or internal_error("good_default_monitor (" . good_default_monitor() . ") is unknown in MonitorsDB");
+ }
+ }
+ $raw_X->set_monitors(@$monitors);
+ $monitors;
+}
+
+sub choose {
+ my ($in, $monitor, $head_nb, $card_Driver, $b_auto) = @_;
+
+ my $ok = is_valid($monitor);
+ if ($b_auto) {
+ log::l("Xconfig::monitor: auto failed") if !$ok;
+ return $ok;
+ }
+
+ my %h_monitors = map { ("$_->{VendorName}|$_->{ModelName}" => $_) } monitors_db();
+
+ ask_monitor:
+ my $merged_name = do {
+ if ($monitor->{VendorName} eq "Plug'n Play") {
+ $monitor->{VendorName};
+ } else {
+ my $merged_name = $monitor->{VendorName} . '|' . $monitor->{ModelName};
+
+ if (!exists $h_monitors{$merged_name}) {
+ $merged_name = is_valid($monitor) ? 'Custom' : good_default_monitor();
+ } else {
+ $merged_name;
+ }
+ }
+ };
+
+ $in->ask_from_({ title => N("Monitor"),
+ messages => $head_nb ? N("Choose a monitor for head #%d", $head_nb) : N("Choose a monitor"),
+ interactive_help_id => 'configureX_monitor'
+ },
+ [ { val => \$merged_name, separator => '|',
+ list => ['Custom', "Plug'n Play", sort keys %h_monitors],
+ format => sub { $_[0] eq 'Custom' ? N("Custom") :
+ $_[0] eq "Plug'n Play" ? N("Plug'n Play") . ($monitor->{VendorName} eq "Plug'n Play" ? " ($monitor->{ModelName})" : '') :
+ $_[0] =~ /^Generic\|(.*)/ ? N("Generic") . "|$1" :
+ N("Vendor") . "|$_[0]" },
+ sort => 0 } ]) or return;
+
+ if ($merged_name eq "Plug'n Play") {
+ local $::noauto = 0; #- hey, you asked for plug'n play, so i do probe!
+ delete @$monitor{'VendorName', 'ModelName', 'EISA_ID'};
+ if ($head_nb <= 1) {
+ if (my $probed_info = probe($card_Driver)) {
+ put_in_hash($monitor, $probed_info);
+ } else {
+ $in->ask_warn('', N("Plug'n Play probing failed. Please select the correct monitor"));
+ goto ask_monitor;
+ }
+ } else {
+ $monitor->{VendorName} = "Plug'n Play";
+ }
+ } elsif ($merged_name eq 'Custom') {
+ $in->ask_from('',
+N("The two critical parameters are the vertical refresh rate, which is the rate
+at which the whole screen is refreshed, and most importantly the horizontal
+sync rate, which is the rate at which scanlines are displayed.
+
+It is VERY IMPORTANT that you do not specify a monitor type with a sync range
+that is beyond the capabilities of your monitor: you may damage your monitor.
+ If in doubt, choose a conservative setting."),
+ [ { val => \$monitor->{HorizSync}, list => \@HorizSync_ranges, label => N("Horizontal refresh rate"), not_edit => 0 },
+ { val => \$monitor->{VertRefresh}, list => \@VertRefresh_ranges, label => N("Vertical refresh rate"), not_edit => 0 } ]) or goto &choose;
+ delete @$monitor{'VendorName', 'ModelName', 'EISA_ID'};
+ } else {
+ put_in_hash($monitor, $h_monitors{$merged_name});
+ }
+ $monitor->{manually_chosen} = 1;
+ 1;
+}
+
+sub configure_automatic {
+ my ($monitor) = @_;
+
+ if ($monitor->{EISA_ID}) {
+ log::l("EISA_ID: $monitor->{EISA_ID}");
+ if (my $mon = find { lc($_->{EISA_ID}) eq $monitor->{EISA_ID} } monitors_db()) {
+ add2hash($monitor, $mon);
+ log::l("EISA_ID corresponds to: $monitor->{ModelName}");
+ } elsif (!is_valid($monitor)) {
+ log::l("unknown EISA_ID and partial DDC probe, so unknown monitor");
+ delete @$monitor{'VendorName', 'ModelName', 'EISA_ID'};
+ }
+ } elsif ($monitor->{VendorName}) {
+ if (my $mon = find { $_->{VendorName} eq $monitor->{VendorName} && $_->{ModelName} eq $monitor->{ModelName} } monitors_db()) {
+ put_in_hash($monitor, $mon);
+ }
+ }
+ is_valid($monitor);
+}
+
+sub is_valid {
+ my ($monitor) = @_;
+ $monitor->{HorizSync} && $monitor->{VertRefresh};
+}
+
+sub probe {
+ my ($o_card_Driver) = @_;
+ probe_DDC() || probe_DMI() || probe_using_X($o_card_Driver);
+}
+
+sub probe_DDC() {
+ my ($edid, $vbe) = any::monitor_full_edid() or return;
+ my $monitor = eval($edid);
+
+ if ($vbe =~ /Memory: (\d+)k/) {
+ $monitor->{VideoRam_probed} = $1;
+ }
+ $monitor->{ModeLine} = Xconfig::xfree::default_ModeLine();
+ my $detailed_timings = $monitor->{detailed_timings} || [];
+ foreach (grep { !$_->{bad_ratio} } @$detailed_timings) {
+ my $ratio = $_->{horizontal_active} / $_->{vertical_active};
+
+ if (abs($ratio - 4 / 3) < 0.01) {
+ #- we don't want the 4/3 modelines otherwise they conflict with the Xorg builtin vesamodes
+ } else {
+ unshift @{$monitor->{ModeLine}},
+ { val => $_->{ModeLine}, pre_comment => $_->{ModeLine_comment} . "\n" };
+ }
+
+ if (@$detailed_timings == 1) {
+ #- should we care about {has_preferred_timing} ?
+ $monitor->{preferred_resolution} = { X => $_->{horizontal_active}, Y => $_->{vertical_active} };
+ }
+ }
+
+ if ($monitor->{EISA_ID}) {
+ $monitor->{VendorName} = "Plug'n Play";
+ $monitor->{ModelName} = $monitor->{monitor_name};
+ $monitor->{ModelName} =~ s/"/''/g;
+ }
+ configure_automatic($monitor) or return;
+ $monitor;
+}
+
+sub probe_using_X {
+ my ($card_Driver) = @_;
+
+ detect_devices::isLaptop() or return;
+
+ $card_Driver ||= do {
+ require Xconfig::card;
+ my @cards = Xconfig::card::probe();
+ $cards[0]{Driver};
+ } or return;
+
+ my $resolution = run_program::rooted_get_stdout($::prefix, 'monitor-probe-using-X', $card_Driver) or return;
+ generic_flat_panel(chomp_($resolution));
+}
+
+sub probe_DMI() {
+ my $res = detect_devices::probe_unique_name('Resolution');
+ $res && generic_flat_panel($res);
+}
+
+sub generic_flat_panel {
+ my ($resolution) = @_;
+ my ($X, $Y) = $resolution =~ /(\d+)x(\d+)/ or log::l("bad resolution $resolution"), return;
+ {
+ VendorName => 'Generic',
+ ModelName => "Flat Panel $resolution",
+ HorizSync => '31.5-100', VertRefresh => '60',
+ preferred_resolution => { X => $X, Y => $Y },
+ };
+}
+
+my $monitors_db;
+sub monitors_db() {
+ $monitors_db ||= readMonitorsDB("$ENV{SHARE_PATH}/ldetect-lst/MonitorsDB");
+ @$monitors_db;
+}
+sub readMonitorsDB {
+ my ($file) = @_;
+
+ my @monitors_db;
+ my $F = openFileMaybeCompressed($file);
+ local $_;
+ my $lineno = 0; while (<$F>) {
+ $lineno++;
+ s/\s+$//;
+ /^#/ and next;
+ /^$/ and next;
+
+ my @fields = qw(VendorName ModelName EISA_ID HorizSync VertRefresh dpms);
+ my %l; @l{@fields} = split /\s*;\s*/;
+ push @monitors_db, \%l;
+ }
+ \@monitors_db;
+}
+
+
+1;
+
diff --git a/lib/Xconfig/parse.pm b/lib/Xconfig/parse.pm
new file mode 100644
index 0000000..71062a0
--- /dev/null
+++ b/lib/Xconfig/parse.pm
@@ -0,0 +1,205 @@
+package Xconfig::parse; # $Id$
+
+use diagnostics;
+use strict;
+
+use common;
+
+
+sub read_XF86Config {
+ my ($file) = @_;
+ my $raw_X = raw_from_file($file);
+ from_raw(@$raw_X);
+ $raw_X;
+}
+
+sub prepare_write_XF86Config {
+ my ($raw_X) = @_;
+ map { raw_to_string(before_to_string({ %$_ }, 0)) } @$raw_X;
+}
+
+sub write_XF86Config {
+ my ($raw_X, $file) = @_;
+ my @blocks = prepare_write_XF86Config($raw_X);
+ @blocks ? output($file, @blocks) : unlink $file;
+}
+
+sub read_XF86Config_from_string {
+ my ($s) = @_;
+ my $raw_X = raw_from_file('-', [ split "\n", $s ]);
+ from_raw(@$raw_X);
+ $raw_X;
+}
+
+#-###############################################################################
+#- raw reading/saving
+#-###############################################################################
+sub raw_from_file { #- internal
+ my ($file, $o_lines) = @_;
+ my $raw_X = [];
+
+ my $lines = $o_lines || [ cat_($file) ];
+ my $line;
+
+ my ($comment, $obj, @objs);
+
+ my $attach_comment = sub {
+ $obj || @objs or warn "$file:$line: can not attach comment\n";
+ if ($comment) {
+ $comment =~ s/\n+$/\n/;
+ ($obj || $objs[0])->{$_[0] . '_comment'} = $comment;
+ $comment = '';
+ }
+ };
+
+ foreach (@$lines) {
+ $line++;
+ s/^\s*//; s/\s*$//;
+
+ if (/^$/) {
+ $comment .= "\n" if $comment;
+ next;
+ } elsif (@objs ? m/^#\W/ || /^#$/ : /^#/) {
+ s/^#\s+/# /;
+ $comment .= "$_\n";
+ next;
+ }
+
+ if (/^Section\s+"(.*)"/i) {
+ die "$file:$line: missing EndSection\n" if @objs;
+ my $e = { name => $1, l => [], kind => 'Section' };
+ push @$raw_X, $e;
+ unshift @objs, $e; $obj = '';
+ $attach_comment->('pre');
+ } elsif (/^Subsection\s+"(.*)"/i) {
+ die "$file:$line: missing EndSubsection\n" if @objs && $objs[0]{kind} eq 'Subsection';
+ die "$file:$line: not in Section\n" if !@objs || $objs[0]{kind} ne 'Section';
+ my $e = { name => $1, l => [], kind => 'Subsection' };
+ push @{$objs[0]{l}}, $e;
+ unshift @objs, $e; $obj = '';
+ $attach_comment->('pre');
+ } elsif (/^EndSection/i) {
+ die "$file:$line: not in Section\n" if !@objs || $objs[0]{kind} ne 'Section';
+ $attach_comment->('post');
+ shift @objs; $obj = '';
+ } elsif (/^EndSubsection/i) {
+ die "$file:$line: not in Subsection\n" if !@objs || $objs[0]{kind} ne 'Subsection';
+ $attach_comment->('post');
+ shift @objs; $obj = '';
+ } else {
+ die "$file:$line: not in Section\n" if !@objs;
+
+ my $commented = s/^#//;
+
+ my $comment_on_line;
+ s/(\s*#.*)/$comment_on_line = $1; ''/e;
+
+ if (/^$/) {
+ die "$file:$line: weird";
+ }
+
+ (my $name, my $Option, $_) =
+ /^Option\s*"(.*?)"(.*)/ ? ($1, 1, $2) : /^(\S+)(.*)/ ? ($1, 0, $2) : internal_error($_);
+ my ($val) = /(\S.*)/;
+
+ my %e = (Option => $Option, commented => $commented, comment_on_line => $comment_on_line, pre_comment => $comment);
+ $comment = '';
+ $obj = { name => $name, val => $val };
+ $e{$_} and $obj->{$_} = $e{$_} foreach keys %e;
+
+ push @{$objs[0]{l}}, $obj;
+ }
+ }
+ $raw_X;
+}
+
+sub raw_to_string {
+ my ($e, $b_want_spacing) = @_;
+ my $s = do {
+ if ($e->{l}) {
+ my $inside = join('', map_index { raw_to_string($_, $::i) } @{$e->{l}});
+ $inside .= $e->{post_comment} || '';
+ $inside =~ s/^/ /mg;
+ qq(\n$e->{kind} "$e->{name}"\n) . $inside . "End$e->{kind}";
+ } else {
+ ($e->{commented} ? '#' : '') .
+ ($e->{Option} ? qq(Option "$e->{name}") : $e->{name}) .
+ (defined $e->{val} ? ($e->{Option} && $e->{val} !~ /^"/ ? qq( "$e->{val}") : qq( $e->{val})) : '');
+ }
+ };
+ ($e->{pre_comment} ? ($b_want_spacing ? "\n" : '') . $e->{pre_comment} : '') . $s . ($e->{comment_on_line} || '') . "\n" . (!$e->{l} && $e->{post_comment} || '');
+}
+
+#-###############################################################################
+#- refine the data structure for easier use
+#-###############################################################################
+my %kind_names = (
+ Pointer => [ qw(Protocol Device Emulate3Buttons Emulate3Timeout EmulateWheel EmulateWheelButton) ],
+ Mouse => [ qw(DeviceName Protocol Device AlwaysCore Emulate3Buttons Emulate3Timeout EmulateWheel EmulateWheelButton) ], # Subsection in XInput
+ Keyboard => [ qw(Protocol Driver XkbModel XkbLayout XkbDisable) ],
+ Monitor => [ qw(Identifier VendorName ModelName HorizSync VertRefresh) ],
+ Device => [ qw(Identifier VendorName BoardName Chipset Driver VideoRam Screen BusID DPMS power_saver) ],
+ Display => [ qw(Depth Modes Virtual) ], # Subsection in Device
+ Screen => [ qw(Identifier Driver Device Monitor DefaultDepth DefaultColorDepth) ],
+ InputDevice => [ qw(Identifier Driver Protocol Device Type Mode XkbModel XkbLayout XkbDisable Emulate3Buttons Emulate3Timeout EmulateWheel EmulateWheelButton) ],
+ WacomCursor => [ qw(Port) ], #-\
+ WacomStylus => [ qw(Port) ], #--> Port must be first
+ WacomEraser => [ qw(Port) ], #-/
+ ServerLayout => [ qw(Identifier) ],
+);
+my @want_string = qw(Identifier DeviceName VendorName ModelName BoardName Driver Device Chipset Monitor Protocol XkbModel XkbLayout XkbOptions XkbCompat Load BusID);
+
+%kind_names = map_each { lc $::a => [ map { lc } @$::b ] } %kind_names;
+@want_string = map { lc } @want_string;
+
+sub from_raw {
+ sub from_raw__rec {
+ my ($current, $e) = @_;
+ if ($e->{l}) {
+ from_raw($e);
+ push @{$current->{l}{$e->{name}}}, $e;
+ } else {
+ if (member(lc $e->{name}, @want_string)) {
+ $e->{val} =~ s/^"(.*)"$/$1/ or warn "$e->{name} $e->{val} has no quote\n";
+ }
+
+ if (member(lc $e->{name}, @{$kind_names{lc $current->{name}} || []})) {
+ if ($current->{l}{$e->{name}} && !$current->{l}{$e->{name}}{commented}) {
+ warn "skipping conflicting line for $e->{name} in $current->{name}\n" if !$e->{commented};
+ } else {
+ $current->{l}{$e->{name}} = $e;
+ }
+ } else {
+ push @{$current->{l}{$e->{name}}}, $e;
+ }
+ }
+ delete $e->{name};
+ }
+
+ foreach my $e (@_) {
+ ($e->{l}, my $l) = ({}, $e->{l});
+ from_raw__rec($e, $_) foreach @$l;
+
+ delete $e->{kind};
+ }
+}
+
+sub before_to_string {
+ my ($e, $depth) = @_;
+
+ if ($e->{l}) {
+ $e->{kind} = $depth ? 'Subsection' : 'Section';
+
+ my %rated = map_index { $_ => $::i + 1 } @{$kind_names{lc $e->{name}} || []};
+ my @sorted = sort { ($rated{lc $a} || 99) <=> ($rated{lc $b} || 99) } keys %{$e->{l}};
+ $e->{l} = [ map {
+ my $name = $_;
+ map {
+ before_to_string({ name => $name, %$_ }, $depth+1);
+ } deref_array($e->{l}{$name});
+ } @sorted ];
+ } elsif (member(lc $e->{name}, @want_string)) {
+ $e->{val} = qq("$e->{val}");
+ }
+ $e;
+}
diff --git a/lib/Xconfig/proprietary.pm b/lib/Xconfig/proprietary.pm
new file mode 100644
index 0000000..ed196de
--- /dev/null
+++ b/lib/Xconfig/proprietary.pm
@@ -0,0 +1,35 @@
+package Xconfig::proprietary; # $Id$
+
+use diagnostics;
+use strict;
+
+use common;
+
+
+sub install_matrox_hal {
+ my ($prefix) = @_;
+ my $tmpdir = "$prefix/root/tmp";
+
+ my $tar = "mgadrivers-2.0.tgz";
+ my $dir_in_tar = "mgadrivers";
+ my $dest_dir = "$prefix/usr/X11R6/lib/modules/drivers";
+
+ #- already installed
+ return if -e "$dest_dir/mga_hal_drv.o" || $::testing;
+
+ system("wget -O $tmpdir/$tar ftp://ftp.matrox.com/pub/mga/archive/linux/2002/$tar") if !-e "$tmpdir/$tar";
+ system("tar xzC $tmpdir -f $tmpdir/$tar");
+
+ my $src_dir = "$tmpdir/$dir_in_tar/xfree86/4.2.1/drivers";
+ foreach (all($src_dir)) {
+ my $src = "$src_dir/$_";
+ my $dest = "$dest_dir/$_";
+ rename $dest, "$dest.non_hal";
+ cp_af($src, $dest_dir);
+ }
+ rm_rf("$tmpdir/$tar");
+ rm_rf("$tmpdir/$dir_in_tar");
+}
+
+1;
+
diff --git a/lib/Xconfig/resolution_and_depth.pm b/lib/Xconfig/resolution_and_depth.pm
new file mode 100644
index 0000000..2942664
--- /dev/null
+++ b/lib/Xconfig/resolution_and_depth.pm
@@ -0,0 +1,386 @@
+package Xconfig::resolution_and_depth; # $Id$
+
+use diagnostics;
+use strict;
+
+use common;
+
+
+our %depth2text = (
+ 8 => N_("256 colors (8 bits)"),
+ 15 => N_("32 thousand colors (15 bits)"),
+ 16 => N_("65 thousand colors (16 bits)"),
+ 24 => N_("16 million colors (24 bits)"),
+);
+our @depths_available = ikeys(%depth2text);
+
+my @bios_vga_modes = (
+ { bios => 769, X => 640, Y => 480, Depth => 8 },
+ { bios => 771, X => 800, Y => 600, Depth => 8 },
+ { bios => 773, X => 1024, Y => 768, Depth => 8 },
+ { bios => 775, X => 1280, Y => 1024, Depth => 8 },
+ { bios => 777, X => 1600, Y => 1200, Depth => 8 },
+ { bios => 784, X => 640, Y => 480, Depth => 15 },
+ { bios => 787, X => 800, Y => 600, Depth => 15 },
+ { bios => 790, X => 1024, Y => 768, Depth => 15 },
+ { bios => 793, X => 1280, Y => 1024, Depth => 15 },
+ { bios => 796, X => 1600, Y => 1200, Depth => 15 },
+ { bios => 785, X => 640, Y => 480, Depth => 16 },
+ { bios => 788, X => 800, Y => 600, Depth => 16 },
+ { bios => 791, X => 1024, Y => 768, Depth => 16 },
+ { bios => 794, X => 1280, Y => 1024, Depth => 16 },
+ { bios => 797, X => 1600, Y => 1200, Depth => 16 },
+);
+
+sub from_bios {
+ my ($bios) = @_;
+ find { $_->{bios} == $bios } @bios_vga_modes;
+}
+
+sub bios_vga_modes() { @bios_vga_modes }
+
+sub size2default_resolution {
+ my ($size) = @_; #- size in inch
+
+ require detect_devices;
+ if (arch() =~ /ppc/) {
+ return "1024x768" if detect_devices::get_mac_model() =~ /^PowerBook|^iMac/;
+ } elsif (detect_devices::is_xbox()) {
+ return "640x480";
+ }
+
+ my %monitorSize2resolution = (
+ 13 => "640x480",
+ 14 => "800x600",
+ 15 => "800x600",
+ 16 => "1024x768",
+ 17 => "1024x768",
+ 18 => "1024x768",
+ 19 => "1280x1024",
+ 20 => "1280x1024",
+ 21 => "1600x1200",
+ 22 => "1600x1200",
+ );
+ $monitorSize2resolution{round($size)} || ($size < 13 ? "640x480" : "1600x1200");
+}
+
+sub to_string {
+ my ($resolution) = @_;
+ $resolution or return '';
+
+ $resolution->{X} ? sprintf("%sx%s %dbpp", @$resolution{'X', 'Y', 'Depth'}) : 'frame-buffer';
+}
+
+sub allowed {
+ my ($card) = @_;
+
+ my ($prefered_depth, @resolution_and_depth);
+
+ if ($card->{Driver} eq 'fbdev') {
+ @resolution_and_depth = grep { $_->{Depth} == 16 } @bios_vga_modes;
+ } else {
+ my @depths;
+ if ($card->{Driver} eq 'fglrx') {
+ @depths = 24;
+ } elsif ($card->{BoardName} eq 'RIVA128') {
+ @depths = qw(8 15 24);
+ } elsif ($card->{use_DRI_GLX}) {
+ $prefered_depth = 16;
+ @depths = (16, 24);
+ } else {
+ @depths = our @depths_available;
+ }
+ my @resolutions = @Xconfig::xfree::resolutions;
+
+ push @resolution_and_depth,
+ map {
+ my $Depth = $_;
+ map { m/(\d+)x(\d+)/ && { X => $1, Y => $2, Depth => $Depth } } @resolutions;
+ } @depths;
+ }
+ $prefered_depth, @resolution_and_depth;
+}
+
+# ($card->{VideoRam} || ($card->{server} eq 'FBDev' ? 2048 : 32768))
+sub filter_using_VideoRam {
+ my ($VideoRam, @resolutions) = @_;
+ my $mem = 1024 * $VideoRam;
+ grep { $_->{X} * $_->{Y} * $_->{Depth}/8 <= $mem } @resolutions;
+
+}
+sub filter_using_HorizSync_VertRefresh {
+ my ($HorizSync, $VertRefresh, @resolutions) = @_;
+ my $max_hsync = 1000 * max(split(/[,-]/, $HorizSync));
+ my ($min_vsync, $max_vsync) = (min(split(/[,-]/, $VertRefresh)), max(split(/[,-]/, $VertRefresh)));
+
+ #- enforce at least 60Hz, if max_vsync > 100 (ie don't do it on LCDs which are ok with low vsync)
+ $min_vsync = max(60, $min_vsync) if $max_vsync > 100;
+
+ #- computing with {Y} which is active sync instead of total sync, but that's ok
+ grep { $max_hsync / $_->{Y} > $min_vsync } @resolutions;
+}
+
+sub choose {
+ my ($in, $default_resolution, @resolutions) = @_;
+
+ my $resolution = $default_resolution || {};
+ $in->ask_from(N("Resolutions"), "",
+ [ {
+ val => \$resolution, type => 'list', sort => 0,
+ list => [ sort { $a->{X} <=> $b->{X} } @resolutions ],
+ format => \&to_string,
+ } ]) or return;
+ $resolution;
+}
+
+
+sub choices {
+ my ($_raw_X, $resolution_wanted, $card, $monitors) = @_;
+ $resolution_wanted ||= {};
+
+ my ($prefered_depth, @resolutions) = allowed($card);
+
+ @resolutions = filter_using_HorizSync_VertRefresh($monitors->[0]{HorizSync}, $monitors->[0]{VertRefresh}, @resolutions) if $monitors->[0]{HorizSync};
+ @resolutions = filter_using_VideoRam($card->{VideoRam}, @resolutions) if $card->{VideoRam};
+
+ #- sort it, so we can take the first one when we want the "best"
+ @resolutions = sort { $b->{X} <=> $a->{X} || $b->{Y} <=> $a->{Y} || $b->{Depth} <=> $a->{Depth} } @resolutions;
+
+ if ($resolution_wanted->{X} && !$resolution_wanted->{Y}) {
+ #- assuming ratio 4/3
+ $resolution_wanted->{Y} = round($resolution_wanted->{X} * 3 / 4);
+ } elsif (!$resolution_wanted->{X}) {
+ if ($monitors->[0]{preferred_resolution}) {
+ put_in_hash($resolution_wanted, $monitors->[0]{preferred_resolution});
+ } elsif ($monitors->[0]{ModelName} =~ /^Flat Panel (\d+)x(\d+)$/) {
+ put_in_hash($resolution_wanted, { X => $1, Y => $2 });
+ } elsif ($monitors->[0]{diagonal_size}) {
+ my ($X, $Y) = split('x', size2default_resolution($monitors->[0]{diagonal_size} * 1.08));
+ put_in_hash($resolution_wanted, { X => $X, Y => $Y });
+ } else {
+ put_in_hash($resolution_wanted, { X => 1024, Y => 768 });
+ }
+ }
+ my @matching = grep { $_->{X} eq $resolution_wanted->{X} && $_->{Y} eq $resolution_wanted->{Y} } @resolutions;
+ if (!@matching) {
+ #- hard choice :-(
+ #- first trying the greater resolution with same ratio
+ my $ratio = $resolution_wanted->{X} / $resolution_wanted->{Y};
+ @matching = grep { abs($ratio - $_->{X} / $_->{Y}) < 0.01 } @resolutions;
+ }
+ if (!@matching) {
+ #- really hard choice :'-(
+ #- take the first available resolution <= the wanted resolution
+ @matching = grep { $_->{X} < $resolution_wanted->{X} } @resolutions;
+ }
+ if (!@matching) {
+ @matching = @resolutions;
+ }
+
+ my $default_resolution;
+ foreach my $Depth ($resolution_wanted->{Depth}, $prefered_depth) {
+ $Depth and $default_resolution ||= find { $_->{Depth} eq $Depth } @matching;
+ }
+ $default_resolution ||= $matching[0];
+
+ $default_resolution, @resolutions;
+}
+
+sub configure {
+ my ($in, $raw_X, $card, $monitors, $b_auto) = @_;
+
+ my ($default_resolution, @resolutions) = choices($raw_X, $raw_X->get_resolution, $card, $monitors);
+
+ if ($b_auto) {
+ #- use $default_resolution
+ if ($card->{Driver} eq 'fglrx') {
+ $default_resolution = first(find { $default_resolution->{Y} eq $_->{Y} && $_->{Depth} == 24 }
+ $default_resolution, @resolutions);
+ $default_resolution ||= first(find { $_->{Depth} == 24 } $default_resolution, @resolutions);
+ }
+ } elsif ($in->isa('interactive::gtk')) {
+ $default_resolution = choose_gtk($in, $card, $default_resolution, @resolutions) or return;
+ } else {
+ $default_resolution = choose($in, $default_resolution, @resolutions) or return;
+ }
+ set_resolution($raw_X, $default_resolution);
+
+ $default_resolution;
+}
+
+sub configure_auto_install {
+ my ($raw_X, $card, $monitors, $old_X) = @_;
+
+ my $resolution_wanted = do {
+ my ($X, $Y) = split('x', $old_X->{resolution_wanted});
+ { X => $X, Y => $Y, Depth => $old_X->{default_depth} };
+ };
+
+ my ($default_resolution) = choices($raw_X, $resolution_wanted, $card, $monitors);
+ $default_resolution or die "you selected an unusable depth";
+
+ set_resolution($raw_X, $default_resolution);
+
+ $default_resolution;
+}
+
+sub set_resolution {
+ my ($raw_X, $resolution) = @_;
+ $raw_X->set_resolution($resolution);
+ set_default_background($resolution);
+}
+sub set_default_background {
+ my ($resolution) = @_;
+
+ my $ratio = $resolution->{X} / $resolution->{Y};
+ my $dir = "$::prefix/usr/share/mdk/backgrounds";
+ my %theme = getVarsFromSh("$::prefix/etc/sysconfig/bootsplash");
+ my @l =
+ sort {
+ $a->[1] <=> $b->[1] || $b->[2] <=> $a->[2] || $a->[3] <=> $b->[3];
+ } map {
+ if (my ($X, $Y) = /^\Q$theme{THEME}\E-(\d+)x(\d+).png$/) {
+ [
+ $_,
+ int(abs($ratio - $X / $Y) * 100), #- we want the nearest ratio (precision .01)
+ $X >= $resolution->{X}, #- then we don't want a resolution smaller
+ abs($X - $resolution->{X}), #- the nearest resolution
+ ];
+ } else { () }
+ } all($dir);
+
+ symlinkf $l[0][0], "$dir/default.png";
+}
+
+sub resolution2ratio {
+ my ($resolution, $b_non_strict) = @_;
+ my $res = $resolution->{X} . 'x' . $resolution->{Y};
+ $res eq '1280x1024' && $b_non_strict ? '4/3' : $Xconfig::xfree::resolution2ratio{$res};
+}
+
+sub choose_gtk {
+ my ($in, $card, $default_resolution, @resolutions) = @_;
+
+ $_->{ratio} ||= resolution2ratio($_) foreach @resolutions;
+
+ my $chosen_Depth = $default_resolution->{Depth};
+ my $chosen_res = { X => $default_resolution->{X} || 1024, Y => $default_resolution->{Y} };
+ my $chosen_ratio = resolution2ratio($chosen_res, 'non-strict') || '4/3';
+
+ my $filter_on_ratio = sub {
+ grep {
+ !$chosen_ratio
+ || $_->{ratio} eq $chosen_ratio
+ || $chosen_ratio eq '4/3' && "$_->{X}x$_->{Y}" eq '1280x1024';
+ } @_;
+ };
+ my $filter_on_Depth = sub {
+ grep { $_->{Depth} == $chosen_Depth } @_;
+ };
+ my $filter_on_res = sub {
+ grep { $_->{X} == $chosen_res->{X} && $_->{Y} == $chosen_res->{Y} } @_;
+ };
+ #- $chosen_res must be one of @resolutions, so that it has a correct {ratio} field
+ $chosen_res = first($filter_on_res->(@resolutions)) || $resolutions[0];
+
+ require ugtk2;
+ mygtk2->import;
+ ugtk2->import(qw(:create :helpers :wrappers));
+ my $W = ugtk2->new(N("Resolution"), modal => 1);
+
+ my %monitor_images_x_res = do {
+ my @l = qw(640 800 1024 1152 1280 1400 1600 1920 2048);
+ my %h = map { $_ => ugtk2::_find_imgfile("monitor-$_.png") } @l;
+
+ #- for the other, use the biggest smaller
+ foreach my $x_res (uniq map { $_->{X} } @resolutions) {
+ my $x_res_ = max(grep { $_ <= $x_res } @l);
+ $h{$x_res} ||= $h{$x_res_} || $h{640};
+ }
+ %h;
+ };
+
+ my $res2text = sub { "$_[0]{X}x$_[0]{Y}" . ($chosen_ratio || $_[0]{ratio} =~ /other/ ? '' : " ($_[0]{ratio})") };
+ my @matching_ratio;
+ my $proposed_resolutions = [];
+ my $set_proposed_resolutions = sub {
+ my ($suggested_res) = @_;
+ @matching_ratio = $filter_on_ratio->(@resolutions);
+ gtkval_modify(\$proposed_resolutions, [
+ (reverse uniq_ { $res2text->($_) } @matching_ratio),
+ if_($chosen_ratio, { text => N_("Other") }),
+ ]);
+ if (!$filter_on_res->(@matching_ratio)) {
+ my $res = $suggested_res || find { $_->{X} == $chosen_res->{X} } @matching_ratio;
+ gtkval_modify(\$chosen_res, $res || $matching_ratio[0]);
+ }
+ };
+ $set_proposed_resolutions->();
+
+ my $depth_combo = gtknew('ComboBox', width => 220,
+ text_ref => \$chosen_Depth,
+ format => sub { translate($depth2text{$_[0]}) },
+ list => [ uniq(reverse map { $_->{Depth} } @resolutions) ],
+ changed => sub {
+ my @matching_Depth = $filter_on_Depth->(@matching_ratio);
+ if (!$filter_on_res->(@matching_Depth)) {
+ gtkval_modify(\$chosen_res, $matching_Depth[0]);
+ }
+ });
+ my $previous_res = $chosen_res;
+ my $res_combo = gtknew('ComboBox',
+ text_ref => \$chosen_res,
+ format => sub { $_[0]{text} ? translate($_[0]{text}) : &$res2text },
+ list_ref => \$proposed_resolutions,
+ changed => sub {
+ if ($chosen_res->{text}) {
+ undef $chosen_ratio;
+ $set_proposed_resolutions->($previous_res);
+ } else {
+ my @matching_res = $filter_on_res->(@matching_ratio);
+ if (!$filter_on_Depth->(@matching_res)) {
+ gtkval_modify(\$chosen_Depth, $matching_res[0]{Depth});
+ }
+ $previous_res = $chosen_res;
+ }
+ });
+ my $pix_colors = gtknew('Image',
+ file_ref => \$chosen_Depth,
+ format => sub {
+ $_[0] >= 24 ? "colors.png" : $_[0] >= 15 ? "colors16.png" : "colors8.png";
+ });
+ my $pixmap_mo = gtknew('Image',
+ file_ref => \$chosen_res,
+ format => sub {
+ $monitor_images_x_res{$_[0]{X}} or internal_error("no image for resolution $chosen_res->{X}");
+ });
+
+ my $help_sub = $in->interactive_help_sub_display_id('configureX_resolution');
+ gtkadd($W->{window},
+ gtkpack_($W->create_box_with_title(N("Choose the resolution and the color depth"),
+ if_($card->{BoardName}, "(" . N("Graphics card: %s", $card->{BoardName}) . ")"),
+ ),
+ 1, '',
+ 0, $pixmap_mo,
+ 0, gtknew('HBox', children => [
+ 1, '',
+ 0, gtknew('Table', col_spacings => 5, row_spacings => 5,
+ children => [
+ [ $res_combo, gtknew('Label', text => "") ],
+ [ $depth_combo, gtknew('Frame', shadow_type => 'etched_out', child => $pix_colors) ],
+ ]),
+ 1, '',
+ ]),
+ 1, '',
+ 0, gtkadd($W->create_okcancel(N("Ok"), N("Cancel"), '', if_($help_sub, [ N("Help"), $help_sub, 1 ]))),
+ ));
+ $W->{ok}->grab_focus;
+
+ $W->main or return;
+
+ find { $_->{X} == $chosen_res->{X} &&
+ $_->{Y} == $chosen_res->{Y} &&
+ $_->{Depth} == $chosen_Depth } @resolutions;
+}
+
+1;
diff --git a/lib/Xconfig/screen.pm b/lib/Xconfig/screen.pm
new file mode 100644
index 0000000..e0a3ebd
--- /dev/null
+++ b/lib/Xconfig/screen.pm
@@ -0,0 +1,29 @@
+package Xconfig::screen; # $Id$
+
+use diagnostics;
+use strict;
+
+use common;
+
+
+sub configure {
+ my ($raw_X) = @_;
+
+ my @devices = $raw_X->get_devices;
+ my @monitors = $raw_X->get_monitors;
+
+ if (@monitors < @devices) {
+ $raw_X->set_monitors(@monitors, ({}) x (@devices - @monitors));
+ @monitors = $raw_X->get_monitors;
+ }
+
+ my @sections = mapn {
+ my ($device, $monitor) = @_;
+ { Device => $device->{Identifier}, Monitor => $monitor->{Identifier} };
+ } \@devices, \@monitors;
+
+ $raw_X->set_screens(@sections);
+ 1;
+}
+
+1;
diff --git a/lib/Xconfig/test.pm b/lib/Xconfig/test.pm
new file mode 100644
index 0000000..524530b
--- /dev/null
+++ b/lib/Xconfig/test.pm
@@ -0,0 +1,140 @@
+package Xconfig::test; # $Id$
+
+use diagnostics;
+use strict;
+
+use Xconfig::card;
+use run_program;
+use common;
+use log;
+
+
+my $tmpconfig = "/tmp/Xconfig";
+
+
+sub xtest {
+ my ($display) = @_;
+ eval {
+ require xf86misc::main;
+ xf86misc::main::Xtest($display);
+ };
+}
+
+sub test {
+ my ($in, $raw_X, $card, $auto, $skip_badcard) = @_;
+
+ my $bad_card = !Xconfig::card::check_bad_card($card);
+ return 1 if $skip_badcard && $bad_card;
+
+ if ($bad_card || !$auto) {
+ $in->ask_yesorno(N("Test of the configuration"),
+ N("Do you want to test the configuration?") . ($bad_card ? "\n" . N("Warning: testing this graphic card may freeze your computer") : ''),
+ !$bad_card) or return 1;
+ }
+
+ unlink "$::prefix/tmp/.X9-lock";
+
+ #- create a link from the non-prefixed /tmp/.X11-unix/X9 to the prefixed one
+ #- that way, you can talk to :9 without doing a chroot
+ #- but take care of non X11 install :-)
+ if (-d "/tmp/.X11-unix") {
+ symlinkf "$::prefix/tmp/.X11-unix/X9", "/tmp/.X11-unix/X9" if $::prefix;
+ } else {
+ symlinkf "$::prefix/tmp/.X11-unix", "/tmp/.X11-unix" if $::prefix;
+ }
+
+ #- ensure xfs is running
+ fuzzy_pidofs(qr/\bxfs\b/) or do { run_program::rooted($::prefix, "/etc/rc.d/init.d/xfs", $_) foreach 'stop', 'start' };
+ fuzzy_pidofs(qr/\bxfs\b/) or die "xfs is not running";
+
+ my $f = $::testing ? $tmpconfig : "/etc/X11/XF86Config.test";
+ $raw_X->write("$::prefix/$f");
+
+ my $f_err = common::secured_file($::prefix . ($ENV{TMPDIR} || "$ENV{HOME}/tmp") . '/.drakx.Xoutput');
+
+ my $pid;
+ unless ($pid = fork()) {
+ system("xauth add :9 . `mcookie`");
+ open STDERR, ">$f_err";
+ chroot $::prefix if $::prefix;
+ exec 'Xorg', '-xf86config', $f, ":9" or c::_exit(0);
+ }
+
+ do { sleep 1 } until xtest(":9") || waitpid($pid, c::WNOHANG());
+
+ my $_b = before_leaving { unlink $f_err };
+
+ my $warn_error = sub {
+ my ($error_msg) = @_;
+ $in->ask_warn('', [ N("An error occurred:\n%s\nTry to change some parameters", $error_msg) ]);
+ };
+
+ if (!xtest(":9")) {
+ open(my $F, $f_err);
+
+ local $_;
+ i: while (<$F>) {
+ if (/^\(EE\)/ && !/Disabling/ || /^Fatal\b/) {
+ my @msg = !/error/ && $_;
+ local $_;
+ while (<$F>) {
+ /reporting a problem/ and last;
+ $warn_error->(join('', @msg, $_));
+ return 0;
+ }
+ }
+ }
+ }
+
+ open(my $F, "|perl 2>/dev/null");
+ printf $F q(
+ use lib qw(%s);
+ BEGIN { $::no_ugtk_init = 1 }
+ require lang;
+ require ugtk2; #- help perl_checker
+ ugtk2->import(qw(:wrappers :helpers)); #- help perl_checker
+ use interactive::gtk;
+ use run_program;
+ use common;
+
+ $::prefix = "%s";
+
+ lang::bindtextdomain();
+
+ $ENV{DISPLAY} = ":9";
+ Gtk2->init;
+
+ gtkset_background(200 * 257, 210 * 257, 210 * 257);
+ my $text = Gtk2::Label->new;
+ my $time = 12;
+ Glib::Timeout->add(1000, sub {
+ $text->set(sprintf(translate("%s"), $time));
+ $time-- or Gtk2->main_quit;
+ 1;
+ });
+
+ eval { #- eval it so that missing pixmap will not break the test completely
+ my $root = gtkroot();
+ my $gc = Gtk2::Gdk::GC->new($root);
+ my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file("$::prefix/usr/share/mdk/xfdrake/xfdrake-test-card.png");
+ my ($w, $h) = ($pixbuf->get_width, $pixbuf->get_height);
+ my $pixmap = Gtk2::Gdk::Pixmap->new($root, $w, $h, $root->get_depth);
+ $pixbuf->render_to_drawable($pixmap, $gc, 0, 0, 0, 0, $w, $h, 'none', 0, 0);
+ $root->set_back_pixmap($pixmap, 0);
+ $root->clear;
+ };
+
+ my $in = interactive::gtk->new;
+ $in->exit($in->ask_yesorno('', [ translate("%s"), $text ], 0) ? 0 : 222);
+ ), join(' ', @INC), $::prefix, N_("Leaving in %d seconds"), N_("Is this the correct setting?");
+ my $rc = close $F;
+ my $err = $?;
+
+ $rc || $err == 222 << 8 or $warn_error->('');
+
+ unlink "$::prefix/$f", "$::prefix/$f-4";
+ unlink "/tmp/.X11-unix/X9" if $::prefix;
+ kill 2, $pid;
+
+ $rc;
+}
diff --git a/lib/Xconfig/various.pm b/lib/Xconfig/various.pm
new file mode 100644
index 0000000..c38205f
--- /dev/null
+++ b/lib/Xconfig/various.pm
@@ -0,0 +1,178 @@
+package Xconfig::various; # $Id$
+
+use diagnostics;
+use strict;
+
+use Xconfig::card;
+use Xconfig::default;
+use Xconfig::resolution_and_depth;
+use common;
+
+
+sub to_string {
+ my ($raw_X) = @_;
+
+ $raw_X->is_fbdev ? 'frame-buffer' : Xconfig::resolution_and_depth::to_string($raw_X->get_resolution);
+}
+
+sub info {
+ my ($raw_X, $card) = @_;
+ my $info;
+ my $xf_ver = Xconfig::card::xorg_version();
+ my $title = $card->{use_DRI_GLX} ? N("Xorg %s with 3D hardware acceleration", $xf_ver) :
+ N("Xorg %s", $xf_ver);
+ my $keyboard = eval { $raw_X->get_keyboard } || {};
+ my @monitors = eval { $raw_X->get_monitors };
+ my $device = eval { $raw_X->get_device } || {};
+ my $mouse = eval { first($raw_X->get_mice) } || {};
+
+ $info .= N("Keyboard layout: %s\n", $keyboard->{XkbLayout});
+ $info .= N("Mouse type: %s\n", $mouse->{Protocol});
+ $info .= N("Mouse device: %s\n", $mouse->{Device}) if $::expert;
+ foreach my $monitor (@monitors) {
+ $info .= N("Monitor: %s\n", $monitor->{ModelName});
+ $info .= N("Monitor HorizSync: %s\n", $monitor->{HorizSync}) if $::expert;
+ $info .= N("Monitor VertRefresh: %s\n", $monitor->{VertRefresh}) if $::expert;
+ }
+ $info .= N("Graphics card: %s\n", $device->{VendorName} . ' ' . $device->{BoardName});
+ $info .= N("Graphics memory: %s kB\n", $device->{VideoRam}) if $device->{VideoRam};
+ if (my $resolution = eval { $raw_X->get_resolution }) {
+ $info .= N("Color depth: %s\n", translate($Xconfig::resolution_and_depth::depth2text{$resolution->{Depth}}));
+ $info .= N("Resolution: %s\n", join('x', @$resolution{'X', 'Y'}));
+ }
+ $info .= N("Xorg driver: %s\n", $device->{Driver}) if $device->{Driver};
+ "$title\n\n$info";
+}
+
+sub various {
+ my ($in, $card, $options, $b_auto) = @_;
+
+ tvout($in, $card, $options) if !$b_auto;
+ choose_xdm($in, $b_auto);
+ 1;
+}
+
+sub runlevel {
+ my ($o_runlevel) = @_;
+ my $f = "$::prefix/etc/inittab";
+ -r $f or log::l("missing inittab!!!"), return;
+ if ($o_runlevel) {
+ substInFile { s/^id:\d:initdefault:\s*$/id:$o_runlevel:initdefault:\n/ } $f if !$::testing;
+ } else {
+ cat_($f) =~ /^id:(\d):initdefault:\s*$/m && $1;
+ }
+}
+
+sub choose_xdm {
+ my ($in, $b_auto) = @_;
+ my $xdm = $::isStandalone ? runlevel() == 5 : 1;
+
+ if (!$b_auto) {
+ $xdm = $in->ask_yesorno_({
+ title => N("Graphical interface at startup"),
+ messages =>
+N("I can setup your computer to automatically start the graphical interface (Xorg) upon booting.
+Would you like Xorg to start when you reboot?"),
+ interactive_help_id => 'configureXxdm',
+ }, $xdm);
+ }
+ runlevel($xdm ? 5 : 3);
+}
+
+sub tvout {
+ my ($in, $card, $options) = @_;
+
+ $card->{FB_TVOUT} && $options->{allowFB} or return;
+
+ $in->ask_yesorno('', N("Your graphic card seems to have a TV-OUT connector.
+It can be configured to work using frame-buffer.
+
+For this you have to plug your graphic card to your TV before booting your computer.
+Then choose the \"TVout\" entry in the bootloader
+
+Do you have this feature?")) or return;
+
+ #- rough default value (rationale: http://download.nvidia.com/XFree86_40/1.0-2960/README.txt)
+ require timezone;
+ my $norm = timezone::read()->{timezone} =~ /America/ ? 'NTSC' : 'PAL';
+
+ $norm = $in->ask_from_list('', N("What norm is your TV using?"), [ 'NTSC', 'PAL' ], $norm) or return;
+
+ configure_FB_TVOUT($in->do_pkgs, { norm => $norm });
+}
+
+sub configure_FB_TVOUT {
+ my ($do_pkgs, $use_FB_TVOUT) = @_;
+
+ my $raw_X = Xconfig::default::configure($do_pkgs);
+ return if is_empty_array_ref($raw_X);
+
+ $raw_X->set_monitors({ HorizSync => '30-50', VertRefresh => ($use_FB_TVOUT->{norm} eq 'NTSC' ? 60 : 50),
+ ModeLine => [
+ { val => '"640x480" 29.50 640 675 678 944 480 530 535 625', pre_comment => "# PAL\n" },
+ { val => '"800x600" 36.00 800 818 820 960 600 653 655 750' },
+ { val => '"640x480" 28.195793 640 656 658 784 480 520 525 600', pre_comment => "# NTSC\n" },
+ { val => '"800x600" 38.769241 800 812 814 880 600 646 649 735' },
+ ] });
+ $raw_X->set_devices({ Driver => 'fbdev' });
+
+ my ($device) = $raw_X->get_devices;
+ my ($monitor) = $raw_X->get_monitors;
+ $raw_X->set_screens({ Device => $device->{Identifier}, Monitor => $monitor->{Identifier} });
+
+ my $Screen = $raw_X->get_default_screen;
+ $Screen->{Display} = [ map { { l => { Depth => { val => $_ } } } } 8, 16 ];
+
+ $raw_X->write("$::prefix/etc/X11/XF86Config.tvout");
+
+ check_XF86Config_symlink();
+
+ {
+ require bootloader;
+ require fsedit;
+ require detect_devices;
+ my $all_hds = $::isInstall ? $::o->{all_hds} : fsedit::get_hds();
+ my $bootloader = $::isInstall ? $::o->{bootloader} : bootloader::read($all_hds);
+
+ if (my $tvout = bootloader::duplicate_kernel_entry($bootloader, 'TVout')) {
+ $tvout->{append} .= " XFree=tvout";
+ bootloader::install($bootloader, $all_hds);
+ }
+ }
+}
+
+sub check_XF86Config_symlink() {
+ my $f = "$::prefix/etc/X11/XF86Config";
+ if (!-l $f && -e "$f.tvout") {
+ rename $f, "$f.standard";
+ symlink "XF86Config.standard", $f;
+ }
+}
+
+sub setupFB {
+ my ($bios_vga_mode) = @_;
+
+ require bootloader;
+ my ($bootloader, $all_hds);
+
+ if ($::isInstall && !$::globetrotter) {
+ ($bootloader, $all_hds) = ($::o->{bootloader}, $::o->{all_hds});
+ } else {
+ require fsedit;
+ require fs;
+ require bootloader;
+ $all_hds = fsedit::get_hds();
+ fs::get_info_from_fstab($all_hds);
+
+ $bootloader = bootloader::read($all_hds) or return;
+ }
+
+ foreach (@{$bootloader->{entries}}) {
+ $_->{vga} = $bios_vga_mode if $_->{vga}; #- replace existing vga= with
+ }
+
+ bootloader::action($bootloader, 'write', $all_hds);
+ bootloader::action($bootloader, 'when_config_changed');
+}
+
+1;
diff --git a/lib/Xconfig/xfree.pm b/lib/Xconfig/xfree.pm
new file mode 100644
index 0000000..5cba3ee
--- /dev/null
+++ b/lib/Xconfig/xfree.pm
@@ -0,0 +1,742 @@
+package Xconfig::xfree; # $Id$
+
+use diagnostics;
+use strict;
+
+use common;
+use Xconfig::parse;
+
+#- mostly internal only
+sub new {
+ my ($class, $val) = @_;
+ bless $val, $class;
+}
+
+sub _conf_files() {
+ map { "$::prefix/etc/X11/$_" } 'xorg.conf', 'XF86Config-4', 'XF86Config';
+}
+
+################################################################################
+# I/O ##########################################################################
+################################################################################
+sub read_and_prepare_write {
+ my ($class) = @_;
+ my $file = find { -f $_ } _conf_files();
+ my $raw_X = $class->new(Xconfig::parse::read_XF86Config($file));
+ my $before = $raw_X->prepare_write;
+
+ if (my ($Keyboard) = $raw_X->get_InputDevices('Keyboard')) {
+ $Keyboard->{Driver}{val} = 'keyboard';
+ }
+
+ #- ugly hack to fix empty ModeLine lines, XFdrake seems to generate some, but where???
+ #- at least this allows fixing the pb by re-running XFdrake
+ foreach ($raw_X->get_Sections('Monitor')) {
+ my $l = $_->{ModeLine} or next;
+ @$l = grep { $_->{val} } @$l;
+ }
+
+ $raw_X, $before;
+}
+sub read {
+ my ($class) = @_;
+ first(read_and_prepare_write($class));
+}
+sub write {
+ my ($raw_X, $o_file) = @_;
+ my $file = $o_file || first(_conf_files());
+ if (!$o_file) {
+ foreach (_conf_files()) {
+ if (-l $_) {
+ unlink $_;
+ } else {
+ renamef($_, "$_.old"); #- there will not be any XF86Config nor XF86Config-4 anymore, we want this!
+ }
+ }
+ #- keep it for old programs still using this name
+ symlink basename($file), "$::prefix/etc/X11/XF86Config";
+ }
+ Xconfig::parse::write_XF86Config($raw_X, $file);
+}
+sub prepare_write {
+ my ($raw_X) = @_;
+ join('', Xconfig::parse::prepare_write_XF86Config($raw_X));
+}
+sub empty_config {
+ my ($class) = @_;
+ $class->new(Xconfig::parse::read_XF86Config_from_string(our $default_header));
+}
+
+################################################################################
+# keyboard #####################################################################
+################################################################################
+my @keyboard_fields = qw(XkbLayout XkbModel XkbDisable XkbOptions XkbCompat);
+sub get_keyboard {
+ my ($raw_X) = @_;
+ my $raw_kbd = first(map { $raw_X->get_InputDevices($_) } 'keyboard', 'kbd') or die "no keyboard section";
+ raw_export_section($raw_kbd, \@keyboard_fields);
+}
+sub set_keyboard {
+ my ($raw_X, $kbd) = @_;
+ my $raw_kbd = first(map { $raw_X->get_InputDevices($_) } 'keyboard', 'kbd') || _new_keyboard_section($raw_X);
+ raw_import_section($raw_kbd, $kbd);
+ _set_Option('keyboard', $raw_kbd, keys %$kbd);
+}
+sub _new_keyboard_section {
+ my ($raw_X) = @_;
+ my $raw_kbd = { Identifier => { val => 'Keyboard1' }, Driver => { val => 'keyboard' } };
+ $raw_X->add_Section('InputDevice', $raw_kbd);
+
+ my $layout = get_ServerLayout($raw_X)->{InputDevice} ||= [];
+ push @$layout, { val => '"Keyboard1" "CoreKeyboard"' };
+
+ $raw_kbd;
+}
+
+
+################################################################################
+# mouse ########################################################################
+################################################################################
+#- example: { Protocol => 'IMPS/2', Device => '/dev/psaux', Emulate3Buttons => undef, Emulate3Timeout => 50, ZAxisMapping => [ '4 5', '6 7' ] }
+my @mouse_fields = qw(Protocol Device ZAxisMapping Emulate3Buttons Emulate3Timeout); #-);
+sub get_mice {
+ my ($raw_X) = @_;
+ my @raw_mice = $raw_X->get_InputDevices('mouse');
+ map { raw_export_section($_, \@mouse_fields) } @raw_mice;
+}
+sub set_mice {
+ my ($raw_X, @mice) = @_;
+ my @raw_mice = _new_mouse_sections($raw_X, int @mice);
+ mapn {
+ my ($raw_mouse, $mouse) = @_;
+ raw_import_section($raw_mouse, $mouse);
+ _set_Option('mouse', $raw_mouse, keys %$mouse);
+ } \@raw_mice, \@mice;
+}
+sub _new_mouse_sections {
+ my ($raw_X, $nb_new) = @_;
+ $raw_X->remove_InputDevices('mouse');
+
+ my $layout = get_ServerLayout($raw_X)->{InputDevice} ||= [];
+ @$layout = grep { $_->{val} !~ /^"Mouse/ } @$layout;
+
+ $nb_new or return;
+
+ my @l = map {
+ my $h = { Identifier => { val => "Mouse$_" }, Driver => { val => 'mouse' } };
+ $raw_X->add_Section('InputDevice', $h);
+ } (1 .. $nb_new);
+
+ push @$layout, { val => qq("Mouse1" "CorePointer") };
+ push @$layout, { val => qq("Mouse$_" "SendCoreEvents") } foreach 2 .. $nb_new;
+
+ @l;
+}
+
+
+################################################################################
+# resolution ###################################################################
+################################################################################
+sub get_resolution {
+ my ($raw_X, $o_Screen) = @_;
+ my $Screen = $o_Screen || $raw_X->get_default_screen or return {};
+
+ my $depth = val($Screen->{DefaultColorDepth} || $Screen->{DefaultDepth});
+ my $Display = find { !$depth || val($_->{l}{Depth}) eq $depth } @{$Screen->{Display} || []} or return {};
+ $Display->{l}{Virtual} && val($Display->{l}{Virtual}) =~ /(\d+)\s+(\d+)/ or
+ val($Display->{l}{Modes}) =~ /(\d+)x(\d+)/ or return {};
+ { X => $1, Y => $2, Depth => val($Display->{l}{Depth}) };
+}
+sub set_resolution {
+ my ($raw_X, $resolution, $o_Screen_) = @_;
+
+ foreach my $Screen ($o_Screen_ ? $o_Screen_ : $raw_X->get_Sections('Screen')) {
+ $Screen ||= $raw_X->get_default_screen or internal_error('no screen');
+
+ my $Mode_name = (any { $_->{l}{Modes} } @{$Screen->{Display} || []}) ? 'Modes' : 'Virtual';
+ my $Mode = sprintf($Mode_name eq 'Modes' ? '"%dx%d"' : '%d %d', @$resolution{'X', 'Y'});
+
+ delete $Screen->{DefaultDepth};
+ $Screen->{DefaultColorDepth} = { val => $resolution->{Depth} eq '32' ? 24 : $resolution->{Depth} };
+ $Screen->{Display} = [ map {
+ { l => { Depth => { val => $_ }, $Mode_name => { val => $Mode } } };
+ } 8, 15, 16, 24 ];
+ }
+ add_gtf_ModeLines($raw_X, $resolution);
+}
+
+
+################################################################################
+# device #######################################################################
+################################################################################
+my @device_fields = qw(VendorName BoardName Driver VideoRam Screen BusID); #-);
+sub get_device {
+ my ($raw_X) = @_;
+ first(get_devices($raw_X));
+}
+sub get_devices {
+ my ($raw_X) = @_;
+ my @raw_devices = $raw_X->get_Sections('Device');
+ map {
+ my $raw_device = $_;
+ my $device = raw_export_section($raw_device, [ 'Identifier', @device_fields ]);
+ $device->{Options} = raw_export_section($raw_device, [ grep { (deref_array($raw_device->{$_}))[0]->{Option} } keys %$raw_device ]);
+ $device;
+ } @raw_devices;
+}
+sub set_devices {
+ my ($raw_X, @devices) = @_;
+ my @raw_devices = _new_device_sections($raw_X, int @devices);
+ mapn {
+ my ($raw_device, $device) = @_;
+ my %Options = %{$device->{Options} || {}};
+ raw_import_section($raw_device, $device, \@device_fields);
+ raw_import_section($raw_device, \%Options);
+ $_->{Option} = 1 foreach map { deref_array($raw_device->{$_}) } keys %Options;
+ $raw_device->{''} = [ { post_comment => $device->{raw_LINES} } ] if $device->{raw_LINES};
+ } \@raw_devices, \@devices;
+}
+sub _new_device_sections {
+ my ($raw_X, $nb_new) = @_;
+ $raw_X->remove_Section('Device');
+ map { $raw_X->add_Section('Device', { Identifier => { val => "device$_" }, DPMS => { Option => 1 } }) } (1 .. $nb_new);
+}
+sub get_Driver {
+ my ($raw_X) = @_;
+ my $card = eval { $raw_X->get_device };
+ $card && $card->{Driver};
+}
+
+################################################################################
+# wacoms #######################################################################
+################################################################################
+sub set_wacoms {
+ my ($raw_X, @wacoms) = @_;
+ $raw_X->remove_InputDevices('wacom');
+
+ my $layout = get_ServerLayout($raw_X)->{InputDevice} ||= [];
+ @$layout = grep { $_->{val} !~ /^"(Stylus|Eraser|Cursor)/ } @$layout;
+
+ @wacoms or return;
+
+ my %Modes = (Stylus => 'Absolute', Eraser => 'Absolute', Cursor => 'Relative');
+
+ each_index {
+ my $wacom = $_;
+ foreach (keys %Modes) {
+ my $identifier = $_ . ($::i + 1);
+ my $h = { Identifier => { val => $identifier },
+ Driver => { val => 'wacom' },
+ Type => { val => lc $_, Option => 1 },
+ Device => { val => $wacom->{Device}, Option => 1 },
+ Mode => { val => $Modes{$_}, Option => 1 },
+ if_($wacom->{USB}, USB => { Option => 1 })
+ };
+ $raw_X->add_Section('InputDevice', $h);
+ push @$layout, { val => qq("$identifier" "AlwaysCore") };
+ }
+ } @wacoms;
+}
+
+
+################################################################################
+# synaptics ####################################################################
+################################################################################
+sub set_synaptics {
+ my ($raw_X, @synaptics) = @_;
+ $raw_X->remove_InputDevices('synaptics');
+
+ my $layout = get_ServerLayout($raw_X)->{InputDevice} ||= [];
+ @$layout = grep { $_->{val} !~ /^"SynapticsMouse/ } @$layout;
+
+ @synaptics or return;
+ add_load_module($raw_X, "synaptics");
+
+ each_index {
+ my $synaptics_mouse = $_;
+ my $identifier = "SynapticsMouse" . ($::i + 1);
+ my $pointer_type = $synaptics_mouse->{Primary} ? "CorePointer" : "AlwaysCore";
+ my $h = {
+ Identifier => { val => $identifier },
+ Driver => { val => "synaptics" },
+ };
+ my %opts = (
+ Device => $synaptics_mouse->{Device},
+ Protocol => $synaptics_mouse->{Protocol},
+ $synaptics_mouse->{ALPS} ? (
+ #- from /usr/share/doc/synaptics-0.14.0/README.alps
+ #- and http://qa.mandrakesoft.com/show_bug.cgi?id=14512
+ LeftEdge => 120,
+ RightEdge => 830,
+ TopEdge => 120,
+ BottomEdge => 650,
+ FingerLow => 14,
+ FingerHigh => 15,
+ MaxTapTime => 180,
+ MaxTapMove => 110,
+ EmulateMidButtonTime => 75,
+ VertScrollDelta => 20,
+ HorizScrollDelta => 20,
+ MinSpeed => '0.8',
+ MaxSpeed => '1.00',
+ AccelFactor => '0.015',
+ EdgeMotionMinSpeed => 200,
+ EdgeMotionMaxSpeed => 200,
+ UpDownScrolling => 1,
+ CircularScrolling => 1,
+ CircScrollDelta => '0.1',
+ CircScrollTrigger => 2,
+ UpDownScrolling => 0,
+ ) : (
+ #- from /usr/share/doc/synaptics-0.14.0/INSTALL
+ LeftEdge => 1700,
+ RightEdge => 5300,
+ TopEdge => 1700,
+ BottomEdge => 4200,
+ FingerLow => 25,
+ FingerHigh => 30,
+ MaxTapTime => 180,
+ MaxTapMove => 220,
+ VertScrollDelta => 100,
+ MinSpeed => '0.09',
+ MaxSpeed => '0.18',
+ AccelFactor => '0.0015',
+ ),
+ SHMConfig => "on",
+ );
+ while (my ($k, $v) = each %opts) {
+ $h->{$k} = { val => $v, Option => 1 };
+ }
+ $raw_X->add_Section('InputDevice', $h);
+ push @$layout, { val => qq("$identifier" "$pointer_type") };
+ } @synaptics;
+}
+
+
+################################################################################
+# monitor ######################################################################
+################################################################################
+my @monitor_fields = qw(VendorName ModelName HorizSync VertRefresh);
+sub get_monitors {
+ my ($raw_X) = @_;
+ my @raw_monitors = $raw_X->get_Sections('Monitor');
+ map {
+ my $h = raw_export_section($_, [ 'Identifier', @monitor_fields ]);
+ $h->{ModeLine} = $_->{ModeLine} if $_->{ModeLine};
+ $h;
+ } @raw_monitors;
+}
+sub set_monitors {
+ my ($raw_X, @monitors) = @_;
+ my @raw_monitors = _new_monitor_sections($raw_X, int @monitors);
+ mapn {
+ my ($raw_monitor, $monitor) = @_;
+ raw_import_section($raw_monitor, $monitor, \@monitor_fields);
+ $raw_monitor->{ModeLine} = $monitor->{ModeLine} if $monitor->{ModeLine};
+ } \@raw_monitors, \@monitors;
+}
+sub get_or_new_monitors {
+ my ($raw_X, $nb_new) = @_;
+ my @monitors = $raw_X->get_monitors;
+
+ #- ensure we have exactly $nb_new monitors;
+ if ($nb_new > @monitors) {
+ @monitors, ({}) x ($nb_new - @monitors);
+ } else {
+ splice(@monitors, 0, $nb_new);
+ }
+}
+sub _new_monitor_sections {
+ my ($raw_X, $nb_new) = @_;
+ $raw_X->remove_Section('Monitor');
+ map { $raw_X->add_Section('Monitor', { Identifier => { val => "monitor$_" }, ModeLine => default_ModeLine() }) } (1 .. $nb_new);
+}
+sub default_ModeLine() {
+ ModeLine_from_string(qq(Section "Monitor"\n) . (our $default_ModeLine) . qq(EndSection\n));
+}
+
+sub add_gtf_ModeLines {
+ my ($raw_X, $resolution) = @_;
+
+ my $banner = 'modeline generated by gtf(1) [handled by XFdrake]';
+ my $res = $resolution->{X} . 'x' . $resolution->{Y};
+ my @to_add;
+ if ($res ne '1280x1024' &&
+ ($res eq '1400x1050' || $res eq '1152x864' || $Xconfig::xfree::resolution2ratio{$res} ne '4/3')) {
+ @to_add = map {
+ my $s = run_program::rooted_get_stdout($::prefix, 'gtf', $resolution->{X}, $resolution->{Y}, $_);
+ if (my ($name, $val) = $s =~ /ModeLine\s*"(.*)"(.*)/i) {
+ chomp $val;
+ $name =~ s/\.00//; #- nicer that way
+ { val => qq("${name}"$val), pre_comment => "# $banner\n" };
+ } else { () }
+ } reverse(sort_numbers(@Xconfig::xfree::vfreqs));
+ }
+
+ $raw_X->set_monitors(map {
+ @{$_->{ModeLine}} = (
+ (grep { index($_->{pre_comment}, $banner) == -1 } @{$_->{ModeLine}}),
+ @to_add,
+ );
+ $_;
+ } $raw_X->get_monitors);
+
+ 1;
+}
+
+
+################################################################################
+# screens ######################################################################
+################################################################################
+sub get_default_screen {
+ my ($raw_X) = @_;
+ my @l = $raw_X->get_Sections('Screen');
+ (find { $_->{Identifier} && val($_->{Identifier}) eq 'screen1' ||
+ $_->{Driver} && val($_->{Driver}) =~ /svga|accel/ } @l) || $l[0];
+}
+sub set_screens {
+ my ($raw_X, @screens) = @_;
+ my @raw_screens = _new_screen_sections($raw_X, int @screens);
+ mapn {
+ my ($raw_screen, $screen) = @_;
+ raw_import_section($raw_screen, $screen);
+ } \@raw_screens, \@screens;
+}
+sub _new_screen_sections {
+ my ($raw_X, $nb_new) = @_;
+ $raw_X->remove_Section('Screen');
+ my @l = map { $raw_X->add_Section('Screen', { Identifier => { val => "screen$_" } }) } (1 .. $nb_new);
+
+ get_ServerLayout($raw_X)->{Screen} = [
+ { val => qq("screen1") },
+ map { { val => sprintf('"screen%d" RightOf "screen%d"', $_, $_ - 1) } } (2 .. $nb_new)
+ ];
+ @l;
+}
+sub is_fbdev {
+ my ($raw_X, $o_Screen) = @_;
+
+ my $Screen = $o_Screen || $raw_X->get_default_screen or return;
+
+ my $Device = $raw_X->get_Section_by_Identifier('Device', val($Screen->{Device})) or internal_error("no device named $Screen->{Device}");
+ val($Device->{Driver}) eq 'fbdev';
+}
+
+
+
+
+################################################################################
+# modules ######################################################################
+################################################################################
+sub get_modules {
+ my ($raw_X) = @_;
+ my $raw_Module = $raw_X->get_Section('Module') or return;
+ my $Module = raw_export_section($raw_Module, ['Load']);
+ @{$Module->{Load} || []};
+}
+sub add_load_module {
+ my ($raw_X, $module) = @_;
+ my $raw_Module = $raw_X->get_Section('Module') || $raw_X->add_Section('Module', {});
+
+ my %load_modules_comment = (
+ dbe => 'Double-Buffering Extension',
+ v4l => 'Video for Linux',
+ dri => 'direct rendering',
+ glx => '3D layer',
+ 'glx-3.so' => '3D layer',
+ );
+ my $comment = $load_modules_comment{$module};
+ push @{$raw_Module->{Load}}, { val => $module,
+ comment_on_line => $comment && " # $comment",
+ } if !member($module, $raw_X->get_modules);
+}
+sub remove_load_module {
+ my ($raw_X, $module) = @_;
+ my $raw_Module = $raw_X->get_Section('Module') or return;
+ if (my @l = grep { $_->{val} ne $module } @{$raw_Module->{Load}}) {
+ $raw_Module->{Load} = \@l;
+ } else {
+ $raw_X->remove_Section('Module');
+ }
+}
+sub set_load_module {
+ my ($raw_X, $module, $bool) = @_;
+ $bool ? add_load_module($raw_X, $module) : remove_load_module($raw_X, $module);
+}
+
+
+#-##############################################################################
+#- helpers
+#-##############################################################################
+sub _set_Option {
+ my ($category, $node, @names) = @_;
+
+ if (member($category, 'keyboard', 'mouse')) {
+ #- everything we export is an Option
+ $_->{Option} = 1 foreach map { deref_array($node->{$_}) } @names;
+ }
+}
+
+sub get_InputDevices {
+ my ($raw_X, $Driver) = @_;
+ $raw_X->get_Sections('InputDevice', sub { val($_[0]{Driver}) eq $Driver });
+}
+sub remove_InputDevices {
+ my ($raw_X, $Driver) = @_;
+ $raw_X->remove_Section('InputDevice', sub { val($_[0]{Driver}) ne $Driver });
+}
+
+sub get_ServerLayout {
+ my ($raw_X) = @_;
+ $raw_X->get_Section('ServerLayout') ||
+ $raw_X->add_Section('ServerLayout', { Identifier => { val => 'layout1' } });
+}
+
+#-##############################################################################
+#- helpers
+#-##############################################################################
+sub raw_export_section {
+ my ($section, $fields) = @_;
+
+ my $export_name = sub {
+ my ($name) = @_;
+ my $h = $section->{$name} or return;
+
+ my @l = map { if_(!$_->{commented}, $_->{val}) } deref_array($h) or return;
+ $name => (ref($h) eq 'ARRAY' ? \@l : $l[0]);
+ };
+
+ my %h = map { $export_name->($_) } @$fields;
+ \%h;
+}
+
+sub raw_import_section {
+ my ($section, $h, $o_fields) = @_;
+ foreach ($o_fields ? grep { exists $h->{$_} } @$o_fields : keys %$h) {
+ my @l = map { ref($_) eq 'HASH' ? $_ : { val => $_ } } deref_array($h->{$_});
+ $section->{$_} = (ref($h->{$_}) eq 'ARRAY' ? \@l : $l[0]);
+ }
+}
+
+sub add_Section {
+ my ($raw_X, $Section, $h) = @_;
+ my @suggested_ordering = qw(Files ServerFlags Module DRI Keyboard Pointer XInput InputDevice Monitor Device Screen ServerLayout);
+ my %order = map_index { { lc($_) => $::i } } @suggested_ordering;
+ my $e = { name => $Section, l => $h };
+ my $added;
+ @$raw_X = map {
+ if ($order{lc $_->{name}} > $order{lc $Section} && !$added) {
+ $added = 1;
+ ($e, $_);
+ } else { $_ }
+ } @$raw_X;
+ push @$raw_X, $e if !$added;
+ $h;
+}
+sub remove_Section {
+ my ($raw_X, $Section, $o_when) = @_;
+ @$raw_X = grep { $_->{name} ne $Section || $o_when && $o_when->($_->{l}) } @$raw_X;
+ $raw_X;
+}
+sub get_Sections {
+ my ($raw_X, $Section, $o_when) = @_;
+ map { if_(lc($_->{name}) eq lc($Section) && (!$o_when || $o_when->($_->{l})), $_->{l}) } @$raw_X;
+}
+sub get_Section {
+ my ($raw_X, $Section, $o_when) = @_;
+ my @l = get_Sections($raw_X, $Section, $o_when);
+ @l > 1 and log::l("Xconfig: found more than one Section $Section");
+ $l[0];
+}
+sub get_Section_by_Identifier {
+ my ($raw_X, $Section, $Identifier) = @_;
+ my @l = get_Sections($raw_X, $Section, sub { val($_[0]{Identifier}) eq $Identifier });
+ @l > 1 and die "more than one Section $Section has Identifier $Identifier";
+ $l[0];
+}
+
+sub val {
+ my ($ref) = @_;
+ $ref && $ref->{val};
+}
+
+
+sub ModeLine_from_string {
+ my ($s) = @_;
+ my $raw_X_for_ModeLine = Xconfig::parse::read_XF86Config_from_string($s);
+ get_Section($raw_X_for_ModeLine, 'Monitor')->{ModeLine};
+}
+
+
+
+# http://home.comcast.net/~igpl/Aspect.html
+# movies http://www.technosound.co.uk/nav.php?pageid=hcg_widescreen
+# esp for 1360x768 http://www.winischhofer.at/linuxsispart1.shtml
+
+# www.dell.com/downloads/global/vectors/2003_cvt.pdf
+# file vesamodes in Xorg is DMT Standard Display Modes
+
+# http://www.vesa.org/Public
+# http://www.vesa.org/Public/EEDIDguideV1.pdf
+
+#- http://www.vesa.org/Public/CVT
+our @CVT_ratios = qw(4/3 16/9 16/10 5/4 15/9 3/2);
+our @CVT_vfreqs = qw(50 60 75 85); # and also 60Hz "reduced blanking" in CVT
+
+our @vfreqs = (@CVT_vfreqs, qw(100 120));
+
+our %ratio2resolutions = (
+
+ # first all the CVT_ratios
+
+ # 1.25
+ '5/4' => [ qw(640x512 720x576 1280x1024 1800x1440) ],
+ # SXGA=1280x1024 QSXGA=2560x2048
+
+ # 1.33
+ '4/3' => [
+ qw(320x240 480x360 640x480 800x600 832x624
+ 1024x768 1152x864 1280x960 1400x1050
+ 1600x1200 1920x1440 2048x1536), # 768x576 1792x1344 1856x1392
+ # DBLSCAN: 400x300 416x312 512x384 576x432 700x525 896x672 928x696 960x720
+ ], # VGA=640x480, SVGA=800x600, XGA=1024x768, SXGA+=1400x1050, UXGA=1600x1200, QXGA=2048x1536 QSXGA+=2800x2100, QUXGA=3200x2400
+
+ # 1.5
+ '3/2' => [ qw(360x240 720x480 1152x768) ], # 576x384 (DBLSCAN of 1152x768)
+
+ # 1.6
+ '16/10' => [ qw(1280x800 1440x900 1600x1000 1680x1050 1920x1200) ], # 320x200 640x400 960x600 2560x1600
+ # WSXGA+=1680x1050, WUXGA=1920x1200, WQUXGA=3840x2400
+
+ # 1.67
+ '15/9' => [ qw(1280x768) ], # 800x480
+ # WXGA=1280x768 or ??? (should be 1366x768)
+
+ # 1.78
+ '16/9' => [ qw(1280x720 1600x900 1920x1080) ], # 960x540 1024x576
+
+
+ # now more weird things
+
+ # 1.32
+ # '192/145' => [ qw(1152x870) ],
+
+ # 1.328
+ # '85/64' => [ qw(1360x1024) ],
+
+ # 1.42
+ # '17/12' => [ qw(544x384) ] ,
+
+ # 1.56
+ # '25/16' => [ qw(1600x1024) ], # WSXGA, (DBLSCAN 800x512)
+
+ # 1.707
+ # '128/75' => [ qw(1024x600) ],
+
+ # 1.767
+ # '53/30' => [ qw(848x480) ],
+
+ # 1.771
+ # '85/48' => [ qw(1360x768) ],
+
+ # 1.775
+ # '71/40' => [ qw(852x480) ],
+
+ # 1.783
+ # '107/60' => [ qw(856x480) ],
+
+ N_("_:weird aspect ratio\nother") => [
+ # 2.13 = 32/15
+ qw(1024x480 1280x600), # VAIO
+
+ # 2.67 = 8/3
+ qw(2048x768 2560x960 3200x1200),
+
+ # 4.0 = 4/1
+ qw(3072x768 3456x864 3840x960 4800x1200),
+
+ # ?? 352x288 640x350 (DBLSCAN 320x175) 720x400 (DBLSCAN 360x200)
+ ],
+);
+
+our %resolution2ratio = map_each { map { $_ => $::a } @$::b } %ratio2resolutions;
+our @resolutions = map_each { @$::b } %ratio2resolutions;
+
+foreach my $ratio (keys %ratio2resolutions) {
+ if ($ratio =~ m!^(\d+)/(\d+)$!) {
+ my $eval = $2 / $1;
+ foreach (@{$ratio2resolutions{$ratio}}) {
+ my ($x, $y) = /(\d+)x(\d+)/;
+ my $y2 = round($x * $eval);
+ $y == $y2 or do {
+ my $good_ratio = (find { m!^(\d+)/(\d+)$! && $y == round($x * $2 / $1) } keys %ratio2resolutions) || '??';
+ die "bad ratio $ratio for resolution $_, it should be $good_ratio\n";
+ };
+ }
+ }
+}
+
+our $default_header = <<'END';
+# File generated by XFdrake.
+
+# **********************************************************************
+# Refer to the xorg.conf man page for details about the format of
+# this file.
+# **********************************************************************
+
+Section "Files"
+ # Multiple FontPath entries are allowed (they are concatenated together)
+ # By default, Mandrake 6.0 and later now use a font server independent of
+ # the X server to render fonts.
+ FontPath "unix/:-1"
+EndSection
+
+Section "ServerFlags"
+ #DontZap # disable <Crtl><Alt><BS> (server abort)
+ #DontZoom # disable <Crtl><Alt><KP_+>/<KP_-> (resolution switching)
+ AllowMouseOpenFail # allows the server to start up even if the mouse does not work
+END
+
+require detect_devices;
+$default_header .= <<'END_XBOX' if detect_devices::is_xbox();
+ Option "PciProbe1" "false"
+ Option "PciProbe2" "false"
+ Option "PciForceConfig1" "false"
+ Option "PciForceConfig2" "false"
+ Option "PciOsConfig" "true"
+END_XBOX
+
+$default_header .= <<'END';
+EndSection
+END
+
+our $default_ModeLine = arch() =~ /ppc/ ? <<'END_PPC' : <<'END';
+ # Apple iMac modes
+ ModeLine "1024x768" 78.525 1024 1049 1145 1312 768 769 772 800 +hsync +vsync
+ ModeLine "800x600" 62.357 800 821 901 1040 600 601 604 632 +hsync +vsync
+ ModeLine "640x480" 49.886 640 661 725 832 480 481 484 514 +hsync +vsync
+ # Apple monitors tend to do 832x624
+ ModeLine "832x624" 57 832 876 940 1152 624 625 628 667 -hsync -vsync
+ # Apple PowerBook G3
+ ModeLine "800x600" 100 800 816 824 840 600 616 624 640 -hsync -vsync
+ # Apple TI Powerbook
+ ModeLine "1152x768" 78.741 1152 1173 1269 1440 768 769 772 800 +vsync +vsync
+ # Pismo Firewire G3
+ ModeLine "1024x768" 65 1024 1032 1176 1344 768 771 777 806 -hsync -vsync
+ # iBook2
+ ModeLine "1024x768" 65 1024 1048 1184 1344 768 771 777 806 -hsync -vsync
+ # 17" Apple Studio Display
+ ModeLine "1024x768" 112.62 1024 1076 1248 1420 768 768 780 808 +hsync +vsync
+ # HiRes Apple Studio Display
+ ModeLine "1280x1024" 135 1280 1288 1392 1664 1024 1027 1030 1064
+ # Another variation
+ ModeLine "1280x1024" 134.989 1280 1317 1429 1688 1024 1025 1028 1066 +hsync +vsync
+END_PPC
+ # TV fullscreen mode or DVD fullscreen output.
+ # 768x576 @ 79 Hz, 50 kHz hsync
+ ModeLine "768x576" 50.00 768 832 846 1000 576 590 595 630
+ # 768x576 @ 100 Hz, 61.6 kHz hsync
+ ModeLine "768x576" 63.07 768 800 960 1024 576 578 590 616
+END
+
+1;