šŸ“œ ā¬†ļø ā¬‡ļø

Smart layout via ComposeKey

This topic is a continuation of my previous one , where I described the problem with switching layouts, if there are three or more. In this topic I will talk about solving this problem through ComposeKey. In addition, ComposeKey is perfect for other purposes.

General information


Since, in alternative layouts, we need only a few rarely used characters, so it is more convenient to link them to specific shortcut keys instead of holding one more extra keyboard layout. Yes, we can write them through Unicode characters, but, first, we need to memorize the character codes, and second, it does not always work (described in the previous article). ComposeKey, a mechanism for non-printable characters in Linux, comes to the rescue.

How does it work?


There is a ComposeKey key, while clamping and a combination of other keys, the symbol is displayed. You can configure this key from the console (for example, setxkbmap -option compose:rwin sets the right Win key to ComposeKey), or from the graphical interface.

image
')

How are combinations available?


All combinations are available in the file /usr/share/X11/locale/CURRENT/Compose , where CURRENT is the current locale. All combinations are intuitive, the main thing is to understand the principle of their construction.

And how does this relate to layouts?


You have the opportunity to announce your own combinations. So that, for example, І displayed on ComposeKey + , and ї was ComposeKey + on ComposeKey + . And it is easy to remember and use will not be additional problems.

For starters, let's solve the problem with the Dwarf. He has all the combinations rigidly inscribed in the code for compatibility on all locales, so we can not change them. But we can override them with the standard Xwindow Input Method (XIM) . To do this, we need to set the environment variable GTK_IM_MODULE = "xim" . Let's write in ~ / .bashrc (if needed for all users, then in / etc / environment):

export GTK_IM_MODULE="xim"

In order to register a combination, we need to know the name of the source keys, the character itself and the unicode code of the character we need.

Name of source keys

The well-known utility xev, which displays all the events of X, comes to the rescue. We launch, we press couple of keys in the Russian layout, we watch an output. It turns out like this:

KeyPress event, serial 35, synthetic NO, window 0x4800001,
root 0x15a, subw 0x0, time 191545195, (-229,390), root:(776,413),
state 0x2000, keycode 58 (keysym 0x6d8, Cyrillic_softsign), same_screen YES,
XLookupString gives 2 bytes: (d1 8c) ""
XmbLookupString gives 2 bytes: (d1 8c) ""
XFilterEvent returns: False

KeyRelease event, serial 35, synthetic NO, window 0x4800001,
root 0x15a, subw 0x0, time 191545265, (-229,390), root:(776,413),
state 0x2000, keycode 58 (keysym 0x6d8, Cyrillic_softsign), same_screen YES,
XLookupString gives 2 bytes: (d1 8c) ""
XFilterEvent returns: False

We look at the line state 0x2000, keycode 58 (keysym 0x6d8, Cyrillic_softsign), same_screen YES , this Cyrillic_softsign is the name of the key.

Symbol and its unicode code

The symbol itself can be found in the symbol table, or copied from somewhere. To find out its unicode code, you need to find a table of unicode characters on the Internet, find a symbol and its code.

What about an example?


For example, let's take a combination, so that the symbol i is output by ComposeKey + . Find the name of the key "s". xev says the symbol is called Cyrillic_yeru . Next, we find the symbol ā€œiā€ and its code in the unicode table: U0456. The line for the description of the combination will look like this:
<Multi_key> <Cyrillic_yeru> : "i" U0456

Multi_key is ComposeKey.

I post my version of the config ~/.XCompose :

include "/usr/share/X11/locale/en_US.UTF-8/Compose"
<Multi_key> <Cyrillic_e> : "є" U0454
<Multi_key> <Cyrillic_E> : "Š„" U0404
<Multi_key> <Cyrillic_yeru> : "i" U0456
<Multi_key> <Cyrillic_YERU> : "І" U0406
<Multi_key> <Cyrillic_ghe> : "Ņ‘" U0491
<Multi_key> <Cyrillic_GHE> : "Ґ" U0490
<Multi_key> <Cyrillic_hardsign> : "ї" U0457
<Multi_key> <Cyrillic_HARDSIGN> : "Ї" U0407


PS After the changes do not forget to restart the X-server

Source: https://habr.com/ru/post/95845/


All Articles