moses-palmer / pystray

GNU General Public License v3.0
473 stars 59 forks source link

Right click on Windows sometimes also opens the task tray context menu #72

Closed Ennea closed 3 years ago

Ennea commented 3 years ago

Sometimes when right clicking the tray icon on Windows, the tray context menu is opened above pystray's own menu. I can reproduce this by opening the menu via right click, then dismissing it by left clicking into another application (Firefox in this case, might not work with all applications). Then try opening the menu with a right click again. If it doesn't open the tray context menu as well, dismiss it again by left clicking into another application, and keep doing that until it happens.

Apologies for the wonky reproduction steps, but I couldn't figure out a surefire way to always trigger it. I've also taken a look at pystray's win32 code, but I have no experience with the Windows API and couldn't figure out where this might've gone wrong.

moses-palmer commented 3 years ago

Thank you for your report.

I have never seen this myself. Reading the MSDN documentation does not provide any insights either; whatever happens before the event is sent to pystray is out of control of the library.

Does any running applications using the tray change how often this happens?

Ennea commented 3 years ago

Hey there, thanks for the reply! I actually fixed this already, but didn't get around to creating a fork/PR yet. In _win32.py, I changed the _on_notify to handle WM_RBUTTONUP instead of WM_RBUTTONDOWN. This behavior is more correct anyway, and... for some reason unbeknownst to me it also fixes the issue at hand. I looked at a different tray icon library to figure this one out, and it just happened to work.

moses-palmer commented 3 years ago

Sorry for the late reply.

You are absolutely correct that this is the expected behaviour. I have applied these changes to the main branch.