Skip to content

[User tip] Key binding corner case explained. #56

@teika-kazura

Description

@teika-kazura

# This is a really niche subject, and it's y2025. I know.

In Sawfish, a key binding looks like "C-F3" or "H-p". Here "F3" and "p" are not what's printed on your keyboard, but a "keysym" in the X jargon. Whatever keyboard layout you have, it's "the key that emits p for you". For example when I typed $ xmodmap -pk, I got this:

....
26         0x002e (period) 0x003e (greater)        0x002e (period) 0x003e (greater)        0xffcc (F15)  0x0000 (NoSymbol)       0x0032 (2)
27         0x0070 (p)      0x0050 (P)      0x0070 (p)      0x0050 (P)      0x0033 (3)      0x0000 (NoSymbol)     0x0033 (3)
....

The leftmost numbers are keycodes, and keysyms are those in parentheses.

In fact, a key binding is internally done to a keycode, not to a keysym. Sawfish simply searches for one keycode that matches the keysym, and establishes a binding to it.

This is not a bug. For a user, it's better to see keysyms. Furthermore if you dynamically switch the keyboard layout, Sawfish keeps the original binding, as it should be. (But this means each time you start Sawfish, you should stick to one specific layout.) For X, you should specify which key (uniquely identified by its keycode) to receive event notifications. ("grab" is the jargon.)

Then there's some catches. For example if you have two keys that emits F2 and you bind something to F2, Sawfish binds to only one of your F2 keys. Or if you connect two keyboards with different layouts, it can be problematic, too.

One "bug" is that you can't specify a keycode to bind in Sawfish. Sawfish always uses keysyms. (Remember it's y2025. Don't ask others to implement this. If you really need it, please write a patch yourself and submit it.)


What complicates a little more is the modifier. This is too much detailed and you can ignore hereafter if you're not interested.

Modifiers are in contrast not directly specified by the key (keycode); this is because you often have two Shift and Control keys on your keyboard. Whichever shift you press, it should be the "S-" state.

# Then you can conjure up a really weird thing. You can bind a command to "Shift_L" by manually editing "~/.sawfish/custom". Then Sawfish will eat your shift key.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions