stackline icon indicating copy to clipboard operation
stackline copied to clipboard

Trick — Trigger refreshes using `yabai -m signal`

Open devnoname120 opened this issue 1 year ago • 3 comments

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).

devnoname120 avatar Jul 11 '22 14:07 devnoname120

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()'"

nilsolofsson avatar Nov 22 '22 12:11 nilsolofsson

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

kiryph avatar Oct 18 '23 12:10 kiryph

Good catch, thanks.

devnoname120 avatar Oct 21 '23 19:10 devnoname120