From 2c311c67d1a75d20f967446b78951f934e8395db Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Tue, 29 Mar 2022 13:25:31 +0200 Subject: [PATCH] input: Try to fix multi-output pointer input --- src/input/mod.rs | 60 ++++++++++++++++++++++++++++++++++++------------ src/shell/mod.rs | 11 +++++---- 2 files changed, 52 insertions(+), 19 deletions(-) diff --git a/src/input/mod.rs b/src/input/mod.rs index 114222fb..5dcebd72 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -347,8 +347,15 @@ impl Common { .min((output_geometry.loc.y + output_geometry.size.h) as f64); let serial = SERIAL_COUNTER.next_serial(); + let relative_pos = + self.shell.space_relative_output_geometry(position, &output); let workspace = self.shell.active_space_mut(&output); - let under = Common::surface_under(position, &output, &workspace.space); + let under = Common::surface_under( + position, + relative_pos, + &output, + &workspace.space, + ); handle_window_movement( under.as_ref().map(|(s, _)| s), &mut workspace.space, @@ -380,11 +387,18 @@ impl Common { if devices.has_device(&device) { let output = active_output(seat, &self); let geometry = self.shell.output_geometry(&output); - let workspace = self.shell.active_space_mut(&output); let position = geometry.loc.to_f64() + event.position_transformed(geometry.size); + let relative_pos = + self.shell.space_relative_output_geometry(position, &output); + let workspace = self.shell.active_space_mut(&output); let serial = SERIAL_COUNTER.next_serial(); - let under = Common::surface_under(position, &output, &workspace.space); + let under = Common::surface_under( + position, + relative_pos, + &output, + &workspace.space, + ); handle_window_movement( under.as_ref().map(|(s, _)| s), &mut workspace.space, @@ -609,7 +623,8 @@ impl Common { } pub fn surface_under( - pos: Point, + global_pos: Point, + relative_pos: Point, output: &Output, space: &Space, ) -> Option<(WlSurface, Point)> { @@ -617,32 +632,47 @@ impl Common { let output_geo = space.output_geometry(output).unwrap(); if let Some(layer) = layers - .layer_under(WlrLayer::Overlay, pos) - .or_else(|| layers.layer_under(WlrLayer::Top, pos)) + .layer_under(WlrLayer::Overlay, relative_pos) + .or_else(|| layers.layer_under(WlrLayer::Top, relative_pos)) { let layer_loc = layers.layer_geometry(layer).unwrap().loc; layer .surface_under( - pos - output_geo.loc.to_f64() - layer_loc.to_f64(), + relative_pos - output_geo.loc.to_f64() - layer_loc.to_f64(), WindowSurfaceType::ALL, ) - .map(|(s, loc)| (s, loc + layer_loc)) - } else if let Some(window) = space.window_under(pos) { + .map(|(s, loc)| { + ( + s, + loc + layer_loc - (relative_pos - global_pos).to_i32_round(), + ) + }) + } else if let Some(window) = space.window_under(relative_pos) { let window_loc = space.window_location(window).unwrap(); window - .surface_under(pos - window_loc.to_f64(), WindowSurfaceType::ALL) - .map(|(s, loc)| (s, loc + window_loc)) + .surface_under(relative_pos - window_loc.to_f64(), WindowSurfaceType::ALL) + .map(|(s, loc)| { + ( + s, + loc + window_loc - (relative_pos - global_pos).to_i32_round(), + ) + }) } else if let Some(layer) = layers - .layer_under(WlrLayer::Bottom, pos) - .or_else(|| layers.layer_under(WlrLayer::Background, pos)) + .layer_under(WlrLayer::Bottom, relative_pos) + .or_else(|| layers.layer_under(WlrLayer::Background, relative_pos)) { let layer_loc = layers.layer_geometry(layer).unwrap().loc; layer .surface_under( - pos - output_geo.loc.to_f64() - layer_loc.to_f64(), + relative_pos - output_geo.loc.to_f64() - layer_loc.to_f64(), WindowSurfaceType::ALL, ) - .map(|(s, loc)| (s, loc + layer_loc)) + .map(|(s, loc)| { + ( + s, + loc + layer_loc - (relative_pos - global_pos).to_i32_round(), + ) + }) } else { None } diff --git a/src/shell/mod.rs b/src/shell/mod.rs index d3efd4af..af9f13dc 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -150,14 +150,17 @@ impl Shell { Rectangle::from_loc_and_size((0, 0), size) } - pub fn space_relative_output_geometry( + pub fn space_relative_output_geometry( &self, - global_loc: impl Into>, + global_loc: impl Into>, output: &Output, - ) -> Point { + ) -> Point { match self.mode { Mode::Global { .. } => global_loc.into(), - Mode::OutputBound => global_loc.into() - self.output_geometry(output).loc, + Mode::OutputBound => { + let p = global_loc.into().to_f64() - self.output_geometry(output).loc.to_f64(); + (C::from_f64(p.x), C::from_f64(p.y)).into() + } } }