-
Notifications
You must be signed in to change notification settings - Fork 15
/
Keyboard.rb
1476 lines (1285 loc) · 46.5 KB
/
Keyboard.rb
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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
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
# encoding: utf-8
# ------------------------------------------------------------------------------
# Copyright (c) 2012 Novell, Inc. All Rights Reserved.
#
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of version 2 of the GNU General Public License as published by the
# Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, contact Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail, you may find
# current contact information at www.novell.com.
# ------------------------------------------------------------------------------
# File:
# Keyboard.ycp
#
# Module:
# Keyboard
#
# Summary:
# Provide information regarding the keyboard.
#
# Authors:
# Thomas Roelz <tom@suse.de>
#
# Maintainer: Jiri Suchomel <jsuchome@suse.cz>
#
# $Id$
#
# Usage:
# ------
# This module provides the following data for public access via Keyboard::<var-name>.
#
# !!! These are to be used READ_ONLY !!!
#
# Set in the constructor after the first import (only after probing):
#
# kb_model
# XkbLayout
# unique_key
#
# Set after having called SetKeyboard( keyboard ).
#
# XkbModel
# XkbVariant
# XkbOptions
# LeftAlt
# RightAlt
# ScrollLock
# RightCtl
# Apply
# keymap
# current_kbd
# ckb_cmd
# xkb_cmd
#
#
# This module provides the following functions for public access via Keyboard::<func-name>(...)
#
# Keyboard() - Module constructor.
# If saved module data exists in continue mode, these are read in.
# Otherwise Hardware is probed.
#
# MakeProposal() - return user-readable description of keyboard
#
# Probe() - Force new hardware probing and set public data accordingly.
#
# Save() - Save module data to /var/lib/YaST2/Keyboard_data.ycp
#
# Restore() - Load module data from /var/lib/YaST2/Keyboard_data.ycp
#
# SetKeyboard() - Set public data to values corresponding to the given language.
#
# GetKeyboardForLanguage() - Get the keyboard language for a given language code.
#
# Set() - Set the keyboard to the given keyboard language.
# SetConsole() - Set the console keyboard to the given keyboard language.
#
# SetX11() - Set the X11 keyboard to the given keyboard language.
#
# Selection() - Get map of translated keyboards to be displayed in the GUI.
#
require "yast"
require "shellwords"
module Yast
class KeyboardClass < Module
include Yast::Logger
# Writing rules in /etc/udev would result in those files being copied to
# the installed system. That's not what we want. sys-int is temporary, so
# writing in its /usr/lib is safe.
UDEV_FILE = "/usr/lib/udev/rules.d/70-installation-keyboard.rules"
UDEV_COMMENT = "# Generated by Yast to handle the layout of keyboards "\
"connected during installation\n"
def main
Yast.import "UI"
textdomain "country"
Yast.import "Arch"
Yast.import "AsciiFile"
Yast.import "Directory"
Yast.import "FileUtils"
Yast.import "Initrd"
Yast.import "Label"
Yast.import "Language"
Yast.import "Linuxrc"
Yast.import "Misc"
Yast.import "Mode"
Yast.import "Package"
Yast.import "OSRelease"
Yast.import "ProductFeatures"
Yast.import "Stage"
Yast.import "XVersion"
Yast.import "Report"
# ------------------------------------------------------------------------
# START: Globally defined data to be accessed via Keyboard::<variable>
# ------------------------------------------------------------------------
# kb_model string
#
@kb_model = "pc104"
# XkbModel string
#
@XkbModel = ""
# XkbLayout string
# Only some keyboards do report this information (e.g. sparc).
#
@XkbLayout = ""
# XkbVariant string
#
@XkbVariant = ""
# keymap string for ncurses
#
@keymap = "us.map.gz"
# X11 Options string
#
@XkbOptions = ""
# X11 LeftAlt
#
@LeftAlt = ""
# X11 RightAlt
#
@RightAlt = ""
# X11 RightCtl
#
@RightCtl = ""
# X11 ScrollLock
#
@ScrollLock = ""
# Apply string fuer xbcmd
#
@Apply = ""
# The console keyboard command
#
@ckb_cmd = ""
# The X11 keyboard command
#
@xkb_cmd = ""
# The keyboard currently set.
#
@current_kbd = ""
# keyboard set on start
@keyboard_on_entry = ""
# expert values on start
@expert_on_entry = {}
# The default keyboard if set.
#
@default_kbd = ""
# Flag indicating if the user has chosen a keyboard.
# To be set from outside.
#
@user_decision = false
# unique key
#
@unique_key = ""
# state of Expert settings
@ExpertSettingsChanged = false
# --------------------------------------------------------------
# END: Globally defined data to be accessed via Keyboard::<variable>
# --------------------------------------------------------------
# --------------------------------------------------------------
# START: Locally defined data
# --------------------------------------------------------------
# if Keyboard::Restore() was called
@restore_called = false
# User readable description, access via Keyboard::MakeProposal()
#
@name = ""
# Keyboard description from DB
#
@kbd_descr = []
@kbd_rate = ""
@kbd_delay = ""
@kbd_numlock = ""
@kbd_disable_capslock = ""
@keyboardprobelist = [] # List of all probed keyboards
# running in XEN?
@xen_is_running = nil
# keyboards map (used as cache for #yast_keyboards)
@all_keyboards = nil
Keyboard()
end
# ------------------------------------------------------------------
# START: Globally defined functions
# ------------------------------------------------------------------
# GetKbdSysconfig()
#
# Restore the the non-keyboard values from sysconfig.
def GetKbdSysconfig
# Read the the variables not touched by the module to be able to
# store them again on Save().
#
@kbd_rate = Misc.SysconfigRead(
path(".sysconfig.keyboard.KBD_RATE"),
@kbd_rate
)
@kbd_delay = Misc.SysconfigRead(
path(".sysconfig.keyboard.KBD_DELAY"),
@kbd_delay
)
@kbd_numlock = Misc.SysconfigRead(
path(".sysconfig.keyboard.KBD_NUMLOCK"),
@kbd_numlock
)
@kbd_disable_capslock = Misc.SysconfigRead(
path(".sysconfig.keyboard.KBD_DISABLE_CAPS_LOCK"),
@kbd_disable_capslock
)
Builtins.y2milestone(
"rate:%1 delay:%2 numlock:%3 disclock:%4",
@kbd_rate,
@kbd_delay,
@kbd_numlock,
@kbd_disable_capslock
)
nil
end
# get_reduced_keyboard_db()
#
# Read the Keyboard DB and select entries for current XkbModel and architecture.
#
# @return Reduced keyboard DB (map)
def get_reduced_keyboard_db
# The keyboard DB is a very big map containing entries for all known keyboard
# languages. Each of these entries contains a map of the different known
# architectures and each of these architectures contains a map for the different
# kb_models possible on the given architecture. This innermost map finally contains
# data relevant for ncurses.
#
# $[
# "english-us":
# [
# ...language stuff...
# $[ "i386" :
# $[ "pc104":
# $[ "ncurses": "us.map.gz" ]],
#
# What now follows is code that cuts out from this map the unnecessary
# architectures and XkbModels. The different languages are kept.
#
# Load the keyboard DB.
# Do not hold this database in a permanent module variable (it's very large).
# The new reduced map of keyboard data.
#
keyboards = {}
Builtins.y2milestone("keyboard model used: %1", @kb_model)
# loop over all languages
Builtins.foreach(all_keyboards) do |kb_lang, description|
if Builtins.size(description) == 2
# Get the data for the current kb_model
#
keyboard_model = Ops.get_map(description, [1, @kb_model], {})
if Ops.greater_than(Builtins.size(keyboard_model), 0) # found an entry
# Add the data found (as list) to the new map under the current
# language key.
#
keyboard_selected = [] # temporary list
# Add the language stuff.
#
keyboard_selected = Builtins.add(
keyboard_selected,
Ops.get_string(description, 0, "")
)
# Add the Qt- and ncurses-data.
#
keyboard_selected = Builtins.add(keyboard_selected, keyboard_model)
# Add this list to the reduced keyboard map under the current language key.
#
Ops.set(keyboards, kb_lang, keyboard_selected)
end
end
end
deep_copy(keyboards)
end # get_reduced_keyboard_db()
# Return a map for conversion from keymap to YaST2 keyboard code()
# Get the map of translated keyboard names.
# @param -
# @return [Hash] of $[ keyboard_code : keyboard_name, ...] for all known
# keyboards. 'keyboard_code' is used internally in Set and Get
# functions. 'keyboard_name' is a user-readable string.
# Uses Language::language for translation.
#
def keymap2yast
Builtins.mapmap(get_reduced_keyboard_db) do |code, kbd_value|
code_map = Ops.get_map(kbd_value, 1, {})
codel = Builtins.splitstring(
Ops.get_string(code_map, "ncurses", ""),
"."
)
{ Ops.get_string(codel, 0, "") => code }
end
end
# GetX11KeyData()
#
# Get the keyboard info for X11 for the given keymap
#
# @param name of the keymap
#
# @return [Hash] containing the x11 config data
#
def GetX11KeyData(keymap)
cmd = "/usr/sbin/xkbctrl"
x11data = {}
if Ops.greater_than(SCR.Read(path(".target.size"), cmd), 0)
file = File.join(Directory.tmpdir, "xkbctrl.out")
SCR.Execute(path(".target.bash"), "#{cmd} #{keymap.shellescape} > #{file.shellescape}")
x11data = Convert.to_map(SCR.Read(path(".target.ycp"), file))
else
Builtins.y2warning("/usr/sbin/xkbctrl not found")
end
deep_copy(x11data)
end
# Return human readable (and translated) name of the given keyboard map
# @param [String] kbd keyboard map
# @return [String]
def GetKeyboardName(kbd)
keyboards = get_reduced_keyboard_db
descr = Ops.get_list(keyboards, kbd, [])
ret = kbd
if descr != []
translate = Ops.get_string(descr, 0, kbd)
ret = Builtins.eval(translate)
end
ret
end
# GetExpertValues()
#
# Return the values for the various expert settings in a map
#
# @return [Hash] with values filled in
#
def GetExpertValues
ret = {
"rate" => @kbd_rate,
"delay" => @kbd_delay,
"numlock" => @kbd_numlock,
"discaps" => @kbd_disable_capslock == "yes" ? true : false
}
deep_copy(ret)
end
# Get the system_language --> keyboard_language conversion map.
#
# @return conversion map
#
# @see #get_xkblayout2keyboard()
def get_lang2keyboard
base_lang2keyboard = Convert.to_map(
SCR.Read(path(".target.yast2"), "lang2keyboard.ycp")
)
base_lang2keyboard = {} if base_lang2keyboard == nil
Builtins.union(base_lang2keyboard, Language.GetLang2KeyboardMap(true))
end
# Get the default key map for selected language
#
# @param sys_language [String] the locale, e.g. cs_CZ
#
# @return [String] the expected key map, e.g. cz-us-qwertz.map.gz
#
def GetKeymapForLanguage(sys_language)
keyboard = GetKeyboardForLanguage(sys_language, "us")
keyboards = get_reduced_keyboard_db
log.debug("reduced kbd db: #{keyboards}")
# Get the entry from the reduced local map for the given language.
#
kbd_descr = keyboards[keyboard] || []
log.info( "Description for keyboard #{keyboard.inspect}: #{kbd_descr.inspect}")
if !kbd_descr.empty? # keyboard found
return Ops.get_string(kbd_descr, [1, "ncurses"], "us.map.gz")
end
"us.map.gz"
end
# GetKeyboardForLanguage()
#
# Get the keyboard language for the given system language.
#
# @param System language code, e.g. "en_US".
# Default keyboard language to be returned if nothing found.
#
# @return The keyboard language for this language, e.g. "english-us"
# or the default value if nothing found.
#
def GetKeyboardForLanguage(sys_language, default_keyboard)
lang2keyboard = get_lang2keyboard
kb = Ops.get_string(lang2keyboard, sys_language, "")
if kb == ""
sys_language = Builtins.substring(sys_language, 0, 2)
kb = Ops.get_string(lang2keyboard, sys_language, default_keyboard)
end
Builtins.y2milestone(
"GetKeyboardForLanguage lang:%1 def:%2 ret:%3",
sys_language,
default_keyboard,
kb
)
kb
end
# check if we are running in XEN (autorepeat functionality not supported)
# seem bnc#376945, #371756
def xen_running
if @xen_is_running == nil
@xen_is_running = Convert.to_boolean(SCR.Read(path(".probe.xen")))
end
@xen_is_running == true
end
# run X11 configuration after inital boot
def x11_setup_needed
Arch.x11_setup_needed &&
!(Linuxrc.serial_console || Linuxrc.vnc || Linuxrc.usessh ||
Linuxrc.text)
end
# SetKeyboard()
#
# Set language specific module data to reflect the given keyboard layout.
#
# @param Keyboard layout e.g. "english-us"
#
# @return true - Success. Language set in public data.
# false - Error. Language not set.
#
def SetKeyboard(keyboard)
Builtins.y2milestone("Setting keyboard to: <%1>", keyboard)
# Get the reduced keyboard DB.
#
keyboards = get_reduced_keyboard_db
Builtins.y2debug("reduced kbd db %1", keyboards)
# Get the entry from the reduced local map for the given language.
#
@kbd_descr = Ops.get_list(keyboards, keyboard, [])
Builtins.y2milestone(
"Description for keyboard <%1>: <%2>",
keyboard,
@kbd_descr
)
if @kbd_descr != [] # keyboard found
# Get keymap for ncurses
#
@keymap = Ops.get_string(@kbd_descr, [1, "ncurses"], "us.map.gz")
translate = Ops.get_string(@kbd_descr, 0, keyboard)
@name = Builtins.eval(translate)
x11data = GetX11KeyData(@keymap)
Builtins.y2milestone("x11data=%1", x11data)
@XkbModel = Ops.get_string(x11data, "XkbModel", "pc104")
@XkbLayout = Ops.get_string(x11data, "XkbLayout", "")
@XkbVariant = Ops.get_string(x11data, "XkbVariant", "")
@XkbOptions = Ops.get_string(x11data, "XkbOptions", "")
@LeftAlt = Ops.get_string(x11data, "LeftAlt", "")
@RightAlt = Ops.get_string(x11data, "RightAlt", "")
@ScrollLock = Ops.get_string(x11data, "ScrollLock", "")
@RightCtl = Ops.get_string(x11data, "RightCtl", "")
@Apply = Ops.get_string(x11data, "Apply", "")
else
return false # Error
end
# loadkeys is already escaped and it is multiple params inside, so cannot be escaped here
@ckb_cmd = "/usr/bin/loadkeys #{loadkeys_devices} #{keymap.shellescape}"
# X11 command...
# do not try to run this with remote X display
if Ops.greater_than(Builtins.size(@Apply), 0) && x11_setup_needed
# Apply cannot be escaped as it is already set of parameters. But it is at least our string and not user provided.
@xkb_cmd = "#{File.join(XVersion.binPath, "setxkbmap")} #{@Apply}"
else
@xkb_cmd = ""
end
# Store keyboard just set.
#
@current_kbd = keyboard
# On first assignment store default keyboard.
#
@default_kbd = @current_kbd if @default_kbd == "" # not yet assigned
true # OK
end # SetKeyboard()
# Restore the the data from sysconfig.
#
# @return true - Data could be restored
# false - Restore not successful
#
# @see #Save()
def Restore
ret = false
@restore_called = true
GetKbdSysconfig()
if !Stage.initial || Mode.live_installation
# Read YaST2 keyboard var.
#
@current_kbd = Misc.SysconfigRead(
path(".sysconfig.keyboard.YAST_KEYBOARD"),
""
)
pos = Builtins.find(@current_kbd, ",")
if pos != nil && Ops.greater_than(pos, 0)
@kb_model = Builtins.substring(@current_kbd, Ops.add(pos, 1))
@current_kbd = Builtins.substring(@current_kbd, 0, pos)
end
Builtins.y2milestone("current_kbd %1 model %2", @current_kbd, @kb_model)
if @current_kbd == ""
Builtins.y2milestone("Restoring data failed, returning defaults")
@current_kbd = "english-us"
@kb_model = "pc104"
ret = false
else
if !Mode.config
# Restore module data.
#
SetKeyboard(@current_kbd)
Builtins.y2milestone(
"Restored data (sysconfig) for keyboard: <%1>",
@current_kbd
)
else
# for cloning, to be shown in Summary
@name = GetKeyboardName(@current_kbd)
end
ret = true
end
else
ret = true
end
ret
end # Restore()
# get_xkblayout2keyboard()
#
# Get the xkblayout --> keyboard_language conversion map.
#
# @return conversion map
#
# @see get_lang2keyboard()
def get_xkblayout2keyboard
# The xkblayout --> keyboard_language conversion map.
#
xkblayout2keyboard = Convert.to_map(
SCR.Read(path(".target.yast2"), "xkblayout2keyboard.ycp")
)
xkblayout2keyboard = {} if xkblayout2keyboard == nil
deep_copy(xkblayout2keyboard)
end # get_xkblayout2keyboard()
# XkblayoutToKeyboard()
#
# Convert X11 keyboard layout name to yast2 name for keyboard description.
# e.g. "de" --> "german"
#
# @param [String] x11_layout
#
# @return [String] yast2 name for keyboard description
def XkblayoutToKeyboard(x11_layout)
xkblayout2keyboard = get_xkblayout2keyboard
# Now get the YaST2 internal representation of this keyboard layout.
#
ret = Ops.get_string(xkblayout2keyboard, x11_layout, "")
Builtins.y2milestone(
" XkblayoutToKeyboard x11:%1 ret:%2",
x11_layout,
ret
)
ret
end
# Probe keyboard and set local module data.
def probe_settings
# First assign the kb_model. This is e.g. "pc104".
# Aside from being used directly for writing the XF86Config file this is later on
# used to search the YaST2 keyboards database (it's a key in a map).
# Probe the keyboard.
#
if !Mode.config
@keyboardprobelist = Convert.to_list(SCR.Read(path(".probe.keyboard")))
Builtins.y2milestone("Probed keyboard: <%1>", @keyboardprobelist)
# Get the first keyboard from the list (it should exist).
#
keyboardmap1 = Ops.get_map(@keyboardprobelist, 0, {})
# Get the unique_key
#
@unique_key = Ops.get_string(keyboardmap1, "unique_key", "")
# Get the keyboard data for this first keyboard.
#
keyboardmap2 = Ops.get_map(keyboardmap1, ["keyboard", 0], {})
# Assign the XkbModel.
#
@kb_model = Ops.get_string(keyboardmap2, "xkbmodel", "pc104")
Builtins.y2milestone("kb_model: <%1>", @kb_model)
# Assign the XkbLayout.
# Only some keyboards do report this information (e.g. sparc).
#
@XkbLayout = Ops.get_string(keyboardmap2, "xkblayout", "")
Builtins.y2milestone("Xkblayout: <%1>", @XkbLayout)
else
@kb_model = "pc104"
end
nil
end # probe_settings()
# Probe()
#
# Allow for intentional probing by applications.
#
# @see #Keyboard()
def Probe
Builtins.y2milestone("Keyboard::Probe")
probe_settings
# Set the module to the current system language to achieve a consistent
# state. This may be superfluous because a client may do it also but
# just in case...
#
default_keyboard = ""
# Some keyboards (i.e. sparc) report their layout, try to use this information here
#
if @XkbLayout != "" # we do have hardware info
default_keyboard = GetKeyboardForLanguage(@XkbLayout, default_keyboard) # no hardware info ==> select default keyboard dependent on system language
else
default_keyboard = GetKeyboardForLanguage(
Language.language,
"english-us"
)
end
# Set the module state.
#
SetKeyboard(default_keyboard)
if Stage.initial
keytable = Linuxrc.InstallInf("Keytable")
# set the keyboard from linuxrc
if keytable != nil
Builtins.y2milestone("linuxrc keyboard: %1", keytable)
map2yast = Builtins.union(
keymap2yast,
{ "dk" => "danish", "de-lat1-nd" => "german", "us" => "english-us" }
)
if Builtins.issubstring(keytable, ".map.gz")
keytable = Builtins.substring(
keytable,
0,
Builtins.find(keytable, ".map.gz")
)
end
if Ops.get_string(map2yast, keytable, "") != ""
Set(Ops.get_string(map2yast, keytable, ""))
# do not reset it in proposal
@user_decision = true
end
# set keyboard now (before proposal - see bug #113664)
elsif Language.preselected != "en_US"
Builtins.y2milestone(
"language (%1) was preselected -> setting keyboard to %2",
Language.preselected,
default_keyboard
)
Set(default_keyboard)
end
end
Builtins.y2milestone("End Probe %1", default_keyboard)
nil
end # Probe()
# Keyboard()
#
# The module constructor.
# Sets the proprietary module data defined globally for public access.
# This is done only once (and automatically) when the module is loaded for the first time.
#
# @see #Probe()
def Keyboard
return if Mode.config
# We have these possible sources of information:
#
# probed data: - installation initial mode --> probing
# sysconfig: - installation continue mode or normal mode
#
Builtins.y2milestone("initial :%1, update:%2", Stage.initial, Mode.update)
success = false
# If not in initial mode try to restore from sysconfig.
if !Stage.initial || Mode.live_installation
success = Restore()
else
GetKbdSysconfig()
end
# In initial mode or if restoring failed do probe.
if !success
# On module entry probe the hardware and set all those data
# needed for public access.
Probe()
end
nil
end # Keyboard()
# Just store inital values - read was done in constructor
def Read
@keyboard_on_entry = @current_kbd
@expert_on_entry = GetExpertValues()
@ExpertSettingsChanged = false
Builtins.y2debug("keyboard_on_entry: %1", @keyboard_on_entry)
true
end
# was anything modified?
def Modified
@current_kbd != @keyboard_on_entry || @ExpertSettingsChanged
end
# Save the current data into a file to be read after a reboot.
#
def Save
if Mode.update
log.info "skipping country changes in update"
return
end
# Write some sysconfig variables.
#
SCR.Write(
path(".sysconfig.keyboard.YAST_KEYBOARD"),
"#{@current_kbd},#{@kb_model}"
)
SCR.Write(
path(".sysconfig.keyboard.YAST_KEYBOARD.comment"),
"\n" +
"# The YaST-internal identifier of the attached keyboard.\n" +
"#\n"
)
SCR.Write(path(".sysconfig.keyboard.KBD_RATE"), @kbd_rate)
SCR.Write(path(".sysconfig.keyboard.KBD_DELAY"), @kbd_delay)
SCR.Write(path(".sysconfig.keyboard.KBD_NUMLOCK"), @kbd_numlock)
SCR.Write(
path(".sysconfig.keyboard.KBD_DISABLE_CAPS_LOCK"),
@kbd_disable_capslock
)
SCR.Write(path(".sysconfig.keyboard"), nil) # flush
chomped_keymap = @keymap.chomp(".map.gz")
if Stage.initial
# do use --root option, running in chroot does not work (bsc#1074481)
cmd = "/usr/bin/systemd-firstboot --root #{Installation.destdir.shellescape} --keymap #{chomped_keymap.shellescape}"
result = WFM.Execute(path(".local.bash_output"), cmd)
else
# this sets both the console and the X11 keyboard (see "man localectl")
cmd = "/usr/bin/localectl set-keymap #{chomped_keymap.shellescape}"
result = SCR.Execute(path(".target.bash_output"), cmd)
end
log.info "Making keyboard settings persistent: command #{cmd} end with #{result.inspect}"
if result["exit"] != 0
log.error "Keyboard configuration not written. Failed to execute '#{cmd}'"
log.error "output: #{result.inspect}"
# TRANSLATORS: the "%s" is replaced by the executed command
Report.Error(_("Could not save the keyboard setting, the command\n%s\nfailed.") % cmd)
end
# As a preliminary step mark all keyboards except the one to be configured
# as configured = no and needed = no. Afterwards this one keyboard will be
# marked as configured = yes and needed = yes. This has to be done to
# prevent any problems that may occur if the user plugs in and out different
# keyboards or if a keyboard is selected from the database despite the fact
# that a keyboard has been probed. Otherwise the config popup may nag the user
# again and again.
#
# In order to get a list of *ALL* keyboards that have ever been conected to
# the system we must do a *manual* probing (accessing the libhd database).
# Doing only a "normal" probing would deliver only the *currently* attached
# keyboards which in turn would not allow to "unmark" all keyboards that may
# have been removed.
#
# Do *NOT* use probe_settings() here because this would newly assign the global
# "unique_key" which is not what we want here. It may have been cleared
# intentionally due to the users selection of a keyboard from the YaST database.
# Furthermore this would assign a unique_key even if there is no keyboard attached
# (if there _was_ a keyboard attached).
#
# Manual probing
@keyboardprobelist = Convert.to_list(
SCR.Read(path(".probe.keyboard.manual"))
)
log.info "No probed keyboards. Not unconfiguring any keyboards" if @keyboardprobelist.empty?
@keyboardprobelist.each do |keyboard|
key = keyboard["unique_key"] || ""
next if key.empty?
# OK, there is a key to mark...
#
if key != @unique_key
# OK, this key is _not_ the key of the keyboard to be configured.
# If the user selected a keyboard from the database Keyboard::unique_key
# has been set to "" there which also applies here.
# ==> Mark with "no".
#
SCR.Write(path(".probe.status.configured"), key, :no)
log.info "Marked keyboard <#{key}> as configured = no"
SCR.Write(path(".probe.status.needed"), key, :no)
log.info "Marked keyboard <#{key}> as needed = no"
else
log.info "Skipping active key <#{key}> --> to be configured"
end
end
# Only if the keyboard has been probed in this run the unique_key
# is not empty. Only in this case mark the device as "configured".
# In any other case the device should already be configured and
# the marking can't be done because the unique_key is missing.
# ==> Only mark after probing!
#
if @unique_key != ""
SCR.Write(path(".probe.status.configured"), @unique_key, :yes)
log.info "Marked keyboard <#{@unique_key}> as configured"
if !Linuxrc.serial_console
SCR.Write(path(".probe.status.needed"), @unique_key, :yes)
log.info "Marked keyboard <#{@unique_key}> as needed"
end
else
log.info "NOT marking keyboard as configured (no unique_key)"
end
log.info "Saved data for keyboard: <#{@current_kbd}>"
# Let's force the generation right away if needed
regenerate_initrd if needs_new_initrd?
nil
end # Save()
# Checks if initrd must be regenerated
#
# According to bnc#888804, initrd must be regenerated in order for any
# configuration change to survive to reboots. That means a regeneration is
# needed unless we are installing or updating (in those situations it will
# be a initrd generation at some point in the future for sure).
def needs_new_initrd?
Mode.normal
end
# Name()
# Just return the keyboard name, without setting anything.
# @return [String] user readable description.
def Name
@name
end
# Set the console keyboard to the given keyboard language.
#
# @param Keyboard language e.g. "english-us"
#
# @return The loadkeys command that has been executed to do it.
# (also stored in Keyboard::ckb_cmd)
def SetConsole(keyboard)
if Mode.test
Builtins.y2milestone("Test mode - NOT setting keyboard")
elsif Arch.board_iseries || Arch.s390 # workaround for bug #39025
Builtins.y2milestone("not calling loadkeys on iseries")
else
SetKeyboard(keyboard)
Builtins.y2milestone("Setting console keyboard to: <%1>", @current_kbd)
Builtins.y2milestone("loadkeys command: <%1>", @ckb_cmd)
SCR.Execute(path(".target.bash"), @ckb_cmd)
UI.SetKeyboard
end
@ckb_cmd
end # SetConsole()