You are not logged in.

#1 2021-03-01 00:13:52

r1amu
Member
Registered: 2020-02-24
Posts: 16

[SOLVED] How to load a custom keymap with xinit?

So, after some struggles I managed to make a custom keymap which I have saved as ~/.Xkeymap and I can load it "by hand" with xkbcomp .Xkeymap $DISPLAY

Now the problem is that I want to load it on start with xinit (if possible), the problem is that this way: test -f ~/.Xkeymap && xkbcomp ~/.Xkeymap $DISPLAY  which I got from arch wiki doesn't work. The problem is that it runs before the $DISPLAY var is set. I will try it with sleep and report back but it seems really hacky.

Here is my ~/.xinitrc:

#!/bin/sh

xrdb -load $HOME/.Xresources &
[ -f ~/.Xkeymap ] && xkbcomp ~/.Xkeymap $DISPLAY &

session=${1:-gnome}

case $session in
    "gn"|"gnome")
        export XDG_SESSION_TYPE=x11
        export GDK_BACKEND=x11
        exec gnome-session
    ;;
    "bsp"|"bspwm")
        exec bspwm
    ;;
    *) exec "$1" ;;
esac

* Adding sleep 1 did work but it really feels hacky...

Last edited by r1amu (2021-03-02 17:14:37)

Offline

#2 2021-03-01 00:34:00

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 25,343

Re: [SOLVED] How to load a custom keymap with xinit?

You should not background either of these two commands (... remove the trailing &) as they are intended to modify specifics of the current xorg server that shouldn't be done concurrently.

In general your .xinitrc is broken and doesn't include a few necessary includes to make sure the environment is properly setup, copy the template from the system directory and add your modifications after, note the blue notes in https://wiki.archlinux.org/index.php/Xinit#xinitrc

Last edited by V1del (2021-03-01 00:58:21)

Offline

#3 2021-03-01 12:19:34

r1amu
Member
Registered: 2020-02-24
Posts: 16

Re: [SOLVED] How to load a custom keymap with xinit?

Thanks for the reply V1del. I had a look at the default xinitrc and added this if statement as that was the only thing that was really missing:

if [ -d /etc/X11/xinit/xinitrc.d ]
then
    for f in /etc/X11/xinit/xinitrc.d/?*.sh
    do
        [ -x "$f" ] && source "$f"
    done
    unset f
fi

(I checked and I do not have default .Xresources or .Xmodmap)

I also removed the the backgrounding of both xrdb and xkbcomp, xrdb works fine but xkbcomp now doesn't load at all even with sleep

Offline

#4 2021-03-01 13:04:32

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,552

Re: [SOLVED] How to load a custom keymap with xinit?

The problem is that it runs before the $DISPLAY var is set.

Are you positive about that? W/o $DISPLAY xrdb should™ fail just as much.
I'd rather suspect that the session simply overrides your keymap - notably yor gnome session.

Does it work if you only "exec xterm"?

Offline

#5 2021-03-01 14:11:02

r1amu
Member
Registered: 2020-02-24
Posts: 16

Re: [SOLVED] How to load a custom keymap with xinit?

So I tested few things and it's kinda weird.

If I background both xrdb and xkbcomp with  & and add a delay with sleep 1 to xkbcomp they both work in bspwm. If I use the same setup with xterm only xkbcomp gets loaded.

If I remove the backgrounding and the delay then it works as expected with xterm, but when launching bspwm only xrdb loads as it should.

Here is what I launch in my bspwmrc:

#!/bin/sh

# Autostart
sxhkd &
setxkbmap -option "caps:escape" \
          -option "altwin:menu_win" \
          -option "terminate:ctrl_alt_bksp" &
xsetroot -cursor_name left_ptr &
xset r rate 250 60 &
wlp -r & # Wallpaper script
unclutter &
picom -b &
hinf & # Show notification with some info

Offline

#6 2021-03-01 14:13:36

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,552

Re: [SOLVED] How to load a custom keymap with xinit?

setxkbmap…
a) don't fork it (same for xsetroot and xset )
b) run it before sxhkd
c) try running xkbmap there and before sxhkd, but after setxkbmap

Offline

#7 2021-03-01 14:19:33

r1amu
Member
Registered: 2020-02-24
Posts: 16

Re: [SOLVED] How to load a custom keymap with xinit?

Thank you seth! now it works, at least in bspwm, any tips for Gnome?

Offline

#8 2021-03-01 14:21:04

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,552

Offline

#9 2021-03-01 14:22:08

r1amu
Member
Registered: 2020-02-24
Posts: 16

Re: [SOLVED] How to load a custom keymap with xinit?

Thank you!

Offline

#10 2021-03-01 14:52:56

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,552

Re: [SOLVED] How to load a custom keymap with xinit?

Please always remember to mark resolved threads by editing your initial posts subject - so others will know that there's no task left, but maybe a solution to find.
Thanks.

Offline

Board footer

Powered by FluxBB