hyprshell-exec-lib 4.9.5

A modern GTK4-based window switcher and application launcher for Hyprland
Documentation
use anyhow::Context;
use core_lib::binds::ExecBind;
use core_lib::{LAUNCHER_NAMESPACE, OVERVIEW_NAMESPACE, SWITCH_NAMESPACE};
use hyprland::config::binds;
use hyprland::config::binds::{Binder, Binding};
use hyprland::dispatch::DispatchType;
use hyprland::keyword::Keyword;
use tracing::{trace, warn};

pub fn apply_layerrules() -> anyhow::Result<()> {
    // TODO add option to enable blur

    Keyword::set("layerrule", format!("noanim, {LAUNCHER_NAMESPACE}"))?;
    Keyword::set("layerrule", format!("xray 0, {LAUNCHER_NAMESPACE}"))?;

    Keyword::set("layerrule", format!("noanim, {OVERVIEW_NAMESPACE}"))?;
    Keyword::set("layerrule", format!("xray 0, {OVERVIEW_NAMESPACE}"))?;

    Keyword::set("layerrule", format!("noanim, {SWITCH_NAMESPACE}"))?;
    Keyword::set("layerrule", format!("dimaround, {SWITCH_NAMESPACE}"))?;
    Keyword::set("layerrule", format!("xray 0, {SWITCH_NAMESPACE}"))?;
    trace!("layerrules applied");
    Ok(())
}

// ctrl+shift+alt, h
// hyprland::bind!(d e | SUPER, Key, "a" => Exec, "pkill hyprshell");
pub fn apply_exec_bind(bind: &ExecBind) -> anyhow::Result<()> {
    let binding = Binding {
        mods: bind
            .mods
            .iter()
            .filter_map(|m| match m.to_lowercase().as_str() {
                "alt" => Some(binds::Mod::ALT),
                "control" | "ctrl" => Some(binds::Mod::CTRL),
                "super" | "win" => Some(binds::Mod::SUPER),
                "shift" => Some(binds::Mod::SHIFT),
                _ => {
                    warn!("unknown mod: {m}");
                    None
                }
            })
            .collect(),
        key: binds::Key::Key(&bind.key),
        flags: vec![],
        dispatcher: DispatchType::Exec(&bind.exec),
    };
    trace!("binding exec: {binding:?}");
    Binder::bind(binding).with_context(|| format!("binding exec failed: {bind:?}"))?;
    Ok(())
}