summaryrefslogtreecommitdiffstats
path: root/perl-install/install_gtk.pm
blob: b1cf13aeb0483e8902581afbfdf54debc71b6a47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
package install_gtk; # $Id$

use diagnostics;
use strict;

use ugtk2 qw(:wrappers :helpers :create);
use common;
use lang;
use devices;

#-#####################################################################################
#-INTERN CONSTANT
#-#####################################################################################

my @background;

#- if we're running for the doc team, we want screenshots with
#- a good B&W contrast: we'll override values of our theme
my $theme_overriding_for_doc = q(style "galaxy-default"
{
    base[SELECTED]    = "#E0E0FF"
    base[ACTIVE]      = "#E0E0FF"
    base[PRELIGHT]    = "#E0E0FF"
    bg[SELECTED]      = "#E0E0FF"
    bg[ACTIVE]        = "#E0E0FF"
    bg[PRELIGHT]      = "#E0E0FF"
    text[ACTIVE]      = "#000000"
    text[PRELIGHT]    = "#000000"
    text[SELECTED]    = "#000000"
    fg[SELECTED]      = "#000000"
}

style "white-on-blue"
{
  base[NORMAL] = { 0.93, 0.93, 0.93 }
  bg[NORMAL] = { 0.93, 0.93, 0.93 }
    
  text[NORMAL] = "#000000"
  fg[NORMAL] = "#000000"
}

style "background"
{
  bg[NORMAL] = { 0.93, 0.93, 0.93 }
}

style "background-logo"
{
  bg[NORMAL] = { 0.70, 0.70, 0.70 }
}
widget "*logo*" style "background-logo"

);

#------------------------------------------------------------------------------
sub load_rc {
    my ($o, $name) = @_;

    if (my $f = find { -r $_ } map { "$_/$name.rc" } ("share", $ENV{SHARE_PATH}, dirname(__FILE__))) {

	my @contents = cat_($f);
	$o->{doc} and push @contents, $theme_overriding_for_doc;

	Gtk2::Rc->parse_string(join("\n", @contents));
	foreach (@contents) {
	    if (/style\s+"background"/ .. /^\s*$/) {
		@background = map { $_ * 256 * 257 } split ',', $1 if /NORMAL.*\{(.*)\}/;
	    }
	}
    }

}

#------------------------------------------------------------------------------
sub load_font {
    my ($o) = @_;

    if (lang::text_direction_rtl()) {
	Gtk2::Widget::set_default_direction('rtl'); 
	my ($x, $y) = $::WizardWindow->get_position;
	my ($width) = $::WizardWindow->get_size;
	$::WizardWindow->move($::rootwidth - $width - $x, $y);
    }

    Gtk2::Rc->parse_string(q(
style "default-font" 
{
   font_name = ") . lang::l2pango_font($o->{locale}{lang}) . q("
}
widget "*" style "default-font"

));
}

#------------------------------------------------------------------------------
sub default_theme {
    my ($o) = @_;
    $o->{meta_class} eq 'firewall' ? 'mdk-Firewall' : 
      $o->{simple_themes} || $o->{vga16} ? 'blue' : 'galaxy';
}

sub install_theme {
    my ($o) = @_;

    $o->{theme} ||= default_theme($o);
    load_rc($o, "themes-$o->{theme}");
    load_font($o);
    gtkset_background(@background) unless $::live; #- || testing;
}

#------------------------------------------------------------------------------
sub create_help_window {
    my ($o) = @_;

    my $w;
    if ($w = $o->{help_window}) {
	$w->{window}->foreach(sub { $_[0]->destroy }, undef);
    } else {
	$w = $o->{help_window} = bless {}, 'ugtk2';
	$w->{rwindow} = $w->{window} = Gtk2::Window->new('toplevel');
	$w->{rwindow}->set_uposition($::rootwidth - $::helpwidth, $::rootheight - $::helpheight);
	$w->{rwindow}->set_size_request($::helpwidth, $::helpheight);
	$w->{rwindow}->set_title('skip');
    };
    gtkadd($w->{window}, create_scrolled_window($o->{help_window_text} = Gtk2::TextView->new));
    $w->show;
}

#------------------------------------------------------------------------------
my %steps;
sub create_steps_window {
    my ($o) = @_;

    return if $::stepswidth == 0;

    $o->{steps_window} and $o->{steps_window}->destroy;
    my $w = bless {}, 'ugtk2';
    $w->{rwindow} = $w->{window} = Gtk2::Window->new('toplevel');
    $w->{rwindow}->set_uposition(lang::text_direction_rtl() ? ($::rootwidth - $::stepswidth - 8) : 8, 150);
    $w->{rwindow}->set_size_request($::stepswidth, -1);
    $w->{rwindow}->set_name('Steps');
    $w->{rwindow}->set_title('skip');

    $steps{$_} ||= gtkcreate_pixbuf("steps_$_") foreach qw(on off);
    my $category = sub { gtkset_markup(Gtk2::Label->new,
				       $o->{doc} ? $_[0] : '<span foreground="gray81">' . $_[0] . '</span>') };

    gtkpack__(my $vb = Gtk2::VBox->new(0, 3), $steps{inst} = $category->(N("System installation")), '');
    foreach (grep { !eval $o->{steps}{$_}{hidden} } @{$o->{orderedSteps}}) {
	$_ eq 'setRootPassword'
	  and gtkpack__($vb, '', '', $steps{conf} = $category->(N("System configuration")), '');
	$steps{steps}{$_} = { img => gtkcreate_img('steps_off.png'),
			      txt => Gtk2::Label->new(translate($o->{steps}{$_}{text})) };
	gtkpack__($vb, gtkpack__(Gtk2::HBox->new(0, 7), $steps{steps}{$_}{img}, $steps{steps}{$_}{txt}));
					      
    }

    gtkadd($w->{window}, $vb);
    $w->show;
    $o->{steps_window} = $w;
}

sub update_steps_position {
    my ($o) = @_;
    return if !$steps{steps};
    my $last_step;
    foreach (@{$o->{orderedSteps}}) {
	exists $steps{steps}{$_} or next;
	if ($o->{steps}{$_}{entered} && !$o->{steps}{$_}{done}) {
	    $steps{steps}{$_}{img}->set_from_pixbuf($steps{on});
	    $last_step and $steps{steps}{$last_step}{img}->set_from_pixbuf($steps{off});
	    return;
	}
	$last_step = $_;
    }
}

#------------------------------------------------------------------------------
sub create_logo_window {
    my ($o) = @_;

    return if $::logowidth == 0;

    gtkdestroy($o->{logo_window});

    my $w = bless {}, 'ugtk2';
    $w->{rwindow} = $w->{window} = Gtk2::Window->new('toplevel');
#    $w->{rwindow}->set_position(0, 0);
    $w->{rwindow}->set_size_request($::logowidth, $::logoheight);
    $w->{rwindow}->set_name("logo");
    $w->{rwindow}->set_title('skip');
    $w->show;
    my $file = $o->{meta_class} eq 'firewall' ? "logo-mandrake-Firewall.png" : "logo-mandrake.png";
    -r $file or $file = "$ENV{SHARE_PATH}/$file";
    -r $file and gtkadd($w->{window}, gtkcreate_img($file));
    $o->{logo_window} = $w;
}

#------------------------------------------------------------------------------
sub init_gtk() {
    symlink("/tmp/stage2/etc/$_", "/etc/$_") foreach qw(gtk-2.0 pango fonts);

    if (!listlength(cat_('/proc/fb'))) {
        #- inactivate antialias in VGA16 because it makes fonts look worse
        output('/tmp/fonts.conf',
q(<fontconfig>
<include>/etc/fonts/fonts.conf</include>
<match target="font"><edit name="antialias"><bool>false</bool></edit></match>
</fontconfig>
));
        $ENV{FONTCONFIG_FILE} = '/tmp/fonts.conf';
    }

    Gtk2->init;
    Gtk2->set_locale;
}

#------------------------------------------------------------------------------
sub init_sizes() {
    ($::rootwidth,  $::rootheight)    = (Gtk2::Gdk->screen_width, Gtk2::Gdk->screen_height);
    $::live and $::rootheight -= 80;
    #- ($::rootheight,  $::rootwidth)    = (min(768, $::rootheight), min(1024, $::rootwidth));
    $::stepswidth = $::rootwidth <= 640 ? 0 : 160;
    ($::logowidth,   $::logoheight)   = $::rootwidth <= 640 ? (0, 0) : (500, 40);
    ($::helpwidth,   $::helpheight)   = ($::rootwidth - $::stepswidth, 0);
    ($::windowwidth, $::windowheight) = ($::rootwidth - $::stepswidth, $::rootheight - $::helpheight - $::logoheight);
}

#------------------------------------------------------------------------------
sub createXconf {
    my ($file, $mouse_type, $mouse_dev, $wacom_dev, $Driver) = @_;

    $mouse_type = 'IMPS/2' if $mouse_type eq 'ExplorerPS/2';
    symlinkf(devices::make($mouse_dev), "/dev/mouse") if $mouse_dev ne 'none';

    #- needed for imlib to start on 8-bit depth visual.
    symlink("/tmp/stage2/etc/imrc", "/etc/imrc");
    symlink("/tmp/stage2/etc/im_palette.pal", "etc/im_palette.pal");

if ($Driver) {
     output($file, sprintf(<<'END', $mouse_type, $Driver));

Section "Files"
   FontPath   "/usr/X11R6/lib/X11/fonts:unscaled"
EndSection

Section "InputDevice"
    Identifier "Keyboard"
    Driver "Keyboard"
    Option "XkbDisable"
    Option "XkbModel" "pc105"
    Option "XkbLayout" ""
EndSection

Section "InputDevice"
    Identifier "Mouse"
    Driver "mouse"
    Option "Protocol" "%s"
    Option "Device" "/dev/mouse"
EndSection

Section "Monitor"
    Identifier "monitor"
    HorizSync 31.5-35.5
    VertRefresh 50-70
EndSection

Section "Device"
    Identifier  "device"
    Driver      "%s"
EndSection

Section "Screen"
    Identifier "screen"
    Device "device"
    Monitor "monitor"
    DefaultColorDepth 16
    Subsection "Display"
        Depth 16
        Modes "800x600" "640x480"
    EndSubsection
EndSection

Section "ServerLayout"
    Identifier "layout"
    Screen "screen"
    InputDevice "Mouse" "CorePointer"
    InputDevice "Keyboard" "CoreKeyboard"
EndSection

END


} else {

    my $wacom;
    if ($wacom_dev) {
	my $dev = devices::make($wacom_dev);
	$wacom = <<END;
Section "Module"
   Load "xf86Wacom.so"
EndSection

Section "XInput"
    SubSection "WacomStylus"
        Port "$dev"
        AlwaysCore
    EndSubSection
    SubSection "WacomCursor"
        Port "$dev"
        AlwaysCore
    EndSubSection
    SubSection "WacomEraser"
        Port "$dev"
        AlwaysCore
    EndSubSection
EndSection
END
    }

    output($file, <<END);
Section "Files"
   FontPath   "/usr/X11R6/lib/X11/fonts:unscaled"
EndSection

Section "Keyboard"
   Protocol    "Standard"
   AutoRepeat  0 0

   LeftAlt         Meta
   RightAlt        Meta
   ScrollLock      Compose
   RightCtl        Control
   XkbDisable
EndSection

Section "Pointer"
   Protocol    "$mouse_type"
   Device      "/dev/mouse"
   ZAxisMapping 4 5
EndSection

$wacom

Section "Monitor"
   Identifier  "monitor"
   HorizSync   31.5-35.5
   VertRefresh 50-70
   ModeLine "640x480"     25.175 640  664  760  800   480  491  493  525
   ModeLine "640x480"     28.3   640  664  760  800   480  491  493  525
   ModeLine "800x600"     36     800  824  896 1024   600  601  603  625
EndSection


Section "Device"
   Identifier "Generic VGA"
   Chipset "generic"
EndSection

Section "Device"
   Identifier "svga"
EndSection

Section "Screen"
    Driver      "vga16"
    Device      "Generic VGA"
    Monitor     "monitor"
    Subsection "Display"
        Modes      "640x480"
        ViewPort   0 0
    EndSubsection
EndSection

Section "Screen"
    Driver      "fbdev"
    Device      "Generic VGA"
    Monitor     "monitor"
    Subsection "Display"
        Depth      16
        Modes      "default"
        ViewPort   0 0
    EndSubsection
EndSection

Section "Screen"
    Driver      "svga"
    Device      "svga"
    Monitor     "monitor"
    Subsection "Display"
        Depth      16
        Modes      "800x600" "640x480"
        ViewPort   0 0
    EndSubsection
EndSection

Section "Screen"
    Driver      "accel"
    Device      "svga"
    Monitor     "monitor"
    Subsection "Display"
        Depth      16
        Modes      "800x600" "640x480"
        ViewPort   0 0
    EndSubsection
EndSection
END
}
}

1;
, 0 ], "ie" => [ N_("Irish"), "uk", "ie", 0 ], "il" => [ N_("Israeli"), "il-8859_8", "il", 1 ], "il_phonetic" => [ N_("Israeli (Phonetic)"), "hebrew", "il_phonetic", 1 ], "ir" => [ N_("Iranian"), "ir-isiri_3342", "ir", 1 ], "is" => [ N_("Icelandic"), "is-latin1", "is", 0 ], "it" => [ N_("Italian"), "it-latin1", "it", 0 ], "iu" => [ N_("Inuktitut"), "us", "iu", 1 ], # Japanese keyboard is dual latin/kana; but telling it here shows a # message to choose the switching key that is misleading, as input methods # aren't automatically enabled when typing in kana "jp" => [ N_("Japanese 106 keys"), "jp106", "jp", 0 ], "kan" => [ N_("Kannada"), "us", "kan", 1 ], #There is no XKB korean file yet; but using xmodmap one disables # some functioanlity; "us" used for XKB until this is fixed "kr" => [ N_("Korean keyboard"), "us", "us", 1 ], "la" => [ N_("Latin American"), "la-latin1", "la", 0 ], "lao" => [ N_("Laotian"), "us", "lo", 1 ], "lt" => [ N_("Lithuanian AZERTY (old)"), "lt-latin7", "lt_a", 0 ], #- TODO: write a console kbd map for lt_new "lt_new" => [ N_("Lithuanian AZERTY (new)"), "lt-latin7", "lt_std", 0 ], "lt_b" => [ N_("Lithuanian \"number row\" QWERTY"), "ltb-latin7", "lt", 1 ], "lt_p" => [ N_("Lithuanian \"phonetic\" QWERTY"), "ltp-latin7", "lt_p", 0 ], "lv" => [ N_("Latvian"), "lv-latin7", "lv", 0 ], "mal" => [ N_("Malayalam"), "us", "ml(mlplusnum)", 1 ], "mk" => [ N_("Macedonian"), "mk", "mk", 1 ], "mm" => [ N_("Myanmar (Burmese)"), "us", "mm", 1 ], "mng" => [ N_("Mongolian (cyrillic)"), "us", "mng", 1 ], "mt" => [ N_("Maltese (UK)"), "uk", "mt", 0 ], "mt_us" => [ N_("Maltese (US)"), "us", "mt_us", 0 ], "nl" => [ N_("Dutch"), "nl-latin1", "nl", 0 ], "no" => [ N_("Norwegian"), "no-latin1", "no", 0 ], "ori" => [ N_("Oriya"), "us", "ori", 1 ], "pl" => [ N_("Polish (qwerty layout)"), "pl", "pl", 0 ], "pl2" => [ N_("Polish (qwertz layout)"), "pl-latin2", "pl2", 0 ], "pt" => [ N_("Portuguese"), "pt-latin1", "pt", 0 ], "qc" => [ N_("Canadian (Quebec)"), "qc-latin1", "ca_enhanced", 0 ], #- TODO: write a console kbd map for ro2 "ro2" => [ N_("Romanian (qwertz)"), "ro2", "ro2", 0 ], "ro" => [ N_("Romanian (qwerty)"), "ro", "ro", 0 ], "ru" => [ N_("Russian"), "ru4", "ru(winkeys)", 1 ], "ru_yawerty" => [ N_("Russian (Phonetic)"), "ru-yawerty", "ru_yawerty", 1 ], "sapmi" => [ N_("Saami (norwegian)"), "no-latin1", "sapmi", 0 ], "sapmi_sefi" => [ N_("Saami (swedish/finnish)"), "se-latin1", "sapmi(sefi)", 0 ], "se" => [ N_("Swedish"), "se-latin1", "se", 0 ], "si" => [ N_("Slovenian"), "slovene", "si", 0 ], "sk" => [ N_("Slovakian (QWERTZ)"), "sk-qwertz", "sk", 0 ], "sk_qwerty" => [ N_("Slovakian (QWERTY)"), "sk-qwerty", "sk_qwerty", 0 ], # TODO: console map "sr" => [ N_("Serbian (cyrillic)"), "sr", "sr", 1 ], "syr" => [ N_("Syriac"), "us", "syr", 1 ], "syr_p" => [ N_("Syriac (phonetic)"), "us", "syr_phonetic", 1 ], "tel" => [ N_("Telugu"), "us", "tel", 1 ], # no console kbd that I'm aware of "tml" => [ N_("Tamil (ISCII-layout)"), "us", "tml", 1 ], "tscii" => [ N_("Tamil (Typewriter-layout)"), "us", "ta(UNI)", 1 ], "th" => [ N_("Thai keyboard"), "th", "th", 1 ], # TODO: console map "tj" => [ N_("Tajik keyboard"), "ru4", "tj", 1 ], "tr_f" => [ N_("Turkish (traditional \"F\" model)"), "trf", "tr_f", 0 ], "tr_q" => [ N_("Turkish (modern \"Q\" model)"), "tr_q-latin5", "tr", 0 ], #-"tw => [ N_("Chineses bopomofo"), "tw", "tw", 1 ], "ua" => [ N_("Ukrainian"), "ua", "ua", 1 ], "uk" => [ N_("UK keyboard"), "uk", "gb", 0 ], "us" => [ N_("US keyboard"), "us", "en_US", 0 ], "us_intl" => [ N_("US keyboard (international)"), "us-latin1", "us_intl", 0 ], "uz" => [ N_("Uzbek (cyrillic)"), "uz.uni", "uz", 1 ], "vn" => [ N_("Vietnamese \"numeric row\" QWERTY"), "vn-tcvn", "vn(toggle)", 0 ], "yu" => [ N_("Yugoslavian (latin)"), "sr", "yu", 0 ], ), ); #- list of possible choices for the key combinations to toggle XKB groups #- (eg in X86Config file: XkbOptions "grp:toggle") my %grp_toggles = ( toggle => N_("Right Alt key"), shift_toggle => N_("Both Shift keys simultaneously"), ctrl_shift_toggle => N_("Control and Shift keys simultaneously"), caps_toggle => N_("CapsLock key"), ctrl_alt_toggle => N_("Ctrl and Alt keys simultaneously"), alt_shift_toggle => N_("Alt and Shift keys simultaneously"), menu_toggle => N_("\"Menu\" key"), lwin_toggle => N_("Left \"Windows\" key"), rwin_toggle => N_("Right \"Windows\" key"), ctrls_toggle => N_("Both Control keys simultaneously"), alts_toggle => N_("Both Alt keys simultaneously"), lshift_toggle => N_("Left Shift key"), rshift_toggle => N_("Right Shift key"), lalt_toggle => N_("Left Alt key"), lctrl_toggle => N_("Left Control key"), rctrl_toggle => N_("Right Control key"), ); #-###################################################################################### #- Functions #-###################################################################################### 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 group_toggle_choose { my ($in, $keyboard) = @_; if (my $grp_toggles = keyboard::grp_toggles($keyboard)) { my $GRP_TOGGLE = $keyboard->{GRP_TOGGLE} || 'caps_toggle'; $GRP_TOGGLE = $in->ask_from_listf('', N("Here you can choose the key or key combination that will allow switching between the different keyboard layouts (eg: latin and non latin)"), sub { translate($grp_toggles->{$_[0]}) }, [ sort keys %$grp_toggles ], $GRP_TOGGLE) or return; $GRP_TOGGLE ne 'rctrl_toggle' and $in->ask_warn(N("Warning"), formatAlaTeX( N("This setting will be activated after the installation. During installation, you will need to use the Right Control key to switch between the different keyboard layouts."))); log::l("GRP_TOGGLE: $GRP_TOGGLE"); $keyboard->{GRP_TOGGLE} = $GRP_TOGGLE; } else { $keyboard->{GRP_TOGGLE} = ''; } 1; } sub loadkeys_files { my ($err) = @_; my $archkbd = arch() =~ /^sparc/ ? "sun" : arch() =~ /i.86/ ? "i386" : arch() =~ /ppc/ ? "mac" : arch(); my $p = "/usr/lib/kbd/keymaps/$archkbd"; my $post = ".kmap.gz"; my %trans = ("cz-latin2" => "cz-lat2"); my %find_file; foreach my $dir (all($p)) { $find_file{$dir} = ''; foreach (all("$p/$dir")) { $find_file{$_} and $err->("file $_ is both in $find_file{$_} and $dir") if $err; $find_file{$_} = "$p/$dir/$_"; } } my (@l, %l); foreach (values %keyboards) { local $_ = $trans{$_->[1]} || $_->[1]; my $l = $find_file{"$_$post"} || $find_file{first(/(..)/) . $post}; if ($l) { push @l, $l; foreach (`zgrep include $l | grep "^include"`) { /include\s+"(.*)"/ or die "bad line $_"; @l{grep { -e $_ } ("$p/$1.inc.gz")} = (); } } else { $err->("invalid loadkeys keytable $_") if $err; } } uniq(@l, keys %l, grep { -e $_ } map { "$p/$_.inc.gz" } qw(compose euro windowkeys linux-keys-bare)); } sub unpack_keyboards { my ($k) = @_; $k or return; [ grep { my $b = $keyboards{$_->[0]}; $b or log::l("bad keyboard $_->[0] in %keyboard::lang2keyboard"); $b; } map { [ split ':' ] } split ' ', $k ]; } sub lang2keyboards { my @li = sort { $b->[1] <=> $a->[1] } map { @$_ } map { #- first try with the 5 first chars of LANG; if it fails then try with #- with the 2 first chars of LANG before resorting to default. unpack_keyboards($lang2keyboard{substr($_, 0, 5)}) || unpack_keyboards($lang2keyboard{substr($_, 0, 2)}) || [ [ ($keyboards{$_} ? $_ : "us") => 100 ] ]; } @_; \@li; } sub lang2keyboard { my ($l) = @_; my $kb = lang2keyboards($l)->[0][0]; { KEYBOARD => $keyboards{$kb} ? $kb : 'us' }; #- handle incorrect keyboard mapping to us. } sub from_usb() { return if $::noauto; 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 }; } sub load { my ($keymap) = @_; return if $::testing; my ($magic, $tables_given, @tables) = common::unpack_with_refs('I' . 'i' . c::MAX_NR_KEYMAPS() . 's' . c::NR_KEYS() . '*', $keymap); $magic != $KMAP_MAGIC and die "failed to read kmap magic"; sysopen(my $F, "/dev/console", 2) or die "failed to open /dev/console: $!"; my $i_tables = 0; each_index { my $table_index = $::i; if (!$_) { #- deallocate table ioctl($F, c::KDSKBENT(), pack("CCS", $table_index, 0, c::K_NOSUCHMAP())) or log::l("removing table $table_index failed: $!"); } else { each_index { ioctl($F, c::KDSKBENT(), pack("CCS", $table_index, $::i, $_)) or log::l("keymap ioctl failed ($table_index $::i $_): $!"); } @{$tables[$i_tables++]}; } } @$tables_given; } sub keyboard2full_xkb { my ($keyboard) = @_; my $XkbLayout = keyboard2xkb($keyboard); my $XkbModel = arch() =~ /sparc/ ? 'sun' : $XkbLayout eq 'jp' ? 'jp106' : $XkbLayout eq 'br' ? 'abnt2' : 'pc105'; $XkbLayout ? { XkbLayout => join(',', if_($keyboard->{GRP_TOGGLE}, 'us'), $XkbLayout), XkbModel => $XkbModel, XkbOptions => $keyboard->{GRP_TOGGLE} ? join(',', if_($keyboard->{GRP_TOGGLE} eq 'rwin_toggle', 'compose:rwin'), "grp:$keyboard->{GRP_TOGGLE}", 'grp_led:scroll') : '', } : { XkbDisable => '' }; } sub xmodmap_file { my ($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"); }; $f = "/tmp/xmodmap.$KEYBOARD"; } -e $f && $f; } sub setxkbmap { my ($keyboard) = @_; my $xkb = keyboard::keyboard2full_xkb($keyboard) or return; run_program::run('setxkbmap', '-option', '') if $xkb->{XkbOptions}; #- need re-initialised other toggles are cumulated run_program::run('setxkbmap', $xkb->{XkbLayout}, '-model' => $xkb->{XkbModel}, '-option' => $xkb->{XkbOptions} || '', '-compat' => $xkb->{XkbCompat} || ''); } sub setup { my ($keyboard) = @_; return if arch() =~ /^sparc/; #- Xpmac doesn't map keys quite right if (arch() =~ /ppc/ && !$::testing && $ENV{DISPLAY}) { log::l("Fixing Mac keyboard"); run_program::run('xmodmap', "-e", "keycode 59 = BackSpace"); run_program::run('xmodmap', "-e", "keycode 131 = Shift_R"); run_program::run('xmodmap', "-e", "add shift = Shift_R"); return; } my $kmap = keyboard2kmap($keyboard) or return; log::l("loading keymap $kmap"); if (-x '/bin/loadkeys') { run_program::run('loadkeys', $kmap); } elsif (-e (my $f = "$ENV{SHARE_PATH}/keymaps/$kmap.bkmap")) { load(scalar cat_($f)); } else { my $kid = bg_command->new(sub { eval { require packdrake; my $packer = new packdrake("$ENV{SHARE_PATH}/keymaps.cz2", quiet => 1); $packer->extract_archive(undef, "$kmap.bkmap"); }; }); local $/ = undef; eval { my $fd = $kid->{fd}; load(join('', <$fd>)) }; } if (-x "/usr/X11R6/bin/setxkbmap") { setxkbmap($keyboard); } else { my $f = xmodmap_file($keyboard); eval { run_program::run('xmodmap', $f) } if $f && !$::testing && $ENV{DISPLAY}; } } sub write { my ($keyboard) = @_; log::l("keyboard::write $keyboard->{KEYBOARD}"); $keyboard = { %$keyboard }; delete $keyboard->{unsafe}; $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"; } } sub read() { 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() { require lang; $^W = 0; my $not_ok = 0; my $warn = sub { print STDERR "$_[0]\n"; }; my $err = sub { &$warn; $not_ok = 1; }; if (my @l = grep { is_empty_array_ref(lang2keyboards($_)) } lang::list_langs()) { $warn->("no keyboard for langs " . join(" ", @l)); } foreach my $lang (lang::list_langs()) { my $l = lang2keyboards($lang); foreach (@$l) { 0 <= $_->[1] && $_->[1] <= 100 or $err->("invalid value $_->[1] in $lang2keyboard{$lang} for $lang in \%lang2keyboard keyboard.pm"); $keyboards{$_->[0]} or $err->("invalid keyboard $_->[0] in $lang2keyboard{$lang} for $lang in \%lang2keyboard keyboard.pm"); } } /SKIP/ || $keyboards{$_} or $err->("invalid keyboard $_ in \@usb2keyboard keyboard.pm") foreach @usb2keyboard; $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 \%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'), (map { (split)[2] } cat_('/usr/lib/X11/xkb/symbols.dir'))); $err->("invalid xkb layout $_") foreach difference2([ map { keyboard2xkb($_) } keyboards() ], \@xkb_layouts); my @kmaps_available = map { if_(m|.*/(.*)\.bkmap|, $1) } `tar tfj share/keymaps.tar.bz2`; my @kmaps_wanted = map { keyboard2kmap($_) } keyboards(); $err->("missing KEYTABLE $_ (either share/keymaps.tar.bz2 need updating or $_ is bad)") foreach difference2(\@kmaps_wanted, \@kmaps_available); $err->("unused KEYTABLE $_ (update share/keymaps.tar.bz2 using share/keymaps_generate)") foreach difference2(\@kmaps_available, \@kmaps_wanted); loadkeys_files($err); exit($not_ok); } 1;