overview: Add hardcoded mouse scroll binds
Browse files at this commitbd3d55438993a898f94500bea194377fb93004f3Parent: af1fca32 changed files +182 -15
- niri-config/src/lib.rs +8 -0
- src/input/mod.rs +174 -15
niri-config/src/lib.rsmodified+8 -0
| @@ -1579,7 +1579,11 @@ pub enum Action { | |||
| 1579 | FocusWindowInColumn(#[knuffel(argument)] u8), | 1579 | FocusWindowInColumn(#[knuffel(argument)] u8), |
| 1580 | FocusWindowPrevious, | 1580 | FocusWindowPrevious, |
| 1581 | FocusColumnLeft, | 1581 | FocusColumnLeft, |
| 1582 | + #[knuffel(skip)] | ||
| 1583 | + FocusColumnLeftUnderMouse, | ||
| 1582 | FocusColumnRight, | 1584 | FocusColumnRight, |
| 1585 | + #[knuffel(skip)] | ||
| 1586 | + FocusColumnRightUnderMouse, | ||
| 1583 | FocusColumnFirst, | 1587 | FocusColumnFirst, |
| 1584 | FocusColumnLast, | 1588 | FocusColumnLast, |
| 1585 | FocusColumnRightOrFirst, | 1589 | FocusColumnRightOrFirst, |
| @@ -1629,7 +1633,11 @@ pub enum Action { | |||
| 1629 | #[knuffel(skip)] | 1633 | #[knuffel(skip)] |
| 1630 | CenterWindowById(u64), | 1634 | CenterWindowById(u64), |
| 1631 | FocusWorkspaceDown, | 1635 | FocusWorkspaceDown, |
| 1636 | + #[knuffel(skip)] | ||
| 1637 | + FocusWorkspaceDownUnderMouse, | ||
| 1632 | FocusWorkspaceUp, | 1638 | FocusWorkspaceUp, |
| 1639 | + #[knuffel(skip)] | ||
| 1640 | + FocusWorkspaceUpUnderMouse, | ||
| 1633 | FocusWorkspace(#[knuffel(argument)] WorkspaceReference), | 1641 | FocusWorkspace(#[knuffel(argument)] WorkspaceReference), |
| 1634 | FocusWorkspacePrevious, | 1642 | FocusWorkspacePrevious, |
| 1635 | MoveWindowToWorkspaceDown, | 1643 | MoveWindowToWorkspaceDown, |
src/input/mod.rsmodified+174 -15
| @@ -895,6 +895,19 @@ impl State { | |||
| 895 | // FIXME: granular | 895 | // FIXME: granular |
| 896 | self.niri.queue_redraw_all(); | 896 | self.niri.queue_redraw_all(); |
| 897 | } | 897 | } |
| 898 | + Action::FocusColumnLeftUnderMouse => { | ||
| 899 | + if let Some((output, ws)) = self.niri.workspace_under_cursor(true) { | ||
| 900 | + let ws_id = ws.id(); | ||
| 901 | + let ws = { | ||
| 902 | + let mut workspaces = self.niri.layout.workspaces_mut(); | ||
| 903 | + workspaces.find(|ws| ws.id() == ws_id).unwrap() | ||
| 904 | + }; | ||
| 905 | + ws.focus_left(); | ||
| 906 | + self.maybe_warp_cursor_to_focus(); | ||
| 907 | + self.niri.layer_shell_on_demand_focus = None; | ||
| 908 | + self.niri.queue_redraw(&output); | ||
| 909 | + } | ||
| 910 | + } | ||
| 898 | Action::FocusColumnRight => { | 911 | Action::FocusColumnRight => { |
| 899 | self.niri.layout.focus_right(); | 912 | self.niri.layout.focus_right(); |
| 900 | self.maybe_warp_cursor_to_focus(); | 913 | self.maybe_warp_cursor_to_focus(); |
| @@ -902,6 +915,19 @@ impl State { | |||
| 902 | // FIXME: granular | 915 | // FIXME: granular |
| 903 | self.niri.queue_redraw_all(); | 916 | self.niri.queue_redraw_all(); |
| 904 | } | 917 | } |
| 918 | + Action::FocusColumnRightUnderMouse => { | ||
| 919 | + if let Some((output, ws)) = self.niri.workspace_under_cursor(true) { | ||
| 920 | + let ws_id = ws.id(); | ||
| 921 | + let ws = { | ||
| 922 | + let mut workspaces = self.niri.layout.workspaces_mut(); | ||
| 923 | + workspaces.find(|ws| ws.id() == ws_id).unwrap() | ||
| 924 | + }; | ||
| 925 | + ws.focus_right(); | ||
| 926 | + self.maybe_warp_cursor_to_focus(); | ||
| 927 | + self.niri.layer_shell_on_demand_focus = None; | ||
| 928 | + self.niri.queue_redraw(&output); | ||
| 929 | + } | ||
| 930 | + } | ||
| 905 | Action::FocusColumnFirst => { | 931 | Action::FocusColumnFirst => { |
| 906 | self.niri.layout.focus_column_first(); | 932 | self.niri.layout.focus_column_first(); |
| 907 | self.maybe_warp_cursor_to_focus(); | 933 | self.maybe_warp_cursor_to_focus(); |
| @@ -1252,6 +1278,16 @@ impl State { | |||
| 1252 | // FIXME: granular | 1278 | // FIXME: granular |
| 1253 | self.niri.queue_redraw_all(); | 1279 | self.niri.queue_redraw_all(); |
| 1254 | } | 1280 | } |
| 1281 | + Action::FocusWorkspaceDownUnderMouse => { | ||
| 1282 | + if let Some(output) = self.niri.output_under_cursor() { | ||
| 1283 | + if let Some(mon) = self.niri.layout.monitor_for_output_mut(&output) { | ||
| 1284 | + mon.switch_workspace_down(); | ||
| 1285 | + self.maybe_warp_cursor_to_focus(); | ||
| 1286 | + self.niri.layer_shell_on_demand_focus = None; | ||
| 1287 | + self.niri.queue_redraw(&output); | ||
| 1288 | + } | ||
| 1289 | + } | ||
| 1290 | + } | ||
| 1255 | Action::FocusWorkspaceUp => { | 1291 | Action::FocusWorkspaceUp => { |
| 1256 | self.niri.layout.switch_workspace_up(); | 1292 | self.niri.layout.switch_workspace_up(); |
| 1257 | self.maybe_warp_cursor_to_focus(); | 1293 | self.maybe_warp_cursor_to_focus(); |
| @@ -1259,6 +1295,16 @@ impl State { | |||
| 1259 | // FIXME: granular | 1295 | // FIXME: granular |
| 1260 | self.niri.queue_redraw_all(); | 1296 | self.niri.queue_redraw_all(); |
| 1261 | } | 1297 | } |
| 1298 | + Action::FocusWorkspaceUpUnderMouse => { | ||
| 1299 | + if let Some(output) = self.niri.output_under_cursor() { | ||
| 1300 | + if let Some(mon) = self.niri.layout.monitor_for_output_mut(&output) { | ||
| 1301 | + mon.switch_workspace_up(); | ||
| 1302 | + self.maybe_warp_cursor_to_focus(); | ||
| 1303 | + self.niri.layer_shell_on_demand_focus = None; | ||
| 1304 | + self.niri.queue_redraw(&output); | ||
| 1305 | + } | ||
| 1306 | + } | ||
| 1307 | + } | ||
| 1262 | Action::FocusWorkspace(reference) => { | 1308 | Action::FocusWorkspace(reference) => { |
| 1263 | if let Some((mut output, index)) = | 1309 | if let Some((mut output, index)) = |
| 1264 | self.niri.find_output_and_workspace_index(reference) | 1310 | self.niri.find_output_and_workspace_index(reference) |
| @@ -2525,23 +2571,81 @@ impl State { | |||
| 2525 | let horizontal_amount_v120 = event.amount_v120(Axis::Horizontal); | 2571 | let horizontal_amount_v120 = event.amount_v120(Axis::Horizontal); |
| 2526 | let vertical_amount_v120 = event.amount_v120(Axis::Vertical); | 2572 | let vertical_amount_v120 = event.amount_v120(Axis::Vertical); |
| 2527 | 2573 | ||
| 2574 | + let is_overview_open = self.niri.layout.is_overview_open(); | ||
| 2575 | + | ||
| 2576 | + // We should only handle scrolling in the overview if the pointer is not over a (top or | ||
| 2577 | + // overlay) layer surface. | ||
| 2578 | + let should_handle_in_overview = if is_overview_open { | ||
| 2579 | + // FIXME: ideally this should happen after updating the pointer contents, which happens | ||
| 2580 | + // below. However, our pointer actions are supposed to act on the old surface, before | ||
| 2581 | + // updating the pointer contents. | ||
| 2582 | + pointer | ||
| 2583 | + .current_focus() | ||
| 2584 | + .map(|surface| self.niri.find_root_shell_surface(&surface)) | ||
| 2585 | + .map_or(true, |root| { | ||
| 2586 | + !self | ||
| 2587 | + .niri | ||
| 2588 | + .mapped_layer_surfaces | ||
| 2589 | + .keys() | ||
| 2590 | + .any(|layer| *layer.wl_surface() == root) | ||
| 2591 | + }) | ||
| 2592 | + } else { | ||
| 2593 | + false | ||
| 2594 | + }; | ||
| 2595 | + | ||
| 2528 | // Handle wheel scroll bindings. | 2596 | // Handle wheel scroll bindings. |
| 2529 | if source == AxisSource::Wheel { | 2597 | if source == AxisSource::Wheel { |
| 2530 | // If we have a scroll bind with current modifiers, then accumulate and don't pass to | 2598 | // If we have a scroll bind with current modifiers, then accumulate and don't pass to |
| 2531 | // Wayland. If there's no bind, reset the accumulator. | 2599 | // Wayland. If there's no bind, reset the accumulator. |
| 2532 | let mods = self.niri.seat.get_keyboard().unwrap().modifier_state(); | 2600 | let mods = self.niri.seat.get_keyboard().unwrap().modifier_state(); |
| 2533 | let modifiers = modifiers_from_state(mods); | 2601 | let modifiers = modifiers_from_state(mods); |
| 2534 | - if self.niri.mods_with_wheel_binds.contains(&modifiers) { | 2602 | + let should_handle = |
| 2603 | + should_handle_in_overview || self.niri.mods_with_wheel_binds.contains(&modifiers); | ||
| 2604 | + if should_handle { | ||
| 2535 | let horizontal = horizontal_amount_v120.unwrap_or(0.); | 2605 | let horizontal = horizontal_amount_v120.unwrap_or(0.); |
| 2536 | let ticks = self.niri.horizontal_wheel_tracker.accumulate(horizontal); | 2606 | let ticks = self.niri.horizontal_wheel_tracker.accumulate(horizontal); |
| 2537 | if ticks != 0 { | 2607 | if ticks != 0 { |
| 2538 | - let config = self.niri.config.borrow(); | 2608 | + let (bind_left, bind_right) = if should_handle_in_overview |
| 2539 | - let bindings = &config.binds; | 2609 | + && modifiers.is_empty() |
| 2540 | - let bind_left = | 2610 | + { |
| 2541 | - find_configured_bind(bindings, mod_key, Trigger::WheelScrollLeft, mods); | 2611 | + let bind_left = Some(Bind { |
| 2542 | - let bind_right = | 2612 | + key: Key { |
| 2543 | - find_configured_bind(bindings, mod_key, Trigger::WheelScrollRight, mods); | 2613 | + trigger: Trigger::WheelScrollLeft, |
| 2544 | - drop(config); | 2614 | + modifiers: Modifiers::empty(), |
| 2615 | + }, | ||
| 2616 | + action: Action::FocusColumnLeftUnderMouse, | ||
| 2617 | + repeat: true, | ||
| 2618 | + cooldown: None, | ||
| 2619 | + allow_when_locked: false, | ||
| 2620 | + allow_inhibiting: false, | ||
| 2621 | + hotkey_overlay_title: None, | ||
| 2622 | + }); | ||
| 2623 | + let bind_right = Some(Bind { | ||
| 2624 | + key: Key { | ||
| 2625 | + trigger: Trigger::WheelScrollRight, | ||
| 2626 | + modifiers: Modifiers::empty(), | ||
| 2627 | + }, | ||
| 2628 | + action: Action::FocusColumnRightUnderMouse, | ||
| 2629 | + repeat: true, | ||
| 2630 | + cooldown: None, | ||
| 2631 | + allow_when_locked: false, | ||
| 2632 | + allow_inhibiting: false, | ||
| 2633 | + hotkey_overlay_title: None, | ||
| 2634 | + }); | ||
| 2635 | + (bind_left, bind_right) | ||
| 2636 | + } else { | ||
| 2637 | + let config = self.niri.config.borrow(); | ||
| 2638 | + let bindings = &config.binds; | ||
| 2639 | + let bind_left = | ||
| 2640 | + find_configured_bind(bindings, mod_key, Trigger::WheelScrollLeft, mods); | ||
| 2641 | + let bind_right = find_configured_bind( | ||
| 2642 | + bindings, | ||
| 2643 | + mod_key, | ||
| 2644 | + Trigger::WheelScrollRight, | ||
| 2645 | + mods, | ||
| 2646 | + ); | ||
| 2647 | + (bind_left, bind_right) | ||
| 2648 | + }; | ||
| 2545 | 2649 | ||
| 2546 | if let Some(right) = bind_right { | 2650 | if let Some(right) = bind_right { |
| 2547 | for _ in 0..ticks { | 2651 | for _ in 0..ticks { |
| @@ -2558,13 +2662,68 @@ impl State { | |||
| 2558 | let vertical = vertical_amount_v120.unwrap_or(0.); | 2662 | let vertical = vertical_amount_v120.unwrap_or(0.); |
| 2559 | let ticks = self.niri.vertical_wheel_tracker.accumulate(vertical); | 2663 | let ticks = self.niri.vertical_wheel_tracker.accumulate(vertical); |
| 2560 | if ticks != 0 { | 2664 | if ticks != 0 { |
| 2561 | - let config = self.niri.config.borrow(); | 2665 | + let (bind_up, bind_down) = if should_handle_in_overview && modifiers.is_empty() |
| 2562 | - let bindings = &config.binds; | 2666 | + { |
| 2563 | - let bind_up = | 2667 | + let bind_up = Some(Bind { |
| 2564 | - find_configured_bind(bindings, mod_key, Trigger::WheelScrollUp, mods); | 2668 | + key: Key { |
| 2565 | - let bind_down = | 2669 | + trigger: Trigger::WheelScrollUp, |
| 2566 | - find_configured_bind(bindings, mod_key, Trigger::WheelScrollDown, mods); | 2670 | + modifiers: Modifiers::empty(), |
| 2567 | - drop(config); | 2671 | + }, |
| 2672 | + action: Action::FocusWorkspaceUpUnderMouse, | ||
| 2673 | + repeat: true, | ||
| 2674 | + cooldown: Some(Duration::from_millis(50)), | ||
| 2675 | + allow_when_locked: false, | ||
| 2676 | + allow_inhibiting: false, | ||
| 2677 | + hotkey_overlay_title: None, | ||
| 2678 | + }); | ||
| 2679 | + let bind_down = Some(Bind { | ||
| 2680 | + key: Key { | ||
| 2681 | + trigger: Trigger::WheelScrollDown, | ||
| 2682 | + modifiers: Modifiers::empty(), | ||
| 2683 | + }, | ||
| 2684 | + action: Action::FocusWorkspaceDownUnderMouse, | ||
| 2685 | + repeat: true, | ||
| 2686 | + cooldown: Some(Duration::from_millis(50)), | ||
| 2687 | + allow_when_locked: false, | ||
| 2688 | + allow_inhibiting: false, | ||
| 2689 | + hotkey_overlay_title: None, | ||
| 2690 | + }); | ||
| 2691 | + (bind_up, bind_down) | ||
| 2692 | + } else if should_handle_in_overview && modifiers == Modifiers::SHIFT { | ||
| 2693 | + let bind_up = Some(Bind { | ||
| 2694 | + key: Key { | ||
| 2695 | + trigger: Trigger::WheelScrollUp, | ||
| 2696 | + modifiers: Modifiers::empty(), | ||
| 2697 | + }, | ||
| 2698 | + action: Action::FocusColumnLeftUnderMouse, | ||
| 2699 | + repeat: true, | ||
| 2700 | + cooldown: Some(Duration::from_millis(50)), | ||
| 2701 | + allow_when_locked: false, | ||
| 2702 | + allow_inhibiting: false, | ||
| 2703 | + hotkey_overlay_title: None, | ||
| 2704 | + }); | ||
| 2705 | + let bind_down = Some(Bind { | ||
| 2706 | + key: Key { | ||
| 2707 | + trigger: Trigger::WheelScrollDown, | ||
| 2708 | + modifiers: Modifiers::empty(), | ||
| 2709 | + }, | ||
| 2710 | + action: Action::FocusColumnRightUnderMouse, | ||
| 2711 | + repeat: true, | ||
| 2712 | + cooldown: Some(Duration::from_millis(50)), | ||
| 2713 | + allow_when_locked: false, | ||
| 2714 | + allow_inhibiting: false, | ||
| 2715 | + hotkey_overlay_title: None, | ||
| 2716 | + }); | ||
| 2717 | + (bind_up, bind_down) | ||
| 2718 | + } else { | ||
| 2719 | + let config = self.niri.config.borrow(); | ||
| 2720 | + let bindings = &config.binds; | ||
| 2721 | + let bind_up = | ||
| 2722 | + find_configured_bind(bindings, mod_key, Trigger::WheelScrollUp, mods); | ||
| 2723 | + let bind_down = | ||
| 2724 | + find_configured_bind(bindings, mod_key, Trigger::WheelScrollDown, mods); | ||
| 2725 | + (bind_up, bind_down) | ||
| 2726 | + }; | ||
| 2568 | 2727 | ||
| 2569 | if let Some(down) = bind_down { | 2728 | if let Some(down) = bind_down { |
| 2570 | for _ in 0..ticks { | 2729 | for _ in 0..ticks { |