Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regional Keyboards #5

Open
s-ol opened this issue May 13, 2024 · 3 comments
Open

Regional Keyboards #5

s-ol opened this issue May 13, 2024 · 3 comments

Comments

@s-ol
Copy link
Contributor

s-ol commented May 13, 2024

Currently all keyboards use the default US layout. I've tried installing console-data and while this installs loadkeys which can be used to set the locale for the vt keyboard, it doesn't affect input in folk which currnetly uses a hardcoded keymap.

The console-data package contains the Linux vt keymap files, for example /usr/share/keymaps/i386/qwerty/it.kmap.gz:

keymaps 0-2,4,6,8-9,12
include "linux-with-alt-and-altgr"
strings as usual
compose as usual for "iso-8859-1"
include "euro"

keycode   1 = Escape           Escape
        alt     keycode   1 = Meta_Escape
keycode   2 = one              exclam
        alt     keycode   2 = Meta_one
        shift alt keycode 2 = Meta_exclam
...
keycode  16 = q
keycode  17 = w
keycode  18 = e
        altgr keycode 18 = currency
keycode  19 = r
keycode  20 = t
keycode  21 = y
keycode  22 = u
keycode  23 = i
keycode  24 = o
keycode  25 = p

These could be parsed, or perhaps there is some existing C library or kernel input layer that can apply the keymap? Also, should the keymap setting be a global setting or perhaps be set on a per-keyboard basis (as part of the keyboard claim)?

@s-ol
Copy link
Contributor Author

s-ol commented May 15, 2024

These keymaps are also used by localectl. The libkeymap library can load both individual files or the kernel keymap (the one set by loadkeys).

@s-ol
Copy link
Contributor Author

s-ol commented May 15, 2024

Okay, I've been noodling around with the cffi for a bit now but I'm getting "strange results" (ex: 16 is Control_p according to lk_code_to_ksym in the us keymap). For reference, heres my attempt: keymap.tcl.txt

I've come to realize that it might be easier to load the keymaps into the kernel with loadkeys <name>, then dump them as a "complete table" with dumpkeys -kf. That's useful because it works everywhere you have a kernel console, rather then being tied to libkeymap which doesn't seem to be widely available as a prebuilt package. It prints something like:

keymaps 0-6,8-10,12-14
keycode  30 = +a               +A               +a               +A               Control_a        Control_a        Control_a        Meta_a           Meta_A           Meta_a           Meta_Control_a   Meta_Control_a   Meta_Control_a
keycode  31 = +s               +S               +s               +S               Control_s        Control_s        Control_s        Meta_s           Meta_S           Meta_s           Meta_Control_s   Meta_Control_s   Meta_Control_s
keycode  32 = +d               +D               +d               +D               Control_d        Control_d        Control_d        Meta_d           Meta_D           Meta_d           Meta_Control_d   Meta_Control_d   Meta_Control_d

Each column represents one set of modifers, but I'm not sure how you're supposed to know which is which, it starts out looking like a bitfield but gets kinda wonky towards the end?

@s-ol
Copy link
Contributor Author

s-ol commented May 16, 2024

from man 5 keymaps: the keymaps line fixes the bitfield logic

   First of all, you can give a map specification line, of the form

          keymaps 0-2,4-5,8,12

   to indicate that the lines of the keymap will not specify all 256 columns, but only the indicated ones. (In  the  example:  only
   the  plain,  Shift,  AltGr,  Control, Control+Shift, Alt and Control+Alt maps, that is, 7 columns instead of 256.)  When no such
   line is given, the keymaps 0-M will be defined, where M+1 is the maximum number of entries found in any definition line.

and, from the same man, here's the modifier table:

  Which of the actions bound to a given key is taken when it is pressed depends on what modifiers are in effect  at  that  moment.
   The  keyboard  driver  supports  9  modifiers.  These modifiers are labeled (completely arbitrarily) Shift, AltGr, Control, Alt,
   ShiftL, ShiftR, CtrlL, CtrlR and CapsShift.  Each of these modifiers has an associated weight of power of two according  to  the
   following table:

          modifier            weight

          Shift                  1
          AltGr                  2
          Control                4
          Alt                    8
          ShiftL                16
          ShiftR                32
          CtrlL                 64
          CtrlR                128
          CapsShift            256

The bit-indices are in linux/keyboard.h as KG_SHIFT, KG_CTRL, ...

lk_dump_keys(ctx, stdout, LK_SHAPE_FULL_TABLE, 0) outputs the same format as dumpkeys -kf, but I was also missing a call to lk_add_constants to complete the loaded data.

Here's updated code that loads a keymap by basename and can look up scancode + modifier-index pairs: keymap.tcl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant