package interactive::gtk; # $Id$ use diagnostics; use strict; use vars qw(@ISA); @ISA = qw(interactive); use interactive; use common; use mygtk2; use ugtk2 qw(:helpers :wrappers :create); use Gtk2::Gdk::Keysyms; my $forgetTime = 1000; #- in milli-seconds sub new { my $w = &interactive::new; ($w->{windowwidth}, $w->{windowheight}) = gtkroot()->get_size if !$::isInstall; $w; } sub enter_console { my ($o) = @_; $o->{suspended} = common::setVirtual(1) } sub leave_console { my ($o) = @_; common::setVirtual(delete $o->{suspended}) } sub adapt_markup { #- nothing needed, the default markup is gtk2's my ($_o, $s) = @_; return $s; } sub exit { ugtk2::exit(@_) } sub ask_fileW { my ($in, $common) = @_; my $w = ugtk2::create_file_selector(%$common); my $file; $w->main(sub { $file = $w->{chooser}->get_filename; my $err = ugtk2::file_selected_check($common->{save}, $common->{want_a_dir}, $file); $err and $in->ask_warn('', $err); !$err; }) && $file; } sub create_boxradio { my ($e, $onchange_f, $double_click) = @_; my $boxradio = gtkpack2__(Gtk2::VBox->new, my @radios = gtkradio('', @{$e->{formatted_list}})); my $tips = Gtk2::Tooltips->new; mapn { my ($txt, $w) = @_; # workaround infamous 6 years old gnome bug #101968: $w->child->set_size_request(mygtk2::get_label_width(), -1) if $e->{alignment} ne 'right' && !$e->{label}; $w->signal_connect(button_press_event => $double_click) if $double_click; $w->signal_connect(key_press_event => $e->{may_go_to_next}); $w->signal_connect(clicked => sub { ${$e->{val}} ne $txt or return; $onchange_f->(sub { $txt }); }); if ($e->{help}) { gtkset_tip($tips, $w, ref($e->{help}) eq 'HASH' ? $e->{help}{$txt} : ref($e->{help}) eq 'CODE' ? $e->{help}($txt) : $e->{help}); } } $e->{list}, \@radios; $boxradio, sub { my ($v, $full_struct) = @_; mapn { $_[0]->set_active($_[1] eq $v); $full_struct->{focus_w} = $_[0] if $_[1] eq $v; } \@radios, $e->{list}; }, $radios[0]; } sub create_treeview_list { my ($e, $onchange_f, $double_click) = @_; my $curr; my $list = Gtk2::ListStore->new("Glib::String"); my $list_tv = Gtk2::TreeView->new_with_model($list); $list_tv->set_headers_visible(0); $list_tv->get_selection->set_mode('browse'); my $textcolumn = Gtk2::TreeViewColumn->new_with_attributes(undef, my $renderer = Gtk2::CellRendererText->new, 'text' => 0); $list_tv->append_column($textcolumn); $renderer->set_property('ellipsize', 'end'); my $select = sub { my ($path) = @_; return if !$list_tv->get_model; $list_tv->set_cursor($path, undef, 0); Glib::Timeout->add(100, sub { $list_tv->scroll_to_cell($path, undef, 1, 0.5, 0); 0 }); }; my ($starting_word, $start_reg) = ('', '^'); my $timeout; $list_tv->set_enable_search(0); $list_tv->signal_connect(key_press_event => sub { my ($_w, $event) = @_; my $c = chr($event->keyval & 0xff); Glib::Source->remove($timeout) if $timeout; $timeout = ''; if ($event->keyval >= 0x100) { $e->{may_go_to_next}(), return 1 if member($event->keyval, ($Gtk2::Gdk::Keysyms{Return}, $Gtk2::Gdk::Keysyms{KP_Enter})); $starting_word = '' if !member($event->keyval, ($Gtk2::Gdk::Keysyms{Control_L}, $Gtk2::Gdk::Keysyms{Control_R})); } else { if (member('control-mask', @{$event->state})) { $c eq 's' or return 1; $start_reg and $start_reg = '', return 1; $curr++; } else { $e->{may_go_to_next}(), return 1 if $c eq ' '; $curr++ if $starting_word eq '' || $starting_word eq $c; $starting_word .= $c unless $starting_word eq $c; } my @l = @{$e->{formatted_list}}; my $word = quotemeta $starting_word; my $j; for ($j = 0; $j < @l; $j++) { $l[($j + $curr) % @l] =~ /$start_reg$word/i and last; } if ($j == @l) { $starting_word = ''; } else { $select->(Gtk2::TreePath->new_from_string(($j + $curr) % @l)); } $timeout = Glib::Timeout->add($forgetTime, sub { $timeout = $starting_word = ''; 0 }); } 0; }); $list_tv->show; $list->append_set([ 0 => $_ ]) foreach @{$e->{formatted_list}}; $list_tv->get_selection->signal_connect(changed => sub { my ($model, $iter) = $_[0]->get_selected; $model && $iter or return; $onchange_f->(sub { my $row = $model->get_path_str($iter); $e->{list}[$curr = $row]; }); }); $list_tv->signal_connect(button_press_event => $double_click) if $double_click; $list_tv, sub { my ($v) = @_; eval { my $nb = find_index { $_ eq $v } @{$e->{list}}; my ($old_path) = $list_tv->get_cursor; if (!$old_path || $nb != $old_path->to_string) { $select->(Gtk2::TreePath->new_from_string($nb)); } undef $old_path if $old_path; }; }; } sub __create_tree_model { my ($e) = @_; my $sep = quotemeta $e->{separator}; my $tree_model = Gtk2::TreeStore->new("Glib::String", if_($e->{image2f}, "Gtk2::Gdk::Pixbuf")); my $build_value = sub { my ($v) = @_; my $type = 0; if ($e->{image2f}) { my $image = $e->{image2f}->($_[0]); ($type, $v) = (1, gtkcreate_pixbuf($image)) if $image; } [ $type => $v ]; }; my (%wtree, $parent); $parent = sub { if (my $w = $wtree{"$_[0]$e->{separator}"}) { return $w } my $s = ''; foreach (split $sep, $_[0]) { $wtree{"$s$_$e->{separator}"} ||= $tree_model->append_set($s ? $parent->($s) : undef, $build_value->($_)); $s .= "$_$e->{separator}"; } $wtree{$s}; }; $tree_model->{path_str_list} = [ map { my ($root, $leaf) = /(.*)$sep(.+)/ ? ($1, $2) : ('', $_); my $iter = $tree_model->append_set($parent->($root), $build_value->($leaf)); $tree_model->get_path_str($iter); } @{$e->{formatted_list}} ]; undef $_ foreach values %wtree; undef %wtree; $tree_model; } sub create_treeview_tree { my ($e, $onchange_f, $double_click) = @_; my $tree_model = __create_tree_model($e); my $tree = Gtk2::TreeView->new_with_model($tree_model); $tree->get_selection->set_mode('browse'); { my $col = Gtk2::TreeViewColumn->new; $col->pack_start(my $texrender = Gtk2::CellRendererText->new, 0); $col->add_attribute($texrender, text => 0); if ($e->{image2f}) { $col->pack_start(my $pixrender = Gtk2::CellRendererPixbuf->new, 0); $col->add_attribute($pixrender, pixbuf => 1); } $tree->append_column($col); } $tree->set_headers_visible(0); my $select = sub { my ($path_str) = @_; my $path = Gtk2::TreePath->new_from_string($path_str); $tree->expand_to_path($path); $tree->set_cursor($path, undef, 0); gtkflush(); #- workaround gtk2 bug not honouring centering on the given row if node was closed $tree->scroll_to_cell($path, undef, 1, 0.5, 0); }; my $curr = $tree_model->get_iter_first; #- default value $tree->expand_all if $e->{tree_expanded}; my $selected_via_click; $tree->get_selection->signal_connect(changed => sub { my ($model, $iter) = $_[0]->get_selected; $model && $iter or return; undef $curr if ref $curr; my $path = $tree_model->get_path($curr = $iter); if (!$tree_model->iter_has_child($iter)) { $onchange_f->(sub { my $path_str = $path->to_string; my $i = find_index { $path_str eq $_ } @{$tree_model->{path_str_list}}; $e->{list}[$i]; }); } else { $tree->expand_row($path, 0) if $selected_via_click; } }); my ($starting_word, $start_reg) = ('', "^"); my $timeout; my $toggle = sub { if ($tree_model->iter_has_child($curr)) { $tree->toggle_expansion($tree_model->get_path($curr), 0); } else { &{$e->{may_go_to_next}}; } }; $tree->set_enable_search(0); $tree->signal_connect(key_press_event => sub { my ($_w, $event) = @_; $selected_via_click = 0; my $c = chr($event->keyval & 0xff); $curr or return 0; Glib::Source->remove($timeout) if $timeout; $timeout = ''; if ($event->keyval >= 0x100) { &$toggle and return 1 if member($event->keyval, ($Gtk2::Gdk::Keysyms{Return}, $Gtk2::Gdk::Keysyms{KP_Enter})); $starting_word = '' if !member($event->keyval, ($Gtk2::Gdk::Keysyms{Control_L}, $Gtk2::Gdk::Keysyms{Control_R})); } else { my $next; if (member('control-mask', @{$event->state})) { $c eq "s" or return 1; $start_reg and $start_reg = '', return 0; $next = 1; } else { &$toggle and return 1 if $c eq ' '; $next = 1 if $starting_word eq '' || $starting_word eq $c; $starting_word .= $c unless $starting_word eq $c; } my $word = quotemeta $starting_word; my ($after, $best); my $sep = quotemeta $e->{separator}; my $currpath = $tree_model->get_path_str($curr); mapn { my ($path_str, $v) = @_; $next &&= !$after; $after ||= $path_str eq $currpath; $v =~ s/.*$sep//; if ($v =~ /$start_reg$word/i) { if ($after && !$next) { ($best, $after) = ($path_str, 0); } else { $best ||= $path_str; } } } $tree_model->{path_str_list}, $e->{formatted_list}; if (defined $best) { $select->($best); } else { $starting_word = ''; } $timeout = Glib::Timeout->add($forgetTime, sub { $timeout = $starting_word = ''; 0 }); } 0; }); $tree->signal_connect(button_press_event => sub { $selected_via_click = 1; &$double_click if $curr && !$tree_model->iter_has_child($curr) && $double_click; }); $tree, sub { my $v = may_apply($e->{format}, $_[0]); eval { my $i = find_index { $v eq $_ } @{$e->{formatted_list}}; my ($model, $iter) = $tree->get_selection->get_selected; my $new_path_str = $tree_model->{path_str_list}[$i]; my $old_path_str = $model && $tree_model->get_path_str($iter); $select->($new_path_str) if $new_path_str ne $old_path_str; undef $iter if ref $iter; }; }; } #- $actions is a ref list of $action #- $action is a { kind => $kind, action => sub { ... }, button => Gtk2::Button->new(...) } #- where $kind is one of '', 'modify', 'remove', 'add' sub add_modify_remove_action { my ($button, $buttons, $e, $treelist) = @_; if (member($button->{kind}, 'modify', 'remove')) { @{$e->{list}} or return; } my $r = $button->{action}->(${$e->{val}}); defined $r or return; if ($button->{kind} eq 'add') { ${$e->{val}} = $r; } elsif ($button->{kind} eq 'remove') { ${$e->{val}} = $e->{list}[0]; } ugtk2::gtk_set_treelist($treelist, [ map { may_apply($e->{format}, $_) } @{$e->{list}} ]); add_modify_remove_sensitive($buttons, $e); 1; } sub add_padding { my ($w) = @_; gtknew('HBox', children => [ 0, gtknew('Alignment', width => $mygtk2::left_padding), 1, $w ]); } sub create_widget { my ($o, $common, $e, $onchange_f, $update, $ignore_ref) = @_; my $onchange = sub { my ($f) = @_; sub { $onchange_f->($f, @_) }; }; my ($w, $real_w, $focus_w, $set); if ($e->{type} eq 'iconlist') { $w = Gtk2::Button->new; $set = sub { gtkdestroy($e->{icon}); my $f = $e->{icon2f}->($_[0]); $e->{icon} = -e $f ? gtkcreate_img($f) : Gtk2::WrappedLabel->new(may_apply($e->{format}, $_[0])); $w->add(gtkshow($e->{icon})); }; $w->signal_connect(clicked => sub { $onchange_f->(sub { next_val_in_array(${$e->{val}}, $e->{list}) }); $set->(${$e->{val}}); }); if ($e->{alignment} eq 'right') { $real_w = gtknew('HButtonBox', layout => 'start', children_tight => [ $w ]); } else { $real_w = gtkpack_(Gtk2::HBox->new(0,10), 1, Gtk2::HBox->new(0,0), 0, $w, 1, Gtk2::HBox->new(0,0)); } } elsif ($e->{type} eq 'bool') { if ($e->{image}) { $w = ugtk2::gtkadd(Gtk2::CheckButton->new, gtkshow(gtkcreate_img($e->{image}))); } else { #- warn "\"text\" member should have been used instead of \"label\" one at:\n", common::backtrace(), "\n" if $e->{label} && !$e->{text}; $w = Gtk2::CheckButton->new_with_label($e->{text}); } $w->signal_connect(clicked => $onchange->(sub { $w->get_active })); $set = sub { $w->set_active($_[0]) }; $real_w = add_padding($w); } elsif ($e->{type} eq 'only_label') { my @common = ( # workaround infamous 6 years old gnome bug #101968: if_($e->{alignment} ne 'right', width => mygtk2::get_label_width()) ); $w = $e->{title} ? gtknew('Title2', label => escape_text_for_TextView_markup_format(${$e->{val}}), @common) : gtknew($e->{alignment} eq 'right' ? 'Label_Right' : 'Label_Left', line_wrap => 1, text_markup => ${$e->{val}}, @common); } elsif ($e->{type} eq 'label') { $w = gtknew('WrappedLabel', text_markup => ${$e->{val}}); $set = sub { $w->set($_[0]) }; } elsif ($e->{type} eq 'empty') { $w = gtknew('HBox', height => $e->{height}); } elsif ($e->{type} eq 'button') { $w = gtknew(($e->{install_button} ? 'Install_Button' : 'Button'), text => '', clicked => $e->{clicked_may_quit_cooked}); $set = sub { my $w = $w->child; # handle Install_Buttons: if (ref($w) =~ /Gtk2::HBox/) { ($w) = find { ref($_) =~ /Gtk2::Label/ } $w->get_children; } # guard against 'advanced' widgets that are now in their own dialog # (instead of in another block child of an expander): return if !$w; $w->set_label(may_apply($e->{format}, $_[0])) }; } elsif ($e->{type} eq 'range') { my $adj = Gtk2::Adjustment->new(${$e->{val}}, $e->{min}, $e->{max} + ($e->{SpinButton} ? 0 : 1), 1, ($e->{max} - $e->{min}) / 10, 1); $w = $e->{SpinButton} ? Gtk2::SpinButton->new($adj, 10, 0) : Gtk2::HScale->new($adj); $w->set_size_request($e->{SpinButton} ? 100 : 200, -1); $w->set_digits(0); $adj->signal_connect(value_changed => $onchange->(sub { $adj->get_value })); $w->signal_connect(key_press_event => $e->{may_go_to_next}); $set = sub { $adj->set_value($_[0]) }; } elsif ($e->{type} eq 'expander') { $e->{grow} = 'fill'; my $children = [ if_($e->{message}, { type => 'only_label', no_indent => 1, val => \$e->{message} }), @{$e->{children}} ]; create_widgets_block($o, $common, $children, $update, $ignore_ref); $w = gtknew('HBox', children_tight => [ gtknew('Install_Button', text => $e->{text}, clicked => sub { ask_fromW($o, { title => $common->{title} || N("Advanced") }, $children) } ) ]); } elsif ($e->{type} =~ /list/) { $e->{formatted_list} = [ map { may_apply($e->{format}, $_) } @{$e->{list}} ]; if (my $actions = $e->{add_modify_remove}) { my @buttons = (N_("Add"), N_("Modify"), N_("Remove")); # Add Up/Down buttons if their actions are defined foreach (qw(Up Down)) { push @buttons, 'gtk-go-' . $_ if $actions->{$_}; } @buttons = map { my $button = /^gtk-/ ? gtknew('Button', image => gtknew('Image', stock => $_)) : Gtk2::Button->new(translate($_)); my $kind = $_; $kind =~ s/^gtk-go-//; { kind => lc $kind, action => $actions->{$kind}, button => $button, real_kind => $_ }; } @buttons; my $modify = find { $_->{kind} eq 'modify' } @buttons; my $do_action = sub { my ($button) = @_; add_modify_remove_action($button, \@buttons, $e, $w) and $update->(); }; ($w, $set, $focus_w) = create_treeview_list($e, $onchange_f, sub { $do_action->($modify) if $_[1]->type =~ /^2/ }); foreach my $button (@buttons) { $button->{button}->signal_connect(clicked => sub { $do_action->($button) }); } add_modify_remove_sensitive(\@buttons, $e); my ($images, $real_buttons) = partition { $_->{real_kind} =~ /^gtk-/ } @buttons; $real_w = gtkpack_(Gtk2::HBox->new(0,0), 1, create_scrolled_window($w), 0, gtkpack__(Gtk2::VBox->new(0,0), (map { $_->{button} } @$real_buttons), if_($images, gtknew('HButtonBox', layout => 'spread', children_loose => [ map { $_->{button} } @$images] ) ), ), ); $e->{grow} = 'expand'; } else { my $use_boxradio = exists $e->{gtk}{use_boxradio} ? $e->{gtk}{use_boxradio} : @{$e->{list}} <= 8; if ($e->{help} || $use_boxradio && $e->{type} ne 'treelist') { #- used only when needed, as key bindings are dropped by List (ListStore does not seems to accepts Tooltips). ($w, $set, $focus_w) = create_boxradio($e, $onchange_f, $e->{quit_if_double_click_cooked}); $real_w = add_padding($w); } elsif ($e->{type} eq 'treelist') { ($w, $set) = create_treeview_tree($e, $onchange_f, $e->{quit_if_double_click_cooked}); } else { ($w, $set, $focus_w) = create_treeview_list($e, $onchange_f, $e->{quit_if_double_click_cooked}); } if (@{$e->{list}} > 10 || $e->{gtk}{use_scrolling}) { $real_w = create_scrolled_window($w); $e->{grow} = 'expand'; } } } else { if ($e->{type} eq "combo") { my $model; my @formatted_list = map { may_apply($e->{format}, $_) } @{$e->{list}}; $e->{formatted_list} = \@formatted_list; if (!$e->{separator}) { if ($e->{not_edit}) { $real_w = $w = Gtk2::ComboBox->new_text; # FIXME: the following causes Gtk-CRITICAL but not solvable at realize time: first($w->child->get_cell_renderers)->set_property('ellipsize', 'end') if !$e->{do_not_ellipsize}; $w->set_wrap_width($e->{gtk}{wrap_width}) if exists $e->{gtk}{wrap_width}; } else { $w = Gtk2::ComboBoxEntry->new_text; ($real_w, $w) = ($w, $w->child); } $real_w->set_popdown_strings(@formatted_list); } else { $model = __create_tree_model($e); $real_w = $w = Gtk2::ComboBox->new_with_model($model); $w->pack_start(my $texrender = Gtk2::CellRendererText->new, 0); $w->add_attribute($texrender, text => 0); if ($e->{image2f}) { $w->pack_start(my $pixrender = Gtk2::CellRendererPixbuf->new, 0); $w->add_attribute($pixrender, pixbuf => 1); } } my $get = sub { my $i = $model ? do { my $s = $model->get_string_from_iter($w->get_active_iter); eval { find_index { $s eq $_ } @{$model->{path_str_list}} }; } : do { my $s = $w->get_text; eval { find_index { $s eq $_ } @formatted_list }; }; defined $i ? $e->{list}[$i] : $w->get_text; }; $w->signal_connect(changed => $onchange->($get)); $set = sub { my $s = may_apply($e->{format}, $_[0]); if ($model) { eval { my $i = find_index { $s eq $_ } @{$e->{formatted_list}}; my $path_str = $model->{path_str_list}[$i]; $w->set_active_iter($model->get_iter_from_string($path_str)); }; } else { $w->set_text($s) if $s ne $w->get_text && $_[0] ne $w->get_text; } }; } else { if ($e->{weakness_check}) { $w = gtknew('WeaknessCheckEntry'); } else { $w = Gtk2::Entry->new; } $w->signal_connect(changed => $onchange->(sub { $w->get_text })); $w->signal_connect(focus_in_event => sub { $w->select_region(0, -1) }); $w->signal_connect(focus_out_event => sub { $w->select_region(0, 0) }); $set = sub { $w->set_text($_[0]) if $_[0] ne $w->get_text }; if ($e->{type} eq 'file') { my $button = gtksignal_connect(Gtk2::Button->new_from_stock('gtk-open'), clicked => sub { my $file = $o->ask_fileW({ title => $e->{label}, want_a_dir => to_bool($e->{want_a_dir}), }); $set->($file) if $file; }); $real_w = gtkpack_(Gtk2::HBox->new(0,0), 1, $w, 0, $button); } } $w->signal_connect(key_press_event => $e->{may_go_to_next}); if ($e->{hidden}) { $w->set_visibility(0); $w->signal_connect(key_press_event => sub { my (undef, $event) = @_; if (!$o->{capslock_warned} && member('lock-mask', @{$event->state}) && !$w->get_text) { $o->{capslock_warned} = 1; $o->ask_warn('', N("Beware, Caps Lock is enabled")); } 0; }); } } if (my $focus_out = $e->{focus_out}) { $w->signal_connect(focus_out_event => sub { $update->($focus_out) }); } $real_w ||= $w; $e->{w} = $w; $e->{real_w} = $real_w; $e->{focus_w} = $focus_w || $w if $e->{type} ne 'empty'; $e->{set} = $set || sub {}; } sub all_entries { my ($l) = @_; map { $_, if_($_->{children}, @{$_->{children}}) } @$l; } sub all_focusable_entries { my ($l) = @_; grep { $_->{focus_w} } @$l; } sub all_title_entries { my ($l) = @_; grep { $_->{title} } @$l; } sub create_widgets_block { my ($o, $common, $l, $update, $ignore_ref) = @_; my $label_sizegrp = Gtk2::SizeGroup->new('horizontal'); my $right_label_sizegrp = Gtk2::SizeGroup->new('horizontal'); my $realw_sizegrp = Gtk2::SizeGroup->new('horizontal'); @$l = map_index { if ($::i && ($_->{type} eq 'expander' || $_->{title})) { ({ type => 'empty', height => 4 }, $_); } else { $_; } } @$l; foreach my $e (@$l) { my $onchange_f = sub { my ($f, @para) = @_; return if $$ignore_ref; ${$e->{val}} = $f->(@para); $update->($e->{changed}); }; create_widget($o, $common, $e, $onchange_f, $update, $ignore_ref); my $label_w; if ($e->{label} || !$e->{no_indent}) { $label_w = gtknew($e->{alignment} eq 'right' ? 'Label_Right' : 'Label_Left', text_markup => $e->{label} || '', size_group => ($e->{alignment} eq 'right' ? $right_label_sizegrp : $label_sizegrp), ); $realw_sizegrp->add_widget($e->{real_w}); } if ($e->{do_not_expand}) { $e->{real_w} = gtknew('HBox', children => [ 0, $e->{real_w}, 1, gtknew('Label'), ]); } my $eater = gtknew('Label') if $e->{alignment} eq 'right' && !$label_w; $e->{real_w} = gtkpack_(Gtk2::HBox->new, if_($e->{icon}, 0, eval { gtkcreate_img($e->{icon}) }), if_($eater, 1, $eater), if_($label_w, $e->{alignment} eq 'right', $label_w), (!$eater, $e->{real_w}), ); } gtknew('VBox', children => [ map { $_->{grow} || 0, $_->{real_w} } @$l ]); } sub create_widgets { my ($o, $common, $mainw, $l) = @_; my $ignore = 0; #-to handle recursivity my $set_all = sub { $ignore = 1; my @all = all_entries($l); $_->{set}->(${$_->{val}}, $_) foreach @all; #- nb: the parameter "$_" is needed for create_boxradio $_->{disabled} and $_->{real_w}->set_sensitive(!$_->{disabled}()) foreach @all; $_->{hidden} and $_->{w}->set_visibility(!(ref($_->{hidden}) eq 'CODE' ? $_->{hidden}() : $_->{hidden})) foreach @all; $mainw->{ok}->set_sensitive(!$common->{ok_disabled}()) if $common->{ok_disabled}; $ignore = 0; }; my $update = sub { my ($f) = @_; return if $ignore; $f->() if $f; $set_all->(); }; my $ok_clicked = sub { !$mainw->{ok} || $mainw->{ok}->get_property('sensitive') or return; $mainw->{retval} = 1; Gtk2->main_quit; }; my @all = all_entries($l); foreach (@all) { my $e = $_; #- for closures # we only consider real widgets (aka ignoring labels and Help/Release Notes/... buttons): if ((grep { !$_->{install_button} && $_->{type} ne 'only_label' } @all) == 1 || $e->{quit_if_double_click}) { #- i'm the only one, double click means accepting $e->{quit_if_double_click_cooked} = sub { $_[1]->type =~ /^2/ && $ok_clicked->() }; } if ($e->{clicked_may_quit}) { $e->{clicked_may_quit_cooked} = sub { $mainw->{rwindow}->hide; if (my $v = $e->{clicked_may_quit}()) { $mainw->{retval} = $v; Gtk2->main_quit; } $mainw->{rwindow}->show; $update->(); }; } $e->{may_go_to_next} = sub { my (undef, $event) = @_; if (!$event || ($event->keyval & 0x7f) == 0xd) { my @current_all = all_focusable_entries($l); my $ind = eval { find_index { $_ == $e } @current_all }; if (my $e_ = $current_all[$ind+1]) { $e_->{focus_w}->grab_focus; } else { @current_all == 1 ? $ok_clicked->() : $mainw->{ok}->grab_focus; } 1; #- prevent an action on the just grabbed focus } else { 0; } }; } # add asterisks before titles when there're more than one: my @all_titles = all_title_entries($l); if (2 <= @all_titles) { ${$_->{val}} = mygtk2::asteriskize(${$_->{val}}) foreach @all_titles; } my $box = create_widgets_block($o, $common, $l, $update, \$ignore); my $tooltips = Gtk2::Tooltips->new; foreach my $e (@all) { $tooltips->set_tip($e->{w}, $e->{help}) if $e->{help} && !ref($e->{help}); } $box, $set_all; } sub add_modify_remove_sensitive { my ($buttons, $e) = @_; $_->{button}->set_sensitive(@{$e->{list}} != ()) foreach grep { member($_->{kind}, 'modify', 'remove') } @$buttons; } sub filter_widgets { my ($l) = @_; foreach my $e (all_entries($l)) { $e->{no_indent} = 1 if member($e->{type}, 'list', 'treelist', 'expander', 'bool', 'only_label'); } } my $help_path = "/usr/share/doc/installer-help/"; sub is_help_file_exist { my ($_o, $id) = @_; # just ignore anchors: $id =~ s/#.*//; -e "$help_path/$id.html"; } sub load_from_uri { my ($view, $url) = @_; $view->open(get_html_file($::o, $url)); } sub get_html_file { my ($o, $url) = @_; my $anchor; ($url, $anchor) = $url =~ /(.*)#(.*)/ if $url =~ /#/; $url .= '.html' if $url !~ /\.html$/; $url = find { -e $_ } map { "$help_path/${_}" } map { my $id = $_; require lang; map { ("$_/$id") } map { $_, lc($_) } (split ':', lang::getLANGUAGE($o->{locale}{lang})), ''; } $url; $url = "file://$url"; $anchor ? "$url#$anchor" : $url; } sub display_help { my ($o, $common, $mainw) = @_; if (my $file = $common->{interactive_help_id}) { require Gtk2::WebKit; my $view = gtknew('WebKit_View'); load_from_uri($view, $file); my $w = ugtk2->new(N("Help"), transient => $mainw->{real_window}, modal => 1); gtkadd($w->{rwindow}, gtkpack_(Gtk2::VBox->new, 1, create_scrolled_window(gtkset_border_width($view, 5), [ 'never', 'automatic' ], ), 0, Gtk2::HSeparator->new, 0, gtkpack(create_hbox('end'), gtknew('Button', text => N("Close"), clicked => sub { Gtk2->main_quit }) ), ), ); mygtk2::set_main_window_size($w->{rwindow}); $w->{real_window}->grab_focus; $w->{real_window}->show_all; $w->main; return; } elsif (my $message = $common->{interactive_help}->()) { $o->ask_warn(N("Help"), $message); } } sub ask_fromW { my ($o, $common, $l) = @_; filter_widgets($l); my $mainw = ugtk2->new($common->{title}, %$o, if__($::main_window, transient => $::main_window), if_($common->{icon}, icon => $common->{icon}), banner_title => $common->{banner_title}, ); my ($box, $set_all) = create_widgets($o, $common, $mainw, $l); $mainw->{box_allow_grow} = 1; my $pack = create_box_with_title($mainw, @{$common->{messages}}); mygtk2::set_main_window_size($mainw->{rwindow}) if $mainw->{pop_it} && !$common->{auto_window_size} && (@$l || $mainw->{box_size} == 200); my @more_buttons = ( if_($common->{interactive_help} || $common->{interactive_help_id}, [ gtknew('Install_Button', text => N("Help"), clicked => sub { display_help($o, $common, $mainw) }), undef, 1 ]), if_($common->{more_buttons}, @{$common->{more_buttons}}), ); my $buttons_pack = ($common->{ok} || !exists $common->{ok}) && $mainw->create_okcancel($common->{ok}, $common->{cancel}, '', @more_buttons); gtkpack_($pack, 1, gtknew('ScrolledWindow', shadow_type => 'none', child => $box)) if @$l; if ($buttons_pack) { $pack->pack_end(gtkshow($buttons_pack), 0, 0, 0); } ugtk2::gtkadd($mainw->{window}, $pack); $set_all->(); my $entry_to_focus = find { $_->{focus} && $_->{focus}() } @$l; my $widget_to_focus = $entry_to_focus ? $entry_to_focus->{focus_w} : $common->{focus_cancel} ? $mainw->{cancel} : @$l && (!$mainw->{ok} || @$l == 1 && member(ref($l->[0]{focus_w}), "Gtk2::TreeView", "Gtk2::RadioButton")) ? $l->[0]{focus_w} : $mainw->{ok}; $widget_to_focus->grab_focus if $widget_to_focus; my $validate = sub { my @all = all_entries($l); my $e = find { $_->{validate} && !$_->{validate}->() } @all; $e ||= $common->{validate} && !$common->{validate}() && $all[0]; if ($e) { $set_all->(); $e->{focus_w}->grab_focus; } !$e; }; $mainw->main($validate); } sub ask_browse_tree_info_refW { my ($o, $common) = @_; add2hash($common, { wait_message => sub { $o->wait_message(@_) } }); ugtk2::ask_browse_tree_info($common); } sub ask_from__add_modify_removeW { my ($o, $title, $message, $l, %callback) = @_; my $e = $l->[0]; my $chosen_element; put_in_hash($e, { allow_empty_list => 1, gtk => { use_boxradio => 0 }, sort => 0, val => \$chosen_element, type => 'list', add_modify_remove => \%callback }); $o->ask_from($title, $message, $l, %callback); } my $reuse_timeout; sub wait_messageW { my ($o, $title, $message, $message_modifiable) = @_; my $to_modify = Gtk2::Label->new(scalar warp_text(ref $message_modifiable ? '' : $message_modifiable)); Glib::Source->remove($reuse_timeout) if $reuse_timeout; $reuse_timeout = ''; my $Window = gtknew('MagicWindow', title => $title, pop_it => defined $o->{pop_wait_messages} ? $o->{pop_wait_messages} : 1, pop_and_reuse => $::isInstall, modal => 1, $::isInstall ? (banner => gtknew('Install_Title', text => $message)) : (), no_Window_Manager => exists $o->{no_Window_Manager} ? $o->{no_Window_Manager} : !$::isStandalone, child => gtknew('VBox', padding => 4, border_width => 10, children => [ 1, $to_modify, if_(ref($message_modifiable), 0, $message_modifiable), ]), ); mygtk2::enable_sync_flush($Window); $Window->{wait_messageW} = $to_modify; mygtk2::sync_flush($Window); $Window; } sub wait_message_nextW { my ($_o, $message, $Window) = @_; return if $message eq $Window->{wait_messageW}->get_text; #- needed otherwise no expose_event :( $Window->{displayed} = 0; $Window->{wait_messageW}->set($message); mygtk2::sync($Window) while !$Window->{displayed}; } sub wait_message_endW { my ($_o, $Window) = @_; if ($Window->{pop_and_reuse}) { $reuse_timeout = Glib::Timeout->add(100, sub { mygtk2::destroy_previous_popped_and_reuse_window(); }); } else { mygtk2::may_destroy($Window); mygtk2::flush(); } } sub wait_message_with_progress_bar { my ($in, $o_title) = @_; my $progress = gtknew('ProgressBar'); my $w = $in->wait_message($o_title, $progress); my $displayed; $progress->signal_connect(expose_event => sub { $displayed = 1; 0 }); $w, sub { my ($msg, $current, $total) = @_; if ($msg) { $w->set($msg); } if ($total) { $progress or internal_error('You must first give some text to display'); my $fraction = min(1, $current / $total); if ($fraction != $progress->get_fraction) { $progress->set_fraction($fraction); $progress->show; $displayed = 0; mygtk2::flush() while !$displayed; } } else { $progress->hide; mygtk2::flush(); } }; } sub kill { my ($_o) = @_; $_->destroy foreach $::WizardTable ? $::WizardTable->get_children : (), @tempory::objects; @tempory::objects = (); } 1; 4' href='#n774'>774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609
package Xconfigurator; # $Id$
use diagnostics;
use strict;
use vars qw($in $do_pkgs @window_managers @depths @monitorSize2resolution @hsyncranges %min_hsync4wres @vsyncranges %depths @resolutions %serversdriver @svgaservers @accelservers @allbutfbservers @allservers @allbutfbdrivers @alldrivers %vgamodes %videomemory @ramdac_name @ramdac_id @clockchip_name @clockchip_id %keymap_translate %standard_monitors $XF86firstchunk_text $keyboardsection_start $keyboardsection_start_v4 $keyboardsection_part2 $keyboardsection_part3 $keyboardsection_part3_v4 $keyboardsection_end $pointersection_text $monitorsection_text1 $monitorsection_text2 $monitorsection_text3 $monitorsection_text4 $modelines_text_Trident_TG_96xx $modelines_text_ext $modelines_text $devicesection_text $devicesection_text_v4 $screensection_text1 %lines @options %xkb_options $good_default_monitor $low_default_monitor $layoutsection_v4 $modelines_text_apple);
use common;
use log;
use detect_devices;
use run_program;
use Xconfigurator_consts;
use any;
use modules;
my $tmpconfig = "/tmp/Xconfig";
my ($prefix, %monitors, %standard_monitors_);
sub xtest {
my ($display) = @_;
$::isStandalone ?
system("DISPLAY=$display /usr/X11R6/bin/xtest") == 0 :
c::Xtest($display);
}
sub getVGAMode($) { $_[0]->{card}{vga_mode} || $vgamodes{"640x480x16"}; }
sub readCardsDB {
my ($file) = @_;
my ($card, %cards);
my $F = common::openFileMaybeCompressed($file);
my ($lineno, $cmd, $val) = 0;
my $fs = {
LINE => sub { push @{$card->{lines}}, $val unless $val eq "VideoRam" },
NAME => sub {
$cards{$card->{type}} = $card if $card;
$card = { type => $val };
},
SEE => sub {
my $c = $cards{$val} or die "Error in database, invalid reference $val at line $lineno";
push @{$card->{lines}}, @{$c->{lines} || []};
add2hash($card->{flags}, $c->{flags});
add2hash($card, $c);
},
CHIPSET => sub {
$card->{chipset} = $val;
$card->{flags}{needChipset} = 1 if $val eq 'GeForce DDR';
$card->{flags}{needVideoRam} = 1 if member($val, qw(mgag10 mgag200 RIVA128 SiS6326));
},
SERVER => sub { $card->{server} = $val; },
DRIVER => sub { $card->{driver} = $val; },
RAMDAC => sub { $card->{ramdac} = $val; },
DACSPEED => sub { $card->{dacspeed} = $val; },
CLOCKCHIP => sub { $card->{clockchip} = $val; $card->{flags}{noclockprobe} = 1; },
NOCLOCKPROBE => sub { $card->{flags}{noclockprobe} = 1 },
UNSUPPORTED => sub { $card->{flags}{unsupported} = 1 },
COMMENT => sub {},
};
local $_;
while (<$F>) { $lineno++;
s/\s+$//;
/^#/ and next;
/^$/ and next;
/^END/ and do { $cards{$card->{type}} = $card if $card; last };
($cmd, $val) = /(\S+)\s*(.*)/ or next; #log::l("bad line $lineno ($_)"), next;
my $f = $fs->{$cmd};
$f ? $f->() : log::l("unknown line $lineno ($_)");
}
\%cards;
}
sub readCardsNames {
my $file = "$ENV{SHARE_PATH}/ldetect-lst/CardsNames";
map { (split '=>')[0] } grep { !/^#/ } catMaybeCompressed($file);
}
sub cardName2RealName {
my ($name) = @_;
my $file = "$ENV{SHARE_PATH}/ldetect-lst/CardsNames";
foreach (catMaybeCompressed($file)) {
chop;
next if /^#/;
my ($name_, $real) = split '=>';
return $real if $name eq $name_;
}
$name;
}
sub realName2CardName {
my ($real) = @_;
my $file = "$ENV{SHARE_PATH}/ldetect-lst/CardsNames";
foreach (catMaybeCompressed($file)) {
chop;
next if /^#/;
my ($name, $real_) = split '=>';
return $name if $real eq $real_;
}
return;
}
sub updateCardAccordingName {
my ($card, $name) = @_;
my $cards = readCardsDB("$ENV{SHARE_PATH}/ldetect-lst/Cards+");
add2hash($card->{flags}, $cards->{$name}{flags});
add2hash($card, $cards->{$name});
$card;
}
sub readMonitorsDB {
my ($file) = @_;
%monitors and return;
my $F = common::openFileMaybeCompressed($file);
local $_;
my $lineno = 0; while (<$F>) {
$lineno++;
s/\s+$//;
/^#/ and next;
/^$/ and next;
my @fields = qw(vendor type eisa hsyncrange vsyncrange dpms);
my @l = split /\s*;\s*/;
my %l; @l{@fields} = @l;
if ($monitors{$l{type}}) {
my $i; for ($i = 0; $monitors{"$l{type} ($i)"}; $i++) {}
$l{type} = "$l{type} ($i)";
}
$monitors{"$l{vendor}|$l{type}"} = \%l;
}
while (my ($k, $v) = each %standard_monitors) {
$monitors{'Generic|' . translate($k)} = $standard_monitors_{$k} =
{ hsyncrange => $v->[1], vsyncrange => $v->[2] };
}
}
sub keepOnlyLegalModes {
my ($card, $monitor) = @_;
my $mem = 1024 * ($card->{memory} || ($card->{server} eq 'FBDev' ? 2048 : 32768)); #- limit to 2048x1536x64
my $hsync = max(split(/[,-]/, $monitor->{hsyncrange}));
while (my ($depth, $res) = each %{$card->{depth}}) {
@$res = grep {
$mem >= product(@$_, $depth / 8) &&
$hsync >= ($min_hsync4wres{$_->[0]} || 0) &&
($card->{server} ne 'FBDev' || $vgamodes{"$_->[0]x$_->[1]x$depth"})
} @$res;
delete $card->{depth}{$depth} if @$res == 0;
}
}
sub cardConfigurationAuto() {
my @cards;
if (my @c = grep { $_->{driver} =~ /(Card|Server):/ } detect_devices::probeall()) {
foreach my $i (0..$#c) {
local $_ = $c[$i]->{driver};
my $card = { identifier => ($c[$i]{description} . (@c > 1 && " $i")) };
$card->{type} = $1 if /Card:(.*)/;
$card->{server} = $1 if /Server:(.*)/;
$card->{driver} = $1 if /Driver:(.*)/;
$card->{flags}{needVideoRam} = /86c368|S3 Inc|Tseng.*ET6\d00/;
$card->{busid} = "PCI:$c[$i]{pci_bus}:$c[$i]{pci_device}:$c[$i]{pci_function}";
push @{$card->{lines}}, @{$lines{$card->{identifier}} || []};
push @cards, $card;
}
}
#- 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!");
local $_ = cat_("/proc/fb");
if (/Mach64/) { push @cards, { server => "Mach64" } }
elsif (/Permedia2/) { push @cards, { server => "3DLabs" } }
else { push @cards, { server => "Sun24" } }
}
#- special case for dual head card using only one busid.
@cards = map { my $dup = $_->{identifier} =~ /MGA G[45]50/ ? 2 : 1;
if ($dup > 1) {
my @result;
my $orig = $_;
foreach (1..$dup) {
my $card = {};
add2hash($card, $orig);
push @result, $card;
}
@result;
} else {
($_);
}
} @cards;
#- make sure no type are already used, duplicate both screen
#- and rename type (because used as id).
if (@cards > 1) {
my $card = 1;
foreach (@cards) {
updateCardAccordingName($_, $_->{type}) if $_->{type};
$_->{type} = "$_->{type} $card";
$card++;
}
}
#- 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?
@cards == 1 and delete $cards[0]{busid} if arch() !~ /ppc/;
@cards;
}
sub cardConfiguration(;$$$) {
my ($card, $noauto, $cardOptions) = @_;
$card ||= {};
updateCardAccordingName($card, $card->{type}) if $card->{type}; #- try to get info from given type
undef $card->{type} unless $card->{server} || $card->{driver}; #- bad type as we can't find the server
my @cards = cardConfigurationAuto();
if (@cards > 1 && ($noauto || !$card->{server})) {#} && !$::isEmbedded) {
my (%single_heads, @choices, $tc);
my $configure_multi_head = sub {
add2hash($card, $cards[0]); #- assume good default.
delete $card->{cards} if $noauto;
$card->{cards} or $card->{cards} = \@cards;
$card->{force_xf4} = 1; #- force XF4 in such case.
$card->{Xinerama} = $_[0];
};
foreach (@cards) {
unless ($_->{driver} && !$_->{flags}{unsupported}) {
log::l("found card \"$_->{identifier}\" not supported by XF4, disabling mutli-head support");
$configure_multi_head = undef;
}
#- if more than one card use the same BusID, we have to use screen.
if ($single_heads{$_->{busid}}) {
$single_heads{$_->{busid}}{screen} ||= 0;
$_->{screen} = $single_heads{$_->{busid}}{screen} + 1;
}
$single_heads{$_->{busid}} = $_;
}
if ($configure_multi_head) {
push @choices, { text => _("Configure all heads independently"), code => sub { $configure_multi_head->('') } };
push @choices, { text => _("Use Xinerama extension"), code => sub { $configure_multi_head->(1) } };
}
foreach my $e (values %single_heads) {
push @choices, { text => _("Configure only card \"%s\" (%s)", $e->{identifier}, $e->{busid}),
code => sub { add2hash($card, $e); foreach (qw(cards screen Xinerama)) { delete $card->{$_} } } };
}
$tc = $in->ask_from_listf(_("Multi-head configuration"),
_("Your system support multiple head configuration.
What do you want to do?"), sub { translate($_[0]{text}) }, \@choices) or return; #- no more die, CHECK with auto that return ''!
$tc->{code} and $tc->{code}();
} else {
#- only one head found, configure it as before.
add2hash($card, $cards[0]) unless $noauto;
delete $card->{cards}; delete $card->{Xinerama};
}
$card->{server} = 'FBDev' unless !$cardOptions->{allowFB} || $card->{server} || $card->{driver} || $card->{type} || $noauto;
my $currentRealName = realName2CardName($card->{type} || $cards[0]{type}) || 'Other|Unlisted';
$card->{type} = cardName2RealName($in->ask_from_treelist(_("Graphic card"),
_("Select a graphic card"), '|', ['Other|Unlisted', readCardsNames()],
$currentRealName))
or return unless $card->{type} || $card->{server} || $card->{driver};
updateCardAccordingName($card, $card->{type}) if $card->{type};
add2hash($card, { vendor => "Unknown", board => "Unknown" });
#- check to use XFree 4 or XFree 3.3.
$card->{use_xf4} = $card->{driver} && !$card->{flags}{unsupported};
$card->{force_xf4} ||= arch() =~ /ppc|ia64/; #- try to figure out ugly hack for PPC (recommend XF4 always so...)
$card->{prefer_xf3} = !$card->{force_xf4} && ($card->{type} =~ /NeoMagic /);
#- take into account current environment in standalone to keep
#- the XFree86 version.
if ($::isStandalone) {
readlink("$prefix/etc/X11/X") =~ /XFree86/ and $card->{prefer_xf3} = 0;
readlink("$prefix/etc/X11/X") =~ /XF86_/ and $card->{prefer_xf3} = !$card->{force_xf4};
}
#- manage X 3.3.6 or above 4.2.0 specific server or driver.
if ($card->{type} eq 'Other|Unlisted') {
undef $card->{type};
my @list = ('server', $cardOptions->{allowFB} ? @allservers : @allbutfbservers);
my $default_server = if_(!$card->{use_xf4} || $card->{prefer_xf3}, $card->{server} || $cards[0]{server}) || 'server';
$card->{server} = $in->ask_from_list(_("X server"), _("Choose a X server"), \@list, $default_server) or return;
if ($card->{server} eq 'server') {
my $fake_card = {};
updateCardAccordingName($fake_card, $cards[0]{type}) if $cards[0]{type};
$card->{server} = $card->{prefer_xf3} = undef;
$card->{use_xf4} = $card->{force_xf4} = 1;
$card->{driver} = $in->ask_from_list(_("X driver"), _("Choose a X driver"),
($cardOptions->{allowFB} ? \@alldrivers : \@allbutfbdrivers),
$card->{driver} || $fake_card->{driver} || $cards[0]{driver}) or return;
} else {
$card->{driver} = $card->{use_xf4} = $card->{force_xf4} = undef;
$card->{prefer_xf3} = 1;
}
}
foreach ($card, @{$card->{cards} || []}) {
$_->{memory} = 4096, delete $_->{depth} if $_->{driver} eq 'i810';
$_->{memory} = 16384, delete $_->{depth} if $_->{chipset} =~ /PERMEDIA/ && $_->{memory} <= 1024;
}
#- 3D acceleration configuration for XFree 3.3 using Utah-GLX.
$card->{Utah_glx} = ($card->{identifier} =~ /Matrox.* G[24]00/ || #- 8bpp does not work.
$card->{identifier} =~ /Rage X[CL]/ ||
$card->{identifier} =~ /3D Rage (?:LT|Pro)/);
#- NOT WORKING $card->{type} =~ /Intel 810/);
$card->{Utah_glx} = '' if arch() =~ /ppc/; #- No 3D XFree 3.3 for PPC
#- 3D acceleration configuration for XFree 3.3 using Utah-GLX but EXPERIMENTAL that may freeze the machine (FOR INFO NOT USED).
$card->{Utah_glx_EXPERIMENTAL} = ($card->{identifier} =~ /[nN]Vidia.*T[nN]T2?/ || #- all RIVA/GeForce comes from NVIDIA ...
$card->{identifier} =~ /[nN]Vidia.*NV[56]/ || #- and may freeze (gltron).
$card->{identifier} =~ /[nN]Vidia.*Vanta/ ||
$card->{identifier} =~ /[nN]Vidia.*GeForce/ ||
$card->{identifier} =~ /[nN]Vidia.*NV1[15]/ ||
$card->{identifier} =~ /[nN]Vidia.*Quadro/ ||
$card->{identifier} =~ /Riva.*128/ || # moved here as not working correctly enough
$card->{identifier} =~ /S3.*Savage.*3D/ || #- only this one is evoluting.
$card->{identifier} =~ /Rage Mobility [PL]/ ||
$card->{identifier} =~ /SiS.*6C?326/ || #- prefer 16bit, other ?
$card->{identifier} =~ /SiS.*6C?236/ ||
$card->{identifier} =~ /SiS.*630/);
#- 3D acceleration configuration for XFree 4 using DRI.
$card->{DRI_glx} = ($card->{identifier} =~ /Voodoo [35]|Voodoo Banshee/ || #- 16bit only
$card->{identifier} =~ /Matrox.* G[245][05]0/ || #- prefer 16bit with AGP only
$card->{identifier} =~ /8281[05].* CGC/ || #- 16bits (Intel 810 & 815).
$card->{identifier} =~ /Radeon / || #- 16bits preferable ?
$card->{identifier} =~ /Rage 128|Rage Mobility M/); #- 16 and 32 bits, prefer 16bit as no DMA.
#- 3D acceleration configuration for XFree 4 using DRI but EXPERIMENTAL that may freeze the machine (FOR INFO NOT USED).
$card->{DRI_glx_EXPERIMENTAL} = ($card->{identifier} =~ /SiS.*6C?326/ || #- prefer 16bit, other ?
$card->{identifier} =~ /SiS.*6C?236/ ||
$card->{identifier} =~ /SiS.*630/);
#- 3D acceleration configuration for XFree 4 using NVIDIA driver (TNT, TN2 and GeForce cards only).
$card->{NVIDIA_glx} = $cardOptions->{allowNVIDIA_rpms} && ($card->{identifier} =~ /[nN]Vidia.*T[nN]T2/ || #- TNT2 cards
$card->{identifier} =~ /[nN]Vidia.*NV[56]/ ||
$card->{identifier} =~ /[nN]Vidia.*Vanta/ ||
$card->{identifier} =~ /[nN]Vidia.*GeForce/ || #- GeForce cards
$card->{identifier} =~ /[nN]Vidia.*NV1[15]/ ||
$card->{identifier} =~ /[nN]Vidia.*Quadro/);
#- hack for SiS 640 for laptop.
if ($card->{identifier} =~ /SiS.*640/ and detect_devices::isLaptop()) {
$card->{use_xf4} = $card->{force_xf4} = '';
$card->{prefer_xf3} = 1;
$card->{server} = 'FBDev';
}
#- XFree version available, better to parse available package and get version from it.
my ($xf4_ver, $xf3_ver) = ("4.2.0", "3.3.6");
#- basic installation, use of XFree 4.2 or XFree 3.3.
my $xf3_tc = { text => _("XFree %s", $xf3_ver),
code => sub { $card->{Utah_glx} = $card->{DRI_glx} = $card->{NVIDIA_glx} = ''; $card->{use_xf4} = '';
log::l("Using XFree $xf3_ver") } };
my $msg = _("Which configuration of XFree do you want to have?");
my @choices = $card->{use_xf4} ? (if_($card->{prefer_xf3}, $xf3_tc),
if_(!$card->{prefer_xf3} || $::expert || $noauto,
{ text => _("XFree %s", $xf4_ver),
code => sub { $card->{Utah_glx} = $card->{DRI_glx} = $card->{NVIDIA_glx} = '';
log::l("Using XFree $xf4_ver") } }),
if_(!$card->{prefer_xf3} && !$card->{force_xf4} && ($::expert || $noauto), $xf3_tc)) : $xf3_tc;
#- try to figure if 3D acceleration is supported
#- by XFree 3.3 but not XFree 4 then ask user to keep XFree 3.3 ?
if ($card->{Utah_glx} && !$card->{force_xf4}) {
$msg = ($card->{use_xf4} && !($card->{DRI_glx} || $card->{NVIDIA_glx}) && !$card->{prefer_xf3} ?
_("Your card can have 3D hardware acceleration support but only with XFree %s.
Your card is supported by XFree %s which may have a better support in 2D.", $xf3_ver, $xf4_ver) :
_("Your card can have 3D hardware acceleration support with XFree %s.", $xf3_ver)) . "\n\n\n" . $msg;
$::expert || $noauto or @choices = (); #- keep it by default here as it is the only choice available.
unshift @choices, { text => _("XFree %s with 3D hardware acceleration", $xf3_ver),
code => sub { $card->{use_xf4} = '';
log::l("Using XFree $xf3_ver with 3D hardware acceleration") } };
}
#- an expert user may want to try to use an EXPERIMENTAL 3D acceleration.
if ($::expert && $card->{use_xf4} && $card->{DRI_glx_EXPERIMENTAL} && !$card->{Xinerama}) {
$msg =
_("Your card can have 3D hardware acceleration support with XFree %s,
NOTE THIS IS EXPERIMENTAL SUPPORT AND MAY FREEZE YOUR COMPUTER.", $xf4_ver) . "\n\n\n" . $msg;
push @choices, { text => _("XFree %s with EXPERIMENTAL 3D hardware acceleration", $xf4_ver),
code => sub { $card->{DRI_glx} = 'EXPERIMENTAL';
log::l("Using XFree $xf4_ver with EXPERIMENTAL 3D hardware acceleration") } };
}
#- an expert user may want to try to use an EXPERIMENTAL 3D acceleration, currenlty
#- this is with Utah GLX and so, it can provide a way of testing.
if ($::expert && $card->{Utah_glx_EXPERIMENTAL} && !$card->{force_xf4}) {
$msg = ($card->{use_xf4} && !($card->{DRI_glx} || $card->{NVIDIA_glx}) && !$card->{prefer_xf3} ?
_("Your card can have 3D hardware acceleration support but only with XFree %s,
NOTE THIS IS EXPERIMENTAL SUPPORT AND MAY FREEZE YOUR COMPUTER.
Your card is supported by XFree %s which may have a better support in 2D.", $xf3_ver, $xf4_ver) :
_("Your card can have 3D hardware acceleration support with XFree %s,
NOTE THIS IS EXPERIMENTAL SUPPORT AND MAY FREEZE YOUR COMPUTER.", $xf3_ver)) . "\n\n\n" . $msg;
push @choices, { text => _("XFree %s with EXPERIMENTAL 3D hardware acceleration", $xf3_ver),
code => sub { $card->{use_xf4} = ''; $card->{Utah_glx} = 'EXPERIMENTAL';
log::l("Using XFree $xf3_ver with EXPERIMENTAL 3D hardware acceleration") } };
}
#- ask the expert or any user on second pass user to enable or not hardware acceleration support.
if ($card->{use_xf4} && ($card->{DRI_glx} || $card->{NVIDIA_glx}) && !$card->{Xinerama}) {
$msg = _("Your card can have 3D hardware acceleration support with XFree %s.", $xf4_ver) . "\n\n\n" . $msg;
$::expert || $noauto or @choices = (); #- keep all user by default with XFree 4 including 3D acceleration.
unshift @choices, { text => _("XFree %s with 3D hardware acceleration", $xf4_ver),
code => sub { log::l("Using XFree $xf4_ver with 3D hardware acceleration") } };
}
if (arch() =~ /ppc/) {
#- not much choice for PPC - we only have XF4, and Xpmac from the installer
@choices = { text => _("XFree %s", $xf4_ver), code => sub { $card->{xpmac} = ''; log::l("Using XFree $xf4_ver") } };
push @choices, { text => _("Xpmac (installation display driver)"), code => sub { $card->{xpmac} = 1 }} if ($ENV{DISPLAY});
}
#- examine choice of user, beware the list MUST NOT BE REORDERED AS the first item should be the
#- proposed one by DrakX.
my $tc = $in->ask_from_listf(_("XFree configuration"), formatAlaTeX($msg), sub { translate($_[0]{text}) }, \@choices) or return;
#- in case of class discarding, this can help ...
$tc or $tc = $choices[0];
$tc->{code} and $tc->{code}();
if ($card->{xpmac} eq "1") {
log::l("Use Xpmac - great...");
#- define this stuff just so XF86Config isn't empty - we don't need it for Xpmac
$card->{type} = "Xpmac Frame Buffer Driver";
$card->{vendor} = $card->{board} = "None";
$card->{driver} = $card->{server} = "Xpmac";
}
$card->{prog} = "/usr/X11R6/bin/" . ($card->{use_xf4} ? 'XFree86' : $card->{server} =~ /Sun(.*)/ ?
"Xsun$1" : "XF86_$card->{server}");
#- additional packages to install according available card.
#- add XFree86-libs-DRI here if using DRI (future split of XFree86 TODO)
my @l = ();
if ($card->{DRI_glx}) {
push @l, 'Glide_V5' if $card->{identifier} =~ /Voodoo 5/;
push @l, 'Glide_V3-DRI' if $card->{identifier} =~ /Voodoo (3|Banshee)/;
push @l, 'XFree86-glide-module' if $card->{identifier} =~ /Voodoo/;
} elsif ($card->{NVIDIA_glx}) {
push @l, @{$cardOptions->{allowNVIDIA_rpms}};
}
if ($card->{Utah_glx}) {
push @l, 'Mesa' if !$card->{use_xf4};
}
if ($card->{xpmac} eq "1") {
push @l, 'XFree86-Xpmac';
$card->{use_xf4} = '';
$card->{prog} = "/usr/X11R6/bin/Xpmac";
$card->{server} = 'Xpmac';
}
unless ($::g_auto_install) {
-x "$prefix$card->{prog}" or $do_pkgs->install($card->{use_xf4} ? 'XFree86-server' : "XFree86-$card->{server}", @l);
-x "$prefix$card->{prog}" or die "server $card->{server} is not available (should be in $prefix$card->{prog})";
}
#- check for Matrox G200 PCI cards, disable AGP in such cases, causes black screen else.
if ($card->{identifier} =~ /Matrox.* G[24]00/ && $card->{identifier} !~ /AGP/) {
log::l("disabling AGP mode for Matrox card, as it seems to be a PCI card");
log::l("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";
}
#- make sure everything is correct at this point, packages have really been installed
#- and driver and GLX extension is present.
if ($card->{NVIDIA_glx} && !$card->{DRI_glx} && (-e "$prefix/usr/X11R6/lib/modules/drivers/nvidia_drv.o" &&
-e "$prefix/usr/X11R6/lib/modules/extensions/libglx.so")) {
log::l("Using specific NVIDIA driver and GLX extensions");
$card->{driver} = 'nvidia';
foreach (@{$cardOptions->{allowNVIDIA_rpms}}) { #- hack as NVIDIA_kernel package does not do it actually (8.1 OEM).
if (/NVIDIA_kernel-([^\-]*)-([^\-]*)(?:-(.*))?/ && -e "$prefix/boot/System.map-$1-$2$3") {
run_program::rooted($prefix, "/sbin/depmod", "-a", "-F", "/boot/System.map-$1-$2$3", "$1-$2$3");
}
}
} else {
$card->{NVIDIA_glx} = '';
}
delete $card->{depth}{32} if $card->{type} =~ /S3 Trio3D|SiS/;
$card->{options}{sw_cursor} = 1 if $card->{type} =~ /S3 Trio3D|SiS 6326/;
unless ($card->{type}) {
$card->{flags}{noclockprobe} = member($card->{server}, qw(I128 S3 S3V Mach64));
}
$card->{options_xf3}{power_saver} = 1;
$card->{options_xf4}{DPMS} = 'on';
$card->{flags}{needVideoRam} and
$card->{memory} ||= $videomemory{$in->ask_from_list_('', _("Select the memory size of your graphic card"),
[ sort { $videomemory{$a} <=> $videomemory{$b} }
keys %videomemory]) || return};
#- hack for ATI Mach64 cards where two options should be used if using Utah-GLX.
if ($card->{identifier} =~ /Rage X[CL]/ ||
$card->{identifier} =~ /Rage Mobility [PL]/ ||
$card->{identifier} =~ /3D Rage (?:LT|Pro)/) {
$card->{options_xf3}{no_font_cache} = $card->{Utah_glx};
$card->{options_xf3}{no_pixmap_cache} = $card->{Utah_glx};
}
#- hack for SiS cards where an option should be used if using Utah-GLX.
if ($card->{identifier} =~ /SiS.*6C?326/ ||
$card->{identifier} =~ /SiS.*6C?236/ ||
$card->{identifier} =~ /SiS.*630/) {
$card->{options_xf3}{no_pixmap_cache} = $card->{Utah_glx};
}
#- 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 won't run).
if ($card->{DRI_glx}) {
$card->{identifier} =~ /Matrox.* G[245][05]0/ and $card->{flags}{needVideoRam} = 'fakeVideoRam';
$card->{identifier} =~ /8281[05].* CGC/ and ($card->{flags}{needVideoRam}, $card->{memory}) = ('fakeVideoRam', 16384);
#- always enable (as a reminder for people using a better AGP mode to change it at their own risk).
$card->{options_xf4}{AGPMode} = '1';
#- hack for ATI Rage 128 card using a bttv or peripheral with PCI bus mastering exchange
#- AND using DRI at the same time.
if ($card->{identifier} =~ /Rage 128|Rage Mobility M/) {
$card->{options_xf4}{UseCCEFor2D} = (detect_devices::matching_desc('Bt8[47][89]') ||
detect_devices::matching_desc('TV') ||
detect_devices::matching_desc('AG GMV1')) ? 'true' : 'false';
}
}
$card;
}
sub optionsConfiguration($) {
my ($o) = @_;
my @l;
my %l;
foreach (@options) {
if ($o->{card}{server} eq $_->[1] && $o->{card}{identifier} =~ /$_->[2]/) {
my $options = 'options_' . ($o->{card}{server} eq 'XFree86' ? 'xf4' : 'xf3');
$o->{card}{$options}{$_->[0]} ||= 0;
unless ($l{$_->[0]}) {
push @l, { label => $_->[0], val => \$o->{card}{$options}{$_->[0]}, type => 'bool' };
$l{$_->[0]} = 1;
}
}
}
@l = @l[0..9] if @l > 9; #- reduce list size to 10 for display
$in->ask_from('', _("Choose options for server"), \@l);
}
sub monitorConfiguration(;$$) {
my $monitor = shift || {};
my $useFB = shift || 0;
readMonitorsDB("$ENV{SHARE_PATH}/ldetect-lst/MonitorsDB");
if ($monitor->{EISA_ID}) {
log::l("EISA_ID: $monitor->{EISA_ID}");
if (my ($mon) = grep { lc($_->{eisa}) eq $monitor->{EISA_ID} } values %monitors) {
add2hash($monitor, $mon);
log::l("EISA_ID corresponds to: $monitor->{type}");
}
}
if ($monitor->{hsyncrange} && $monitor->{vsyncrange}) {
add2hash($monitor, { type => "monitor1", vendor => "Unknown", model => "Unknown" });
return $monitor;
}
my $good_default = (arch() =~ /ppc/ ? 'Apple|' : 'Generic|') . translate($good_default_monitor);
$monitor->{type} ||=
($::auto_install ? $low_default_monitor :
$in->ask_from_treelist(_("Monitor"), _("Choose a monitor"), '|', ['Custom', keys %monitors], $good_default));
if ($monitor->{type} eq 'Custom') {
$in->ask_from('',
_("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->{hsyncrange}, list => \@hsyncranges, label => _("Horizontal refresh rate"), not_edit => 0 },
{ val => \$monitor->{vsyncrange}, list => \@vsyncranges, label => _("Vertical refresh rate"), not_edit => 0 } ]);
} else {
add2hash($monitor, $monitors{$monitor->{type}} || $standard_monitors_{$monitor->{type}});
}
add2hash($monitor, { type => "Unknown", vendor => "Unknown", model => "Unknown", manual => 1 });
}
sub testConfig($) {
my ($o) = @_;
my ($resolutions, $clocklines);
write_XF86Config($o, $tmpconfig);
unlink "/tmp/.X9-lock";
#- restart_xfs;
my $f = $tmpconfig . ($o->{card}{use_xf4} && "-4");
local *F; open F, "$prefix$o->{card}{prog} :9 -probeonly -pn -xf86config $f 2>&1 |";
local $_;
while (<F>) {
$o->{card}{memory} ||= $2 if /(videoram|Video RAM):\s*(\d*)/;
# look for clocks
push @$clocklines, $1 if /clocks: (.*)/ && !/(pixel |num)clocks:/;
push @$resolutions, [ $1, $2 ] if /: Mode "(\d+)x(\d+)": mode clock/;
print;
}
close F or die "X probeonly failed";
($resolutions, $clocklines);
}
sub testFinalConfig {
my ($o, $auto, $skiptest, $skip_badcard) = @_;
$o->{monitor}{hsyncrange} && $o->{monitor}{vsyncrange} or
$in->ask_warn('', _("Monitor not configured")), return;
$o->{card}{server} || $o->{card}{driver} or
$in->ask_warn('', _("Graphic card not configured yet")), return;
$o->{card}{depth} or
$in->ask_warn('', _("Resolutions not chosen yet")), return;
my $f = "/etc/X11/XF86Config.test";
write_XF86Config($o, $::testing ? $tmpconfig : "$prefix/$f");
$skiptest || $o->{card}{server} =~ 'FBDev|Sun' and return 1; #- avoid testing with these.
#- needed for bad cards not restoring cleanly framebuffer, according to which version of XFree are used.
my $bad_card = ($o->{card}{use_xf4} ?
$o->{card}{identifier} =~ /Matrox|SiS.*SG86C2.5|SiS.*559[78]|SiS.*300|SiS.*540|SiS.*6C?326|SiS.*6C?236|Tseng.*ET6\d00|Riva.*128/ :
$o->{card}{identifier} =~ /i740|Rage Mobility [PL]|3D Rage LT|Rage 128/);
$::live and $bad_card ||= $o->{card}{identifier} =~ /S3.*ViRGE/;
log::l("the graphic card does not like X in framebuffer") if $bad_card;
my $verybad_card = $o->{card}{driver} eq 'i810' || $o->{card}{driver} eq 'fbdev';
$verybad_card ||= $o->{card}{driver} eq 'nvidia' && !$::isStandalone; #- avoid testing during install at any price.
$bad_card || $verybad_card and return 1; #- deactivating bad_card test too.
my $mesg = _("Do you want to test the configuration?");
my $def = 1;
if ($bad_card && !$::isStandalone) {
$skip_badcard and return 1;
$mesg = $mesg . "\n" . _("Warning: testing this graphic card may freeze your computer");
$def = 0;
}
$auto && $def or $in->ask_yesorno(_("Test of the configuration"), $mesg, $def) 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;
}
#- restart_xfs;
my $f_err = "$prefix/tmp/Xoutput";
my $pid;
unless ($pid = fork) {
system("xauth add :9 . `mcookie`");
open STDERR, ">$f_err";
chroot $prefix if $prefix;
exec $o->{card}{prog},
if_($o->{card}{prog} !~ /Xsun/, "-xf86config", ($::testing ? $tmpconfig : $f) . ($o->{card}{use_xf4} && "-4")),
":9" or c::_exit(0);
}
do { sleep 1 } until xtest(":9") || waitpid($pid, c::WNOHANG());
my $b = before_leaving { unlink $f_err };
unless (xtest(":9")) {
local $_;
local *F; open F, $f_err;
i: while (<F>) {
if ($o->{card}{use_xf4}) {
if (/^\(EE\)/ && $_ !~ /Disabling/ || /^Fatal\b/) {
my @msg = !/error/ && $_ ;
while (<F>) {
/reporting a problem/ and last;
push @msg, $_;
$in->ask_warn('', [ _("An error has occurred:"), " ", @msg, _("\ntry to change some parameters") ]);
return 0;
}
}
} else {
if (/\b(error|not supported)\b/i) {
my @msg = !/error/ && $_ ;
while (<F>) {
/not fatal/ and last i;
/^$/ and last;
push @msg, $_;
}
$in->ask_warn('', [ _("An error has occurred:"), " ", @msg, _("\ntry to change some parameters") ]);
return 0;
}
}
}
}
$::noShadow = 1;
local *F;
open F, "|perl 2>/dev/null" or die '';
print F "use lib qw(", join(' ', @INC), ");\n";
print F q{
use interactive_gtk;
use my_gtk qw(:wrappers);
$ENV{DISPLAY} = ":9";
gtkset_background(200 * 257, 210 * 257, 210 * 257);
my ($h, $w) = Gtk::Gdk::Window->new_foreign(Gtk::Gdk->ROOT_WINDOW)->get_size;
$my_gtk::force_position = [ $w / 3, $h / 2.4 ];
$my_gtk::force_focus = 1;
my $text = Gtk::Label->new;
my $time = 8;
Gtk->timeout_add(1000, sub {
$text->set(_("Leaving in %d seconds", $time));
$time-- or Gtk->main_quit;
1;
});
my $background = "/usr/share/pixmaps/backgrounds/linux-mandrake/XFdrake-image-test.jpg";
my $qiv = "/usr/bin/qiv";
-r "} . $prefix . q{/$background" && -x "} . $prefix . q{/$qiv" and
system(($::testing ? "} . $prefix . q{" : "chroot } . $prefix . q{/ ") . "$qiv -y $background");
my $in = interactive_gtk->new;
$in->exit($in->ask_yesorno('', [ _("Is this the correct setting?"), $text ], 0) ? 0 : 222);
};
my $rc = close F;
my $err = $?;
unlink "/tmp/.X11-unix/X9" if $prefix;
kill 2, $pid;
$::noShadow = 0;
$rc || $err == 222 << 8 or $in->ask_warn('', _("An error has occurred, try to change some parameters"));
$rc;
}
sub allowedDepth($) {
my ($card) = @_;
my %allowed_depth;
if ($card->{Utah_glx} || $card->{DRI_glx}) {
$allowed_depth{16} = 1; #- this is the default.
$card->{identifier} =~ /Voodoo 5/ and $allowed_depth{24} = undef;
$card->{identifier} =~ /Matrox.* G[245][05]0/ and $allowed_depth{24} = undef;
$card->{identifier} =~ /Rage 128/ and $allowed_depth{24} = undef;
$card->{identifier} =~ /Radeon/ and $allowed_depth{24} = undef;
}
for ($card->{server}) {
#- this should work by default, FBDev is allowed only if install currently uses it at 16bpp.
/FBDev/ and $allowed_depth{16} = 1;
#- Sun servers, Sun24 handles 24,8,2; Sun only 8 and 2; and SunMono only 2.
/^Sun24$/ and @allowed_depth{qw(24 8 2)} = (1);
/^Sun$/ and @allowed_depth{qw(8 2)} = (1);
/^SunMono$/ and @allowed_depth{qw(2)} = (1);
}
return %allowed_depth && \%allowed_depth; #- no restriction if false is returned.
}
sub autoDefaultDepth($$) {
my ($card, $wres_wanted) = @_;
my ($best, $depth);
#- check for forced depth according to current environment.
my $allowed_depth = allowedDepth($card);
if ($allowed_depth) {
foreach (keys %$allowed_depth) {
$allowed_depth->{$_} and return $_; #- a default depth is given.
}
}
while (my ($d, $r) = each %{$card->{depth}}) {
$allowed_depth && ! exists $allowed_depth->{$d} and next; #- reject depth.
$depth = max($depth || 0, $d);
#- try to have resolution_wanted
$best = max($best || 0, $d) if $r->[0][0] >= $wres_wanted;
$best = $card->{suggest_depth}, last if ($card->{suggest_depth} &&
$card->{suggest_wres} && $r->[0][0] >= $card->{suggest_wres});
}
$best || $depth or die "no valid modes";
}
sub autoDefaultResolution {
# return "1024x768" if detect_devices::hasPCMCIA;
if (arch() =~ /ppc/) {
return "1024x768" if detect_devices::get_mac_model =~ /^PowerBook|^iMac/;
}
my ($size) = @_;
$monitorSize2resolution[round($size || 14)] || #- assume a small monitor (size is in inch)
$monitorSize2resolution[-1]; #- no corresponding resolution for this size. It means a big monitor, take biggest we have
}
sub chooseResolutionsGtk($$;$) {
my ($card, $chosen_depth, $chosen_w) = @_;
require my_gtk;
my_gtk->import(qw(:helpers :wrappers));
my $W = my_gtk->new(_("Resolution"));
my %txt2depth = reverse %depths;
my ($r, $depth_combo, %w2depth, %w2h, %w2widget, $pix_monitor, $pix_colors, $w2_combo);
$w2_combo = new Gtk::Combo;
my $best_w;
my $allowed_depth = allowedDepth($card);
my %allowed_depth;
while (my ($depth, $res) = each %{$card->{depth}}) {
$allowed_depth && ! exists $allowed_depth->{$depth} and next; #- reject depth.
foreach (@$res) {
++$allowed_depth{$depth};
$w2h{$_->[0]} = $_->[1];
push @{$w2depth{$_->[0]}}, $depth;
$best_w = max($_->[0], $best_w) if $_->[0] <= $chosen_w;
}
}
$chosen_w = $best_w;
my $set_depth = sub { $depth_combo->entry->set_text(translate($depths{$chosen_depth})) };
#- the set function is usefull to toggle the CheckButton with the callback being ignored
my $ignore;
my $no_human; # is the w2_combo->entry changed by a human?
my $set = sub { $ignore = 1; $_[0] and $_[0]->set_active(1); $ignore = 0; };
my %monitor;
$monitor{$_} = [ gtkcreate_png("monitor-" . $_ . ".png") ] foreach (640, 800, 1024, 1280);
$monitor{1152} = [ gtkcreate_png("monitor-" . 1024 . ".png") ];
$monitor{1600} = [ gtkcreate_png("monitor-" . 1280 . ".png") ];
my $pixmap_m = new Gtk::Pixmap( $monitor{$chosen_w}[0] , $monitor{$chosen_w}[1] );