pinnacle_api/
experimental.rs1#[cfg(feature = "snowcap")]
6pub use snowcap_api;
7
8#[cfg(feature = "snowcap")]
10pub mod input_grab {
11 use snowcap_api::{
12 input::Modifiers,
13 layer::LayerHandle,
14 widget::{Program, row::Row},
15 };
16 use xkbcommon::xkb::Keysym;
17
18 struct InputGrab;
19
20 impl Program for InputGrab {
21 type Message = ();
22
23 fn update(&mut self, _msg: Self::Message) {}
24
25 fn view(&self) -> Option<snowcap_api::widget::WidgetDef<Self::Message>> {
26 Some(
27 Row::new()
28 .width(snowcap_api::widget::Length::Fixed(1.0))
29 .height(snowcap_api::widget::Length::Fixed(1.0))
30 .into(),
31 )
32 }
33 }
34
35 pub struct InputGrabber(LayerHandle<()>);
37
38 impl InputGrabber {
39 pub fn stop(&self) {
41 self.0.close();
42 }
43 }
44
45 pub fn grab_input<F>(mut with_input: F)
68 where
69 F: FnMut(InputGrabber, Keysym, Modifiers) + Send + 'static,
70 {
71 let grabber = snowcap_api::layer::new_widget(
72 InputGrab,
73 None,
74 snowcap_api::layer::KeyboardInteractivity::Exclusive,
75 snowcap_api::layer::ExclusiveZone::Respect,
76 snowcap_api::layer::ZLayer::Overlay,
77 );
78
79 let grabber = match grabber {
80 Ok(grabber) => grabber,
81 Err(err) => {
82 println!("ERROR: failed to grab input: {err}");
83 return;
84 }
85 };
86
87 grabber.on_key_press(move |this, key, mods| {
88 with_input(InputGrabber(this), key, mods);
89 });
90 }
91}