From f31e33ad30f7a529cfeb9d37adb0d7d676477f91 Mon Sep 17 00:00:00 2001 From: Lysander Treumann Date: Sat, 31 Jan 2026 03:49:52 +0100 Subject: [PATCH] Added feature "action on typing", i.e. cosmic-workspaces opens cosmic-launcher or cosmic-app-library, if the setting is set. When opened by typing, cosmic-launcher or cosmic-app-library are closed when existing the workspaces overview. Changed exiting workspaces overview by pressing Escape from KeyReleased to KeyPressed to improve interaction between cosmic-workspaces and cosmic-launcher/cosmic-app-library. --- src/main.rs | 69 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 65fd6db..c6c5009 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,6 +38,7 @@ use std::{ collections::{HashMap, HashSet}, mem, path::PathBuf, + process::Command, str, time::Duration, }; @@ -118,6 +119,7 @@ enum Msg { DBus(dbus::Event), PanelContainerEntries(Vec), PanelConfig(CosmicPanelConfig), + ActionOnTyping(String), Ignore, } @@ -198,6 +200,7 @@ struct App { scroll: DiscreteScrollState, dbus_interface: Option, panel_configs: HashMap>, + action_on_typing_activated: bool, } #[derive(Debug, Default)] @@ -303,6 +306,33 @@ impl App { }); } + if self.action_on_typing_activated { + let cmd = match self.conf.workspace_config.action_on_typing { + cosmic_comp_config::workspace::Action::None => return Task::none(), + cosmic_comp_config::workspace::Action::OpenLauncher => { + // self.common.config.system_actions.get(&Launcher) + Some("cosmic-launcher \"$@\"".to_string()) + } + cosmic_comp_config::workspace::Action::OpenApplications => { + // self.common.config.system_actions.get(&Applications) + Some("cosmic-app-library \"$@\"".to_string()) + } + }; + if let Some(cmd) = cmd { + tokio::spawn(async { + let mut child = Command::new("/bin/sh") + .arg("-c") + .arg(cmd) + .arg("_") + .arg("close") + .spawn() + .unwrap(); + let _ = child.wait().unwrap(); + }); + } + } + self.action_on_typing_activated = false; + self.visible = false; self.update_capture_filter(); self.drag_surface = None; @@ -750,6 +780,31 @@ impl Application for App { Msg::PanelConfig(config) => { self.panel_configs.insert(config.name.clone(), Some(config)); } + Msg::ActionOnTyping(input) => { + let cmd = match self.conf.workspace_config.action_on_typing { + cosmic_comp_config::workspace::Action::None => return Task::none(), + cosmic_comp_config::workspace::Action::OpenLauncher => { + Some("cosmic-launcher \"$@\"".to_string()) + } + cosmic_comp_config::workspace::Action::OpenApplications => { + Some("cosmic-app-library \"$@\"".to_string()) + } + }; + if let Some(cmd) = cmd { + tokio::spawn(async { + let mut child = Command::new("/bin/sh") + .arg("-c") + .arg(cmd) + .arg("_") + .arg("input") + .arg(input) + .spawn() + .unwrap(); + let _ = child.wait().unwrap(); + }); + } + self.action_on_typing_activated = true; + } Msg::Ignore => {} } @@ -776,13 +831,17 @@ impl Application for App { None } } - iced::Event::Keyboard(iced::keyboard::Event::KeyReleased { + iced::Event::Keyboard(iced::keyboard::Event::KeyPressed { key: Key::Named(Named::Escape), - modifiers: _, - location: _, - modified_key: _, - physical_key: _, + .. }) => Some(Msg::Close), + iced::Event::Keyboard(iced::keyboard::Event::KeyPressed { + key: Key::Character(key), + modifiers, + .. + }) if !modifiers.control() && !modifiers.alt() && !modifiers.logo() => { + Some(Msg::ActionOnTyping(key.to_string())) + } // XXX Workaround for `on_finish`/`on_cancel` not being called, seemingly // due to state diffing behavior. iced::Event::Dnd(DndEvent::Source(SourceEvent::Finished | SourceEvent::Cancelled)) => {