Skip to content

Conversation

crumblingstatue
Copy link

@crumblingstatue crumblingstatue commented May 13, 2025

SNI protocol does not mandate the presence of a DBus menu. The ItemIsMenu method returns whether the item is a menu or not. But we should also handle items that don't provide a menu, even if they don't advertise this fact through ItemIsMenu.

If the item isn't a menu (or doesn't have one), then:

  • Left click should call the Activate method on the item.
  • Right click should call the ContextMenu method on the item.

This is a work-in-progress implementation to make the applet respect the above.

Fixes #944

This is my first pull request to COSMIC, I would appreciate any mentoring!

SNI protocol does not mandate the presence of a DBus menu.
The `ItemIsMenu` method returns whether the item is a menu or not.
But we should also handle items that don't provide a menu, even if they
don't advertise this fact through `ItemIsMenu`.

If the item isn't a menu (or doesn't have one), then:
- Left click should call the `Activate` method on the item.
- Right click should call the `ContextMenu` method on the item.

This is a work-in-progress implementation to make the applet
respect the above.
@crumblingstatue crumblingstatue marked this pull request as draft May 13, 2025 18:41
Copy link
Author

@crumblingstatue crumblingstatue left a comment

Choose a reason for hiding this comment

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

Please review carefully, this is my first COSMIC pull request.

@@ -26,6 +26,7 @@ pub enum Msg {
TogglePopup(usize),
Hovered(usize),
Surface(surface::Action),
RightPressed(usize),
Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure what to name this.
If we go with this name, it might also make sense to rename TogglePopup to LeftPressed to better reflect the logic.

Copy link
Member

Choose a reason for hiding this comment

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

It should be named based on what action the message will perform.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you, I renamed it to OpenContextMenu. Let me know if that's a suitable name.

@@ -188,6 +189,10 @@ impl cosmic::Application for App {
}
Task::none()
}
Msg::RightPressed(id) => {
self.menus[&id].ctx_menu_activate();
Task::none()
Copy link
Author

Choose a reason for hiding this comment

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

To be sure I'm not sure about what to return here.
I need to better familiarize myself with tasks (and async Rust in general)

@@ -12,7 +12,7 @@ use zbus::zvariant::{self, OwnedValue};
pub struct StatusNotifierItem {
name: String,
item_proxy: StatusNotifierItemProxy<'static>,
menu_proxy: DBusMenuProxy<'static>,
menu_proxy: Option<DBusMenuProxy<'static>>,
Copy link
Author

Choose a reason for hiding this comment

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

We make menu_proxy optional to reflect the fact that some clients don't provide a DBus menu.

@@ -64,7 +71,9 @@ impl StatusNotifierItem {

// TODO: Only fetch changed part of layout, if that's any faster
pub fn layout_subscription(&self) -> iced::Subscription<Result<Layout, String>> {
let menu_proxy = self.menu_proxy.clone();
let Some(menu_proxy) = self.menu_proxy.clone() else {
return iced::Subscription::none();
Copy link
Author

Choose a reason for hiding this comment

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

Not sure what iced subscriptions are, or if it's okay to return none here. I'm gonna have to look into that as well.

Copy link
Member

@mmstick mmstick May 14, 2025

Choose a reason for hiding this comment

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

They are tasks that automatically spawn for the duration that they remain in the subscription state of the application. Typically kept active for the whole duration of the application.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you. It looks like Layout is used for menus only, so Subscription::none() can be safely returned here.
I also renamed layout_subscription to menu_layout_subscription to help clarify this.

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.

[Status Area] Clients without menus aren't handled correctly
2 participants