/[soft]/drakx-kbd-mouse-x11/trunk/lib/Xconfig/main.pm
ViewVC logotype

Contents of /drakx-kbd-mouse-x11/trunk/lib/Xconfig/main.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 981 - (show annotations) (download)
Sat Apr 23 00:21:48 2011 UTC (12 years, 11 months ago) by blino
File size: 8447 byte(s)
- harddrake: configure default resolution (and background) even if card
  configuration fails (useful if vbox video driver is not available)

1 package Xconfig::main; # $Id: main.pm 261482 2009-10-06 10:15:34Z cfergeau $
2
3 use diagnostics;
4 use strict;
5
6 use Xconfig::monitor;
7 use Xconfig::card;
8 use Xconfig::plugins;
9 use Xconfig::resolution_and_depth;
10 use Xconfig::various;
11 use Xconfig::screen;
12 use Xconfig::test;
13 use Xconfig::xfree;
14 use common;
15
16
17 sub configure_monitor {
18 my ($in) = @_;
19
20 my $raw_X = Xconfig::xfree->read;
21 Xconfig::monitor::configure($in, $raw_X, int($raw_X->get_devices)) or return;
22 if ($raw_X->is_modified) {
23 $raw_X->write;
24 'need_restart';
25 } else {
26 '';
27 }
28 }
29
30 sub configure_resolution {
31 my ($in) = @_;
32
33 my $raw_X = Xconfig::xfree->read;
34 my $X = {
35 card => Xconfig::card::from_raw_X($raw_X),
36 monitors => [ $raw_X->get_monitors ],
37 };
38
39 $X->{resolutions} = Xconfig::resolution_and_depth::configure($in, $raw_X, $X->{card}, $X->{monitors}) or return;
40 if ($raw_X->is_modified) {
41 &write($raw_X, $X);
42 } else {
43 '';
44 }
45 }
46
47
48 sub configure_everything_auto_install {
49 my ($raw_X, $do_pkgs, $old_X, $options) = @_;
50 my $X = {};
51 $X->{monitors} = Xconfig::monitor::configure_auto_install($raw_X, $old_X) or return;
52 $options->{VideoRam_probed} = $X->{monitors}[0]{VideoRam_probed};
53 $X->{card} = Xconfig::card::configure_auto_install($raw_X, $do_pkgs, $old_X, $options);
54 my $configured = $X->{card} && Xconfig::screen::configure($raw_X);
55
56 #- still try to configure screen and resolution (to set default background)
57 #- if card configuration failed (for example if best driver is not available)
58 $X->{resolutions} = Xconfig::resolution_and_depth::configure_auto_install($raw_X, $X->{card} ||{}, $X->{monitors}, $old_X);
59 return if !$configured;
60
61 my $action = &write($raw_X, $X, $options->{skip_fb_setup});
62
63 $action;
64 }
65
66 sub configure_everything {
67 my ($in, $raw_X, $do_pkgs, $auto, $options) = @_;
68 my $X = {};
69 my $ok = 1;
70
71 my $probed_info = Xconfig::monitor::probe($raw_X->get_Driver);
72 $options->{VideoRam_probed} = $probed_info->{VideoRam_probed};
73 $ok &&= $X->{card} = Xconfig::card::configure($in, $raw_X, $do_pkgs, $auto, $options);
74 $ok &&= $X->{monitors} = Xconfig::monitor::configure($in, $raw_X, int($raw_X->get_devices), $probed_info, $auto);
75 $ok &&= Xconfig::screen::configure($raw_X);
76 $ok &&= $X->{resolutions} = Xconfig::resolution_and_depth::configure($in, $raw_X, $X->{card}, $X->{monitors}, $auto, {});
77 $ok &&= Xconfig::test::test($in, $raw_X, $X->{card}, '', 'skip_badcard') if !$auto;
78
79 if (!$ok) {
80 return if $auto;
81 ($ok) = configure_chooser_raw($in, $raw_X, $do_pkgs, $options, $X, 1);
82 }
83 may_write($in, $raw_X, $X, $ok);
84 }
85
86 sub configure_chooser_raw {
87 my ($in, $raw_X, $do_pkgs, $options, $X, $b_modified) = @_;
88
89 my %texts;
90
91 my $update_texts = sub {
92 $texts{card} = $X->{card} && $X->{card}{BoardName} || N("Custom");
93 $texts{monitors} = $X->{monitors} && $X->{monitors}[0]{ModelName} || N("Custom");
94 $texts{resolutions} = Xconfig::resolution_and_depth::to_string($X->{resolutions}[0]);
95
96 $texts{$_} =~ s/(.{20}).*/$1.../ foreach keys %texts; #- ensure not too long
97 };
98 $update_texts->();
99
100 my $may_set;
101 my $prompt_for_resolution = sub {
102 $may_set->('resolutions', Xconfig::resolution_and_depth::configure($in, $raw_X, $X->{card}, $X->{monitors}));
103 };
104 $may_set = sub {
105 my ($field, $val) = @_;
106 if ($val) {
107 $X->{$field} = $val;
108 $X->{"modified_$field"} = 1;
109 $b_modified = 1;
110 $update_texts->();
111
112 if (member($field, 'card', 'monitors')) {
113 my ($default_resolution, @other_resolutions) = Xconfig::resolution_and_depth::choices($raw_X, $X->{resolutions}[0], $X->{card}, $X->{monitors});
114 if (Xconfig::resolution_and_depth::to_string($default_resolution) ne
115 Xconfig::resolution_and_depth::to_string($X->{resolutions}[0])) {
116 $prompt_for_resolution->();
117 } else {
118 Xconfig::screen::configure($raw_X);
119 $may_set->('resolutions', Xconfig::resolution_and_depth::set_resolution($raw_X, $X->{card}, $X->{monitors}, $default_resolution, @other_resolutions));
120 }
121 }
122 }
123 };
124
125 my $ok;
126 $in->ask_from_({ interactive_help_id => 'configureX_chooser',
127 title => N("Graphic Card & Monitor Configuration"),
128 if_($::isStandalone, ok => N("Quit")) },
129 [
130 { label => N("Graphic Card"), val => \$texts{card}, clicked => sub {
131 $may_set->('card', Xconfig::card::configure($in, $raw_X, $do_pkgs, 0, $options));
132 } },
133 { label => N("_: This is a display device\nMonitor"), val => \$texts{monitors}, clicked => sub {
134 $may_set->('monitors', Xconfig::monitor::configure($in, $raw_X, int($raw_X->get_devices)));
135 } },
136 { label => N("Resolution"), val => \$texts{resolutions}, disabled => sub { !$X->{card} || !$X->{monitors} },
137 clicked => $prompt_for_resolution },
138 if_(Xconfig::card::check_bad_card($X->{card}) || $::isStandalone,
139 { val => N("Test"), disabled => sub { !$X->{card} || !$X->{monitors} },
140 clicked => sub {
141 $ok = Xconfig::test::test($in, $raw_X, $X->{card}, 'auto', 0);
142 } },
143 ),
144 { val => N("Options"), clicked => sub {
145 Xconfig::various::various($in, $raw_X, $X->{card}, $options, 0, 'read_existing');
146 Xconfig::card::to_raw_X($X->{card}, $raw_X);
147 } },
148 if_(Xconfig::plugins::list(),
149 { val => N("Plugins"), clicked => sub {
150 Xconfig::plugins::choose($in, $raw_X);
151 } },
152 ),
153 ]);
154 $ok, $b_modified;
155 }
156
157 sub configure_chooser {
158 my ($in, $raw_X, $do_pkgs, $options) = @_;
159
160 my $X = {
161 card => scalar eval { Xconfig::card::from_raw_X($raw_X) },
162 monitors => [ $raw_X->get_monitors ],
163 resolutions => [ eval { $raw_X->get_resolutions } ],
164 };
165 my ($ok) = configure_chooser_raw($in, $raw_X, $do_pkgs, $options, $X);
166
167 if ($raw_X->is_modified) {
168 may_write($in, $raw_X, $X, $ok);
169 } else {
170 '';
171 }
172 }
173
174 sub configure_everything_or_configure_chooser {
175 my ($in, $options, $auto, $o_keyboard, $o_mouse) = @_;
176
177 my $raw_X = eval { Xconfig::xfree->read };
178 my $err = $@ && formatError($@);
179 $err ||= _check_valid($raw_X) if $raw_X; #- that's ok if config is empty
180 if ($err) {
181 log::l("ERROR: bad X config file (error: $err)");
182 $options->{ignore_bad_conf} or $in->ask_okcancel('',
183 N("Your Xorg configuration file is broken, we will ignore it.")) or return;
184 undef $raw_X;
185 }
186
187 my $rc = 'ok';
188 if (!$raw_X) {
189 $raw_X = Xconfig::default::configure($in->do_pkgs, $o_keyboard, $o_mouse);
190 $rc = configure_everything($in, $raw_X, $in->do_pkgs, $auto, $options);
191 } elsif (!$auto) {
192 $rc = configure_chooser($in, $raw_X, $in->do_pkgs, $options);
193 }
194 $rc && $raw_X, $rc;
195 }
196
197
198 sub may_write {
199 my ($in, $raw_X, $X, $ok) = @_;
200
201 $ok ||= $in->ask_yesorno('', N("Keep the changes?
202 The current configuration is:
203
204 %s", Xconfig::various::info($raw_X, $X->{card})), 1);
205
206 $ok && &write($raw_X, $X);
207 }
208
209 sub write {
210 my ($raw_X, $X, $o_skip_fb_setup) = @_;
211 export_to_install_X($X) if $::isInstall;
212 my $only_resolution = $raw_X->is_only_resolution_modified;
213 $raw_X->write;
214 Xconfig::various::check_xorg_conf_symlink();
215 Xconfig::various::setup_kms();
216 if ($X->{resolutions}[0]{bios}) {
217 Xconfig::various::setupFB($X->{resolutions}[0]{bios}) if !$o_skip_fb_setup;;
218 'need_reboot';
219 } elsif (my $resolution = $only_resolution && eval { $raw_X->get_resolution }) {
220 'need_xrandr' . sprintf(' --size %dx%d', @$resolution{'X', 'Y'});
221 } else {
222 # Always ask for reboot as the driver could've changed.
223 # TODO: Do 'need_restart' instead when no reboot needed, like no driver
224 # change.
225 'need_reboot';
226 }
227 }
228
229
230 sub export_to_install_X {
231 my ($X) = @_;
232
233 my $resolution = $X->{resolutions}[0];
234 $::o->{X}{resolution_wanted} = $resolution->{automatic} ? 'automatic' : $resolution->{X} . 'x' . $resolution->{Y};
235 $::o->{X}{default_depth} = $resolution->{Depth} if $resolution->{Depth};
236 $::o->{X}{bios_vga_mode} = $resolution->{bios} if $resolution->{bios};
237 $::o->{X}{monitors} = $X->{monitors} if $X->{monitors}[0]{manually_chosen} && $X->{monitors}[0]{vendor} ne "Plug'n Play";
238 $::o->{X}{card} = $X->{card} if $X->{card}{manually_chosen};
239 $::o->{X}{Xinerama} = 1 if $X->{card}{Xinerama};
240 }
241
242 sub _check_valid {
243 my ($raw_X) = @_;
244
245 my %_sections = map {
246 my @l = $raw_X->get_Sections($_) or return "missing section $_";
247 $_ => \@l;
248 } qw(Device Screen ServerLayout);
249
250 '';
251 }
252
253 1;

  ViewVC Help
Powered by ViewVC 1.1.30