Class: Yast::KeyboardClass

Inherits:
Module
  • Object
show all
Includes:
Logger
Defined in:
../../src/modules/Keyboard.rb

Constant Summary

UDEV_FILE =

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.

"/usr/lib/udev/rules.d/70-installation-keyboard.rules"
UDEV_COMMENT =
"# Generated by Yast to handle the layout of keyboards "\
"connected during installation\n"

Instance Method Summary (collapse)

Instance Method Details

- (Object) CalledRestore

CalledRestore()

Return if the kbd values have already been read from /etc/sysconfig/keyboard



1186
1187
1188
# File '../../src/modules/Keyboard.rb', line 1186

def CalledRestore
  @restore_called
end

- (Object) CheckKeyboardDuringUpdate(destdir)

Special function for update mode only. Checks for the keyboard layout on the system which should be updated and if it differs from current one, opens a popup with the offer to change the layout. See discussion in bug #71069

Parameters:

  • destdir (String)

    path to the mounted system to update (e.g. “/mnt”)



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
# File '../../src/modules/Keyboard.rb', line 1289

def CheckKeyboardDuringUpdate(destdir)
  # autoupgrade is not interactive, therefore skip this check and use data
  # from profile directly
  return if Mode.autoupgrade

  target_kbd = Misc.CustomSysconfigRead(
    "YAST_KEYBOARD",
    @current_kbd,
    Ops.add(destdir, "/etc/sysconfig/keyboard")
  )
  pos = Builtins.find(target_kbd, ",")
  if pos != nil && Ops.greater_than(pos, 0)
    target_kbd = Builtins.substring(target_kbd, 0, pos)
  end

  keyboards = get_reduced_keyboard_db

  if target_kbd != @current_kbd &&
      Ops.get_list(keyboards, target_kbd, []) != []
    Builtins.y2milestone(
      "current_kbd: %1, target_kbd: %2",
      @current_kbd,
      target_kbd
    )

    target_name = GetKeyboardName(target_kbd)

    UI.OpenDialog(
      Opt(:decorated),
      HBox(
        HSpacing(1.5),
        VBox(
          HSpacing(40),
          VSpacing(0.5),
          # label text: user can choose the keyboard from the updated system
          # or continue with the one defined by his language.
          # 2 radio-buttons follow this label.
          # Such keyboard layout is used only for the time of the update,
          # it is not saved to the system.
          Left(
            Label(
              _(
                "You are currently using a keyboard layout\n" +
                  "different from the one in the system to update.\n" +
                  "Select the layout to use during update:"
              )
            )
          ),
          VSpacing(0.5),
          RadioButtonGroup(
            VBox(
              Left(RadioButton(Id(:current), @name)),
              Left(RadioButton(Id(:target), target_name, true))
            )
          ),
          VSpacing(0.5),
          ButtonBox(
            PushButton(Id(:ok), Opt(:default, :key_F10), Label.OKButton),
            PushButton(Id(:cancel), Opt(:key_F9), Label.CancelButton)
          ),
          VSpacing(0.5)
        ),
        HSpacing(1.5)
      )
    )
    ret = UI.UserInput

    if ret == :ok && Convert.to_boolean(UI.QueryWidget(Id(:target), :Value))
      Set(target_kbd)
      @user_decision = true
    end

    UI.CloseDialog
  end

  nil
end

- (Hash) Export

AutoYaST interface function: Return the Keyboard configuration as a map.

Returns:

  • (Hash)

    with the settings



1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
# File '../../src/modules/Keyboard.rb', line 1396

def Export
  diff_values = {}
  Builtins.foreach(
    Convert.convert(
      GetExpertValues(),
      :from => "map",
      :to   => "map <string, any>"
    )
  ) do |key, val|
    Ops.set(diff_values, key, val) if Ops.get(@expert_on_entry, key) != val
  end
  ret = { "keymap" => @current_kbd }
  Ops.set(ret, "keyboard_values", diff_values) if diff_values != {}
  deep_copy(ret)
end

- (Object) get_lang2keyboard

Get the system_language –> keyboard_language conversion map.

Returns:

  • conversion map

See Also:

  • #get_xkblayout2keyboard()


436
437
438
439
440
441
442
443
# File '../../src/modules/Keyboard.rb', line 436

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

- (Object) get_reduced_keyboard_db

get_reduced_keyboard_db()

Read the Keyboard DB and select entries for current XkbModel and architecture.

Returns:

  • Reduced keyboard DB (map)



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
# File '../../src/modules/Keyboard.rb', line 289

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).

  # eval is necessary for translating the texts needed to be translated
  all_keyboards = Convert.convert(
    Builtins.eval(SCR.Read(path(".target.yast2"), "keyboard_raw.ycp")),
    :from => "any",
    :to   => "map <string, list>"
  )

  all_keyboards = {} if all_keyboards == nil

  # 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

- (Object) get_xkblayout2keyboard

get_xkblayout2keyboard()

Get the xkblayout –> keyboard_language conversion map.

Returns:

  • conversion map

See Also:

  • get_lang2keyboard()


640
641
642
643
644
645
646
647
648
649
650
# File '../../src/modules/Keyboard.rb', line 640

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

- (Hash) GetExpertValues

GetExpertValues()

Return the values for the various expert settings in a map

Returns:

  • (Hash)

    with values filled in



420
421
422
423
424
425
426
427
428
# File '../../src/modules/Keyboard.rb', line 420

def GetExpertValues
  ret = {
    "rate"     => @kbd_rate,
    "delay"    => @kbd_delay,
    "numlock"  => @kbd_numlock,
    "discaps"  => @kbd_disable_capslock == "yes" ? true : false
  }
  deep_copy(ret)
end

- (Object) GetKbdSysconfig

GetKbdSysconfig()

Restore the the non-keyboard values from sysconfig.



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
# File '../../src/modules/Keyboard.rb', line 251

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

- (Object) GetKeyboardForLanguage(sys_language, default_keyboard)

GetKeyboardForLanguage()

Get the keyboard language for the given system language.

Parameters:

  • System

    language code, e.g. “en_US”. Default keyboard language to be returned if nothing found.

Returns:

  • The keyboard language for this language, e.g. “english-us” or the default value if nothing found.



458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
# File '../../src/modules/Keyboard.rb', line 458

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

- (Object) GetKeyboardItems

Return item list of keyboard items, sorted according to current language



1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
# File '../../src/modules/Keyboard.rb', line 1213

def GetKeyboardItems
  ret = Builtins.maplist(Selection()) do |code, name|
    Item(Id(code), name, @current_kbd == code)
  end
  Builtins.sort(ret) do |a, b|
    # bnc#385172: must use < instead of <=, the following means:
    # strcoll(x) <= strcoll(y) && strcoll(x) != strcoll(y)
    lsorted = Builtins.lsort(
      [Ops.get_string(a, 1, ""), Ops.get_string(b, 1, "")]
    )
    lsorted_r = Builtins.lsort(
      [Ops.get_string(b, 1, ""), Ops.get_string(a, 1, "")]
    )
    Ops.get_string(lsorted, 0, "") == Ops.get_string(a, 1, "") &&
      lsorted == lsorted_r
  end
end

- (String) GetKeyboardName(kbd)

Return human readable (and translated) name of the given keyboard map

Parameters:

  • kbd (String)

    keyboard map

Returns:

  • (String)


402
403
404
405
406
407
408
409
410
411
412
# File '../../src/modules/Keyboard.rb', line 402

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

- (Hash) GetX11KeyData(keymap)

GetX11KeyData()

Get the keyboard info for X11 for the given keymap

Parameters:

  • name

    of the keymap

Returns:

  • (Hash)

    containing the x11 config data



384
385
386
387
388
389
390
391
392
393
394
395
396
397
# File '../../src/modules/Keyboard.rb', line 384

def GetX11KeyData(keymap)
  cmd = "/usr/sbin/xkbctrl"
  x11data = {}

  if Ops.greater_than(SCR.Read(path(".target.size"), cmd), 0)
    file = Ops.add(Directory.tmpdir, "/xkbctrl.out")
    cmd = Ops.add(Ops.add(cmd, " "), keymap)
    SCR.Execute(path(".target.bash"), Ops.add(Ops.add(cmd, " > "), file))
    x11data = Convert.to_map(SCR.Read(path(".target.ycp"), file))
  else
    Builtins.y2warning("/usr/sbin/xkbctrl not found")
  end
  deep_copy(x11data)
end

- (Object) Import(settings, syntax = :keyboard)

AutoYaST interface function: Get the Keyboard configuration from a map.

Parameters:

  • settings (Hash)

    imported map with the content of either the 'keyboard' or the 'language' section

  • syntax (:keyboard, :language) (defaults to: :keyboard)

    format of settings: if :language, the data for Language.Import

Returns:

  • success



1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
# File '../../src/modules/Keyboard.rb', line 1374

def Import(settings, syntax = :keyboard)
  settings = deep_copy(settings)
  # Read was not called -> do the init
  Read() if @expert_on_entry == {}

  keyboard = @current_kbd
  expert_values = {}

  case syntax
  when :keyboard
    keyboard = settings["keymap"] if settings["keymap"]
    expert_values = settings["keyboard_values"] if settings["keyboard_values"]
  when :language
    keyboard = GetKeyboardForLanguage(settings["language"], keyboard)
  end
  Set(keyboard)
  SetExpertValues(expert_values)
  true
end

- (Object) Keyboard

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 Also:

  • #Probe()


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
# File '../../src/modules/Keyboard.rb', line 795

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

- (Hash) keymap2yast

Return a map for conversion from keymap to YaST2 keyboard code() Get the map of translated keyboard names.

Parameters:

  • -

Returns:

  • (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.



365
366
367
368
369
370
371
372
373
374
# File '../../src/modules/Keyboard.rb', line 365

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

- (Object) main



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
# File '../../src/modules/Keyboard.rb', line 105

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 "ProductFeatures"
  Yast.import "Stage"
  Yast.import "XVersion"

  # ------------------------------------------------------------------------
  # 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"

  # compose_table entry
  #
  @compose_table = "clear winkeys shiftctrl latin1.add"

  # 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
  Keyboard()
end

- (String) MakeProposal(force_reset, language_changed)

MakeProposal()

Return proposal string and set system keyboard.

Parameters:

  • force_reset (Boolean)

    boolean language_changed

Returns:

  • (String)

    user readable description. If force_reset is true reset the module to the keyboard stored in default_kbd.



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
# File '../../src/modules/Keyboard.rb', line 1139

def MakeProposal(force_reset, language_changed)
  Builtins.y2milestone("force_reset: %1", force_reset)
  Builtins.y2milestone("language_changed: %1", language_changed)

  if force_reset
    # If user wants to reset do it if a default is available.
    if @default_kbd != ""
      Set(@default_kbd) # reset
    end

    # Reset user_decision flag.
    @user_decision = false
    @restore_called = false # no reset
  else
    # Only follow the language if the user has never actively chosen
    # a keyboard. The indicator for this is user_decision which is
    # set from outside the module.
    if @user_decision || Mode.update && !Stage.initial || Mode.autoinst ||
        Mode.live_installation ||
        ProductFeatures.GetStringFeature("globals", "keyboard") != ""
      if language_changed
        Builtins.y2milestone(
          "User has chosen a keyboard; not following language - only retranslation."
        )

        Set(@current_kbd)
      end
    else
      # User has not yet chosen a keyboard ==> follow language.
      local_kbd = GetKeyboardForLanguage(Language.language, "english-us")
      if local_kbd != ""
        Set(local_kbd)
      elsif language_changed
        Builtins.y2error("Can't follow language - only retranslation")
        Set(@current_kbd)
      end
    end
  end
  @name
end

- (Object) Modified

was anything modified?



834
835
836
# File '../../src/modules/Keyboard.rb', line 834

def Modified
  @current_kbd != @keyboard_on_entry || @ExpertSettingsChanged
end

- (String) Name

Name() Just return the keyboard name, without setting anything.

Returns:

  • (String)

    user readable description.



996
997
998
# File '../../src/modules/Keyboard.rb', line 996

def Name
  @name
end

- (Boolean) needs_new_initrd?

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).

Returns:

  • (Boolean)


988
989
990
# File '../../src/modules/Keyboard.rb', line 988

def needs_new_initrd?
  Mode.normal
end

- (Object) Probe

Probe()

Allow for intentional probing by applications.

See Also:

  • #Keyboard()


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
# File '../../src/modules/Keyboard.rb', line 726

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" }
      )
      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

- (Object) probe_settings

Probe keyboard and set local module data.



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
# File '../../src/modules/Keyboard.rb', line 678

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

- (Object) Read

Just store inital values - read was done in constructor



825
826
827
828
829
830
831
# File '../../src/modules/Keyboard.rb', line 825

def Read
  @keyboard_on_entry = @current_kbd
  @expert_on_entry = GetExpertValues()
  @ExpertSettingsChanged = false
  Builtins.y2debug("keyboard_on_entry: %1", @keyboard_on_entry)
  true
end

- (Object) Restore

Restore the the data from sysconfig.

Returns:

  • true - Data could be restored false - Restore not successful

See Also:

  • #Save()


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
# File '../../src/modules/Keyboard.rb', line 587

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

- (Object) Save

Save the current data into a file to be read after a reboot.



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
# File '../../src/modules/Keyboard.rb', line 841

def Save
  if Mode.update
    kbd = Misc.SysconfigRead(path(".sysconfig.keyboard.YAST_KEYBOARD"), "")
    if kbd.empty?
      kmap = Misc.SysconfigRead(path(".etc.vconsole_conf.KEYMAP"), "")
      # if still nothing found, lets check the obsolete config option:
      kmap = Misc.SysconfigRead(path(".sysconfig.keyboard.KEYTABLE"), "") if kmap.empty?
      if !kmap.empty?
        data = GetX11KeyData(kmap)
        if (data["XkbLayout"] || "").size > 0
          kbd = XkblayoutToKeyboard(data["XkbLayout"]) + "," + (data["XkbModel"] || "pc104")
          SCR.Write(path(".sysconfig.keyboard.YAST_KEYBOARD"), kbd)
          SCR.Write(
            path(".sysconfig.keyboard.YAST_KEYBOARD.comment"),
            "\n" +
              "# The YaST-internal identifier of the attached keyboard.\n" +
              "#\n"
          )
          SCR.Write(path(".sysconfig.keyboard"), nil) # flush
        end
      end
    end
    return
  end

  # Write some sysconfig variables.
  # Set keytable, compose_table and tty list.
  #
  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.COMPOSETABLE"), @compose_table)
  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

  # Write systemd settings for console
  SCR.Write(path(".etc.vconsole_conf.KEYMAP"), @keymap.gsub(/(.*)\.map\.gz/, '\1'))
  SCR.Write(path(".etc.vconsole_conf"), nil) # flush

  # Write systemd settings for X11
  if x11_setup_needed
    # According to localectl syntax, if one option is empty then skip
    # the following ones
    args = [@XkbLayout, @XkbModel, @XkbVariant, @XkbOptions]
    blank = args.find_index("")
    args = args[0, blank] if blank
    if !args.empty?
      cmd = "/usr/bin/localectl --no-convert set-x11-keymap #{args.join(' ')}"
      if SCR.Execute(path(".target.bash"), cmd) != 0
        log.error "X11 configuration not written. Failed to execute '#{cmd}'"
      end
    end
  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

- (Hash) Selection

Selection()

Get the map of translated keyboard names.

Returns:

  • (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.



1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
# File '../../src/modules/Keyboard.rb', line 1198

def Selection
  # Get the reduced keyboard DB.
  #
  keyboards = get_reduced_keyboard_db
  translate = ""
  trans_str = ""

  Builtins.mapmap(keyboards) do |keyboard_code, keyboard_value|
    translate = Ops.get_string(keyboard_value, 0, "")
    trans_str = Builtins.eval(translate)
    { keyboard_code => trans_str }
  end
end

- (void) Set(keyboard)

This method returns an undefined value.

Set()

Set the keyboard to the given keyboard language.

Parameters:

  • Keyboard

    language e.g. “english-us”

See Also:

  • SetConsole()


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
# File '../../src/modules/Keyboard.rb', line 1086

def Set(keyboard)
  Builtins.y2milestone("set to %1", keyboard)
  if Mode.config
    @current_kbd = keyboard
    @name = GetKeyboardName(@current_kbd)
    return
  end

  SetConsole(keyboard)
  SetX11(keyboard)
  if Stage.initial && !Mode.live_installation
    yinf = {}
    yinf_ref = arg_ref(yinf)
    AsciiFile.SetDelimiter(yinf_ref, " ")
    yinf = yinf_ref.value
    yinf_ref = arg_ref(yinf)
    AsciiFile.ReadFile(yinf_ref, "/etc/yast.inf")
    yinf = yinf_ref.value
    lines = AsciiFile.FindLineField(yinf, 0, "Keytable:")
    if Ops.greater_than(Builtins.size(lines), 0)
      yinf_ref = arg_ref(yinf)
      AsciiFile.ChangeLineField(
        yinf_ref,
        Ops.get_integer(lines, 0, -1),
        1,
        @keymap
      )
      yinf = yinf_ref.value
    else
      yinf_ref = arg_ref(yinf)
      AsciiFile.AppendLine(yinf_ref, ["Keytable:", @keymap])
      yinf = yinf_ref.value
    end
    yinf_ref = arg_ref(yinf)
    AsciiFile.RewriteFile(yinf_ref, "/etc/yast.inf")
    yinf = yinf_ref.value
  end

  nil
end

- (Object) SetConsole(keyboard)

Set the console keyboard to the given keyboard language.

Parameters:

  • Keyboard

    language e.g. “english-us”

Returns:

  • The loadkeys command that has been executed to do it. (also stored in Keyboard::ckb_cmd)



1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
# File '../../src/modules/Keyboard.rb', line 1006

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

- (Object) SetExpertValues(val)

SetExpertValues()

Set the values of the various expert setting

Parameters:

  • val (Hash)

    map with new values of expert settings



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
# File '../../src/modules/Keyboard.rb', line 1237

def SetExpertValues(val)
  val = deep_copy(val)
  orig_values = GetExpertValues()

  if Builtins.haskey(val, "rate") &&
      Ops.greater_than(Builtins.size(Ops.get_string(val, "rate", "")), 0)
    @kbd_rate = Ops.get_string(val, "rate", "")
  end
  if Builtins.haskey(val, "delay") &&
      Ops.greater_than(Builtins.size(Ops.get_string(val, "delay", "")), 0)
    @kbd_delay = Ops.get_string(val, "delay", "")
  end
  if Builtins.haskey(val, "numlock")
    @kbd_numlock = Ops.get_string(val, "numlock", "")
  end
  if Builtins.haskey(val, "discaps")
    @kbd_disable_capslock = Ops.get_boolean(val, "discaps", false) ? "yes" : "no"
  end

  if !@ExpertSettingsChanged && orig_values != GetExpertValues()
    @ExpertSettingsChanged = true
  end

  nil
end

- (Object) SetKeyboard(keyboard)

SetKeyboard()

Set language specific module data to reflect the given keyboard layout.

Parameters:

  • Keyboard

    layout e.g. “english-us”

Returns:

  • true - Success. Language set in public data. false - Error. Language not set.



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
# File '../../src/modules/Keyboard.rb', line 502

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", "basic")
    @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", "")

    # Build the compose table entry.
    #
    @compose_table = "clear "

    if @XkbModel == "pc104" || @XkbModel == "pc105"
      @compose_table = Ops.add(@compose_table, "winkeys shiftctrl ")
    end

    # Check for "compose" entry in keytable, might define
    # a different encoding (i.e. "latin2").
    #
    compose = Ops.get_string(@kbd_descr, [1, "compose"], "latin1.add")

    @compose_table = Ops.add(@compose_table, compose) # Language not found.
  else
    return false # Error
  end

  # Console command...
  @ckb_cmd = Ops.add("/bin/loadkeys ", @keymap)

  # X11 command...
  # do not try to run this with remote X display
  if Ops.greater_than(Builtins.size(@Apply), 0) && x11_setup_needed
    @xkb_cmd = Ops.add(Ops.add(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

- (Object) SetKeyboardDefault



1276
1277
1278
1279
1280
1281
# File '../../src/modules/Keyboard.rb', line 1276

def SetKeyboardDefault
  Builtins.y2milestone("SetKeyboardDefault to %1", @current_kbd)
  @default_kbd = @current_kbd

  nil
end

- (Object) SetKeyboardForLang(lang)



1272
1273
1274
# File '../../src/modules/Keyboard.rb', line 1272

def SetKeyboardForLang(lang)
  SetKeyboardForLanguage(lang)
end

- (Object) SetKeyboardForLanguage(lang)

set the keayboard layout according to given language



1264
1265
1266
1267
1268
1269
1270
# File '../../src/modules/Keyboard.rb', line 1264

def SetKeyboardForLanguage(lang)
  lkbd = GetKeyboardForLanguage(lang, "english-us")
  Builtins.y2milestone("language %1 proposed keyboard %2", lang, lkbd)
  Set(lkbd) if lkbd != ""

  nil
end

- (Object) SetX11(keyboard)

Set the X11 keyboard to the given keyboard language.

Parameters:

  • Keyboard

    language e.g. “english-us”

Returns:

  • The xkbset command that has been executed to do it. (also stored in Keyboard::xkb_cmd)



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
# File '../../src/modules/Keyboard.rb', line 1031

def SetX11(keyboard)
  if Mode.test
    Builtins.y2milestone("Test mode - would have called:\n %1", @xkb_cmd)
  else
    # Actually do it only if we are in graphical mode.
    #
    textmode = Linuxrc.text
    if !Stage.initial || Mode.live_installation
      display_info = UI.GetDisplayInfo
      textmode = Ops.get_boolean(display_info, "TextMode", false)
    end
    display = Builtins.getenv("DISPLAY")
    if textmode
      Builtins.y2milestone("Not setting X keyboard due to text mode")
    # check if we are running over ssh: bnc#539218,c4
    elsif Ops.greater_or_equal(
        Builtins.tointeger(
          Ops.get(Builtins.splitstring(display, ":"), 1, "0")
        ),
        10
      )
      Builtins.y2milestone("Not setting X keyboard: running over ssh")
    elsif Ops.greater_than(Builtins.size(@xkb_cmd), 0)
      SetKeyboard(keyboard)
      Builtins.y2milestone("Setting X11 keyboard to: <%1>", @current_kbd)
      Builtins.y2milestone("Setting X11 keyboard:\n %1", @xkb_cmd)
      SCR.Execute(path(".target.bash"), @xkb_cmd)
      # bnc#371756: enable autorepeat
      if Stage.initial && !Mode.live_installation && !xen_running
        cmd = "xset r on"
        Builtins.y2milestone(
          "calling xset to fix autorepeat problem: %1",
          cmd
        )
        SCR.Execute(path(".target.bash"), cmd)
      end
      # bnc#885271: set udev rule to handle incoming attached keyboards
      write_udev_rule if Stage.initial
    end
  end
  @xkb_cmd
end

- (Object) Summary

AutoYaST interface function: Return the summary of Keyboard configuration as a map.

Returns:

  • summary string (html)



1414
1415
1416
1417
1418
1419
1420
1421
1422
# File '../../src/modules/Keyboard.rb', line 1414

def Summary
  Yast.import "HTML"

  ret = [
    # summary label
    Builtins.sformat(_("Current Keyboard Layout: %1"), @name)
  ]
  HTML.List(ret)
end

- (Object) x11_setup_needed

run X11 configuration after inital boot



486
487
488
489
490
# File '../../src/modules/Keyboard.rb', line 486

def x11_setup_needed
  Arch.x11_setup_needed &&
    !(Linuxrc.serial_console || Linuxrc.vnc || Linuxrc.usessh ||
      Linuxrc.text)
end

- (Object) xen_running

check if we are running in XEN (autorepeat functionality not supported) seem bnc#376945, #371756



477
478
479
480
481
482
# File '../../src/modules/Keyboard.rb', line 477

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

- (String) XkblayoutToKeyboard(x11_layout)

XkblayoutToKeyboard()

Convert X11 keyboard layout name to yast2 name for keyboard description. e.g. “de” –> “german”

Parameters:

  • x11_layout (String)

Returns:

  • (String)

    yast2 name for keyboard description



662
663
664
665
666
667
668
669
670
671
672
673
674
# File '../../src/modules/Keyboard.rb', line 662

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