Class: Yast::KeyboardClass

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) CalledRestore

CalledRestore()

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



1198
1199
1200
# File '../../src/modules/Keyboard.rb', line 1198

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



1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
# File '../../src/modules/Keyboard.rb', line 1311

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



1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
# File '../../src/modules/Keyboard.rb', line 1404

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


447
448
449
450
451
452
453
454
# File '../../src/modules/Keyboard.rb', line 447

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)



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

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


651
652
653
654
655
656
657
658
659
660
661
# File '../../src/modules/Keyboard.rb', line 651

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



428
429
430
431
432
433
434
435
436
437
438
439
# File '../../src/modules/Keyboard.rb', line 428

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

- (Object) GetKbdSysconfig

GetKbdSysconfig()

Restore the the non-keyboard values from sysconfig.



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

def GetKbdSysconfig
  # Read the the variables not touched by the module to be able to
  # store them again on Save().
  #
  @kbd_tty = Misc.SysconfigRead(
    path(".sysconfig.keyboard.KBD_TTY"),
    @kbd_tty
  )
  @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_capslock = Misc.SysconfigRead(
    path(".sysconfig.keyboard.KBD_CAPSLOCK"),
    @kbd_capslock
  )
  @kbd_scrlock = Misc.SysconfigRead(
    path(".sysconfig.keyboard.KBD_SCRLOCK"),
    @kbd_scrlock
  )
  @kbd_disable_capslock = Misc.SysconfigRead(
    path(".sysconfig.keyboard.KBD_DISABLE_CAPS_LOCK"),
    @kbd_disable_capslock
  )

  Builtins.y2milestone(
    "rate:%1 delay:%2 numlock:%3 capslock:%4 scrlock:%5 disclock:%6",
    @kbd_rate,
    @kbd_delay,
    @kbd_numlock,
    @kbd_capslock,
    @kbd_scrlock,
    @kbd_disable_capslock
  )
  Builtins.y2milestone("tty:%1", @kbd_tty)

  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.



469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
# File '../../src/modules/Keyboard.rb', line 469

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



1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
# File '../../src/modules/Keyboard.rb', line 1225

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)


410
411
412
413
414
415
416
417
418
419
420
# File '../../src/modules/Keyboard.rb', line 410

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



392
393
394
395
396
397
398
399
400
401
402
403
404
405
# File '../../src/modules/Keyboard.rb', line 392

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)

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

Parameters:

  • settings (Hash)

    imported map

Returns:

  • success



1392
1393
1394
1395
1396
1397
1398
1399
1400
# File '../../src/modules/Keyboard.rb', line 1392

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

  Set(Ops.get_string(settings, "keymap", @current_kbd))
  SetExpertValues(Ops.get_map(settings, "keyboard_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()


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

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.



373
374
375
376
377
378
379
380
381
382
# File '../../src/modules/Keyboard.rb', line 373

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



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

def main
  Yast.import "UI"
  textdomain "country"

  Yast.import "Arch"
  Yast.import "AsciiFile"
  Yast.import "Directory"
  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_tty = "tty1 tty2 tty3 tty4 tty5 tty6 tty8 tty9 tty10 tty11 tty12 tty13 tty14 tty15 tty16 tty17 tty18 tty19 tty20"

  @kbd_rate = ""
  @kbd_delay = ""
  @kbd_numlock = ""
  @kbd_capslock = ""
  @kbd_scrlock = ""
  @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.



1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
# File '../../src/modules/Keyboard.rb', line 1151

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?



845
846
847
# File '../../src/modules/Keyboard.rb', line 845

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.



1010
1011
1012
# File '../../src/modules/Keyboard.rb', line 1010

def Name
  @name
end

- (Object) Probe

Probe()

Allow for intentional probing by applications.

See Also:

  • #Keyboard()


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

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.



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

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



836
837
838
839
840
841
842
# File '../../src/modules/Keyboard.rb', line 836

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


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

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.



852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
# File '../../src/modules/Keyboard.rb', line 852

def Save
  if Mode.update
    kbd = Misc.SysconfigRead(path(".sysconfig.keyboard.YAST_KEYBOARD"), "")
    if Builtins.size(kbd) == 0
      kmap = Misc.SysconfigRead(path(".sysconfig.keyboard.KEYTABLE"), "")
      if Ops.greater_than(Builtins.size(kmap), 0)
        data = GetX11KeyData(kmap)
        if Ops.greater_than(
            Builtins.size(Ops.get_string(data, "XkbLayout", "")),
            0
          )
          kbd = XkblayoutToKeyboard(Ops.get_string(data, "XkbLayout", ""))
          kbd = Ops.add(
            Ops.add(kbd, ","),
            Ops.get_string(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"),
    Ops.add(Ops.add(@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.KEYTABLE"), @keymap)
  SCR.Write(path(".sysconfig.keyboard.COMPOSETABLE"), @compose_table)
  SCR.Write(path(".sysconfig.keyboard.KBD_TTY"), @kbd_tty)
  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_CAPSLOCK"), @kbd_capslock)
  SCR.Write(path(".sysconfig.keyboard.KBD_SCRLOCK"), @kbd_scrlock)
  SCR.Write(
    path(".sysconfig.keyboard.KBD_DISABLE_CAPS_LOCK"),
    @kbd_disable_capslock
  )
  SCR.Write(path(".sysconfig.keyboard"), nil) # flush

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

  list_size = Builtins.size(@keyboardprobelist)

  if Ops.greater_than(list_size, 0)
    i = 0

    while Ops.less_than(i, list_size)
      current_keyboard = Ops.get_map(@keyboardprobelist, i, {})
      current_key = Ops.get_string(current_keyboard, "unique_key", "")

      if current_key != ""
        # OK, there is a key to mark...
        #
        if current_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"), current_key, :no)
          Builtins.y2milestone(
            "Marked keyboard <%1> as configured = no",
            current_key
          )

          SCR.Write(path(".probe.status.needed"), current_key, :no)
          Builtins.y2milestone(
            "Marked keyboard <%1> as needed = no",
            current_key
          )
        else
          Builtins.y2milestone(
            "Skipping active key <%1> --> to be configured",
            current_key
          )
        end
      end

      i = Ops.add(i, 1) # next keyboard
    end
  else
    Builtins.y2milestone(
      "No probed keyboards. Not unconfiguring any keyboards"
    )
  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)
    Builtins.y2milestone("Marked keyboard <%1> as configured", @unique_key)

    if !Linuxrc.serial_console
      SCR.Write(path(".probe.status.needed"), @unique_key, :yes)
      Builtins.y2milestone("Marked keyboard <%1> as needed", @unique_key)
    end
  else
    Builtins.y2milestone(
      "NOT marking keyboard as configured (no unique_key)"
    )
  end

  Builtins.y2milestone("Saved data for keyboard: <%1>", @current_kbd)

  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.



1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
# File '../../src/modules/Keyboard.rb', line 1210

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


1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
# File '../../src/modules/Keyboard.rb', line 1098

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)



1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
# File '../../src/modules/Keyboard.rb', line 1020

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



1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
# File '../../src/modules/Keyboard.rb', line 1249

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, "capslock")
    @kbd_capslock = Ops.get_boolean(val, "capslock", false) ? "yes" : "no"
  end
  if Builtins.haskey(val, "scrlock")
    @kbd_scrlock = Ops.get_boolean(val, "scrlock", false) ? "yes" : "no"
  end
  if Builtins.haskey(val, "tty") &&
      Ops.greater_than(Builtins.size(Ops.get_string(val, "tty", "")), 0)
    @kbd_tty = Ops.get_string(val, "tty", "")
  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.



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

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



1298
1299
1300
1301
1302
1303
# File '../../src/modules/Keyboard.rb', line 1298

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

  nil
end

- (Object) SetKeyboardForLang(lang)



1294
1295
1296
# File '../../src/modules/Keyboard.rb', line 1294

def SetKeyboardForLang(lang)
  SetKeyboardForLanguage(lang)
end

- (Object) SetKeyboardForLanguage(lang)

set the keayboard layout according to given language



1286
1287
1288
1289
1290
1291
1292
# File '../../src/modules/Keyboard.rb', line 1286

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)



1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
# File '../../src/modules/Keyboard.rb', line 1045

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
    end
  end
  @xkb_cmd
end

- (Object) Summary

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

Returns:

  • summary string (html)



1422
1423
1424
1425
1426
1427
1428
1429
1430
# File '../../src/modules/Keyboard.rb', line 1422

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



497
498
499
500
501
# File '../../src/modules/Keyboard.rb', line 497

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



488
489
490
491
492
493
# File '../../src/modules/Keyboard.rb', line 488

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



673
674
675
676
677
678
679
680
681
682
683
684
685
# File '../../src/modules/Keyboard.rb', line 673

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