diff --git a/src/dim.rs b/src/dim.rs index 87a211d..188b220 100644 --- a/src/dim.rs +++ b/src/dim.rs @@ -1,6 +1,6 @@ use log::{debug, error}; use smithay_client_toolkit::{ - compositor::{CompositorHandler, CompositorState}, + compositor::{CompositorHandler, CompositorState, Region}, delegate_compositor, delegate_keyboard, delegate_layer, delegate_output, delegate_pointer, delegate_registry, delegate_seat, delegate_simple, delegate_touch, output::{OutputHandler, OutputState}, @@ -51,6 +51,7 @@ pub struct DimData { viewporter: SimpleGlobal, alpha: f32, + passthrough: bool, views: Vec, keyboard: Option, @@ -76,6 +77,7 @@ impl DimData { qh: &QueueHandle, layer_shell: LayerShell, alpha: f32, + passthrough: bool, ) -> Self { Self { compositor, @@ -89,6 +91,7 @@ impl DimData { .expect("wp_viewporter not available"), alpha, + passthrough, views: Vec::new(), exit: false, @@ -121,8 +124,15 @@ impl DimData { (INIT_SIZE, INIT_SIZE) }; + if self.passthrough { + let input_region = Region::new(&self.compositor).expect("Failed to get a wl_region"); + layer.set_keyboard_interactivity(KeyboardInteractivity::None); + layer.set_input_region(Some(input_region.wl_region())); + } else { + layer.set_keyboard_interactivity(KeyboardInteractivity::Exclusive); + } + layer.set_exclusive_zone(-1); - layer.set_keyboard_interactivity(KeyboardInteractivity::Exclusive); layer.set_size(width, height); layer.commit(); @@ -435,7 +445,7 @@ impl PointerHandler for DimData { if self.alpha == 1.0 { pointer.set_cursor(serial, None, 0, 0); } - }, + } PointerEventKind::Leave { .. } => {} _ => { debug!("Mouse event"); diff --git a/src/main.rs b/src/main.rs index 4b2ce0f..20846f1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,7 +38,7 @@ fn main() -> anyhow::Result<()> { }); } - let (mut data, mut event_queue) = create_wl_app(alpha)?; + let (mut data, mut event_queue) = create_wl_app(alpha, opts.passthrough)?; while !data.should_exit() { event_queue .blocking_dispatch(&mut data) @@ -72,7 +72,7 @@ fn get_config(dir: Option<&Path>) -> anyhow::Result> { Ok(Some(config)) } -fn create_wl_app(alpha: f32) -> anyhow::Result<(DimData, EventQueue)> { +fn create_wl_app(alpha: f32, passthrough: bool) -> anyhow::Result<(DimData, EventQueue)> { let conn = Connection::connect_to_env().context("Failed to connect to environment")?; let (globals, event_queue) = @@ -83,7 +83,7 @@ fn create_wl_app(alpha: f32) -> anyhow::Result<(DimData, EventQueue)> { let layer_shell = LayerShell::bind(&globals, &qh).context("Layer shell failed?")?; Ok(( - DimData::new(compositor, &globals, &qh, layer_shell, alpha), + DimData::new(compositor, &globals, &qh, layer_shell, alpha, passthrough), event_queue, )) } diff --git a/src/opts.rs b/src/opts.rs index 46e8312..b332ee3 100644 --- a/src/opts.rs +++ b/src/opts.rs @@ -24,6 +24,13 @@ pub struct DimOpts { )] pub alpha: Option, + #[arg( + short, + long, + help = "Make dim ignore input, passing it to lower surfaces. (You probably want to use `-d 0` with this)" + )] + pub passthrough: bool, + #[serde(skip)] #[arg(long, value_name = "PATH", help = "Generate completions at given path")] pub gen_completions: Option, @@ -50,6 +57,7 @@ impl DimOpts { Self { duration: other.duration.or(self.duration), alpha: other.alpha.or(self.alpha), + passthrough: self.passthrough || other.passthrough, ..self }