hyprshell-exec-lib 4.10.9

A modern GTK4-based window switcher and application launcher for Hyprland
Documentation
use core_lib::binds::ExecBind;
use core_lib::{LAUNCHER_NAMESPACE, OVERVIEW_NAMESPACE, SWITCH_NAMESPACE};
use hyprland::bind_new::{Binding, Flag, Mod};
use hyprland::dispatch_new::Dispatch;
use hyprland::window_rule::{LayerEffect, LayerMatch, LayerRule};
use tracing::{trace, warn};

pub fn apply_layerrules() -> anyhow::Result<()> {
    // TODO add option to enable blur
    let rules = vec![
        LayerRule {
            name: None,
            r#match: vec![LayerMatch::Namespace(LAUNCHER_NAMESPACE.into())],
            effects: vec![LayerEffect::NoAnim(true), LayerEffect::Xray(false)],
        },
        LayerRule {
            name: None,
            r#match: vec![LayerMatch::Namespace(OVERVIEW_NAMESPACE.into())],
            effects: vec![LayerEffect::NoAnim(true), LayerEffect::Xray(false)],
        },
        LayerRule {
            name: None,
            r#match: vec![LayerMatch::Namespace(SWITCH_NAMESPACE.into())],
            effects: vec![
                LayerEffect::NoAnim(true),
                LayerEffect::Xray(false),
                LayerEffect::DimAround(true),
            ],
        },
    ];

    for rule in rules {
        rule.apply()?;
    }
    Ok(())
}

pub fn apply_exec_bind(bind: &ExecBind) -> anyhow::Result<()> {
    let binds: Vec<_> = bind
        .mods
        .iter()
        .filter_map(|m| match m.to_lowercase().as_str() {
            "alt" => Some(Mod::Alt),
            "control" | "ctrl" => Some(Mod::Ctrl),
            "super" | "win" => Some(Mod::Super),
            "shift" => Some(Mod::Shift),
            _ => {
                warn!("unknown mod: {m}");
                None
            }
        })
        .collect();
    let desc = format!("hyprshell-keybind: {}", bind.desc);

    let binding = Binding {
        mods: binds,
        key: bind.key.to_string(),
        flags: {
            let mut flags = vec![Flag::AutoConsuming, Flag::Description(desc)];
            if bind.release {
                flags.push(Flag::Release);
            } else {
                flags.push(Flag::Repeating);
            }
            if bind.transparent {
                flags.push(Flag::Transparent);
            }
            flags
        },
        dispatcher: Dispatch::ExecCmd(bind.exec.clone(), None),
    };
    trace!("binding exec: {binding:?}");
    binding.unbind()?;
    binding.bind()?;
    Ok(())
}