From 33d774591c8f145c38c9381ef6a811dbd69971bb Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Tue, 25 Sep 2007 14:01:30 +0000 Subject: - add support for "Automatic" resolution (aka "let xorg do everything") --- lib/Xconfig/main.pm | 2 +- lib/Xconfig/resolution_and_depth.pm | 57 +++++++++++++++++++++++-------------- lib/Xconfig/xfree.pm | 29 +++++++++++-------- 3 files changed, 54 insertions(+), 34 deletions(-) diff --git a/lib/Xconfig/main.pm b/lib/Xconfig/main.pm index cc31fc6..812706f 100644 --- a/lib/Xconfig/main.pm +++ b/lib/Xconfig/main.pm @@ -224,7 +224,7 @@ sub export_to_install_X { my ($X) = @_; my $resolution = $X->{resolutions}[0]; - $::o->{X}{resolution_wanted} = $resolution->{X} . 'x' . $resolution->{Y} if $resolution->{X}; + $::o->{X}{resolution_wanted} = $resolution->{automatic} ? 'automatic' : $resolution->{X} . 'x' . $resolution->{Y}; $::o->{X}{default_depth} = $resolution->{Depth} if $resolution->{Depth}; $::o->{X}{bios_vga_mode} = $resolution->{bios} if $resolution->{bios}; $::o->{X}{monitors} = $X->{monitors} if $X->{monitors}[0]{manually_chosen} && $X->{monitors}[0]{vendor} ne "Plug'n Play"; diff --git a/lib/Xconfig/resolution_and_depth.pm b/lib/Xconfig/resolution_and_depth.pm index 2564980..c8bd4f7 100644 --- a/lib/Xconfig/resolution_and_depth.pm +++ b/lib/Xconfig/resolution_and_depth.pm @@ -69,7 +69,8 @@ sub to_string { my ($resolution) = @_; $resolution or return ''; - $resolution->{X} ? sprintf("%sx%s %dbpp", @$resolution{'X', 'Y', 'Depth'}) : 'frame-buffer'; + $resolution->{automatic} ? N("Automatic") : + $resolution->{X} ? sprintf("%sx%s %dbpp", @$resolution{'X', 'Y', 'Depth'}) : 'frame-buffer'; } sub allowed { @@ -128,7 +129,7 @@ sub choose { $in->ask_from(N("Resolutions"), "", [ { val => \$resolution, type => 'list', sort => 0, - list => [ sort { $a->{X} <=> $b->{X} } @resolutions ], + list => [ (sort { $a->{X} <=> $b->{X} } @resolutions), { automatic => 1 } ], format => \&to_string, } ]) or return; $resolution; @@ -212,29 +213,35 @@ sub configure { 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, @resolutions) = choices($raw_X, $resolution_wanted, $card, $monitors); - $default_resolution or die "you selected an unusable depth"; + my ($default_resolution, @resolutions); + if ($old_X->{resolution_wanted} eq 'automatic' || 1) { + $default_resolution = { automatic => 1 }; + } else { + my $resolution_wanted = do { + my ($X, $Y) = split('x', $old_X->{resolution_wanted}); + { X => $X, Y => $Y, Depth => $old_X->{default_depth} }; + }; + ($default_resolution, @resolutions) = choices($raw_X, $resolution_wanted, $card, $monitors); + $default_resolution or die "you selected an unusable depth"; + } set_resolution($raw_X, $default_resolution, @resolutions); } sub set_resolution { my ($raw_X, $resolution, @other) = @_; - my $ratio = resolution2ratio($resolution, 'non-strict'); - @other = uniq_ { $_->{X} . 'x' . $_->{Y} } @other; - @other = grep { $_->{X} < $resolution->{X} } @other; - @other = filter_on_ratio($ratio, @other); - my $resolutions = [ $resolution, @other ]; + if (!$resolution->{automatic}) { + my $ratio = resolution2ratio($resolution, 'non-strict'); + @other = uniq_ { $_->{X} . 'x' . $_->{Y} } @other; + @other = grep { $_->{X} < $resolution->{X} } @other; + @other = filter_on_ratio($ratio, @other); + set_default_background($resolution); + set_915resolution($resolution) if is_915resolution_configured(); + } + my $resolutions = [ $resolution, @other ]; $raw_X->set_resolutions($resolutions); - set_default_background($resolution); - set_915resolution($resolution) if is_915resolution_configured(); $resolutions; } sub set_default_background { @@ -331,6 +338,7 @@ sub choose_gtk { @matching_ratio = filter_on_ratio($chosen_ratio, @resolutions); gtkval_modify(\$proposed_resolutions, [ (reverse uniq_ { $res2text->($_) } @matching_ratio), + { automatic => 1, text => N_("Automatic") }, if_($chosen_ratio, { text => N_("Other") }), ]); if (!$filter_on_res->(@matching_ratio)) { @@ -356,9 +364,11 @@ sub choose_gtk { format => sub { $_[0]{text} ? translate($_[0]{text}) : &$res2text }, list_ref => \$proposed_resolutions, changed => sub { - if ($chosen_res->{text}) { + if ($chosen_res->{text} eq 'Other') { undef $chosen_ratio; $set_proposed_resolutions->($previous_res); + } elsif ($chosen_res->{text} eq 'Automatic') { + # TODO: disable depth choice } else { my @matching_res = $filter_on_res->(@matching_ratio); if (!$filter_on_Depth->(@matching_res)) { @@ -375,7 +385,8 @@ sub choose_gtk { 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 $X = $_[0]{X} || '1024'; + $monitor_images_x_res{$X} or internal_error("no image for resolution $X"); }); my $help_sub = $in->interactive_help_sub_display_id('configureX_resolution'); @@ -401,9 +412,13 @@ sub choose_gtk { $W->main or return; - find { $_->{X} == $chosen_res->{X} && - $_->{Y} == $chosen_res->{Y} && - $_->{Depth} == $chosen_Depth } @resolutions; + if ($chosen_res->{automatic}) { + $chosen_res; + } else { + find { $_->{X} == $chosen_res->{X} && + $_->{Y} == $chosen_res->{Y} && + $_->{Depth} == $chosen_Depth } @resolutions; + } } 1; diff --git a/lib/Xconfig/xfree.pm b/lib/Xconfig/xfree.pm index c6b3e28..6cf6df7 100644 --- a/lib/Xconfig/xfree.pm +++ b/lib/Xconfig/xfree.pm @@ -188,7 +188,7 @@ sub get_resolutions { 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 {}; + my $Display = find { !$depth || val($_->{l}{Depth}) eq $depth } @{$Screen->{Display} || []} or return { automatic => 1 }; my $s = val($Display->{l}{Virtual} || $Display->{l}{Modes}); my @l; while ($s =~ /(\d+)(x|\s+)(\d+)/g) { @@ -204,21 +204,26 @@ sub set_resolutions { foreach my $Screen ($o_Screen ? $o_Screen : $raw_X->get_Sections('Screen')) { $Screen ||= $raw_X->get_default_screen or internal_error('no screen'); - - #- if the existing config is using Virtual, keep Virtual, otherwise default to Modes - my $Mode_name = (any { $_->{l}{Virtual} } @{$Screen->{Display} || []}) ? 'Virtual' : 'Modes'; - - my @l = $Mode_name eq 'Modes' ? @$resolutions : first(@$resolutions); - my @Modes = map { sprintf($Mode_name eq 'Modes' ? '"%dx%d"' : '%d %d', @$_{'X', 'Y'}) } @l; delete $Screen->{DefaultDepth}; $only_resolution &&= $Screen->{DefaultColorDepth} && $Screen->{DefaultColorDepth}{val} eq $Depth; - $Screen->{DefaultColorDepth} = { val => $Depth }; - $Screen->{Display} = [ map { - { l => { Depth => { val => $_ }, $Mode_name => { val => join(' ', @Modes) } } }; - } 8, 15, 16, 24 ]; + if ($resolutions->[0]{X}) { + #- if the existing config is using Virtual, keep Virtual, otherwise default to Modes + my $Mode_name = (any { $_->{l}{Virtual} } @{$Screen->{Display} || []}) ? 'Virtual' : 'Modes'; + + my @l = $Mode_name eq 'Modes' ? @$resolutions : first(@$resolutions); + my @Modes = map { sprintf($Mode_name eq 'Modes' ? '"%dx%d"' : '%d %d', @$_{'X', 'Y'}) } @l; + + $Screen->{DefaultColorDepth} = { val => $Depth }; + $Screen->{Display} = [ map { + { l => { Depth => { val => $_ }, $Mode_name => { val => join(' ', @Modes) } } }; + } 8, 15, 16, 24 ]; + } else { + delete $Screen->{DefaultColorDepth}; + delete $Screen->{Display}; + } } - add_gtf_ModeLines($raw_X, $resolutions); + add_gtf_ModeLines($raw_X, $resolutions) if $resolutions->[0]{X}; $raw_X->{after_set_resolutions} = $only_resolution ? $raw_X->prepare_write : ''; } -- cgit v1.2.1