Skip to content

Commit

Permalink
new: add -p, --passthrough to ignore input
Browse files Browse the repository at this point in the history
fixes #11
  • Loading branch information
marcelohdez committed Nov 5, 2024
1 parent 3540fcd commit 79282a2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
16 changes: 13 additions & 3 deletions src/dim.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -51,6 +51,7 @@ pub struct DimData {
viewporter: SimpleGlobal<WpViewporter, 1>,

alpha: f32,
passthrough: bool,
views: Vec<DimView>,

keyboard: Option<wl_keyboard::WlKeyboard>,
Expand All @@ -76,6 +77,7 @@ impl DimData {
qh: &QueueHandle<Self>,
layer_shell: LayerShell,
alpha: f32,
passthrough: bool,
) -> Self {
Self {
compositor,
Expand All @@ -89,6 +91,7 @@ impl DimData {
.expect("wp_viewporter not available"),

alpha,
passthrough,
views: Vec::new(),

exit: false,
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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");
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -72,7 +72,7 @@ fn get_config(dir: Option<&Path>) -> anyhow::Result<Option<DimOpts>> {
Ok(Some(config))
}

fn create_wl_app(alpha: f32) -> anyhow::Result<(DimData, EventQueue<DimData>)> {
fn create_wl_app(alpha: f32, passthrough: bool) -> anyhow::Result<(DimData, EventQueue<DimData>)> {
let conn = Connection::connect_to_env().context("Failed to connect to environment")?;

let (globals, event_queue) =
Expand All @@ -83,7 +83,7 @@ fn create_wl_app(alpha: f32) -> anyhow::Result<(DimData, EventQueue<DimData>)> {
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,
))
}
8 changes: 8 additions & 0 deletions src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ pub struct DimOpts {
)]
pub alpha: Option<f32>,

#[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<PathBuf>,
Expand All @@ -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
}
Expand Down

0 comments on commit 79282a2

Please sign in to comment.