1
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
blog/output/custom-xkb-tweaks.html

165 lines
7.6 KiB
HTML

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<!doctype html>
<html>
<head>
<meta charset=utf-8>
<meta name=generator content="Pelican 4.9.1">
<meta name=author content="LEdoian">
<meta name=description content="My personal webpage">
<meta name=referrer content=no-referrer>
<link rel=stylesheet href="./theme/css/theme.css">
<title>Creating own XKB tweaks LEdoian's Blog</title>
</head>
<body>
<header>
<h1>LEdoian's Blog</h1>
</header>
<div id=main>
<nav>
<div>
<!-- Main navigation -->
<!-- TODO! -->
</div>
<div>
<h2>Categories</h2>
<ul>
<li><a href="./category/networking.html">networking</a></li>
<li><a href="./category/queer.html">queer</a></li>
<li><a href="./category/talks.html">talks</a></li>
<li><a href="./category/technology.html">technology</a></li>
<li><a href="./category/til.html">til</a></li>
</ul>
<h2>Tags</h2>
<ul>
<li><a href="./tag/linux.html">linux</a></li>
<li><a href="./tag/lifehack.html">lifehack</a></li>
<li><a href="./tag/software.html">software</a></li>
<li><a href="./tag/relationships.html">relationships</a></li>
<li><a href="./tag/identity.html">identity</a></li>
<li><a href="./tag/print.html">print</a></li>
<li><a href="./tag/comics.html">comics</a></li>
<li><a href="./tag/ipv6-only.html">ipv6-only</a></li>
<li><a href="./tag/dns.html">dns</a></li>
<li><a href="./tag/meta.html">meta</a></li>
<li><a href="./tag/infrastructure.html">infrastructure</a></li>
<li><a href="./tag/smrst.html">smršť</a></li>
<li><a href="./tag/trains.html">trains</a></li>
<li><a href="./tag/software-engineering.html">software-engineering</a></li>
</ul>
</div>
<div>
<h2>Stalk me also at</h2>
TODO!
<h2>I stalk</h2>
TODO!
</nav>
<main>
<div>
<div class="details"><time datetime="2024-04-17T16:40:00+02:00">2024-04-17 16:40</time></div>
<h1>Creating own XKB tweaks</h1>
<p>Debugging this took me a bit too long, so I want to write about the caveat.</p>
<p>My problem: My laptop does not have PageUp and PageDown keys, and many other
keyboards I use have similar deficiencies. And I use various environments and
various systems, some of which are shared with other people who don't need/want
my tweaks. IOW: I want something generic, but it must be confined to my user
no system-wide daemon, no udev remapping. (I mostly ended up with these
solutions when I searched for a way to remap keys on Wayland.)</p>
<p>Requirements: xkbcommon implementation of XKB with utilities. It is quite
common these days (duh…), but you could probably just compile this yourself if
you don't have it.</p>
<div class="section" id="the-tweaking">
<h2>The tweaking</h2>
<p>The <a class="reference external" href="https://xkbcommon.org/doc/current/user-configuration.html">xkbcommon guide</a> tells us that we
can inspect the files in <a class="footnote-reference" href="#lazy" id="footnote-reference-1">[1]</a> <tt class="docutils literal">/usr/share/X11/xkb</tt> for the source files
and just write our bits to <tt class="docutils literal"><span class="pre">~/.config/xkb/symbols/ledoian</span></tt>. In particular, I
added this snippet to remap keyboard brightness controls to PageUp/Down:</p>
<pre class="literal-block">
partial
xkb_symbols &quot;qs&quot; {
key &lt;I238&gt; {[ Prior ]};
key &lt;I237&gt; {[ Next ]};
};
</pre>
<p>The key identifiers are taken e.g. from <tt class="docutils literal">xkbcli <span class="pre">interactive-wayland</span></tt>.
However, this is KcCGST <a class="footnote-reference" href="#kccgst-vs-rmlvo" id="footnote-reference-2">[2]</a> description, but layouts are
configured using RMLVO, so I need to define an option and tell what it should
do. The guide wants me to create <tt class="docutils literal"><span class="pre">~/.config/xkb/rules/evdev</span></tt> with:</p>
<pre class="literal-block">
! option = symbols
ledoian:qs = +ledoian(qs)
! include %S/evdev
</pre>
<p>Now I just add <tt class="docutils literal">ledoian:qs</tt> <a class="footnote-reference" href="#option-vs-symbol" id="footnote-reference-3">[3]</a> to my keyboard configuration
and… it does not work. For this, at all, but if I remap e.g. the L key, that
gets applied. The problem? That included file says that the default keyboard
model always includes <tt class="docutils literal">inet(evdev)</tt> symbols. Those symbols set the default
meaning of the keys, but since that got applied later, it overrides my tweak.</p>
<p>Solution: first include, then add my option.</p>
<p>How to debug: read stuff that <tt class="docutils literal">xkbcli <span class="pre">compile-keymap</span> <span class="pre">--verbose</span></tt> tells you
(pass your config as <tt class="docutils literal"><span class="pre">--layout</span></tt>, <tt class="docutils literal"><span class="pre">--variant</span></tt>, <tt class="docutils literal"><span class="pre">--options</span></tt>, …). At the top
it says what it does:</p>
<pre class="literal-block">
xkbcommon: DEBUG: Include path added: /home/ledoian/.config/xkb
xkbcommon: DEBUG: Include path added: /usr/share/X11/xkb
xkbcommon: DEBUG: Compiling from RMLVO: rules 'evdev', model 'pc105', layout 'us', variant '(null)', options '(null)'
xkbcommon: DEBUG: Compiling from KcCGST: keycodes 'evdev+aliases(qwerty)', types 'complete', compat 'complete', symbols 'pc+us+inet(evdev)'
</pre>
<p>My option would appear before the <tt class="docutils literal">inet(evdev)</tt> part.</p>
</div>
<div class="section" id="a-note-about-x11">
<h2>A note about X11</h2>
<p>X11 uses a separate implementation of XKB (the original one, in fact), which
does _not_ look into the user directory, just the system ones. However, you can
compile the keymap yourself using <tt class="docutils literal">xkbcli <span class="pre">compile-keymap</span> [KEYMAP OPTIONS] &gt;
my_layout.xkb</tt> and load it into the X server with <tt class="docutils literal">xkbcomp my_layout.xkb $DISPLAY</tt>.</p>
<hr class="docutils" />
<table class="docutils footnote" frame="void" id="lazy" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#footnote-reference-1">[1]</a></td><td>This is not technically accurate, really the paths reference
<tt class="docutils literal">$XDG_something</tt> variables. I am lazy and just copied my system, so YMMV
(probably won't, though).</td></tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="kccgst-vs-rmlvo" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#footnote-reference-2">[2]</a></td><td>There are two levels of describing the keymap: the
lowlevel one is called KcCGST (short for keycodes, compat, geometry,
symbols, types) and is considered to be an implementation detail; the
user-facing one is RMLVO (rules, model, layout, variant, options) and that
is what you use in the configs, with <tt class="docutils literal">setxkbmap</tt> &amp;c.</td></tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="option-vs-symbol" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#footnote-reference-3">[3]</a></td><td>While both this example and the <a class="reference external" href="https://www.freedesktop.org/wiki/Software/XKeyboardConfig/">upstream</a> layouts name
the symbols and options similarly, I think they don't need to be related
you should be able to put whatever you want in your options to the left of
<tt class="docutils literal">=</tt>, the right hand side is the name of the symbol file and if a
non-default layout from that file is used, its name is put in the
parentheses.</td></tr>
</tbody>
</table>
</div>
</div>
</main>
</div> <!-- #main -->
<footer>
<hr>
Written using Pelican 4.9.1 by LEdoian.
</footer>
</body>
</html>