Many people might already be knowing this, for example people who use custom keyboard layouts, or people using different keyboard layouts, other than US, which most manufacturers and operating system and desktop environmnets use as default.

Most of my applications use vi like bindings, so pressing shift + ; to get : was a bit annoying, and so i was trying to find a way to swap them, and while doing so, I added most of greek alphabet, makes my technical writing a bit more easier (instead of doing $alpha$, I can do alt + a to get $α$), If you use TeX, then you can use #XeTeX to enter unicode, I use Typst, so I can directly use them, and they are used appropriately in text and equation mode. This also is helpful if your notes system does not have some math mode rendering (like plain markdown, without any katex).

If you are multilingual, but don’t write much in the other language, this approach works well, if you write comparable amount in both languages, then you should consider setting a keyboard shortcut in you DE/WM config to switch the keyboard layouts

The following procedure is linux specific (or maybe other posix systems too, if they use xkb to manage keyboard stuff (this also works on wayland)), but I am sure windows and macos will have something similar (though i have not bothered to check for it, sorry for that). This does not work as a daemon sitting in between, this is using the standard way to modiify keyboard layout.

You can start by making a file like the following, and you can start with /usr/share/X11/xkb/symbols/us (or the base language of your choice, for most european language layouts, base is /usr/share/X11/xkb/symbols/latin). You have to save it in the /usr/share/X11/xkb/symbols/ directory (in my case, my original file is in config dir, and I have symlinked it to /usr/share/X11/xkb/symbols/us-custom). For list of valid symbols (most of unicode, the thing we want is the correct names) please refer /usr/include/X11/keysymdef.h. You can choose what modifier you want to use with include "level3(ralt_switch)" - I am using right alt as the third modifier, so to get the third layer, I go alt + <key>, for 4th layer, mod3 + shift + <key>. Then you can set to use this custom symbol map in your DE/WM config, in my case I have added xkb_layout "us-custom" in my sway config (for input keyboard).

// parent system is US, with a lot of greek sybols appended, and some more
// ; -> :, : -> ; - mostly for vim modes (easier to do : now)
default partial alphanumeric_keys modifier_keys
xkb_symbols "basic" {
    name[Group1]= "English US - Custom"; 
    include "level3(ralt_switch)"

    key <TLDE> {[ grave, asciitilde ]};
    key <AE01> {[ 1, exclam, exclamdown ]};
    key <AE02> {[ 2, at ]};
    key <AE03> {[ 3, numbersign, Greek_pi ]};
    key <AE04> {[ 4, dollar, trademark ]};
    key <AE05> {[ 5, percent ]};
    key <AE06> {[ 6, asciicircum ]};
    key <AE07> {[ 7, ampersand ]};
    key <AE08> {[ 8, asterisk, Greek_PI ]};
    key <AE09> {[ 9, parenleft ]};
    key <AE10> {[ 0, parenright, degree, schwa ]};
    key <AE11> {[ minus, underscore ]};
    key <AE12> {[ equal, plus, plusminus ]};

    key <AD01> {[ q, Q ]};
    key <AD02> {[ w, W ]};
    key <AD03> {[ e, E, Greek_epsilon, eacute ]};
    key <AD04> {[ r, R, Greek_rho ]};
    key <AD05> {[ t, T, Greek_theta, Greek_tau ]};
    key <AD06> {[ y, Y ]};
    key <AD07> {[ u, U ]};
    key <AD08> {[ i, I, integral ]};
    key <AD09> {[ o, O, Greek_omega, Greek_OMEGA ]};
    key <AD10> {[ p, P, Greek_phi, Greek_psi ]};
    key <AD11> {[ bracketleft, braceleft ]};
    key <AD12> {[ bracketright, braceright ]};

    key <AC01> {[ a, A, Greek_alpha, ae ]};
    key <AC02> {[ s, S, Greek_sigma, Greek_SIGMA ]};
    key <AC03> {[ d, D, Greek_delta, Greek_DELTA ]};
    key <AC04> {[ f, F ]};
    key <AC05> {[ g, G, Greek_gamma, Greek_GAMMA ]};
    key <AC06> {[ h, H, Greek_eta ]};
    key <AC07> {[ j, J ]};
    key <AC08> {[ k, K, Greek_kappa ]};
    key <AC09> {[ l, L, Greek_lambda, Greek_LAMBDA ]};
    key <AC10> {[ colon, semicolon ]};
    key <AC11> {[ apostrophe, quotedbl ]};
    key <BKSL> {[ backslash, bar ]};

    key <AB01> {[ z, Z, Greek_zeta ]};
    key <AB02> {[ x, X, Greek_xi, Greek_XI ]};
    key <AB03> {[ c, C, Greek_chi ]};
    key <AB04> {[ v, V ]};
    key <AB05> {[ b, B, Greek_beta ]};
    key <AB06> {[ n, N, Greek_nu, ntilde ]};
    key <AB07> {[ m, M, mu ]};
    key <AB08> {[ comma, less ]};
    key <AB09> {[ period, greater ]};
    key <AB10> {[ slash, question, questiondown ]};
};

  • Ordoviz@lemmy.ml
    link
    fedilink
    arrow-up
    2
    ·
    3 days ago

    You can also put this in ~/.config/xkb/symbols/us-custom (create the parent directories if necessary) and set the environment variable XKB_DEFAULT_LAYOUT=us-custom. This works in most Wayland compositors, including river and niri. For Hyprland, you can add this to your config file:

    input {
    	kb_layout = us-custom
    }
    

    If you use GNOME, run

    gsettings set org.gnome.desktop.input-sources mru-sources "[('xkb', 'us-custom')]"
    gsettings set org.gnome.desktop.input-sources sources "[('xkb', 'us-custom')]"
    

    and restart GNOME.


    This is my keyboard layout (I explained some bits of it here):

    default partial alphanumeric_keys
    xkb_symbols "basic" {
    include "us(de_se_fi)" // Umlauts (ä, ö, ü) and €
    
    include "level5(rctrl_switch)"
    
    key.type[Group1] = "EIGHT_LEVEL";
    
    // Number row
    key <TLDE> {[ grave,      asciitilde,  dead_grave,           dead_tilde                                       ]};
    key <AE01> {[ 1,          exclam,      onesuperior,          U2081                                            ]}; // x₁
    key <AE02> {[ 2,          at,          twosuperior,          U2082                                            ]}; // x₂
    key <AE03> {[ 3,          numbersign,  threesuperior,        U2083                                            ]}; // x₃
    key <AE06> {[ 6,          asciicircum, dead_circumflex,      dead_caron                                       ]};
    key <AE08> {[ 8,          asterisk,    enfilledcircbullet,   U22C5,               infinity                    ]}; // dot operator
    key <AE10> {[ 0,          parenright,  NoSymbol,             NoSymbol                                         ]};
    key <AE11> {[ minus,      underscore,  endash,               emdash,              U207B                       ]}; // x⁻
    key <AE12> {[ equal,      plus,        notequal,             approxeq                                         ]};
    
    // Top row
    key <AD01> {[ q,          Q,           NoSymbol,             U211A,               NoSymbol,      NoSymbol     ]}; // ℚ
    key <AD02> {[ w,          W,           NoSymbol,             NoSymbol,            Greek_omega,   Greek_OMEGA  ]};
    key <AD03> {[ e,          E,           NoSymbol,             NoSymbol,            Greek_epsilon, U2203        ]}; // ∃
    key <AD04> {[ r,          R,           NoSymbol,             U211D,               Greek_rho,     U03F1        ]}; // ℝ ϱ
    key <AD05> {[ t,          T,           U03D1,                Greek_tau,           Greek_theta,   Greek_THETA  ]}; // ϑ
    key <AD08> {[ i,          I,           U21d2,                U21d4,               Greek_iota,    integral     ]}; // ⇒ ⇔
    key <AD09> {[ o,          O,           NoSymbol,             NoSymbol,            Greek_omega,   Greek_OMEGA  ]};
    key <AD10> {[ p,          P,           section,              paragraph,           Greek_pi,      Greek_PI     ]};
    
    // Home row
    key <AC01> {[ a,          A,           NoSymbol,             NoSymbol,            Greek_alpha,   U2200        ]}; // ∀
    key <AC02> {[ s,          S,           NoSymbol,             NoSymbol,            Greek_sigma,   Greek_SIGMA  ]};
    key <AC03> {[ d,          D,           NoSymbol,             NoSymbol,            Greek_delta,   Greek_DELTA  ]};
    key <AC04> {[ f,          F,           NoSymbol,             NoSymbol,            Greek_phi,     Greek_PHI    ]};
    key <AC05> {[ g,          G,           degree,               NoSymbol,            Greek_gamma,   Greek_GAMMA  ]};
    key <AC06> {[ h,          H,           U2190,                NoSymbol,            Greek_eta,     U2225        ]}; // ← ∥
    key <AC07> {[ j,          J,           U2193,                NoSymbol,            NoSymbol,      NoSymbol     ]}; // ↓
    key <AC08> {[ k,          K,           U2191,                NoSymbol,            Greek_kappa,   U03F0        ]}; // ↑ ϰ
    key <AC09> {[ l,          L,           U2192,                NoSymbol,            Greek_lambda,  Greek_LAMBDA ]}; // →
    key <AC10> {[ semicolon,  colon,       dead_diaeresis,       NoSymbol,            NoSymbol,      NoSymbol     ]};
    key <AC11> {[ apostrophe, quotedbl,    rightsinglequotemark, NoSymbol,            NoSymbol,      NoSymbol     ]};
    key <AC12> {[ backslash,  bar,         U2500,                U2502,               NoSymbol,      NoSymbol     ]}; // box drawing
    
    // Bottom row
    key <AB01> {[ z,          Z,           NoSymbol,             U2124,               Greek_zeta,    U2220        ]}; // ℤ ∠
    key <AB02> {[ x,          X,           multiply,             NoSymbol,            Greek_xi,      Greek_XI     ]};
    key <AB03> {[ c,          C,           NoSymbol,             U2102,               Greek_chi,     copyright    ]}; // ℂ
    key <AB04> {[ v,          V,           doublelowquotemark,   singlelowquotemark,  Greek_psi,     Greek_PSI    ]};
    key <AB05> {[ b,          B,           leftdoublequotemark,  leftsinglequotemark, Greek_beta,    NoSymbol     ]};
    key <AB06> {[ n,          N,           rightdoublequotemark, rightsinglequotemark,Greek_nu,      U2115        ]}; // ℕ
    key <AB07> {[ m,          M,           U2212,                plusminus,           Greek_mu,      NoSymbol     ]}; // minus
    key <AB08> {[ comma,      less,        dead_cedilla,         NoSymbol,            U27e8,         NoSymbol     ]}; // ⟨
    key <AB09> {[ period,     greater,     ellipsis,             dead_abovedot,       U27e9,         NoSymbol     ]}; // ⟩
    key <AB10> {[ slash,      question,    division,             questiondown,        NoSymbol,      NoSymbol     ]};
    };
    

    GNOME Settings shows a visual preview of the first four layers:

    See also this writeup by Leon Plickat.

    • sgaOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      3 days ago

      thank you, but what was the most amazing thing for me is a 5 year old post on lemmy

  • Victor@lemmy.world
    link
    fedilink
    arrow-up
    2
    ·
    edit-2
    3 days ago

    Also have a look at Kanata to enable your keyboard to have multiple custom layers and other functionality like tap-dancing, even if you don’t have a custom keyboard. I tried it, it works pretty well.

    • sgaOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      3 days ago

      sorry i am unware of it. I looked up, and from github page they are are remapper. They are great too, but they are a additional thing to install and run. For layers, you can already use keyboard shortcut to switch between predefined layouts in most setups, but thanks

      • Victor@lemmy.world
        link
        fedilink
        arrow-up
        2
        ·
        1 day ago

        Kanata is not only a remapper, and layers are not used only to switch language layouts. It is much, much more powerful than that. And with a much simpler configuration than what you have described.

        The extra thing to install is a lot less of a hassle than learning the config you have posted. That’s my personal opinion. 😁

        You found your solution that works for you. That’s great. Kanata is a tip for people who want even more power from their regular keyboard than what is possible without it. If you don’t need this power, don’t install. 👍

        • sgaOP
          link
          fedilink
          English
          arrow-up
          1
          ·
          1 day ago

          well i would like to understand what can you do with it. Also, simplicity is in the eye of beholder