forge
Explore
Log in

Don't you dare go Hollow

input: Simplify logic when cursor is outside outputs

Browse files at this commit

a413f3e91d3538cc16d82880129732df7e31ec86Ivan MolodetskikhParent: f381db8
src/input.rsmodified+5 -24
@@ -17,7 +17,7 @@ use smithay::wayland::tablet_manager::{TabletDescriptor, TabletSeatTrait};
17 17
18 use crate::config::{Action, Config, Modifiers};18 use crate::config::{Action, Config, Modifiers};
19 use crate::niri::State;19 use crate::niri::State;
20-use crate::utils::{get_monotonic_time, spawn};20+use crate::utils::{center, get_monotonic_time, spawn};
21 21
22 pub enum CompositorMod {22 pub enum CompositorMod {
23 Super,23 Super,
@@ -335,29 +335,10 @@ impl State {
335 .clamp(geom.loc.y as f64, (geom.loc.y + geom.size.h - 1) as f64);335 .clamp(geom.loc.y as f64, (geom.loc.y + geom.size.h - 1) as f64);
336 } else {336 } else {
337 // The pointer was not on any output in the first place. Find one for it.337 // The pointer was not on any output in the first place. Find one for it.
338- // Start by clamping the X coordinate.338+ // Let's do the simple thing and just put it on the first output.
339- let mut min_x = i32::MAX;339+ let output = self.niri.global_space.outputs().next().unwrap();
340- let mut max_x = 0;340+ let geom = self.niri.global_space.output_geometry(output).unwrap();
341- for output in self.niri.global_space.outputs() {341+ new_pos = center(geom).to_f64();
342- let geom = self.niri.global_space.output_geometry(output).unwrap();
343- min_x = min_x.min(geom.loc.x);
344- max_x = max_x.max(geom.loc.x + geom.size.w);
345- }
346-
347- new_pos.x = new_pos.x.clamp(min_x as f64, (max_x - 1) as f64);
348-
349- // Now clamp the Y coordinate. Assume every X from min to max has some
350- // output.
351- let geom = self
352- .niri
353- .global_space
354- .outputs()
355- .map(|output| self.niri.global_space.output_geometry(output).unwrap())
356- .find(|geom| geom.contains((new_pos.x as i32, geom.loc.y)))
357- .unwrap();
358- new_pos.y = new_pos
359- .y
360- .clamp(geom.loc.y as f64, (geom.loc.y + geom.size.h - 1) as f64);
361 }342 }
362 }343 }
363 344