FelixKratz / SketchyBar

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

mouse.exited and mouse.exited.global not properly triggered? #564

Closed aspauldingcode closed 4 months ago

aspauldingcode commented 5 months ago

Having issues keeping my popup drawing set as off when mouse has exited the apple item. in my apple.sh:

# Handle mouse events
case "$SENDER" in
  "mouse.entered")
    sleep 2  # Wait for 2 seconds before showing the popup
      sketchybar --set $NAME popup.drawing=on
    ;;
  "mouse.exited" | "mouse.exited.global")
    sketchybar --set $NAME popup.drawing=off
    ;;
  "mouse.clicked")
    sketchybar --set $NAME popup.drawing=toggle
    ;;
  "routine")
    ;;
esac

I wanted to add a nested if statement which double checks after 2 seconds if I am still hovered on the item, before setting the popup drawing=on.

However, the code above doesn't do this, because if I add the nested for loop it seems to still think it's hovered. I'm not exactly sure how to approach this.

aspauldingcode commented 5 months ago

it might be more of: how do I do this? before triggering the popup, I want it to check for 2 seconds (in case I move the mouse away, it should instead not popup). If I hold on the item for 2 seconds, and after 2 seconds I am still hovering, then it would know I'm expecting a popup and it will set popup drawing on.

zcag commented 5 months ago

these are events that trigger the instant they happen, so it you won't get if the mouse is on the item afterwards. You can consider doing something like this:

# on the entered event
rm /tmp/sk_exited_"$NAME"
(
  sleep 2
  [[ -f /tmp/sk_exited_"$NAME" ]] || sketchybar --set $NAME popup.drawing=on
) &

# on the exited event
touch /tmp/sk_exited_"$NAME"

With this, exit events set a flag, so you can read that 2 seconds after the enter event to know if your cursor is still didn't exit.

Maybe there's a more straightforward way of doing it, but idk