Preserve inherited input keys and later keyboard changes

This commit is contained in:
David Heinemeier Hansson committed 2026-10-07 15:19:06 +02:00
1 parent cd0025b62f
commit 0f14a84934
4 files changed
+22 -4

No files matched your search

+3 -1
View File
@@ -31,7 +31,9 @@ end
function keyboard.installed()
local values = keyboard.vconsole()
if read_values("/etc/omarchy/input-method").XKB_LAYOUT == "kr" then
if read_values("/etc/omarchy/input-method").XKB_LAYOUT == "kr"
and (values.XKBLAYOUT or "us") == "us"
and (values.XKBVARIANT or "") == "" then
values.XKBLAYOUT, values.XKBVARIANT = "kr", ""
end
return values
+3 -2
View File
@@ -83,7 +83,8 @@ def defaults(config_home, fresh=False):
existing = sections(original)
additions = []
for section, entries in sections(shipped).items():
if not fresh and section == "Hotkey/TriggerKeys":
# Missing hotkey sections also represent a choice: Fcitx's defaults.
if not fresh and section.startswith("Hotkey/"):
continue
# Existing lists (including explicitly empty lists) are user choices.
# A fresh profile has no working IME shortcut to preserve.
@@ -163,7 +164,7 @@ def selection():
preference = values(read(Path(os.environ.get("OMARCHY_INPUT_SELECTION", "/etc/omarchy/input-method"))))
layout = vconsole.get("XKBLAYOUT", "us").split(",")[0] or "us"
variant = vconsole.get("XKBVARIANT", "").split(",")[0]
if preference.get("XKB_LAYOUT") == "kr":
if preference.get("XKB_LAYOUT") == "kr" and vconsole.get("XKBLAYOUT", "us") == "us" and not variant:
layout, variant = "kr", ""
method = preference.get("INPUT_METHOD", "mozc" if layout == "jp" else "none")
if method not in PRESETS:
@@ -138,4 +138,6 @@ sddm_layouts=$(sed -n '/^local non_latin_layouts =/,+1p' "$sddm_lua" | grep -o '
fail "greeter non-latin layout list stays in sync" "$(diff <(echo "$hooks_layouts") <(echo "$sddm_layouts"))"
pass "greeter non-latin layout list stays in sync with the initramfs hook"
TEST_INPUT_PREFERENCE=$'INPUT_METHOD=hangul\n XKB_LAYOUT="kr" # desktop only\n' assert_input "Korean selection overrides desktop layout and clears the US variant" "[kr] [] [$base_options]" $'XKBLAYOUT=us\nXKBVARIANT=intl\n'
TEST_INPUT_PREFERENCE=$'INPUT_METHOD=hangul\n XKB_LAYOUT="kr" # desktop only\n' assert_input "Korean selection overrides its installer US layout" "[kr] [] [$base_options]" $'XKBLAYOUT=us\n'
TEST_INPUT_PREFERENCE=$'INPUT_METHOD=hangul\nXKB_LAYOUT=kr\n' assert_input "a later US variant overrides the Korean preference" "[us] [intl] [$base_options]" $'XKBLAYOUT=us\nXKBVARIANT=intl\n'
TEST_INPUT_PREFERENCE=$'INPUT_METHOD=hangul\nXKB_LAYOUT=kr\n' assert_input "a later layout overrides the Korean preference" "[de] [nodeadkeys] [$base_options]" $'XKBLAYOUT=de\nXKBVARIANT=nodeadkeys\n'
+13
View File
@@ -98,6 +98,19 @@ class InputMethodTest(unittest.TestCase):
self.assertEqual(config["Hotkey/EnumerateGroupForwardKeys"], {})
self.assertNotIn("Control+space", config["Hotkey/TriggerKeys"].values())
def test_existing_engine_inherited_hotkeys_are_preserved(self):
path = self.config / "fcitx5/config"
setup.atomic_write(path, "[Behavior]\nActiveByDefault=True\n")
setup.defaults(self.config, fresh=False)
self.assertEqual(path.read_text(), "[Behavior]\nActiveByDefault=True\n")
def test_korean_preference_yields_to_a_later_keyboard_change(self):
self.preference.write_text("INPUT_METHOD=hangul\nXKB_LAYOUT=kr\n")
self.assertEqual(setup.selection(), ("hangul", "kr"))
for layout, variant, expected in [("de", "nodeadkeys", "de-nodeadkeys"), ("us", "intl", "us-intl")]:
self.vconsole.write_text(f"XKBLAYOUT={layout}\nXKBVARIANT={variant}\n")
self.assertEqual(setup.selection(), ("hangul", expected))
def test_live_append_keeps_every_method_and_layout(self):
info = json.dumps({"data": ["de-nodeadkeys", [["keyboard-de-nodeadkeys", ""], ["mozc", "jp"]]]})
updated = json.dumps({"data": ["de-nodeadkeys", [["keyboard-de-nodeadkeys", ""], ["mozc", "jp"], ["hangul", ""]]]})