hyprshell_exec_lib/
binds.rs1use anyhow::Context;
2use core_lib::binds::ExecBind;
3use core_lib::{LAUNCHER_NAMESPACE, OVERVIEW_NAMESPACE, SWITCH_NAMESPACE};
4use hyprland::config::binds;
5use hyprland::config::binds::{Binder, Binding};
6use hyprland::dispatch::DispatchType;
7use hyprland::keyword::Keyword;
8use tracing::{trace, warn};
9
10pub fn apply_layerrules() -> anyhow::Result<()> {
11 Keyword::set("layerrule", format!("noanim, {LAUNCHER_NAMESPACE}"))?;
14 Keyword::set("layerrule", format!("xray 0, {LAUNCHER_NAMESPACE}"))?;
15
16 Keyword::set("layerrule", format!("noanim, {OVERVIEW_NAMESPACE}"))?;
17 Keyword::set("layerrule", format!("xray 0, {OVERVIEW_NAMESPACE}"))?;
18
19 Keyword::set("layerrule", format!("noanim, {SWITCH_NAMESPACE}"))?;
20 Keyword::set("layerrule", format!("dimaround, {SWITCH_NAMESPACE}"))?;
21 Keyword::set("layerrule", format!("xray 0, {SWITCH_NAMESPACE}"))?;
22 trace!("layerrules applied");
23 Ok(())
24}
25
26pub fn apply_exec_bind(bind: &ExecBind) -> anyhow::Result<()> {
29 let binding = Binding {
30 mods: bind
31 .mods
32 .iter()
33 .filter_map(|m| match m.to_lowercase().as_str() {
34 "alt" => Some(binds::Mod::ALT),
35 "control" | "ctrl" => Some(binds::Mod::CTRL),
36 "super" | "win" => Some(binds::Mod::SUPER),
37 "shift" => Some(binds::Mod::SHIFT),
38 _ => {
39 warn!("unknown mod: {m}");
40 None
41 }
42 })
43 .collect(),
44 key: binds::Key::Key(&bind.key),
45 flags: vec![],
46 dispatcher: DispatchType::Exec(&bind.exec),
47 };
48 trace!("binding exec: {binding:?}");
49 Binder::bind(binding).with_context(|| format!("binding exec failed: {bind:?}"))?;
50 Ok(())
51}