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}"))?;
12 Keyword::set("layerrule", format!("ignorezero, {LAUNCHER_NAMESPACE}"))?;
13 Keyword::set("layerrule", format!("blur, {LAUNCHER_NAMESPACE}"))?;
14 Keyword::set("layerrule", format!("xray 0, {LAUNCHER_NAMESPACE}"))?;
15 Keyword::set("layerrule", format!("blurpopups, {LAUNCHER_NAMESPACE}"))?;
16
17 Keyword::set("layerrule", format!("noanim, {OVERVIEW_NAMESPACE}"))?;
18 Keyword::set("layerrule", format!("dimaround, {OVERVIEW_NAMESPACE}"))?;
19 Keyword::set("layerrule", format!("ignorezero, {OVERVIEW_NAMESPACE}"))?;
20 Keyword::set("layerrule", format!("blur, {OVERVIEW_NAMESPACE}"))?;
21 Keyword::set("layerrule", format!("xray 0, {OVERVIEW_NAMESPACE}"))?;
22 Keyword::set("layerrule", format!("blurpopups, {OVERVIEW_NAMESPACE}"))?;
23
24 Keyword::set("layerrule", format!("noanim, {SWITCH_NAMESPACE}"))?;
25 Keyword::set("layerrule", format!("dimaround, {SWITCH_NAMESPACE}"))?;
26 Keyword::set("layerrule", format!("ignorezero, {SWITCH_NAMESPACE}"))?;
27 Keyword::set("layerrule", format!("blur, {SWITCH_NAMESPACE}"))?;
28 Keyword::set("layerrule", format!("xray 0, {SWITCH_NAMESPACE}"))?;
29 Keyword::set("layerrule", format!("blurpopups, {SWITCH_NAMESPACE}"))?;
30 trace!("layerrules applied");
31 Ok(())
32}
33
34pub fn apply_exec_bind(bind: &ExecBind) -> anyhow::Result<()> {
37 let binding = Binding {
38 mods: bind
39 .mods
40 .iter()
41 .filter_map(|m| match m.to_lowercase().as_str() {
42 "alt" => Some(binds::Mod::ALT),
43 "control" | "ctrl" => Some(binds::Mod::CTRL),
44 "super" | "win" => Some(binds::Mod::SUPER),
45 "shift" => Some(binds::Mod::SHIFT),
46 _ => {
47 warn!("unknown mod: {m}");
48 None
49 }
50 })
51 .collect(),
52 key: binds::Key::Key(&bind.key),
53 flags: vec![],
54 dispatcher: DispatchType::Exec(&bind.exec),
55 };
56 trace!("binding exec: {binding:?}");
57 Binder::bind(binding).with_context(|| format!("binding exec failed: {bind:?}"))?;
58 Ok(())
59}