Merge pull request #276 from SammyMcFly/action-on-typing
feat: "action on typing"
This commit is contained in:
commit
abf1bb8885
3 changed files with 67 additions and 8 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
|
@ -1107,8 +1107,8 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "cosmic-comp-config"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/pop-os/cosmic-comp#84f1d6b7a97516bacb4d10b680e9154caa4272b5"
|
||||
version = "1.0.0"
|
||||
source = "git+https://github.com/pop-os/cosmic-comp?branch=action-on-typing#df7819b2b24bb6b66ca97a2456572410f3e05521"
|
||||
dependencies = [
|
||||
"cosmic-config",
|
||||
"input",
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ anyhow = "1.0.99"
|
|||
calloop = { version = "0.14.3", features = ["executor"] }
|
||||
clap = { version = "4", features = ["derive"] }
|
||||
cosmic-bg-config = { git = "https://github.com/pop-os/cosmic-bg" }
|
||||
cosmic-comp-config = { git = "https://github.com/pop-os/cosmic-comp" }
|
||||
cosmic-comp-config = { git = "https://github.com/pop-os/cosmic-comp", branch = "action-on-typing" }
|
||||
env_logger = "0.11.8"
|
||||
futures-channel = "0.3.31"
|
||||
gbm = "0.18.0"
|
||||
|
|
|
|||
69
src/main.rs
69
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<String>),
|
||||
PanelConfig(CosmicPanelConfig),
|
||||
ActionOnTyping(String),
|
||||
Ignore,
|
||||
}
|
||||
|
||||
|
|
@ -198,6 +200,7 @@ struct App {
|
|||
scroll: DiscreteScrollState,
|
||||
dbus_interface: Option<dbus::Interface>,
|
||||
panel_configs: HashMap<String, Option<CosmicPanelConfig>>,
|
||||
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)) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue