forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiB7b3bef1Suyashtnt2 years ago1225 commits

mod.rs2863 lines, 104.2 KiBHistoryRawDownload
1use std::any::Any;
2use std::cmp::min;
3use std::collections::hash_map::Entry;
4use std::collections::HashSet;
5use std::time::Duration;
6
7use calloop::timer::{TimeoutAction, Timer};
8use input::event::gesture::GestureEventCoordinates as _;
9use niri_config::{Action, Bind, Binds, Key, Modifiers, Trigger};
10use niri_ipc::LayoutSwitchTarget;
11use smithay::backend::input::{
12 AbsolutePositionEvent, Axis, AxisSource, ButtonState, Device, DeviceCapability, Event,
13 GestureBeginEvent, GestureEndEvent, GesturePinchUpdateEvent as _, GestureSwipeUpdateEvent as _,
14 InputBackend, InputEvent, KeyState, KeyboardKeyEvent, MouseButton, PointerAxisEvent,
15 PointerButtonEvent, PointerMotionEvent, ProximityState, TabletToolButtonEvent, TabletToolEvent,
16 TabletToolProximityEvent, TabletToolTipEvent, TabletToolTipState, TouchEvent,
17};
18use smithay::backend::libinput::LibinputInputBackend;
19use smithay::input::keyboard::{keysyms, FilterResult, Keysym, ModifiersState};
20use smithay::input::pointer::{
21 AxisFrame, ButtonEvent, CursorIcon, CursorImageStatus, Focus, GestureHoldBeginEvent,
22 GestureHoldEndEvent, GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent,
23 GestureSwipeBeginEvent, GestureSwipeEndEvent, GestureSwipeUpdateEvent,
24 GrabStartData as PointerGrabStartData, MotionEvent, RelativeMotionEvent,
25};
26use smithay::input::touch::{DownEvent, MotionEvent as TouchMotionEvent, UpEvent};
27use smithay::utils::{Logical, Point, Rectangle, SERIAL_COUNTER};
28use smithay::wayland::pointer_constraints::{with_pointer_constraint, PointerConstraint};
29use smithay::wayland::tablet_manager::{TabletDescriptor, TabletSeatTrait};
30
31use self::resize_grab::ResizeGrab;
32use self::spatial_movement_grab::SpatialMovementGrab;
33use crate::niri::State;
34use crate::ui::screenshot_ui::ScreenshotUi;
35use crate::utils::spawning::spawn;
36use crate::utils::{center, get_monotonic_time, ResizeEdge};
37
38pub mod resize_grab;
39pub mod scroll_tracker;
40pub mod spatial_movement_grab;
41pub mod swipe_tracker;
42
43pub const DOUBLE_CLICK_TIME: Duration = Duration::from_millis(400);
44
45#[derive(Debug, Clone, Copy, PartialEq, Eq)]
46pub enum CompositorMod {
47 Super,
48 Alt,
49}
50
51#[derive(Debug, Clone, Copy, PartialEq)]
52pub struct TabletData {
53 pub aspect_ratio: f64,
54}
55
56impl State {
57 pub fn process_input_event<I: InputBackend + 'static>(&mut self, event: InputEvent<I>)
58 where
59 I::Device: 'static, // Needed for downcasting.
60 {
61 let _span = tracy_client::span!("process_input_event");
62
63 // A bit of a hack, but animation end runs some logic (i.e. workspace clean-up) and it
64 // doesn't always trigger due to damage, etc. So run it here right before it might prove
65 // important. Besides, animations affect the input, so it's best to have up-to-date values
66 // here.
67 self.niri.layout.advance_animations(get_monotonic_time());
68
69 if self.niri.monitors_active {
70 // Notify the idle-notifier of activity.
71 if should_notify_activity(&event) {
72 let _span = tracy_client::span!("IdleNotifierState::notify_activity");
73 self.niri
74 .idle_notifier_state
75 .notify_activity(&self.niri.seat);
76 }
77 } else {
78 // Power on monitors if they were off.
79 if should_activate_monitors(&event) {
80 self.niri.activate_monitors(&mut self.backend);
81
82 // Notify the idle-notifier of activity only if we're also powering on the
83 // monitors.
84 self.niri
85 .idle_notifier_state
86 .notify_activity(&self.niri.seat);
87 }
88 }
89
90 let hide_hotkey_overlay =
91 self.niri.hotkey_overlay.is_open() && should_hide_hotkey_overlay(&event);
92
93 let hide_exit_confirm_dialog = self
94 .niri
95 .exit_confirm_dialog
96 .as_ref()
97 .map_or(false, |d| d.is_open())
98 && should_hide_exit_confirm_dialog(&event);
99
100 use InputEvent::*;
101 match event {
102 DeviceAdded { device } => self.on_device_added(device),
103 DeviceRemoved { device } => self.on_device_removed(device),
104 Keyboard { event } => self.on_keyboard::<I>(event),
105 PointerMotion { event } => self.on_pointer_motion::<I>(event),
106 PointerMotionAbsolute { event } => self.on_pointer_motion_absolute::<I>(event),
107 PointerButton { event } => self.on_pointer_button::<I>(event),
108 PointerAxis { event } => self.on_pointer_axis::<I>(event),
109 TabletToolAxis { event } => self.on_tablet_tool_axis::<I>(event),
110 TabletToolTip { event } => self.on_tablet_tool_tip::<I>(event),
111 TabletToolProximity { event } => self.on_tablet_tool_proximity::<I>(event),
112 TabletToolButton { event } => self.on_tablet_tool_button::<I>(event),
113 GestureSwipeBegin { event } => self.on_gesture_swipe_begin::<I>(event),
114 GestureSwipeUpdate { event } => self.on_gesture_swipe_update::<I>(event),
115 GestureSwipeEnd { event } => self.on_gesture_swipe_end::<I>(event),
116 GesturePinchBegin { event } => self.on_gesture_pinch_begin::<I>(event),
117 GesturePinchUpdate { event } => self.on_gesture_pinch_update::<I>(event),
118 GesturePinchEnd { event } => self.on_gesture_pinch_end::<I>(event),
119 GestureHoldBegin { event } => self.on_gesture_hold_begin::<I>(event),
120 GestureHoldEnd { event } => self.on_gesture_hold_end::<I>(event),
121 TouchDown { event } => self.on_touch_down::<I>(event),
122 TouchMotion { event } => self.on_touch_motion::<I>(event),
123 TouchUp { event } => self.on_touch_up::<I>(event),
124 TouchCancel { event } => self.on_touch_cancel::<I>(event),
125 TouchFrame { event } => self.on_touch_frame::<I>(event),
126 SwitchToggle { .. } => (),
127 Special(_) => (),
128 }
129
130 // Do this last so that screenshot still gets it.
131 // FIXME: do this in a less cursed fashion somehow.
132 if hide_hotkey_overlay && self.niri.hotkey_overlay.hide() {
133 self.niri.queue_redraw_all();
134 }
135
136 if let Some(dialog) = &mut self.niri.exit_confirm_dialog {
137 if hide_exit_confirm_dialog && dialog.hide() {
138 self.niri.queue_redraw_all();
139 }
140 }
141 }
142
143 pub fn process_libinput_event(&mut self, event: &mut InputEvent<LibinputInputBackend>) {
144 let _span = tracy_client::span!("process_libinput_event");
145
146 match event {
147 InputEvent::DeviceAdded { device } => {
148 self.niri.devices.insert(device.clone());
149
150 if device.has_capability(input::DeviceCapability::TabletTool) {
151 match device.size() {
152 Some((w, h)) => {
153 let aspect_ratio = w / h;
154 let data = TabletData { aspect_ratio };
155 self.niri.tablets.insert(device.clone(), data);
156 }
157 None => {
158 warn!("tablet tool device has no size");
159 }
160 }
161 }
162
163 if device.has_capability(input::DeviceCapability::Keyboard) {
164 if let Some(led_state) = self
165 .niri
166 .seat
167 .get_keyboard()
168 .map(|keyboard| keyboard.led_state())
169 {
170 device.led_update(led_state.into());
171 }
172 }
173
174 if device.has_capability(input::DeviceCapability::Touch) {
175 self.niri.touch.insert(device.clone());
176 }
177
178 apply_libinput_settings(&self.niri.config.borrow().input, device);
179 }
180 InputEvent::DeviceRemoved { device } => {
181 self.niri.touch.remove(device);
182 self.niri.tablets.remove(device);
183 self.niri.devices.remove(device);
184 }
185 _ => (),
186 }
187 }
188
189 fn on_device_added(&mut self, device: impl Device) {
190 if device.has_capability(DeviceCapability::TabletTool) {
191 let tablet_seat = self.niri.seat.tablet_seat();
192
193 let desc = TabletDescriptor::from(&device);
194 tablet_seat.add_tablet::<Self>(&self.niri.display_handle, &desc);
195 }
196 if device.has_capability(DeviceCapability::Touch) && self.niri.seat.get_touch().is_none() {
197 self.niri.seat.add_touch();
198 }
199 }
200
201 fn on_device_removed(&mut self, device: impl Device) {
202 if device.has_capability(DeviceCapability::TabletTool) {
203 let tablet_seat = self.niri.seat.tablet_seat();
204
205 let desc = TabletDescriptor::from(&device);
206 tablet_seat.remove_tablet(&desc);
207
208 // If there are no tablets in seat we can remove all tools
209 if tablet_seat.count_tablets() == 0 {
210 tablet_seat.clear_tools();
211 }
212 }
213 if device.has_capability(DeviceCapability::Touch) && self.niri.touch.is_empty() {
214 self.niri.seat.remove_touch();
215 }
216 }
217
218 /// Computes the rectangle that covers all outputs in global space.
219 fn global_bounding_rectangle(&self) -> Option<Rectangle<i32, Logical>> {
220 self.niri.global_space.outputs().fold(
221 None,
222 |acc: Option<Rectangle<i32, Logical>>, output| {
223 self.niri
224 .global_space
225 .output_geometry(output)
226 .map(|geo| acc.map(|acc| acc.merge(geo)).unwrap_or(geo))
227 },
228 )
229 }
230
231 /// Computes the cursor position for the tablet event.
232 ///
233 /// This function handles the tablet output mapping, as well as coordinate clamping and aspect
234 /// ratio correction.
235 fn compute_tablet_position<I: InputBackend>(
236 &self,
237 event: &(impl Event<I> + TabletToolEvent<I>),
238 ) -> Option<Point<f64, Logical>>
239 where
240 I::Device: 'static,
241 {
242 let (target_geo, keep_ratio, px) = if let Some(output) = self.niri.output_for_tablet() {
243 (
244 self.niri.global_space.output_geometry(output).unwrap(),
245 true,
246 1. / output.current_scale().fractional_scale(),
247 )
248 } else {
249 let geo = self.global_bounding_rectangle()?;
250
251 // FIXME: this 1 px size should ideally somehow be computed for the rightmost output
252 // corresponding to the position on the right when clamping.
253 let output = self.niri.global_space.outputs().next().unwrap();
254 let scale = output.current_scale().fractional_scale();
255
256 // Do not keep ratio for the unified mode as this is what OpenTabletDriver expects.
257 (geo, false, 1. / scale)
258 };
259
260 let mut pos = event.position_transformed(target_geo.size);
261
262 if keep_ratio {
263 pos.x /= target_geo.size.w as f64;
264 pos.y /= target_geo.size.h as f64;
265
266 let device = event.device();
267 if let Some(device) = (&device as &dyn Any).downcast_ref::<input::Device>() {
268 if let Some(data) = self.niri.tablets.get(device) {
269 // This code does the same thing as mutter with "keep aspect ratio" enabled.
270 let output_aspect_ratio = target_geo.size.w as f64 / target_geo.size.h as f64;
271 let ratio = data.aspect_ratio / output_aspect_ratio;
272
273 if ratio > 1. {
274 pos.x *= ratio;
275 } else {
276 pos.y /= ratio;
277 }
278 }
279 };
280
281 pos.x *= target_geo.size.w as f64;
282 pos.y *= target_geo.size.h as f64;
283 }
284
285 pos.x = pos.x.clamp(0.0, target_geo.size.w as f64 - px);
286 pos.y = pos.y.clamp(0.0, target_geo.size.h as f64 - px);
287 Some(pos + target_geo.loc.to_f64())
288 }
289
290 fn on_keyboard<I: InputBackend>(&mut self, event: I::KeyboardKeyEvent) {
291 let comp_mod = self.backend.mod_key();
292
293 let serial = SERIAL_COUNTER.next_serial();
294 let time = Event::time_msec(&event);
295 let pressed = event.state() == KeyState::Pressed;
296
297 // Stop bind key repeat on any release. This won't work 100% correctly in cases like:
298 // 1. Press Mod
299 // 2. Press Left (repeat starts)
300 // 3. Press PgDown (new repeat starts)
301 // 4. Release Left (PgDown repeat stops)
302 // But it's good enough for now.
303 // FIXME: handle this properly.
304 if !pressed {
305 if let Some(token) = self.niri.bind_repeat_timer.take() {
306 self.niri.event_loop.remove(token);
307 }
308 }
309
310 let Some(Some(bind)) = self.niri.seat.get_keyboard().unwrap().input(
311 self,
312 event.key_code(),
313 event.state(),
314 serial,
315 time,
316 |this, mods, keysym| {
317 let bindings = &this.niri.config.borrow().binds;
318 let key_code = event.key_code();
319 let modified = keysym.modified_sym();
320 let raw = keysym.raw_latin_sym_or_raw_current_sym();
321
322 if let Some(dialog) = &this.niri.exit_confirm_dialog {
323 if dialog.is_open() && pressed && raw == Some(Keysym::Return) {
324 info!("quitting after confirming exit dialog");
325 this.niri.stop_signal.stop();
326 }
327 }
328
329 should_intercept_key(
330 &mut this.niri.suppressed_keys,
331 bindings,
332 comp_mod,
333 key_code,
334 modified,
335 raw,
336 pressed,
337 *mods,
338 &this.niri.screenshot_ui,
339 this.niri.config.borrow().input.disable_power_key_handling,
340 )
341 },
342 ) else {
343 return;
344 };
345
346 if !pressed {
347 return;
348 }
349
350 self.handle_bind(bind.clone());
351
352 // Start the key repeat timer if necessary.
353 if !bind.repeat {
354 return;
355 }
356
357 // Stop the previous key repeat if any.
358 if let Some(token) = self.niri.bind_repeat_timer.take() {
359 self.niri.event_loop.remove(token);
360 }
361
362 let config = self.niri.config.borrow();
363 let config = &config.input.keyboard;
364
365 let repeat_rate = config.repeat_rate;
366 if repeat_rate == 0 {
367 return;
368 }
369 let repeat_duration = Duration::from_secs_f64(1. / f64::from(repeat_rate));
370
371 let repeat_timer =
372 Timer::from_duration(Duration::from_millis(u64::from(config.repeat_delay)));
373
374 let token = self
375 .niri
376 .event_loop
377 .insert_source(repeat_timer, move |_, _, state| {
378 state.handle_bind(bind.clone());
379 TimeoutAction::ToDuration(repeat_duration)
380 })
381 .unwrap();
382
383 self.niri.bind_repeat_timer = Some(token);
384 }
385
386 pub fn handle_bind(&mut self, bind: Bind) {
387 let Some(cooldown) = bind.cooldown else {
388 self.do_action(bind.action, bind.allow_when_locked);
389 return;
390 };
391
392 // Check this first so that it doesn't trigger the cooldown.
393 if self.niri.is_locked() && !(bind.allow_when_locked || allowed_when_locked(&bind.action)) {
394 return;
395 }
396
397 match self.niri.bind_cooldown_timers.entry(bind.key) {
398 // The bind is on cooldown.
399 Entry::Occupied(_) => (),
400 Entry::Vacant(entry) => {
401 let timer = Timer::from_duration(cooldown);
402 let token = self
403 .niri
404 .event_loop
405 .insert_source(timer, move |_, _, state| {
406 if state.niri.bind_cooldown_timers.remove(&bind.key).is_none() {
407 error!("bind cooldown timer entry disappeared");
408 }
409 TimeoutAction::Drop
410 })
411 .unwrap();
412 entry.insert(token);
413
414 self.do_action(bind.action, bind.allow_when_locked);
415 }
416 }
417 }
418
419 pub fn do_action(&mut self, action: Action, allow_when_locked: bool) {
420 if self.niri.is_locked() && !(allow_when_locked || allowed_when_locked(&action)) {
421 return;
422 }
423
424 if let Some(touch) = self.niri.seat.get_touch() {
425 touch.cancel(self);
426 }
427
428 match action {
429 Action::Quit(skip_confirmation) => {
430 if !skip_confirmation {
431 if let Some(dialog) = &mut self.niri.exit_confirm_dialog {
432 if dialog.show() {
433 self.niri.queue_redraw_all();
434 }
435 return;
436 }
437 }
438
439 info!("quitting as requested");
440 self.niri.stop_signal.stop()
441 }
442 Action::ChangeVt(vt) => {
443 self.backend.change_vt(vt);
444 // Changing VT may not deliver the key releases, so clear the state.
445 self.niri.suppressed_keys.clear();
446 }
447 Action::Suspend => {
448 self.backend.suspend();
449 // Suspend may not deliver the key releases, so clear the state.
450 self.niri.suppressed_keys.clear();
451 }
452 Action::PowerOffMonitors => {
453 self.niri.deactivate_monitors(&mut self.backend);
454 }
455 Action::ToggleDebugTint => {
456 self.backend.toggle_debug_tint();
457 self.niri.queue_redraw_all();
458 }
459 Action::DebugToggleOpaqueRegions => {
460 self.niri.debug_draw_opaque_regions = !self.niri.debug_draw_opaque_regions;
461 self.niri.queue_redraw_all();
462 }
463 Action::DebugToggleDamage => {
464 self.niri.debug_toggle_damage();
465 }
466 Action::Spawn(command) => {
467 spawn(command);
468 }
469 Action::DoScreenTransition(delay_ms) => {
470 self.backend.with_primary_renderer(|renderer| {
471 self.niri.do_screen_transition(renderer, delay_ms);
472 });
473 }
474 Action::ScreenshotScreen => {
475 let active = self.niri.layout.active_output().cloned();
476 if let Some(active) = active {
477 self.backend.with_primary_renderer(|renderer| {
478 if let Err(err) = self.niri.screenshot(renderer, &active) {
479 warn!("error taking screenshot: {err:?}");
480 }
481 });
482 }
483 }
484 Action::ConfirmScreenshot => {
485 self.backend.with_primary_renderer(|renderer| {
486 match self.niri.screenshot_ui.capture(renderer) {
487 Ok((size, pixels)) => {
488 if let Err(err) = self.niri.save_screenshot(size, pixels) {
489 warn!("error saving screenshot: {err:?}");
490 }
491 }
492 Err(err) => {
493 warn!("error capturing screenshot: {err:?}");
494 }
495 }
496 });
497
498 self.niri.screenshot_ui.close();
499 self.niri
500 .cursor_manager
501 .set_cursor_image(CursorImageStatus::default_named());
502 self.niri.queue_redraw_all();
503 }
504 Action::CancelScreenshot => {
505 self.niri.screenshot_ui.close();
506 self.niri
507 .cursor_manager
508 .set_cursor_image(CursorImageStatus::default_named());
509 self.niri.queue_redraw_all();
510 }
511 Action::ScreenshotTogglePointer => {
512 self.niri.screenshot_ui.toggle_pointer();
513 self.niri.queue_redraw_all();
514 }
515 Action::Screenshot => {
516 self.open_screenshot_ui();
517 }
518 Action::ScreenshotWindow => {
519 let active = self.niri.layout.active_window();
520 if let Some((mapped, output)) = active {
521 self.backend.with_primary_renderer(|renderer| {
522 if let Err(err) = self.niri.screenshot_window(renderer, output, mapped) {
523 warn!("error taking screenshot: {err:?}");
524 }
525 });
526 }
527 }
528 Action::CloseWindow => {
529 if let Some(mapped) = self.niri.layout.focus() {
530 mapped.toplevel().send_close();
531 }
532 }
533 Action::FullscreenWindow => {
534 let focus = self.niri.layout.focus().map(|m| m.window.clone());
535 if let Some(window) = focus {
536 self.niri.layout.toggle_fullscreen(&window);
537 // FIXME: granular
538 self.niri.queue_redraw_all();
539 }
540 }
541 Action::SwitchLayout(action) => {
542 self.niri.seat.get_keyboard().unwrap().with_xkb_state(
543 self,
544 |mut state| match action {
545 LayoutSwitchTarget::Next => state.cycle_next_layout(),
546 LayoutSwitchTarget::Prev => state.cycle_prev_layout(),
547 },
548 );
549 }
550 Action::MoveColumnLeft => {
551 self.niri.layout.move_left();
552 self.maybe_warp_cursor_to_focus();
553 // FIXME: granular
554 self.niri.queue_redraw_all();
555 }
556 Action::MoveColumnRight => {
557 self.niri.layout.move_right();
558 self.maybe_warp_cursor_to_focus();
559 // FIXME: granular
560 self.niri.queue_redraw_all();
561 }
562 Action::MoveColumnToFirst => {
563 self.niri.layout.move_column_to_first();
564 self.maybe_warp_cursor_to_focus();
565 // FIXME: granular
566 self.niri.queue_redraw_all();
567 }
568 Action::MoveColumnToLast => {
569 self.niri.layout.move_column_to_last();
570 self.maybe_warp_cursor_to_focus();
571 // FIXME: granular
572 self.niri.queue_redraw_all();
573 }
574 Action::MoveWindowDown => {
575 self.niri.layout.move_down();
576 self.maybe_warp_cursor_to_focus();
577 // FIXME: granular
578 self.niri.queue_redraw_all();
579 }
580 Action::MoveWindowUp => {
581 self.niri.layout.move_up();
582 self.maybe_warp_cursor_to_focus();
583 // FIXME: granular
584 self.niri.queue_redraw_all();
585 }
586 Action::MoveWindowDownOrToWorkspaceDown => {
587 self.niri.layout.move_down_or_to_workspace_down();
588 self.maybe_warp_cursor_to_focus();
589 // FIXME: granular
590 self.niri.queue_redraw_all();
591 }
592 Action::MoveWindowUpOrToWorkspaceUp => {
593 self.niri.layout.move_up_or_to_workspace_up();
594 self.maybe_warp_cursor_to_focus();
595 // FIXME: granular
596 self.niri.queue_redraw_all();
597 }
598 Action::ConsumeOrExpelWindowLeft => {
599 self.niri.layout.consume_or_expel_window_left();
600 self.maybe_warp_cursor_to_focus();
601 // FIXME: granular
602 self.niri.queue_redraw_all();
603 }
604 Action::ConsumeOrExpelWindowRight => {
605 self.niri.layout.consume_or_expel_window_right();
606 self.maybe_warp_cursor_to_focus();
607 // FIXME: granular
608 self.niri.queue_redraw_all();
609 }
610 Action::FocusColumnLeft => {
611 self.niri.layout.focus_left();
612 self.maybe_warp_cursor_to_focus();
613 // FIXME: granular
614 self.niri.queue_redraw_all();
615 }
616 Action::FocusColumnRight => {
617 self.niri.layout.focus_right();
618 self.maybe_warp_cursor_to_focus();
619 // FIXME: granular
620 self.niri.queue_redraw_all();
621 }
622 Action::FocusColumnFirst => {
623 self.niri.layout.focus_column_first();
624 self.maybe_warp_cursor_to_focus();
625 // FIXME: granular
626 self.niri.queue_redraw_all();
627 }
628 Action::FocusColumnLast => {
629 self.niri.layout.focus_column_last();
630 self.maybe_warp_cursor_to_focus();
631 // FIXME: granular
632 self.niri.queue_redraw_all();
633 }
634 Action::FocusColumnRightOrFirst => {
635 self.niri.layout.focus_column_right_or_first();
636 self.maybe_warp_cursor_to_focus();
637 // FIXME: granular
638 self.niri.queue_redraw_all();
639 }
640 Action::FocusColumnLeftOrLast => {
641 self.niri.layout.focus_column_left_or_last();
642 self.maybe_warp_cursor_to_focus();
643 // FIXME: granular
644 self.niri.queue_redraw_all();
645 }
646 Action::FocusWindowOrMonitorUp => {
647 if let Some(output) = self.niri.output_up() {
648 if self.niri.layout.focus_window_up_or_output(&output)
649 && !self.maybe_warp_cursor_to_focus_centered()
650 {
651 self.move_cursor_to_output(&output);
652 } else {
653 self.maybe_warp_cursor_to_focus();
654 }
655 } else {
656 self.niri.layout.focus_up();
657 self.maybe_warp_cursor_to_focus();
658 }
659
660 // FIXME: granular
661 self.niri.queue_redraw_all();
662 }
663 Action::FocusWindowOrMonitorDown => {
664 if let Some(output) = self.niri.output_down() {
665 if self.niri.layout.focus_window_down_or_output(&output)
666 && !self.maybe_warp_cursor_to_focus_centered()
667 {
668 self.move_cursor_to_output(&output);
669 } else {
670 self.maybe_warp_cursor_to_focus();
671 }
672 } else {
673 self.niri.layout.focus_down();
674 self.maybe_warp_cursor_to_focus();
675 }
676
677 // FIXME: granular
678 self.niri.queue_redraw_all();
679 }
680 Action::FocusColumnOrMonitorLeft => {
681 if let Some(output) = self.niri.output_left() {
682 if self.niri.layout.focus_column_left_or_output(&output)
683 && !self.maybe_warp_cursor_to_focus_centered()
684 {
685 self.move_cursor_to_output(&output);
686 } else {
687 self.maybe_warp_cursor_to_focus();
688 }
689 } else {
690 self.niri.layout.focus_left();
691 self.maybe_warp_cursor_to_focus();
692 }
693
694 // FIXME: granular
695 self.niri.queue_redraw_all();
696 }
697 Action::FocusColumnOrMonitorRight => {
698 if let Some(output) = self.niri.output_right() {
699 if self.niri.layout.focus_column_right_or_output(&output)
700 && !self.maybe_warp_cursor_to_focus_centered()
701 {
702 self.move_cursor_to_output(&output);
703 } else {
704 self.maybe_warp_cursor_to_focus();
705 }
706 } else {
707 self.niri.layout.focus_right();
708 self.maybe_warp_cursor_to_focus();
709 }
710
711 // FIXME: granular
712 self.niri.queue_redraw_all();
713 }
714 Action::FocusWindowDown => {
715 self.niri.layout.focus_down();
716 self.maybe_warp_cursor_to_focus();
717 // FIXME: granular
718 self.niri.queue_redraw_all();
719 }
720 Action::FocusWindowUp => {
721 self.niri.layout.focus_up();
722 self.maybe_warp_cursor_to_focus();
723 // FIXME: granular
724 self.niri.queue_redraw_all();
725 }
726 Action::FocusWindowDownOrColumnLeft => {
727 self.niri.layout.focus_down_or_left();
728 self.maybe_warp_cursor_to_focus();
729 // FIXME: granular
730 self.niri.queue_redraw_all();
731 }
732 Action::FocusWindowDownOrColumnRight => {
733 self.niri.layout.focus_down_or_right();
734 self.maybe_warp_cursor_to_focus();
735 // FIXME: granular
736 self.niri.queue_redraw_all();
737 }
738 Action::FocusWindowUpOrColumnLeft => {
739 self.niri.layout.focus_up_or_left();
740 self.maybe_warp_cursor_to_focus();
741 // FIXME: granular
742 self.niri.queue_redraw_all();
743 }
744 Action::FocusWindowUpOrColumnRight => {
745 self.niri.layout.focus_up_or_right();
746 self.maybe_warp_cursor_to_focus();
747 // FIXME: granular
748 self.niri.queue_redraw_all();
749 }
750 Action::FocusWindowOrWorkspaceDown => {
751 self.niri.layout.focus_window_or_workspace_down();
752 self.maybe_warp_cursor_to_focus();
753 // FIXME: granular
754 self.niri.queue_redraw_all();
755 }
756 Action::FocusWindowOrWorkspaceUp => {
757 self.niri.layout.focus_window_or_workspace_up();
758 self.maybe_warp_cursor_to_focus();
759 // FIXME: granular
760 self.niri.queue_redraw_all();
761 }
762 Action::MoveWindowToWorkspaceDown => {
763 self.niri.layout.move_to_workspace_down();
764 self.maybe_warp_cursor_to_focus();
765 // FIXME: granular
766 self.niri.queue_redraw_all();
767 }
768 Action::MoveWindowToWorkspaceUp => {
769 self.niri.layout.move_to_workspace_up();
770 self.maybe_warp_cursor_to_focus();
771 // FIXME: granular
772 self.niri.queue_redraw_all();
773 }
774 Action::MoveWindowToWorkspace(reference) => {
775 if let Some((output, index)) = self.niri.find_output_and_workspace_index(reference)
776 {
777 if let Some(output) = output {
778 self.niri.layout.move_to_workspace_on_output(&output, index);
779 if !self.maybe_warp_cursor_to_focus_centered() {
780 self.move_cursor_to_output(&output);
781 }
782 } else {
783 self.niri.layout.move_to_workspace(index);
784 self.maybe_warp_cursor_to_focus();
785 }
786
787 // FIXME: granular
788 self.niri.queue_redraw_all();
789 }
790 }
791 Action::MoveColumnToWorkspaceDown => {
792 self.niri.layout.move_column_to_workspace_down();
793 self.maybe_warp_cursor_to_focus();
794 // FIXME: granular
795 self.niri.queue_redraw_all();
796 }
797 Action::MoveColumnToWorkspaceUp => {
798 self.niri.layout.move_column_to_workspace_up();
799 self.maybe_warp_cursor_to_focus();
800 // FIXME: granular
801 self.niri.queue_redraw_all();
802 }
803 Action::MoveColumnToWorkspace(reference) => {
804 if let Some((output, index)) = self.niri.find_output_and_workspace_index(reference)
805 {
806 if let Some(output) = output {
807 self.niri
808 .layout
809 .move_column_to_workspace_on_output(&output, index);
810 if !self.maybe_warp_cursor_to_focus_centered() {
811 self.move_cursor_to_output(&output);
812 }
813 } else {
814 self.niri.layout.move_column_to_workspace(index);
815 self.maybe_warp_cursor_to_focus();
816 }
817
818 // FIXME: granular
819 self.niri.queue_redraw_all();
820 }
821 }
822 Action::FocusWorkspaceDown => {
823 self.niri.layout.switch_workspace_down();
824 self.maybe_warp_cursor_to_focus();
825 // FIXME: granular
826 self.niri.queue_redraw_all();
827 }
828 Action::FocusWorkspaceUp => {
829 self.niri.layout.switch_workspace_up();
830 self.maybe_warp_cursor_to_focus();
831 // FIXME: granular
832 self.niri.queue_redraw_all();
833 }
834 Action::FocusWorkspace(reference) => {
835 if let Some((output, index)) = self.niri.find_output_and_workspace_index(reference)
836 {
837 if let Some(output) = output {
838 self.niri.layout.focus_output(&output);
839 self.niri.layout.switch_workspace(index);
840 if !self.maybe_warp_cursor_to_focus_centered() {
841 self.move_cursor_to_output(&output);
842 }
843 } else {
844 let config = &self.niri.config;
845 if config.borrow().input.workspace_auto_back_and_forth {
846 self.niri.layout.switch_workspace_auto_back_and_forth(index);
847 } else {
848 self.niri.layout.switch_workspace(index);
849 }
850 self.maybe_warp_cursor_to_focus();
851 }
852
853 // FIXME: granular
854 self.niri.queue_redraw_all();
855 }
856 }
857 Action::FocusWorkspacePrevious => {
858 self.niri.layout.switch_workspace_previous();
859 // FIXME: granular
860 self.niri.queue_redraw_all();
861 }
862 Action::MoveWorkspaceDown => {
863 self.niri.layout.move_workspace_down();
864 // FIXME: granular
865 self.niri.queue_redraw_all();
866 }
867 Action::MoveWorkspaceUp => {
868 self.niri.layout.move_workspace_up();
869 // FIXME: granular
870 self.niri.queue_redraw_all();
871 }
872 Action::ConsumeWindowIntoColumn => {
873 self.niri.layout.consume_into_column();
874 // This does not cause immediate focus or window size change, so warping mouse to
875 // focus won't do anything here.
876 // FIXME: granular
877 self.niri.queue_redraw_all();
878 }
879 Action::ExpelWindowFromColumn => {
880 self.niri.layout.expel_from_column();
881 self.maybe_warp_cursor_to_focus();
882 // FIXME: granular
883 self.niri.queue_redraw_all();
884 }
885 Action::SwitchPresetColumnWidth => {
886 self.niri.layout.toggle_width();
887 }
888 Action::CenterColumn => {
889 self.niri.layout.center_column();
890 // FIXME: granular
891 self.niri.queue_redraw_all();
892 }
893 Action::MaximizeColumn => {
894 self.niri.layout.toggle_full_width();
895 }
896 Action::FocusMonitorLeft => {
897 if let Some(output) = self.niri.output_left() {
898 self.niri.layout.focus_output(&output);
899 if !self.maybe_warp_cursor_to_focus_centered() {
900 self.move_cursor_to_output(&output);
901 }
902 }
903 }
904 Action::FocusMonitorRight => {
905 if let Some(output) = self.niri.output_right() {
906 self.niri.layout.focus_output(&output);
907 if !self.maybe_warp_cursor_to_focus_centered() {
908 self.move_cursor_to_output(&output);
909 }
910 }
911 }
912 Action::FocusMonitorDown => {
913 if let Some(output) = self.niri.output_down() {
914 self.niri.layout.focus_output(&output);
915 if !self.maybe_warp_cursor_to_focus_centered() {
916 self.move_cursor_to_output(&output);
917 }
918 }
919 }
920 Action::FocusMonitorUp => {
921 if let Some(output) = self.niri.output_up() {
922 self.niri.layout.focus_output(&output);
923 if !self.maybe_warp_cursor_to_focus_centered() {
924 self.move_cursor_to_output(&output);
925 }
926 }
927 }
928 Action::MoveWindowToMonitorLeft => {
929 if let Some(output) = self.niri.output_left() {
930 self.niri.layout.move_to_output(&output);
931 self.niri.layout.focus_output(&output);
932 if !self.maybe_warp_cursor_to_focus_centered() {
933 self.move_cursor_to_output(&output);
934 }
935 }
936 }
937 Action::MoveWindowToMonitorRight => {
938 if let Some(output) = self.niri.output_right() {
939 self.niri.layout.move_to_output(&output);
940 self.niri.layout.focus_output(&output);
941 if !self.maybe_warp_cursor_to_focus_centered() {
942 self.move_cursor_to_output(&output);
943 }
944 }
945 }
946 Action::MoveWindowToMonitorDown => {
947 if let Some(output) = self.niri.output_down() {
948 self.niri.layout.move_to_output(&output);
949 self.niri.layout.focus_output(&output);
950 if !self.maybe_warp_cursor_to_focus_centered() {
951 self.move_cursor_to_output(&output);
952 }
953 }
954 }
955 Action::MoveWindowToMonitorUp => {
956 if let Some(output) = self.niri.output_up() {
957 self.niri.layout.move_to_output(&output);
958 self.niri.layout.focus_output(&output);
959 if !self.maybe_warp_cursor_to_focus_centered() {
960 self.move_cursor_to_output(&output);
961 }
962 }
963 }
964 Action::MoveColumnToMonitorLeft => {
965 if let Some(output) = self.niri.output_left() {
966 self.niri.layout.move_column_to_output(&output);
967 self.niri.layout.focus_output(&output);
968 if !self.maybe_warp_cursor_to_focus_centered() {
969 self.move_cursor_to_output(&output);
970 }
971 }
972 }
973 Action::MoveColumnToMonitorRight => {
974 if let Some(output) = self.niri.output_right() {
975 self.niri.layout.move_column_to_output(&output);
976 self.niri.layout.focus_output(&output);
977 if !self.maybe_warp_cursor_to_focus_centered() {
978 self.move_cursor_to_output(&output);
979 }
980 }
981 }
982 Action::MoveColumnToMonitorDown => {
983 if let Some(output) = self.niri.output_down() {
984 self.niri.layout.move_column_to_output(&output);
985 self.niri.layout.focus_output(&output);
986 if !self.maybe_warp_cursor_to_focus_centered() {
987 self.move_cursor_to_output(&output);
988 }
989 }
990 }
991 Action::MoveColumnToMonitorUp => {
992 if let Some(output) = self.niri.output_up() {
993 self.niri.layout.move_column_to_output(&output);
994 self.niri.layout.focus_output(&output);
995 if !self.maybe_warp_cursor_to_focus_centered() {
996 self.move_cursor_to_output(&output);
997 }
998 }
999 }
1000 Action::SetColumnWidth(change) => {
1001 self.niri.layout.set_column_width(change);
1002 }
1003 Action::SetWindowHeight(change) => {
1004 self.niri.layout.set_window_height(change);
1005 }
1006 Action::ResetWindowHeight => {
1007 self.niri.layout.reset_window_height();
1008 }
1009 Action::ShowHotkeyOverlay => {
1010 if self.niri.hotkey_overlay.show() {
1011 self.niri.queue_redraw_all();
1012 }
1013 }
1014 Action::MoveWorkspaceToMonitorLeft => {
1015 if let Some(output) = self.niri.output_left() {
1016 self.niri.layout.move_workspace_to_output(&output);
1017 if !self.maybe_warp_cursor_to_focus_centered() {
1018 self.move_cursor_to_output(&output);
1019 }
1020 }
1021 }
1022 Action::MoveWorkspaceToMonitorRight => {
1023 if let Some(output) = self.niri.output_right() {
1024 self.niri.layout.move_workspace_to_output(&output);
1025 if !self.maybe_warp_cursor_to_focus_centered() {
1026 self.move_cursor_to_output(&output);
1027 }
1028 }
1029 }
1030 Action::MoveWorkspaceToMonitorDown => {
1031 if let Some(output) = self.niri.output_down() {
1032 self.niri.layout.move_workspace_to_output(&output);
1033 if !self.maybe_warp_cursor_to_focus_centered() {
1034 self.move_cursor_to_output(&output);
1035 }
1036 }
1037 }
1038 Action::MoveWorkspaceToMonitorUp => {
1039 if let Some(output) = self.niri.output_up() {
1040 self.niri.layout.move_workspace_to_output(&output);
1041 if !self.maybe_warp_cursor_to_focus_centered() {
1042 self.move_cursor_to_output(&output);
1043 }
1044 }
1045 }
1046 }
1047 }
1048
1049 fn on_pointer_motion<I: InputBackend>(&mut self, event: I::PointerMotionEvent) {
1050 // We need an output to be able to move the pointer.
1051 if self.niri.global_space.outputs().next().is_none() {
1052 return;
1053 }
1054
1055 let serial = SERIAL_COUNTER.next_serial();
1056
1057 let pointer = self.niri.seat.get_pointer().unwrap();
1058
1059 let pos = pointer.current_location();
1060
1061 // We have an output, so we can compute the new location and focus.
1062 let mut new_pos = pos + event.delta();
1063
1064 // We received an event for the regular pointer, so show it now.
1065 self.niri.pointer_hidden = false;
1066 self.niri.tablet_cursor_location = None;
1067
1068 // Check if we have an active pointer constraint.
1069 let mut pointer_confined = None;
1070 if let Some(focus) = &self.niri.pointer_focus.surface {
1071 let pos_within_surface = pos - focus.1;
1072
1073 let mut pointer_locked = false;
1074 with_pointer_constraint(&focus.0, &pointer, |constraint| {
1075 let Some(constraint) = constraint else { return };
1076 if !constraint.is_active() {
1077 return;
1078 }
1079
1080 // Constraint does not apply if not within region.
1081 if let Some(region) = constraint.region() {
1082 if !region.contains(pos_within_surface.to_i32_round()) {
1083 return;
1084 }
1085 }
1086
1087 match &*constraint {
1088 PointerConstraint::Locked(_locked) => {
1089 pointer_locked = true;
1090 }
1091 PointerConstraint::Confined(confine) => {
1092 pointer_confined = Some((focus.clone(), confine.region().cloned()));
1093 }
1094 }
1095 });
1096
1097 // If the pointer is locked, only send relative motion.
1098 if pointer_locked {
1099 pointer.relative_motion(
1100 self,
1101 Some(focus.clone()),
1102 &RelativeMotionEvent {
1103 delta: event.delta(),
1104 delta_unaccel: event.delta_unaccel(),
1105 utime: event.time(),
1106 },
1107 );
1108
1109 pointer.frame(self);
1110
1111 // I guess a redraw to hide the tablet cursor could be nice? Doesn't matter too
1112 // much here I think.
1113 return;
1114 }
1115 }
1116
1117 if self
1118 .niri
1119 .global_space
1120 .output_under(new_pos)
1121 .next()
1122 .is_none()
1123 {
1124 // We ended up outside the outputs and need to clip the movement.
1125 if let Some(output) = self.niri.global_space.output_under(pos).next() {
1126 // The pointer was previously on some output. Clip the movement against its
1127 // boundaries.
1128 let geom = self.niri.global_space.output_geometry(output).unwrap();
1129 new_pos.x = new_pos
1130 .x
1131 .clamp(geom.loc.x as f64, (geom.loc.x + geom.size.w - 1) as f64);
1132 new_pos.y = new_pos
1133 .y
1134 .clamp(geom.loc.y as f64, (geom.loc.y + geom.size.h - 1) as f64);
1135 } else {
1136 // The pointer was not on any output in the first place. Find one for it.
1137 // Let's do the simple thing and just put it on the first output.
1138 let output = self.niri.global_space.outputs().next().unwrap();
1139 let geom = self.niri.global_space.output_geometry(output).unwrap();
1140 new_pos = center(geom).to_f64();
1141 }
1142 }
1143
1144 if let Some(output) = self.niri.screenshot_ui.selection_output() {
1145 let geom = self.niri.global_space.output_geometry(output).unwrap();
1146 let mut point = (new_pos - geom.loc.to_f64())
1147 .to_physical(output.current_scale().fractional_scale())
1148 .to_i32_round::<i32>();
1149
1150 let size = output.current_mode().unwrap().size;
1151 let transform = output.current_transform();
1152 let size = transform.transform_size(size);
1153 point.x = point.x.clamp(0, size.w - 1);
1154 point.y = point.y.clamp(0, size.h - 1);
1155
1156 self.niri.screenshot_ui.pointer_motion(point);
1157 }
1158
1159 let under = self.niri.surface_under_and_global_space(new_pos);
1160
1161 // Handle confined pointer.
1162 if let Some((focus_surface, region)) = pointer_confined {
1163 let mut prevent = false;
1164
1165 // Prevent the pointer from leaving the focused surface.
1166 if Some(&focus_surface.0) != under.surface.as_ref().map(|(s, _)| s) {
1167 prevent = true;
1168 }
1169
1170 // Prevent the pointer from leaving the confine region, if any.
1171 if let Some(region) = region {
1172 let new_pos_within_surface = new_pos - focus_surface.1;
1173 if !region.contains(new_pos_within_surface.to_i32_round()) {
1174 prevent = true;
1175 }
1176 }
1177
1178 if prevent {
1179 pointer.relative_motion(
1180 self,
1181 Some(focus_surface),
1182 &RelativeMotionEvent {
1183 delta: event.delta(),
1184 delta_unaccel: event.delta_unaccel(),
1185 utime: event.time(),
1186 },
1187 );
1188
1189 pointer.frame(self);
1190
1191 return;
1192 }
1193 }
1194
1195 self.niri.handle_focus_follows_mouse(&under);
1196
1197 // Activate a new confinement if necessary.
1198 self.niri.maybe_activate_pointer_constraint(new_pos, &under);
1199
1200 self.niri.pointer_focus.clone_from(&under);
1201
1202 pointer.motion(
1203 self,
1204 under.surface.clone(),
1205 &MotionEvent {
1206 location: new_pos,
1207 serial,
1208 time: event.time_msec(),
1209 },
1210 );
1211
1212 pointer.relative_motion(
1213 self,
1214 under.surface,
1215 &RelativeMotionEvent {
1216 delta: event.delta(),
1217 delta_unaccel: event.delta_unaccel(),
1218 utime: event.time(),
1219 },
1220 );
1221
1222 pointer.frame(self);
1223
1224 // Redraw to update the cursor position.
1225 // FIXME: redraw only outputs overlapping the cursor.
1226 self.niri.queue_redraw_all();
1227 }
1228
1229 fn on_pointer_motion_absolute<I: InputBackend>(
1230 &mut self,
1231 event: I::PointerMotionAbsoluteEvent,
1232 ) {
1233 let Some(output_geo) = self.global_bounding_rectangle() else {
1234 return;
1235 };
1236
1237 let pos = event.position_transformed(output_geo.size) + output_geo.loc.to_f64();
1238
1239 let serial = SERIAL_COUNTER.next_serial();
1240
1241 let pointer = self.niri.seat.get_pointer().unwrap();
1242
1243 if let Some(output) = self.niri.screenshot_ui.selection_output() {
1244 let geom = self.niri.global_space.output_geometry(output).unwrap();
1245 let mut point = (pos - geom.loc.to_f64())
1246 .to_physical(output.current_scale().fractional_scale())
1247 .to_i32_round::<i32>();
1248
1249 let size = output.current_mode().unwrap().size;
1250 let transform = output.current_transform();
1251 let size = transform.transform_size(size);
1252 point.x = point.x.clamp(0, size.w - 1);
1253 point.y = point.y.clamp(0, size.h - 1);
1254
1255 self.niri.screenshot_ui.pointer_motion(point);
1256 }
1257
1258 let under = self.niri.surface_under_and_global_space(pos);
1259
1260 self.niri.handle_focus_follows_mouse(&under);
1261
1262 self.niri.maybe_activate_pointer_constraint(pos, &under);
1263 self.niri.pointer_focus.clone_from(&under);
1264
1265 pointer.motion(
1266 self,
1267 under.surface,
1268 &MotionEvent {
1269 location: pos,
1270 serial,
1271 time: event.time_msec(),
1272 },
1273 );
1274
1275 pointer.frame(self);
1276
1277 // We moved the pointer, show it.
1278 self.niri.pointer_hidden = false;
1279
1280 // We moved the regular pointer, so show it now.
1281 self.niri.tablet_cursor_location = None;
1282
1283 // Redraw to update the cursor position.
1284 // FIXME: redraw only outputs overlapping the cursor.
1285 self.niri.queue_redraw_all();
1286 }
1287
1288 fn on_pointer_button<I: InputBackend>(&mut self, event: I::PointerButtonEvent) {
1289 let pointer = self.niri.seat.get_pointer().unwrap();
1290
1291 let serial = SERIAL_COUNTER.next_serial();
1292
1293 let button = event.button_code();
1294
1295 let button_state = event.state();
1296
1297 if ButtonState::Pressed == button_state {
1298 if let Some(mapped) = self.niri.window_under_cursor() {
1299 let window = mapped.window.clone();
1300
1301 // Check if we need to start an interactive resize.
1302 if event.button() == Some(MouseButton::Right) && !pointer.is_grabbed() {
1303 let mods = self.niri.seat.get_keyboard().unwrap().modifier_state();
1304 let mod_down = match self.backend.mod_key() {
1305 CompositorMod::Super => mods.logo,
1306 CompositorMod::Alt => mods.alt,
1307 };
1308 if mod_down {
1309 let location = pointer.current_location();
1310 let (output, pos_within_output) = self.niri.output_under(location).unwrap();
1311 let edges = self
1312 .niri
1313 .layout
1314 .resize_edges_under(output, pos_within_output)
1315 .unwrap();
1316
1317 if !edges.is_empty() {
1318 // See if we got a double resize-click gesture.
1319 // FIXME: deduplicate with resize_request in xdg-shell somehow.
1320 let time = get_monotonic_time();
1321 let last_cell = mapped.last_interactive_resize_start();
1322 let last = last_cell.get();
1323 last_cell.set(Some((time, edges)));
1324 if let Some((last_time, last_edges)) = last {
1325 if time.saturating_sub(last_time) <= DOUBLE_CLICK_TIME {
1326 // Allow quick resize after a triple click.
1327 last_cell.set(None);
1328
1329 let intersection = edges.intersection(last_edges);
1330 if intersection.intersects(ResizeEdge::LEFT_RIGHT) {
1331 // FIXME: don't activate once we can pass specific windows
1332 // to actions.
1333 self.niri.layout.activate_window(&window);
1334 self.niri.layout.toggle_full_width();
1335 }
1336 if intersection.intersects(ResizeEdge::TOP_BOTTOM) {
1337 // FIXME: don't activate once we can pass specific windows
1338 // to actions.
1339 self.niri.layout.activate_window(&window);
1340 self.niri.layout.reset_window_height();
1341 }
1342 // FIXME: granular.
1343 self.niri.queue_redraw_all();
1344 return;
1345 }
1346 }
1347
1348 self.niri.layout.activate_window(&window);
1349
1350 if self
1351 .niri
1352 .layout
1353 .interactive_resize_begin(window.clone(), edges)
1354 {
1355 let start_data = PointerGrabStartData {
1356 focus: None,
1357 button: event.button_code(),
1358 location,
1359 };
1360 let grab = ResizeGrab::new(start_data, window.clone());
1361 pointer.set_grab(self, grab, serial, Focus::Clear);
1362 self.niri.pointer_grab_ongoing = true;
1363 self.niri.cursor_manager.set_cursor_image(
1364 CursorImageStatus::Named(edges.cursor_icon()),
1365 );
1366 }
1367 }
1368 }
1369 }
1370
1371 self.niri.layout.activate_window(&window);
1372
1373 // FIXME: granular.
1374 self.niri.queue_redraw_all();
1375 } else if let Some(output) = self.niri.output_under_cursor() {
1376 self.niri.layout.activate_output(&output);
1377
1378 // FIXME: granular.
1379 self.niri.queue_redraw_all();
1380 }
1381
1382 if event.button() == Some(MouseButton::Middle) && !pointer.is_grabbed() {
1383 let mods = self.niri.seat.get_keyboard().unwrap().modifier_state();
1384 let mod_down = match self.backend.mod_key() {
1385 CompositorMod::Super => mods.logo,
1386 CompositorMod::Alt => mods.alt,
1387 };
1388 if mod_down {
1389 if let Some(output) = self.niri.output_under_cursor() {
1390 let location = pointer.current_location();
1391 let start_data = PointerGrabStartData {
1392 focus: None,
1393 button: event.button_code(),
1394 location,
1395 };
1396 let grab = SpatialMovementGrab::new(start_data, output);
1397 pointer.set_grab(self, grab, serial, Focus::Clear);
1398 self.niri.pointer_grab_ongoing = true;
1399 self.niri
1400 .cursor_manager
1401 .set_cursor_image(CursorImageStatus::Named(CursorIcon::AllScroll));
1402 }
1403 }
1404 }
1405 };
1406
1407 self.update_pointer_focus();
1408
1409 if ButtonState::Pressed == button_state {
1410 let layer_focus = self.niri.pointer_focus.layer.clone();
1411 self.niri.focus_layer_surface_if_on_demand(layer_focus);
1412 }
1413
1414 if let Some(button) = event.button() {
1415 let pos = pointer.current_location();
1416 if let Some((output, _)) = self.niri.output_under(pos) {
1417 let output = output.clone();
1418 let geom = self.niri.global_space.output_geometry(&output).unwrap();
1419 let mut point = (pos - geom.loc.to_f64())
1420 .to_physical(output.current_scale().fractional_scale())
1421 .to_i32_round();
1422
1423 let size = output.current_mode().unwrap().size;
1424 let transform = output.current_transform();
1425 let size = transform.transform_size(size);
1426 point.x = min(size.w - 1, point.x);
1427 point.y = min(size.h - 1, point.y);
1428
1429 if self
1430 .niri
1431 .screenshot_ui
1432 .pointer_button(output, point, button, button_state)
1433 {
1434 self.niri.queue_redraw_all();
1435 }
1436 }
1437 }
1438
1439 pointer.button(
1440 self,
1441 &ButtonEvent {
1442 button,
1443 state: button_state,
1444 serial,
1445 time: event.time_msec(),
1446 },
1447 );
1448 pointer.frame(self);
1449 }
1450
1451 fn on_pointer_axis<I: InputBackend>(&mut self, event: I::PointerAxisEvent) {
1452 let source = event.source();
1453
1454 let horizontal_amount_v120 = event.amount_v120(Axis::Horizontal);
1455 let vertical_amount_v120 = event.amount_v120(Axis::Vertical);
1456
1457 // Handle wheel scroll bindings.
1458 if source == AxisSource::Wheel {
1459 // If we have a scroll bind with current modifiers, then accumulate and don't pass to
1460 // Wayland. If there's no bind, reset the accumulator.
1461 let mods = self.niri.seat.get_keyboard().unwrap().modifier_state();
1462 let modifiers = modifiers_from_state(mods);
1463 if self.niri.mods_with_wheel_binds.contains(&modifiers) {
1464 let comp_mod = self.backend.mod_key();
1465
1466 let horizontal = horizontal_amount_v120.unwrap_or(0.);
1467 let ticks = self.niri.horizontal_wheel_tracker.accumulate(horizontal);
1468 if ticks != 0 {
1469 let config = self.niri.config.borrow();
1470 let bindings = &config.binds;
1471 let bind_left =
1472 find_configured_bind(bindings, comp_mod, Trigger::WheelScrollLeft, mods);
1473 let bind_right =
1474 find_configured_bind(bindings, comp_mod, Trigger::WheelScrollRight, mods);
1475 drop(config);
1476
1477 if let Some(right) = bind_right {
1478 for _ in 0..ticks {
1479 self.handle_bind(right.clone());
1480 }
1481 }
1482 if let Some(left) = bind_left {
1483 for _ in ticks..0 {
1484 self.handle_bind(left.clone());
1485 }
1486 }
1487 }
1488
1489 let vertical = vertical_amount_v120.unwrap_or(0.);
1490 let ticks = self.niri.vertical_wheel_tracker.accumulate(vertical);
1491 if ticks != 0 {
1492 let config = self.niri.config.borrow();
1493 let bindings = &config.binds;
1494 let bind_up =
1495 find_configured_bind(bindings, comp_mod, Trigger::WheelScrollUp, mods);
1496 let bind_down =
1497 find_configured_bind(bindings, comp_mod, Trigger::WheelScrollDown, mods);
1498 drop(config);
1499
1500 if let Some(down) = bind_down {
1501 for _ in 0..ticks {
1502 self.handle_bind(down.clone());
1503 }
1504 }
1505 if let Some(up) = bind_up {
1506 for _ in ticks..0 {
1507 self.handle_bind(up.clone());
1508 }
1509 }
1510 }
1511
1512 return;
1513 } else {
1514 self.niri.horizontal_wheel_tracker.reset();
1515 self.niri.vertical_wheel_tracker.reset();
1516 }
1517 }
1518
1519 let horizontal_amount = event.amount(Axis::Horizontal);
1520 let vertical_amount = event.amount(Axis::Vertical);
1521
1522 // Handle touchpad scroll bindings.
1523 if source == AxisSource::Finger {
1524 let mods = self.niri.seat.get_keyboard().unwrap().modifier_state();
1525 let modifiers = modifiers_from_state(mods);
1526 if self.niri.mods_with_finger_scroll_binds.contains(&modifiers) {
1527 let comp_mod = self.backend.mod_key();
1528
1529 let horizontal = horizontal_amount.unwrap_or(0.);
1530 let ticks = self
1531 .niri
1532 .horizontal_finger_scroll_tracker
1533 .accumulate(horizontal);
1534 if ticks != 0 {
1535 let config = self.niri.config.borrow();
1536 let bindings = &config.binds;
1537 let bind_left =
1538 find_configured_bind(bindings, comp_mod, Trigger::TouchpadScrollLeft, mods);
1539 let bind_right = find_configured_bind(
1540 bindings,
1541 comp_mod,
1542 Trigger::TouchpadScrollRight,
1543 mods,
1544 );
1545 drop(config);
1546
1547 if let Some(right) = bind_right {
1548 for _ in 0..ticks {
1549 self.handle_bind(right.clone());
1550 }
1551 }
1552 if let Some(left) = bind_left {
1553 for _ in ticks..0 {
1554 self.handle_bind(left.clone());
1555 }
1556 }
1557 }
1558
1559 let vertical = vertical_amount.unwrap_or(0.);
1560 let ticks = self
1561 .niri
1562 .vertical_finger_scroll_tracker
1563 .accumulate(vertical);
1564 if ticks != 0 {
1565 let config = self.niri.config.borrow();
1566 let bindings = &config.binds;
1567 let bind_up =
1568 find_configured_bind(bindings, comp_mod, Trigger::TouchpadScrollUp, mods);
1569 let bind_down =
1570 find_configured_bind(bindings, comp_mod, Trigger::TouchpadScrollDown, mods);
1571 drop(config);
1572
1573 if let Some(down) = bind_down {
1574 for _ in 0..ticks {
1575 self.handle_bind(down.clone());
1576 }
1577 }
1578 if let Some(up) = bind_up {
1579 for _ in ticks..0 {
1580 self.handle_bind(up.clone());
1581 }
1582 }
1583 }
1584
1585 return;
1586 } else {
1587 self.niri.horizontal_finger_scroll_tracker.reset();
1588 self.niri.vertical_finger_scroll_tracker.reset();
1589 }
1590 }
1591
1592 let horizontal_amount = horizontal_amount.unwrap_or_else(|| {
1593 // Winit backend, discrete scrolling.
1594 horizontal_amount_v120.unwrap_or(0.0) / 120. * 15.
1595 });
1596 let vertical_amount = vertical_amount.unwrap_or_else(|| {
1597 // Winit backend, discrete scrolling.
1598 vertical_amount_v120.unwrap_or(0.0) / 120. * 15.
1599 });
1600
1601 let mut frame = AxisFrame::new(event.time_msec()).source(source);
1602 if horizontal_amount != 0.0 {
1603 frame = frame
1604 .relative_direction(Axis::Horizontal, event.relative_direction(Axis::Horizontal));
1605 frame = frame.value(Axis::Horizontal, horizontal_amount);
1606 if let Some(v120) = horizontal_amount_v120 {
1607 frame = frame.v120(Axis::Horizontal, v120 as i32);
1608 }
1609 }
1610 if vertical_amount != 0.0 {
1611 frame =
1612 frame.relative_direction(Axis::Vertical, event.relative_direction(Axis::Vertical));
1613 frame = frame.value(Axis::Vertical, vertical_amount);
1614 if let Some(v120) = vertical_amount_v120 {
1615 frame = frame.v120(Axis::Vertical, v120 as i32);
1616 }
1617 }
1618
1619 if source == AxisSource::Finger {
1620 if event.amount(Axis::Horizontal) == Some(0.0) {
1621 frame = frame.stop(Axis::Horizontal);
1622 }
1623 if event.amount(Axis::Vertical) == Some(0.0) {
1624 frame = frame.stop(Axis::Vertical);
1625 }
1626 }
1627
1628 self.update_pointer_focus();
1629
1630 let pointer = &self.niri.seat.get_pointer().unwrap();
1631 pointer.axis(self, frame);
1632 pointer.frame(self);
1633 }
1634
1635 fn on_tablet_tool_axis<I: InputBackend>(&mut self, event: I::TabletToolAxisEvent)
1636 where
1637 I::Device: 'static, // Needed for downcasting.
1638 {
1639 let Some(pos) = self.compute_tablet_position(&event) else {
1640 return;
1641 };
1642
1643 let under = self.niri.surface_under_and_global_space(pos);
1644
1645 let tablet_seat = self.niri.seat.tablet_seat();
1646 let tablet = tablet_seat.get_tablet(&TabletDescriptor::from(&event.device()));
1647 let tool = tablet_seat.get_tool(&event.tool());
1648 if let (Some(tablet), Some(tool)) = (tablet, tool) {
1649 if event.pressure_has_changed() {
1650 tool.pressure(event.pressure());
1651 }
1652 if event.distance_has_changed() {
1653 tool.distance(event.distance());
1654 }
1655 if event.tilt_has_changed() {
1656 tool.tilt(event.tilt());
1657 }
1658 if event.slider_has_changed() {
1659 tool.slider_position(event.slider_position());
1660 }
1661 if event.rotation_has_changed() {
1662 tool.rotation(event.rotation());
1663 }
1664 if event.wheel_has_changed() {
1665 tool.wheel(event.wheel_delta(), event.wheel_delta_discrete());
1666 }
1667
1668 tool.motion(
1669 pos,
1670 under.surface,
1671 &tablet,
1672 SERIAL_COUNTER.next_serial(),
1673 event.time_msec(),
1674 );
1675
1676 self.niri.pointer_hidden = false;
1677 self.niri.tablet_cursor_location = Some(pos);
1678 }
1679
1680 // Redraw to update the cursor position.
1681 // FIXME: redraw only outputs overlapping the cursor.
1682 self.niri.queue_redraw_all();
1683 }
1684
1685 fn on_tablet_tool_tip<I: InputBackend>(&mut self, event: I::TabletToolTipEvent) {
1686 let tool = self.niri.seat.tablet_seat().get_tool(&event.tool());
1687
1688 if let Some(tool) = tool {
1689 match event.tip_state() {
1690 TabletToolTipState::Down => {
1691 let serial = SERIAL_COUNTER.next_serial();
1692 tool.tip_down(serial, event.time_msec());
1693
1694 if let Some(pos) = self.niri.tablet_cursor_location {
1695 let under = self.niri.surface_under_and_global_space(pos);
1696 if let Some(window) = under.window {
1697 self.niri.layout.activate_window(&window);
1698
1699 // FIXME: granular.
1700 self.niri.queue_redraw_all();
1701 } else if let Some(output) = under.output {
1702 self.niri.layout.activate_output(&output);
1703
1704 // FIXME: granular.
1705 self.niri.queue_redraw_all();
1706 }
1707 self.niri.focus_layer_surface_if_on_demand(under.layer);
1708 }
1709 }
1710 TabletToolTipState::Up => {
1711 tool.tip_up(event.time_msec());
1712 }
1713 }
1714 }
1715 }
1716
1717 fn on_tablet_tool_proximity<I: InputBackend>(&mut self, event: I::TabletToolProximityEvent)
1718 where
1719 I::Device: 'static, // Needed for downcasting.
1720 {
1721 let Some(pos) = self.compute_tablet_position(&event) else {
1722 return;
1723 };
1724
1725 let under = self.niri.surface_under_and_global_space(pos);
1726
1727 let tablet_seat = self.niri.seat.tablet_seat();
1728 let tool = tablet_seat.add_tool::<Self>(&self.niri.display_handle, &event.tool());
1729 let tablet = tablet_seat.get_tablet(&TabletDescriptor::from(&event.device()));
1730 if let Some(tablet) = tablet {
1731 match event.state() {
1732 ProximityState::In => {
1733 if let Some(under) = under.surface {
1734 tool.proximity_in(
1735 pos,
1736 under,
1737 &tablet,
1738 SERIAL_COUNTER.next_serial(),
1739 event.time_msec(),
1740 );
1741 }
1742 self.niri.pointer_hidden = false;
1743 self.niri.tablet_cursor_location = Some(pos);
1744 }
1745 ProximityState::Out => {
1746 tool.proximity_out(event.time_msec());
1747
1748 // Move the mouse pointer here to avoid discontinuity.
1749 //
1750 // Plus, Wayland SDL2 currently warps the pointer into some weird
1751 // location on proximity out, so this should help it a little.
1752 if let Some(pos) = self.niri.tablet_cursor_location {
1753 self.move_cursor(pos);
1754 }
1755
1756 self.niri.tablet_cursor_location = None;
1757 }
1758 }
1759
1760 // FIXME: granular.
1761 self.niri.queue_redraw_all();
1762 }
1763 }
1764
1765 fn on_tablet_tool_button<I: InputBackend>(&mut self, event: I::TabletToolButtonEvent) {
1766 let tool = self.niri.seat.tablet_seat().get_tool(&event.tool());
1767
1768 if let Some(tool) = tool {
1769 tool.button(
1770 event.button(),
1771 event.button_state(),
1772 SERIAL_COUNTER.next_serial(),
1773 event.time_msec(),
1774 );
1775 }
1776 }
1777
1778 fn on_gesture_swipe_begin<I: InputBackend>(&mut self, event: I::GestureSwipeBeginEvent) {
1779 if event.fingers() == 3 {
1780 self.niri.gesture_swipe_3f_cumulative = Some((0., 0.));
1781
1782 // We handled this event.
1783 return;
1784 }
1785
1786 let serial = SERIAL_COUNTER.next_serial();
1787 let pointer = self.niri.seat.get_pointer().unwrap();
1788
1789 if self.update_pointer_focus() {
1790 pointer.frame(self);
1791 }
1792
1793 pointer.gesture_swipe_begin(
1794 self,
1795 &GestureSwipeBeginEvent {
1796 serial,
1797 time: event.time_msec(),
1798 fingers: event.fingers(),
1799 },
1800 );
1801 }
1802
1803 fn on_gesture_swipe_update<I: InputBackend + 'static>(
1804 &mut self,
1805 event: I::GestureSwipeUpdateEvent,
1806 ) where
1807 I::Device: 'static,
1808 {
1809 let mut delta_x = event.delta_x();
1810 let mut delta_y = event.delta_y();
1811
1812 if let Some(libinput_event) =
1813 (&event as &dyn Any).downcast_ref::<input::event::gesture::GestureSwipeUpdateEvent>()
1814 {
1815 delta_x = libinput_event.dx_unaccelerated();
1816 delta_y = libinput_event.dy_unaccelerated();
1817 }
1818
1819 let device = event.device();
1820 if let Some(device) = (&device as &dyn Any).downcast_ref::<input::Device>() {
1821 if device.config_scroll_natural_scroll_enabled() {
1822 delta_x = -delta_x;
1823 delta_y = -delta_y;
1824 }
1825 }
1826
1827 if let Some((cx, cy)) = &mut self.niri.gesture_swipe_3f_cumulative {
1828 *cx += delta_x;
1829 *cy += delta_y;
1830
1831 // Check if the gesture moved far enough to decide. Threshold copied from GNOME Shell.
1832 let (cx, cy) = (*cx, *cy);
1833 if cx * cx + cy * cy >= 16. * 16. {
1834 self.niri.gesture_swipe_3f_cumulative = None;
1835
1836 if let Some(output) = self.niri.output_under_cursor() {
1837 if cx.abs() > cy.abs() {
1838 self.niri.layout.view_offset_gesture_begin(&output, true);
1839 } else {
1840 self.niri
1841 .layout
1842 .workspace_switch_gesture_begin(&output, true);
1843 }
1844 }
1845 }
1846 }
1847
1848 let timestamp = Duration::from_micros(event.time());
1849
1850 let mut handled = false;
1851 let res = self
1852 .niri
1853 .layout
1854 .workspace_switch_gesture_update(delta_y, timestamp, true);
1855 if let Some(output) = res {
1856 if let Some(output) = output {
1857 self.niri.queue_redraw(&output);
1858 }
1859 handled = true;
1860 }
1861
1862 let res = self
1863 .niri
1864 .layout
1865 .view_offset_gesture_update(delta_x, timestamp, true);
1866 if let Some(output) = res {
1867 if let Some(output) = output {
1868 self.niri.queue_redraw(&output);
1869 }
1870 handled = true;
1871 }
1872
1873 if handled {
1874 // We handled this event.
1875 return;
1876 }
1877
1878 let pointer = self.niri.seat.get_pointer().unwrap();
1879
1880 if self.update_pointer_focus() {
1881 pointer.frame(self);
1882 }
1883
1884 pointer.gesture_swipe_update(
1885 self,
1886 &GestureSwipeUpdateEvent {
1887 time: event.time_msec(),
1888 delta: event.delta(),
1889 },
1890 );
1891 }
1892
1893 fn on_gesture_swipe_end<I: InputBackend>(&mut self, event: I::GestureSwipeEndEvent) {
1894 self.niri.gesture_swipe_3f_cumulative = None;
1895
1896 let mut handled = false;
1897 let res = self
1898 .niri
1899 .layout
1900 .workspace_switch_gesture_end(event.cancelled(), Some(true));
1901 if let Some(output) = res {
1902 self.niri.queue_redraw(&output);
1903 handled = true;
1904 }
1905
1906 let res = self
1907 .niri
1908 .layout
1909 .view_offset_gesture_end(event.cancelled(), Some(true));
1910 if let Some(output) = res {
1911 self.niri.queue_redraw(&output);
1912 handled = true;
1913 }
1914
1915 if handled {
1916 // We handled this event.
1917 return;
1918 }
1919
1920 let serial = SERIAL_COUNTER.next_serial();
1921 let pointer = self.niri.seat.get_pointer().unwrap();
1922
1923 if self.update_pointer_focus() {
1924 pointer.frame(self);
1925 }
1926
1927 pointer.gesture_swipe_end(
1928 self,
1929 &GestureSwipeEndEvent {
1930 serial,
1931 time: event.time_msec(),
1932 cancelled: event.cancelled(),
1933 },
1934 );
1935 }
1936
1937 fn on_gesture_pinch_begin<I: InputBackend>(&mut self, event: I::GesturePinchBeginEvent) {
1938 let serial = SERIAL_COUNTER.next_serial();
1939 let pointer = self.niri.seat.get_pointer().unwrap();
1940
1941 if self.update_pointer_focus() {
1942 pointer.frame(self);
1943 }
1944
1945 pointer.gesture_pinch_begin(
1946 self,
1947 &GesturePinchBeginEvent {
1948 serial,
1949 time: event.time_msec(),
1950 fingers: event.fingers(),
1951 },
1952 );
1953 }
1954
1955 fn on_gesture_pinch_update<I: InputBackend>(&mut self, event: I::GesturePinchUpdateEvent) {
1956 let pointer = self.niri.seat.get_pointer().unwrap();
1957
1958 if self.update_pointer_focus() {
1959 pointer.frame(self);
1960 }
1961
1962 pointer.gesture_pinch_update(
1963 self,
1964 &GesturePinchUpdateEvent {
1965 time: event.time_msec(),
1966 delta: event.delta(),
1967 scale: event.scale(),
1968 rotation: event.rotation(),
1969 },
1970 );
1971 }
1972
1973 fn on_gesture_pinch_end<I: InputBackend>(&mut self, event: I::GesturePinchEndEvent) {
1974 let serial = SERIAL_COUNTER.next_serial();
1975 let pointer = self.niri.seat.get_pointer().unwrap();
1976
1977 if self.update_pointer_focus() {
1978 pointer.frame(self);
1979 }
1980
1981 pointer.gesture_pinch_end(
1982 self,
1983 &GesturePinchEndEvent {
1984 serial,
1985 time: event.time_msec(),
1986 cancelled: event.cancelled(),
1987 },
1988 );
1989 }
1990
1991 fn on_gesture_hold_begin<I: InputBackend>(&mut self, event: I::GestureHoldBeginEvent) {
1992 let serial = SERIAL_COUNTER.next_serial();
1993 let pointer = self.niri.seat.get_pointer().unwrap();
1994
1995 if self.update_pointer_focus() {
1996 pointer.frame(self);
1997 }
1998
1999 pointer.gesture_hold_begin(
2000 self,
2001 &GestureHoldBeginEvent {
2002 serial,
2003 time: event.time_msec(),
2004 fingers: event.fingers(),
2005 },
2006 );
2007 }
2008
2009 fn on_gesture_hold_end<I: InputBackend>(&mut self, event: I::GestureHoldEndEvent) {
2010 let serial = SERIAL_COUNTER.next_serial();
2011 let pointer = self.niri.seat.get_pointer().unwrap();
2012
2013 if self.update_pointer_focus() {
2014 pointer.frame(self);
2015 }
2016
2017 pointer.gesture_hold_end(
2018 self,
2019 &GestureHoldEndEvent {
2020 serial,
2021 time: event.time_msec(),
2022 cancelled: event.cancelled(),
2023 },
2024 );
2025 }
2026
2027 /// Computes the cursor position for the touch event.
2028 ///
2029 /// This function handles the touch output mapping, as well as coordinate transform
2030 fn compute_touch_location<I: InputBackend, E: AbsolutePositionEvent<I>>(
2031 &self,
2032 evt: &E,
2033 ) -> Option<Point<f64, Logical>> {
2034 let output = self.niri.output_for_touch()?;
2035 let output_geo = self.niri.global_space.output_geometry(output).unwrap();
2036 let transform = output.current_transform();
2037 let size = transform.invert().transform_size(output_geo.size);
2038 Some(
2039 transform.transform_point_in(evt.position_transformed(size), &size.to_f64())
2040 + output_geo.loc.to_f64(),
2041 )
2042 }
2043
2044 fn on_touch_down<I: InputBackend>(&mut self, evt: I::TouchDownEvent) {
2045 let Some(handle) = self.niri.seat.get_touch() else {
2046 return;
2047 };
2048 let Some(touch_location) = self.compute_touch_location(&evt) else {
2049 return;
2050 };
2051
2052 let under = self.niri.surface_under_and_global_space(touch_location);
2053
2054 if !handle.is_grabbed() {
2055 if let Some(window) = under.window {
2056 self.niri.layout.activate_window(&window);
2057
2058 // FIXME: granular.
2059 self.niri.queue_redraw_all();
2060 } else if let Some(output) = under.output {
2061 self.niri.layout.activate_output(&output);
2062
2063 // FIXME: granular.
2064 self.niri.queue_redraw_all();
2065 }
2066 self.niri.focus_layer_surface_if_on_demand(under.layer);
2067 };
2068
2069 let serial = SERIAL_COUNTER.next_serial();
2070 handle.down(
2071 self,
2072 under.surface,
2073 &DownEvent {
2074 slot: evt.slot(),
2075 location: touch_location,
2076 serial,
2077 time: evt.time_msec(),
2078 },
2079 );
2080
2081 // We're using touch, hide the pointer.
2082 self.niri.pointer_hidden = true;
2083 }
2084 fn on_touch_up<I: InputBackend>(&mut self, evt: I::TouchUpEvent) {
2085 let Some(handle) = self.niri.seat.get_touch() else {
2086 return;
2087 };
2088 let serial = SERIAL_COUNTER.next_serial();
2089 handle.up(
2090 self,
2091 &UpEvent {
2092 slot: evt.slot(),
2093 serial,
2094 time: evt.time_msec(),
2095 },
2096 )
2097 }
2098 fn on_touch_motion<I: InputBackend>(&mut self, evt: I::TouchMotionEvent) {
2099 let Some(handle) = self.niri.seat.get_touch() else {
2100 return;
2101 };
2102 let Some(touch_location) = self.compute_touch_location(&evt) else {
2103 return;
2104 };
2105 let under = self.niri.surface_under_and_global_space(touch_location);
2106 handle.motion(
2107 self,
2108 under.surface,
2109 &TouchMotionEvent {
2110 slot: evt.slot(),
2111 location: touch_location,
2112 time: evt.time_msec(),
2113 },
2114 );
2115 }
2116 fn on_touch_frame<I: InputBackend>(&mut self, _evt: I::TouchFrameEvent) {
2117 let Some(handle) = self.niri.seat.get_touch() else {
2118 return;
2119 };
2120 handle.frame(self);
2121 }
2122 fn on_touch_cancel<I: InputBackend>(&mut self, _evt: I::TouchCancelEvent) {
2123 let Some(handle) = self.niri.seat.get_touch() else {
2124 return;
2125 };
2126 handle.cancel(self);
2127 }
2128}
2129
2130/// Check whether the key should be intercepted and mark intercepted
2131/// pressed keys as `suppressed`, thus preventing `releases` corresponding
2132/// to them from being delivered.
2133#[allow(clippy::too_many_arguments)]
2134fn should_intercept_key(
2135 suppressed_keys: &mut HashSet<u32>,
2136 bindings: &Binds,
2137 comp_mod: CompositorMod,
2138 key_code: u32,
2139 modified: Keysym,
2140 raw: Option<Keysym>,
2141 pressed: bool,
2142 mods: ModifiersState,
2143 screenshot_ui: &ScreenshotUi,
2144 disable_power_key_handling: bool,
2145) -> FilterResult<Option<Bind>> {
2146 // Actions are only triggered on presses, release of the key
2147 // shouldn't try to intercept anything unless we have marked
2148 // the key to suppress.
2149 if !pressed && !suppressed_keys.contains(&key_code) {
2150 return FilterResult::Forward;
2151 }
2152
2153 let mut final_bind = find_bind(
2154 bindings,
2155 comp_mod,
2156 modified,
2157 raw,
2158 mods,
2159 disable_power_key_handling,
2160 );
2161
2162 // Allow only a subset of compositor actions while the screenshot UI is open, since the user
2163 // cannot see the screen.
2164 if screenshot_ui.is_open() {
2165 let mut use_screenshot_ui_action = true;
2166
2167 if let Some(bind) = &final_bind {
2168 if allowed_during_screenshot(&bind.action) {
2169 use_screenshot_ui_action = false;
2170 }
2171 }
2172
2173 if use_screenshot_ui_action {
2174 if let Some(raw) = raw {
2175 final_bind = screenshot_ui.action(raw, mods).map(|action| Bind {
2176 key: Key {
2177 trigger: Trigger::Keysym(raw),
2178 // Not entirely correct but it doesn't matter in how we currently use it.
2179 modifiers: Modifiers::empty(),
2180 },
2181 action,
2182 repeat: true,
2183 cooldown: None,
2184 allow_when_locked: false,
2185 });
2186 }
2187 }
2188 }
2189
2190 match (final_bind, pressed) {
2191 (Some(bind), true) => {
2192 suppressed_keys.insert(key_code);
2193 FilterResult::Intercept(Some(bind))
2194 }
2195 (_, false) => {
2196 suppressed_keys.remove(&key_code);
2197 FilterResult::Intercept(None)
2198 }
2199 (None, true) => FilterResult::Forward,
2200 }
2201}
2202
2203fn find_bind(
2204 bindings: &Binds,
2205 comp_mod: CompositorMod,
2206 modified: Keysym,
2207 raw: Option<Keysym>,
2208 mods: ModifiersState,
2209 disable_power_key_handling: bool,
2210) -> Option<Bind> {
2211 use keysyms::*;
2212
2213 // Handle hardcoded binds.
2214 #[allow(non_upper_case_globals)] // wat
2215 let hardcoded_action = match modified.raw() {
2216 modified @ KEY_XF86Switch_VT_1..=KEY_XF86Switch_VT_12 => {
2217 let vt = (modified - KEY_XF86Switch_VT_1 + 1) as i32;
2218 Some(Action::ChangeVt(vt))
2219 }
2220 KEY_XF86PowerOff if !disable_power_key_handling => Some(Action::Suspend),
2221 _ => None,
2222 };
2223
2224 if let Some(action) = hardcoded_action {
2225 return Some(Bind {
2226 key: Key {
2227 // Not entirely correct but it doesn't matter in how we currently use it.
2228 trigger: Trigger::Keysym(modified),
2229 modifiers: Modifiers::empty(),
2230 },
2231 action,
2232 repeat: true,
2233 cooldown: None,
2234 allow_when_locked: false,
2235 });
2236 }
2237
2238 let trigger = Trigger::Keysym(raw?);
2239 find_configured_bind(bindings, comp_mod, trigger, mods)
2240}
2241
2242fn find_configured_bind(
2243 bindings: &Binds,
2244 comp_mod: CompositorMod,
2245 trigger: Trigger,
2246 mods: ModifiersState,
2247) -> Option<Bind> {
2248 // Handle configured binds.
2249 let mut modifiers = modifiers_from_state(mods);
2250
2251 let (mod_down, comp_mod) = match comp_mod {
2252 CompositorMod::Super => (mods.logo, Modifiers::SUPER),
2253 CompositorMod::Alt => (mods.alt, Modifiers::ALT),
2254 };
2255 if mod_down {
2256 modifiers |= Modifiers::COMPOSITOR;
2257 }
2258
2259 for bind in &bindings.0 {
2260 if bind.key.trigger != trigger {
2261 continue;
2262 }
2263
2264 let mut bind_modifiers = bind.key.modifiers;
2265 if bind_modifiers.contains(Modifiers::COMPOSITOR) {
2266 bind_modifiers |= comp_mod;
2267 } else if bind_modifiers.contains(comp_mod) {
2268 bind_modifiers |= Modifiers::COMPOSITOR;
2269 }
2270
2271 if bind_modifiers == modifiers {
2272 return Some(bind.clone());
2273 }
2274 }
2275
2276 None
2277}
2278
2279fn modifiers_from_state(mods: ModifiersState) -> Modifiers {
2280 let mut modifiers = Modifiers::empty();
2281 if mods.ctrl {
2282 modifiers |= Modifiers::CTRL;
2283 }
2284 if mods.shift {
2285 modifiers |= Modifiers::SHIFT;
2286 }
2287 if mods.alt {
2288 modifiers |= Modifiers::ALT;
2289 }
2290 if mods.logo {
2291 modifiers |= Modifiers::SUPER;
2292 }
2293 if mods.iso_level3_shift {
2294 modifiers |= Modifiers::ISO_LEVEL3_SHIFT;
2295 }
2296 modifiers
2297}
2298
2299fn should_activate_monitors<I: InputBackend>(event: &InputEvent<I>) -> bool {
2300 match event {
2301 InputEvent::Keyboard { event } if event.state() == KeyState::Pressed => true,
2302 InputEvent::PointerButton { event } if event.state() == ButtonState::Pressed => true,
2303 InputEvent::PointerMotion { .. }
2304 | InputEvent::PointerMotionAbsolute { .. }
2305 | InputEvent::PointerAxis { .. }
2306 | InputEvent::GestureSwipeBegin { .. }
2307 | InputEvent::GesturePinchBegin { .. }
2308 | InputEvent::GestureHoldBegin { .. }
2309 | InputEvent::TouchDown { .. }
2310 | InputEvent::TouchMotion { .. }
2311 | InputEvent::TabletToolAxis { .. }
2312 | InputEvent::TabletToolProximity { .. }
2313 | InputEvent::TabletToolTip { .. }
2314 | InputEvent::TabletToolButton { .. } => true,
2315 // Ignore events like device additions and removals, key releases, gesture ends.
2316 _ => false,
2317 }
2318}
2319
2320fn should_hide_hotkey_overlay<I: InputBackend>(event: &InputEvent<I>) -> bool {
2321 match event {
2322 InputEvent::Keyboard { event } if event.state() == KeyState::Pressed => true,
2323 InputEvent::PointerButton { event } if event.state() == ButtonState::Pressed => true,
2324 InputEvent::PointerAxis { .. }
2325 | InputEvent::GestureSwipeBegin { .. }
2326 | InputEvent::GesturePinchBegin { .. }
2327 | InputEvent::TouchDown { .. }
2328 | InputEvent::TouchMotion { .. }
2329 | InputEvent::TabletToolTip { .. }
2330 | InputEvent::TabletToolButton { .. } => true,
2331 _ => false,
2332 }
2333}
2334
2335fn should_hide_exit_confirm_dialog<I: InputBackend>(event: &InputEvent<I>) -> bool {
2336 match event {
2337 InputEvent::Keyboard { event } if event.state() == KeyState::Pressed => true,
2338 InputEvent::PointerButton { event } if event.state() == ButtonState::Pressed => true,
2339 InputEvent::PointerAxis { .. }
2340 | InputEvent::GestureSwipeBegin { .. }
2341 | InputEvent::GesturePinchBegin { .. }
2342 | InputEvent::TouchDown { .. }
2343 | InputEvent::TouchMotion { .. }
2344 | InputEvent::TabletToolTip { .. }
2345 | InputEvent::TabletToolButton { .. } => true,
2346 _ => false,
2347 }
2348}
2349
2350fn should_notify_activity<I: InputBackend>(event: &InputEvent<I>) -> bool {
2351 !matches!(
2352 event,
2353 InputEvent::DeviceAdded { .. } | InputEvent::DeviceRemoved { .. }
2354 )
2355}
2356
2357fn allowed_when_locked(action: &Action) -> bool {
2358 matches!(
2359 action,
2360 Action::Quit(_)
2361 | Action::ChangeVt(_)
2362 | Action::Suspend
2363 | Action::PowerOffMonitors
2364 | Action::SwitchLayout(_)
2365 )
2366}
2367
2368fn allowed_during_screenshot(action: &Action) -> bool {
2369 matches!(
2370 action,
2371 Action::Quit(_) | Action::ChangeVt(_) | Action::Suspend | Action::PowerOffMonitors
2372 )
2373}
2374
2375pub fn apply_libinput_settings(config: &niri_config::Input, device: &mut input::Device) {
2376 // According to Mutter code, this setting is specific to touchpads.
2377 let is_touchpad = device.config_tap_finger_count() > 0;
2378 if is_touchpad {
2379 let c = &config.touchpad;
2380 let _ = device.config_send_events_set_mode(if c.off {
2381 input::SendEventsMode::DISABLED
2382 } else if c.disabled_on_external_mouse {
2383 input::SendEventsMode::DISABLED_ON_EXTERNAL_MOUSE
2384 } else {
2385 input::SendEventsMode::ENABLED
2386 });
2387 let _ = device.config_tap_set_enabled(c.tap);
2388 let _ = device.config_dwt_set_enabled(c.dwt);
2389 let _ = device.config_dwtp_set_enabled(c.dwtp);
2390 let _ = device.config_scroll_set_natural_scroll_enabled(c.natural_scroll);
2391 let _ = device.config_accel_set_speed(c.accel_speed);
2392 let _ = device.config_left_handed_set(c.left_handed);
2393
2394 if let Some(accel_profile) = c.accel_profile {
2395 let _ = device.config_accel_set_profile(accel_profile.into());
2396 } else if let Some(default) = device.config_accel_default_profile() {
2397 let _ = device.config_accel_set_profile(default);
2398 }
2399
2400 if let Some(method) = c.scroll_method {
2401 let _ = device.config_scroll_set_method(method.into());
2402 } else if let Some(default) = device.config_scroll_default_method() {
2403 let _ = device.config_scroll_set_method(default);
2404 }
2405
2406 if let Some(tap_button_map) = c.tap_button_map {
2407 let _ = device.config_tap_set_button_map(tap_button_map.into());
2408 } else if let Some(default) = device.config_tap_default_button_map() {
2409 let _ = device.config_tap_set_button_map(default);
2410 }
2411
2412 if let Some(method) = c.click_method {
2413 let _ = device.config_click_set_method(method.into());
2414 } else if let Some(default) = device.config_click_default_method() {
2415 let _ = device.config_click_set_method(default);
2416 }
2417 }
2418
2419 // This is how Mutter tells apart mice.
2420 let mut is_trackball = false;
2421 let mut is_trackpoint = false;
2422 if let Some(udev_device) = unsafe { device.udev_device() } {
2423 if udev_device.property_value("ID_INPUT_TRACKBALL").is_some() {
2424 is_trackball = true;
2425 }
2426 if udev_device
2427 .property_value("ID_INPUT_POINTINGSTICK")
2428 .is_some()
2429 {
2430 is_trackpoint = true;
2431 }
2432 }
2433
2434 let is_mouse = device.has_capability(input::DeviceCapability::Pointer)
2435 && !is_touchpad
2436 && !is_trackball
2437 && !is_trackpoint;
2438 if is_mouse {
2439 let c = &config.mouse;
2440 let _ = device.config_send_events_set_mode(if c.off {
2441 input::SendEventsMode::DISABLED
2442 } else {
2443 input::SendEventsMode::ENABLED
2444 });
2445 let _ = device.config_scroll_set_natural_scroll_enabled(c.natural_scroll);
2446 let _ = device.config_accel_set_speed(c.accel_speed);
2447 let _ = device.config_left_handed_set(c.left_handed);
2448
2449 if let Some(accel_profile) = c.accel_profile {
2450 let _ = device.config_accel_set_profile(accel_profile.into());
2451 } else if let Some(default) = device.config_accel_default_profile() {
2452 let _ = device.config_accel_set_profile(default);
2453 }
2454
2455 if let Some(method) = c.scroll_method {
2456 let _ = device.config_scroll_set_method(method.into());
2457 } else if let Some(default) = device.config_scroll_default_method() {
2458 let _ = device.config_scroll_set_method(default);
2459 }
2460 }
2461
2462 if is_trackpoint {
2463 let c = &config.trackpoint;
2464 let _ = device.config_send_events_set_mode(if c.off {
2465 input::SendEventsMode::DISABLED
2466 } else {
2467 input::SendEventsMode::ENABLED
2468 });
2469 let _ = device.config_scroll_set_natural_scroll_enabled(c.natural_scroll);
2470 let _ = device.config_accel_set_speed(c.accel_speed);
2471
2472 if let Some(accel_profile) = c.accel_profile {
2473 let _ = device.config_accel_set_profile(accel_profile.into());
2474 } else if let Some(default) = device.config_accel_default_profile() {
2475 let _ = device.config_accel_set_profile(default);
2476 }
2477
2478 if let Some(method) = c.scroll_method {
2479 let _ = device.config_scroll_set_method(method.into());
2480 } else if let Some(default) = device.config_scroll_default_method() {
2481 let _ = device.config_scroll_set_method(default);
2482 }
2483 }
2484
2485 let is_tablet = device.has_capability(input::DeviceCapability::TabletTool);
2486 if is_tablet {
2487 let c = &config.tablet;
2488 let _ = device.config_send_events_set_mode(if c.off {
2489 input::SendEventsMode::DISABLED
2490 } else {
2491 input::SendEventsMode::ENABLED
2492 });
2493 let _ = device.config_left_handed_set(c.left_handed);
2494 }
2495}
2496
2497pub fn mods_with_binds(
2498 comp_mod: CompositorMod,
2499 binds: &Binds,
2500 triggers: &[Trigger],
2501) -> HashSet<Modifiers> {
2502 let comp_mod = match comp_mod {
2503 CompositorMod::Super => Modifiers::SUPER,
2504 CompositorMod::Alt => Modifiers::ALT,
2505 };
2506
2507 let mut rv = HashSet::new();
2508 for bind in &binds.0 {
2509 if !triggers.iter().any(|trigger| bind.key.trigger == *trigger) {
2510 continue;
2511 }
2512
2513 let mut mods = bind.key.modifiers;
2514 if mods.contains(Modifiers::COMPOSITOR) {
2515 mods.remove(Modifiers::COMPOSITOR);
2516 mods.insert(comp_mod);
2517 }
2518
2519 rv.insert(mods);
2520 }
2521
2522 rv
2523}
2524
2525pub fn mods_with_wheel_binds(comp_mod: CompositorMod, binds: &Binds) -> HashSet<Modifiers> {
2526 mods_with_binds(
2527 comp_mod,
2528 binds,
2529 &[
2530 Trigger::WheelScrollUp,
2531 Trigger::WheelScrollDown,
2532 Trigger::WheelScrollLeft,
2533 Trigger::WheelScrollRight,
2534 ],
2535 )
2536}
2537
2538pub fn mods_with_finger_scroll_binds(comp_mod: CompositorMod, binds: &Binds) -> HashSet<Modifiers> {
2539 mods_with_binds(
2540 comp_mod,
2541 binds,
2542 &[
2543 Trigger::TouchpadScrollUp,
2544 Trigger::TouchpadScrollDown,
2545 Trigger::TouchpadScrollLeft,
2546 Trigger::TouchpadScrollRight,
2547 ],
2548 )
2549}
2550
2551#[cfg(test)]
2552mod tests {
2553 use super::*;
2554
2555 #[test]
2556 fn bindings_suppress_keys() {
2557 let close_keysym = Keysym::q;
2558 let bindings = Binds(vec![Bind {
2559 key: Key {
2560 trigger: Trigger::Keysym(close_keysym),
2561 modifiers: Modifiers::COMPOSITOR | Modifiers::CTRL,
2562 },
2563 action: Action::CloseWindow,
2564 repeat: true,
2565 cooldown: None,
2566 allow_when_locked: false,
2567 }]);
2568
2569 let comp_mod = CompositorMod::Super;
2570 let mut suppressed_keys = HashSet::new();
2571
2572 let screenshot_ui = ScreenshotUi::new(Default::default());
2573 let disable_power_key_handling = false;
2574
2575 // The key_code we pick is arbitrary, the only thing
2576 // that matters is that they are different between cases.
2577
2578 let close_key_code = close_keysym.into();
2579 let close_key_event = |suppr: &mut HashSet<u32>, mods: ModifiersState, pressed| {
2580 should_intercept_key(
2581 suppr,
2582 &bindings,
2583 comp_mod,
2584 close_key_code,
2585 close_keysym,
2586 Some(close_keysym),
2587 pressed,
2588 mods,
2589 &screenshot_ui,
2590 disable_power_key_handling,
2591 )
2592 };
2593
2594 // Key event with the code which can't trigger any action.
2595 let none_key_event = |suppr: &mut HashSet<u32>, mods: ModifiersState, pressed| {
2596 should_intercept_key(
2597 suppr,
2598 &bindings,
2599 comp_mod,
2600 Keysym::l.into(),
2601 Keysym::l,
2602 Some(Keysym::l),
2603 pressed,
2604 mods,
2605 &screenshot_ui,
2606 disable_power_key_handling,
2607 )
2608 };
2609
2610 let mut mods = ModifiersState {
2611 logo: true,
2612 ctrl: true,
2613 ..Default::default()
2614 };
2615
2616 // Action press/release.
2617
2618 let filter = close_key_event(&mut suppressed_keys, mods, true);
2619 assert!(matches!(
2620 filter,
2621 FilterResult::Intercept(Some(Bind {
2622 action: Action::CloseWindow,
2623 ..
2624 }))
2625 ));
2626 assert!(suppressed_keys.contains(&close_key_code));
2627
2628 let filter = close_key_event(&mut suppressed_keys, mods, false);
2629 assert!(matches!(filter, FilterResult::Intercept(None)));
2630 assert!(suppressed_keys.is_empty());
2631
2632 // Remove mod to make it for a binding.
2633
2634 mods.shift = true;
2635 let filter = close_key_event(&mut suppressed_keys, mods, true);
2636 assert!(matches!(filter, FilterResult::Forward));
2637
2638 mods.shift = false;
2639 let filter = close_key_event(&mut suppressed_keys, mods, false);
2640 assert!(matches!(filter, FilterResult::Forward));
2641
2642 // Just none press/release.
2643
2644 let filter = none_key_event(&mut suppressed_keys, mods, true);
2645 assert!(matches!(filter, FilterResult::Forward));
2646
2647 let filter = none_key_event(&mut suppressed_keys, mods, false);
2648 assert!(matches!(filter, FilterResult::Forward));
2649
2650 // Press action, press arbitrary, release action, release arbitrary.
2651
2652 let filter = close_key_event(&mut suppressed_keys, mods, true);
2653 assert!(matches!(
2654 filter,
2655 FilterResult::Intercept(Some(Bind {
2656 action: Action::CloseWindow,
2657 ..
2658 }))
2659 ));
2660
2661 let filter = none_key_event(&mut suppressed_keys, mods, true);
2662 assert!(matches!(filter, FilterResult::Forward));
2663
2664 let filter = close_key_event(&mut suppressed_keys, mods, false);
2665 assert!(matches!(filter, FilterResult::Intercept(None)));
2666
2667 let filter = none_key_event(&mut suppressed_keys, mods, false);
2668 assert!(matches!(filter, FilterResult::Forward));
2669
2670 // Trigger and remove all mods.
2671
2672 let filter = close_key_event(&mut suppressed_keys, mods, true);
2673 assert!(matches!(
2674 filter,
2675 FilterResult::Intercept(Some(Bind {
2676 action: Action::CloseWindow,
2677 ..
2678 }))
2679 ));
2680
2681 mods = Default::default();
2682 let filter = close_key_event(&mut suppressed_keys, mods, false);
2683 assert!(matches!(filter, FilterResult::Intercept(None)));
2684
2685 // Ensure that no keys are being suppressed.
2686 assert!(suppressed_keys.is_empty());
2687 }
2688
2689 #[test]
2690 fn comp_mod_handling() {
2691 let bindings = Binds(vec![
2692 Bind {
2693 key: Key {
2694 trigger: Trigger::Keysym(Keysym::q),
2695 modifiers: Modifiers::COMPOSITOR,
2696 },
2697 action: Action::CloseWindow,
2698 repeat: true,
2699 cooldown: None,
2700 allow_when_locked: false,
2701 },
2702 Bind {
2703 key: Key {
2704 trigger: Trigger::Keysym(Keysym::h),
2705 modifiers: Modifiers::SUPER,
2706 },
2707 action: Action::FocusColumnLeft,
2708 repeat: true,
2709 cooldown: None,
2710 allow_when_locked: false,
2711 },
2712 Bind {
2713 key: Key {
2714 trigger: Trigger::Keysym(Keysym::j),
2715 modifiers: Modifiers::empty(),
2716 },
2717 action: Action::FocusWindowDown,
2718 repeat: true,
2719 cooldown: None,
2720 allow_when_locked: false,
2721 },
2722 Bind {
2723 key: Key {
2724 trigger: Trigger::Keysym(Keysym::k),
2725 modifiers: Modifiers::COMPOSITOR | Modifiers::SUPER,
2726 },
2727 action: Action::FocusWindowUp,
2728 repeat: true,
2729 cooldown: None,
2730 allow_when_locked: false,
2731 },
2732 Bind {
2733 key: Key {
2734 trigger: Trigger::Keysym(Keysym::l),
2735 modifiers: Modifiers::SUPER | Modifiers::ALT,
2736 },
2737 action: Action::FocusColumnRight,
2738 repeat: true,
2739 cooldown: None,
2740 allow_when_locked: false,
2741 },
2742 ]);
2743
2744 assert_eq!(
2745 find_configured_bind(
2746 &bindings,
2747 CompositorMod::Super,
2748 Trigger::Keysym(Keysym::q),
2749 ModifiersState {
2750 logo: true,
2751 ..Default::default()
2752 }
2753 )
2754 .as_ref(),
2755 Some(&bindings.0[0])
2756 );
2757 assert_eq!(
2758 find_configured_bind(
2759 &bindings,
2760 CompositorMod::Super,
2761 Trigger::Keysym(Keysym::q),
2762 ModifiersState::default(),
2763 ),
2764 None,
2765 );
2766
2767 assert_eq!(
2768 find_configured_bind(
2769 &bindings,
2770 CompositorMod::Super,
2771 Trigger::Keysym(Keysym::h),
2772 ModifiersState {
2773 logo: true,
2774 ..Default::default()
2775 }
2776 )
2777 .as_ref(),
2778 Some(&bindings.0[1])
2779 );
2780 assert_eq!(
2781 find_configured_bind(
2782 &bindings,
2783 CompositorMod::Super,
2784 Trigger::Keysym(Keysym::h),
2785 ModifiersState::default(),
2786 ),
2787 None,
2788 );
2789
2790 assert_eq!(
2791 find_configured_bind(
2792 &bindings,
2793 CompositorMod::Super,
2794 Trigger::Keysym(Keysym::j),
2795 ModifiersState {
2796 logo: true,
2797 ..Default::default()
2798 }
2799 ),
2800 None,
2801 );
2802 assert_eq!(
2803 find_configured_bind(
2804 &bindings,
2805 CompositorMod::Super,
2806 Trigger::Keysym(Keysym::j),
2807 ModifiersState::default(),
2808 )
2809 .as_ref(),
2810 Some(&bindings.0[2])
2811 );
2812
2813 assert_eq!(
2814 find_configured_bind(
2815 &bindings,
2816 CompositorMod::Super,
2817 Trigger::Keysym(Keysym::k),
2818 ModifiersState {
2819 logo: true,
2820 ..Default::default()
2821 }
2822 )
2823 .as_ref(),
2824 Some(&bindings.0[3])
2825 );
2826 assert_eq!(
2827 find_configured_bind(
2828 &bindings,
2829 CompositorMod::Super,
2830 Trigger::Keysym(Keysym::k),
2831 ModifiersState::default(),
2832 ),
2833 None,
2834 );
2835
2836 assert_eq!(
2837 find_configured_bind(
2838 &bindings,
2839 CompositorMod::Super,
2840 Trigger::Keysym(Keysym::l),
2841 ModifiersState {
2842 logo: true,
2843 alt: true,
2844 ..Default::default()
2845 }
2846 )
2847 .as_ref(),
2848 Some(&bindings.0[4])
2849 );
2850 assert_eq!(
2851 find_configured_bind(
2852 &bindings,
2853 CompositorMod::Super,
2854 Trigger::Keysym(Keysym::l),
2855 ModifiersState {
2856 logo: true,
2857 ..Default::default()
2858 },
2859 ),
2860 None,
2861 );
2862 }
2863}