Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trick — Trigger refreshes using yabai -m signal #110

Open
devnoname120 opened this issue Jul 11, 2022 · 3 comments
Open

Trick — Trigger refreshes using yabai -m signal #110

devnoname120 opened this issue Jul 11, 2022 · 3 comments

Comments

@devnoname120
Copy link

devnoname120 commented Jul 11, 2022

Using yabai's signals is more reliable than Hammerspoon, as the latter uses some deprecated macOS APIs, some of which don't work anymore (see #113).

This can be fixed by adding the following code to ~/.config/yabai/yabairc:

# See https://github.com/koekeishiya/yabai/blob/master/doc/yabai.asciidoc#673-event
EVENT_TYPES=(
    display_added
    display_removed
    display_changed
    space_changed
    application_visible
    application_hidden
    window_created
    window_destroyed
)

for event in ${EVENT_TYPES[@]}; do
    yabai -m signal --add event=$event action="hs -A -c 'stackline.manager:update({forceRedraw = true})'"
done

Edit: looks like it can quickly cause stackline or Hammerspoon to crash, probably due to race conditions and duplicated event handling (yabai's signals defined above + stackline event callbacks registered in Hammerspoon).

@devnoname120 devnoname120 changed the title Trigger refreshes using Trigger refreshes using yabai -m signal Jul 11, 2022
@devnoname120 devnoname120 changed the title Trigger refreshes using yabai -m signal Trick — Trigger refreshes using yabai -m signal Aug 19, 2022
@nilsolofsson
Copy link

I'd suggest that you should modify the commands with the a flag as without it, at least on macOS Ventura, you'll be spammed with prompts to start Hammerspoon as it seems to be not running (even if it is).
I.E yabai -m signal --add event=display_added action="hs -ac 'stackline.refresh()'"

@kiryph
Copy link

kiryph commented Oct 18, 2023

Note the order of the flags -c -A in the first edited post is incorrect:

❯ hs -c -A 'stackline.manager:update({forceRedraw = true})'
/usr/local/bin/hs: illegal option: stackline.manager:update({forceRedraw = true})

It should be

# See https://github.com/koekeishiya/yabai/blob/master/doc/yabai.asciidoc#673-event
EVENT_TYPES=(
    display_added
    display_removed
    display_changed
    space_changed
    application_visible
    application_hidden
    window_created
    window_destroyed
)

for event in ${EVENT_TYPES[@]}; do
    yabai -m signal --add event=$event action="hs -A -c 'stackline.manager:update({forceRedraw = true})'"
done

@devnoname120
Copy link
Author

Good catch, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants