forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiB02f37c8Ivan Molodetskikh3 years ago275 commits

input.rs795 lines, 32.8 KiBHistoryRawDownload
1use smithay::backend::input::{
2 AbsolutePositionEvent, Axis, AxisSource, ButtonState, Device, DeviceCapability, Event,
3 GestureBeginEvent, GestureEndEvent, GesturePinchUpdateEvent as _, GestureSwipeUpdateEvent as _,
4 InputBackend, InputEvent, KeyState, KeyboardKeyEvent, PointerAxisEvent, PointerButtonEvent,
5 PointerMotionEvent, ProximityState, TabletToolButtonEvent, TabletToolEvent,
6 TabletToolProximityEvent, TabletToolTipEvent, TabletToolTipState,
7};
8use smithay::backend::libinput::LibinputInputBackend;
9use smithay::input::keyboard::{keysyms, FilterResult, KeysymHandle, ModifiersState};
10use smithay::input::pointer::{
11 AxisFrame, ButtonEvent, GestureHoldBeginEvent, GestureHoldEndEvent, GesturePinchBeginEvent,
12 GesturePinchEndEvent, GesturePinchUpdateEvent, GestureSwipeBeginEvent, GestureSwipeEndEvent,
13 GestureSwipeUpdateEvent, MotionEvent, RelativeMotionEvent,
14};
15use smithay::utils::SERIAL_COUNTER;
16use smithay::wayland::tablet_manager::{TabletDescriptor, TabletSeatTrait};
17
18use crate::config::{Action, Config, Modifiers};
19use crate::niri::State;
20use crate::utils::{center, get_monotonic_time, spawn};
21
22pub enum CompositorMod {
23 Super,
24 Alt,
25}
26
27impl From<Action> for FilterResult<Action> {
28 fn from(value: Action) -> Self {
29 match value {
30 Action::None => FilterResult::Forward,
31 action => FilterResult::Intercept(action),
32 }
33 }
34}
35
36fn action(
37 config: &Config,
38 comp_mod: CompositorMod,
39 keysym: KeysymHandle,
40 mods: ModifiersState,
41) -> Action {
42 use keysyms::*;
43
44 // Handle hardcoded binds.
45 #[allow(non_upper_case_globals)] // wat
46 match keysym.modified_sym().raw() {
47 modified @ KEY_XF86Switch_VT_1..=KEY_XF86Switch_VT_12 => {
48 let vt = (modified - KEY_XF86Switch_VT_1 + 1) as i32;
49 return Action::ChangeVt(vt);
50 }
51 KEY_XF86PowerOff => return Action::Suspend,
52 _ => (),
53 }
54
55 // Handle configured binds.
56 let mut modifiers = Modifiers::empty();
57 if mods.ctrl {
58 modifiers |= Modifiers::CTRL;
59 }
60 if mods.shift {
61 modifiers |= Modifiers::SHIFT;
62 }
63 if mods.alt {
64 modifiers |= Modifiers::ALT;
65 }
66 if mods.logo {
67 modifiers |= Modifiers::SUPER;
68 }
69
70 let (mod_down, mut comp_mod) = match comp_mod {
71 CompositorMod::Super => (mods.logo, Modifiers::SUPER),
72 CompositorMod::Alt => (mods.alt, Modifiers::ALT),
73 };
74 if mod_down {
75 modifiers |= Modifiers::COMPOSITOR;
76 } else {
77 comp_mod = Modifiers::empty();
78 }
79
80 let Some(&raw) = keysym.raw_syms().first() else {
81 return Action::None;
82 };
83 for bind in &config.binds.0 {
84 if bind.key.keysym != raw {
85 continue;
86 }
87
88 if bind.key.modifiers | comp_mod == modifiers {
89 return bind.actions.first().cloned().unwrap_or(Action::None);
90 }
91 }
92
93 Action::None
94}
95
96impl State {
97 pub fn process_input_event<I: InputBackend>(&mut self, event: InputEvent<I>) {
98 let _span = tracy_client::span!("process_input_event");
99
100 // A bit of a hack, but animation end runs some logic (i.e. workspace clean-up) and it
101 // doesn't always trigger due to damage, etc. So run it here right before it might prove
102 // important. Besides, animations affect the input, so it's best to have up-to-date values
103 // here.
104 self.niri.layout.advance_animations(get_monotonic_time());
105
106 // Power on monitors if they were off.
107 // HACK: ignore key releases so that the power-off-monitors bind can work.
108 if !matches!(&event, InputEvent::Keyboard { event } if event.state() == KeyState::Released)
109 {
110 self.niri.activate_monitors(&self.backend);
111 }
112
113 let comp_mod = self.backend.mod_key();
114
115 match event {
116 InputEvent::Keyboard { event, .. } => {
117 let serial = SERIAL_COUNTER.next_serial();
118 let time = Event::time_msec(&event);
119
120 let action = self.niri.seat.get_keyboard().unwrap().input(
121 self,
122 event.key_code(),
123 event.state(),
124 serial,
125 time,
126 |self_, mods, keysym| {
127 if event.state() == KeyState::Pressed {
128 let config = self_.niri.config.borrow();
129 action(&config, comp_mod, keysym, *mods).into()
130 } else {
131 FilterResult::Forward
132 }
133 },
134 );
135
136 if let Some(action) = action {
137 match action {
138 Action::None => unreachable!(),
139 Action::Quit => {
140 info!("quitting because quit bind was pressed");
141 self.niri.stop_signal.stop()
142 }
143 Action::ChangeVt(vt) => {
144 self.backend.change_vt(vt);
145 }
146 Action::Suspend => {
147 self.backend.suspend();
148 }
149 Action::PowerOffMonitors => {
150 self.niri.deactivate_monitors(&self.backend);
151 }
152 Action::ToggleDebugTint => {
153 self.backend.toggle_debug_tint();
154 }
155 Action::Spawn(command) => {
156 if let Some((command, args)) = command.split_first() {
157 spawn(command, args);
158 }
159 }
160 Action::Screenshot => {
161 let active = self.niri.layout.active_output().cloned();
162 if let Some(active) = active {
163 if let Some(renderer) = self.backend.renderer() {
164 if let Err(err) = self.niri.screenshot(renderer, &active) {
165 warn!("error taking screenshot: {err:?}");
166 }
167 }
168 }
169 }
170 Action::CloseWindow => {
171 if let Some(window) = self.niri.layout.focus() {
172 window.toplevel().send_close();
173 }
174 }
175 Action::FullscreenWindow => {
176 let focus = self.niri.layout.focus().cloned();
177 if let Some(window) = focus {
178 self.niri.layout.toggle_fullscreen(&window);
179 }
180 }
181 Action::MoveColumnLeft => {
182 self.niri.layout.move_left();
183 // FIXME: granular
184 self.niri.queue_redraw_all();
185 }
186 Action::MoveColumnRight => {
187 self.niri.layout.move_right();
188 // FIXME: granular
189 self.niri.queue_redraw_all();
190 }
191 Action::MoveWindowDown => {
192 self.niri.layout.move_down();
193 // FIXME: granular
194 self.niri.queue_redraw_all();
195 }
196 Action::MoveWindowUp => {
197 self.niri.layout.move_up();
198 // FIXME: granular
199 self.niri.queue_redraw_all();
200 }
201 Action::FocusColumnLeft => {
202 self.niri.layout.focus_left();
203 }
204 Action::FocusColumnRight => {
205 self.niri.layout.focus_right();
206 }
207 Action::FocusWindowDown => {
208 self.niri.layout.focus_down();
209 }
210 Action::FocusWindowUp => {
211 self.niri.layout.focus_up();
212 }
213 Action::MoveWindowToWorkspaceDown => {
214 self.niri.layout.move_to_workspace_down();
215 // FIXME: granular
216 self.niri.queue_redraw_all();
217 }
218 Action::MoveWindowToWorkspaceUp => {
219 self.niri.layout.move_to_workspace_up();
220 // FIXME: granular
221 self.niri.queue_redraw_all();
222 }
223 Action::MoveWindowToWorkspace(idx) => {
224 self.niri.layout.move_to_workspace(idx);
225 // FIXME: granular
226 self.niri.queue_redraw_all();
227 }
228 Action::FocusWorkspaceDown => {
229 self.niri.layout.switch_workspace_down();
230 // FIXME: granular
231 self.niri.queue_redraw_all();
232 }
233 Action::FocusWorkspaceUp => {
234 self.niri.layout.switch_workspace_up();
235 // FIXME: granular
236 self.niri.queue_redraw_all();
237 }
238 Action::FocusWorkspace(idx) => {
239 self.niri.layout.switch_workspace(idx);
240 // FIXME: granular
241 self.niri.queue_redraw_all();
242 }
243 Action::ConsumeWindowIntoColumn => {
244 self.niri.layout.consume_into_column();
245 // FIXME: granular
246 self.niri.queue_redraw_all();
247 }
248 Action::ExpelWindowFromColumn => {
249 self.niri.layout.expel_from_column();
250 // FIXME: granular
251 self.niri.queue_redraw_all();
252 }
253 Action::SwitchPresetColumnWidth => {
254 self.niri.layout.toggle_width();
255 }
256 Action::MaximizeColumn => {
257 self.niri.layout.toggle_full_width();
258 }
259 Action::FocusMonitorLeft => {
260 if let Some(output) = self.niri.output_left() {
261 self.niri.layout.focus_output(&output);
262 self.move_cursor_to_output(&output);
263 }
264 }
265 Action::FocusMonitorRight => {
266 if let Some(output) = self.niri.output_right() {
267 self.niri.layout.focus_output(&output);
268 self.move_cursor_to_output(&output);
269 }
270 }
271 Action::FocusMonitorDown => {
272 if let Some(output) = self.niri.output_down() {
273 self.niri.layout.focus_output(&output);
274 self.move_cursor_to_output(&output);
275 }
276 }
277 Action::FocusMonitorUp => {
278 if let Some(output) = self.niri.output_up() {
279 self.niri.layout.focus_output(&output);
280 self.move_cursor_to_output(&output);
281 }
282 }
283 Action::MoveWindowToMonitorLeft => {
284 if let Some(output) = self.niri.output_left() {
285 self.niri.layout.move_to_output(&output);
286 self.move_cursor_to_output(&output);
287 }
288 }
289 Action::MoveWindowToMonitorRight => {
290 if let Some(output) = self.niri.output_right() {
291 self.niri.layout.move_to_output(&output);
292 self.move_cursor_to_output(&output);
293 }
294 }
295 Action::MoveWindowToMonitorDown => {
296 if let Some(output) = self.niri.output_down() {
297 self.niri.layout.move_to_output(&output);
298 self.move_cursor_to_output(&output);
299 }
300 }
301 Action::MoveWindowToMonitorUp => {
302 if let Some(output) = self.niri.output_up() {
303 self.niri.layout.move_to_output(&output);
304 self.move_cursor_to_output(&output);
305 }
306 }
307 Action::SetColumnWidth(change) => {
308 self.niri.layout.set_column_width(change);
309 }
310 }
311 }
312 }
313 InputEvent::PointerMotion { event, .. } => {
314 // We need an output to be able to move the pointer.
315 if self.niri.global_space.outputs().next().is_none() {
316 return;
317 }
318
319 let serial = SERIAL_COUNTER.next_serial();
320
321 let pointer = self.niri.seat.get_pointer().unwrap();
322
323 let pos = pointer.current_location();
324
325 // We have an output, so we can compute the new location and focus.
326 let mut new_pos = pos + event.delta();
327
328 if self
329 .niri
330 .global_space
331 .output_under(new_pos)
332 .next()
333 .is_none()
334 {
335 // We ended up outside the outputs and need to clip the movement.
336 if let Some(output) = self.niri.global_space.output_under(pos).next() {
337 // The pointer was previously on some output. Clip the movement against its
338 // boundaries.
339 let geom = self.niri.global_space.output_geometry(output).unwrap();
340 new_pos.x = new_pos
341 .x
342 .clamp(geom.loc.x as f64, (geom.loc.x + geom.size.w - 1) as f64);
343 new_pos.y = new_pos
344 .y
345 .clamp(geom.loc.y as f64, (geom.loc.y + geom.size.h - 1) as f64);
346 } else {
347 // The pointer was not on any output in the first place. Find one for it.
348 // Let's do the simple thing and just put it on the first output.
349 let output = self.niri.global_space.outputs().next().unwrap();
350 let geom = self.niri.global_space.output_geometry(output).unwrap();
351 new_pos = center(geom).to_f64();
352 }
353 }
354
355 let under = self.niri.surface_under_and_global_space(new_pos);
356
357 pointer.motion(
358 self,
359 under.clone(),
360 &MotionEvent {
361 location: new_pos,
362 serial,
363 time: event.time_msec(),
364 },
365 );
366
367 pointer.relative_motion(
368 self,
369 under,
370 &RelativeMotionEvent {
371 delta: event.delta(),
372 delta_unaccel: event.delta_unaccel(),
373 utime: event.time(),
374 },
375 );
376
377 pointer.frame(self);
378
379 // Redraw to update the cursor position.
380 // FIXME: redraw only outputs overlapping the cursor.
381 self.niri.queue_redraw_all();
382 }
383 InputEvent::PointerMotionAbsolute { event, .. } => {
384 let Some(output) = self.niri.global_space.outputs().next() else {
385 return;
386 };
387
388 let output_geo = self.niri.global_space.output_geometry(output).unwrap();
389
390 let pos = event.position_transformed(output_geo.size) + output_geo.loc.to_f64();
391
392 let serial = SERIAL_COUNTER.next_serial();
393
394 let pointer = self.niri.seat.get_pointer().unwrap();
395
396 let under = self.niri.surface_under_and_global_space(pos);
397
398 pointer.motion(
399 self,
400 under,
401 &MotionEvent {
402 location: pos,
403 serial,
404 time: event.time_msec(),
405 },
406 );
407
408 pointer.frame(self);
409
410 // Redraw to update the cursor position.
411 // FIXME: redraw only outputs overlapping the cursor.
412 self.niri.queue_redraw_all();
413 }
414 InputEvent::PointerButton { event, .. } => {
415 let pointer = self.niri.seat.get_pointer().unwrap();
416
417 let serial = SERIAL_COUNTER.next_serial();
418
419 let button = event.button_code();
420
421 let button_state = event.state();
422
423 if ButtonState::Pressed == button_state && !pointer.is_grabbed() {
424 if let Some(window) = self.niri.window_under_cursor() {
425 let window = window.clone();
426 self.niri.layout.activate_window(&window);
427 } else if let Some(output) = self.niri.output_under_cursor() {
428 self.niri.layout.activate_output(&output);
429 }
430 };
431
432 pointer.button(
433 self,
434 &ButtonEvent {
435 button,
436 state: button_state,
437 serial,
438 time: event.time_msec(),
439 },
440 );
441 pointer.frame(self);
442 }
443 InputEvent::PointerAxis { event, .. } => {
444 let source = event.source();
445
446 let horizontal_amount = event.amount(Axis::Horizontal).unwrap_or_else(|| {
447 event.amount_discrete(Axis::Horizontal).unwrap_or(0.0) * 3.0
448 });
449 let vertical_amount = event
450 .amount(Axis::Vertical)
451 .unwrap_or_else(|| event.amount_discrete(Axis::Vertical).unwrap_or(0.0) * 3.0);
452 let horizontal_amount_discrete = event.amount_discrete(Axis::Horizontal);
453 let vertical_amount_discrete = event.amount_discrete(Axis::Vertical);
454
455 let mut frame = AxisFrame::new(event.time_msec()).source(source);
456 if horizontal_amount != 0.0 {
457 frame = frame.value(Axis::Horizontal, horizontal_amount);
458 if let Some(discrete) = horizontal_amount_discrete {
459 frame = frame.discrete(Axis::Horizontal, discrete as i32);
460 }
461 }
462 if vertical_amount != 0.0 {
463 frame = frame.value(Axis::Vertical, vertical_amount);
464 if let Some(discrete) = vertical_amount_discrete {
465 frame = frame.discrete(Axis::Vertical, discrete as i32);
466 }
467 }
468
469 if source == AxisSource::Finger {
470 if event.amount(Axis::Horizontal) == Some(0.0) {
471 frame = frame.stop(Axis::Horizontal);
472 }
473 if event.amount(Axis::Vertical) == Some(0.0) {
474 frame = frame.stop(Axis::Vertical);
475 }
476 }
477
478 let pointer = &self.niri.seat.get_pointer().unwrap();
479 pointer.axis(self, frame);
480 pointer.frame(self);
481 }
482 InputEvent::TabletToolAxis { event, .. } => {
483 let Some(output) = self.niri.output_for_tablet() else {
484 return;
485 };
486
487 let output_geo = self.niri.global_space.output_geometry(output).unwrap();
488
489 let pos = event.position_transformed(output_geo.size) + output_geo.loc.to_f64();
490
491 let serial = SERIAL_COUNTER.next_serial();
492
493 let pointer = self.niri.seat.get_pointer().unwrap();
494
495 let under = self.niri.surface_under_and_global_space(pos);
496
497 pointer.motion(
498 self,
499 under.clone(),
500 &MotionEvent {
501 location: pos,
502 serial,
503 time: event.time_msec(),
504 },
505 );
506 pointer.frame(self);
507
508 let tablet_seat = self.niri.seat.tablet_seat();
509 let tablet = tablet_seat.get_tablet(&TabletDescriptor::from(&event.device()));
510 let tool = tablet_seat.get_tool(&event.tool());
511 if let (Some(tablet), Some(tool)) = (tablet, tool) {
512 if event.pressure_has_changed() {
513 tool.pressure(event.pressure());
514 }
515 if event.distance_has_changed() {
516 tool.distance(event.distance());
517 }
518 if event.tilt_has_changed() {
519 tool.tilt(event.tilt());
520 }
521 if event.slider_has_changed() {
522 tool.slider_position(event.slider_position());
523 }
524 if event.rotation_has_changed() {
525 tool.rotation(event.rotation());
526 }
527 if event.wheel_has_changed() {
528 tool.wheel(event.wheel_delta(), event.wheel_delta_discrete());
529 }
530
531 tool.motion(
532 pos,
533 under,
534 &tablet,
535 SERIAL_COUNTER.next_serial(),
536 event.time_msec(),
537 );
538 }
539
540 // Redraw to update the cursor position.
541 // FIXME: redraw only outputs overlapping the cursor.
542 self.niri.queue_redraw_all();
543 }
544 InputEvent::TabletToolTip { event, .. } => {
545 let tool = self.niri.seat.tablet_seat().get_tool(&event.tool());
546
547 if let Some(tool) = tool {
548 match event.tip_state() {
549 TabletToolTipState::Down => {
550 let serial = SERIAL_COUNTER.next_serial();
551 tool.tip_down(serial, event.time_msec());
552
553 let pointer = self.niri.seat.get_pointer().unwrap();
554 if !pointer.is_grabbed() {
555 if let Some(window) = self.niri.window_under_cursor() {
556 let window = window.clone();
557 self.niri.layout.activate_window(&window);
558 } else if let Some(output) = self.niri.output_under_cursor() {
559 self.niri.layout.activate_output(&output);
560 }
561 };
562 }
563 TabletToolTipState::Up => {
564 tool.tip_up(event.time_msec());
565 }
566 }
567 }
568 }
569 InputEvent::TabletToolProximity { event, .. } => {
570 let Some(output) = self.niri.output_for_tablet() else {
571 return;
572 };
573
574 let output_geo = self.niri.global_space.output_geometry(output).unwrap();
575
576 let pos = event.position_transformed(output_geo.size) + output_geo.loc.to_f64();
577
578 let serial = SERIAL_COUNTER.next_serial();
579
580 let pointer = self.niri.seat.get_pointer().unwrap();
581
582 let under = self.niri.surface_under_and_global_space(pos);
583
584 pointer.motion(
585 self,
586 under.clone(),
587 &MotionEvent {
588 location: pos,
589 serial,
590 time: event.time_msec(),
591 },
592 );
593 pointer.frame(self);
594
595 let tablet_seat = self.niri.seat.tablet_seat();
596 let tool = tablet_seat.add_tool::<Self>(&self.niri.display_handle, &event.tool());
597 let tablet = tablet_seat.get_tablet(&TabletDescriptor::from(&event.device()));
598 if let (Some(under), Some(tablet)) = (under, tablet) {
599 match event.state() {
600 ProximityState::In => tool.proximity_in(
601 pos,
602 under,
603 &tablet,
604 SERIAL_COUNTER.next_serial(),
605 event.time_msec(),
606 ),
607 ProximityState::Out => tool.proximity_out(event.time_msec()),
608 }
609 }
610 }
611 InputEvent::TabletToolButton { event, .. } => {
612 let tool = self.niri.seat.tablet_seat().get_tool(&event.tool());
613
614 if let Some(tool) = tool {
615 tool.button(
616 event.button(),
617 event.button_state(),
618 SERIAL_COUNTER.next_serial(),
619 event.time_msec(),
620 );
621 }
622 }
623 InputEvent::DeviceAdded { device } => {
624 if device.has_capability(DeviceCapability::TabletTool) {
625 self.niri.seat.tablet_seat().add_tablet::<Self>(
626 &self.niri.display_handle,
627 &TabletDescriptor::from(&device),
628 );
629 }
630 }
631 InputEvent::DeviceRemoved { device } => {
632 if device.has_capability(DeviceCapability::TabletTool) {
633 let tablet_seat = self.niri.seat.tablet_seat();
634
635 tablet_seat.remove_tablet(&TabletDescriptor::from(&device));
636
637 // If there are no tablets in seat we can remove all tools
638 if tablet_seat.count_tablets() == 0 {
639 tablet_seat.clear_tools();
640 }
641 }
642 }
643 InputEvent::GestureSwipeBegin { event } => {
644 if event.fingers() == 3 {
645 if let Some(output) = self.niri.output_under_cursor() {
646 self.niri.layout.workspace_switch_gesture_begin(&output);
647
648 // FIXME: granular. This one is awkward because this can cancel a gesture on
649 // multiple other outputs in theory.
650 self.niri.queue_redraw_all();
651 }
652
653 // We handled this event.
654 return;
655 }
656
657 let serial = SERIAL_COUNTER.next_serial();
658 let pointer = self.niri.seat.get_pointer().unwrap();
659 pointer.gesture_swipe_begin(
660 self,
661 &GestureSwipeBeginEvent {
662 serial,
663 time: event.time_msec(),
664 fingers: event.fingers(),
665 },
666 );
667 }
668 InputEvent::GestureSwipeUpdate { event } => {
669 let res = self
670 .niri
671 .layout
672 .workspace_switch_gesture_update(event.delta_y());
673 if let Some(output) = res {
674 if let Some(output) = output {
675 self.niri.queue_redraw(output);
676 }
677
678 // We handled this event.
679 return;
680 }
681
682 let pointer = self.niri.seat.get_pointer().unwrap();
683 pointer.gesture_swipe_update(
684 self,
685 &GestureSwipeUpdateEvent {
686 time: event.time_msec(),
687 delta: event.delta(),
688 },
689 );
690 }
691 InputEvent::GestureSwipeEnd { event } => {
692 let res = self
693 .niri
694 .layout
695 .workspace_switch_gesture_end(event.cancelled());
696 if let Some(output) = res {
697 self.niri.queue_redraw(output);
698
699 // We handled this event.
700 return;
701 }
702
703 let serial = SERIAL_COUNTER.next_serial();
704 let pointer = self.niri.seat.get_pointer().unwrap();
705 pointer.gesture_swipe_end(
706 self,
707 &GestureSwipeEndEvent {
708 serial,
709 time: event.time_msec(),
710 cancelled: event.cancelled(),
711 },
712 );
713 }
714 InputEvent::GesturePinchBegin { event } => {
715 let serial = SERIAL_COUNTER.next_serial();
716 let pointer = self.niri.seat.get_pointer().unwrap();
717 pointer.gesture_pinch_begin(
718 self,
719 &GesturePinchBeginEvent {
720 serial,
721 time: event.time_msec(),
722 fingers: event.fingers(),
723 },
724 );
725 }
726 InputEvent::GesturePinchUpdate { event } => {
727 let pointer = self.niri.seat.get_pointer().unwrap();
728 pointer.gesture_pinch_update(
729 self,
730 &GesturePinchUpdateEvent {
731 time: event.time_msec(),
732 delta: event.delta(),
733 scale: event.scale(),
734 rotation: event.rotation(),
735 },
736 );
737 }
738 InputEvent::GesturePinchEnd { event } => {
739 let serial = SERIAL_COUNTER.next_serial();
740 let pointer = self.niri.seat.get_pointer().unwrap();
741 pointer.gesture_pinch_end(
742 self,
743 &GesturePinchEndEvent {
744 serial,
745 time: event.time_msec(),
746 cancelled: event.cancelled(),
747 },
748 );
749 }
750 InputEvent::GestureHoldBegin { event } => {
751 let serial = SERIAL_COUNTER.next_serial();
752 let pointer = self.niri.seat.get_pointer().unwrap();
753 pointer.gesture_hold_begin(
754 self,
755 &GestureHoldBeginEvent {
756 serial,
757 time: event.time_msec(),
758 fingers: event.fingers(),
759 },
760 );
761 }
762 InputEvent::GestureHoldEnd { event } => {
763 let serial = SERIAL_COUNTER.next_serial();
764 let pointer = self.niri.seat.get_pointer().unwrap();
765 pointer.gesture_hold_end(
766 self,
767 &GestureHoldEndEvent {
768 serial,
769 time: event.time_msec(),
770 cancelled: event.cancelled(),
771 },
772 );
773 }
774 InputEvent::TouchDown { .. } => (),
775 InputEvent::TouchMotion { .. } => (),
776 InputEvent::TouchUp { .. } => (),
777 InputEvent::TouchCancel { .. } => (),
778 InputEvent::TouchFrame { .. } => (),
779 InputEvent::Special(_) => (),
780 }
781 }
782
783 pub fn process_libinput_event(&mut self, event: &mut InputEvent<LibinputInputBackend>) {
784 if let InputEvent::DeviceAdded { device } = event {
785 // According to Mutter code, this setting is specific to touchpads.
786 let is_touchpad = device.config_tap_finger_count() > 0;
787 if is_touchpad {
788 let c = &self.niri.config.borrow().input.touchpad;
789 let _ = device.config_tap_set_enabled(c.tap);
790 let _ = device.config_scroll_set_natural_scroll_enabled(c.natural_scroll);
791 let _ = device.config_accel_set_speed(c.accel_speed);
792 }
793 }
794 }
795}