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

front_app_switched event firing multiple times #545

Open
bustinbung opened this issue May 2, 2024 · 7 comments
Open

front_app_switched event firing multiple times #545

bustinbung opened this issue May 2, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@bustinbung
Copy link

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

#!/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

#!/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

#!/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
Screen.Recording.2024-05-02.at.09.38.29-1.mov

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
Copy link
Owner

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?

@FelixKratz FelixKratz added the bug Something isn't working label May 16, 2024
@bustinbung
Copy link
Author

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

@Bellavene
Copy link

Bellavene commented Jun 4, 2024

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

@FelixKratz
Copy link
Owner

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
Copy link

Bellavene commented Jun 5, 2024

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
Copy link
Owner

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants