keyboard-config.patch 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. Index: zorg-2.0.4/zorg/config.py
  2. ===================================================================
  3. --- zorg-2.0.4.orig/zorg/config.py
  4. +++ zorg-2.0.4/zorg/config.py
  5. @@ -11,6 +11,21 @@ from zorg.parser import *
  6. from zorg.probe import VideoDevice, Monitor, Output
  7. from zorg.utils import *
  8. +KEYMAP_CONF_TEMPLATE="""\
  9. +# This file is generated by zorg. If you want to change settings
  10. +# in this file, edit the file 10-keyboard.conf in the same
  11. +# directory.
  12. +
  13. +Section "InputClass"
  14. + Identifier "Configured Keymap"
  15. + MatchIsKeyboard "on"
  16. + MatchTag "use_configured_keymap"
  17. +
  18. + %(comment_layout)sOption "xkb_layout" "%(layout)s"
  19. + %(comment_variant)sOption "xkb_variant" "%(variant)s"
  20. +EndSection
  21. +"""
  22. +
  23. def saveXorgConfig(card):
  24. parser = XorgParser()
  25. @@ -265,7 +280,7 @@ def saveDeviceInfo(card):
  26. f = open(consts.config_file, "w")
  27. f.write(doc.toPrettyString().replace("\n\n", ""))
  28. -def getKeymap():
  29. +def getKeymapOld():
  30. layout = None
  31. variant = ""
  32. @@ -297,24 +312,44 @@ def getKeymap():
  33. return layout, variant
  34. -def saveKeymap(layout, variant=""):
  35. - if not os.path.exists(consts.config_dir):
  36. - os.mkdir(consts.config_dir, 0755)
  37. +def getKeymap():
  38. + layout = None
  39. + variant = ""
  40. try:
  41. - doc = piksemel.parse(consts.config_file)
  42. + p = XorgParser()
  43. + p.parseFile(consts.keymap_conf)
  44. + section = p.getSections("InputClass")[0]
  45. + layout = section.get("xkb_layout")
  46. + variant = section.get("xkb_variant", "")
  47. +
  48. except OSError:
  49. - doc = piksemel.newDocument("ZORG")
  50. + pass
  51. +
  52. + if not layout:
  53. + from pardus.localedata import languages
  54. - keyboardTag = doc.getTag("Keyboard")
  55. + try:
  56. + language = file("/etc/mudur/language").read().strip()
  57. + except IOError:
  58. + language = "en"
  59. +
  60. + if not languages.has_key(language):
  61. + language = "en"
  62. - if keyboardTag:
  63. - keyboardTag.hide()
  64. + keymap = languages[language].keymaps[0]
  65. + layout = keymap.xkb_layout
  66. + variant = keymap.xkb_variant
  67. - keyboardTag = doc.insertTag("Keyboard")
  68. - keyboardTag.insertTag("Layout").insertData(layout)
  69. - if variant:
  70. - keyboardTag.insertTag("Variant").insertData(variant)
  71. + return layout, variant
  72. - f = file(consts.config_file, "w")
  73. - f.write(doc.toPrettyString().replace("\n\n", ""))
  74. +def saveKeymap(layout, variant=""):
  75. + opts = {"layout": layout,
  76. + "variant": variant,
  77. + "comment_layout": "" if layout else "#",
  78. + "comment_variant": "" if variant else "#"}
  79. +
  80. + with open(consts.keymap_conf, "w") as f:
  81. + f.write(KEYMAP_CONF_TEMPLATE % opts)
  82. + f.flush()
  83. + os.fsync(f.fileno())
  84. Index: zorg-2.0.4/zorg/consts.py
  85. ===================================================================
  86. --- zorg-2.0.4.orig/zorg/consts.py
  87. +++ zorg-2.0.4/zorg/consts.py
  88. @@ -8,6 +8,7 @@ data_dir = "/usr/share/X11"
  89. modules_dir = "/usr/lib/xorg/modules"
  90. xorg_conf_file = "/etc/X11/xorg.conf"
  91. +keymap_conf = "/etc/X11/xorg.conf.d/00-configured-keymap.conf"
  92. config_file = join(config_dir, "config.xml")
  93. configured_bus_file = join(config_dir, "configured_bus")
  94. drivers_file = join(data_dir, "DriversDB")