From 5e9fcfcac7ed23a7e31c13c8edc54bb50cdb06ea Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Fri, 30 May 2025 16:13:09 -0400 Subject: [PATCH] refactor: use built in method for activation token sets the correct app id --- cosmic-app-list/src/app.rs | 100 +++++++++++--------- cosmic-app-list/src/wayland_handler.rs | 53 +---------- cosmic-app-list/src/wayland_subscription.rs | 11 --- 3 files changed, 58 insertions(+), 106 deletions(-) diff --git a/cosmic-app-list/src/app.rs b/cosmic-app-list/src/app.rs index f92405fa0..4ea8f90fd 100755 --- a/cosmic-app-list/src/app.rs +++ b/cosmic-app-list/src/app.rs @@ -19,7 +19,6 @@ use cctk::{ workspace::v1::client::ext_workspace_handle_v1::ExtWorkspaceHandleV1, }, }; -use cosmic::desktop::fde::{get_languages_from_env, DesktopEntry}; use cosmic::{ app, applet::{ @@ -50,6 +49,10 @@ use cosmic::{ Apply, Element, Task, }; use cosmic::{desktop::fde, widget}; +use cosmic::{ + desktop::fde::{get_languages_from_env, DesktopEntry}, + iced_winit::commands::activation::request_token, +}; use cosmic_app_list_config::{AppListConfig, APP_ID}; use cosmic_protocols::toplevel_info::v1::client::zcosmic_toplevel_handle_v1::State; use futures::future::pending; @@ -358,6 +361,7 @@ pub enum PopupType { #[derive(Debug, Clone)] enum Message { + ActivationToken(Option, String, String, Option), Wayland(WaylandUpdate), PinApp(u32), UnpinApp(u32), @@ -369,7 +373,7 @@ enum Message { ClosePopup, Activate(ExtForeignToplevelHandleV1), Toggle(ExtForeignToplevelHandleV1), - Exec(String, Option), + Exec(String, String, Option), Quit(String), NewSeat(WlSeat), RemovedSeat, @@ -659,6 +663,19 @@ impl cosmic::Application for CosmicAppList { fn update(&mut self, message: Self::Message) -> app::Task { match message { + Message::ActivationToken(token, app_id, exec, gpu_idx) => { + let mut env_vars = Vec::new(); + if let Some(token) = token { + env_vars.push(("XDG_ACTIVATION_TOKEN".to_string(), token.clone())); + env_vars.push(("DESKTOP_STARTUP_ID".to_string(), token)); + } + if let (Some(gpus), Some(idx)) = (self.gpus.as_ref(), gpu_idx) { + env_vars.extend(gpus[idx].environment.clone().into_iter()); + } + tokio::spawn(async move { + cosmic::desktop::spawn_desktop_exec(exec, env_vars, Some(&app_id)).await + }); + } Message::Popup(id, parent_window_id) => { if let Some(Popup { parent, @@ -1232,29 +1249,6 @@ impl cosmic::Application for CosmicAppList { self.output_list.remove(&output); } }, - WaylandUpdate::ActivationToken { - token, - app_id, - exec, - gpu_idx, - } => { - let mut envs = Vec::new(); - if let Some(token) = token { - envs.push(("XDG_ACTIVATION_TOKEN".to_string(), token.clone())); - envs.push(("DESKTOP_STARTUP_ID".to_string(), token)); - } - if let (Some(gpus), Some(idx)) = (self.gpus.as_ref(), gpu_idx) { - envs.extend( - gpus[idx] - .environment - .iter() - .map(|(k, v)| (k.clone(), v.clone())), - ); - } - tokio::spawn(async move { - cosmic::desktop::spawn_desktop_exec(exec, envs, app_id.as_deref()).await - }); - } } } Message::NewSeat(s) => { @@ -1263,14 +1257,19 @@ impl cosmic::Application for CosmicAppList { Message::RemovedSeat => { self.seat.take(); } - Message::Exec(exec, gpu_idx) => { - if let Some(tx) = self.wayland_sender.as_ref() { - let _ = tx.send(WaylandRequest::TokenRequest { - app_id: Self::APP_ID.to_string(), - exec, + Message::Exec(app_id, exec, gpu_idx) => { + return request_token( + Some(String::from(::APP_ID)), + Some(self.core.main_window_id().unwrap().clone()), + ) + .map(move |t| { + cosmic::Action::App(Message::ActivationToken( + t, + app_id.clone(), + exec.clone(), gpu_idx, - }); - } + )) + }); } Message::Rectangle(u) => match u { RectangleUpdate::Rectangle(r) => { @@ -1825,8 +1824,11 @@ impl cosmic::Application for CosmicAppList { if let Some(exec) = desktop_info.exec() { if !toplevels.is_empty() { content = content.push( - menu_button(text::body(fl!("new-window"))) - .on_press(Message::Exec(exec.to_string(), None)), + menu_button(text::body(fl!("new-window"))).on_press(Message::Exec( + desktop_info.id().to_string(), + exec.to_string(), + None, + )), ); } else if let Some(gpus) = self.gpus.as_ref() { let default_idx = if desktop_info.prefers_non_default_gpu() { @@ -1845,14 +1847,21 @@ impl cosmic::Application for CosmicAppList { String::new() } ))) - .on_press(Message::Exec(exec.to_string(), Some(i))), + .on_press(Message::Exec( + desktop_info.id().to_string(), + exec.to_string(), + Some(i), + )), ); } } else { - content = content.push( - menu_button(text::body(fl!("run"))) - .on_press(Message::Exec(exec.to_string(), None)), - ); + content = content.push(menu_button(text::body(fl!("run"))).on_press( + Message::Exec( + desktop_info.id().to_string(), + exec.to_string(), + None, + ), + )); } for action in desktop_info.actions().into_iter().flatten() { if action == "new-window" { @@ -1867,10 +1876,9 @@ impl cosmic::Application for CosmicAppList { else { continue; }; - content = content.push( - menu_button(text::body(name)) - .on_press(Message::Exec(exec.into(), None)), - ); + content = content.push(menu_button(text::body(name)).on_press( + Message::Exec(desktop_info.id().to_string(), exec.into(), None), + )); } content = content.push(divider::horizontal::light()); } @@ -2351,7 +2359,11 @@ fn launch_on_preferred_gpu(desktop_info: &DesktopEntry, gpus: Option<&[Gpu]>) -> } }); - Some(Message::Exec(exec.to_string(), gpu_idx)) + Some(Message::Exec( + desktop_info.id().to_string(), + exec.to_string(), + gpu_idx, + )) } #[derive(Debug, Default, Clone)] diff --git a/cosmic-app-list/src/wayland_handler.rs b/cosmic-app-list/src/wayland_handler.rs index 1635afbb6..30bbae075 100644 --- a/cosmic-app-list/src/wayland_handler.rs +++ b/cosmic-app-list/src/wayland_handler.rs @@ -50,10 +50,8 @@ use cosmic_protocols::{ toplevel_management::v1::client::zcosmic_toplevel_manager_v1, }; use futures::channel::mpsc::UnboundedSender; -use sctk::{ - activation::{ActivationHandler, ActivationState}, - registry::{ProvidesRegistryState, RegistryState}, -}; +use sctk::registry::{ProvidesRegistryState, RegistryState}; + struct AppData { exit: bool, tx: UnboundedSender, @@ -67,7 +65,6 @@ struct AppData { registry_state: RegistryState, seat_state: SeatState, shm_state: Shm, - activation_state: Option, } // Workspace and toplevel handling @@ -173,18 +170,6 @@ impl RequestDataExt for ExecRequestData { } } -impl ActivationHandler for AppData { - type RequestData = ExecRequestData; - fn new_token(&mut self, token: String, data: &ExecRequestData) { - let _ = self.tx.unbounded_send(WaylandUpdate::ActivationToken { - token: Some(token), - app_id: data.app_id().map(|x| x.to_owned()), - exec: data.exec.clone(), - gpu_idx: data.gpu_idx, - }); - } -} - impl SeatHandler for AppData { fn seat_state(&mut self) -> &mut sctk::seat::SeatState { &mut self.seat_state @@ -649,37 +634,6 @@ pub(crate) fn wayland_handler( } } }, - WaylandRequest::TokenRequest { - app_id, - exec, - gpu_idx, - } => { - if let Some(activation_state) = state.activation_state.as_ref() { - activation_state.request_token_with_data( - &state.queue_handle, - ExecRequestData { - data: RequestData { - app_id: Some(app_id), - seat_and_serial: state - .seat_state - .seats() - .next() - .map(|seat| (seat, 0)), - surface: None, - }, - exec, - gpu_idx, - }, - ); - } else { - let _ = state.tx.unbounded_send(WaylandUpdate::ActivationToken { - token: None, - app_id: Some(app_id), - exec, - gpu_idx, - }); - } - } }, calloop::channel::Event::Closed => { state.exit = true; @@ -704,7 +658,6 @@ pub(crate) fn wayland_handler( registry_state, seat_state: SeatState::new(&globals, &qh), shm_state: Shm::bind(&globals, &qh).unwrap(), - activation_state: ActivationState::bind::(&globals, &qh).ok(), }; loop { @@ -723,6 +676,4 @@ cctk::delegate_workspace!(AppData); cctk::delegate_toplevel_manager!(AppData); cctk::delegate_screencopy!(AppData, session: [SessionData], frame: [FrameData]); -sctk::delegate_activation!(AppData, ExecRequestData); - sctk::delegate_output!(AppData); diff --git a/cosmic-app-list/src/wayland_subscription.rs b/cosmic-app-list/src/wayland_subscription.rs index 31448e93f..da58ddb49 100644 --- a/cosmic-app-list/src/wayland_subscription.rs +++ b/cosmic-app-list/src/wayland_subscription.rs @@ -114,12 +114,6 @@ pub enum WaylandUpdate { Toplevel(ToplevelUpdate), Workspace(Vec), Output(OutputUpdate), - ActivationToken { - token: Option, - app_id: Option, - exec: String, - gpu_idx: Option, - }, Image(ExtForeignToplevelHandleV1, WaylandImage), } @@ -140,11 +134,6 @@ pub enum OutputUpdate { #[derive(Clone, Debug)] pub enum WaylandRequest { Toplevel(ToplevelRequest), - TokenRequest { - app_id: String, - exec: String, - gpu_idx: Option, - }, Screencopy(ExtForeignToplevelHandleV1), }