Smart layout through 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’s more convenient to bind them to specific keyboard shortcuts instead of holding another extra keyboard layout. Yes, we can write them through Unicode characters, but, firstly, you need to remember the character codes, and secondly, it does not always work (described in the previous article). ComposeKey comes to the rescue, a mechanism in Linux for typing unprintable characters.

    How does it work?


    There is a ComposeKey key, when pressed and a combination of other keys, a symbol is displayed. You can configure this key from the console (for example, setxkbmap -option compose:rwinsets 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 declare your own combinations. In order, for example, to be ComposeKey + Ы displayed І, and to be ComposeKey + ъ displayed ї. And simple to remember, and use will not be additional problems.

    To start, let's solve the problem with the Gnome. He has all the combinations hard coded into the code for compatibility on all locales, so we won’t be able to 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". We write it in ~ / .bashrc (if necessary 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.

    Source Key Name

    The notorious xev utility comes to the rescue, which displays all the X events. We start, press a couple of keys in the Russian layout, we look at the output. It will turn out like this: We look at the line , this one is the name of the key.

    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

    state 0x2000, keycode 58 (keysym 0x6d8, Cyrillic_softsign), same_screen YESCyrillic_softsign

    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 the character and its code.

    But what about an example?


    For example, take a combination so that ComposeKey + ыi is displayed. Find the name of the "s" key. xevsays the character is called Cyrillic_yeru. Further, we find in the unicode table the symbol "i" and its code: U0456. The line for the description of the combination will look like this: Multi_key is the ComposeKey. I post my version of the config : PS After the changes, do not forget to restart the X-server
    : "i" U0456



    ~/.XCompose

    include "/usr/share/X11/locale/en_US.UTF-8/Compose"
    : "є" U0454
    : "Є" U0404
    : "i" U0456
    : "І" U0406
    : "ґ" U0491
    : "Ґ" U0490
    : "ї" U0457
    : "Ї" U0407



    Also popular now: