-
Notifications
You must be signed in to change notification settings - Fork 125
[WIP] status-area: Handle menuless items properly #946
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
base: master
Are you sure you want to change the base?
Changes from all commits
a91c3ae
e03f5ce
c0fc7bc
c1619a5
b39f95e
0547d98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,15 @@ | ||
// Copyright 2023 System76 <[email protected]> | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
use cosmic::{ | ||
iced::{self, Subscription}, | ||
widget::icon, | ||
}; | ||
use cosmic::iced::{self, Subscription}; | ||
use futures::{FutureExt, StreamExt}; | ||
use zbus::zvariant::{self, OwnedValue}; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct StatusNotifierItem { | ||
name: String, | ||
item_proxy: StatusNotifierItemProxy<'static>, | ||
menu_proxy: DBusMenuProxy<'static>, | ||
menu_proxy: Option<DBusMenuProxy<'static>>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
|
||
#[derive(Clone, Debug, zvariant::Value)] | ||
|
@@ -44,12 +41,22 @@ impl StatusNotifierItem { | |
.build() | ||
.await?; | ||
|
||
let menu_path = item_proxy.menu().await?; | ||
let menu_proxy = DBusMenuProxy::builder(connection) | ||
.destination(dest.to_string())? | ||
.path(menu_path)? | ||
.build() | ||
.await?; | ||
let menu_proxy = match item_proxy.menu().await { | ||
Ok(menu_path) => Some( | ||
DBusMenuProxy::builder(connection) | ||
.destination(dest.to_string())? | ||
.path(menu_path)? | ||
.build() | ||
.await?, | ||
), | ||
Err(e) => { | ||
let destination = item_proxy.inner().destination(); | ||
tracing::error!( | ||
"Error getting Menu property for {destination}: {e}. Treating as menuless item.", | ||
); | ||
None | ||
} | ||
}; | ||
|
||
Ok(Self { | ||
name, | ||
|
@@ -63,8 +70,10 @@ 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(); | ||
pub fn menu_layout_subscription(&self) -> iced::Subscription<Result<Layout, String>> { | ||
let Some(menu_proxy) = self.menu_proxy.clone() else { | ||
return iced::Subscription::none(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you. It looks like |
||
}; | ||
Subscription::run_with_id( | ||
format!("status-notifier-item-layout-{}", &self.name), | ||
async move { | ||
|
@@ -109,8 +118,12 @@ impl StatusNotifierItem { | |
) | ||
} | ||
|
||
pub fn menu_proxy(&self) -> &DBusMenuProxy<'static> { | ||
&self.menu_proxy | ||
pub fn menu_proxy(&self) -> Option<&DBusMenuProxy<'static>> { | ||
self.menu_proxy.as_ref() | ||
} | ||
|
||
pub fn item_proxy(&self) -> &StatusNotifierItemProxy<'static> { | ||
&self.item_proxy | ||
} | ||
} | ||
|
||
|
@@ -135,6 +148,10 @@ trait StatusNotifierItem { | |
|
||
#[zbus(signal)] | ||
fn new_icon(&self) -> zbus::Result<()>; | ||
|
||
fn activate(&self, x: i32, y: i32) -> zbus::Result<()>; | ||
fn context_menu(&self, x: i32, y: i32) -> zbus::Result<()>; | ||
fn item_is_menu(&self) -> zbus::Result<bool>; | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
|
There was a problem hiding this comment.
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)