Propagate the InputTime to do_action.
Browse files at this commitce83bb8636ddd4f7092d2e7204456a675a2abbd8Parent: fb706d65 changed files +38 -29
- src/backend/tty.rs +2 -1
- src/backend/winit.rs +2 -1
- src/input/mod.rs +28 -25
- src/ipc/server.rs +4 -1
- src/tests/binds.rs +2 -1
src/backend/tty.rsmodified+2 -1
| @@ -28,6 +28,7 @@ use smithay::backend::drm::{ | ||
| 28 | 28 | }; |
| 29 | 29 | use smithay::backend::egl::context::ContextPriority; |
| 30 | 30 | use smithay::backend::egl::{EGLDevice, EGLDisplay}; |
| 31 | +use smithay::backend::input::InputTime; | |
| 31 | 32 | use smithay::backend::libinput::{LibinputInputBackend, LibinputSessionInterface}; |
| 32 | 33 | use smithay::backend::renderer::gles::GlesRenderer; |
| 33 | 34 | use smithay::backend::renderer::multigpu::gbm::GbmGlesBackend; |
| @@ -624,7 +625,7 @@ impl Tty { | ||
| 624 | 625 | // Slightly cursed to do from an idle... But we don't have State here conveniently, |
| 625 | 626 | // and it should be fine to delay this until the loop callback. |
| 626 | 627 | niri.event_loop |
| 627 | - .insert_idle(|state| state.release_held_inputs()); | |
| 628 | + .insert_idle(|state| state.release_held_inputs(InputTime::now())); | |
| 628 | 629 | |
| 629 | 630 | self.libinput.suspend(); |
| 630 | 631 |
src/backend/winit.rsmodified+2 -1
| @@ -9,6 +9,7 @@ use niri_config::{Config, OutputName}; | ||
| 9 | 9 | use smithay::backend::allocator::dmabuf::Dmabuf; |
| 10 | 10 | use smithay::backend::drm::DrmNode; |
| 11 | 11 | use smithay::backend::egl::EGLDevice; |
| 12 | +use smithay::backend::input::InputTime; | |
| 12 | 13 | use smithay::backend::renderer::damage::OutputDamageTracker; |
| 13 | 14 | use smithay::backend::renderer::gles::GlesRenderer; |
| 14 | 15 | use smithay::backend::renderer::{DebugFlags, ImportDma, ImportEgl, Renderer}; |
| @@ -155,7 +156,7 @@ impl Winit { | ||
| 155 | 156 | WinitEvent::Input(event) => state.process_input_event(event), |
| 156 | 157 | WinitEvent::Focus(false) => { |
| 157 | 158 | // Lost focus. Reset key pressed (like alt or windows key) |
| 158 | - state.release_held_inputs(); | |
| 159 | + state.release_held_inputs(InputTime::now()); | |
| 159 | 160 | |
| 160 | 161 | if let Some(keyboard) = state.niri.seat.get_keyboard() { |
| 161 | 162 | keyboard.release_source(state, KeyboardSource::MAIN); |
src/input/mod.rsmodified+28 -25
| @@ -14,7 +14,7 @@ use niri_ipc::LayoutSwitchTarget; | ||
| 14 | 14 | use smithay::backend::input::{ |
| 15 | 15 | AbsolutePositionEvent, Axis, AxisSource, ButtonState, Device, DeviceCapability, Event, |
| 16 | 16 | GestureBeginEvent, GestureEndEvent, GesturePinchUpdateEvent as _, GestureSwipeUpdateEvent as _, |
| 17 | - InputEvent, KeyState, KeyboardKeyEvent, Keycode, MouseButton, PointerAxisEvent, | |
| 17 | + InputEvent, InputTime, KeyState, KeyboardKeyEvent, Keycode, MouseButton, PointerAxisEvent, | |
| 18 | 18 | PointerButtonEvent, PointerMotionEvent, ProximityState, Switch, SwitchState, SwitchToggleEvent, |
| 19 | 19 | TabletToolButtonEvent, TabletToolEvent, TabletToolProximityEvent, TabletToolTipEvent, |
| 20 | 20 | TabletToolTipState, TouchEvent, |
| @@ -501,7 +501,7 @@ impl State { | ||
| 501 | 501 | if !pressed { |
| 502 | 502 | if let Some(bind) = self.niri.pending_release_binds.remove(&event.key_code()) { |
| 503 | 503 | self.niri.suppressed_keys.remove(&event.key_code()); |
| 504 | - self.handle_bind(bind, false); | |
| 504 | + self.handle_bind(bind, false, time); | |
| 505 | 505 | } |
| 506 | 506 | } |
| 507 | 507 | return; |
| @@ -651,7 +651,7 @@ impl State { | ||
| 651 | 651 | // Check if all modifiers were released while the MRU UI was open. If so, close the |
| 652 | 652 | // UI (which will also transfer the focus to the current MRU UI selection). |
| 653 | 653 | if this.niri.window_mru_ui.is_open() && !pressed && modifiers.is_empty() { |
| 654 | - this.do_action(Action::MruConfirm, false); | |
| 654 | + this.do_action(Action::MruConfirm, false, time); | |
| 655 | 655 | |
| 656 | 656 | // A pending release action recorded for the key must still run if it |
| 657 | 657 | // closed the MRU instead of going through the regular bind lookup. |
| @@ -754,7 +754,7 @@ impl State { | ||
| 754 | 754 | if pressed && bind.repeat { |
| 755 | 755 | self.start_key_repeat(bind.clone()); |
| 756 | 756 | } |
| 757 | - self.handle_bind(bind, pressed); | |
| 757 | + self.handle_bind(bind, pressed, time); | |
| 758 | 758 | } |
| 759 | 759 | ShouldInterceptResult::Forward | ShouldInterceptResult::InterceptOnly => {} |
| 760 | 760 | } |
| @@ -786,7 +786,10 @@ impl State { | ||
| 786 | 786 | .niri |
| 787 | 787 | .event_loop |
| 788 | 788 | .insert_source(repeat_timer, move |_, _, state| { |
| 789 | - state.handle_bind(bind.clone(), true); | |
| 789 | + // We don't get an InputTime from the timer (only an instant). Just use now instead. | |
| 790 | + // It should be close enough. | |
| 791 | + let time = InputTime::now(); | |
| 792 | + state.handle_bind(bind.clone(), true, time); | |
| 790 | 793 | TimeoutAction::ToDuration(repeat_duration) |
| 791 | 794 | }) |
| 792 | 795 | .unwrap(); |
| @@ -816,7 +819,7 @@ impl State { | ||
| 816 | 819 | self.niri.queue_redraw_all(); |
| 817 | 820 | } |
| 818 | 821 | |
| 819 | - pub fn handle_bind(&mut self, bind: Bind, pressed: bool) { | |
| 822 | + pub fn handle_bind(&mut self, bind: Bind, pressed: bool, time: InputTime) { | |
| 820 | 823 | let allowed_when_locked = bind_allowed_when_locked(&bind, pressed); |
| 821 | 824 | let allowed_during_screenshot = bind_allowed_during_screenshot(&bind, pressed); |
| 822 | 825 | |
| @@ -858,11 +861,11 @@ impl State { | ||
| 858 | 861 | return; |
| 859 | 862 | }; |
| 860 | 863 | |
| 861 | - self.do_action(action, allowed_when_locked); | |
| 864 | + self.do_action(action, allowed_when_locked, time); | |
| 862 | 865 | } |
| 863 | 866 | |
| 864 | 867 | /// Forgets all held inputs, running the release actions of anything that was still held. |
| 865 | - pub fn release_held_inputs(&mut self) { | |
| 868 | + pub fn release_held_inputs(&mut self, time: InputTime) { | |
| 866 | 869 | let mut binds = Vec::new(); |
| 867 | 870 | binds.extend( |
| 868 | 871 | self.niri |
| @@ -887,11 +890,11 @@ impl State { | ||
| 887 | 890 | self.niri.clear_input_state(); |
| 888 | 891 | |
| 889 | 892 | for bind in binds { |
| 890 | - self.handle_bind(bind, false); | |
| 893 | + self.handle_bind(bind, false, time); | |
| 891 | 894 | } |
| 892 | 895 | } |
| 893 | 896 | |
| 894 | - pub fn do_action(&mut self, action: Action, allow_when_locked: bool) { | |
| 897 | + pub fn do_action(&mut self, action: Action, allow_when_locked: bool, time: InputTime) { | |
| 895 | 898 | if self.niri.is_locked() && !(allow_when_locked || allowed_when_locked(&action)) { |
| 896 | 899 | return; |
| 897 | 900 | } |
| @@ -913,14 +916,14 @@ impl State { | ||
| 913 | 916 | Action::ChangeVt(vt) => { |
| 914 | 917 | // Changing VT may not deliver the key releases, so treat the held binds as |
| 915 | 918 | // released while the session is still usable. |
| 916 | - self.release_held_inputs(); | |
| 919 | + self.release_held_inputs(time); | |
| 917 | 920 | |
| 918 | 921 | self.backend.change_vt(vt as i32); |
| 919 | 922 | } |
| 920 | 923 | Action::Suspend => { |
| 921 | 924 | // Suspend may not deliver the key releases, so treat the held binds as |
| 922 | 925 | // released before suspending. |
| 923 | - self.release_held_inputs(); | |
| 926 | + self.release_held_inputs(time); | |
| 924 | 927 | |
| 925 | 928 | self.backend.suspend(); |
| 926 | 929 | } |
| @@ -3110,7 +3113,7 @@ impl State { | ||
| 3110 | 3113 | if ButtonState::Released == button_state { |
| 3111 | 3114 | if let Some(bind) = self.niri.pending_mouse_release_binds.remove(&button_code) { |
| 3112 | 3115 | self.niri.suppressed_buttons.remove(&button_code); |
| 3113 | - self.handle_bind(bind, false); | |
| 3116 | + self.handle_bind(bind, false, event.time()); | |
| 3114 | 3117 | return; |
| 3115 | 3118 | } |
| 3116 | 3119 | } |
| @@ -3169,7 +3172,7 @@ impl State { | ||
| 3169 | 3172 | .insert(button_code, bind.clone()); |
| 3170 | 3173 | } |
| 3171 | 3174 | if bind.has_press() { |
| 3172 | - self.handle_bind(bind.clone(), true); | |
| 3175 | + self.handle_bind(bind.clone(), true, event.time()); | |
| 3173 | 3176 | } |
| 3174 | 3177 | return; |
| 3175 | 3178 | } |
| @@ -3532,12 +3535,12 @@ impl State { | ||
| 3532 | 3535 | |
| 3533 | 3536 | if let Some(right) = bind_right { |
| 3534 | 3537 | for _ in 0..ticks { |
| 3535 | - self.handle_bind(right.clone(), true); | |
| 3538 | + self.handle_bind(right.clone(), true, event.time()); | |
| 3536 | 3539 | } |
| 3537 | 3540 | } |
| 3538 | 3541 | if let Some(left) = bind_left { |
| 3539 | 3542 | for _ in ticks..0 { |
| 3540 | - self.handle_bind(left.clone(), true); | |
| 3543 | + self.handle_bind(left.clone(), true, event.time()); | |
| 3541 | 3544 | } |
| 3542 | 3545 | } |
| 3543 | 3546 | } |
| @@ -3622,12 +3625,12 @@ impl State { | ||
| 3622 | 3625 | |
| 3623 | 3626 | if let Some(down) = bind_down { |
| 3624 | 3627 | for _ in 0..ticks { |
| 3625 | - self.handle_bind(down.clone(), true); | |
| 3628 | + self.handle_bind(down.clone(), true, event.time()); | |
| 3626 | 3629 | } |
| 3627 | 3630 | } |
| 3628 | 3631 | if let Some(up) = bind_up { |
| 3629 | 3632 | for _ in ticks..0 { |
| 3630 | - self.handle_bind(up.clone(), true); | |
| 3633 | + self.handle_bind(up.clone(), true, event.time()); | |
| 3631 | 3634 | } |
| 3632 | 3635 | } |
| 3633 | 3636 | } |
| @@ -3757,12 +3760,12 @@ impl State { | ||
| 3757 | 3760 | |
| 3758 | 3761 | if let Some(right) = bind_right { |
| 3759 | 3762 | for _ in 0..ticks { |
| 3760 | - self.handle_bind(right.clone(), true); | |
| 3763 | + self.handle_bind(right.clone(), true, event.time()); | |
| 3761 | 3764 | } |
| 3762 | 3765 | } |
| 3763 | 3766 | if let Some(left) = bind_left { |
| 3764 | 3767 | for _ in ticks..0 { |
| 3765 | - self.handle_bind(left.clone(), true); | |
| 3768 | + self.handle_bind(left.clone(), true, event.time()); | |
| 3766 | 3769 | } |
| 3767 | 3770 | } |
| 3768 | 3771 | } |
| @@ -3779,12 +3782,12 @@ impl State { | ||
| 3779 | 3782 | |
| 3780 | 3783 | if let Some(down) = bind_down { |
| 3781 | 3784 | for _ in 0..ticks { |
| 3782 | - self.handle_bind(down.clone(), true); | |
| 3785 | + self.handle_bind(down.clone(), true, event.time()); | |
| 3783 | 3786 | } |
| 3784 | 3787 | } |
| 3785 | 3788 | if let Some(up) = bind_up { |
| 3786 | 3789 | for _ in ticks..0 { |
| 3787 | - self.handle_bind(up.clone(), true); | |
| 3790 | + self.handle_bind(up.clone(), true, event.time()); | |
| 3788 | 3791 | } |
| 3789 | 3792 | } |
| 3790 | 3793 | } |
| @@ -4193,7 +4196,7 @@ impl State { | ||
| 4193 | 4196 | if button_state == ButtonState::Released { |
| 4194 | 4197 | if let Some(bind) = self.niri.pending_tablet_release_binds.remove(&button) { |
| 4195 | 4198 | self.niri.suppressed_buttons.remove(&button); |
| 4196 | - self.handle_bind(bind, false); | |
| 4199 | + self.handle_bind(bind, false, event.time()); | |
| 4197 | 4200 | return; |
| 4198 | 4201 | } |
| 4199 | 4202 | } |
| @@ -4226,7 +4229,7 @@ impl State { | ||
| 4226 | 4229 | .insert(button, bind.clone()); |
| 4227 | 4230 | } |
| 4228 | 4231 | if bind.has_press() { |
| 4229 | - self.handle_bind(bind.clone(), true); | |
| 4232 | + self.handle_bind(bind.clone(), true, event.time()); | |
| 4230 | 4233 | } |
| 4231 | 4234 | return; |
| 4232 | 4235 | } |
| @@ -4818,7 +4821,7 @@ impl State { | ||
| 4818 | 4821 | }; |
| 4819 | 4822 | |
| 4820 | 4823 | if let Some(action) = action { |
| 4821 | - self.do_action(action, true); | |
| 4824 | + self.do_action(action, true, evt.time()); | |
| 4822 | 4825 | } |
| 4823 | 4826 | } |
| 4824 | 4827 |
src/ipc/server.rsmodified+4 -1
| @@ -20,6 +20,7 @@ use niri_ipc::{ | ||
| 20 | 20 | Action, Event, KeyboardLayouts, OutputConfigChanged, Overview, Reply, Request, Response, |
| 21 | 21 | Timestamp, WindowLayout, Workspace, |
| 22 | 22 | }; |
| 23 | +use smithay::backend::input::InputTime; | |
| 23 | 24 | use smithay::desktop::layer_map_for_output; |
| 24 | 25 | use smithay::input::pointer::{ |
| 25 | 26 | CursorIcon, CursorImageStatus, Focus, GrabStartData as PointerGrabStartData, |
| @@ -389,7 +390,9 @@ async fn process(ctx: &ClientCtx, request: Request) -> Reply { | ||
| 389 | 390 | // Make sure some logic like workspace clean-up has a chance to run before doing |
| 390 | 391 | // actions. |
| 391 | 392 | state.niri.advance_animations(); |
| 392 | - state.do_action(action, false); | |
| 393 | + // This action didn't come from an input, so just use the current time. | |
| 394 | + let time = InputTime::now(); | |
| 395 | + state.do_action(action, false, time); | |
| 393 | 396 | let _ = tx.send_blocking(()); |
| 394 | 397 | }); |
| 395 | 398 |
src/tests/binds.rsmodified+2 -1
| @@ -2332,7 +2332,8 @@ fn vt_switch_runs_release_actions_of_held_binds() { | ||
| 2332 | 2332 | assert_eq!(f.niri().test_action_count, 2); |
| 2333 | 2333 | |
| 2334 | 2334 | // The VT switch runs both release actions. |
| 2335 | - f.niri_state().do_action(Action::ChangeVt(1), false); | |
| 2335 | + f.niri_state() | |
| 2336 | + .do_action(Action::ChangeVt(1), false, InputTime::now()); | |
| 2336 | 2337 | assert_eq!(f.niri().test_action_count, 4); |
| 2337 | 2338 | |
| 2338 | 2339 | // If the releases arrive anyway, they run nothing. |