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 · 2 comments
Open

front_app_switched event firing multiple times #545

bustinbung opened this issue May 2, 2024 · 2 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.

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

2 participants