diff options
| author | Don Williams <don.e.williams@gmail.com> | 2026-08-05 07:28:34 -0400 |
|---|---|---|
| committer | Pinapelz <yukais@pinapelz.com> | 2026-08-29 21:41:34 -0700 |
| commit | 0911f2c77d6b2d42203f47da072437f32f1029f3 (patch) | |
| tree | 45e541829017764d33fcf03e5c28c02d149e8f20 | |
| parent | ff8a39488f28343df98973817ce87351080a2063 (diff) | |
Fixed migrate script to handle SHIFT
Signed-off-by: Don Williams <don.e.williams@gmail.com>
| -rw-r--r-- | CHANGELOG.md | 4 | ||||
| -rw-r--r-- | config/hypr/configs/Keybinds.conf | 2 | ||||
| -rw-r--r-- | config/hypr/configs/system_keybinds.lua | 39 | ||||
| -rw-r--r-- | config/hypr/lua/keybind_helpers.lua | 41 | ||||
| -rw-r--r-- | config/hypr/lua/user_keybinds_helper.lua | 39 | ||||
| -rwxr-xr-x | scripts/migrate-hypr-to-lua.sh | 84 |
6 files changed, 197 insertions, 12 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 126882cf..e78c4bd3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,9 @@ ## Fixed: -- Duplicate keybinds +- Fixed lua migrate script to force uppercase `SHIFT` + - LUA API doesn't allow `shift` +- Duplicate keybinds:wq - `copy.sh` was ovewritting sddm background and wallpaper - Also removed prompt for `Hypridle` restore - Background image in rofi didn't get updated in LUA workflow diff --git a/config/hypr/configs/Keybinds.conf b/config/hypr/configs/Keybinds.conf index b426ea91..7a7712bc 100644 --- a/config/hypr/configs/Keybinds.conf +++ b/config/hypr/configs/Keybinds.conf @@ -141,7 +141,7 @@ bindd = $mainMod ALT, S, Toggle scrolling V/H, exec, bash -c '[[ $(hyprctl getop $layout = 'smartgrid' # Or, using XDG_CONFIG_HOME: -bindd = $mainMod shift, tab, Toggle HyprView, exec, $scriptsDir/toggle-qs-hyprview.sh $layout +bindd = $mainMod SHIFT, tab, Toggle HyprView, exec, $scriptsDir/toggle-qs-hyprview.sh $layout # Cycle windows; if floating bring to top bindd = ALT, Tab, Cycle next window, cyclenext diff --git a/config/hypr/configs/system_keybinds.lua b/config/hypr/configs/system_keybinds.lua index 79407eac..9e6e7ebd 100644 --- a/config/hypr/configs/system_keybinds.lua +++ b/config/hypr/configs/system_keybinds.lua @@ -49,8 +49,43 @@ local function trim(value) return (value or ""):gsub("^%s+", ""):gsub("%s+$", "") end +local function normalize_mods(mods) + mods = trim(mods) + if mods == "" then + return "" + end + local known = { + super = "SUPER", + super_l = "SUPER_L", + super_r = "SUPER_R", + shift = "SHIFT", + shift_l = "SHIFT_L", + shift_r = "SHIFT_R", + ctrl = "CTRL", + control = "CTRL", + ctrl_l = "CTRL_L", + ctrl_r = "CTRL_R", + control_l = "CTRL_L", + control_r = "CTRL_R", + alt = "ALT", + alt_l = "ALT_L", + alt_r = "ALT_R", + meta = "META", + meta_l = "META_L", + meta_r = "META_R", + mod2 = "MOD2", + mod3 = "MOD3", + mod5 = "MOD5", + } + local parts = {} + for token in mods:gmatch("%S+") do + parts[#parts + 1] = known[token:lower()] or token + end + return table.concat(parts, " ") +end + local function chord(mods, key) - mods = trim(mods):gsub("%s+", " + ") + mods = normalize_mods(mods):gsub("%s+", " + ") key = trim(key) if mods == "" then return key @@ -92,7 +127,7 @@ local function key_variants(key, mods) ["code:18"] = "9", ["code:19"] = "0", } - if mods:match("SHIFT") and shifted_number_keys[key] then + if mods:upper():match("SHIFT") and shifted_number_keys[key] then local number_key = number_keys[key] if number_key then return { shifted_number_keys[key], number_key } diff --git a/config/hypr/lua/keybind_helpers.lua b/config/hypr/lua/keybind_helpers.lua index 97618d8f..8240cc60 100644 --- a/config/hypr/lua/keybind_helpers.lua +++ b/config/hypr/lua/keybind_helpers.lua @@ -225,8 +225,43 @@ local function dispatch(name, args) return raw_dispatch_cmd(name) end +local function normalize_mods(mods) + mods = trim(mods) + if mods == "" then + return "" + end + local known = { + super = "SUPER", + super_l = "SUPER_L", + super_r = "SUPER_R", + shift = "SHIFT", + shift_l = "SHIFT_L", + shift_r = "SHIFT_R", + ctrl = "CTRL", + control = "CTRL", + ctrl_l = "CTRL_L", + ctrl_r = "CTRL_R", + control_l = "CTRL_L", + control_r = "CTRL_R", + alt = "ALT", + alt_l = "ALT_L", + alt_r = "ALT_R", + meta = "META", + meta_l = "META_L", + meta_r = "META_R", + mod2 = "MOD2", + mod3 = "MOD3", + mod5 = "MOD5", + } + local parts = {} + for token in mods:gmatch("%S+") do + parts[#parts + 1] = known[token:lower()] or token + end + return table.concat(parts, " ") +end + local function chord(mods, key) - mods = trim(mods):gsub("%s+", " + ") + mods = normalize_mods(mods):gsub("%s+", " + ") key = trim(key) key = key:gsub("^xf86", "XF86") local key_aliases = { @@ -261,7 +296,7 @@ local function chord(mods, key) ["code:18"] = "9", ["code:19"] = "0", } - if mods:match("SHIFT") and shifted_number_keys[key] then + if mods:upper():match("SHIFT") and shifted_number_keys[key] then key = shifted_number_keys[key] else key = number_keys[key] or key @@ -278,7 +313,7 @@ local function bind(mods, key, fn, opts) else hl.bind(chord(mods, key), fn) end - if mods:match("SHIFT") then + if mods:upper():match("SHIFT") then local number_key = ({ ["code:10"] = "1", ["code:11"] = "2", diff --git a/config/hypr/lua/user_keybinds_helper.lua b/config/hypr/lua/user_keybinds_helper.lua index 66398bd9..aabb5f03 100644 --- a/config/hypr/lua/user_keybinds_helper.lua +++ b/config/hypr/lua/user_keybinds_helper.lua @@ -30,8 +30,43 @@ local function trim(value) return (value or ""):gsub("^%s+", ""):gsub("%s+$", "") end +local function normalize_mods(mods) + mods = trim(mods) + if mods == "" then + return "" + end + local known = { + super = "SUPER", + super_l = "SUPER_L", + super_r = "SUPER_R", + shift = "SHIFT", + shift_l = "SHIFT_L", + shift_r = "SHIFT_R", + ctrl = "CTRL", + control = "CTRL", + ctrl_l = "CTRL_L", + ctrl_r = "CTRL_R", + control_l = "CTRL_L", + control_r = "CTRL_R", + alt = "ALT", + alt_l = "ALT_L", + alt_r = "ALT_R", + meta = "META", + meta_l = "META_L", + meta_r = "META_R", + mod2 = "MOD2", + mod3 = "MOD3", + mod5 = "MOD5", + } + local parts = {} + for token in mods:gmatch("%S+") do + parts[#parts + 1] = known[token:lower()] or token + end + return table.concat(parts, " ") +end + local function chord(mods, key) - mods = trim(mods):gsub("%s+", " + ") + mods = normalize_mods(mods):gsub("%s+", " + ") key = trim(key) if mods == "" then return key @@ -73,7 +108,7 @@ local function key_variants(key, mods) ["code:18"] = "9", ["code:19"] = "0", } - if mods and mods:match("SHIFT") and shifted_number_keys[key] then + if mods and mods:upper():match("SHIFT") and shifted_number_keys[key] then local number_key = number_keys[key] if number_key then return { shifted_number_keys[key], number_key } diff --git a/scripts/migrate-hypr-to-lua.sh b/scripts/migrate-hypr-to-lua.sh index 0a127688..75a61db9 100755 --- a/scripts/migrate-hypr-to-lua.sh +++ b/scripts/migrate-hypr-to-lua.sh @@ -1112,6 +1112,46 @@ def emit_rule(rule_type, rule): lines.append("})") return "\n".join(lines) +def normalize_bind_mods(mods): + """Uppercase known modifiers for Hyprland Lua key chords. + + Hyprlang accepts mixed-case modifiers (e.g. "shift"), but hl.bind keysyms + require canonical names like SHIFT/CTRL/ALT/SUPER. + """ + if not mods: + return "" + tokens = re.split(r"\s+", mods.strip()) + known = { + "super": "SUPER", + "super_l": "SUPER_L", + "super_r": "SUPER_R", + "shift": "SHIFT", + "shift_l": "SHIFT_L", + "shift_r": "SHIFT_R", + "ctrl": "CTRL", + "control": "CTRL", + "ctrl_l": "CTRL_L", + "ctrl_r": "CTRL_R", + "control_l": "CTRL_L", + "control_r": "CTRL_R", + "alt": "ALT", + "alt_l": "ALT_L", + "alt_r": "ALT_R", + "meta": "META", + "meta_l": "META_L", + "meta_r": "META_R", + "mod2": "MOD2", + "mod3": "MOD3", + "mod5": "MOD5", + } + normalized = [] + for token in tokens: + if not token: + continue + key = token.lower() + normalized.append(known.get(key, token)) + return " ".join(normalized) + def parse_keybinds(path, *, variables=None, visited=None): if not path.exists(): return [] @@ -1164,7 +1204,8 @@ def parse_keybinds(path, *, variables=None, visited=None): if unbind: parts = [expand(part.strip()) for part in unbind.group(1).split(",")] if len(parts) >= 2: - converted.append(f"unbind({lua_string(parts[0])}, {lua_string(parts[1])})") + mods = normalize_bind_mods(parts[0]) + converted.append(f"unbind({lua_string(mods)}, {lua_string(parts[1])})") continue bind = re.match(r"^(bind[a-z]*)\s*=\s*(.+)$", line) @@ -1185,6 +1226,8 @@ def parse_keybinds(path, *, variables=None, visited=None): else: continue + mods = normalize_bind_mods(mods) + opts = [] if description: opts.append(f"description = {lua_string(description)}") @@ -1444,8 +1487,43 @@ system_keybind_lines = [ " return (value or \"\"):gsub(\"^%s+\", \"\"):gsub(\"%s+$\", \"\")", "end", "", + "local function normalize_mods(mods)", + " mods = trim(mods)", + " if mods == \"\" then", + " return \"\"", + " end", + " local known = {", + " super = \"SUPER\",", + " super_l = \"SUPER_L\",", + " super_r = \"SUPER_R\",", + " shift = \"SHIFT\",", + " shift_l = \"SHIFT_L\",", + " shift_r = \"SHIFT_R\",", + " ctrl = \"CTRL\",", + " control = \"CTRL\",", + " ctrl_l = \"CTRL_L\",", + " ctrl_r = \"CTRL_R\",", + " control_l = \"CTRL_L\",", + " control_r = \"CTRL_R\",", + " alt = \"ALT\",", + " alt_l = \"ALT_L\",", + " alt_r = \"ALT_R\",", + " meta = \"META\",", + " meta_l = \"META_L\",", + " meta_r = \"META_R\",", + " mod2 = \"MOD2\",", + " mod3 = \"MOD3\",", + " mod5 = \"MOD5\",", + " }", + " local parts = {}", + " for token in mods:gmatch(\"%S+\") do", + " parts[#parts + 1] = known[token:lower()] or token", + " end", + " return table.concat(parts, \" \")", + "end", + "", "local function chord(mods, key)", - " mods = trim(mods):gsub(\"%s+\", \" + \")", + " mods = normalize_mods(mods):gsub(\"%s+\", \" + \")", " key = trim(key)", " if mods == \"\" then", " return key", @@ -1487,7 +1565,7 @@ system_keybind_lines = [ " [\"code:18\"] = \"9\",", " [\"code:19\"] = \"0\",", " }", - " if mods:match(\"SHIFT\") and shifted_number_keys[key] then", + " if mods:upper():match(\"SHIFT\") and shifted_number_keys[key] then", " local number_key = number_keys[key]", " if number_key then", " return { shifted_number_keys[key], number_key }", |
