Skip to main content

hyprshell_exec_lib/
kill.rs

1use crate::util::to_client_address;
2use anyhow::Context;
3use core_lib::ClientId;
4use hyprland::data::Clients;
5use hyprland::dispatch::{Dispatch, DispatchType, WindowIdentifier};
6use hyprland::prelude::HyprData;
7use std::thread;
8use std::time::Duration;
9use tracing::instrument;
10
11/// Sends a close window request to hyprland and waits for the client to be killed
12///
13/// Returns true if the client was killed successfully, false if close was interrupted
14#[instrument(level = "debug", ret(level = "trace"))]
15pub fn kill_client_blocking(address: ClientId, timeout: Duration) -> anyhow::Result<bool> {
16    Dispatch::call(DispatchType::CloseWindow(WindowIdentifier::Address(
17        to_client_address(address),
18    )))?;
19    thread::sleep(timeout);
20    let client = Clients::get()
21        .context("get clients failed")?
22        .into_iter()
23        .find(|c| c.address == to_client_address(address));
24
25    Ok(client.is_none())
26}