always use xkb and complain if only variant is set
This commit is contained in:
parent
874650ad22
commit
1b330dd7c1
2 changed files with 19 additions and 16 deletions
24
dotool.go
24
dotool.go
|
@ -221,25 +221,29 @@ func cutWord(s, word string) (string, bool) {
|
|||
func main() {
|
||||
var keymap *xkb.Keymap
|
||||
{
|
||||
names := xkb.RuleNames{
|
||||
Rules: "",
|
||||
Model: "",
|
||||
Layout: os.Getenv("DOTOOL_XKB_LAYOUT"),
|
||||
Variant: os.Getenv("DOTOOL_XKB_VARIANT"),
|
||||
Options: "",
|
||||
layout := os.Getenv("DOTOOL_XKB_LAYOUT")
|
||||
if layout == "" {
|
||||
layout = os.Getenv("XKB_DEFAULT_LAYOUT")
|
||||
}
|
||||
variant := os.Getenv("DOTOOL_XKB_VARIANT")
|
||||
if variant == "" {
|
||||
variant = os.Getenv("XKB_DEFAULT_VARIANT")
|
||||
}
|
||||
if variant != "" && layout == "" {
|
||||
// Otherwise xkbcommon just ignores the variant.
|
||||
fatal("you need to set $DOTOOL_XKB_LAYOUT or $XKB_DEFAULT_LAYOUT if the variant is set")
|
||||
}
|
||||
names := xkb.RuleNames{Layout: layout, Variant: variant}
|
||||
|
||||
ctx := xkb.ContextNew(xkb.ContextNoFlags)
|
||||
defer ctx.Unref()
|
||||
|
||||
keymap = ctx.KeymapNewFromNames(&names, xkb.KeymapCompileNoFlags)
|
||||
defer keymap.Unref()
|
||||
|
||||
if keymap == nil {
|
||||
fatal("failed to compile keymap")
|
||||
}
|
||||
defer keymap.Unref()
|
||||
|
||||
initKeys(keymap, names != xkb.RuleNames{})
|
||||
initKeys(keymap)
|
||||
}
|
||||
|
||||
{
|
||||
|
|
5
keys.go
5
keys.go
|
@ -27,6 +27,7 @@ var LinuxKeys = map[string]Chord{
|
|||
"ro": Chord{Key: uinput.KeyRo},
|
||||
"zenkakuhankaku": Chord{Key: uinput.KeyZenkakuhankaku},
|
||||
|
||||
// Potentially overwritten by initKeys()
|
||||
"esc": Chord{Key: uinput.KeyEsc},
|
||||
"1": Chord{Key: uinput.Key1},
|
||||
"2": Chord{Key: uinput.Key2},
|
||||
|
@ -495,20 +496,18 @@ func newChord(keymap *xkb.Keymap, mask, code uint32) Chord{
|
|||
}
|
||||
}
|
||||
|
||||
func initKeys(keymap *xkb.Keymap, linux bool) {
|
||||
func initKeys(keymap *xkb.Keymap) {
|
||||
maxCode := keymap.MaxKeycode()
|
||||
for code := keymap.MinKeycode(); code <= maxCode && code < 256; code++ {
|
||||
numLevels := keymap.NumLevelsForKey(code, 0)
|
||||
for level := uint32(0); level < numLevels; level++ {
|
||||
for _, sym := range keymap.KeyGetSymsByLevel(code, 0, level) {
|
||||
chord := newChord(keymap, keymap.KeyGetMod(code, 0, level), code)
|
||||
if linux {
|
||||
for name, s := range linuxXSyms {
|
||||
if s == sym {
|
||||
LinuxKeys[name] = chord
|
||||
}
|
||||
}
|
||||
}
|
||||
XKeys[xkb.KeysymGetName(sym)] = chord
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue