From b60b957d3a8821b7f1afb298e40809d58deb3c9c Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Thu, 1 Aug 2002 21:25:55 +0000 Subject: - the old $o->{keyboard} is now $o->{keyboard}{KEYBOARD} - KBCHARSET is $o->{keyboard}{KBCHARSET} - isNotDelete is $o->{keyboard}{BACKSPACE} (as written in sysconfig/keyboard) - add GRP_TOGGLE which gives XkbOptions "grp:GRP_TOGGLE" - add dialog box to choose GRP_TOGGLE --- perl-install/Xconfig/default.pm | 1 + perl-install/Xconfig/parse.pm | 2 +- perl-install/Xconfig/xfreeX.pm | 2 +- perl-install/any.pm | 16 +++++ perl-install/commands.pm | 2 +- perl-install/install2.pm | 9 +-- perl-install/install_steps.pm | 10 ++- perl-install/install_steps_interactive.pm | 48 +++++++------- perl-install/keyboard.pm | 107 ++++++++++++++++-------------- perl-install/printerdrake.pm | 2 +- perl-install/standalone/keyboarddrake | 75 +++++++++++---------- 11 files changed, 153 insertions(+), 121 deletions(-) (limited to 'perl-install') diff --git a/perl-install/Xconfig/default.pm b/perl-install/Xconfig/default.pm index c33d084d8..b9072140e 100644 --- a/perl-install/Xconfig/default.pm +++ b/perl-install/Xconfig/default.pm @@ -63,6 +63,7 @@ sub config_keyboard { my $xkb = { $XkbLayout ? ( XkbLayout => $XkbLayout, XkbModel => $XkbModel, + if_($keyboard->{GRP_TOGGLE}, XkbOptions => "grp:$keyboard->{GRP_TOGGLE}"), ) : (XkbDisable => undef) }; $raw_X->set_keyboard($xkb); } diff --git a/perl-install/Xconfig/parse.pm b/perl-install/Xconfig/parse.pm index 02daa3227..dbd8851ea 100644 --- a/perl-install/Xconfig/parse.pm +++ b/perl-install/Xconfig/parse.pm @@ -139,7 +139,7 @@ my %kind_names = ( InputDevice => [ qw(Identifier Driver Protocol Device Type Mode XkbModel XkbLayout XkbDisable Emulate3Buttons Emulate3Timeout) ], ServerLayout => [ qw(Identifier) ], ); -my @want_string = qw(Identifier DeviceName VendorName ModelName BoardName Driver Device Chipset Monitor Protocol XkbModel XkbLayout Load BusID); +my @want_string = qw(Identifier DeviceName VendorName ModelName BoardName Driver Device Chipset Monitor Protocol XkbModel XkbLayout XkbOptions Load BusID); %kind_names = map_each { lc $::a => [ map { lc } @$::b ] } %kind_names; @want_string = map { lc } @want_string; diff --git a/perl-install/Xconfig/xfreeX.pm b/perl-install/Xconfig/xfreeX.pm index f6aa17f78..6154cb547 100644 --- a/perl-install/Xconfig/xfreeX.pm +++ b/perl-install/Xconfig/xfreeX.pm @@ -51,7 +51,7 @@ sub get_monitor { $l[0] } -my @keyboard_fields = qw(XkbLayout XkbModel XkbDisable); +my @keyboard_fields = qw(XkbLayout XkbModel XkbDisable XkbOptions); sub get_keyboard { my ($raw_X) = @_; my $raw_kbd = $raw_X->get_keyboard_section; diff --git a/perl-install/any.pm b/perl-install/any.pm index 4085add9c..30816b056 100644 --- a/perl-install/any.pm +++ b/perl-install/any.pm @@ -13,6 +13,7 @@ use fsedit; use fs; use lang; use run_program; +use keyboard; use devices; use modules; use log; @@ -1181,4 +1182,19 @@ sub config_mtools { } $file; } +sub keyboard_group_toggle_choose { + my ($in, $keyboard) = @_; + + my $grp_toggles = keyboard::grp_toggles($keyboard) or return 1; + + my $GRP_TOGGLE = + $in->ask_from_listf('', _("Here you can choose the key or key combination that will +allow switching between the different keyboard layouts +(eg: latin and non latin)"), sub { $grp_toggles->{$_[0]} }, [ sort keys %$grp_toggles ], 'caps_toggle') or return; + + log::l("GRP_TOGGLE: $GRP_TOGGLE"); + $keyboard->{GRP_TOGGLE} = $GRP_TOGGLE; + 1; +} + 1; diff --git a/perl-install/commands.pm b/perl-install/commands.pm index 3294c1060..1a7f09634 100644 --- a/perl-install/commands.pm +++ b/perl-install/commands.pm @@ -576,7 +576,7 @@ sub loadkeys { $h || @_ != 1 and die "usage: loadkeys \n"; require keyboard; - keyboard::setup($_[0]); + keyboard::setup({ KEYBOARD => $_[0]}); } sub sync { common::sync() } diff --git a/perl-install/install2.pm b/perl-install/install2.pm index 0010268cd..66e7f32b2 100644 --- a/perl-install/install2.pm +++ b/perl-install/install2.pm @@ -119,10 +119,11 @@ sub setupSCSI { #------------------------------------------------------------------------------ sub selectKeyboard { my ($clicked, $first_time, $auto) = ($_[0], $_[1] == 1, $_[2]); - - if ($o->{isUpgrade} && $first_time && $o->{keyboard_unsafe}) { - my $keyboard = keyboard::read($o->{prefix}); - $keyboard and $o->{keyboard} = $keyboard; + + if ($o->{isUpgrade} && $first_time && $o->{keyboard}{unsafe}) { + if (my $keyboard = keyboard::read($o->{prefix})) { + $o->{keyboard} = $keyboard; + } } installStepsCall($o, $auto, 'selectKeyboard', $clicked); } diff --git a/perl-install/install_steps.pm b/perl-install/install_steps.pm index d1509224b..74a7bab16 100644 --- a/perl-install/install_steps.pm +++ b/perl-install/install_steps.pm @@ -93,9 +93,12 @@ sub selectLanguage { log::l("selectLanguage: pack_langs ", lang::pack_langs($o->{langs})); - if ($o->{keyboard_unsafe} || !$o->{keyboard}) { - $o->{keyboard_unsafe} = 1; + #- for auto_install compatibility with old $o->{keyboard} containing directly $o->{keyboard}{KEYBOARD} + $o->{keyboard} = { KEYBOARD => $o->{keyboard} } if $o->{keyboard} && !ref($o->{keyboard}); + + if (!$o->{keyboard} || $o->{keyboard}{unsafe}) { $o->{keyboard} = keyboard::from_usb() || keyboard::lang2keyboard($o->{lang}); + $o->{keyboard}{unsafe} = 1; keyboard::setup($o->{keyboard}) if !$::live; } @@ -109,10 +112,11 @@ sub selectLanguage { #------------------------------------------------------------------------------ sub selectKeyboard { my ($o) = @_; + $o->{keyboard}{KBCHARSET} = lang::lang2charset($o->{lang}); keyboard::setup($o->{keyboard}); addToBeDone { - keyboard::write($o->{prefix}, $o->{keyboard}, lang::lang2charset($o->{lang})); + keyboard::write($o->{keyboard}); } 'installPackages' unless $::g_auto_install; } #------------------------------------------------------------------------------ diff --git a/perl-install/install_steps_interactive.pm b/perl-install/install_steps_interactive.pm index 212e3fd4a..b80f0d7f4 100644 --- a/perl-install/install_steps_interactive.pm +++ b/perl-install/install_steps_interactive.pm @@ -200,30 +200,28 @@ sub selectKeyboard { my $from_usb = keyboard::from_usb(); my $l = keyboard::lang2keyboards(lang::langs($o->{langs})); - #- good guess, don't ask ($o->{keyboard} already set) - return install_steps::selectKeyboard($o) - if !$::expert && !$clicked && ($from_usb || $l->[0][1] >= 90) && listlength(lang::langs($o->{langs})) == 1; - - my @best = uniq(if_($from_usb, $from_usb), (map { $_->[0] } @$l), 'us_intl'); - - my $format = sub { translate(keyboard::keyboard2text($_[0])) }; - my $other; - my $ext_keyboard = $o->{keyboard}; - $o->ask_from_( - { title => _("Keyboard"), - messages => _("Please choose your keyboard layout."), - advanced_messages => _("Here is the full list of keyboards available"), - advanced_label => _("More"), - callbacks => { changed => sub { $other = $_[0]==1 } }, - }, - [ if_(@best > 1, { val => \$o->{keyboard}, type => 'list', format => $format, sort => 1, - list => [ @best ] }), - { val => \$ext_keyboard, type => 'list', format => $format, - list => [ difference2([ keyboard::keyboards ], \@best) ], advanced => @best > 1 } - ]); - delete $o->{keyboard_unsafe}; - - $o->{keyboard} = $ext_keyboard if $other; + if ($::expert || $clicked || !($from_usb || @$l && $l->[0][1] >= 90) || listlength(lang::langs($o->{langs})) > 1) { + add2hash($o->{keyboard}, $from_usb); + my @best = uniq($from_usb ? $from_usb->{KEYBOARD} : (), (map { $_->[0] } @$l), 'us_intl'); + + my $format = sub { translate(keyboard::KEYBOARD2text($_[0])) }; + my $other; + my $ext_keyboard = my $KEYBOARD = $o->{keyboard}{KEYBOARD}; + $o->ask_from_( + { title => _("Keyboard"), + messages => _("Please choose your keyboard layout."), + advanced_messages => _("Here is the full list of keyboards available"), + advanced_label => _("More"), + callbacks => { changed => sub { $other = $_[0]==1 } }, + }, + [ if_(@best > 1, { val => \$KEYBOARD, type => 'list', format => $format, sort => 1, + list => [ @best ] }), + { val => \$ext_keyboard, type => 'list', format => $format, + list => [ difference2([ keyboard::KEYBOARDs() ], \@best) ], advanced => @best > 1 } + ]); + $o->{keyboard}{KEYBOARD} = $other ? $ext_keyboard : $KEYBOARD; + } + any::keyboard_group_toggle_choose($o, $o->{keyboard}) or goto &selectKeyboard; install_steps::selectKeyboard($o); } #------------------------------------------------------------------------------ @@ -850,7 +848,7 @@ sub configureNetwork { my ($o, $first_time, $noauto) = @_; require network::netconnect; network::netconnect::main($o->{prefix}, $o->{netcnx} ||= {}, $o->{netc}, $o->{mouse}, $o, $o->{intf}, - $first_time, $o->{lang} eq "fr_FR" && $o->{keyboard} eq "fr", $noauto); + $first_time, $o->{lang} eq "fr_FR" && $o->{keyboard}{KEYBOARD} eq "fr", $noauto); } #-configureNetworkIntf moved to network diff --git a/perl-install/keyboard.pm b/perl-install/keyboard.pm index 38cd03c72..8c29c8e03 100644 --- a/perl-install/keyboard.pm +++ b/perl-install/keyboard.pm @@ -264,27 +264,40 @@ arch() =~ /^sparc/ ? ( #- list of possible choices for the key combinations to toggle XKB groups #- (eg in X86Config file: XkbOptions "grp:toggle") -my %kbdgrptoggle = -( - 'toggle' => _("Right Alt key"), - 'shift_toggle' => _("Both Shift keys simultaneously"), - 'ctrl_shift_toggle' => _("Control and Shift keys simultaneously"), - 'caps_toggle' => _("CapsLock key"), - 'ctrl_alt_toggle' => _("Ctrl and Alt keys simultaneously"), - 'alt_shift_toggle' => _("Alt and Shift keys simultaneously"), - 'menu_toggle' => _("\"Menu\" key"), - 'lwin_toggle' => _("Left \"Windows\" key"), - 'rwin_toggle' => _("Right \"Windows\" key"), +my %grp_toggles = ( + toggle => _("Right Alt key"), + shift_toggle => _("Both Shift keys simultaneously"), + ctrl_shift_toggle => _("Control and Shift keys simultaneously"), + caps_toggle => _("CapsLock key"), + ctrl_alt_toggle => _("Ctrl and Alt keys simultaneously"), + alt_shift_toggle => _("Alt and Shift keys simultaneously"), + menu_toggle => _("\"Menu\" key"), + lwin_toggle => _("Left \"Windows\" key"), + rwin_toggle => _("Right \"Windows\" key"), ); #-###################################################################################### #- Functions #-###################################################################################### -sub keyboards { keys %keyboards } -sub keyboard2text { $keyboards{$_[0]} && $keyboards{$_[0]}[0] } -sub keyboard2kmap { $keyboards{$_[0]} && $keyboards{$_[0]}[1] } -sub keyboard2xkb { $keyboards{$_[0]} && $keyboards{$_[0]}[2] } +sub KEYBOARDs { keys %keyboards } +sub KEYBOARD2text { $keyboards{$_[0]} && $keyboards{$_[0]}[0] } +sub keyboards { map { { KEYBOARD => $_ } } keys %keyboards } +sub keyboard2one { + my ($keyboard, $nb) = @_; + ref $keyboard or internal_error(); + my $l = $keyboards{$keyboard->{KEYBOARD}} or return; + $l->[$nb]; +} +sub keyboard2text { keyboard2one($_[0], 0) } +sub keyboard2kmap { keyboard2one($_[0], 1) } +sub keyboard2xkb { keyboard2one($_[0], 2) } + +sub grp_toggles { + my ($keyboard) = @_; + keyboard2one($keyboard, 3) or return; + \%grp_toggles; +} sub loadkeys_files { my ($err) = @_; @@ -336,7 +349,7 @@ sub lang2keyboards { sub lang2keyboard { my ($l) = @_; my $kb = lang2keyboards($l)->[0][0]; - $keyboards{$kb} ? $kb : "us"; #- handle incorrect keyboard mapping to us. + { KEYBOARD => $keyboards{$kb} ? $kb : 'us' }; #- handle incorrect keyboard mapping to us. } sub from_usb { @@ -344,7 +357,7 @@ sub from_usb { my ($usb_kbd) = detect_devices::usbKeyboards() or return; my $country_code = detect_devices::usbKeyboard2country_code($usb_kbd) or return; my $keyboard = $usb2keyboard[$country_code]; - $keyboard !~ /SKIP/ && $keyboard; + $keyboard !~ /SKIP/ && { KEYBOARD => $keyboard }; } sub load { @@ -379,19 +392,22 @@ sub load { sub xmodmap_file { my ($keyboard) = @_; - my $f = "$ENV{SHARE_PATH}/xmodmap/xmodmap.$keyboard"; + my $KEYBOARD = $keyboard->{KEYBOARD}; + my $f = "$ENV{SHARE_PATH}/xmodmap/xmodmap.$KEYBOARD"; if (! -e $f) { eval { require packdrake; my $packer = new packdrake("$ENV{SHARE_PATH}/xmodmap.cz2", quiet => 1); - $packer->extract_archive("/tmp", "xmodmap.$keyboard"); + $packer->extract_archive("/tmp", "xmodmap.$KEYBOARD"); }; - $f = "/tmp/xmodmap.$keyboard"; + $f = "/tmp/xmodmap.$KEYBOARD"; } -e $f && $f; } sub setup { + my ($keyboard) = @_; + return if arch() =~ /^sparc/; #- Xpmac doesn't map keys quite right @@ -403,11 +419,10 @@ sub setup { return; } - my ($keyboard) = @_; - my $o = $keyboards{$keyboard} or return; + my $kmap = keyboard2kmap($keyboard) or return; - log::l("loading keymap $o->[1]"); - if (-e (my $f = "$ENV{SHARE_PATH}/keymaps/$o->[1].bkmap")) { + log::l("loading keymap $kmap"); + if (-e (my $f = "$ENV{SHARE_PATH}/keymaps/$kmap.bkmap")) { load(scalar cat_($f)); } else { local *F; @@ -419,7 +434,7 @@ sub setup { eval { require packdrake; my $packer = new packdrake("$ENV{SHARE_PATH}/keymaps.cz2", quiet => 1); - $packer->extract_archive(undef, "$o->[1].bkmap"); + $packer->extract_archive(undef, "$kmap.bkmap"); }; c::_exit(0); } @@ -429,39 +444,29 @@ sub setup { } sub write { - my ($prefix, $keyboard, $charset, $isNotDelete) = @_; - - my $config = read_raw($prefix); - put_in_hash($config, { - KEYTABLE => keyboard2kmap($keyboard), - KBCHARSET => $charset, - }); - add2hash_($config, { - DISABLE_WINDOWS_KEY => bool2yesno(detect_devices::isLaptop()), - BACKSPACE => $isNotDelete ? "BackSpace" : "Delete", - }); - setVarsInSh("$prefix/etc/sysconfig/keyboard", $config); - run_program::rooted($prefix, "dumpkeys > /etc/sysconfig/console/default.kmap") or log::l("dumpkeys failed"); + my ($keyboard) = @_; + + $keyboard->{KEYTABLE} = keyboard2kmap($keyboard); + + setVarsInSh("$::prefix/etc/sysconfig/keyboard", $keyboard); + run_program::rooted($::prefix, "dumpkeys > /etc/sysconfig/console/default.kmap") or log::l("dumpkeys failed"); if (arch() =~ /ppc/) { my $s = "dev.mac_hid.keyboard_sends_linux_keycodes = 1\n"; substInFile { $_ = '' if /^\Qdev.mac_hid.keyboard_sends_linux_keycodes/; $_ .= $s if eof; - } "$prefix/etc/sysctl.conf"; + } "$::prefix/etc/sysctl.conf"; } } -sub read_raw { - my ($prefix) = @_; - my %config = getVarsFromSh("$prefix/etc/sysconfig/keyboard"); - \%config; -} - sub read { - my ($prefix) = @_; - my $keytable = read_raw($prefix)->{KEYTABLE}; - keyboard2kmap($_) eq $keytable and return $_ foreach keys %keyboards; - $keyboards{$keytable} && $keytable; #- keep track of unknown keyboard. + my %keyboard = getVarsFromSh("$::prefix/etc/sysconfig/keyboard") or return {}; + if (!$keyboard{KEYBOARD}) { + add2hash(\%keyboard, grep { keyboard2kmap($_) eq $keyboard{KEYTABLE} } keyboards()); + } + $keyboard{DISABLE_WINDOWS_KEY} = bool2yesno(detect_devices::isLaptop()); + + keyboard2text(\%keyboard) ? \%keyboard : {}; } sub check { @@ -491,8 +496,8 @@ sub check { $usb2keyboard[0x21] eq 'us' or $err->("\@usb2keyboard is badly modified, 0x21 is not us keyboard"); my @xkb_groups = map { if_(/grp:(\S+)/, $1) } cat_('/usr/lib/X11/xkb/rules/xfree86.lst'); - $err->("invalid xkb group toggle '$_' in \%kbdgrptoggle") foreach difference2([ keys %kbdgrptoggle ], \@xkb_groups); - $warn->("unused xkb group toggle '$_'") foreach difference2(\@xkb_groups, [ keys %kbdgrptoggle ]); + $err->("invalid xkb group toggle '$_' in \%grp_toggles") foreach difference2([ keys %grp_toggles ], \@xkb_groups); + $warn->("unused xkb group toggle '$_'") foreach grep { !/switch/ } difference2(\@xkb_groups, [ keys %grp_toggles ]); my @xkb_layouts = (#- (map { (split)[0] } grep { /^! layout/ .. /^\s*$/ } cat_('/usr/lib/X11/xkb/rules/xfree86.lst')), all('/usr/lib/X11/xkb/symbols'), diff --git a/perl-install/printerdrake.pm b/perl-install/printerdrake.pm index b7ae0fdab..bde98bd6f 100644 --- a/perl-install/printerdrake.pm +++ b/perl-install/printerdrake.pm @@ -2101,7 +2101,7 @@ sub check_network { $in->{netc}, $in->{mouse}, $in, $in->{intf}, 0, $in->{lang} eq "fr_FR" && - $in->{keyboard} eq "fr", 0); + $in->{keyboard}{KEYBOARD} eq "fr", 0); } else { system("/usr/sbin/drakconnet"); } diff --git a/perl-install/standalone/keyboarddrake b/perl-install/standalone/keyboarddrake index a5b8f75b8..e5137530c 100755 --- a/perl-install/standalone/keyboarddrake +++ b/perl-install/standalone/keyboarddrake @@ -8,6 +8,7 @@ use interactive; use keyboard; use Xconfig::xfree; use common; +use any; use c; local $_ = join '', @ARGV; @@ -16,45 +17,51 @@ local $_ = join '', @ARGV; $::expert = /-expert/; -print "[$::expert]\n"; -my $keyboard; -if ($::expert) { ($keyboard) = grep { !/^-/ } @ARGV } -print "[$keyboard]\n"; -my $in = 'interactive'->vnew('su', 'keyboard'); - -begin: -$::isEmbedded and kill USR2, $::CCPID; -$keyboard ||= $in->ask_from_listf_(_("Keyboard"), - _("Please, choose your keyboard layout."), - \&keyboard::keyboard2text, - [ keyboard::keyboards() ], - keyboard::read()); -if ($keyboard) { - keyboard::keyboard2text($keyboard) or die "bad keyboard $keyboard\n"; - - my $isNotDelete = $::expert && !$in->ask_yesorno("BackSpace", _("Do you want the BackSpace to return Delete in console?"), 1); - - my $kmap = keyboard::keyboard2kmap($keyboard); - system('loadkeys', $kmap); - - my $xkb = keyboard::keyboard2xkb($keyboard); - system('setxkbmap', $xkb); - - eval { - my $xfree_conf = Xconfig::xfree->read; - my $x_kbd_conf = $xfree_conf->get_keyboard; - $x_kbd_conf->{XkbLayout} = $xkb; - $xfree_conf->set_keyboard($x_kbd_conf); - $xfree_conf->write; - }; - - keyboard::write('', $keyboard, $isNotDelete); +my $in; +my $keyboard = keyboard::read(); +if (my ($kb) = grep { !/^-/ } @ARGV) { + keyboard::KEYBOARD2text($kb) or die "bad keyboard $kb\n"; + $keyboard->{KEYBOARD} = $kb; +} else { + $in = 'interactive'->vnew('su', 'keyboard'); + + begin: + $::isEmbedded and kill USR2, $::CCPID; + choose: + $keyboard->{KEYBOARD} = $in->ask_from_listf(_("Keyboard"), + _("Please, choose your keyboard layout."), + \&keyboard::KEYBOARD2text, + [ keyboard::KEYBOARDs() ], + $keyboard->{KEYBOARD}) or goto end; + + any::keyboard_group_toggle_choose($in, $keyboard) or goto choose; +} + +if ($::expert) { + my $isNotDelete = !$in->ask_yesorno("BackSpace", _("Do you want the BackSpace to return Delete in console?"), 1); + $keyboard->{BACKSPACE} = $isNotDelete ? "BackSpace" : "Delete"; } +system('loadkeys', keyboard::keyboard2kmap($keyboard)); + +my $xkb = keyboard::keyboard2xkb($keyboard); +system('setxkbmap', $xkb); + +eval { + my $xfree_conf = Xconfig::xfree->read; + my $x_kbd_conf = $xfree_conf->get_keyboard; + $x_kbd_conf->{XkbLayout} = $xkb; + $xfree_conf->set_keyboard($x_kbd_conf); + $xfree_conf->write; +}; + +keyboard::write($keyboard); + +end: if ($::isEmbedded) { kill(USR1, $::CCPID); $keyboard = ''; goto begin; } else { - $in->exit(0); + $in->exit(0) if $in; } -- cgit v1.2.1