forge
Explore
Log in

Don't you dare go Hollow

Propagate the InputTime to do_action.

Browse files at this commit

ce83bb8636ddd4f7092d2e7204456a675a2abbd8andriyDevParent: fb706d6
src/backend/tty.rsmodified+2 -1
@@ -28,6 +28,7 @@ use smithay::backend::drm::{
2828 };
2929 use smithay::backend::egl::context::ContextPriority;
3030 use smithay::backend::egl::{EGLDevice, EGLDisplay};
31+use smithay::backend::input::InputTime;
3132 use smithay::backend::libinput::{LibinputInputBackend, LibinputSessionInterface};
3233 use smithay::backend::renderer::gles::GlesRenderer;
3334 use smithay::backend::renderer::multigpu::gbm::GbmGlesBackend;
@@ -624,7 +625,7 @@ impl Tty {
624625 // Slightly cursed to do from an idle... But we don't have State here conveniently,
625626 // and it should be fine to delay this until the loop callback.
626627 niri.event_loop
627- .insert_idle(|state| state.release_held_inputs());
628+ .insert_idle(|state| state.release_held_inputs(InputTime::now()));
628629
629630 self.libinput.suspend();
630631
src/backend/winit.rsmodified+2 -1
@@ -9,6 +9,7 @@ use niri_config::{Config, OutputName};
99 use smithay::backend::allocator::dmabuf::Dmabuf;
1010 use smithay::backend::drm::DrmNode;
1111 use smithay::backend::egl::EGLDevice;
12+use smithay::backend::input::InputTime;
1213 use smithay::backend::renderer::damage::OutputDamageTracker;
1314 use smithay::backend::renderer::gles::GlesRenderer;
1415 use smithay::backend::renderer::{DebugFlags, ImportDma, ImportEgl, Renderer};
@@ -155,7 +156,7 @@ impl Winit {
155156 WinitEvent::Input(event) => state.process_input_event(event),
156157 WinitEvent::Focus(false) => {
157158 // Lost focus. Reset key pressed (like alt or windows key)
158- state.release_held_inputs();
159+ state.release_held_inputs(InputTime::now());
159160
160161 if let Some(keyboard) = state.niri.seat.get_keyboard() {
161162 keyboard.release_source(state, KeyboardSource::MAIN);
src/input/mod.rsmodified+28 -25
@@ -14,7 +14,7 @@ use niri_ipc::LayoutSwitchTarget;
1414 use smithay::backend::input::{
1515 AbsolutePositionEvent, Axis, AxisSource, ButtonState, Device, DeviceCapability, Event,
1616 GestureBeginEvent, GestureEndEvent, GesturePinchUpdateEvent as _, GestureSwipeUpdateEvent as _,
17- InputEvent, KeyState, KeyboardKeyEvent, Keycode, MouseButton, PointerAxisEvent,
17+ InputEvent, InputTime, KeyState, KeyboardKeyEvent, Keycode, MouseButton, PointerAxisEvent,
1818 PointerButtonEvent, PointerMotionEvent, ProximityState, Switch, SwitchState, SwitchToggleEvent,
1919 TabletToolButtonEvent, TabletToolEvent, TabletToolProximityEvent, TabletToolTipEvent,
2020 TabletToolTipState, TouchEvent,
@@ -501,7 +501,7 @@ impl State {
501501 if !pressed {
502502 if let Some(bind) = self.niri.pending_release_binds.remove(&event.key_code()) {
503503 self.niri.suppressed_keys.remove(&event.key_code());
504- self.handle_bind(bind, false);
504+ self.handle_bind(bind, false, time);
505505 }
506506 }
507507 return;
@@ -651,7 +651,7 @@ impl State {
651651 // Check if all modifiers were released while the MRU UI was open. If so, close the
652652 // UI (which will also transfer the focus to the current MRU UI selection).
653653 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);
655655
656656 // A pending release action recorded for the key must still run if it
657657 // closed the MRU instead of going through the regular bind lookup.
@@ -754,7 +754,7 @@ impl State {
754754 if pressed && bind.repeat {
755755 self.start_key_repeat(bind.clone());
756756 }
757- self.handle_bind(bind, pressed);
757+ self.handle_bind(bind, pressed, time);
758758 }
759759 ShouldInterceptResult::Forward | ShouldInterceptResult::InterceptOnly => {}
760760 }
@@ -786,7 +786,10 @@ impl State {
786786 .niri
787787 .event_loop
788788 .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);
790793 TimeoutAction::ToDuration(repeat_duration)
791794 })
792795 .unwrap();
@@ -816,7 +819,7 @@ impl State {
816819 self.niri.queue_redraw_all();
817820 }
818821
819- pub fn handle_bind(&mut self, bind: Bind, pressed: bool) {
822+ pub fn handle_bind(&mut self, bind: Bind, pressed: bool, time: InputTime) {
820823 let allowed_when_locked = bind_allowed_when_locked(&bind, pressed);
821824 let allowed_during_screenshot = bind_allowed_during_screenshot(&bind, pressed);
822825
@@ -858,11 +861,11 @@ impl State {
858861 return;
859862 };
860863
861- self.do_action(action, allowed_when_locked);
864+ self.do_action(action, allowed_when_locked, time);
862865 }
863866
864867 /// 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) {
866869 let mut binds = Vec::new();
867870 binds.extend(
868871 self.niri
@@ -887,11 +890,11 @@ impl State {
887890 self.niri.clear_input_state();
888891
889892 for bind in binds {
890- self.handle_bind(bind, false);
893+ self.handle_bind(bind, false, time);
891894 }
892895 }
893896
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) {
895898 if self.niri.is_locked() && !(allow_when_locked || allowed_when_locked(&action)) {
896899 return;
897900 }
@@ -913,14 +916,14 @@ impl State {
913916 Action::ChangeVt(vt) => {
914917 // Changing VT may not deliver the key releases, so treat the held binds as
915918 // released while the session is still usable.
916- self.release_held_inputs();
919+ self.release_held_inputs(time);
917920
918921 self.backend.change_vt(vt as i32);
919922 }
920923 Action::Suspend => {
921924 // Suspend may not deliver the key releases, so treat the held binds as
922925 // released before suspending.
923- self.release_held_inputs();
926+ self.release_held_inputs(time);
924927
925928 self.backend.suspend();
926929 }
@@ -3110,7 +3113,7 @@ impl State {
31103113 if ButtonState::Released == button_state {
31113114 if let Some(bind) = self.niri.pending_mouse_release_binds.remove(&button_code) {
31123115 self.niri.suppressed_buttons.remove(&button_code);
3113- self.handle_bind(bind, false);
3116+ self.handle_bind(bind, false, event.time());
31143117 return;
31153118 }
31163119 }
@@ -3169,7 +3172,7 @@ impl State {
31693172 .insert(button_code, bind.clone());
31703173 }
31713174 if bind.has_press() {
3172- self.handle_bind(bind.clone(), true);
3175+ self.handle_bind(bind.clone(), true, event.time());
31733176 }
31743177 return;
31753178 }
@@ -3532,12 +3535,12 @@ impl State {
35323535
35333536 if let Some(right) = bind_right {
35343537 for _ in 0..ticks {
3535- self.handle_bind(right.clone(), true);
3538+ self.handle_bind(right.clone(), true, event.time());
35363539 }
35373540 }
35383541 if let Some(left) = bind_left {
35393542 for _ in ticks..0 {
3540- self.handle_bind(left.clone(), true);
3543+ self.handle_bind(left.clone(), true, event.time());
35413544 }
35423545 }
35433546 }
@@ -3622,12 +3625,12 @@ impl State {
36223625
36233626 if let Some(down) = bind_down {
36243627 for _ in 0..ticks {
3625- self.handle_bind(down.clone(), true);
3628+ self.handle_bind(down.clone(), true, event.time());
36263629 }
36273630 }
36283631 if let Some(up) = bind_up {
36293632 for _ in ticks..0 {
3630- self.handle_bind(up.clone(), true);
3633+ self.handle_bind(up.clone(), true, event.time());
36313634 }
36323635 }
36333636 }
@@ -3757,12 +3760,12 @@ impl State {
37573760
37583761 if let Some(right) = bind_right {
37593762 for _ in 0..ticks {
3760- self.handle_bind(right.clone(), true);
3763+ self.handle_bind(right.clone(), true, event.time());
37613764 }
37623765 }
37633766 if let Some(left) = bind_left {
37643767 for _ in ticks..0 {
3765- self.handle_bind(left.clone(), true);
3768+ self.handle_bind(left.clone(), true, event.time());
37663769 }
37673770 }
37683771 }
@@ -3779,12 +3782,12 @@ impl State {
37793782
37803783 if let Some(down) = bind_down {
37813784 for _ in 0..ticks {
3782- self.handle_bind(down.clone(), true);
3785+ self.handle_bind(down.clone(), true, event.time());
37833786 }
37843787 }
37853788 if let Some(up) = bind_up {
37863789 for _ in ticks..0 {
3787- self.handle_bind(up.clone(), true);
3790+ self.handle_bind(up.clone(), true, event.time());
37883791 }
37893792 }
37903793 }
@@ -4193,7 +4196,7 @@ impl State {
41934196 if button_state == ButtonState::Released {
41944197 if let Some(bind) = self.niri.pending_tablet_release_binds.remove(&button) {
41954198 self.niri.suppressed_buttons.remove(&button);
4196- self.handle_bind(bind, false);
4199+ self.handle_bind(bind, false, event.time());
41974200 return;
41984201 }
41994202 }
@@ -4226,7 +4229,7 @@ impl State {
42264229 .insert(button, bind.clone());
42274230 }
42284231 if bind.has_press() {
4229- self.handle_bind(bind.clone(), true);
4232+ self.handle_bind(bind.clone(), true, event.time());
42304233 }
42314234 return;
42324235 }
@@ -4818,7 +4821,7 @@ impl State {
48184821 };
48194822
48204823 if let Some(action) = action {
4821- self.do_action(action, true);
4824+ self.do_action(action, true, evt.time());
48224825 }
48234826 }
48244827
src/ipc/server.rsmodified+4 -1
@@ -20,6 +20,7 @@ use niri_ipc::{
2020 Action, Event, KeyboardLayouts, OutputConfigChanged, Overview, Reply, Request, Response,
2121 Timestamp, WindowLayout, Workspace,
2222 };
23+use smithay::backend::input::InputTime;
2324 use smithay::desktop::layer_map_for_output;
2425 use smithay::input::pointer::{
2526 CursorIcon, CursorImageStatus, Focus, GrabStartData as PointerGrabStartData,
@@ -389,7 +390,9 @@ async fn process(ctx: &ClientCtx, request: Request) -> Reply {
389390 // Make sure some logic like workspace clean-up has a chance to run before doing
390391 // actions.
391392 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);
393396 let _ = tx.send_blocking(());
394397 });
395398
src/tests/binds.rsmodified+2 -1
@@ -2332,7 +2332,8 @@ fn vt_switch_runs_release_actions_of_held_binds() {
23322332 assert_eq!(f.niri().test_action_count, 2);
23332333
23342334 // 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());
23362337 assert_eq!(f.niri().test_action_count, 4);
23372338
23382339 // If the releases arrive anyway, they run nothing.