-
As in Also, can i do it for any/all keyboards, instead of hardcoding for example the weird value of |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 13 replies
-
hyprctl getoption input:kb_layout |
Beta Was this translation helpful? Give feedback.
-
get-lang of a device with a specific name: hyprctl devices -j | gojq -r '.keyboards[] | select(.name == "at-translated-set-2-keyboard") | .active_keymap' | cut -c 1-2 | tr 'A-Z' 'a-z' |
Beta Was this translation helpful? Give feedback.
-
If I understand the hyprctl devices -j | jq -r '.keyboards[] | select(.main == true) | .active_keymap' |
Beta Was this translation helpful? Give feedback.
-
here is a pure go version. :D
package main
import (
"bytes"
"encoding/json"
"fmt"
"os"
"os/exec"
"strings"
)
type Data struct {
Keyboards []Keyboard `json:"keyboards"`
}
type Keyboard struct {
ActiveKeymap string `json:"active_keymap"`
Main bool `json:"main"`
}
func main() {
cmd := []string{"hyprctl", "devices", "-j"}
buf := new(bytes.Buffer)
c := exec.Command(cmd[0], cmd[1:]...)
c.Stdout = buf
if err := c.Run(); err != nil {
fmt.Fprintf(os.Stderr, "while running: %s\n", err)
os.Exit(1)
}
d := Data{}
if err := json.Unmarshal(buf.Bytes(), &d); err != nil {
fmt.Fprintf(os.Stderr, "while parsing json: %s\n", err)
os.Exit(1)
}
for _, k := range d.Keyboards {
if k.Main && len(k.ActiveKeymap) >= 2 {
fmt.Println(strings.ToLower(k.ActiveKeymap[:2]))
return
}
}
fmt.Fprintf(os.Stderr, "err: could not find any layout\n")
os.Exit(1)
} |
Beta Was this translation helpful? Give feedback.
ok, this is definitely an answer for both of them:
thx. although the
switch-lang
is rather slow (0.070s-0.150s for me, which is noticeable) compared toxkblayout-state set +1
which only takes 0.006s. any suggestions on how to make it faster?