Skip to content

Binding reload-config in the main binding mode is unreliable #1231

@nikitabobko

Description

@nikitabobko

To reproduce, run AeroSpace with the following config snippet:

[mode.main.binding]
    # dialog command is to indicate whether the keybinding was triggered.
    alt-e = ['reload-config', '''exec-and-forget osascript -e 'display dialog "Test"' ''']

Pressing alt-e once triggers the keybind as expected. However, pressing alt-e a second time will no longer trigger the key binding.

I suspect the issue is that the HotKey library ties hotkey registration/deregistration to the lifetime of the HotKey object: https://github.com/soffes/HotKey/blob/a3cf605d7a96f6ff50e04fcb6dea6e2613cfcbe4/Sources/HotKey/HotKey.swift#L30-L50

Hotkey handlers are called with the HotKey object still in scope:
https://github.com/soffes/HotKey/blob/a3cf605d7a96f6ff50e04fcb6dea6e2613cfcbe4/Sources/HotKey/HotKeysController.swift#L127-L133

When a ReloadConfigCommand triggered by a hotkey resets and reinstalls hotkeys, the HotKey for the reload is still alive. I suspect this causes attempts to register the same hotkey in the reloaded config to fail silently at:
https://github.com/soffes/HotKey/blob/a3cf605d7a96f6ff50e04fcb6dea6e2613cfcbe4/Sources/HotKey/HotKeysController.swift#L69-L72

It's pretty easy to work around this in practice by binding exec-and-forget aerospace reload-config instead of reload-config, but it would be nice if this sharp edge didn't exist.

Perhaps a fix could be to change ReloadConfigCommand to dispatch a separate callback to the main thread so that the config reload no longer runs from inside a hotkey handler. Alternately, resetHotKeys could unregister existing hotkeys by setting isPaused = true on every hotkey before clearing hotkeys.

btw, thank you so much for building AeroSpace - I have long wished for a macOS window manager that implements its own workspaces instead of building on the not-great Spaces model/APIs!

Originally posted by @rickyz in #1230

Metadata

Metadata

Assignees

No one assigned

    Labels

    1.0-blockerbugSomething isn't working as expected

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions