diff --git a/src/backend/tty.rs b/src/backend/tty.rs index 3629a15f..6126dc2c 100644 --- a/src/backend/tty.rs +++ b/src/backend/tty.rs @@ -28,6 +28,7 @@ use smithay::backend::drm::{ }; use smithay::backend::egl::context::ContextPriority; use smithay::backend::egl::{EGLDevice, EGLDisplay}; +use smithay::backend::input::InputTime; use smithay::backend::libinput::{LibinputInputBackend, LibinputSessionInterface}; use smithay::backend::renderer::gles::GlesRenderer; use smithay::backend::renderer::multigpu::gbm::GbmGlesBackend; @@ -624,7 +625,7 @@ impl Tty { // Slightly cursed to do from an idle... But we don't have State here conveniently, // and it should be fine to delay this until the loop callback. niri.event_loop - .insert_idle(|state| state.release_held_inputs()); + .insert_idle(|state| state.release_held_inputs(InputTime::now())); self.libinput.suspend(); diff --git a/src/backend/winit.rs b/src/backend/winit.rs index 4e6127c0..9ce07603 100644 --- a/src/backend/winit.rs +++ b/src/backend/winit.rs @@ -9,6 +9,7 @@ use niri_config::{Config, OutputName}; use smithay::backend::allocator::dmabuf::Dmabuf; use smithay::backend::drm::DrmNode; use smithay::backend::egl::EGLDevice; +use smithay::backend::input::InputTime; use smithay::backend::renderer::damage::OutputDamageTracker; use smithay::backend::renderer::gles::GlesRenderer; use smithay::backend::renderer::{DebugFlags, ImportDma, ImportEgl, Renderer}; @@ -155,7 +156,7 @@ impl Winit { WinitEvent::Input(event) => state.process_input_event(event), WinitEvent::Focus(false) => { // Lost focus. Reset key pressed (like alt or windows key) - state.release_held_inputs(); + state.release_held_inputs(InputTime::now()); if let Some(keyboard) = state.niri.seat.get_keyboard() { keyboard.release_source(state, KeyboardSource::MAIN); diff --git a/src/input/mod.rs b/src/input/mod.rs index 069a9f5d..584b441a 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -14,7 +14,7 @@ use niri_ipc::LayoutSwitchTarget; use smithay::backend::input::{ AbsolutePositionEvent, Axis, AxisSource, ButtonState, Device, DeviceCapability, Event, GestureBeginEvent, GestureEndEvent, GesturePinchUpdateEvent as _, GestureSwipeUpdateEvent as _, - InputEvent, KeyState, KeyboardKeyEvent, Keycode, MouseButton, PointerAxisEvent, + InputEvent, InputTime, KeyState, KeyboardKeyEvent, Keycode, MouseButton, PointerAxisEvent, PointerButtonEvent, PointerMotionEvent, ProximityState, Switch, SwitchState, SwitchToggleEvent, TabletToolButtonEvent, TabletToolEvent, TabletToolProximityEvent, TabletToolTipEvent, TabletToolTipState, TouchEvent, @@ -501,7 +501,7 @@ impl State { if !pressed { if let Some(bind) = self.niri.pending_release_binds.remove(&event.key_code()) { self.niri.suppressed_keys.remove(&event.key_code()); - self.handle_bind(bind, false); + self.handle_bind(bind, false, time); } } return; @@ -651,7 +651,7 @@ impl State { // Check if all modifiers were released while the MRU UI was open. If so, close the // UI (which will also transfer the focus to the current MRU UI selection). if this.niri.window_mru_ui.is_open() && !pressed && modifiers.is_empty() { - this.do_action(Action::MruConfirm, false); + this.do_action(Action::MruConfirm, false, time); // A pending release action recorded for the key must still run if it // closed the MRU instead of going through the regular bind lookup. @@ -754,7 +754,7 @@ impl State { if pressed && bind.repeat { self.start_key_repeat(bind.clone()); } - self.handle_bind(bind, pressed); + self.handle_bind(bind, pressed, time); } ShouldInterceptResult::Forward | ShouldInterceptResult::InterceptOnly => {} } @@ -786,7 +786,10 @@ impl State { .niri .event_loop .insert_source(repeat_timer, move |_, _, state| { - state.handle_bind(bind.clone(), true); + // We don't get an InputTime from the timer (only an instant). Just use now instead. + // It should be close enough. + let time = InputTime::now(); + state.handle_bind(bind.clone(), true, time); TimeoutAction::ToDuration(repeat_duration) }) .unwrap(); @@ -816,7 +819,7 @@ impl State { self.niri.queue_redraw_all(); } - pub fn handle_bind(&mut self, bind: Bind, pressed: bool) { + pub fn handle_bind(&mut self, bind: Bind, pressed: bool, time: InputTime) { let allowed_when_locked = bind_allowed_when_locked(&bind, pressed); let allowed_during_screenshot = bind_allowed_during_screenshot(&bind, pressed); @@ -858,11 +861,11 @@ impl State { return; }; - self.do_action(action, allowed_when_locked); + self.do_action(action, allowed_when_locked, time); } /// Forgets all held inputs, running the release actions of anything that was still held. - pub fn release_held_inputs(&mut self) { + pub fn release_held_inputs(&mut self, time: InputTime) { let mut binds = Vec::new(); binds.extend( self.niri @@ -887,11 +890,11 @@ impl State { self.niri.clear_input_state(); for bind in binds { - self.handle_bind(bind, false); + self.handle_bind(bind, false, time); } } - pub fn do_action(&mut self, action: Action, allow_when_locked: bool) { + pub fn do_action(&mut self, action: Action, allow_when_locked: bool, time: InputTime) { if self.niri.is_locked() && !(allow_when_locked || allowed_when_locked(&action)) { return; } @@ -913,14 +916,14 @@ impl State { Action::ChangeVt(vt) => { // Changing VT may not deliver the key releases, so treat the held binds as // released while the session is still usable. - self.release_held_inputs(); + self.release_held_inputs(time); self.backend.change_vt(vt as i32); } Action::Suspend => { // Suspend may not deliver the key releases, so treat the held binds as // released before suspending. - self.release_held_inputs(); + self.release_held_inputs(time); self.backend.suspend(); } @@ -3110,7 +3113,7 @@ impl State { if ButtonState::Released == button_state { if let Some(bind) = self.niri.pending_mouse_release_binds.remove(&button_code) { self.niri.suppressed_buttons.remove(&button_code); - self.handle_bind(bind, false); + self.handle_bind(bind, false, event.time()); return; } } @@ -3169,7 +3172,7 @@ impl State { .insert(button_code, bind.clone()); } if bind.has_press() { - self.handle_bind(bind.clone(), true); + self.handle_bind(bind.clone(), true, event.time()); } return; } @@ -3532,12 +3535,12 @@ impl State { if let Some(right) = bind_right { for _ in 0..ticks { - self.handle_bind(right.clone(), true); + self.handle_bind(right.clone(), true, event.time()); } } if let Some(left) = bind_left { for _ in ticks..0 { - self.handle_bind(left.clone(), true); + self.handle_bind(left.clone(), true, event.time()); } } } @@ -3622,12 +3625,12 @@ impl State { if let Some(down) = bind_down { for _ in 0..ticks { - self.handle_bind(down.clone(), true); + self.handle_bind(down.clone(), true, event.time()); } } if let Some(up) = bind_up { for _ in ticks..0 { - self.handle_bind(up.clone(), true); + self.handle_bind(up.clone(), true, event.time()); } } } @@ -3757,12 +3760,12 @@ impl State { if let Some(right) = bind_right { for _ in 0..ticks { - self.handle_bind(right.clone(), true); + self.handle_bind(right.clone(), true, event.time()); } } if let Some(left) = bind_left { for _ in ticks..0 { - self.handle_bind(left.clone(), true); + self.handle_bind(left.clone(), true, event.time()); } } } @@ -3779,12 +3782,12 @@ impl State { if let Some(down) = bind_down { for _ in 0..ticks { - self.handle_bind(down.clone(), true); + self.handle_bind(down.clone(), true, event.time()); } } if let Some(up) = bind_up { for _ in ticks..0 { - self.handle_bind(up.clone(), true); + self.handle_bind(up.clone(), true, event.time()); } } } @@ -4193,7 +4196,7 @@ impl State { if button_state == ButtonState::Released { if let Some(bind) = self.niri.pending_tablet_release_binds.remove(&button) { self.niri.suppressed_buttons.remove(&button); - self.handle_bind(bind, false); + self.handle_bind(bind, false, event.time()); return; } } @@ -4226,7 +4229,7 @@ impl State { .insert(button, bind.clone()); } if bind.has_press() { - self.handle_bind(bind.clone(), true); + self.handle_bind(bind.clone(), true, event.time()); } return; } @@ -4818,7 +4821,7 @@ impl State { }; if let Some(action) = action { - self.do_action(action, true); + self.do_action(action, true, evt.time()); } } diff --git a/src/ipc/server.rs b/src/ipc/server.rs index f2e1ad44..0a9d0ea9 100644 --- a/src/ipc/server.rs +++ b/src/ipc/server.rs @@ -20,6 +20,7 @@ use niri_ipc::{ Action, Event, KeyboardLayouts, OutputConfigChanged, Overview, Reply, Request, Response, Timestamp, WindowLayout, Workspace, }; +use smithay::backend::input::InputTime; use smithay::desktop::layer_map_for_output; use smithay::input::pointer::{ CursorIcon, CursorImageStatus, Focus, GrabStartData as PointerGrabStartData, @@ -389,7 +390,9 @@ async fn process(ctx: &ClientCtx, request: Request) -> Reply { // Make sure some logic like workspace clean-up has a chance to run before doing // actions. state.niri.advance_animations(); - state.do_action(action, false); + // This action didn't come from an input, so just use the current time. + let time = InputTime::now(); + state.do_action(action, false, time); let _ = tx.send_blocking(()); }); diff --git a/src/tests/binds.rs b/src/tests/binds.rs index d77b2af0..0bd595bf 100644 --- a/src/tests/binds.rs +++ b/src/tests/binds.rs @@ -2332,7 +2332,8 @@ fn vt_switch_runs_release_actions_of_held_binds() { assert_eq!(f.niri().test_action_count, 2); // The VT switch runs both release actions. - f.niri_state().do_action(Action::ChangeVt(1), false); + f.niri_state() + .do_action(Action::ChangeVt(1), false, InputTime::now()); assert_eq!(f.niri().test_action_count, 4); // If the releases arrive anyway, they run nothing.