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

tray module enhancements #1145

Merged
merged 6 commits into from
Jul 23, 2021
Merged

tray module enhancements #1145

merged 6 commits into from
Jul 23, 2021

Conversation

alebastr
Copy link
Contributor

@alebastr alebastr commented Jun 30, 2021

Assorted enhancements for tray module.

I had to drop the tooltip icon changes with intent to finish those later, once I have a complete grasp of a possible implementation.
Need to take another look at update_pending_ for possibility of races. Shouldn't be a blocker for the merge though, as I haven't found anything harmful so far. Only a minuscule chance of missing a property update.

Changes:

  • Try to optimize updates by assuming that signals don't lie and could be using to infer all modified properties. A somewhat risky assumption, given how broken is an average sni client implementation, but I've seen other trays working like that.
  • Support tooltips for tray items (text only).
  • Support Scroll SNI method.
  • Support Status property: hide Passive items by default; attach corresponding CSS classes to the icon.

Fixes #1138, #1150

@alebastr
Copy link
Contributor Author

@12101111, do you mind checking if the CPU usage is acceptable with this PR?
I haven't managed to get a good data with perf, likely because most of my profiling experience is with other tools and I don't have access to any of those at home ☹️

// TODO: tooltip
tooltip = get_variant<ToolTip>(value);
if (!tooltip.text.empty()) {
event_box.set_tooltip_markup(tooltip.text);
Copy link
Owner

Choose a reason for hiding this comment

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

❤️

static const std::map<std::string_view, std::set<std::string_view>> signal2props = {
{"NewTitle", {"Title"}},
{"NewIcon", {"IconName", "IconPixmap"}},
// {"NewAttentionIcon", {"AttentionIconName", "AttentionIconPixmap", "AttentionMovieName"}},
Copy link
Owner

@Alexays Alexays Jul 21, 2021

Choose a reason for hiding this comment

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

No need of these mappings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Commented mappings are things we don't support at the moment. I.e. no reason to process AttentionIconPixmap updates if we aren't capable of displaying it.

Copy link
Owner

Choose a reason for hiding this comment

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

Ok got it

Copy link
Owner

@Alexays Alexays left a comment

Choose a reason for hiding this comment

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

Apart from some questions, LGTM
Thanks!

Comparing two GVariants is too expensive; let's collect the set of
properties updated by each signal and apply them unconditionally.
On the `Passive` value of `Status` tray items would be hidden unless
`show-passive-items` is set to true.
On the `NeedsAttention` value of `Status` tray items will have a
`.needs-attention` CSS class.
@Alexays Alexays merged commit b33be38 into Alexays:master Jul 23, 2021
@alebastr alebastr deleted the sni-enhancements branch July 23, 2021 14:52
@12101111
Copy link

@12101111, do you mind checking if the CPU usage is acceptable with this PR?
I haven't managed to get a good data with perf, likely because most of my profiling experience is with other tools and I don't have access to any of those at home frowning_face

Sorry for the late, the CPU usage is nearly to 0 and perf result looks great.
图片

@rieje
Copy link

rieje commented Sep 18, 2021

The issue that prompted #1150 was udiskie's --smart-tray option which only shows the icon if when actions are available. Prior to this fix, it will always show the icon. With this fix, the icon is appropriately hidden except on the first instance of waybar, where it will always show the icon. Killing and starting another instance correctly shows the icon as hidden.

I have waybar autostarted but even if disable autostart and start waybar for the first time at a later time, the tray icon is incorrectly showing until I kill the instance and start another. I am on latest version 0.9.8.

@alebastr
Copy link
Contributor Author

@rieje can you please check waybar -l trace output when running the first time? Does it get the right Status from udiskie?

@rieje
Copy link

rieje commented Sep 19, 2021

Ok, just did some quick testing and I was wrong--it happens randomly all the time. I run multiple waybars to see what happens (the status is passive on all these instances which is correct), and on each instance that starts, it may trigger show/hide of the udiskie icon on all other waybars independently. -l trace output of the typical instance.

@alebastr
Copy link
Contributor Author

I believe it's not so random. I managed to reproduce the issue, and everything is right from our side: we're calling event_box.set_visible(false) for the udiskie tray item and subsequent event_box.get_visible() returns false as well.

Do you happen to notice if the issue is reproducible when udiskie is not the first icon in the tray? My suspicion is that the first item in a GtkBox cannot be hidden, but I'll need to check GTK sources to confirm that.

@rieje
Copy link

rieje commented Sep 19, 2021

Yes, still happens if not the first (leftmost) icon. I see it as the second icon, and less frequently as the third (last) icon.

@alebastr
Copy link
Contributor Author

So I got some time to debug the issue and found that it's our fault. I just never looked at the code dealing with updates on the whole tray module level and missed the right (or wrong in this case) line.

@rieje do you mind giving alebastr@dc67bcc a try? Worked for me, but I only did limited testing.

@rieje
Copy link

rieje commented Sep 21, 2021

This works, I have not experienced any unexpected results at all. Looks fixed!

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.

High CPU usage in tray module
4 participants