From 7a8cef89ad6a7d2fd4f3cd722d9404962f4ff2b0 Mon Sep 17 00:00:00 2001 From: piotr Date: Thu, 5 Oct 2023 01:34:01 +0200 Subject: [PATCH] detect keyboard layout, if possible --- nwg_shell/installer.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/nwg_shell/installer.py b/nwg_shell/installer.py index f431669..55b2881 100644 --- a/nwg_shell/installer.py +++ b/nwg_shell/installer.py @@ -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) @@ -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" @@ -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)