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) -> snowcap_api::widget::WidgetDef<Self::Message> {
26 Row::new()
27 .width(snowcap_api::widget::Length::Fixed(1.0))
28 .height(snowcap_api::widget::Length::Fixed(1.0))
29 .into()
30 }
31 }
32
33 pub struct InputGrabber(LayerHandle<()>);
35
36 impl InputGrabber {
37 pub fn stop(&self) {
39 self.0.close();
40 }
41 }
42
43 pub fn grab_input<F>(mut with_input: F)
66 where
67 F: FnMut(InputGrabber, Keysym, Modifiers) + Send + 'static,
68 {
69 let grabber = snowcap_api::layer::new_widget(
70 InputGrab,
71 None,
72 snowcap_api::layer::KeyboardInteractivity::Exclusive,
73 snowcap_api::layer::ExclusiveZone::Respect,
74 snowcap_api::layer::ZLayer::Overlay,
75 );
76
77 let grabber = match grabber {
78 Ok(grabber) => grabber,
79 Err(err) => {
80 println!("ERROR: failed to grab input: {err}");
81 return;
82 }
83 };
84
85 grabber.on_key_press(move |this, key, mods| {
86 with_input(InputGrabber(this), key, mods);
87 });
88 }
89}