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

Handle mouse clicks for systray items #6

Closed
wants to merge 4 commits into from

Conversation

moetayuko
Copy link

No description provided.

@moetayuko
Copy link
Author

gtk::Window is subclassed just to store its global coordinates, which looks a bit overkill, but I didn't come up with better ideas. This could be further polished.

@x3rAx
Copy link

x3rAx commented Feb 6, 2024

Hi,

I've tested your changes and I really like the ability to change the spacing, but I noticed that the context menu window is no longer nicely aligned with the icon/bar, but instead appears right where the cursor is when the icon is right-clicked. Is this intentional?

Also, double-clicks do not seem to be handled. I have an application called "Barrier" that normally opens its window when double-clicked (e.g. when displayed in the Polybar tray area), but in EWW a double-click does nothing.

Comment on lines -1065 to -1157
// @prop pack-direction - how to arrange tray items
prop(pack_direction: as_string) { gtk_widget.set_pack_direction(parse_packdirection(&pack_direction)?); },
Copy link

@x3rAx x3rAx Feb 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry to ask, but has this been removed on purpose? I just realized that the pack direction does not work with your fork.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The orientation property partially supersedes it, allowing you to switch between horizontal and vertical layouts. The ltr/rtl provided by pack_direction isn't meaningful because the icons are already randomly ordered, and vice versa for ttb/btt.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ltr/rtl provided by pack_direction isn't meaningful because the icons are already randomly ordered

At least for me, the implementation of @ralismark shows the icons in the same order that programs are adding them. For example I configure :pack_directon "rtl" and have three programs currently open:

[a]  [b]  [c]

If I launch a 4th program [D], the icon is added to the left side:

[D]  [a]  [b]  [c]

which is nice if the tray is on the right side of the bar because then all previous icons stay in the same place and do not move around as new apps are launched.

Without this property, the icons always get added to the right side. They are only ordered randomly when the bar reloads (due to a config change for example) but I'd say this is not the normal case and I guess this is nothing that can be worked around easily.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is easy to implement, just need to choose between pack_start() and pack_end() when adding the icon widget to the container, and that would require adding another property for the user to configure.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is now a prepend-new property to achieve this goal.

@moetayuko
Copy link
Author

moetayuko commented Feb 7, 2024

Hi,

I've tested your changes and I really like the ability to change the spacing, but I noticed that the context menu window is no longer nicely aligned with the icon/bar, but instead appears right where the cursor is when the icon is right-clicked. Is this intentional?

Yes. The anchor of the context menu is expected to be your mouse cursor in the current implementation. Aligning it to the bar border can be added in the future, with a new property to allow users to toggle it.

Also, double-clicks do not seem to be handled. I have an application called "Barrier" that normally opens its window when double-clicked (e.g. when displayed in the Polybar tray area), but in EWW a double-click does nothing.

Indeed it's not and I don't think it's possible. According to the spec https://www.freedesktop.org/wiki/Specifications/StatusNotifierItem/StatusNotifierItem/ there's no way to tell the program whether it's a single click or double click, so this implementation handles single clicks only, and a double click is treated as two single clicks.

p.s.: other systray implementations might map the left button double-click to the middle button single-click, it's worth trying if the middle button opens your application.

@x3rAx
Copy link

x3rAx commented Feb 7, 2024

According to the spec https://www.freedesktop.org/wiki/Specifications/StatusNotifierItem/StatusNotifierItem/ there's no way to tell the program whether it's a single click or double click

This is sad..

it's worth trying if the middle button opens your application.

Unfortunately it does not. But it's not too big of a deal since I can still use right-click > show to open the window (and I really don't need to open it all the time).

Anyways, thanks for your answer 🙂

The major benefit of MenuItem is automatic handling of context menus.
However, MenuItem cannot properly process right mouse click, making it
less useful. Hence, this patch replaces it (as long as the container)
with a simple EventBox and process button clicks on our own.
@hylophile
Copy link

Thanks, this works great! Most importantly (for me), I can now quit tray apps via their menu, which wasn't possible before.

@moetayuko
Copy link
Author

Moved to elkowar#1059

@moetayuko moetayuko closed this Mar 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants