Track tablet pointer separately, don't sent wl_pointer events
Browse files at this commitcb1e5d6c192d58c33229c32e34628ecadf84c02fParent: 11ae17b2 changed files +76 -53
- src/input.rs +39 -46
- src/niri.rs +37 -7
src/input.rsmodified+39 -46
| @@ -439,6 +439,9 @@ impl State { | |||
| 439 | 439 | ||
| 440 | pointer.frame(self); | 440 | pointer.frame(self); |
| 441 | 441 | ||
| 442 | + // We moved the regular pointer, so show it now. | ||
| 443 | + self.niri.tablet_cursor_location = None; | ||
| 444 | + | ||
| 442 | // Redraw to update the cursor position. | 445 | // Redraw to update the cursor position. |
| 443 | // FIXME: redraw only outputs overlapping the cursor. | 446 | // FIXME: redraw only outputs overlapping the cursor. |
| 444 | self.niri.queue_redraw_all(); | 447 | self.niri.queue_redraw_all(); |
| @@ -487,6 +490,9 @@ impl State { | |||
| 487 | 490 | ||
| 488 | pointer.frame(self); | 491 | pointer.frame(self); |
| 489 | 492 | ||
| 493 | + // We moved the regular pointer, so show it now. | ||
| 494 | + self.niri.tablet_cursor_location = None; | ||
| 495 | + | ||
| 490 | // Redraw to update the cursor position. | 496 | // Redraw to update the cursor position. |
| 491 | // FIXME: redraw only outputs overlapping the cursor. | 497 | // FIXME: redraw only outputs overlapping the cursor. |
| 492 | self.niri.queue_redraw_all(); | 498 | self.niri.queue_redraw_all(); |
| @@ -596,25 +602,9 @@ impl State { | |||
| 596 | return; | 602 | return; |
| 597 | }; | 603 | }; |
| 598 | 604 | ||
| 599 | - let serial = SERIAL_COUNTER.next_serial(); | ||
| 600 | - | ||
| 601 | - let pointer = self.niri.seat.get_pointer().unwrap(); | ||
| 602 | - | ||
| 603 | let under = self.niri.surface_under_and_global_space(pos); | 605 | let under = self.niri.surface_under_and_global_space(pos); |
| 604 | - self.niri.pointer_focus = under.clone(); | ||
| 605 | let under = under.map(|u| u.surface); | 606 | let under = under.map(|u| u.surface); |
| 606 | 607 | ||
| 607 | - pointer.motion( | ||
| 608 | - self, | ||
| 609 | - under.clone(), | ||
| 610 | - &MotionEvent { | ||
| 611 | - location: pos, | ||
| 612 | - serial, | ||
| 613 | - time: event.time_msec(), | ||
| 614 | - }, | ||
| 615 | - ); | ||
| 616 | - pointer.frame(self); | ||
| 617 | - | ||
| 618 | let tablet_seat = self.niri.seat.tablet_seat(); | 608 | let tablet_seat = self.niri.seat.tablet_seat(); |
| 619 | let tablet = tablet_seat.get_tablet(&TabletDescriptor::from(&event.device())); | 609 | let tablet = tablet_seat.get_tablet(&TabletDescriptor::from(&event.device())); |
| 620 | let tool = tablet_seat.get_tool(&event.tool()); | 610 | let tool = tablet_seat.get_tool(&event.tool()); |
| @@ -645,6 +635,8 @@ impl State { | |||
| 645 | SERIAL_COUNTER.next_serial(), | 635 | SERIAL_COUNTER.next_serial(), |
| 646 | event.time_msec(), | 636 | event.time_msec(), |
| 647 | ); | 637 | ); |
| 638 | + | ||
| 639 | + self.niri.tablet_cursor_location = Some(pos); | ||
| 648 | } | 640 | } |
| 649 | 641 | ||
| 650 | // Redraw to update the cursor position. | 642 | // Redraw to update the cursor position. |
| @@ -660,15 +652,21 @@ impl State { | |||
| 660 | let serial = SERIAL_COUNTER.next_serial(); | 652 | let serial = SERIAL_COUNTER.next_serial(); |
| 661 | tool.tip_down(serial, event.time_msec()); | 653 | tool.tip_down(serial, event.time_msec()); |
| 662 | 654 | ||
| 663 | - let pointer = self.niri.seat.get_pointer().unwrap(); | 655 | + if let Some(pos) = self.niri.tablet_cursor_location { |
| 664 | - if !pointer.is_grabbed() { | 656 | + if let Some(window) = self.niri.window_under(pos) { |
| 665 | - if let Some(window) = self.niri.window_under_cursor() { | ||
| 666 | let window = window.clone(); | 657 | let window = window.clone(); |
| 667 | self.niri.layout.activate_window(&window); | 658 | self.niri.layout.activate_window(&window); |
| 668 | - } else if let Some(output) = self.niri.output_under_cursor() { | 659 | + |
| 660 | + // FIXME: granular. | ||
| 661 | + self.niri.queue_redraw_all(); | ||
| 662 | + } else if let Some((output, _)) = self.niri.output_under(pos) { | ||
| 663 | + let output = output.clone(); | ||
| 669 | self.niri.layout.activate_output(&output); | 664 | self.niri.layout.activate_output(&output); |
| 665 | + | ||
| 666 | + // FIXME: granular. | ||
| 667 | + self.niri.queue_redraw_all(); | ||
| 670 | } | 668 | } |
| 671 | - }; | 669 | + } |
| 672 | } | 670 | } |
| 673 | TabletToolTipState::Up => { | 671 | TabletToolTipState::Up => { |
| 674 | tool.tip_up(event.time_msec()); | 672 | tool.tip_up(event.time_msec()); |
| @@ -681,39 +679,34 @@ impl State { | |||
| 681 | return; | 679 | return; |
| 682 | }; | 680 | }; |
| 683 | 681 | ||
| 684 | - let serial = SERIAL_COUNTER.next_serial(); | ||
| 685 | - | ||
| 686 | - let pointer = self.niri.seat.get_pointer().unwrap(); | ||
| 687 | - | ||
| 688 | let under = self.niri.surface_under_and_global_space(pos); | 682 | let under = self.niri.surface_under_and_global_space(pos); |
| 689 | - self.niri.pointer_focus = under.clone(); | ||
| 690 | let under = under.map(|u| u.surface); | 683 | let under = under.map(|u| u.surface); |
| 691 | 684 | ||
| 692 | - pointer.motion( | ||
| 693 | - self, | ||
| 694 | - under.clone(), | ||
| 695 | - &MotionEvent { | ||
| 696 | - location: pos, | ||
| 697 | - serial, | ||
| 698 | - time: event.time_msec(), | ||
| 699 | - }, | ||
| 700 | - ); | ||
| 701 | - pointer.frame(self); | ||
| 702 | - | ||
| 703 | let tablet_seat = self.niri.seat.tablet_seat(); | 685 | let tablet_seat = self.niri.seat.tablet_seat(); |
| 704 | let tool = tablet_seat.add_tool::<Self>(&self.niri.display_handle, &event.tool()); | 686 | let tool = tablet_seat.add_tool::<Self>(&self.niri.display_handle, &event.tool()); |
| 705 | let tablet = tablet_seat.get_tablet(&TabletDescriptor::from(&event.device())); | 687 | let tablet = tablet_seat.get_tablet(&TabletDescriptor::from(&event.device())); |
| 706 | - if let (Some(under), Some(tablet)) = (under, tablet) { | 688 | + if let Some(tablet) = tablet { |
| 707 | match event.state() { | 689 | match event.state() { |
| 708 | - ProximityState::In => tool.proximity_in( | 690 | + ProximityState::In => { |
| 709 | - pos, | 691 | + if let Some(under) = under { |
| 710 | - under, | 692 | + tool.proximity_in( |
| 711 | - &tablet, | 693 | + pos, |
| 712 | - SERIAL_COUNTER.next_serial(), | 694 | + under, |
| 713 | - event.time_msec(), | 695 | + &tablet, |
| 714 | - ), | 696 | + SERIAL_COUNTER.next_serial(), |
| 715 | - ProximityState::Out => tool.proximity_out(event.time_msec()), | 697 | + event.time_msec(), |
| 698 | + ); | ||
| 699 | + } | ||
| 700 | + self.niri.tablet_cursor_location = Some(pos); | ||
| 701 | + } | ||
| 702 | + ProximityState::Out => { | ||
| 703 | + tool.proximity_out(event.time_msec()); | ||
| 704 | + self.niri.tablet_cursor_location = None; | ||
| 705 | + } | ||
| 716 | } | 706 | } |
| 707 | + | ||
| 708 | + // FIXME: granular. | ||
| 709 | + self.niri.queue_redraw_all(); | ||
| 717 | } | 710 | } |
| 718 | } | 711 | } |
| 719 | InputEvent::TabletToolButton { event, .. } => { | 712 | InputEvent::TabletToolButton { event, .. } => { |
src/niri.rsmodified+37 -7
| @@ -74,7 +74,7 @@ use smithay::wayland::shell::xdg::decoration::XdgDecorationState; | |||
| 74 | use smithay::wayland::shell::xdg::XdgShellState; | 74 | use smithay::wayland::shell::xdg::XdgShellState; |
| 75 | use smithay::wayland::shm::ShmState; | 75 | use smithay::wayland::shm::ShmState; |
| 76 | use smithay::wayland::socket::ListeningSocketSource; | 76 | use smithay::wayland::socket::ListeningSocketSource; |
| 77 | -use smithay::wayland::tablet_manager::TabletManagerState; | 77 | +use smithay::wayland::tablet_manager::{TabletManagerState, TabletSeatTrait}; |
| 78 | use smithay::wayland::text_input::TextInputManagerState; | 78 | use smithay::wayland::text_input::TextInputManagerState; |
| 79 | use smithay::wayland::virtual_keyboard::VirtualKeyboardManagerState; | 79 | use smithay::wayland::virtual_keyboard::VirtualKeyboardManagerState; |
| 80 | 80 | ||
| @@ -157,6 +157,7 @@ pub struct Niri { | |||
| 157 | pub cursor_shape_manager_state: CursorShapeManagerState, | 157 | pub cursor_shape_manager_state: CursorShapeManagerState, |
| 158 | pub dnd_icon: Option<WlSurface>, | 158 | pub dnd_icon: Option<WlSurface>, |
| 159 | pub pointer_focus: Option<PointerFocus>, | 159 | pub pointer_focus: Option<PointerFocus>, |
| 160 | + pub tablet_cursor_location: Option<Point<f64, Logical>>, | ||
| 160 | 161 | ||
| 161 | pub lock_state: LockState, | 162 | pub lock_state: LockState, |
| 162 | 163 | ||
| @@ -645,6 +646,23 @@ impl Niri { | |||
| 645 | let cursor_manager = | 646 | let cursor_manager = |
| 646 | CursorManager::new(&config_.cursor.xcursor_theme, config_.cursor.xcursor_size); | 647 | CursorManager::new(&config_.cursor.xcursor_theme, config_.cursor.xcursor_size); |
| 647 | 648 | ||
| 649 | + let (tx, rx) = calloop::channel::channel(); | ||
| 650 | + event_loop | ||
| 651 | + .insert_source(rx, move |event, _, state| { | ||
| 652 | + if let calloop::channel::Event::Msg(image) = event { | ||
| 653 | + state.niri.cursor_manager.set_cursor_image(image); | ||
| 654 | + // FIXME: granular. | ||
| 655 | + state.niri.queue_redraw_all(); | ||
| 656 | + } | ||
| 657 | + }) | ||
| 658 | + .unwrap(); | ||
| 659 | + seat.tablet_seat() | ||
| 660 | + .on_cursor_surface(move |_tool, new_image| { | ||
| 661 | + if let Err(err) = tx.send(new_image) { | ||
| 662 | + warn!("error sending new tablet cursor image: {err:?}"); | ||
| 663 | + }; | ||
| 664 | + }); | ||
| 665 | + | ||
| 648 | let screenshot_ui = ScreenshotUi::new(); | 666 | let screenshot_ui = ScreenshotUi::new(); |
| 649 | 667 | ||
| 650 | let socket_source = ListeningSocketSource::new_auto().unwrap(); | 668 | let socket_source = ListeningSocketSource::new_auto().unwrap(); |
| @@ -724,6 +742,7 @@ impl Niri { | |||
| 724 | cursor_shape_manager_state, | 742 | cursor_shape_manager_state, |
| 725 | dnd_icon: None, | 743 | dnd_icon: None, |
| 726 | pointer_focus: None, | 744 | pointer_focus: None, |
| 745 | + tablet_cursor_location: None, | ||
| 727 | 746 | ||
| 728 | lock_state: LockState::Unlocked, | 747 | lock_state: LockState::Unlocked, |
| 729 | 748 | ||
| @@ -980,17 +999,21 @@ impl Niri { | |||
| 980 | Some((output, pos_within_output)) | 999 | Some((output, pos_within_output)) |
| 981 | } | 1000 | } |
| 982 | 1001 | ||
| 983 | - pub fn window_under_cursor(&self) -> Option<&Window> { | 1002 | + pub fn window_under(&self, pos: Point<f64, Logical>) -> Option<&Window> { |
| 984 | if self.is_locked() || self.screenshot_ui.is_open() { | 1003 | if self.is_locked() || self.screenshot_ui.is_open() { |
| 985 | return None; | 1004 | return None; |
| 986 | } | 1005 | } |
| 987 | 1006 | ||
| 988 | - let pos = self.seat.get_pointer().unwrap().current_location(); | ||
| 989 | let (output, pos_within_output) = self.output_under(pos)?; | 1007 | let (output, pos_within_output) = self.output_under(pos)?; |
| 990 | let (window, _loc) = self.layout.window_under(output, pos_within_output)?; | 1008 | let (window, _loc) = self.layout.window_under(output, pos_within_output)?; |
| 991 | Some(window) | 1009 | Some(window) |
| 992 | } | 1010 | } |
| 993 | 1011 | ||
| 1012 | + pub fn window_under_cursor(&self) -> Option<&Window> { | ||
| 1013 | + let pos = self.seat.get_pointer().unwrap().current_location(); | ||
| 1014 | + self.window_under(pos) | ||
| 1015 | + } | ||
| 1016 | + | ||
| 994 | /// Returns the surface under cursor and its position in the global space. | 1017 | /// Returns the surface under cursor and its position in the global space. |
| 995 | /// | 1018 | /// |
| 996 | /// Pointer needs location in global space, and focused window location compatible with that | 1019 | /// Pointer needs location in global space, and focused window location compatible with that |
| @@ -1223,7 +1246,12 @@ impl Niri { | |||
| 1223 | let _span = tracy_client::span!("Niri::pointer_element"); | 1246 | let _span = tracy_client::span!("Niri::pointer_element"); |
| 1224 | let output_scale = output.current_scale(); | 1247 | let output_scale = output.current_scale(); |
| 1225 | let output_pos = self.global_space.output_geometry(output).unwrap().loc; | 1248 | let output_pos = self.global_space.output_geometry(output).unwrap().loc; |
| 1226 | - let pointer_pos = self.seat.get_pointer().unwrap().current_location() - output_pos.to_f64(); | 1249 | + |
| 1250 | + // Check whether we need to draw the tablet cursor or the regular cursor. | ||
| 1251 | + let pointer_pos = self | ||
| 1252 | + .tablet_cursor_location | ||
| 1253 | + .unwrap_or_else(|| self.seat.get_pointer().unwrap().current_location()); | ||
| 1254 | + let pointer_pos = pointer_pos - output_pos.to_f64(); | ||
| 1227 | 1255 | ||
| 1228 | // Get the render cursor to draw. | 1256 | // Get the render cursor to draw. |
| 1229 | let cursor_scale = output_scale.integer_scale(); | 1257 | let cursor_scale = output_scale.integer_scale(); |
| @@ -1294,6 +1322,11 @@ impl Niri { | |||
| 1294 | pub fn refresh_pointer_outputs(&mut self) { | 1322 | pub fn refresh_pointer_outputs(&mut self) { |
| 1295 | let _span = tracy_client::span!("Niri::refresh_pointer_outputs"); | 1323 | let _span = tracy_client::span!("Niri::refresh_pointer_outputs"); |
| 1296 | 1324 | ||
| 1325 | + // Check whether we need to draw the tablet cursor or the regular cursor. | ||
| 1326 | + let pointer_pos = self | ||
| 1327 | + .tablet_cursor_location | ||
| 1328 | + .unwrap_or_else(|| self.seat.get_pointer().unwrap().current_location()); | ||
| 1329 | + | ||
| 1297 | match self.cursor_manager.cursor_image().clone() { | 1330 | match self.cursor_manager.cursor_image().clone() { |
| 1298 | CursorImageStatus::Surface(ref surface) => { | 1331 | CursorImageStatus::Surface(ref surface) => { |
| 1299 | let hotspot = with_states(surface, |states| { | 1332 | let hotspot = with_states(surface, |states| { |
| @@ -1306,7 +1339,6 @@ impl Niri { | |||
| 1306 | .hotspot | 1339 | .hotspot |
| 1307 | }); | 1340 | }); |
| 1308 | 1341 | ||
| 1309 | - let pointer_pos = self.seat.get_pointer().unwrap().current_location(); | ||
| 1310 | let surface_pos = pointer_pos.to_i32_round() - hotspot; | 1342 | let surface_pos = pointer_pos.to_i32_round() - hotspot; |
| 1311 | let bbox = bbox_from_surface_tree(surface, surface_pos); | 1343 | let bbox = bbox_from_surface_tree(surface, surface_pos); |
| 1312 | 1344 | ||
| @@ -1364,8 +1396,6 @@ impl Niri { | |||
| 1364 | Default::default() | 1396 | Default::default() |
| 1365 | }; | 1397 | }; |
| 1366 | 1398 | ||
| 1367 | - let pointer_pos = self.seat.get_pointer().unwrap().current_location(); | ||
| 1368 | - | ||
| 1369 | let mut dnd_scale = 1; | 1399 | let mut dnd_scale = 1; |
| 1370 | for output in self.global_space.outputs() { | 1400 | for output in self.global_space.outputs() { |
| 1371 | let geo = self.global_space.output_geometry(output).unwrap(); | 1401 | let geo = self.global_space.output_geometry(output).unwrap(); |