hyprshell_exec_lib/
binds.rs1use anyhow::Context;
2use core_lib::binds::ExecBind;
3use core_lib::config::Mod;
4use core_lib::{LAUNCHER_NAMESPACE, OVERVIEW_NAMESPACE, SWITCH_NAMESPACE};
5use hyprland::config::binds;
6use hyprland::config::binds::{Binder, Binding, Flag};
7use hyprland::dispatch::DispatchType;
8use hyprland::keyword::Keyword;
9use tracing::trace;
10
11pub fn apply_layerrules() -> anyhow::Result<()> {
12 Keyword::set("layerrule", format!("noanim, {LAUNCHER_NAMESPACE}"))?;
13 Keyword::set("layerrule", format!("ignorezero, {LAUNCHER_NAMESPACE}"))?;
14 Keyword::set("layerrule", format!("noanim, {OVERVIEW_NAMESPACE}"))?;
15 Keyword::set("layerrule", format!("dimaround, {OVERVIEW_NAMESPACE}"))?;
16 Keyword::set("layerrule", format!("ignorezero, {OVERVIEW_NAMESPACE}"))?;
17 Keyword::set("layerrule", format!("noanim, {SWITCH_NAMESPACE}"))?;
18 Keyword::set("layerrule", format!("dimaround, {SWITCH_NAMESPACE}"))?;
19 Keyword::set("layerrule", format!("ignorezero, {SWITCH_NAMESPACE}"))?;
20 Ok(())
21}
22
23pub fn apply_exec_bind(bind: &ExecBind) -> anyhow::Result<()> {
26 let binding = Binding {
27 mods: bind
28 .mods
29 .iter()
30 .map(|m| match m {
31 Mod::Alt => binds::Mod::ALT,
32 Mod::Ctrl => binds::Mod::CTRL,
33 Mod::Super => binds::Mod::SUPER,
34 Mod::Shift => binds::Mod::SHIFT,
35 })
36 .collect(),
37 key: binds::Key::Key(&bind.key),
38 flags: if bind.on_release {
39 vec![Flag::r, Flag::t]
40 } else {
41 vec![]
42 },
43 dispatcher: DispatchType::Exec(&bind.exec),
44 };
45 trace!("binding exec: {binding:?}");
46 Binder::bind(binding).with_context(|| format!("binding exec failed: {bind:?}"))?;
47 Ok(())
48}