OPINIONATED OMARCHY
TROUBLESHOOTING CORPUS
790
RECORDS
790
AUDITED
0
UNCHECKED
2388
SOURCES
LIVE
hyprland-config low occasional DISPUTE

Fix a conditional keybinding that always does the same thing

hyprlandomarchyarch
AUDITED Audited against its sources and confirmed accurate. · checked against Omarchy omarchy 4.0.4-1 on 2026-10-05
AUDIT NOTE

The binds wiki page has a section, 'Conditional bind resolution at bind time', that uses this exact example and states the cause and the function-wrapper fix. The record's fix adds a nil guard on hl.get_active_window(), which is sound Lua and covers the load-time error the symptom mentions. The wiki does not state that error, but it follows from indexing nil. The Omarchy branch was checked in /usr/share/omarchy/default/hypr/helpers.lua: command_from returns a non-table value unchanged, and o.bind wraps only strings in hl.dsp.exec_cmd, so a function reaches hl.bind as a callback. ~/.config/hypr/bindings.lua is the shipped user file. The dispatchers page confirms that a bare hl.dsp.* call without hl.dispatch does nothing. Not exercised: no bind was added here.

Symptom

A Lua bind meant to behave differently depending on state, such as hl.bind("SUPER + L", hl.dsp.exec_cmd("foot", { float = not (hl.get_active_window().title == "foot") })), always does whatever was true when the config last loaded. It changes behaviour only after a reload, and sometimes the config errors at load because no window was focused.

Cause

Arguments to hl.bind are evaluated once, when the config file runs. The condition is computed at load time and baked into the dispatcher, so the bind stays fixed until the next reload. Only a function passed as the bind action is evaluated on each keypress.

Fix

Wrap the logic in a function and call hl.dispatch inside it:


hl.bind("SUPER + L", function()
  local w = hl.get_active_window()
  local is_foot = w and w.title == "foot"
  hl.dispatch(hl.dsp.exec_cmd("foot", { float = not is_foot }))
end)

On Omarchy 4 the same works through the helper in ~/.config/hypr/bindings.lua, since o.bind passes a function straight to hl.bind:


o.bind("SUPER + L", "Foot toggle float", function()
  local w = hl.get_active_window()
  hl.dispatch(hl.dsp.exec_cmd("foot", { float = not (w and w.title == "foot") }))
end)

A bare hl.dsp.* call inside the function without hl.dispatch does nothing.

Verify

Press the bind with different windows focused and get different results without reloading.

Sources

lua-bind-condition-frozen-at-config-load