Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 56 additions & 44 deletions cosmic-app-list/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -358,6 +361,7 @@ pub enum PopupType {

#[derive(Debug, Clone)]
enum Message {
ActivationToken(Option<String>, String, String, Option<usize>),
Wayland(WaylandUpdate),
PinApp(u32),
UnpinApp(u32),
Expand All @@ -369,7 +373,7 @@ enum Message {
ClosePopup,
Activate(ExtForeignToplevelHandleV1),
Toggle(ExtForeignToplevelHandleV1),
Exec(String, Option<usize>),
Exec(String, String, Option<usize>),
Quit(String),
NewSeat(WlSeat),
RemovedSeat,
Expand Down Expand Up @@ -659,6 +663,19 @@ impl cosmic::Application for CosmicAppList {

fn update(&mut self, message: Self::Message) -> app::Task<Self::Message> {
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,
Expand Down Expand Up @@ -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) => {
Expand All @@ -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(<Self as cosmic::Application>::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) => {
Expand Down Expand Up @@ -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() {
Expand All @@ -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" {
Expand All @@ -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());
}
Expand Down Expand Up @@ -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)]
Expand Down
53 changes: 2 additions & 51 deletions cosmic-app-list/src/wayland_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<WaylandUpdate>,
Expand All @@ -67,7 +65,6 @@ struct AppData {
registry_state: RegistryState,
seat_state: SeatState,
shm_state: Shm,
activation_state: Option<ActivationState>,
}

// Workspace and toplevel handling
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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::<AppData>(&globals, &qh).ok(),
};

loop {
Expand All @@ -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);
11 changes: 0 additions & 11 deletions cosmic-app-list/src/wayland_subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,6 @@ pub enum WaylandUpdate {
Toplevel(ToplevelUpdate),
Workspace(Vec<ExtWorkspaceHandleV1>),
Output(OutputUpdate),
ActivationToken {
token: Option<String>,
app_id: Option<String>,
exec: String,
gpu_idx: Option<usize>,
},
Image(ExtForeignToplevelHandleV1, WaylandImage),
}

Expand All @@ -140,11 +134,6 @@ pub enum OutputUpdate {
#[derive(Clone, Debug)]
pub enum WaylandRequest {
Toplevel(ToplevelRequest),
TokenRequest {
app_id: String,
exec: String,
gpu_idx: Option<usize>,
},
Screencopy(ExtForeignToplevelHandleV1),
}

Expand Down
Loading