forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiB64a9351Ivan Molodetskikh2 years ago1319 commits

mod.rs2908 lines, 106.1 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, XkbContextHandler};
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 let keyboard = &self.niri.seat.get_keyboard().unwrap();
543 let new_idx = keyboard.with_xkb_state(self, |mut state| {
544 match action {
545 LayoutSwitchTarget::Next => state.cycle_next_layout(),
546 LayoutSwitchTarget::Prev => state.cycle_prev_layout(),
547 };
548 state.active_layout().0
549 });
550
551 if let Some(server) = &self.niri.ipc_server {
552 server.keyboard_layout_switched(new_idx as u8);
553 }
554 }
555 Action::MoveColumnLeft => {
556 self.niri.layout.move_left();
557 self.maybe_warp_cursor_to_focus();
558 // FIXME: granular
559 self.niri.queue_redraw_all();
560 }
561 Action::MoveColumnRight => {
562 self.niri.layout.move_right();
563 self.maybe_warp_cursor_to_focus();
564 // FIXME: granular
565 self.niri.queue_redraw_all();
566 }
567 Action::MoveColumnToFirst => {
568 self.niri.layout.move_column_to_first();
569 self.maybe_warp_cursor_to_focus();
570 // FIXME: granular
571 self.niri.queue_redraw_all();
572 }
573 Action::MoveColumnToLast => {
574 self.niri.layout.move_column_to_last();
575 self.maybe_warp_cursor_to_focus();
576 // FIXME: granular
577 self.niri.queue_redraw_all();
578 }
579 Action::MoveColumnLeftOrToMonitorLeft => {
580 if let Some(output) = self.niri.output_left() {
581 if self.niri.layout.move_column_left_or_to_output(&output)
582 && !self.maybe_warp_cursor_to_focus_centered()
583 {
584 self.move_cursor_to_output(&output);
585 } else {
586 self.maybe_warp_cursor_to_focus();
587 }
588 } else {
589 self.niri.layout.move_left();
590 self.maybe_warp_cursor_to_focus();
591 }
592
593 // FIXME: granular
594 self.niri.queue_redraw_all();
595 }
596 Action::MoveColumnRightOrToMonitorRight => {
597 if let Some(output) = self.niri.output_right() {
598 if self.niri.layout.move_column_right_or_to_output(&output)
599 && !self.maybe_warp_cursor_to_focus_centered()
600 {
601 self.move_cursor_to_output(&output);
602 } else {
603 self.maybe_warp_cursor_to_focus();
604 }
605 } else {
606 self.niri.layout.move_right();
607 self.maybe_warp_cursor_to_focus();
608 }
609
610 // FIXME: granular
611 self.niri.queue_redraw_all();
612 }
613 Action::MoveWindowDown => {
614 self.niri.layout.move_down();
615 self.maybe_warp_cursor_to_focus();
616 // FIXME: granular
617 self.niri.queue_redraw_all();
618 }
619 Action::MoveWindowUp => {
620 self.niri.layout.move_up();
621 self.maybe_warp_cursor_to_focus();
622 // FIXME: granular
623 self.niri.queue_redraw_all();
624 }
625 Action::MoveWindowDownOrToWorkspaceDown => {
626 self.niri.layout.move_down_or_to_workspace_down();
627 self.maybe_warp_cursor_to_focus();
628 // FIXME: granular
629 self.niri.queue_redraw_all();
630 }
631 Action::MoveWindowUpOrToWorkspaceUp => {
632 self.niri.layout.move_up_or_to_workspace_up();
633 self.maybe_warp_cursor_to_focus();
634 // FIXME: granular
635 self.niri.queue_redraw_all();
636 }
637 Action::ConsumeOrExpelWindowLeft => {
638 self.niri.layout.consume_or_expel_window_left();
639 self.maybe_warp_cursor_to_focus();
640 // FIXME: granular
641 self.niri.queue_redraw_all();
642 }
643 Action::ConsumeOrExpelWindowRight => {
644 self.niri.layout.consume_or_expel_window_right();
645 self.maybe_warp_cursor_to_focus();
646 // FIXME: granular
647 self.niri.queue_redraw_all();
648 }
649 Action::FocusColumnLeft => {
650 self.niri.layout.focus_left();
651 self.maybe_warp_cursor_to_focus();
652 // FIXME: granular
653 self.niri.queue_redraw_all();
654 }
655 Action::FocusColumnRight => {
656 self.niri.layout.focus_right();
657 self.maybe_warp_cursor_to_focus();
658 // FIXME: granular
659 self.niri.queue_redraw_all();
660 }
661 Action::FocusColumnFirst => {
662 self.niri.layout.focus_column_first();
663 self.maybe_warp_cursor_to_focus();
664 // FIXME: granular
665 self.niri.queue_redraw_all();
666 }
667 Action::FocusColumnLast => {
668 self.niri.layout.focus_column_last();
669 self.maybe_warp_cursor_to_focus();
670 // FIXME: granular
671 self.niri.queue_redraw_all();
672 }
673 Action::FocusColumnRightOrFirst => {
674 self.niri.layout.focus_column_right_or_first();
675 self.maybe_warp_cursor_to_focus();
676 // FIXME: granular
677 self.niri.queue_redraw_all();
678 }
679 Action::FocusColumnLeftOrLast => {
680 self.niri.layout.focus_column_left_or_last();
681 self.maybe_warp_cursor_to_focus();
682 // FIXME: granular
683 self.niri.queue_redraw_all();
684 }
685 Action::FocusWindowOrMonitorUp => {
686 if let Some(output) = self.niri.output_up() {
687 if self.niri.layout.focus_window_up_or_output(&output)
688 && !self.maybe_warp_cursor_to_focus_centered()
689 {
690 self.move_cursor_to_output(&output);
691 } else {
692 self.maybe_warp_cursor_to_focus();
693 }
694 } else {
695 self.niri.layout.focus_up();
696 self.maybe_warp_cursor_to_focus();
697 }
698
699 // FIXME: granular
700 self.niri.queue_redraw_all();
701 }
702 Action::FocusWindowOrMonitorDown => {
703 if let Some(output) = self.niri.output_down() {
704 if self.niri.layout.focus_window_down_or_output(&output)
705 && !self.maybe_warp_cursor_to_focus_centered()
706 {
707 self.move_cursor_to_output(&output);
708 } else {
709 self.maybe_warp_cursor_to_focus();
710 }
711 } else {
712 self.niri.layout.focus_down();
713 self.maybe_warp_cursor_to_focus();
714 }
715
716 // FIXME: granular
717 self.niri.queue_redraw_all();
718 }
719 Action::FocusColumnOrMonitorLeft => {
720 if let Some(output) = self.niri.output_left() {
721 if self.niri.layout.focus_column_left_or_output(&output)
722 && !self.maybe_warp_cursor_to_focus_centered()
723 {
724 self.move_cursor_to_output(&output);
725 } else {
726 self.maybe_warp_cursor_to_focus();
727 }
728 } else {
729 self.niri.layout.focus_left();
730 self.maybe_warp_cursor_to_focus();
731 }
732
733 // FIXME: granular
734 self.niri.queue_redraw_all();
735 }
736 Action::FocusColumnOrMonitorRight => {
737 if let Some(output) = self.niri.output_right() {
738 if self.niri.layout.focus_column_right_or_output(&output)
739 && !self.maybe_warp_cursor_to_focus_centered()
740 {
741 self.move_cursor_to_output(&output);
742 } else {
743 self.maybe_warp_cursor_to_focus();
744 }
745 } else {
746 self.niri.layout.focus_right();
747 self.maybe_warp_cursor_to_focus();
748 }
749
750 // FIXME: granular
751 self.niri.queue_redraw_all();
752 }
753 Action::FocusWindowDown => {
754 self.niri.layout.focus_down();
755 self.maybe_warp_cursor_to_focus();
756 // FIXME: granular
757 self.niri.queue_redraw_all();
758 }
759 Action::FocusWindowUp => {
760 self.niri.layout.focus_up();
761 self.maybe_warp_cursor_to_focus();
762 // FIXME: granular
763 self.niri.queue_redraw_all();
764 }
765 Action::FocusWindowDownOrColumnLeft => {
766 self.niri.layout.focus_down_or_left();
767 self.maybe_warp_cursor_to_focus();
768 // FIXME: granular
769 self.niri.queue_redraw_all();
770 }
771 Action::FocusWindowDownOrColumnRight => {
772 self.niri.layout.focus_down_or_right();
773 self.maybe_warp_cursor_to_focus();
774 // FIXME: granular
775 self.niri.queue_redraw_all();
776 }
777 Action::FocusWindowUpOrColumnLeft => {
778 self.niri.layout.focus_up_or_left();
779 self.maybe_warp_cursor_to_focus();
780 // FIXME: granular
781 self.niri.queue_redraw_all();
782 }
783 Action::FocusWindowUpOrColumnRight => {
784 self.niri.layout.focus_up_or_right();
785 self.maybe_warp_cursor_to_focus();
786 // FIXME: granular
787 self.niri.queue_redraw_all();
788 }
789 Action::FocusWindowOrWorkspaceDown => {
790 self.niri.layout.focus_window_or_workspace_down();
791 self.maybe_warp_cursor_to_focus();
792 // FIXME: granular
793 self.niri.queue_redraw_all();
794 }
795 Action::FocusWindowOrWorkspaceUp => {
796 self.niri.layout.focus_window_or_workspace_up();
797 self.maybe_warp_cursor_to_focus();
798 // FIXME: granular
799 self.niri.queue_redraw_all();
800 }
801 Action::MoveWindowToWorkspaceDown => {
802 self.niri.layout.move_to_workspace_down();
803 self.maybe_warp_cursor_to_focus();
804 // FIXME: granular
805 self.niri.queue_redraw_all();
806 }
807 Action::MoveWindowToWorkspaceUp => {
808 self.niri.layout.move_to_workspace_up();
809 self.maybe_warp_cursor_to_focus();
810 // FIXME: granular
811 self.niri.queue_redraw_all();
812 }
813 Action::MoveWindowToWorkspace(reference) => {
814 if let Some((output, index)) = self.niri.find_output_and_workspace_index(reference)
815 {
816 if let Some(output) = output {
817 self.niri.layout.move_to_workspace_on_output(&output, index);
818 if !self.maybe_warp_cursor_to_focus_centered() {
819 self.move_cursor_to_output(&output);
820 }
821 } else {
822 self.niri.layout.move_to_workspace(index);
823 self.maybe_warp_cursor_to_focus();
824 }
825
826 // FIXME: granular
827 self.niri.queue_redraw_all();
828 }
829 }
830 Action::MoveColumnToWorkspaceDown => {
831 self.niri.layout.move_column_to_workspace_down();
832 self.maybe_warp_cursor_to_focus();
833 // FIXME: granular
834 self.niri.queue_redraw_all();
835 }
836 Action::MoveColumnToWorkspaceUp => {
837 self.niri.layout.move_column_to_workspace_up();
838 self.maybe_warp_cursor_to_focus();
839 // FIXME: granular
840 self.niri.queue_redraw_all();
841 }
842 Action::MoveColumnToWorkspace(reference) => {
843 if let Some((output, index)) = self.niri.find_output_and_workspace_index(reference)
844 {
845 if let Some(output) = output {
846 self.niri
847 .layout
848 .move_column_to_workspace_on_output(&output, index);
849 if !self.maybe_warp_cursor_to_focus_centered() {
850 self.move_cursor_to_output(&output);
851 }
852 } else {
853 self.niri.layout.move_column_to_workspace(index);
854 self.maybe_warp_cursor_to_focus();
855 }
856
857 // FIXME: granular
858 self.niri.queue_redraw_all();
859 }
860 }
861 Action::FocusWorkspaceDown => {
862 self.niri.layout.switch_workspace_down();
863 self.maybe_warp_cursor_to_focus();
864 // FIXME: granular
865 self.niri.queue_redraw_all();
866 }
867 Action::FocusWorkspaceUp => {
868 self.niri.layout.switch_workspace_up();
869 self.maybe_warp_cursor_to_focus();
870 // FIXME: granular
871 self.niri.queue_redraw_all();
872 }
873 Action::FocusWorkspace(reference) => {
874 if let Some((output, index)) = self.niri.find_output_and_workspace_index(reference)
875 {
876 if let Some(output) = output {
877 self.niri.layout.focus_output(&output);
878 self.niri.layout.switch_workspace(index);
879 if !self.maybe_warp_cursor_to_focus_centered() {
880 self.move_cursor_to_output(&output);
881 }
882 } else {
883 let config = &self.niri.config;
884 if config.borrow().input.workspace_auto_back_and_forth {
885 self.niri.layout.switch_workspace_auto_back_and_forth(index);
886 } else {
887 self.niri.layout.switch_workspace(index);
888 }
889 self.maybe_warp_cursor_to_focus();
890 }
891
892 // FIXME: granular
893 self.niri.queue_redraw_all();
894 }
895 }
896 Action::FocusWorkspacePrevious => {
897 self.niri.layout.switch_workspace_previous();
898 // FIXME: granular
899 self.niri.queue_redraw_all();
900 }
901 Action::MoveWorkspaceDown => {
902 self.niri.layout.move_workspace_down();
903 // FIXME: granular
904 self.niri.queue_redraw_all();
905 }
906 Action::MoveWorkspaceUp => {
907 self.niri.layout.move_workspace_up();
908 // FIXME: granular
909 self.niri.queue_redraw_all();
910 }
911 Action::ConsumeWindowIntoColumn => {
912 self.niri.layout.consume_into_column();
913 // This does not cause immediate focus or window size change, so warping mouse to
914 // focus won't do anything here.
915 // FIXME: granular
916 self.niri.queue_redraw_all();
917 }
918 Action::ExpelWindowFromColumn => {
919 self.niri.layout.expel_from_column();
920 self.maybe_warp_cursor_to_focus();
921 // FIXME: granular
922 self.niri.queue_redraw_all();
923 }
924 Action::SwitchPresetColumnWidth => {
925 self.niri.layout.toggle_width();
926 }
927 Action::CenterColumn => {
928 self.niri.layout.center_column();
929 // FIXME: granular
930 self.niri.queue_redraw_all();
931 }
932 Action::MaximizeColumn => {
933 self.niri.layout.toggle_full_width();
934 }
935 Action::FocusMonitorLeft => {
936 if let Some(output) = self.niri.output_left() {
937 self.niri.layout.focus_output(&output);
938 if !self.maybe_warp_cursor_to_focus_centered() {
939 self.move_cursor_to_output(&output);
940 }
941 }
942 }
943 Action::FocusMonitorRight => {
944 if let Some(output) = self.niri.output_right() {
945 self.niri.layout.focus_output(&output);
946 if !self.maybe_warp_cursor_to_focus_centered() {
947 self.move_cursor_to_output(&output);
948 }
949 }
950 }
951 Action::FocusMonitorDown => {
952 if let Some(output) = self.niri.output_down() {
953 self.niri.layout.focus_output(&output);
954 if !self.maybe_warp_cursor_to_focus_centered() {
955 self.move_cursor_to_output(&output);
956 }
957 }
958 }
959 Action::FocusMonitorUp => {
960 if let Some(output) = self.niri.output_up() {
961 self.niri.layout.focus_output(&output);
962 if !self.maybe_warp_cursor_to_focus_centered() {
963 self.move_cursor_to_output(&output);
964 }
965 }
966 }
967 Action::MoveWindowToMonitorLeft => {
968 if let Some(output) = self.niri.output_left() {
969 self.niri.layout.move_to_output(&output);
970 self.niri.layout.focus_output(&output);
971 if !self.maybe_warp_cursor_to_focus_centered() {
972 self.move_cursor_to_output(&output);
973 }
974 }
975 }
976 Action::MoveWindowToMonitorRight => {
977 if let Some(output) = self.niri.output_right() {
978 self.niri.layout.move_to_output(&output);
979 self.niri.layout.focus_output(&output);
980 if !self.maybe_warp_cursor_to_focus_centered() {
981 self.move_cursor_to_output(&output);
982 }
983 }
984 }
985 Action::MoveWindowToMonitorDown => {
986 if let Some(output) = self.niri.output_down() {
987 self.niri.layout.move_to_output(&output);
988 self.niri.layout.focus_output(&output);
989 if !self.maybe_warp_cursor_to_focus_centered() {
990 self.move_cursor_to_output(&output);
991 }
992 }
993 }
994 Action::MoveWindowToMonitorUp => {
995 if let Some(output) = self.niri.output_up() {
996 self.niri.layout.move_to_output(&output);
997 self.niri.layout.focus_output(&output);
998 if !self.maybe_warp_cursor_to_focus_centered() {
999 self.move_cursor_to_output(&output);
1000 }
1001 }
1002 }
1003 Action::MoveColumnToMonitorLeft => {
1004 if let Some(output) = self.niri.output_left() {
1005 self.niri.layout.move_column_to_output(&output);
1006 self.niri.layout.focus_output(&output);
1007 if !self.maybe_warp_cursor_to_focus_centered() {
1008 self.move_cursor_to_output(&output);
1009 }
1010 }
1011 }
1012 Action::MoveColumnToMonitorRight => {
1013 if let Some(output) = self.niri.output_right() {
1014 self.niri.layout.move_column_to_output(&output);
1015 self.niri.layout.focus_output(&output);
1016 if !self.maybe_warp_cursor_to_focus_centered() {
1017 self.move_cursor_to_output(&output);
1018 }
1019 }
1020 }
1021 Action::MoveColumnToMonitorDown => {
1022 if let Some(output) = self.niri.output_down() {
1023 self.niri.layout.move_column_to_output(&output);
1024 self.niri.layout.focus_output(&output);
1025 if !self.maybe_warp_cursor_to_focus_centered() {
1026 self.move_cursor_to_output(&output);
1027 }
1028 }
1029 }
1030 Action::MoveColumnToMonitorUp => {
1031 if let Some(output) = self.niri.output_up() {
1032 self.niri.layout.move_column_to_output(&output);
1033 self.niri.layout.focus_output(&output);
1034 if !self.maybe_warp_cursor_to_focus_centered() {
1035 self.move_cursor_to_output(&output);
1036 }
1037 }
1038 }
1039 Action::SetColumnWidth(change) => {
1040 self.niri.layout.set_column_width(change);
1041 }
1042 Action::SetWindowHeight(change) => {
1043 self.niri.layout.set_window_height(change);
1044 }
1045 Action::ResetWindowHeight => {
1046 self.niri.layout.reset_window_height();
1047 }
1048 Action::ShowHotkeyOverlay => {
1049 if self.niri.hotkey_overlay.show() {
1050 self.niri.queue_redraw_all();
1051 }
1052 }
1053 Action::MoveWorkspaceToMonitorLeft => {
1054 if let Some(output) = self.niri.output_left() {
1055 self.niri.layout.move_workspace_to_output(&output);
1056 if !self.maybe_warp_cursor_to_focus_centered() {
1057 self.move_cursor_to_output(&output);
1058 }
1059 }
1060 }
1061 Action::MoveWorkspaceToMonitorRight => {
1062 if let Some(output) = self.niri.output_right() {
1063 self.niri.layout.move_workspace_to_output(&output);
1064 if !self.maybe_warp_cursor_to_focus_centered() {
1065 self.move_cursor_to_output(&output);
1066 }
1067 }
1068 }
1069 Action::MoveWorkspaceToMonitorDown => {
1070 if let Some(output) = self.niri.output_down() {
1071 self.niri.layout.move_workspace_to_output(&output);
1072 if !self.maybe_warp_cursor_to_focus_centered() {
1073 self.move_cursor_to_output(&output);
1074 }
1075 }
1076 }
1077 Action::MoveWorkspaceToMonitorUp => {
1078 if let Some(output) = self.niri.output_up() {
1079 self.niri.layout.move_workspace_to_output(&output);
1080 if !self.maybe_warp_cursor_to_focus_centered() {
1081 self.move_cursor_to_output(&output);
1082 }
1083 }
1084 }
1085 }
1086 }
1087
1088 fn on_pointer_motion<I: InputBackend>(&mut self, event: I::PointerMotionEvent) {
1089 // We need an output to be able to move the pointer.
1090 if self.niri.global_space.outputs().next().is_none() {
1091 return;
1092 }
1093
1094 let serial = SERIAL_COUNTER.next_serial();
1095
1096 let pointer = self.niri.seat.get_pointer().unwrap();
1097
1098 let pos = pointer.current_location();
1099
1100 // We have an output, so we can compute the new location and focus.
1101 let mut new_pos = pos + event.delta();
1102
1103 // We received an event for the regular pointer, so show it now.
1104 self.niri.pointer_hidden = false;
1105 self.niri.tablet_cursor_location = None;
1106
1107 // Check if we have an active pointer constraint.
1108 let mut pointer_confined = None;
1109 if let Some(focus) = &self.niri.pointer_focus.surface {
1110 let pos_within_surface = pos - focus.1;
1111
1112 let mut pointer_locked = false;
1113 with_pointer_constraint(&focus.0, &pointer, |constraint| {
1114 let Some(constraint) = constraint else { return };
1115 if !constraint.is_active() {
1116 return;
1117 }
1118
1119 // Constraint does not apply if not within region.
1120 if let Some(region) = constraint.region() {
1121 if !region.contains(pos_within_surface.to_i32_round()) {
1122 return;
1123 }
1124 }
1125
1126 match &*constraint {
1127 PointerConstraint::Locked(_locked) => {
1128 pointer_locked = true;
1129 }
1130 PointerConstraint::Confined(confine) => {
1131 pointer_confined = Some((focus.clone(), confine.region().cloned()));
1132 }
1133 }
1134 });
1135
1136 // If the pointer is locked, only send relative motion.
1137 if pointer_locked {
1138 pointer.relative_motion(
1139 self,
1140 Some(focus.clone()),
1141 &RelativeMotionEvent {
1142 delta: event.delta(),
1143 delta_unaccel: event.delta_unaccel(),
1144 utime: event.time(),
1145 },
1146 );
1147
1148 pointer.frame(self);
1149
1150 // I guess a redraw to hide the tablet cursor could be nice? Doesn't matter too
1151 // much here I think.
1152 return;
1153 }
1154 }
1155
1156 if self
1157 .niri
1158 .global_space
1159 .output_under(new_pos)
1160 .next()
1161 .is_none()
1162 {
1163 // We ended up outside the outputs and need to clip the movement.
1164 if let Some(output) = self.niri.global_space.output_under(pos).next() {
1165 // The pointer was previously on some output. Clip the movement against its
1166 // boundaries.
1167 let geom = self.niri.global_space.output_geometry(output).unwrap();
1168 new_pos.x = new_pos
1169 .x
1170 .clamp(geom.loc.x as f64, (geom.loc.x + geom.size.w - 1) as f64);
1171 new_pos.y = new_pos
1172 .y
1173 .clamp(geom.loc.y as f64, (geom.loc.y + geom.size.h - 1) as f64);
1174 } else {
1175 // The pointer was not on any output in the first place. Find one for it.
1176 // Let's do the simple thing and just put it on the first output.
1177 let output = self.niri.global_space.outputs().next().unwrap();
1178 let geom = self.niri.global_space.output_geometry(output).unwrap();
1179 new_pos = center(geom).to_f64();
1180 }
1181 }
1182
1183 if let Some(output) = self.niri.screenshot_ui.selection_output() {
1184 let geom = self.niri.global_space.output_geometry(output).unwrap();
1185 let mut point = (new_pos - geom.loc.to_f64())
1186 .to_physical(output.current_scale().fractional_scale())
1187 .to_i32_round::<i32>();
1188
1189 let size = output.current_mode().unwrap().size;
1190 let transform = output.current_transform();
1191 let size = transform.transform_size(size);
1192 point.x = point.x.clamp(0, size.w - 1);
1193 point.y = point.y.clamp(0, size.h - 1);
1194
1195 self.niri.screenshot_ui.pointer_motion(point);
1196 }
1197
1198 let under = self.niri.surface_under_and_global_space(new_pos);
1199
1200 // Handle confined pointer.
1201 if let Some((focus_surface, region)) = pointer_confined {
1202 let mut prevent = false;
1203
1204 // Prevent the pointer from leaving the focused surface.
1205 if Some(&focus_surface.0) != under.surface.as_ref().map(|(s, _)| s) {
1206 prevent = true;
1207 }
1208
1209 // Prevent the pointer from leaving the confine region, if any.
1210 if let Some(region) = region {
1211 let new_pos_within_surface = new_pos - focus_surface.1;
1212 if !region.contains(new_pos_within_surface.to_i32_round()) {
1213 prevent = true;
1214 }
1215 }
1216
1217 if prevent {
1218 pointer.relative_motion(
1219 self,
1220 Some(focus_surface),
1221 &RelativeMotionEvent {
1222 delta: event.delta(),
1223 delta_unaccel: event.delta_unaccel(),
1224 utime: event.time(),
1225 },
1226 );
1227
1228 pointer.frame(self);
1229
1230 return;
1231 }
1232 }
1233
1234 self.niri.handle_focus_follows_mouse(&under);
1235
1236 // Activate a new confinement if necessary.
1237 self.niri.maybe_activate_pointer_constraint(new_pos, &under);
1238
1239 self.niri.pointer_focus.clone_from(&under);
1240
1241 pointer.motion(
1242 self,
1243 under.surface.clone(),
1244 &MotionEvent {
1245 location: new_pos,
1246 serial,
1247 time: event.time_msec(),
1248 },
1249 );
1250
1251 pointer.relative_motion(
1252 self,
1253 under.surface,
1254 &RelativeMotionEvent {
1255 delta: event.delta(),
1256 delta_unaccel: event.delta_unaccel(),
1257 utime: event.time(),
1258 },
1259 );
1260
1261 pointer.frame(self);
1262
1263 // Redraw to update the cursor position.
1264 // FIXME: redraw only outputs overlapping the cursor.
1265 self.niri.queue_redraw_all();
1266 }
1267
1268 fn on_pointer_motion_absolute<I: InputBackend>(
1269 &mut self,
1270 event: I::PointerMotionAbsoluteEvent,
1271 ) {
1272 let Some(output_geo) = self.global_bounding_rectangle() else {
1273 return;
1274 };
1275
1276 let pos = event.position_transformed(output_geo.size) + output_geo.loc.to_f64();
1277
1278 let serial = SERIAL_COUNTER.next_serial();
1279
1280 let pointer = self.niri.seat.get_pointer().unwrap();
1281
1282 if let Some(output) = self.niri.screenshot_ui.selection_output() {
1283 let geom = self.niri.global_space.output_geometry(output).unwrap();
1284 let mut point = (pos - geom.loc.to_f64())
1285 .to_physical(output.current_scale().fractional_scale())
1286 .to_i32_round::<i32>();
1287
1288 let size = output.current_mode().unwrap().size;
1289 let transform = output.current_transform();
1290 let size = transform.transform_size(size);
1291 point.x = point.x.clamp(0, size.w - 1);
1292 point.y = point.y.clamp(0, size.h - 1);
1293
1294 self.niri.screenshot_ui.pointer_motion(point);
1295 }
1296
1297 let under = self.niri.surface_under_and_global_space(pos);
1298
1299 self.niri.handle_focus_follows_mouse(&under);
1300
1301 self.niri.maybe_activate_pointer_constraint(pos, &under);
1302 self.niri.pointer_focus.clone_from(&under);
1303
1304 pointer.motion(
1305 self,
1306 under.surface,
1307 &MotionEvent {
1308 location: pos,
1309 serial,
1310 time: event.time_msec(),
1311 },
1312 );
1313
1314 pointer.frame(self);
1315
1316 // We moved the pointer, show it.
1317 self.niri.pointer_hidden = false;
1318
1319 // We moved the regular pointer, so show it now.
1320 self.niri.tablet_cursor_location = None;
1321
1322 // Redraw to update the cursor position.
1323 // FIXME: redraw only outputs overlapping the cursor.
1324 self.niri.queue_redraw_all();
1325 }
1326
1327 fn on_pointer_button<I: InputBackend>(&mut self, event: I::PointerButtonEvent) {
1328 let pointer = self.niri.seat.get_pointer().unwrap();
1329
1330 let serial = SERIAL_COUNTER.next_serial();
1331
1332 let button = event.button_code();
1333
1334 let button_state = event.state();
1335
1336 if ButtonState::Pressed == button_state {
1337 if let Some(mapped) = self.niri.window_under_cursor() {
1338 let window = mapped.window.clone();
1339
1340 // Check if we need to start an interactive resize.
1341 if event.button() == Some(MouseButton::Right) && !pointer.is_grabbed() {
1342 let mods = self.niri.seat.get_keyboard().unwrap().modifier_state();
1343 let mod_down = match self.backend.mod_key() {
1344 CompositorMod::Super => mods.logo,
1345 CompositorMod::Alt => mods.alt,
1346 };
1347 if mod_down {
1348 let location = pointer.current_location();
1349 let (output, pos_within_output) = self.niri.output_under(location).unwrap();
1350 let edges = self
1351 .niri
1352 .layout
1353 .resize_edges_under(output, pos_within_output)
1354 .unwrap();
1355
1356 if !edges.is_empty() {
1357 // See if we got a double resize-click gesture.
1358 // FIXME: deduplicate with resize_request in xdg-shell somehow.
1359 let time = get_monotonic_time();
1360 let last_cell = mapped.last_interactive_resize_start();
1361 let last = last_cell.get();
1362 last_cell.set(Some((time, edges)));
1363 if let Some((last_time, last_edges)) = last {
1364 if time.saturating_sub(last_time) <= DOUBLE_CLICK_TIME {
1365 // Allow quick resize after a triple click.
1366 last_cell.set(None);
1367
1368 let intersection = edges.intersection(last_edges);
1369 if intersection.intersects(ResizeEdge::LEFT_RIGHT) {
1370 // FIXME: don't activate once we can pass specific windows
1371 // to actions.
1372 self.niri.layout.activate_window(&window);
1373 self.niri.layout.toggle_full_width();
1374 }
1375 if intersection.intersects(ResizeEdge::TOP_BOTTOM) {
1376 // FIXME: don't activate once we can pass specific windows
1377 // to actions.
1378 self.niri.layout.activate_window(&window);
1379 self.niri.layout.reset_window_height();
1380 }
1381 // FIXME: granular.
1382 self.niri.queue_redraw_all();
1383 return;
1384 }
1385 }
1386
1387 self.niri.layout.activate_window(&window);
1388
1389 if self
1390 .niri
1391 .layout
1392 .interactive_resize_begin(window.clone(), edges)
1393 {
1394 let start_data = PointerGrabStartData {
1395 focus: None,
1396 button: event.button_code(),
1397 location,
1398 };
1399 let grab = ResizeGrab::new(start_data, window.clone());
1400 pointer.set_grab(self, grab, serial, Focus::Clear);
1401 self.niri.pointer_grab_ongoing = true;
1402 self.niri.cursor_manager.set_cursor_image(
1403 CursorImageStatus::Named(edges.cursor_icon()),
1404 );
1405 }
1406 }
1407 }
1408 }
1409
1410 self.niri.layout.activate_window(&window);
1411
1412 // FIXME: granular.
1413 self.niri.queue_redraw_all();
1414 } else if let Some(output) = self.niri.output_under_cursor() {
1415 self.niri.layout.activate_output(&output);
1416
1417 // FIXME: granular.
1418 self.niri.queue_redraw_all();
1419 }
1420
1421 if event.button() == Some(MouseButton::Middle) && !pointer.is_grabbed() {
1422 let mods = self.niri.seat.get_keyboard().unwrap().modifier_state();
1423 let mod_down = match self.backend.mod_key() {
1424 CompositorMod::Super => mods.logo,
1425 CompositorMod::Alt => mods.alt,
1426 };
1427 if mod_down {
1428 if let Some(output) = self.niri.output_under_cursor() {
1429 let location = pointer.current_location();
1430 let start_data = PointerGrabStartData {
1431 focus: None,
1432 button: event.button_code(),
1433 location,
1434 };
1435 let grab = SpatialMovementGrab::new(start_data, output);
1436 pointer.set_grab(self, grab, serial, Focus::Clear);
1437 self.niri.pointer_grab_ongoing = true;
1438 self.niri
1439 .cursor_manager
1440 .set_cursor_image(CursorImageStatus::Named(CursorIcon::AllScroll));
1441 }
1442 }
1443 }
1444 };
1445
1446 self.update_pointer_focus();
1447
1448 if ButtonState::Pressed == button_state {
1449 let layer_focus = self.niri.pointer_focus.layer.clone();
1450 self.niri.focus_layer_surface_if_on_demand(layer_focus);
1451 }
1452
1453 if let Some(button) = event.button() {
1454 let pos = pointer.current_location();
1455 if let Some((output, _)) = self.niri.output_under(pos) {
1456 let output = output.clone();
1457 let geom = self.niri.global_space.output_geometry(&output).unwrap();
1458 let mut point = (pos - geom.loc.to_f64())
1459 .to_physical(output.current_scale().fractional_scale())
1460 .to_i32_round();
1461
1462 let size = output.current_mode().unwrap().size;
1463 let transform = output.current_transform();
1464 let size = transform.transform_size(size);
1465 point.x = min(size.w - 1, point.x);
1466 point.y = min(size.h - 1, point.y);
1467
1468 if self
1469 .niri
1470 .screenshot_ui
1471 .pointer_button(output, point, button, button_state)
1472 {
1473 self.niri.queue_redraw_all();
1474 }
1475 }
1476 }
1477
1478 pointer.button(
1479 self,
1480 &ButtonEvent {
1481 button,
1482 state: button_state,
1483 serial,
1484 time: event.time_msec(),
1485 },
1486 );
1487 pointer.frame(self);
1488 }
1489
1490 fn on_pointer_axis<I: InputBackend>(&mut self, event: I::PointerAxisEvent) {
1491 let source = event.source();
1492
1493 let horizontal_amount_v120 = event.amount_v120(Axis::Horizontal);
1494 let vertical_amount_v120 = event.amount_v120(Axis::Vertical);
1495
1496 // Handle wheel scroll bindings.
1497 if source == AxisSource::Wheel {
1498 // If we have a scroll bind with current modifiers, then accumulate and don't pass to
1499 // Wayland. If there's no bind, reset the accumulator.
1500 let mods = self.niri.seat.get_keyboard().unwrap().modifier_state();
1501 let modifiers = modifiers_from_state(mods);
1502 if self.niri.mods_with_wheel_binds.contains(&modifiers) {
1503 let comp_mod = self.backend.mod_key();
1504
1505 let horizontal = horizontal_amount_v120.unwrap_or(0.);
1506 let ticks = self.niri.horizontal_wheel_tracker.accumulate(horizontal);
1507 if ticks != 0 {
1508 let config = self.niri.config.borrow();
1509 let bindings = &config.binds;
1510 let bind_left =
1511 find_configured_bind(bindings, comp_mod, Trigger::WheelScrollLeft, mods);
1512 let bind_right =
1513 find_configured_bind(bindings, comp_mod, Trigger::WheelScrollRight, mods);
1514 drop(config);
1515
1516 if let Some(right) = bind_right {
1517 for _ in 0..ticks {
1518 self.handle_bind(right.clone());
1519 }
1520 }
1521 if let Some(left) = bind_left {
1522 for _ in ticks..0 {
1523 self.handle_bind(left.clone());
1524 }
1525 }
1526 }
1527
1528 let vertical = vertical_amount_v120.unwrap_or(0.);
1529 let ticks = self.niri.vertical_wheel_tracker.accumulate(vertical);
1530 if ticks != 0 {
1531 let config = self.niri.config.borrow();
1532 let bindings = &config.binds;
1533 let bind_up =
1534 find_configured_bind(bindings, comp_mod, Trigger::WheelScrollUp, mods);
1535 let bind_down =
1536 find_configured_bind(bindings, comp_mod, Trigger::WheelScrollDown, mods);
1537 drop(config);
1538
1539 if let Some(down) = bind_down {
1540 for _ in 0..ticks {
1541 self.handle_bind(down.clone());
1542 }
1543 }
1544 if let Some(up) = bind_up {
1545 for _ in ticks..0 {
1546 self.handle_bind(up.clone());
1547 }
1548 }
1549 }
1550
1551 return;
1552 } else {
1553 self.niri.horizontal_wheel_tracker.reset();
1554 self.niri.vertical_wheel_tracker.reset();
1555 }
1556 }
1557
1558 let horizontal_amount = event.amount(Axis::Horizontal);
1559 let vertical_amount = event.amount(Axis::Vertical);
1560
1561 // Handle touchpad scroll bindings.
1562 if source == AxisSource::Finger {
1563 let mods = self.niri.seat.get_keyboard().unwrap().modifier_state();
1564 let modifiers = modifiers_from_state(mods);
1565 if self.niri.mods_with_finger_scroll_binds.contains(&modifiers) {
1566 let comp_mod = self.backend.mod_key();
1567
1568 let horizontal = horizontal_amount.unwrap_or(0.);
1569 let ticks = self
1570 .niri
1571 .horizontal_finger_scroll_tracker
1572 .accumulate(horizontal);
1573 if ticks != 0 {
1574 let config = self.niri.config.borrow();
1575 let bindings = &config.binds;
1576 let bind_left =
1577 find_configured_bind(bindings, comp_mod, Trigger::TouchpadScrollLeft, mods);
1578 let bind_right = find_configured_bind(
1579 bindings,
1580 comp_mod,
1581 Trigger::TouchpadScrollRight,
1582 mods,
1583 );
1584 drop(config);
1585
1586 if let Some(right) = bind_right {
1587 for _ in 0..ticks {
1588 self.handle_bind(right.clone());
1589 }
1590 }
1591 if let Some(left) = bind_left {
1592 for _ in ticks..0 {
1593 self.handle_bind(left.clone());
1594 }
1595 }
1596 }
1597
1598 let vertical = vertical_amount.unwrap_or(0.);
1599 let ticks = self
1600 .niri
1601 .vertical_finger_scroll_tracker
1602 .accumulate(vertical);
1603 if ticks != 0 {
1604 let config = self.niri.config.borrow();
1605 let bindings = &config.binds;
1606 let bind_up =
1607 find_configured_bind(bindings, comp_mod, Trigger::TouchpadScrollUp, mods);
1608 let bind_down =
1609 find_configured_bind(bindings, comp_mod, Trigger::TouchpadScrollDown, mods);
1610 drop(config);
1611
1612 if let Some(down) = bind_down {
1613 for _ in 0..ticks {
1614 self.handle_bind(down.clone());
1615 }
1616 }
1617 if let Some(up) = bind_up {
1618 for _ in ticks..0 {
1619 self.handle_bind(up.clone());
1620 }
1621 }
1622 }
1623
1624 return;
1625 } else {
1626 self.niri.horizontal_finger_scroll_tracker.reset();
1627 self.niri.vertical_finger_scroll_tracker.reset();
1628 }
1629 }
1630
1631 let horizontal_amount = horizontal_amount.unwrap_or_else(|| {
1632 // Winit backend, discrete scrolling.
1633 horizontal_amount_v120.unwrap_or(0.0) / 120. * 15.
1634 });
1635 let vertical_amount = vertical_amount.unwrap_or_else(|| {
1636 // Winit backend, discrete scrolling.
1637 vertical_amount_v120.unwrap_or(0.0) / 120. * 15.
1638 });
1639
1640 let mut frame = AxisFrame::new(event.time_msec()).source(source);
1641 if horizontal_amount != 0.0 {
1642 frame = frame
1643 .relative_direction(Axis::Horizontal, event.relative_direction(Axis::Horizontal));
1644 frame = frame.value(Axis::Horizontal, horizontal_amount);
1645 if let Some(v120) = horizontal_amount_v120 {
1646 frame = frame.v120(Axis::Horizontal, v120 as i32);
1647 }
1648 }
1649 if vertical_amount != 0.0 {
1650 frame =
1651 frame.relative_direction(Axis::Vertical, event.relative_direction(Axis::Vertical));
1652 frame = frame.value(Axis::Vertical, vertical_amount);
1653 if let Some(v120) = vertical_amount_v120 {
1654 frame = frame.v120(Axis::Vertical, v120 as i32);
1655 }
1656 }
1657
1658 if source == AxisSource::Finger {
1659 if event.amount(Axis::Horizontal) == Some(0.0) {
1660 frame = frame.stop(Axis::Horizontal);
1661 }
1662 if event.amount(Axis::Vertical) == Some(0.0) {
1663 frame = frame.stop(Axis::Vertical);
1664 }
1665 }
1666
1667 self.update_pointer_focus();
1668
1669 let pointer = &self.niri.seat.get_pointer().unwrap();
1670 pointer.axis(self, frame);
1671 pointer.frame(self);
1672 }
1673
1674 fn on_tablet_tool_axis<I: InputBackend>(&mut self, event: I::TabletToolAxisEvent)
1675 where
1676 I::Device: 'static, // Needed for downcasting.
1677 {
1678 let Some(pos) = self.compute_tablet_position(&event) else {
1679 return;
1680 };
1681
1682 let under = self.niri.surface_under_and_global_space(pos);
1683
1684 let tablet_seat = self.niri.seat.tablet_seat();
1685 let tablet = tablet_seat.get_tablet(&TabletDescriptor::from(&event.device()));
1686 let tool = tablet_seat.get_tool(&event.tool());
1687 if let (Some(tablet), Some(tool)) = (tablet, tool) {
1688 if event.pressure_has_changed() {
1689 tool.pressure(event.pressure());
1690 }
1691 if event.distance_has_changed() {
1692 tool.distance(event.distance());
1693 }
1694 if event.tilt_has_changed() {
1695 tool.tilt(event.tilt());
1696 }
1697 if event.slider_has_changed() {
1698 tool.slider_position(event.slider_position());
1699 }
1700 if event.rotation_has_changed() {
1701 tool.rotation(event.rotation());
1702 }
1703 if event.wheel_has_changed() {
1704 tool.wheel(event.wheel_delta(), event.wheel_delta_discrete());
1705 }
1706
1707 tool.motion(
1708 pos,
1709 under.surface,
1710 &tablet,
1711 SERIAL_COUNTER.next_serial(),
1712 event.time_msec(),
1713 );
1714
1715 self.niri.pointer_hidden = false;
1716 self.niri.tablet_cursor_location = Some(pos);
1717 }
1718
1719 // Redraw to update the cursor position.
1720 // FIXME: redraw only outputs overlapping the cursor.
1721 self.niri.queue_redraw_all();
1722 }
1723
1724 fn on_tablet_tool_tip<I: InputBackend>(&mut self, event: I::TabletToolTipEvent) {
1725 let tool = self.niri.seat.tablet_seat().get_tool(&event.tool());
1726
1727 if let Some(tool) = tool {
1728 match event.tip_state() {
1729 TabletToolTipState::Down => {
1730 let serial = SERIAL_COUNTER.next_serial();
1731 tool.tip_down(serial, event.time_msec());
1732
1733 if let Some(pos) = self.niri.tablet_cursor_location {
1734 let under = self.niri.surface_under_and_global_space(pos);
1735 if let Some(window) = under.window {
1736 self.niri.layout.activate_window(&window);
1737
1738 // FIXME: granular.
1739 self.niri.queue_redraw_all();
1740 } else if let Some(output) = under.output {
1741 self.niri.layout.activate_output(&output);
1742
1743 // FIXME: granular.
1744 self.niri.queue_redraw_all();
1745 }
1746 self.niri.focus_layer_surface_if_on_demand(under.layer);
1747 }
1748 }
1749 TabletToolTipState::Up => {
1750 tool.tip_up(event.time_msec());
1751 }
1752 }
1753 }
1754 }
1755
1756 fn on_tablet_tool_proximity<I: InputBackend>(&mut self, event: I::TabletToolProximityEvent)
1757 where
1758 I::Device: 'static, // Needed for downcasting.
1759 {
1760 let Some(pos) = self.compute_tablet_position(&event) else {
1761 return;
1762 };
1763
1764 let under = self.niri.surface_under_and_global_space(pos);
1765
1766 let tablet_seat = self.niri.seat.tablet_seat();
1767 let tool = tablet_seat.add_tool::<Self>(&self.niri.display_handle, &event.tool());
1768 let tablet = tablet_seat.get_tablet(&TabletDescriptor::from(&event.device()));
1769 if let Some(tablet) = tablet {
1770 match event.state() {
1771 ProximityState::In => {
1772 if let Some(under) = under.surface {
1773 tool.proximity_in(
1774 pos,
1775 under,
1776 &tablet,
1777 SERIAL_COUNTER.next_serial(),
1778 event.time_msec(),
1779 );
1780 }
1781 self.niri.pointer_hidden = false;
1782 self.niri.tablet_cursor_location = Some(pos);
1783 }
1784 ProximityState::Out => {
1785 tool.proximity_out(event.time_msec());
1786
1787 // Move the mouse pointer here to avoid discontinuity.
1788 //
1789 // Plus, Wayland SDL2 currently warps the pointer into some weird
1790 // location on proximity out, so this should help it a little.
1791 if let Some(pos) = self.niri.tablet_cursor_location {
1792 self.move_cursor(pos);
1793 }
1794
1795 self.niri.tablet_cursor_location = None;
1796 }
1797 }
1798
1799 // FIXME: granular.
1800 self.niri.queue_redraw_all();
1801 }
1802 }
1803
1804 fn on_tablet_tool_button<I: InputBackend>(&mut self, event: I::TabletToolButtonEvent) {
1805 let tool = self.niri.seat.tablet_seat().get_tool(&event.tool());
1806
1807 if let Some(tool) = tool {
1808 tool.button(
1809 event.button(),
1810 event.button_state(),
1811 SERIAL_COUNTER.next_serial(),
1812 event.time_msec(),
1813 );
1814 }
1815 }
1816
1817 fn on_gesture_swipe_begin<I: InputBackend>(&mut self, event: I::GestureSwipeBeginEvent) {
1818 if event.fingers() == 3 {
1819 self.niri.gesture_swipe_3f_cumulative = Some((0., 0.));
1820
1821 // We handled this event.
1822 return;
1823 }
1824
1825 let serial = SERIAL_COUNTER.next_serial();
1826 let pointer = self.niri.seat.get_pointer().unwrap();
1827
1828 if self.update_pointer_focus() {
1829 pointer.frame(self);
1830 }
1831
1832 pointer.gesture_swipe_begin(
1833 self,
1834 &GestureSwipeBeginEvent {
1835 serial,
1836 time: event.time_msec(),
1837 fingers: event.fingers(),
1838 },
1839 );
1840 }
1841
1842 fn on_gesture_swipe_update<I: InputBackend + 'static>(
1843 &mut self,
1844 event: I::GestureSwipeUpdateEvent,
1845 ) where
1846 I::Device: 'static,
1847 {
1848 let mut delta_x = event.delta_x();
1849 let mut delta_y = event.delta_y();
1850
1851 if let Some(libinput_event) =
1852 (&event as &dyn Any).downcast_ref::<input::event::gesture::GestureSwipeUpdateEvent>()
1853 {
1854 delta_x = libinput_event.dx_unaccelerated();
1855 delta_y = libinput_event.dy_unaccelerated();
1856 }
1857
1858 let device = event.device();
1859 if let Some(device) = (&device as &dyn Any).downcast_ref::<input::Device>() {
1860 if device.config_scroll_natural_scroll_enabled() {
1861 delta_x = -delta_x;
1862 delta_y = -delta_y;
1863 }
1864 }
1865
1866 if let Some((cx, cy)) = &mut self.niri.gesture_swipe_3f_cumulative {
1867 *cx += delta_x;
1868 *cy += delta_y;
1869
1870 // Check if the gesture moved far enough to decide. Threshold copied from GNOME Shell.
1871 let (cx, cy) = (*cx, *cy);
1872 if cx * cx + cy * cy >= 16. * 16. {
1873 self.niri.gesture_swipe_3f_cumulative = None;
1874
1875 if let Some(output) = self.niri.output_under_cursor() {
1876 if cx.abs() > cy.abs() {
1877 self.niri.layout.view_offset_gesture_begin(&output, true);
1878 } else {
1879 self.niri
1880 .layout
1881 .workspace_switch_gesture_begin(&output, true);
1882 }
1883 }
1884 }
1885 }
1886
1887 let timestamp = Duration::from_micros(event.time());
1888
1889 let mut handled = false;
1890 let res = self
1891 .niri
1892 .layout
1893 .workspace_switch_gesture_update(delta_y, timestamp, true);
1894 if let Some(output) = res {
1895 if let Some(output) = output {
1896 self.niri.queue_redraw(&output);
1897 }
1898 handled = true;
1899 }
1900
1901 let res = self
1902 .niri
1903 .layout
1904 .view_offset_gesture_update(delta_x, timestamp, true);
1905 if let Some(output) = res {
1906 if let Some(output) = output {
1907 self.niri.queue_redraw(&output);
1908 }
1909 handled = true;
1910 }
1911
1912 if handled {
1913 // We handled this event.
1914 return;
1915 }
1916
1917 let pointer = self.niri.seat.get_pointer().unwrap();
1918
1919 if self.update_pointer_focus() {
1920 pointer.frame(self);
1921 }
1922
1923 pointer.gesture_swipe_update(
1924 self,
1925 &GestureSwipeUpdateEvent {
1926 time: event.time_msec(),
1927 delta: event.delta(),
1928 },
1929 );
1930 }
1931
1932 fn on_gesture_swipe_end<I: InputBackend>(&mut self, event: I::GestureSwipeEndEvent) {
1933 self.niri.gesture_swipe_3f_cumulative = None;
1934
1935 let mut handled = false;
1936 let res = self
1937 .niri
1938 .layout
1939 .workspace_switch_gesture_end(event.cancelled(), Some(true));
1940 if let Some(output) = res {
1941 self.niri.queue_redraw(&output);
1942 handled = true;
1943 }
1944
1945 let res = self
1946 .niri
1947 .layout
1948 .view_offset_gesture_end(event.cancelled(), Some(true));
1949 if let Some(output) = res {
1950 self.niri.queue_redraw(&output);
1951 handled = true;
1952 }
1953
1954 if handled {
1955 // We handled this event.
1956 return;
1957 }
1958
1959 let serial = SERIAL_COUNTER.next_serial();
1960 let pointer = self.niri.seat.get_pointer().unwrap();
1961
1962 if self.update_pointer_focus() {
1963 pointer.frame(self);
1964 }
1965
1966 pointer.gesture_swipe_end(
1967 self,
1968 &GestureSwipeEndEvent {
1969 serial,
1970 time: event.time_msec(),
1971 cancelled: event.cancelled(),
1972 },
1973 );
1974 }
1975
1976 fn on_gesture_pinch_begin<I: InputBackend>(&mut self, event: I::GesturePinchBeginEvent) {
1977 let serial = SERIAL_COUNTER.next_serial();
1978 let pointer = self.niri.seat.get_pointer().unwrap();
1979
1980 if self.update_pointer_focus() {
1981 pointer.frame(self);
1982 }
1983
1984 pointer.gesture_pinch_begin(
1985 self,
1986 &GesturePinchBeginEvent {
1987 serial,
1988 time: event.time_msec(),
1989 fingers: event.fingers(),
1990 },
1991 );
1992 }
1993
1994 fn on_gesture_pinch_update<I: InputBackend>(&mut self, event: I::GesturePinchUpdateEvent) {
1995 let pointer = self.niri.seat.get_pointer().unwrap();
1996
1997 if self.update_pointer_focus() {
1998 pointer.frame(self);
1999 }
2000
2001 pointer.gesture_pinch_update(
2002 self,
2003 &GesturePinchUpdateEvent {
2004 time: event.time_msec(),
2005 delta: event.delta(),
2006 scale: event.scale(),
2007 rotation: event.rotation(),
2008 },
2009 );
2010 }
2011
2012 fn on_gesture_pinch_end<I: InputBackend>(&mut self, event: I::GesturePinchEndEvent) {
2013 let serial = SERIAL_COUNTER.next_serial();
2014 let pointer = self.niri.seat.get_pointer().unwrap();
2015
2016 if self.update_pointer_focus() {
2017 pointer.frame(self);
2018 }
2019
2020 pointer.gesture_pinch_end(
2021 self,
2022 &GesturePinchEndEvent {
2023 serial,
2024 time: event.time_msec(),
2025 cancelled: event.cancelled(),
2026 },
2027 );
2028 }
2029
2030 fn on_gesture_hold_begin<I: InputBackend>(&mut self, event: I::GestureHoldBeginEvent) {
2031 let serial = SERIAL_COUNTER.next_serial();
2032 let pointer = self.niri.seat.get_pointer().unwrap();
2033
2034 if self.update_pointer_focus() {
2035 pointer.frame(self);
2036 }
2037
2038 pointer.gesture_hold_begin(
2039 self,
2040 &GestureHoldBeginEvent {
2041 serial,
2042 time: event.time_msec(),
2043 fingers: event.fingers(),
2044 },
2045 );
2046 }
2047
2048 fn on_gesture_hold_end<I: InputBackend>(&mut self, event: I::GestureHoldEndEvent) {
2049 let serial = SERIAL_COUNTER.next_serial();
2050 let pointer = self.niri.seat.get_pointer().unwrap();
2051
2052 if self.update_pointer_focus() {
2053 pointer.frame(self);
2054 }
2055
2056 pointer.gesture_hold_end(
2057 self,
2058 &GestureHoldEndEvent {
2059 serial,
2060 time: event.time_msec(),
2061 cancelled: event.cancelled(),
2062 },
2063 );
2064 }
2065
2066 /// Computes the cursor position for the touch event.
2067 ///
2068 /// This function handles the touch output mapping, as well as coordinate transform
2069 fn compute_touch_location<I: InputBackend, E: AbsolutePositionEvent<I>>(
2070 &self,
2071 evt: &E,
2072 ) -> Option<Point<f64, Logical>> {
2073 let output = self.niri.output_for_touch()?;
2074 let output_geo = self.niri.global_space.output_geometry(output).unwrap();
2075 let transform = output.current_transform();
2076 let size = transform.invert().transform_size(output_geo.size);
2077 Some(
2078 transform.transform_point_in(evt.position_transformed(size), &size.to_f64())
2079 + output_geo.loc.to_f64(),
2080 )
2081 }
2082
2083 fn on_touch_down<I: InputBackend>(&mut self, evt: I::TouchDownEvent) {
2084 let Some(handle) = self.niri.seat.get_touch() else {
2085 return;
2086 };
2087 let Some(touch_location) = self.compute_touch_location(&evt) else {
2088 return;
2089 };
2090
2091 let under = self.niri.surface_under_and_global_space(touch_location);
2092
2093 if !handle.is_grabbed() {
2094 if let Some(window) = under.window {
2095 self.niri.layout.activate_window(&window);
2096
2097 // FIXME: granular.
2098 self.niri.queue_redraw_all();
2099 } else if let Some(output) = under.output {
2100 self.niri.layout.activate_output(&output);
2101
2102 // FIXME: granular.
2103 self.niri.queue_redraw_all();
2104 }
2105 self.niri.focus_layer_surface_if_on_demand(under.layer);
2106 };
2107
2108 let serial = SERIAL_COUNTER.next_serial();
2109 handle.down(
2110 self,
2111 under.surface,
2112 &DownEvent {
2113 slot: evt.slot(),
2114 location: touch_location,
2115 serial,
2116 time: evt.time_msec(),
2117 },
2118 );
2119
2120 // We're using touch, hide the pointer.
2121 self.niri.pointer_hidden = true;
2122 }
2123 fn on_touch_up<I: InputBackend>(&mut self, evt: I::TouchUpEvent) {
2124 let Some(handle) = self.niri.seat.get_touch() else {
2125 return;
2126 };
2127 let serial = SERIAL_COUNTER.next_serial();
2128 handle.up(
2129 self,
2130 &UpEvent {
2131 slot: evt.slot(),
2132 serial,
2133 time: evt.time_msec(),
2134 },
2135 )
2136 }
2137 fn on_touch_motion<I: InputBackend>(&mut self, evt: I::TouchMotionEvent) {
2138 let Some(handle) = self.niri.seat.get_touch() else {
2139 return;
2140 };
2141 let Some(touch_location) = self.compute_touch_location(&evt) else {
2142 return;
2143 };
2144 let under = self.niri.surface_under_and_global_space(touch_location);
2145 handle.motion(
2146 self,
2147 under.surface,
2148 &TouchMotionEvent {
2149 slot: evt.slot(),
2150 location: touch_location,
2151 time: evt.time_msec(),
2152 },
2153 );
2154 }
2155 fn on_touch_frame<I: InputBackend>(&mut self, _evt: I::TouchFrameEvent) {
2156 let Some(handle) = self.niri.seat.get_touch() else {
2157 return;
2158 };
2159 handle.frame(self);
2160 }
2161 fn on_touch_cancel<I: InputBackend>(&mut self, _evt: I::TouchCancelEvent) {
2162 let Some(handle) = self.niri.seat.get_touch() else {
2163 return;
2164 };
2165 handle.cancel(self);
2166 }
2167}
2168
2169/// Check whether the key should be intercepted and mark intercepted
2170/// pressed keys as `suppressed`, thus preventing `releases` corresponding
2171/// to them from being delivered.
2172#[allow(clippy::too_many_arguments)]
2173fn should_intercept_key(
2174 suppressed_keys: &mut HashSet<u32>,
2175 bindings: &Binds,
2176 comp_mod: CompositorMod,
2177 key_code: u32,
2178 modified: Keysym,
2179 raw: Option<Keysym>,
2180 pressed: bool,
2181 mods: ModifiersState,
2182 screenshot_ui: &ScreenshotUi,
2183 disable_power_key_handling: bool,
2184) -> FilterResult<Option<Bind>> {
2185 // Actions are only triggered on presses, release of the key
2186 // shouldn't try to intercept anything unless we have marked
2187 // the key to suppress.
2188 if !pressed && !suppressed_keys.contains(&key_code) {
2189 return FilterResult::Forward;
2190 }
2191
2192 let mut final_bind = find_bind(
2193 bindings,
2194 comp_mod,
2195 modified,
2196 raw,
2197 mods,
2198 disable_power_key_handling,
2199 );
2200
2201 // Allow only a subset of compositor actions while the screenshot UI is open, since the user
2202 // cannot see the screen.
2203 if screenshot_ui.is_open() {
2204 let mut use_screenshot_ui_action = true;
2205
2206 if let Some(bind) = &final_bind {
2207 if allowed_during_screenshot(&bind.action) {
2208 use_screenshot_ui_action = false;
2209 }
2210 }
2211
2212 if use_screenshot_ui_action {
2213 if let Some(raw) = raw {
2214 final_bind = screenshot_ui.action(raw, mods).map(|action| Bind {
2215 key: Key {
2216 trigger: Trigger::Keysym(raw),
2217 // Not entirely correct but it doesn't matter in how we currently use it.
2218 modifiers: Modifiers::empty(),
2219 },
2220 action,
2221 repeat: true,
2222 cooldown: None,
2223 allow_when_locked: false,
2224 });
2225 }
2226 }
2227 }
2228
2229 match (final_bind, pressed) {
2230 (Some(bind), true) => {
2231 suppressed_keys.insert(key_code);
2232 FilterResult::Intercept(Some(bind))
2233 }
2234 (_, false) => {
2235 suppressed_keys.remove(&key_code);
2236 FilterResult::Intercept(None)
2237 }
2238 (None, true) => FilterResult::Forward,
2239 }
2240}
2241
2242fn find_bind(
2243 bindings: &Binds,
2244 comp_mod: CompositorMod,
2245 modified: Keysym,
2246 raw: Option<Keysym>,
2247 mods: ModifiersState,
2248 disable_power_key_handling: bool,
2249) -> Option<Bind> {
2250 use keysyms::*;
2251
2252 // Handle hardcoded binds.
2253 #[allow(non_upper_case_globals)] // wat
2254 let hardcoded_action = match modified.raw() {
2255 modified @ KEY_XF86Switch_VT_1..=KEY_XF86Switch_VT_12 => {
2256 let vt = (modified - KEY_XF86Switch_VT_1 + 1) as i32;
2257 Some(Action::ChangeVt(vt))
2258 }
2259 KEY_XF86PowerOff if !disable_power_key_handling => Some(Action::Suspend),
2260 _ => None,
2261 };
2262
2263 if let Some(action) = hardcoded_action {
2264 return Some(Bind {
2265 key: Key {
2266 // Not entirely correct but it doesn't matter in how we currently use it.
2267 trigger: Trigger::Keysym(modified),
2268 modifiers: Modifiers::empty(),
2269 },
2270 action,
2271 repeat: true,
2272 cooldown: None,
2273 allow_when_locked: false,
2274 });
2275 }
2276
2277 let trigger = Trigger::Keysym(raw?);
2278 find_configured_bind(bindings, comp_mod, trigger, mods)
2279}
2280
2281fn find_configured_bind(
2282 bindings: &Binds,
2283 comp_mod: CompositorMod,
2284 trigger: Trigger,
2285 mods: ModifiersState,
2286) -> Option<Bind> {
2287 // Handle configured binds.
2288 let mut modifiers = modifiers_from_state(mods);
2289
2290 let (mod_down, comp_mod) = match comp_mod {
2291 CompositorMod::Super => (mods.logo, Modifiers::SUPER),
2292 CompositorMod::Alt => (mods.alt, Modifiers::ALT),
2293 };
2294 if mod_down {
2295 modifiers |= Modifiers::COMPOSITOR;
2296 }
2297
2298 for bind in &bindings.0 {
2299 if bind.key.trigger != trigger {
2300 continue;
2301 }
2302
2303 let mut bind_modifiers = bind.key.modifiers;
2304 if bind_modifiers.contains(Modifiers::COMPOSITOR) {
2305 bind_modifiers |= comp_mod;
2306 } else if bind_modifiers.contains(comp_mod) {
2307 bind_modifiers |= Modifiers::COMPOSITOR;
2308 }
2309
2310 if bind_modifiers == modifiers {
2311 return Some(bind.clone());
2312 }
2313 }
2314
2315 None
2316}
2317
2318fn modifiers_from_state(mods: ModifiersState) -> Modifiers {
2319 let mut modifiers = Modifiers::empty();
2320 if mods.ctrl {
2321 modifiers |= Modifiers::CTRL;
2322 }
2323 if mods.shift {
2324 modifiers |= Modifiers::SHIFT;
2325 }
2326 if mods.alt {
2327 modifiers |= Modifiers::ALT;
2328 }
2329 if mods.logo {
2330 modifiers |= Modifiers::SUPER;
2331 }
2332 if mods.iso_level3_shift {
2333 modifiers |= Modifiers::ISO_LEVEL3_SHIFT;
2334 }
2335 if mods.iso_level5_shift {
2336 modifiers |= Modifiers::ISO_LEVEL5_SHIFT;
2337 }
2338 modifiers
2339}
2340
2341fn should_activate_monitors<I: InputBackend>(event: &InputEvent<I>) -> bool {
2342 match event {
2343 InputEvent::Keyboard { event } if event.state() == KeyState::Pressed => true,
2344 InputEvent::PointerButton { event } if event.state() == ButtonState::Pressed => true,
2345 InputEvent::PointerMotion { .. }
2346 | InputEvent::PointerMotionAbsolute { .. }
2347 | InputEvent::PointerAxis { .. }
2348 | InputEvent::GestureSwipeBegin { .. }
2349 | InputEvent::GesturePinchBegin { .. }
2350 | InputEvent::GestureHoldBegin { .. }
2351 | InputEvent::TouchDown { .. }
2352 | InputEvent::TouchMotion { .. }
2353 | InputEvent::TabletToolAxis { .. }
2354 | InputEvent::TabletToolProximity { .. }
2355 | InputEvent::TabletToolTip { .. }
2356 | InputEvent::TabletToolButton { .. } => true,
2357 // Ignore events like device additions and removals, key releases, gesture ends.
2358 _ => false,
2359 }
2360}
2361
2362fn should_hide_hotkey_overlay<I: InputBackend>(event: &InputEvent<I>) -> bool {
2363 match event {
2364 InputEvent::Keyboard { event } if event.state() == KeyState::Pressed => true,
2365 InputEvent::PointerButton { event } if event.state() == ButtonState::Pressed => true,
2366 InputEvent::PointerAxis { .. }
2367 | InputEvent::GestureSwipeBegin { .. }
2368 | InputEvent::GesturePinchBegin { .. }
2369 | InputEvent::TouchDown { .. }
2370 | InputEvent::TouchMotion { .. }
2371 | InputEvent::TabletToolTip { .. }
2372 | InputEvent::TabletToolButton { .. } => true,
2373 _ => false,
2374 }
2375}
2376
2377fn should_hide_exit_confirm_dialog<I: InputBackend>(event: &InputEvent<I>) -> bool {
2378 match event {
2379 InputEvent::Keyboard { event } if event.state() == KeyState::Pressed => true,
2380 InputEvent::PointerButton { event } if event.state() == ButtonState::Pressed => true,
2381 InputEvent::PointerAxis { .. }
2382 | InputEvent::GestureSwipeBegin { .. }
2383 | InputEvent::GesturePinchBegin { .. }
2384 | InputEvent::TouchDown { .. }
2385 | InputEvent::TouchMotion { .. }
2386 | InputEvent::TabletToolTip { .. }
2387 | InputEvent::TabletToolButton { .. } => true,
2388 _ => false,
2389 }
2390}
2391
2392fn should_notify_activity<I: InputBackend>(event: &InputEvent<I>) -> bool {
2393 !matches!(
2394 event,
2395 InputEvent::DeviceAdded { .. } | InputEvent::DeviceRemoved { .. }
2396 )
2397}
2398
2399fn allowed_when_locked(action: &Action) -> bool {
2400 matches!(
2401 action,
2402 Action::Quit(_)
2403 | Action::ChangeVt(_)
2404 | Action::Suspend
2405 | Action::PowerOffMonitors
2406 | Action::SwitchLayout(_)
2407 )
2408}
2409
2410fn allowed_during_screenshot(action: &Action) -> bool {
2411 matches!(
2412 action,
2413 Action::Quit(_) | Action::ChangeVt(_) | Action::Suspend | Action::PowerOffMonitors
2414 )
2415}
2416
2417pub fn apply_libinput_settings(config: &niri_config::Input, device: &mut input::Device) {
2418 // According to Mutter code, this setting is specific to touchpads.
2419 let is_touchpad = device.config_tap_finger_count() > 0;
2420 if is_touchpad {
2421 let c = &config.touchpad;
2422 let _ = device.config_send_events_set_mode(if c.off {
2423 input::SendEventsMode::DISABLED
2424 } else if c.disabled_on_external_mouse {
2425 input::SendEventsMode::DISABLED_ON_EXTERNAL_MOUSE
2426 } else {
2427 input::SendEventsMode::ENABLED
2428 });
2429 let _ = device.config_tap_set_enabled(c.tap);
2430 let _ = device.config_dwt_set_enabled(c.dwt);
2431 let _ = device.config_dwtp_set_enabled(c.dwtp);
2432 let _ = device.config_scroll_set_natural_scroll_enabled(c.natural_scroll);
2433 let _ = device.config_accel_set_speed(c.accel_speed);
2434 let _ = device.config_left_handed_set(c.left_handed);
2435 let _ = device.config_middle_emulation_set_enabled(c.middle_emulation);
2436
2437 if let Some(accel_profile) = c.accel_profile {
2438 let _ = device.config_accel_set_profile(accel_profile.into());
2439 } else if let Some(default) = device.config_accel_default_profile() {
2440 let _ = device.config_accel_set_profile(default);
2441 }
2442
2443 if let Some(method) = c.scroll_method {
2444 let _ = device.config_scroll_set_method(method.into());
2445 } else if let Some(default) = device.config_scroll_default_method() {
2446 let _ = device.config_scroll_set_method(default);
2447 }
2448
2449 if let Some(tap_button_map) = c.tap_button_map {
2450 let _ = device.config_tap_set_button_map(tap_button_map.into());
2451 } else if let Some(default) = device.config_tap_default_button_map() {
2452 let _ = device.config_tap_set_button_map(default);
2453 }
2454
2455 if let Some(method) = c.click_method {
2456 let _ = device.config_click_set_method(method.into());
2457 } else if let Some(default) = device.config_click_default_method() {
2458 let _ = device.config_click_set_method(default);
2459 }
2460 }
2461
2462 // This is how Mutter tells apart mice.
2463 let mut is_trackball = false;
2464 let mut is_trackpoint = false;
2465 if let Some(udev_device) = unsafe { device.udev_device() } {
2466 if udev_device.property_value("ID_INPUT_TRACKBALL").is_some() {
2467 is_trackball = true;
2468 }
2469 if udev_device
2470 .property_value("ID_INPUT_POINTINGSTICK")
2471 .is_some()
2472 {
2473 is_trackpoint = true;
2474 }
2475 }
2476
2477 let is_mouse = device.has_capability(input::DeviceCapability::Pointer)
2478 && !is_touchpad
2479 && !is_trackball
2480 && !is_trackpoint;
2481 if is_mouse {
2482 let c = &config.mouse;
2483 let _ = device.config_send_events_set_mode(if c.off {
2484 input::SendEventsMode::DISABLED
2485 } else {
2486 input::SendEventsMode::ENABLED
2487 });
2488 let _ = device.config_scroll_set_natural_scroll_enabled(c.natural_scroll);
2489 let _ = device.config_accel_set_speed(c.accel_speed);
2490 let _ = device.config_left_handed_set(c.left_handed);
2491 let _ = device.config_middle_emulation_set_enabled(c.middle_emulation);
2492
2493 if let Some(accel_profile) = c.accel_profile {
2494 let _ = device.config_accel_set_profile(accel_profile.into());
2495 } else if let Some(default) = device.config_accel_default_profile() {
2496 let _ = device.config_accel_set_profile(default);
2497 }
2498
2499 if let Some(method) = c.scroll_method {
2500 let _ = device.config_scroll_set_method(method.into());
2501 } else if let Some(default) = device.config_scroll_default_method() {
2502 let _ = device.config_scroll_set_method(default);
2503 }
2504 }
2505
2506 if is_trackpoint {
2507 let c = &config.trackpoint;
2508 let _ = device.config_send_events_set_mode(if c.off {
2509 input::SendEventsMode::DISABLED
2510 } else {
2511 input::SendEventsMode::ENABLED
2512 });
2513 let _ = device.config_scroll_set_natural_scroll_enabled(c.natural_scroll);
2514 let _ = device.config_accel_set_speed(c.accel_speed);
2515 let _ = device.config_middle_emulation_set_enabled(c.middle_emulation);
2516
2517 if let Some(accel_profile) = c.accel_profile {
2518 let _ = device.config_accel_set_profile(accel_profile.into());
2519 } else if let Some(default) = device.config_accel_default_profile() {
2520 let _ = device.config_accel_set_profile(default);
2521 }
2522
2523 if let Some(method) = c.scroll_method {
2524 let _ = device.config_scroll_set_method(method.into());
2525 } else if let Some(default) = device.config_scroll_default_method() {
2526 let _ = device.config_scroll_set_method(default);
2527 }
2528 }
2529
2530 let is_tablet = device.has_capability(input::DeviceCapability::TabletTool);
2531 if is_tablet {
2532 let c = &config.tablet;
2533 let _ = device.config_send_events_set_mode(if c.off {
2534 input::SendEventsMode::DISABLED
2535 } else {
2536 input::SendEventsMode::ENABLED
2537 });
2538 let _ = device.config_left_handed_set(c.left_handed);
2539 }
2540}
2541
2542pub fn mods_with_binds(
2543 comp_mod: CompositorMod,
2544 binds: &Binds,
2545 triggers: &[Trigger],
2546) -> HashSet<Modifiers> {
2547 let comp_mod = match comp_mod {
2548 CompositorMod::Super => Modifiers::SUPER,
2549 CompositorMod::Alt => Modifiers::ALT,
2550 };
2551
2552 let mut rv = HashSet::new();
2553 for bind in &binds.0 {
2554 if !triggers.iter().any(|trigger| bind.key.trigger == *trigger) {
2555 continue;
2556 }
2557
2558 let mut mods = bind.key.modifiers;
2559 if mods.contains(Modifiers::COMPOSITOR) {
2560 mods.remove(Modifiers::COMPOSITOR);
2561 mods.insert(comp_mod);
2562 }
2563
2564 rv.insert(mods);
2565 }
2566
2567 rv
2568}
2569
2570pub fn mods_with_wheel_binds(comp_mod: CompositorMod, binds: &Binds) -> HashSet<Modifiers> {
2571 mods_with_binds(
2572 comp_mod,
2573 binds,
2574 &[
2575 Trigger::WheelScrollUp,
2576 Trigger::WheelScrollDown,
2577 Trigger::WheelScrollLeft,
2578 Trigger::WheelScrollRight,
2579 ],
2580 )
2581}
2582
2583pub fn mods_with_finger_scroll_binds(comp_mod: CompositorMod, binds: &Binds) -> HashSet<Modifiers> {
2584 mods_with_binds(
2585 comp_mod,
2586 binds,
2587 &[
2588 Trigger::TouchpadScrollUp,
2589 Trigger::TouchpadScrollDown,
2590 Trigger::TouchpadScrollLeft,
2591 Trigger::TouchpadScrollRight,
2592 ],
2593 )
2594}
2595
2596#[cfg(test)]
2597mod tests {
2598 use super::*;
2599
2600 #[test]
2601 fn bindings_suppress_keys() {
2602 let close_keysym = Keysym::q;
2603 let bindings = Binds(vec![Bind {
2604 key: Key {
2605 trigger: Trigger::Keysym(close_keysym),
2606 modifiers: Modifiers::COMPOSITOR | Modifiers::CTRL,
2607 },
2608 action: Action::CloseWindow,
2609 repeat: true,
2610 cooldown: None,
2611 allow_when_locked: false,
2612 }]);
2613
2614 let comp_mod = CompositorMod::Super;
2615 let mut suppressed_keys = HashSet::new();
2616
2617 let screenshot_ui = ScreenshotUi::new(Default::default());
2618 let disable_power_key_handling = false;
2619
2620 // The key_code we pick is arbitrary, the only thing
2621 // that matters is that they are different between cases.
2622
2623 let close_key_code = close_keysym.into();
2624 let close_key_event = |suppr: &mut HashSet<u32>, mods: ModifiersState, pressed| {
2625 should_intercept_key(
2626 suppr,
2627 &bindings,
2628 comp_mod,
2629 close_key_code,
2630 close_keysym,
2631 Some(close_keysym),
2632 pressed,
2633 mods,
2634 &screenshot_ui,
2635 disable_power_key_handling,
2636 )
2637 };
2638
2639 // Key event with the code which can't trigger any action.
2640 let none_key_event = |suppr: &mut HashSet<u32>, mods: ModifiersState, pressed| {
2641 should_intercept_key(
2642 suppr,
2643 &bindings,
2644 comp_mod,
2645 Keysym::l.into(),
2646 Keysym::l,
2647 Some(Keysym::l),
2648 pressed,
2649 mods,
2650 &screenshot_ui,
2651 disable_power_key_handling,
2652 )
2653 };
2654
2655 let mut mods = ModifiersState {
2656 logo: true,
2657 ctrl: true,
2658 ..Default::default()
2659 };
2660
2661 // Action press/release.
2662
2663 let filter = close_key_event(&mut suppressed_keys, mods, true);
2664 assert!(matches!(
2665 filter,
2666 FilterResult::Intercept(Some(Bind {
2667 action: Action::CloseWindow,
2668 ..
2669 }))
2670 ));
2671 assert!(suppressed_keys.contains(&close_key_code));
2672
2673 let filter = close_key_event(&mut suppressed_keys, mods, false);
2674 assert!(matches!(filter, FilterResult::Intercept(None)));
2675 assert!(suppressed_keys.is_empty());
2676
2677 // Remove mod to make it for a binding.
2678
2679 mods.shift = true;
2680 let filter = close_key_event(&mut suppressed_keys, mods, true);
2681 assert!(matches!(filter, FilterResult::Forward));
2682
2683 mods.shift = false;
2684 let filter = close_key_event(&mut suppressed_keys, mods, false);
2685 assert!(matches!(filter, FilterResult::Forward));
2686
2687 // Just none press/release.
2688
2689 let filter = none_key_event(&mut suppressed_keys, mods, true);
2690 assert!(matches!(filter, FilterResult::Forward));
2691
2692 let filter = none_key_event(&mut suppressed_keys, mods, false);
2693 assert!(matches!(filter, FilterResult::Forward));
2694
2695 // Press action, press arbitrary, release action, release arbitrary.
2696
2697 let filter = close_key_event(&mut suppressed_keys, mods, true);
2698 assert!(matches!(
2699 filter,
2700 FilterResult::Intercept(Some(Bind {
2701 action: Action::CloseWindow,
2702 ..
2703 }))
2704 ));
2705
2706 let filter = none_key_event(&mut suppressed_keys, mods, true);
2707 assert!(matches!(filter, FilterResult::Forward));
2708
2709 let filter = close_key_event(&mut suppressed_keys, mods, false);
2710 assert!(matches!(filter, FilterResult::Intercept(None)));
2711
2712 let filter = none_key_event(&mut suppressed_keys, mods, false);
2713 assert!(matches!(filter, FilterResult::Forward));
2714
2715 // Trigger and remove all mods.
2716
2717 let filter = close_key_event(&mut suppressed_keys, mods, true);
2718 assert!(matches!(
2719 filter,
2720 FilterResult::Intercept(Some(Bind {
2721 action: Action::CloseWindow,
2722 ..
2723 }))
2724 ));
2725
2726 mods = Default::default();
2727 let filter = close_key_event(&mut suppressed_keys, mods, false);
2728 assert!(matches!(filter, FilterResult::Intercept(None)));
2729
2730 // Ensure that no keys are being suppressed.
2731 assert!(suppressed_keys.is_empty());
2732 }
2733
2734 #[test]
2735 fn comp_mod_handling() {
2736 let bindings = Binds(vec![
2737 Bind {
2738 key: Key {
2739 trigger: Trigger::Keysym(Keysym::q),
2740 modifiers: Modifiers::COMPOSITOR,
2741 },
2742 action: Action::CloseWindow,
2743 repeat: true,
2744 cooldown: None,
2745 allow_when_locked: false,
2746 },
2747 Bind {
2748 key: Key {
2749 trigger: Trigger::Keysym(Keysym::h),
2750 modifiers: Modifiers::SUPER,
2751 },
2752 action: Action::FocusColumnLeft,
2753 repeat: true,
2754 cooldown: None,
2755 allow_when_locked: false,
2756 },
2757 Bind {
2758 key: Key {
2759 trigger: Trigger::Keysym(Keysym::j),
2760 modifiers: Modifiers::empty(),
2761 },
2762 action: Action::FocusWindowDown,
2763 repeat: true,
2764 cooldown: None,
2765 allow_when_locked: false,
2766 },
2767 Bind {
2768 key: Key {
2769 trigger: Trigger::Keysym(Keysym::k),
2770 modifiers: Modifiers::COMPOSITOR | Modifiers::SUPER,
2771 },
2772 action: Action::FocusWindowUp,
2773 repeat: true,
2774 cooldown: None,
2775 allow_when_locked: false,
2776 },
2777 Bind {
2778 key: Key {
2779 trigger: Trigger::Keysym(Keysym::l),
2780 modifiers: Modifiers::SUPER | Modifiers::ALT,
2781 },
2782 action: Action::FocusColumnRight,
2783 repeat: true,
2784 cooldown: None,
2785 allow_when_locked: false,
2786 },
2787 ]);
2788
2789 assert_eq!(
2790 find_configured_bind(
2791 &bindings,
2792 CompositorMod::Super,
2793 Trigger::Keysym(Keysym::q),
2794 ModifiersState {
2795 logo: true,
2796 ..Default::default()
2797 }
2798 )
2799 .as_ref(),
2800 Some(&bindings.0[0])
2801 );
2802 assert_eq!(
2803 find_configured_bind(
2804 &bindings,
2805 CompositorMod::Super,
2806 Trigger::Keysym(Keysym::q),
2807 ModifiersState::default(),
2808 ),
2809 None,
2810 );
2811
2812 assert_eq!(
2813 find_configured_bind(
2814 &bindings,
2815 CompositorMod::Super,
2816 Trigger::Keysym(Keysym::h),
2817 ModifiersState {
2818 logo: true,
2819 ..Default::default()
2820 }
2821 )
2822 .as_ref(),
2823 Some(&bindings.0[1])
2824 );
2825 assert_eq!(
2826 find_configured_bind(
2827 &bindings,
2828 CompositorMod::Super,
2829 Trigger::Keysym(Keysym::h),
2830 ModifiersState::default(),
2831 ),
2832 None,
2833 );
2834
2835 assert_eq!(
2836 find_configured_bind(
2837 &bindings,
2838 CompositorMod::Super,
2839 Trigger::Keysym(Keysym::j),
2840 ModifiersState {
2841 logo: true,
2842 ..Default::default()
2843 }
2844 ),
2845 None,
2846 );
2847 assert_eq!(
2848 find_configured_bind(
2849 &bindings,
2850 CompositorMod::Super,
2851 Trigger::Keysym(Keysym::j),
2852 ModifiersState::default(),
2853 )
2854 .as_ref(),
2855 Some(&bindings.0[2])
2856 );
2857
2858 assert_eq!(
2859 find_configured_bind(
2860 &bindings,
2861 CompositorMod::Super,
2862 Trigger::Keysym(Keysym::k),
2863 ModifiersState {
2864 logo: true,
2865 ..Default::default()
2866 }
2867 )
2868 .as_ref(),
2869 Some(&bindings.0[3])
2870 );
2871 assert_eq!(
2872 find_configured_bind(
2873 &bindings,
2874 CompositorMod::Super,
2875 Trigger::Keysym(Keysym::k),
2876 ModifiersState::default(),
2877 ),
2878 None,
2879 );
2880
2881 assert_eq!(
2882 find_configured_bind(
2883 &bindings,
2884 CompositorMod::Super,
2885 Trigger::Keysym(Keysym::l),
2886 ModifiersState {
2887 logo: true,
2888 alt: true,
2889 ..Default::default()
2890 }
2891 )
2892 .as_ref(),
2893 Some(&bindings.0[4])
2894 );
2895 assert_eq!(
2896 find_configured_bind(
2897 &bindings,
2898 CompositorMod::Super,
2899 Trigger::Keysym(Keysym::l),
2900 ModifiersState {
2901 logo: true,
2902 ..Default::default()
2903 },
2904 ),
2905 None,
2906 );
2907 }
2908}