Add --kill flag to quit-window

Implements: https://todo.sr.ht/~tsdh/swayr/11
timeout_old
Tassilo Horn 3 years ago
parent e7718597fe
commit 4ae50bbfc5
  1. 40
      Cargo.lock
  2. 2
      Cargo.toml
  3. 7
      NEWS.md
  4. 49
      src/cmds.rs

40
Cargo.lock generated

@ -42,9 +42,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "3.0.0-rc.5"
version = "3.0.0-rc.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d358d5dcd274692e60df775bd452f66341a49ab90cc6cc1084c4350a3f914d9"
checksum = "c7843ae7a539bef687e018bf9edf7e87728024b29d02b0f8409726be8880ae1a"
dependencies = [
"atty",
"bitflags",
@ -59,9 +59,9 @@ dependencies = [
[[package]]
name = "clap_derive"
version = "3.0.0-rc.5"
version = "3.0.0-rc.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a0823802ec32930a7b22133dc3a8b7cf297297e8af413e59d2fbbf864c7bd63"
checksum = "cae3cc2f259ea636871f5da15b0ac033f1821d7a5506c3d1bfbdde201f14c803"
dependencies = [
"heck",
"proc-macro-error",
@ -200,18 +200,18 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.34"
version = "1.0.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f84e92c0f7c9d58328b85a78557813e4bd845130db68d7184635344399423b1"
checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029"
dependencies = [
"unicode-xid",
]
[[package]]
name = "quote"
version = "1.0.10"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05"
checksum = "47aa80447ce4daf1717500037052af176af5d38cc3e571d9ec1c7353fc10c87d"
dependencies = [
"proc-macro2",
]
@ -300,18 +300,18 @@ checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f"
[[package]]
name = "serde"
version = "1.0.131"
version = "1.0.132"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4ad69dfbd3e45369132cc64e6748c2d65cdfb001a2b1c232d128b4ad60561c1"
checksum = "8b9875c23cf305cd1fd7eb77234cbb705f21ea6a72c637a5c6db5fe4b8e7f008"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.131"
version = "1.0.132"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b710a83c4e0dff6a3d511946b95274ad9ca9e5d3ae497b63fda866ac955358d2"
checksum = "ecc0db5cb2556c0e558887d9bbdcf6ac4471e83ff66cf696e5419024d1606276"
dependencies = [
"proc-macro2",
"quote",
@ -337,9 +337,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "swayipc"
version = "3.0.0-alpha.3"
version = "3.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9cd9a688c43e93f1e1d2b2366a5403815b8017dd5f9cdaf51ae8ae9ae8fba5d0"
checksum = "40cc7e2bba9f31e7c46b119d9c542496806b9114676d8f46aa5c9c950ececaec"
dependencies = [
"serde",
"serde_json",
@ -348,9 +348,9 @@ dependencies = [
[[package]]
name = "swayipc-types"
version = "1.0.0-alpha.3"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e125745767953fbbea5ba38caede26c89e4aeaf741afff7eb655967611b695d6"
checksum = "6d63c88513504fd598a6c2218bd83d19e1f8cc6dd1a9892f2f982b223f01a803"
dependencies = [
"serde",
"serde_json",
@ -374,9 +374,9 @@ dependencies = [
[[package]]
name = "syn"
version = "1.0.82"
version = "1.0.84"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8daf5dd0bb60cbd4137b1b587d2fc0ae729bc07cf01cd70b36a1ed5ade3b9d59"
checksum = "ecb2e6da8ee5eb9a61068762a32fa9619cc591ceb055b3687f4cd4051ec2e06b"
dependencies = [
"proc-macro2",
"quote",
@ -441,9 +441,9 @@ checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
[[package]]
name = "version_check"
version = "0.9.3"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "wasi"

@ -12,7 +12,7 @@ exclude = ["misc/"]
[dependencies]
serde = { version = "1.0.126", features = ["derive"] }
serde_json = "1.0.64"
clap = {version = "3.0.0-beta.2", features = ["derive"] }
clap = {version = "3.0.0-rc.9", features = ["derive"] }
swayipc = "3.0.0-alpha.3"
toml = "0.5.8"
directories = "4.0"

@ -1,3 +1,10 @@
swayr v0.12.0
=============
- The `quit-window` command now has an optional `--kill` / `-k` flag. If
given, the process of the window to be quit will be killed using `kill -9
<pid>` instead of just sending sending the `kill` IPC message to sway.
swayr v0.11.1
=============

@ -82,7 +82,14 @@ pub enum SwayrCommand {
/// container, or window.
SwitchTo,
/// Quit the selected window.
QuitWindow,
QuitWindow {
#[clap(
short,
long,
help = "Kill the window's process rather than just quitting it"
)]
kill: bool,
},
/// Quit all windows of selected workspace or the selected window.
QuitWorkspaceOrWindow,
/// Quit all windows of selected workspace, or container or the selected
@ -254,7 +261,9 @@ pub fn exec_swayr_cmd(args: ExecSwayrCmdArgs) {
switch_workspace_container_or_window(&*props.read().unwrap())
}
SwayrCommand::SwitchTo => switch_to(&*props.read().unwrap()),
SwayrCommand::QuitWindow => quit_window(&*props.read().unwrap()),
SwayrCommand::QuitWindow { kill } => {
quit_window(&*props.read().unwrap(), *kill)
}
SwayrCommand::QuitWorkspaceOrWindow => {
quit_workspace_or_window(&*props.read().unwrap())
}
@ -373,7 +382,6 @@ pub fn exec_swayr_cmd(args: ExecSwayrCmdArgs) {
SwayrCommand::MoveFocusedToWorkspace,
SwayrCommand::MoveFocusedTo,
SwayrCommand::SwapFocusedWith,
SwayrCommand::QuitWindow,
SwayrCommand::QuitWorkspaceOrWindow,
SwayrCommand::SwitchWindow,
SwayrCommand::SwitchWorkspace,
@ -400,6 +408,11 @@ pub fn exec_swayr_cmd(args: ExecSwayrCmdArgs) {
floating: f.clone(),
});
}
for kill in [false, true] {
cmds.push(SwayrCommand::QuitWindow { kill });
}
for w in [
ConsiderWindows::AllWorkspaces,
ConsiderWindows::CurrentWorkspace,
@ -593,7 +606,21 @@ pub fn switch_to(extra_props: &HashMap<i64, t::ExtraProps>) {
);
}
fn select_and_quit(prompt: &str, choices: &[t::DisplayNode]) {
fn kill_process_by_pid(pid: Option<i32>) {
if let Some(pid) = pid {
if let Err(err) = std::process::Command::new("kill")
.arg("-9")
.arg(format!("{}", pid))
.output()
{
eprintln!("Error killing process {}: {}", pid, err)
}
} else {
eprintln!("Cannot kill window with no pid.");
}
}
fn select_and_quit(prompt: &str, choices: &[t::DisplayNode], kill: bool) {
if let Ok(tn) = util::select_from_menu(prompt, choices) {
match tn.node.get_type() {
t::Type::Workspace | t::Type::Container => {
@ -603,7 +630,13 @@ fn select_and_quit(prompt: &str, choices: &[t::DisplayNode]) {
quit_window_by_id(win.id)
}
}
t::Type::Window => quit_window_by_id(tn.node.id),
t::Type::Window => {
if kill {
kill_process_by_pid(tn.node.pid)
} else {
quit_window_by_id(tn.node.id)
}
}
t => {
eprintln!("Cannot handle {:?} in quit_workspace_or_window", t)
}
@ -611,10 +644,10 @@ fn select_and_quit(prompt: &str, choices: &[t::DisplayNode]) {
}
}
pub fn quit_window(extra_props: &HashMap<i64, t::ExtraProps>) {
pub fn quit_window(extra_props: &HashMap<i64, t::ExtraProps>, kill: bool) {
let root = get_tree(true);
let tree = t::get_tree(&root, extra_props);
select_and_quit("Quit window", &tree.get_windows());
select_and_quit("Quit window", &tree.get_windows(), kill);
}
pub fn quit_workspace_or_window(extra_props: &HashMap<i64, t::ExtraProps>) {
@ -623,6 +656,7 @@ pub fn quit_workspace_or_window(extra_props: &HashMap<i64, t::ExtraProps>) {
select_and_quit(
"Quit workspace or window",
&tree.get_workspaces_and_windows(),
false,
);
}
@ -634,6 +668,7 @@ pub fn quit_workspace_container_or_window(
select_and_quit(
"Quit workspace, container or window",
&tree.get_workspaces_containers_and_windows(),
false,
);
}

Loading…
Cancel
Save