Skip to content

Commit

Permalink
detect keyboard layout, if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
nwg-piotr committed Oct 4, 2023
1 parent 674c5a8 commit 7a8cef8
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion nwg_shell/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def main():
for item in ["nwg-look", "nwg-shell-config"]:
copy_from_skel(item, folder="data", skip_confirmation=skip, hyprland=args.hypr)

# Set default apps, if found, for nwg-shell-config(s)
# Detect default apps and keyboard layout
shell_config_settings_file = os.path.join(data_home, "nwg-shell-config", "settings")
shell_config_settings = load_json(shell_config_settings_file)

Expand All @@ -233,6 +233,7 @@ def main():
if args.hypr:
settings.append(shell_config_settings_hyprland)

# Set default apps, if found
for s in settings:
if "terminal" not in s or not s["terminal"]:
s["terminal"] = "foot"
Expand All @@ -257,6 +258,23 @@ def main():
s["browser"] = browsers[cmd]
break

# Set keyboard layout (requires systemd)
if is_command("localectl"):
keymap = ""
try:
lines = subprocess.check_output("localectl status", shell=True).decode("utf-8").strip().splitlines()
for line in lines:
if "VC Keymap" in line:
if "unset" not in line:
keymap = line.split()[-1]
break
except subprocess.CalledProcessError:
pass
if keymap:
shell_config_settings["keyboard-xkb-layout"] = keymap
if shell_config_settings_hyprland:
shell_config_settings_hyprland["input-kb_layout"] = keymap

save_json(shell_config_settings, shell_config_settings_file)
if args.hypr:
save_json(shell_config_settings_hyprland, shell_config_settings_hyprland_file)
Expand Down

0 comments on commit 7a8cef8

Please sign in to comment.