AdamWagner / stackline

Visualize yabai window stacks on macOS. Works with yabai & hammerspoon.
944 stars 47 forks source link

Trick — Trigger refreshes using `yabai -m signal` #110

Open devnoname120 opened 2 years ago

devnoname120 commented 2 years ago

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 https://github.com/AdamWagner/stackline/issues/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).

nilsolofsson commented 1 year ago

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 commented 10 months ago

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 commented 10 months ago

Good catch, thanks.