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

Global mouse entered and exited events #178

Closed
zcag opened this issue Apr 27, 2022 · 7 comments
Closed

Global mouse entered and exited events #178

zcag opened this issue Apr 27, 2022 · 7 comments
Labels

Comments

@zcag
Copy link

zcag commented Apr 27, 2022

What i want to achieve is to be able to hover over an item and select something from the popup menu.
Right now when when my mouse exits the item and enters the popup, popup goes away naturally as i bound mouse.exit to close the popup.
Is there a way i can let the popup close when mouse exits the item to sides for example but not when mouse goes over the popup?
I have this for example:

	sketchybar -m --add item upcoming left \
		--set upcoming update_freq=20 \
		--set upcoming updates=on \
		--set upcoming popup.background.color=0xff000000 \
		--subscribe upcoming mouse.entered mouse.exited \
		--set upcoming script="python3 ~/.config/sketchybar/plugins/upcoming.py" 

and the script has:

def hover(sender):
    if 'entered' in sender:
        os.system('sketchybar -m --set upcoming popup.drawing=on')
    elif 'exited' in sender:
        os.system('sketchybar -m --set upcoming popup.drawing=off')
in.mov

I guess one option for me could be to have popup items bound to another script (currently click_script is an open command with a link for popup items) and enable drawing there as well, but this will be messy and it could cause a flicker (didn't try this).
Or i could hold a system-wide state somewhere to decide when to properly toggle the popup menu, but it'll be still ugly.

Sharing the issue in case you might see a value on having some sort of internal functionality for this.. However i don't see how this could be implemented in a nice way internally as well.

edit: ah maybe i can use brackets with a seperate script for hover, let's see
edit2: ok i don't think brackets support either scripts or mouse events

@FelixKratz
Copy link
Owner

FelixKratz commented Apr 27, 2022

With the current capabilities this is not possible in a non janky way I think.

The way this could be approached internally is to create a new event that triggers when the mouse moves out of all sketchybar windows. However, this has the potential to be a bit confusing since there is already the mouse.entered and mouse.exited event for the specific items. The naming of the "mouse entered anywhere" and "mouse left everywhere" would need to be very precise to not lead to major confusion.

If nothing better comes to mind we could go with the two new events:

  • mouse.entered.globally
  • mouse.exited.globally

Then you could simply subscribe to the mouse.exited.globally event to close the popup.

Would this fix your problem?

btw: The video gave me quite a good laugh

@zcag
Copy link
Author

zcag commented Apr 28, 2022

Yeah it would be quite nice to have something like this. And with mouse.entered.globally we can do make some items only shown in the bar when mouse is over. Similar to this bartender functionality:
quickreveal

@FelixKratz FelixKratz added the enhancement New feature or request label Apr 28, 2022
@FelixKratz FelixKratz changed the title Elegant way to show popup on mouse hover Global mouse entered and exited events Apr 28, 2022
@FelixKratz
Copy link
Owner

With #148 we can even have the item showing and hiding animated.
I will have to rework the way my tracking rects work for these new events, will look at it after #148.

@zcag
Copy link
Author

zcag commented May 23, 2022

With #148 we can even have the item showing and hiding animated. I will have to rework the way my tracking rects work for these new events, will look at it after #148.

oh nice! looking forward to it, thanks for the update!
I was thinking of maybe tackling this ticket myself but as a lowly ruby/java dev sadly i have no idea what's going on :)
Best of luck to you

@FelixKratz
Copy link
Owner

I have implemented this feature here 5531582 in the drawing rewrite branch. Once the pull request for this rewrite #191 is merged it will become available on the master branch. The events are called:
mouse.entered.global and mouse.exited.global and they are fired once the mouse leaves or enters over a bar.

So as it is currently you can have the bartender like items appearing when the mouse enters, however, still problematic is the use case you described with the mouse going off to a popup. I will include an additional check to see if the mouse is over a popup when it leaves the bar and only fire the mouse.exited.global event once the popup is also left with the cursor.

@FelixKratz
Copy link
Owner

Since 20c3326 popups are respected in the global mouse exited event and the event will only trigger once both the bar and all popups are left. Additionally I have made it such that the mouse.exited event for individual items is not triggered if mouse.exited.global is also subscribed and the mouse enters over a popup.
So if you subscribe to mouse.entered mouse.exited and mouse.exited.global you will have the desired behavior:

events.mp4

@zcag
Copy link
Author

zcag commented Jun 27, 2022

Hey, i've only been able to test now, works perfectly!
Thanks a lot for this, really appreciate it ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants