From 2a25ab2319ee9531302ff6ca2bf23a122eeda266 Mon Sep 17 00:00:00 2001 From: Ottatop Date: Mon, 4 Mar 2024 16:43:54 -0600 Subject: [PATCH] Remove `state.pointer_location` --- src/api.rs | 11 +++++-- src/backend/udev.rs | 8 ++++- src/backend/winit.rs | 8 ++++- src/input.rs | 71 ++++++++++++++++---------------------------- src/state.rs | 4 +-- 5 files changed, 50 insertions(+), 52 deletions(-) diff --git a/src/api.rs b/src/api.rs index 5e96b94..bde064a 100644 --- a/src/api.rs +++ b/src/api.rs @@ -1518,7 +1518,11 @@ impl window_service_server::WindowService for WindowService { .ok_or_else(|| Status::invalid_argument("no button specified"))?; run_unary_no_response(&self.sender, move |state| { - let Some((pointer_focus, _)) = state.pointer_focus_target_under(state.pointer_location) + let Some(pointer_location) = state.seat.get_pointer().map(|ptr| ptr.current_location()) + else { + return; + }; + let Some((pointer_focus, _)) = state.pointer_focus_target_under(pointer_location) else { return; }; @@ -1553,7 +1557,10 @@ impl window_service_server::WindowService for WindowService { .ok_or_else(|| Status::invalid_argument("no button specified"))?; run_unary_no_response(&self.sender, move |state| { - let pointer_loc = state.pointer_location; + let Some(pointer_loc) = state.seat.get_pointer().map(|ptr| ptr.current_location()) + else { + return; + }; let Some((pointer_focus, window_loc)) = state.pointer_focus_target_under(pointer_loc) else { return; diff --git a/src/backend/udev.rs b/src/backend/udev.rs index 564efb6..1d0859e 100644 --- a/src/backend/udev.rs +++ b/src/backend/udev.rs @@ -1237,6 +1237,12 @@ impl State { let windows = self.space.elements().cloned().collect::>(); + let pointer_location = self + .seat + .get_pointer() + .map(|ptr| ptr.current_location()) + .unwrap_or((0.0, 0.0).into()); + let result = render_surface( surface, &mut renderer, @@ -1247,7 +1253,7 @@ impl State { &mut self.cursor_status, &pointer_image, &mut udev.pointer_element, - self.pointer_location, + pointer_location, &self.clock, ); diff --git a/src/backend/winit.rs b/src/backend/winit.rs index 33b6092..0ece68e 100644 --- a/src/backend/winit.rs +++ b/src/backend/winit.rs @@ -265,12 +265,18 @@ impl State { // of every event loop cycle let windows = self.space.elements().cloned().collect::>(); + let pointer_location = self + .seat + .get_pointer() + .map(|ptr| ptr.current_location()) + .unwrap_or((0.0, 0.0).into()); + let output_render_elements = crate::render::generate_render_elements( output, winit.backend.renderer(), &self.space, &windows, - self.pointer_location, + pointer_location, &mut self.cursor_status, self.dnd_icon.as_ref(), // self.seat.input_method(), diff --git a/src/input.rs b/src/input.rs index c6131cd..43cf370 100644 --- a/src/input.rs +++ b/src/input.rs @@ -494,37 +494,29 @@ impl State { nearest_point.map(|point| point.into()).unwrap_or(pos) } + /// Handle an absolute pointer motion event. + /// + /// This *should* only be generated on the winit backend. + /// Unless there's a case where it's generated on udev that I'm unaware of. fn pointer_motion_absolute(&mut self, event: I::PointerMotionAbsoluteEvent) { + let Some(pointer) = self.seat.get_pointer() else { + tracing::error!("Pointer motion absolute received with no pointer on seat"); + return; + }; + let Some(output) = self.space.outputs().next() else { return; }; - let output_geo = self - .space - .output_geometry(output) - .expect("Output geometry doesn't exist"); + let Some(output_geo) = self.space.output_geometry(output) else { + unreachable!("output should have a geometry as it was mapped"); + }; + let pointer_loc = event.position_transformed(output_geo.size) + output_geo.loc.to_f64(); let serial = SERIAL_COUNTER.next_serial(); - let pointer = self.seat.get_pointer().expect("Seat has no pointer"); // FIXME: handle err - self.pointer_location = pointer_loc; - - match self.output_focus_stack.current_focus() { - Some(_) => { - if let Some(output) = self - .space - .output_under(self.pointer_location) - .next() - .cloned() - { - self.output_focus_stack.set_focus(output); - } - } - None => { - if let Some(output) = self.space.outputs().next().cloned() { - self.output_focus_stack.set_focus(output); - } - } + if let Some(output) = self.space.output_under(pointer_loc).next().cloned() { + self.output_focus_stack.set_focus(output); } pointer.motion( @@ -541,40 +533,29 @@ impl State { } fn pointer_motion(&mut self, event: I::PointerMotionEvent) { - let serial = SERIAL_COUNTER.next_serial(); - self.pointer_location += event.delta(); + let Some(pointer) = self.seat.get_pointer() else { + tracing::error!("Pointer motion received with no pointer on seat"); + return; + }; + let mut pointer_loc = pointer.current_location(); // clamp to screen limits // this event is never generated by winit - self.pointer_location = self.clamp_coords(self.pointer_location); + pointer_loc = self.clamp_coords(pointer_loc); - match self.output_focus_stack.current_focus() { - Some(_) => { - if let Some(output) = self - .space - .output_under(self.pointer_location) - .next() - .cloned() - { - self.output_focus_stack.set_focus(output); - } - } - None => { - if let Some(output) = self.space.outputs().next().cloned() { - self.output_focus_stack.set_focus(output); - } - } + if let Some(output) = self.space.output_under(pointer_loc).next().cloned() { + self.output_focus_stack.set_focus(output); } - let surface_under = self.pointer_focus_target_under(self.pointer_location); + let surface_under = self.pointer_focus_target_under(pointer_loc); if let Some(pointer) = self.seat.get_pointer() { pointer.motion( self, surface_under.clone(), &MotionEvent { - location: self.pointer_location, - serial, + location: pointer_loc, + serial: SERIAL_COUNTER.next_serial(), time: event.time_msec(), }, ); diff --git a/src/state.rs b/src/state.rs index 622a9c4..e8133a5 100644 --- a/src/state.rs +++ b/src/state.rs @@ -17,7 +17,7 @@ use smithay::{ Display, DisplayHandle, }, }, - utils::{Clock, Logical, Monotonic, Point, Size}, + utils::{Clock, Monotonic, Point, Size}, wayland::{ compositor::{self, CompositorClientState, CompositorState}, dmabuf::DmabufFeedback, @@ -78,7 +78,6 @@ pub struct State { pub popup_manager: PopupManager, pub cursor_status: CursorImageStatus, - pub pointer_location: Point, pub dnd_icon: Option, /// The main window vec @@ -236,7 +235,6 @@ impl State { compositor_state: CompositorState::new::(&display_handle), data_device_state: DataDeviceState::new::(&display_handle), seat_state, - pointer_location: (0.0, 0.0).into(), shm_state: ShmState::new::(&display_handle, vec![]), space: Space::::default(), cursor_status: CursorImageStatus::default_named(),