FelixKratz / SketchyBar

A highly customizable macOS status bar replacement
https://felixkratz.github.io/SketchyBar/
GNU General Public License v3.0
5.19k stars 82 forks source link

front_app_switched event firing multiple times #545

Open bustinbung opened 2 months ago

bustinbung commented 2 months ago

Recently noticed some strange flickering issues with one of my items, traced it back to the front_app_switched event firing multiple times when it shouldn't. Unsure if this is a personal config issue or an issue with SketchyBar, but wanted to open an issue anyways. If you need any additional information, please let me know. Thanks again!

System Information - SketchyBar v2.21.0 - yabai v7.1.0
Config sketchybarrc ```sh #!/usr/bin/env bash # import colors source "$CONFIG_DIR/colors.sh" # setting global variables ITEMS_DIR="$CONFIG_DIR/items" FONT_FAMILY="JetBrains Mono" FONT_WEIGHT="Regular" FONT_SIZE="12.0" export FONT="${FONT_FAMILY}:${FONT_WEIGHT}:${FONT_SIZE}" BAR_PADDING=3 ITEM_PADDING=5 INTERNAL_PADDING=8 bar=( color="$BAR_COLOR" position=bottom height=34 margin=0 padding_left="$BAR_PADDING" padding_right="$BAR_PADDING" topmost=window sticky=off shadow=off ) sketchybar --bar "${bar[@]}" # default options defaults=( # geometry padding_left="$ITEM_PADDING" padding_right="$ITEM_PADDING" # background background.color="$ITEM_COLOR" background.border_color="0x00FFFFFF" background.border_width=2 background.height=28 background.corner_radius=5 # icon icon.padding_left="$INTERNAL_PADDING" icon.padding_right="$INTERNAL_PADDING" icon.color="$ICON_COLOR" icon.highlight_color="$ICON_HIGHLIGHT" icon.font="$FONT" # label label.padding_left="$INTERNAL_PADDING" label.padding_right="$INTERNAL_PADDING" label.color="$LABEL_COLOR" label.highlight_color="$LABEL_HIGHLIGHT" label.font="$FONT" ) sketchybar --default "${defaults[@]}" # add left side items # these have been commented out for debugging # source "$ITEMS_DIR/spaces.sh" # source "$ITEMS_DIR/layout.sh" source "$ITEMS_DIR/apps.sh" # final steps sketchybar --hotload on sketchybar --update ``` apps.sh ```sh #!/usr/bin/env bash source "$CONFIG_DIR/colors.sh" PLUGIN_DIR="$CONFIG_DIR/plugins" # item properties app=( background.color="$ITEM_HIGHLIGHT" padding_left=0 label.max_chars=25 icon.padding_right=0 label.color="$LABEL_HIGHLIGHT" icon.color="$LABEL_HIGHLIGHT" script="$PLUGIN_DIR/apps_plugin.sh" ) sketchybar --add item app left \ --set app "${app[@]}" \ --add event app_update \ --subscribe app front_app_switched \ mouse.entered \ mouse.exited \ app_update ``` apps_plugin.sh ```sh #!/usr/bin/env bash source "$CONFIG_DIR/plugins/icon_map.sh" source "$CONFIG_DIR/colors.sh" mouse() { if [[ "$SENDER" == "mouse.entered" ]]; then sketchybar --set app scroll_texts=on else sketchybar --set app scroll_texts=off fi } update() { # this is for debugging echo ran update from $SENDER at $(date "+%H:%M:%S") APP=$(yabai -m query --windows --window) if [ ! -z "$APP" ]; then APP_NAME=$(jq '.app' <<< "$APP" | tr -d '"') APP_TITLE=$(jq '.title' <<< "$APP" | tr -d '"' | xargs echo) __icon_map "${APP_NAME}" ICON="${icon_result}" app=( drawing=on icon.font="sketchybar-app-font:Regular:12" icon="$ICON" ) if [ "$APP_NAME" == "$APP_TITLE" ]; then app+=(label="$APP_NAME") else app+=(label="$APP_NAME / $APP_TITLE") fi if $(jq '."is-floating"' <<< "$APP"); then app+=(background.border_color="$SPACE_NATIVE_FULLSCREEN") else app+=(background.border_color="0x00ffffff") fi else app=( drawing=off ) fi sketchybar --set app "${app[@]}" } case "$SENDER" in "mouse.entered" | "mouse.exited") mouse ;; *) update ;; esac ```
Screen Recording https://github.com/FelixKratz/SketchyBar/assets/22670587/5cb643c2-cfbb-4ca6-a4ca-b4666e51c384 Explanation: - Run sketchybar from the command line - Open new window (issue first appeared when using Arc/Little Arc so unsure if it's an issue with how Little Arc windows are handled) - Switch spaces around (using skhd/yabai) - App item switches between Arc/Alacritty quickly, even when not switching windows
FelixKratz commented 1 month ago

Thats odd. The only explanation I have for this is that for some reason alacritty steals focus because of something sketchybar (or a script invoked by it) does. Could you try running sketchybar from Terminal, kitty or some other terminal and via brew? Is the problem still there then?

bustinbung commented 1 month ago

Can confirm that running via brew services and through Terminal.app causes the same issues.

Bellavene commented 4 weeks ago

I have near the same bug with Vivaldi browser. It doesn't steal focus, but for some reason, when you watch videos on youtube with captions on, it engages constantly title update signal. And when you hover over pictures with a link it does so also, but one time per hover. Maybe we can update the script to ignore the title change signal, when the title actually stayed unchanged? It will still spam the script execution, but at least without distraction. Or maybe @FelixKratz has some more clever idea, to implement it inside Sketchybar? The less there are unneeded script executions, the better for the system overall. I believe this is an overlook by the coders of those apps, yet still an issue for us.

https://github.com/FelixKratz/SketchyBar/assets/77557804/09c997ed-8f39-4423-804f-7fc44785d5f8

FelixKratz commented 4 weeks ago

I have near the same bug with Vivaldi browser. It doesn't steal focus, but for some reason, when you watch videos on youtube with captions on, it engages constantly title update signal. And when you hover over pictures with a link it does so also, but one time per hover. Maybe we can update the script to ignore the title change signal, when the title actually stayed unchanged? It will still spam the script execution, but at least without distraction. Or maybe @FelixKratz has some more clever idea, to implement it inside Sketchybar? The less there are unneeded script executions, the better for the system overall. I believe this is an overlook by the coders of those apps, yet still an issue for us.

240604.Screen.Recording.2024-06-03.at.15.06.38.mp4

Are you sure that the front_app_switched event is responsible for these updates in sketchybar? It looks like you might be using a custom event to detect when the title of the window changes, wich might be triggered by yabai?

Bellavene commented 4 weeks ago

No, it is a title change trigger, and yes, it is triggered by yabai. Which, I believe, is looking at the system signal for title change?

--subscribe title title_change window_focus

yabai -m signal --add event=window_title_changed action="sketchybar --trigger title_change &> /dev/null &disown"

FelixKratz commented 4 weeks ago

No, it is a title change trigger, and yes, it is triggered by yabai, which I believe is looking at the system signal for title change?

Yes exactly, it seems that the yabai event is fired even tough the title was not changed. Probably because of some shenanigans the devs of the vivaldi app are doing. This particular problem can not be fixed from within sketchybar because it is a custom event triggered by an external source, so there is no additional bookkeeping I could internally do to buffer the events (like I am doing for most other events) because inside of sketchybar the event has no attached meaning. This would probably need to be addressed in the script thats executed, or in yabais code.

Bellavene commented 4 weeks ago

Would be great, if that will be fixed in yabai.

Bellavene commented 4 weeks ago

https://github.com/FelixKratz/SketchyBar/discussions/12#discussioncomment-9681283

@bustinbung I believe, you can modify this script for your issue, as a dirty fix.