Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can this be used from a local xkb dir? #1

Open
infokiller opened this issue Dec 27, 2015 · 14 comments
Open

Can this be used from a local xkb dir? #1

infokiller opened this issue Dec 27, 2015 · 14 comments

Comments

@infokiller
Copy link

I saw in the setxkb.sh script that it says NOTE: It now works with local xkb(-mod) dir, but I couldn't make it work. Can you please provide some guidance?

Thanks a lot!

@DreymaR
Copy link
Owner

DreymaR commented Dec 28, 2015

Hi! The setxkbmap command can take a path to an xkb directory; my setxkb.sh script does this simply by running setxkbmap from the specified directory (which can be set by the '-d {path}' switch). But don't use the provided xkb files alone as they aren't a complete xkb directory! You should install to your preferred local path first using my install script with the '-i {path}' switch. Make sure you have write privileges in the target path. And follow the instructions closely – both my scripts use bash for instance.

Is that helpful?

@infokiller
Copy link
Author

Hi!
Will running setxkbmap from a directory with xkb files use the directory contents? in general, do you know how setxkbmap searches configuration files?
The reason I want to use a local xkb dir is that I have a git repo with all my configuration files (vimrc etc), and this repo is used in a few machines. I want to add the xkb config to this repo. Using local files is much easier for managing it because then when updating a machine I can just git pull the changes without the need to write to system files.

BTW, yesterday I installed these files to two of my machines and it works great! Thanks a lot for this awesome work. Up until now I implemented something similar using xbindkeys, but using xkb has many advantages over xbindkeys.

@infokiller
Copy link
Author

Also, it would be great if I could chat with you about a few things:

  • I'm considering moving to Colemak
  • I don't know how to implement some of the stuff I have in xbindkeys using xkb and wanted to verify whether it can be done with someone who knows xkb config better than me

If you're cool with that then let me know what's the best way to contact you. Sorry for doing this conversation in a github issue but there's no private messaging in github.

@DreymaR
Copy link
Owner

DreymaR commented Dec 28, 2015

Hi! Come to Colemak, we have... ummm, not cookies but an awesome layout!
:-) I use WideAngle Colemak-DH, mind you, which is a set of minor tweaks.
Have you read my Big Bag of Tricks topic at the Colemak forum yet?

If I reply to this email, you'll be able to reply back directly I hope. [nope!]

The setxkbmap will look for a workable set of xkb files in the current directory and failing that, in the default system X11 path. So changing to a (complete) xkb directory and running setxkbmap does the trick.

best,
Øystein "DreymaR"
On Dec 28, 2015 12:49 PM, "infokiller" [email protected] wrote:

Also, it would be great if I could chat with you about a few things:

  • I'm considering moving to Colemak
  • I don't know how to implement some of the stuff I have in xbindkeys
    using xkb and wanted to verify whether it can be done with someone who
    knows xkb config better than me

If you're cool with that then let me know what's the best way to contact
you. Sorry for doing this conversation in a github issue but there's no
private messaging in github.


Reply to this email directly or view it on GitHub
#1 (comment)
.

@infokiller
Copy link
Author

Yes, that's how I found this repo, awesome work 👍
I can't reply directly... a privacy feature I guess :)
Anyway, I can send you a message in the Colemak forum, does that work for you?

@DreymaR
Copy link
Owner

DreymaR commented Dec 29, 2015

Of course, anytime!

I'm still a bit new to the GitHub thing, and never seem to find the time to
learn it properly... yet.

Ø
On Dec 28, 2015 4:03 PM, "infokiller" [email protected] wrote:

Yes, that's how I found this repo, awesome work [image: 👍]
I can't reply directly... a privacy feature I guess :)
Anyway, I can send you a message in the Colemak forum, does that work for
you?


Reply to this email directly or view it on GitHub
#1 (comment)
.

@infokiller
Copy link
Author

Thanks a lot Øystein!
I sent an email to your Colemak forum user, I hope it arrives!

@DreymaR
Copy link
Owner

DreymaR commented Jun 17, 2016

So, at the moment it seems that setxkbmap does NOT handle local files? The default is then to use the system (X11 dir) install. Sorry about that.

@neeasade
Copy link

I was able to accomplish this with this post: https://unix.stackexchange.com/questions/397716/custom-keyboard-layout-without-root

made that tweak to setxkb and some small changes to use a hardcoded $HOME dir path, and it appears good 👍

@birdspider
Copy link

I was able to make it work locally (in my case right out of the git clone) except I couldn't get the Extend to work on caps or any other key

# in the repo, PWD=the repo root dir

setxkbmap -I"$PWD/xkb-data_xmod/xkb" \
  -model 'pc104wide-qu' \
  -keycodes 'evdev(pc104wide-qu)' \
  -layout us \
  -variant cmk_ed_us \
  -option misc:extend,lv5:caps_switch_lock \
  -print | xkbcomp -I"$PWD/xkb-data_xmod/xkb" - "$DISPLAY"

everything seemed to work, even wide mode, except Extend which would behave as normal CapsLock.

any idea why that would be? or what to do to enable the Extend functionality ?


PS:
I also discovered that xkbcomp -I -I"$PWD/xkb-data_xmod/xkb" (double -I, checked with strace, see man xkbcomp) would force xkbcomp to exclusively look in the specified dir (that is - ignoring system dirs).

Which in turn could not load some files (symbols/complete if I remember correctly). May be useful for some usecase.

@infokiller
Copy link
Author

@birdspider I don't have a solution for you, but in case it's useful for anyone, what I'm doing for some time now is running xkbcomp keymap.xkb "$DISPLAY" where keymap.xkb is the full keymap (self contained, no includes) which I track in a git repo. I find this easier than using xkbcomp with includes.

@birdspider
Copy link

birdspider commented Apr 13, 2021

@infokiller

I don't have a solution for you,...

but I have :) - somewhat

Solution

full local loading script (beware that xkbcomp and setxkbmap handle their respective -I different, setxkbmap is fine with spaces after -I, xkbcomp is not), (tee /dev/tty additionaly just also prints out the piped xkb_keymap)

#!/usr/bin/env sh

# in the repo, PWD=the repo root dir
XKB_ROOT=./xkb-data_xmod/xkb/
XKB_RULES=`pwd`/xkb-data_xmod/xkb/rules/evdev
setxkbmap \
  -rules "${XKB_RULES}" \
  -I "${XKB_ROOT}" \
  -model 'pc104wide-qu' \
  -keycodes 'evdev(pc104wide-qu)' \
  -layout 'us' \
  -variant 'cmk_ed_us' \
  -option 'misc:extend,lv5:caps_switch_lock' \
  -print | tee /dev/tty | xkbcomp -I"${XKB_ROOT}" - "$DISPLAY"

Analysis

it seems that setxkbmap ... -option misc:extend,lv5:caps_switch_lock does not produce the correct xkb symbols, instead I get:

xkb_keymap {
	xkb_keycodes  { include "evdev(pc104wide-qu)"	};
	xkb_types     { include "complete"	};
	xkb_compat    { include "complete"	};
	xkb_symbols   { include "pc+us(cmk_ed_us)+inet(evdev)"};
	xkb_geometry  { include "pc(pc104)"	};
};

If I manually add +level5(caps_switch_lock)+extend(basic) to xkb_symbols like so:

xkb_keymap {
	xkb_keycodes  { include "evdev(pc104wide-qu)"	};
	xkb_types     { include "complete"	};
	xkb_compat    { include "complete"	};
	xkb_symbols   { include "pc+us(cmk_ed_us)+level5(caps_switch_lock)+extend(basic)+inet(evdev)"};
	xkb_geometry  { include "pc(pc104)"	};
};

At least Extend/Pg{Up,Down} seems to work


After strace-ing setxkbd, I finally suceeded by excplicitly telling it where the rules are, otherwise it would use the sys-evdev rules, which lack the options.

setxkbmap \
  -rules $PWD/xkb-data_xmod/xkb/rules/evdev \
  -I "./xkb-data_xmod/xkb/" \
  -model 'pc104wide-qu' \
  -keycodes 'evdev(pc104wide-qu)' \
  -layout 'us' -variant 'cmk_ed_us' \
  -option 'misc:extend,lv5:caps_switch_lock' \
  -print

#got me
xkb_keymap {
	xkb_keycodes  { include "evdev(pc104wide-qu)"	};
	xkb_types     { include "complete"	};
	xkb_compat    { include "complete"	};
	xkb_symbols   { include "pc+us(cmk_ed_us)+inet(evdev)+level5(caps_switch_lock)+extend(basic)"	};
	xkb_geometry  { include "pc(pc104wide-qu)"	};
};

#which in turn actually loads fine with `xkbcomp`

@DreymaR
Copy link
Owner

DreymaR commented Apr 15, 2021

Interesting! Also see #14 for a way that looks cleaner to me. I think that -rules evdev should suffice if you have the right dirs set? The initial problem with your option line should indeed be that setxkbmap doesn't find the local rules.

I'd think the idea of feeding xkbcomp the sequence -I -I$MYXKB -I/usr/share/X11/xkb is to ensure that it reads first my/your XKB dir and then the system's? But it shouldn't be strictly necessary since I haven't overriden any system rules, just added new ones.

@birdspider
Copy link

birdspider commented Apr 15, 2021

@DreymaR: I think that -rules evdev should suffice

well thats what I though initally but look at the strace --trace=file setxkbmap ... when calling it in the repos root dir.

-rules evdev

for some reason it expects rules/ to be in the current dir. In the end it finds it in /usr/share/X11/xkb/rules/

openat(AT_FDCWD, "./rules/evdev-C.lst", O_RDONLY) = -1 ENOENT (Datei oder Verzeichnis nicht gefunden)
openat(AT_FDCWD, "./rules/evdev.lst", O_RDONLY) = -1 ENOENT (Datei oder Verzeichnis nicht gefunden)
openat(AT_FDCWD, "/usr/share/X11/xkb/rules/evdev-C.lst", O_RDONLY) = -1 ENOENT (Datei oder Verzeichnis nicht gefunden)
openat(AT_FDCWD, "/usr/share/X11/xkb/rules/evdev.lst", O_RDONLY) = 4
newfstatat(4, "", {st_mode=S_IFREG|0644, st_size=44667, ...}, AT_EMPTY_PATH) = 0
openat(AT_FDCWD, "/usr/share/X11/xkb/rules/evdev-C", O_RDONLY) = -1 ENOENT (Datei oder Verzeichnis nicht gefunden)
openat(AT_FDCWD, "/usr/share/X11/xkb/rules/evdev", O_RDONLY) = 4

that might not be an issue when actually being inside of xkb-data_xmod/xkb/ where rules/ resides - haven't testet that.

EDIT: which is exactly what happens in #14 (cd into the xkb/ dir first)

vs.

-rules $PWD/xkb-data_xmod/xkb/rules/evdev

from the getgo looks and finds them in ./xkb-data_xmod/xkb/rules/

openat(AT_FDCWD, "/home/birdspider/repos/BigBagKbdTrixXKB/xkb-data_xmod/xkb/rules/evdev-C.lst",O_RDONLY) = -1 ENOENT (Datei oder Verzeichnis nicht gefunden)
openat(AT_FDCWD, "/home/birdspider/repos/BigBagKbdTrixXKB/xkb-data_xmod/xkb/rules/evdev.lst", O_RDONLY) = 4
newfstatat(4, "", {st_mode=S_IFREG|0644, st_size=47351, ...}, AT_EMPTY_PATH) = 0
openat(AT_FDCWD, "/home/birdspider/repos/BigBagKbdTrixXKB/xkb-data_xmod/xkb/rules/evdev-C", O_RDONLY) = -1 ENOENT (Datei oder Verzeichnis nicht gefunden)
openat(AT_FDCWD, "/home/birdspider/repos/BigBagKbdTrixXKB/xkb-data_xmod/xkb/rules/evdev", O_RDONLY) = 4

also the order of -I and -rules does not seem to matter for setxkbmap

double -I for xkbcomp

It works fine with -I$MYXKB, I was simply testing/debugging it with only -I$MYXKB be means of -I -I$MYXKB but it needs the systems /usr/share/X11/xkb/types/complete or else:

Can't find file "complete" for types include

@DreymaR: But it shouldn't be strictly necessary since I haven't overridden any system rules

it's not necessary, I do not have any complains - everything works as good as it can under the limits of setxkbmap and xkbcomp
I just wanted to report my findings.

-model

As an aside, sadly setxkbmap only takes ONE model[keycodes], so switching per xkb's grp:ctrls_toggle between evdev[evdev+alias(querty)] and pc104wide-qu[pc104wide-qu] - which was my initial plan - remains a no-go

Ypnose pushed a commit to Ypnose/dotfiles that referenced this issue Sep 16, 2023
used. It's a pain to deal with custom keymaps installed outside
/usr/share/X11/xkb/. Switch back to xkbcomp.

https://gitlab.freedesktop.org/xorg/app/setxkbmap/-/issues/5
DreymaR/BigBagKbdTrixXKB#1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants