diff --git a/README.rst b/README.rst index befea95..a551d0d 100644 --- a/README.rst +++ b/README.rst @@ -112,11 +112,35 @@ To apply a keyboard layout in user-space: This has limitations: it doesn’t work on Wayland and the keyboard layout doesn’t show up in the Gnome keyboard manager. Besides, on some distros, media keys might stop working. -The proper way to install a keyboard layout on Linux is to modify directly the files in ``/usr/share/X11/xkb``. This is where ``xkalamine`` comes in: +The proper way to install a keyboard layout on Linux is to modify directly the files in ``/usr/share/X11/xkb``. This is where ``xkalamine`` comes in (for this example the locale is ``us``). + +Optionally backup your original system files as root: + +.. code-block:: bash + + # cd /usr/share/X11/xkb + # cp rules/base.xml rules/base.xml.orig + # cp rules/evdev.xml rules/evdev.xml.orig + # cp symbols/us symbols/us.orig + +Generate the ``base.xml``, ``evdev.xml`` and ``us`` (or your locale) files as a regular user .. code-block:: bash - sudo xkalamine install layout.yaml + $ ls + layout.yaml + $ xkalamine install layout.yaml + $ ls + base.xml evdev.xml layout.yaml us + +and install the layout by coping them into ``/usr/share/X11/xkb/`` as root: + +.. code-block:: bash + + # cp -f base.xml /usr/share/X11/xkb/rules/base.xml + # cp -f evdev.xml /usr/share/X11/xkb/rules/evdev.xml + # cp -f us /usr/share/X11/xkb/symbols/us + There’s also: diff --git a/kalamine/xkb_manager.py b/kalamine/xkb_manager.py index 2304e25..1a36ff9 100644 --- a/kalamine/xkb_manager.py +++ b/kalamine/xkb_manager.py @@ -174,17 +174,17 @@ def update_symbols(xkb_root, kbindex): if not os.path.exists(path): exit_LocaleNotSupported(locale) - try: - if not os.path.isfile(path + '.orig'): - # backup, just in case :-) - shutil.copy(path, path + '.orig') - print('... ' + path + '.orig (backup)') + basename = os.path.basename(path) + if not os.path.isfile(basename): + shutil.copy(path, basename) + print ('... ' + path + ' (copy)') - print('... ' + path) - update_symbols_locale(path, named_layouts) + try: + print('... ' + basename) + update_symbols_locale(basename, named_layouts) except Exception as e: - exit_FileNotWritable(e, path) + exit_FileNotWritable(e, basename) ############################################################################### @@ -224,26 +224,31 @@ def update_rules(xkb_root, kbindex): """ Update references in XKB/rules/{base,evdev}.xml. """ for filename in ['base.xml', 'evdev.xml']: + path = os.path.join(xkb_root, 'rules', filename) + basename = os.path.basename(path) + if not os.path.isfile(basename): + shutil.copy(path, basename) + print('... ' + path + ' (copy)') + try: - path = os.path.join(xkb_root, 'rules', filename) - tree = etree.parse(path, etree.XMLParser(remove_blank_text=True)) + tree = etree.parse(basename, etree.XMLParser(remove_blank_text=True)) for locale, named_layouts in kbindex.items(): vlist = get_rules_locale(tree, locale).xpath('variantList') if len(vlist) != 1: - exit('Error: unexpected xml format in %s.' % path) + exit('Error: unexpected xml format in %s.' % basename) for name, layout in named_layouts.items(): remove_rules_variant(vlist[0], name) if layout is not None: description = layout.meta['description'] add_rules_variant(vlist[0], name, description) - tree.write(path, pretty_print=True, xml_declaration=True, + tree.write(basename, pretty_print=True, xml_declaration=True, encoding='utf-8') - print('... ' + path) + print('... ' + basename) except Exception as e: - exit_FileNotWritable(e, path) + exit_FileNotWritable(e, basename) def list_rules(xkb_root, mask='', include_non_kalamine_variants=False):