wip: subsurfaces
This commit is contained in:
parent
8a0e74b189
commit
91459591ec
7 changed files with 175 additions and 15 deletions
|
|
@ -1,3 +1,5 @@
|
|||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use cosmic::app::Core;
|
||||
use cosmic::iced::application;
|
||||
use cosmic::iced::platform_specific::shell::commands::popup::{destroy_popup, get_popup};
|
||||
|
|
@ -6,7 +8,7 @@ use cosmic::iced::{Length, Limits, Task};
|
|||
use cosmic::iced_runtime::core::window;
|
||||
use cosmic::theme::iced;
|
||||
use cosmic::widget::{list_column, settings, toggler};
|
||||
use cosmic::{Element, Theme};
|
||||
use cosmic::{applet, Element, Theme};
|
||||
|
||||
const ID: &str = "com.system76.CosmicAppletExample";
|
||||
|
||||
|
|
@ -14,7 +16,7 @@ const ID: &str = "com.system76.CosmicAppletExample";
|
|||
pub struct Window {
|
||||
core: Core,
|
||||
popup: Option<Id>,
|
||||
example_row: bool,
|
||||
example_row: Arc<Mutex<bool>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
|
@ -73,6 +75,32 @@ impl cosmic::Application for Window {
|
|||
.height(500)
|
||||
.width(500);
|
||||
popup_settings.positioner.size = Some((500, 500));
|
||||
|
||||
let applet = self.core.applet.clone();
|
||||
let toggled = self.example_row.clone();
|
||||
popup_settings = popup_settings.with_view(Box::new(
|
||||
move || -> Option<cosmic::Element<'static, cosmic::app::Message<Message>>> {
|
||||
{
|
||||
let guard = toggled.lock().unwrap();
|
||||
|
||||
let content_list =
|
||||
list_column().padding(5).spacing(0).add(settings::item(
|
||||
"Example row",
|
||||
cosmic::widget::container(
|
||||
toggler(*guard).on_toggle(|value| {
|
||||
Message::ToggleExampleRow(value)
|
||||
}),
|
||||
)
|
||||
.height(Length::Fixed(50.)),
|
||||
));
|
||||
|
||||
Some(
|
||||
Element::from(applet.popup_container(content_list))
|
||||
.map(cosmic::app::Message::App),
|
||||
)
|
||||
}
|
||||
},
|
||||
));
|
||||
get_popup(popup_settings)
|
||||
};
|
||||
}
|
||||
|
|
@ -81,7 +109,10 @@ impl cosmic::Application for Window {
|
|||
self.popup = None;
|
||||
}
|
||||
}
|
||||
Message::ToggleExampleRow(toggled) => self.example_row = toggled,
|
||||
Message::ToggleExampleRow(toggled) => {
|
||||
let mut guard = self.example_row.lock().unwrap();
|
||||
*guard = toggled;
|
||||
}
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
|
|
@ -95,15 +126,7 @@ impl cosmic::Application for Window {
|
|||
}
|
||||
|
||||
fn view_window(&self, _id: Id) -> Element<Self::Message> {
|
||||
let content_list = list_column().padding(5).spacing(0).add(settings::item(
|
||||
"Example row",
|
||||
cosmic::widget::container(
|
||||
toggler(self.example_row).on_toggle(|value| Message::ToggleExampleRow(value)),
|
||||
)
|
||||
.height(Length::Fixed(50.)),
|
||||
));
|
||||
|
||||
self.core.applet.popup_container(content_list).into()
|
||||
"oops".into()
|
||||
}
|
||||
|
||||
fn style(&self) -> Option<cosmic::iced_runtime::Appearance> {
|
||||
|
|
|
|||
89
examples/application/src/notif.rs
Normal file
89
examples/application/src/notif.rs
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
use std::error::Error;
|
||||
use std::time::Duration;
|
||||
use std::{collections::HashMap, convert::Infallible};
|
||||
|
||||
use cosmic::{app::Message, Task};
|
||||
use zbus::{export::futures_util::StreamExt, proxy, zvariant::Value, Connection};
|
||||
|
||||
#[proxy(
|
||||
default_service = "org.freedesktop.Notifications",
|
||||
default_path = "/org/freedesktop/Notifications"
|
||||
)]
|
||||
trait Notifications {
|
||||
/// Call the org.freedesktop.Notifications.Notify D-Bus method
|
||||
fn notify(
|
||||
&self,
|
||||
app_name: &str,
|
||||
replaces_id: u32,
|
||||
app_icon: &str,
|
||||
summary: &str,
|
||||
body: &str,
|
||||
actions: &[&str],
|
||||
hints: HashMap<&str, &Value<'_>>,
|
||||
expire_timeout: i32,
|
||||
) -> zbus::Result<u32>;
|
||||
|
||||
// We need to define the signal we want to listen for
|
||||
#[zbus(signal)]
|
||||
fn action_invoked(&self, id: u32, action_key: String) -> zbus::Result<()>;
|
||||
|
||||
// We need to define the signal we want to listen for
|
||||
#[zbus(signal)]
|
||||
fn activation_token(&self, id: u32, activation_token: String) -> zbus::Result<()>;
|
||||
}
|
||||
|
||||
pub fn notif_task<M: std::marker::Send + 'static>() -> Task<cosmic::app::Message<M>> {
|
||||
Task::future(async {
|
||||
match notif().await {
|
||||
Ok(t) => t,
|
||||
Err(err) => {
|
||||
tracing::error!("Ooops: {err:?}");
|
||||
panic!("oops");
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn notif<M: std::marker::Send + 'static>(
|
||||
) -> Result<cosmic::app::Message<M>, Box<dyn Error>> {
|
||||
tokio::time::sleep(Duration::from_secs(2)).await;
|
||||
let connection = Connection::session().await?;
|
||||
|
||||
let proxy = NotificationsProxy::new(&connection).await?;
|
||||
let mut actions = proxy.receive_action_invoked().await?;
|
||||
let mut tokens = proxy.receive_activation_token().await?;
|
||||
|
||||
let _reply = proxy
|
||||
.notify(
|
||||
"my-app",
|
||||
0,
|
||||
"dialog-information",
|
||||
"A summary",
|
||||
"Some body",
|
||||
&["default", "asdf"],
|
||||
HashMap::new(),
|
||||
5000,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let token = if let Some(msg) = tokens.next().await {
|
||||
// struct `JobNewArgs` is generated from `job_new` signal function arguments
|
||||
let args: ActivationTokenArgs = msg.args().expect("Error parsing message");
|
||||
|
||||
println!("action: id={} action={}", args.id, args.activation_token,);
|
||||
args.activation_token
|
||||
} else {
|
||||
eprintln!("no token");
|
||||
panic!("oops");
|
||||
};
|
||||
if let Some(msg) = actions.next().await {
|
||||
// struct `JobNewArgs` is generated from `job_new` signal function arguments
|
||||
let args: ActionInvokedArgs = msg.args().expect("Error parsing message");
|
||||
|
||||
println!("action: id={} action={}", args.id, args.action_key,);
|
||||
}
|
||||
|
||||
Ok(Message::Cosmic(cosmic::app::cosmic::Message::Activate(
|
||||
token,
|
||||
)))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue