From 88cea708c12d905ee0bbed4e7480694c92704391 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Fri, 3 Nov 2023 16:59:43 +0100 Subject: [PATCH 1/3] chore: Update libcosmic --- Cargo.lock | 106 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 81 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 66f5452..ca43a60 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5,12 +5,12 @@ version = 3 [[package]] name = "accesskit" version = "0.11.0" -source = "git+https://github.com/wash2/accesskit.git?tag=v0.11.0#2dee3df0a525d727df9f54ae71cfe8b47d7c2751" +source = "git+https://github.com/wash2/accesskit.git?tag=winit-0.28#db6f2587f663eafd8f7888e8507baa3a092599b0" [[package]] name = "accesskit_consumer" version = "0.15.0" -source = "git+https://github.com/wash2/accesskit.git?tag=v0.11.0#2dee3df0a525d727df9f54ae71cfe8b47d7c2751" +source = "git+https://github.com/wash2/accesskit.git?tag=winit-0.28#db6f2587f663eafd8f7888e8507baa3a092599b0" dependencies = [ "accesskit", ] @@ -18,7 +18,7 @@ dependencies = [ [[package]] name = "accesskit_unix" version = "0.4.0" -source = "git+https://github.com/wash2/accesskit.git?tag=v0.11.0#2dee3df0a525d727df9f54ae71cfe8b47d7c2751" +source = "git+https://github.com/wash2/accesskit.git?tag=winit-0.28#db6f2587f663eafd8f7888e8507baa3a092599b0" dependencies = [ "accesskit", "accesskit_consumer", @@ -667,7 +667,7 @@ dependencies = [ [[package]] name = "cosmic-config" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic/#6b517ddb0e7fe2ed8b04d6f71d1c45a374c92e14" +source = "git+https://github.com/pop-os/libcosmic/#e0b34e5d289155ee1836af6fb6f74cd5bba9cf1c" dependencies = [ "atomicwrites", "cosmic-config-derive", @@ -681,7 +681,7 @@ dependencies = [ [[package]] name = "cosmic-config-derive" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic/#6b517ddb0e7fe2ed8b04d6f71d1c45a374c92e14" +source = "git+https://github.com/pop-os/libcosmic/#e0b34e5d289155ee1836af6fb6f74cd5bba9cf1c" dependencies = [ "quote", "syn 1.0.109", @@ -710,7 +710,7 @@ dependencies = [ [[package]] name = "cosmic-theme" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic/#6b517ddb0e7fe2ed8b04d6f71d1c45a374c92e14" +source = "git+https://github.com/pop-os/libcosmic/#e0b34e5d289155ee1836af6fb6f74cd5bba9cf1c" dependencies = [ "almost", "cosmic-config", @@ -1790,7 +1790,7 @@ dependencies = [ [[package]] name = "iced" version = "0.10.0" -source = "git+https://github.com/pop-os/libcosmic/#6b517ddb0e7fe2ed8b04d6f71d1c45a374c92e14" +source = "git+https://github.com/pop-os/libcosmic/#e0b34e5d289155ee1836af6fb6f74cd5bba9cf1c" dependencies = [ "iced_accessibility", "iced_core", @@ -1805,7 +1805,7 @@ dependencies = [ [[package]] name = "iced_accessibility" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic/#6b517ddb0e7fe2ed8b04d6f71d1c45a374c92e14" +source = "git+https://github.com/pop-os/libcosmic/#e0b34e5d289155ee1836af6fb6f74cd5bba9cf1c" dependencies = [ "accesskit", "accesskit_unix", @@ -1814,14 +1814,14 @@ dependencies = [ [[package]] name = "iced_core" version = "0.10.0" -source = "git+https://github.com/pop-os/libcosmic/#6b517ddb0e7fe2ed8b04d6f71d1c45a374c92e14" +source = "git+https://github.com/pop-os/libcosmic/#e0b34e5d289155ee1836af6fb6f74cd5bba9cf1c" dependencies = [ "bitflags 1.3.2", "iced_accessibility", "instant", "log", "palette", - "smithay-client-toolkit 0.17.0", + "smithay-client-toolkit 0.18.0", "thiserror", "twox-hash", ] @@ -1829,7 +1829,7 @@ dependencies = [ [[package]] name = "iced_futures" version = "0.7.0" -source = "git+https://github.com/pop-os/libcosmic/#6b517ddb0e7fe2ed8b04d6f71d1c45a374c92e14" +source = "git+https://github.com/pop-os/libcosmic/#e0b34e5d289155ee1836af6fb6f74cd5bba9cf1c" dependencies = [ "futures", "iced_core", @@ -1842,7 +1842,7 @@ dependencies = [ [[package]] name = "iced_graphics" version = "0.9.0" -source = "git+https://github.com/pop-os/libcosmic/#6b517ddb0e7fe2ed8b04d6f71d1c45a374c92e14" +source = "git+https://github.com/pop-os/libcosmic/#e0b34e5d289155ee1836af6fb6f74cd5bba9cf1c" dependencies = [ "bitflags 1.3.2", "bytemuck", @@ -1860,7 +1860,7 @@ dependencies = [ [[package]] name = "iced_renderer" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic/#6b517ddb0e7fe2ed8b04d6f71d1c45a374c92e14" +source = "git+https://github.com/pop-os/libcosmic/#e0b34e5d289155ee1836af6fb6f74cd5bba9cf1c" dependencies = [ "iced_graphics", "iced_tiny_skia", @@ -1873,19 +1873,19 @@ dependencies = [ [[package]] name = "iced_runtime" version = "0.1.1" -source = "git+https://github.com/pop-os/libcosmic/#6b517ddb0e7fe2ed8b04d6f71d1c45a374c92e14" +source = "git+https://github.com/pop-os/libcosmic/#e0b34e5d289155ee1836af6fb6f74cd5bba9cf1c" dependencies = [ "iced_accessibility", "iced_core", "iced_futures", - "smithay-client-toolkit 0.17.0", + "smithay-client-toolkit 0.18.0", "thiserror", ] [[package]] name = "iced_sctk" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic/#6b517ddb0e7fe2ed8b04d6f71d1c45a374c92e14" +source = "git+https://github.com/pop-os/libcosmic/#e0b34e5d289155ee1836af6fb6f74cd5bba9cf1c" dependencies = [ "enum-repr", "float-cmp", @@ -1897,7 +1897,7 @@ dependencies = [ "itertools 0.10.5", "lazy_static", "raw-window-handle", - "smithay-client-toolkit 0.17.0", + "smithay-client-toolkit 0.18.0", "smithay-clipboard", "thiserror", "tracing", @@ -1909,7 +1909,7 @@ dependencies = [ [[package]] name = "iced_style" version = "0.9.0" -source = "git+https://github.com/pop-os/libcosmic/#6b517ddb0e7fe2ed8b04d6f71d1c45a374c92e14" +source = "git+https://github.com/pop-os/libcosmic/#e0b34e5d289155ee1836af6fb6f74cd5bba9cf1c" dependencies = [ "iced_core", "once_cell", @@ -1919,7 +1919,7 @@ dependencies = [ [[package]] name = "iced_tiny_skia" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic/#6b517ddb0e7fe2ed8b04d6f71d1c45a374c92e14" +source = "git+https://github.com/pop-os/libcosmic/#e0b34e5d289155ee1836af6fb6f74cd5bba9cf1c" dependencies = [ "bytemuck", "cosmic-text", @@ -1937,7 +1937,7 @@ dependencies = [ [[package]] name = "iced_wgpu" version = "0.11.1" -source = "git+https://github.com/pop-os/libcosmic/#6b517ddb0e7fe2ed8b04d6f71d1c45a374c92e14" +source = "git+https://github.com/pop-os/libcosmic/#e0b34e5d289155ee1836af6fb6f74cd5bba9cf1c" dependencies = [ "bitflags 1.3.2", "bytemuck", @@ -1959,14 +1959,14 @@ dependencies = [ [[package]] name = "iced_widget" version = "0.1.3" -source = "git+https://github.com/pop-os/libcosmic/#6b517ddb0e7fe2ed8b04d6f71d1c45a374c92e14" +source = "git+https://github.com/pop-os/libcosmic/#e0b34e5d289155ee1836af6fb6f74cd5bba9cf1c" dependencies = [ "iced_renderer", "iced_runtime", "iced_style", "num-traits", "ouroboros", - "smithay-client-toolkit 0.17.0", + "smithay-client-toolkit 0.18.0", "thiserror", "unicode-segmentation", ] @@ -2208,7 +2208,7 @@ checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" [[package]] name = "libcosmic" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic/#6b517ddb0e7fe2ed8b04d6f71d1c45a374c92e14" +source = "git+https://github.com/pop-os/libcosmic/#e0b34e5d289155ee1836af6fb6f74cd5bba9cf1c" dependencies = [ "apply", "ashpd", @@ -2409,6 +2409,24 @@ dependencies = [ "libc", ] +[[package]] +name = "memmap2" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a5a03cefb0d953ec0be133036f14e109412fa594edc2f77227249db66cc3ed" +dependencies = [ + "libc", +] + +[[package]] +name = "memmap2" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "deaba38d7abf1d4cca21cc89e932e542ba2b9258664d2a9ef0e61512039c9375" +dependencies = [ + "libc", +] + [[package]] name = "memoffset" version = "0.6.5" @@ -3596,7 +3614,34 @@ dependencies = [ "wayland-protocols 0.31.0", "wayland-protocols-wlr", "wayland-scanner 0.31.0", - "xkbcommon", + "xkbcommon 0.5.1", + "xkeysym", +] + +[[package]] +name = "smithay-client-toolkit" +version = "0.18.0" +source = "git+https://github.com/smithay/client-toolkit?rev=2e9bf9f#2e9bf9f31698851ca373e5f1e7ba3e6e804e4db1" +dependencies = [ + "bitflags 2.4.1", + "bytemuck", + "calloop", + "calloop-wayland-source", + "cursor-icon", + "libc", + "log", + "memmap2 0.9.0", + "pkg-config", + "rustix 0.38.21", + "thiserror", + "wayland-backend 0.3.2", + "wayland-client 0.31.1", + "wayland-csd-frame", + "wayland-cursor 0.31.0", + "wayland-protocols 0.31.0", + "wayland-protocols-wlr", + "wayland-scanner 0.31.0", + "xkbcommon 0.7.0", "xkeysym", ] @@ -3757,7 +3802,7 @@ dependencies = [ [[package]] name = "taffy" version = "0.3.11" -source = "git+https://github.com/DioxusLabs/taffy#d4374b93f0ec2c0ace42d3feafec22d3af1940d8" +source = "git+https://github.com/DioxusLabs/taffy#1876f72bee5e376023eaa518aa7b8a34c769bd1b" dependencies = [ "arrayvec", "grid", @@ -4920,6 +4965,17 @@ dependencies = [ "memmap2 0.7.1", ] +[[package]] +name = "xkbcommon" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13867d259930edc7091a6c41b4ce6eee464328c6ff9659b7e4c668ca20d4c91e" +dependencies = [ + "libc", + "memmap2 0.8.0", + "xkeysym", +] + [[package]] name = "xkeysym" version = "0.2.0" From aecff8e021501cf8ac654d44f04fb1af5cab3870 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Fri, 3 Nov 2023 17:00:18 +0100 Subject: [PATCH 2/3] app: Use xdg-activation --- src/app.rs | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/src/app.rs b/src/app.rs index 980abb5..64ed69c 100644 --- a/src/app.rs +++ b/src/app.rs @@ -22,6 +22,7 @@ use cosmic::iced_runtime::core::event::{wayland, PlatformSpecific}; use cosmic::iced_runtime::core::keyboard::KeyCode; use cosmic::iced_runtime::core::window::Id as SurfaceId; use cosmic::iced_sctk::commands; +use cosmic::iced_sctk::commands::activation::request_token; use cosmic::iced_sctk::commands::data_device::cancel_dnd; use cosmic::iced_style::application::{self, Appearance}; use cosmic::iced_widget::text_input::focus; @@ -38,7 +39,6 @@ use log::error; use once_cell::sync::Lazy; use crate::app_group::{AppLibraryConfig, DesktopEntryData}; -use crate::config::APP_ID; use crate::fl; use crate::subscriptions::desktop_files::desktop_files; use crate::subscriptions::toggle_dbus::dbus_toggle; @@ -110,6 +110,7 @@ enum Message { Hide, Clear, ActivateApp(usize), + ActivationToken(Option, String), SelectGroup(usize), Delete(usize), ConfirmDelete, @@ -225,20 +226,34 @@ impl cosmic::Application for CosmicAppLibrary { Message::ActivateApp(i) => { self.edit_name = None; if let Some(de) = self.entry_path_input.get(i) { - let mut exec = shlex::Shlex::new(&de.exec); - let mut cmd = match exec.next() { - Some(cmd) if !cmd.contains("=") => tokio::process::Command::new(cmd), - _ => return Command::none(), - }; - for arg in exec { - // TODO handle "%" args here if necessary? - if !arg.starts_with("%") { - cmd.arg(arg); - } + let exec = de.exec.clone(); + return request_token( + Some(String::from(Self::APP_ID)), + Some(WINDOW_ID), + move |token| { + cosmic::app::Message::App(Message::ActivationToken(token, exec)) + }, + ); + } + } + Message::ActivationToken(token, exec) => { + let mut exec = shlex::Shlex::new(&exec); + let mut cmd = match exec.next() { + Some(cmd) if !cmd.contains("=") => tokio::process::Command::new(cmd), + _ => return Command::none(), + }; + for arg in exec { + // TODO handle "%" args here if necessary? + if !arg.starts_with("%") { + cmd.arg(arg); } - let _ = cmd.spawn(); - return self.update(Message::Hide); } + if let Some(token) = token { + cmd.env("XDG_ACTIVATION_TOKEN", token.clone()); + cmd.env("DESKTOP_STARTUP_ID", token); + } + let _ = cmd.spawn(); + return self.update(Message::Hide); } Message::SelectGroup(i) => { self.edit_name = None; From 2a353310abd9da72aba10ebf4ce16f486db71cea Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Mon, 6 Nov 2023 17:05:48 +0100 Subject: [PATCH 3/3] app: Spawn using double-fork --- Cargo.lock | 1 + Cargo.toml | 1 + src/app.rs | 6 ++++-- src/main.rs | 1 + src/process.rs | 31 +++++++++++++++++++++++++++++++ 5 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 src/process.rs diff --git a/Cargo.lock b/Cargo.lock index ca43a60..45c79cd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -651,6 +651,7 @@ dependencies = [ "itertools 0.11.0", "libcosmic", "log", + "nix 0.26.4", "notify", "once_cell", "pretty_env_logger", diff --git a/Cargo.toml b/Cargo.toml index 4f7f073..433e5ee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,7 @@ itertools = "0.11" freedesktop-icons = "0.2.4" current_locale = "0.1.1" url = "2.4" +nix = "0.26" [profile.release] lto = "thin" diff --git a/src/app.rs b/src/app.rs index 64ed69c..be92036 100644 --- a/src/app.rs +++ b/src/app.rs @@ -239,7 +239,7 @@ impl cosmic::Application for CosmicAppLibrary { Message::ActivationToken(token, exec) => { let mut exec = shlex::Shlex::new(&exec); let mut cmd = match exec.next() { - Some(cmd) if !cmd.contains("=") => tokio::process::Command::new(cmd), + Some(cmd) if !cmd.contains("=") => std::process::Command::new(cmd), _ => return Command::none(), }; for arg in exec { @@ -252,7 +252,9 @@ impl cosmic::Application for CosmicAppLibrary { cmd.env("XDG_ACTIVATION_TOKEN", token.clone()); cmd.env("DESKTOP_STARTUP_ID", token); } - let _ = cmd.spawn(); + tokio::task::spawn_blocking(|| { + crate::process::spawn(cmd); + }); return self.update(Message::Hide); } Message::SelectGroup(i) => { diff --git a/src/main.rs b/src/main.rs index f8b5e7b..b004ef8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ mod config; mod app; mod app_group; mod localize; +pub mod process; mod subscriptions; mod widgets; diff --git a/src/process.rs b/src/process.rs new file mode 100644 index 0000000..1f58531 --- /dev/null +++ b/src/process.rs @@ -0,0 +1,31 @@ +use std::process::{exit, Command, Stdio}; + +use nix::sys::wait::waitpid; +use nix::unistd::{fork, ForkResult}; + +/// Performs a double fork with setsid to spawn and detach a command. +pub fn spawn(mut command: Command) { + command + .stdin(Stdio::null()) + .stdout(Stdio::null()) + .stderr(Stdio::null()); + + unsafe { + match fork() { + Ok(ForkResult::Parent { child }) => { + let _res = waitpid(Some(child), None); + } + + Ok(ForkResult::Child) => { + let _res = nix::unistd::setsid(); + let _res = command.spawn(); + + exit(0); + } + + Err(why) => { + println!("failed to fork and spawn command: {}", why.desc()); + } + } + } +}