input: Try to fix multi-output pointer input

This commit is contained in:
Victoria Brekenfeld 2022-03-29 13:25:31 +02:00
parent 936356b312
commit 2c311c67d1
2 changed files with 52 additions and 19 deletions

View file

@ -347,8 +347,15 @@ impl Common {
.min((output_geometry.loc.y + output_geometry.size.h) as f64); .min((output_geometry.loc.y + output_geometry.size.h) as f64);
let serial = SERIAL_COUNTER.next_serial(); 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 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( handle_window_movement(
under.as_ref().map(|(s, _)| s), under.as_ref().map(|(s, _)| s),
&mut workspace.space, &mut workspace.space,
@ -380,11 +387,18 @@ impl Common {
if devices.has_device(&device) { if devices.has_device(&device) {
let output = active_output(seat, &self); let output = active_output(seat, &self);
let geometry = self.shell.output_geometry(&output); let geometry = self.shell.output_geometry(&output);
let workspace = self.shell.active_space_mut(&output);
let position = let position =
geometry.loc.to_f64() + event.position_transformed(geometry.size); 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 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( handle_window_movement(
under.as_ref().map(|(s, _)| s), under.as_ref().map(|(s, _)| s),
&mut workspace.space, &mut workspace.space,
@ -609,7 +623,8 @@ impl Common {
} }
pub fn surface_under( pub fn surface_under(
pos: Point<f64, Logical>, global_pos: Point<f64, Logical>,
relative_pos: Point<f64, Logical>,
output: &Output, output: &Output,
space: &Space, space: &Space,
) -> Option<(WlSurface, Point<i32, Logical>)> { ) -> Option<(WlSurface, Point<i32, Logical>)> {
@ -617,32 +632,47 @@ impl Common {
let output_geo = space.output_geometry(output).unwrap(); let output_geo = space.output_geometry(output).unwrap();
if let Some(layer) = layers if let Some(layer) = layers
.layer_under(WlrLayer::Overlay, pos) .layer_under(WlrLayer::Overlay, relative_pos)
.or_else(|| layers.layer_under(WlrLayer::Top, pos)) .or_else(|| layers.layer_under(WlrLayer::Top, relative_pos))
{ {
let layer_loc = layers.layer_geometry(layer).unwrap().loc; let layer_loc = layers.layer_geometry(layer).unwrap().loc;
layer layer
.surface_under( .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, WindowSurfaceType::ALL,
) )
.map(|(s, loc)| (s, loc + layer_loc)) .map(|(s, loc)| {
} else if let Some(window) = space.window_under(pos) { (
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(); let window_loc = space.window_location(window).unwrap();
window window
.surface_under(pos - window_loc.to_f64(), WindowSurfaceType::ALL) .surface_under(relative_pos - window_loc.to_f64(), WindowSurfaceType::ALL)
.map(|(s, loc)| (s, loc + window_loc)) .map(|(s, loc)| {
(
s,
loc + window_loc - (relative_pos - global_pos).to_i32_round(),
)
})
} else if let Some(layer) = layers } else if let Some(layer) = layers
.layer_under(WlrLayer::Bottom, pos) .layer_under(WlrLayer::Bottom, relative_pos)
.or_else(|| layers.layer_under(WlrLayer::Background, pos)) .or_else(|| layers.layer_under(WlrLayer::Background, relative_pos))
{ {
let layer_loc = layers.layer_geometry(layer).unwrap().loc; let layer_loc = layers.layer_geometry(layer).unwrap().loc;
layer layer
.surface_under( .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, WindowSurfaceType::ALL,
) )
.map(|(s, loc)| (s, loc + layer_loc)) .map(|(s, loc)| {
(
s,
loc + layer_loc - (relative_pos - global_pos).to_i32_round(),
)
})
} else { } else {
None None
} }

View file

@ -150,14 +150,17 @@ impl Shell {
Rectangle::from_loc_and_size((0, 0), size) Rectangle::from_loc_and_size((0, 0), size)
} }
pub fn space_relative_output_geometry( pub fn space_relative_output_geometry<C: smithay::utils::Coordinate>(
&self, &self,
global_loc: impl Into<Point<i32, Logical>>, global_loc: impl Into<Point<C, Logical>>,
output: &Output, output: &Output,
) -> Point<i32, Logical> { ) -> Point<C, Logical> {
match self.mode { match self.mode {
Mode::Global { .. } => global_loc.into(), 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()
}
} }
} }