I recently switched to Hyprland on my laptop and was able to set it up as I like, but I struggle hard to set up keybinds to simply print different characters when pressing certain key combinations.

For example, one small snippet from my .Xmodmap (there are more in this file but that’s enough for a minimal working example)

keycode 108 = Mode_switch
keycode 38 = a A adiaeresis Adiaeresis

This allows me to press the A key in combination with the right Alt key to print an ä or an Ä when shift is pressed, to.

wtype and built-in key binding

After some research I found wtype which allows me to write arbitrary text when called with the parameters.

After I learned that Hyprland (or Wayland) does not distinguish between Alt_R and Alt_L (they’re shown as Alt_R and Alt_L in wev with different keysyms, so they’re clearly two different keys) and I accepted it, I just found out that this tool only works when being in a terminal emulator and not in a GUI application so this tool is useless for me.

keyd

Then I tried keyd. After setting it up and adding my user to the needed groups and starting the service and trying to figure out how to actually define keymaps I was able to send something when pressing a defined key combination.

But: Nothing else than ASCII.

The dev thinks it’s a Chromium problem based on this issue but it actually isn’t. I wasn’t able to send an ä to ANY application, no matter if GUI or terminal or Qutebrowser.

Since there is basically no online resources or user community for this tool, I cannot find any usable information on this issue except the unrelated Chrome reference and thus I removed it again because I cannot use it for what I want to use it for.

xkb

For whatever reason Wayland (or Hyprland) uses certain parts of the X keyboard extension, so I also tried this one.

Despite being absurdly complex and annoying to setup I was able to configure a user based keyboard variant using user-based symbols. From what I’ve taken from various sites my config should do nothing more than remapping Alt_R to ISO_Layer3_Shift just for testing purposes.

But all I achieved was reproducibly crashing Hyprland when setting it up to actually use said keyboard variant and there seems to be no log file.

yeah, that’s where we are

Again, it’s not about the umlauts, and not about the German keyboard layout, and not about switching lkayouts on-the-fly, it’s just to demonstrate what I mean. You can replace ä with any other character you want.

After a long night of trying out to have the Xmodmap functionality in Wayland using Hyprland as compositor I ended up with not being successful.

I give up for now.

Maybe one day there will be an actually working solution requiring nothing more than two lines in a file.

  • mranderson17@infosec.pub
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    1 year ago

    Here’s what I did for sway, though I agree it took me a while to arrive at this solution:

    In the file .config/sway/config:

    input "type:keyboard" {
      # Use the following to remap single keys.
      # Weird letter codes are in /usr/share/X11/xkb/keycodes/evdev
      # Keysym names are in /usr/include/X11/keysymdef.h
      # xkb moded layout is in .xkb/symbols/qwerty_prtsc_to_menu in this repo
      #
      xkb_layout "qwerty_prtsc_to_menu"
      xkb_options caps:super
      repeat_delay 220
      repeat_rate 70
    }
    

    in the file .xkb/symbols/qwerty_prtsc_to_menu:

    default partial alphanumeric_keys
    xkb_symbols "basic" {
      include "us"
      replace key "replacewithlessthansymbol"PRSC"replacewithgreaterthansymbol" { [ Menu ] };
    };
    

    I’m pretty sure you can do xkb_layout with input device matching in hyprland though I stopped using hyprland a while back.

    Some things like caps:super already exist in xkb_options, but less common ones require manually creating a layout. I found an xkb doc describing all these when I was working on this but I can’t find it now. If I manage to locate it I’ll update this comment.

    EDIT: For the qwerty_prtsc_to_menu file above it’s suppose to be the actual less than and greater than symbols however lemmy’s code formatting is removing them when I save the comment, sorry about that

    EDIT2: I didn’t realize that you wanted a momentary layer, so this solution will not work for you exactly. However I believe this is possible with keymap switching like described here https://wiki.archlinux.org/title/sway#Keymap in addition to what I have suggested above.

    • 𝘋𝘪𝘳𝘬OP
      link
      fedilink
      arrow-up
      2
      ·
      1 year ago

      I didn’t realize that you wanted a momentary layer

      Thanks anyways. I think I’ll go the xkb route in the end, even if it is the most complex and annoying one. But at least it works on kernel level and is independent of the display manager or the applications.

      It just seems to be so far out of anything that I couldn’t really find any documentation regarding this. Instead there are hundreds of tutorials on how to permanently remap Caps Lock to Esc or other funny things. But a simple “press key Alt_R+X to get character Y” seems to be something no-one does and neither Wayland nor Hyperland have an option for that.

      I could easily switch layouts, yes. I can even add as many as I want and cycle through them with Hyprland functionality and displaying the current layout in Waybar. But that’s totally not what I want. I have an US layout keyboard and want to keep the layout at all time but randomly press Alt_R+something to do write something.

      I have Alt_R+Numbers to do ₁₂₃₄₅₆₇₈₉₀ or ¹²³⁴⁵⁶⁷⁸⁹⁰ with Alt_R+Shift+Numbers. And inner and outer quotation marks with Alt_R+z, x, c, v for German „“, ‚‘ and in combination with Shift for English “”, ‘’. Or the rarely used capital ß with Alt_R+Shift+S: . and some others.

      Just switching the keyboard layout from US to German sometimes to have umlauts isn’t the point at all :)

      … and Xmodmap does exactly that and is incredibly easy to set up and works out of the box in all applications and frameworks and types of inputs that run on X11.