Skip to content

Add MRU window navigation actions #977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 32 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5db4c37
Add MRU window navigation actions
rustn00b Jan 13, 2025
e3bc967
Rename WindowMRU fields
rustn00b Jan 13, 2025
b1146e3
Improve window close handling during MRU traversal
rustn00b Jan 13, 2025
5677748
Removed dbg! calls
rustn00b Jan 13, 2025
029d215
Merge remote-tracking branch 'upstream/main' into window-mru
rustn00b Jan 14, 2025
84597fd
Hardcode Alt-Tab/Alt-shift-Tab for MRU window nav
rustn00b Jan 16, 2025
ea612c4
Remove `focus-window-mru` actions from config
rustn00b Jan 16, 2025
3ac6a66
Cancel MRU traversal with Alt-Esc
rustn00b Jan 16, 2025
f2e929d
Rephrase some comments
rustn00b Jan 16, 2025
2c69396
Fix Alt-Esc not cancelling window-mru
rustn00b Jan 16, 2025
944a3eb
Merge remote-tracking branch 'upstream/main' into window-mru
rustn00b Jan 16, 2025
80cfd4a
Lock-in focus immediately on user interaction
rustn00b Jan 18, 2025
b4ab021
Merge remote-tracking branch 'upstream/main' into window-mru
rustn00b Jan 18, 2025
74ee34e
Simplify WindowMRU::new
rustn00b Jan 19, 2025
46e6d59
Replace Duration with Instant in WindowMRU timestamp
rustn00b Jan 19, 2025
bef1c0b
Merge remote-tracking branch 'upstream/main' into window-mru
rustn00b Jan 26, 2025
2f96fa5
Address PR comments - partial
rustn00b Jan 27, 2025
b03864f
Simplify early-mru-commit logic
rustn00b Jan 28, 2025
97d582d
Handle PR comments
rustn00b Feb 1, 2025
1d57839
Merge remote-tracking branch 'upstream/main' into window-mru
rustn00b Feb 1, 2025
7a9e0e2
Merge remote-tracking branch 'upstream/main' into window-mru
rustn00b Feb 11, 2025
cf7491d
Add MRU window navigation actions
rustn00b Feb 13, 2025
f525612
Include never focused windows in MRU list
rustn00b Feb 19, 2025
531851d
Remove mru_commit_ms from configurable options
rustn00b Feb 19, 2025
e3cc921
Merge remote-tracking branch 'upstream/main' into HEAD
rustn00b Feb 19, 2025
5bc01b1
Add hotkey_overlay_tile for PRESET_BINDINGS
rustn00b Feb 19, 2025
931b9de
Merge remote-tracking branch 'origin/window-mru' into HEAD
rustn00b Feb 19, 2025
ccc359a
Merge remote-tracking branch 'upstream/main' into window-mru
rustn00b Mar 1, 2025
d3577fc
Merge remote-tracking branch 'upstream/main' into window-mru
rustn00b Mar 23, 2025
89cee2d
Merge remote-tracking branch 'upstream/main' into window-mru
rustn00b Apr 20, 2025
f63dd94
Merge remote-tracking branch 'upstream/main' into window-mru
rustn00b Apr 26, 2025
d9d35a8
Run cargo fmt
rustn00b Apr 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 26 additions & 43 deletions src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::any::Any;
use std::cmp::min;
use std::collections::hash_map::Entry;
use std::collections::HashSet;
use std::sync::atomic::AtomicBool;
use std::time::{Duration, Instant};

use calloop::timer::{TimeoutAction, Timer};
Expand Down Expand Up @@ -129,17 +128,6 @@ impl State {
.is_some_and(|d| d.is_open())
&& should_hide_exit_confirm_dialog(&event);

// If an event was forwarded to the focused window and it still has
// a running lockin_token, cancel the token and update the timestamp
// immediately
if self
.niri
.event_forwarded_to_focused_client
.swap(false, std::sync::atomic::Ordering::Relaxed)
{
self.niri.lockin_focus();
}

use InputEvent::*;
match event {
DeviceAdded { device } => self.on_device_added(device),
Expand Down Expand Up @@ -430,22 +418,29 @@ impl State {
}
}

let bindings = &this.niri.config.borrow().binds;

should_intercept_key(
&mut this.niri.suppressed_keys,
bindings,
comp_mod,
key_code,
modified,
raw,
pressed,
*mods,
&this.niri.screenshot_ui,
this.niri.config.borrow().input.disable_power_key_handling,
is_inhibiting_shortcuts,
&mut this.niri.event_forwarded_to_focused_client,
)
let intercept_result = {
let bindings = &this.niri.config.borrow().binds;
should_intercept_key(
&mut this.niri.suppressed_keys,
bindings,
comp_mod,
key_code,
modified,
raw,
pressed,
*mods,
&this.niri.screenshot_ui,
this.niri.config.borrow().input.disable_power_key_handling,
is_inhibiting_shortcuts,
)
};
if matches!(intercept_result, FilterResult::Forward) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably ok but fwiw you don't have to handle this inside. If keyboard.input() returns None, that means the closure returned FilterResult::Forward.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean something like match ...input(...) { None => { mru_commit(); return}, Some(None) => return, _ => ()}?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now there's an if let Some(Some(bind)) = keyboard.input(...) and it has an } else { branch, I think you can put this line into that else branch?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually not exactly since then it will catch Some(None) too which is not what we want.. Idk maybe there's a cleaner way here

// Interaction with the active window, immediately update
// the active window's focus timestamp without waiting for a
// possible lockin period.
this.niri.lockin_focus();
}
intercept_result
},
) else {
return;
Expand Down Expand Up @@ -2173,10 +2168,8 @@ impl State {
}

// The event is getting forwarded to a client, consider that the
// focus should be locked-in
self.niri
.event_forwarded_to_focused_client
.store(true, std::sync::atomic::Ordering::Relaxed);
// focus should be locked-in.
self.niri.lockin_focus();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess this should also happen on touch taps and tablet touches and possibly other stuff?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. I've sprinkled mru_commit() in interactions that are forwarded to the client App (to the extent I understood what was going on). However tbh I mostly can't test out if it's really working as intended.


pointer.button(
self,
Expand Down Expand Up @@ -2968,7 +2961,6 @@ fn should_intercept_key(
screenshot_ui: &ScreenshotUi,
disable_power_key_handling: bool,
is_inhibiting_shortcuts: bool,
event_forwarded_to_focused_client: &mut AtomicBool,
) -> FilterResult<Option<Bind>> {
// Actions are only triggered on presses, release of the key
// shouldn't try to intercept anything unless we have marked
Expand Down Expand Up @@ -3036,14 +3028,7 @@ fn should_intercept_key(
suppressed_keys.remove(&key_code);
FilterResult::Intercept(None)
}
(None, true) => {
// Interaction with the active window, the event will be picked
// up by Niri on the next event loop at which point it can do an
// immediate update of the active window's focus timestamp without
// waiting for a possible lockin period.
event_forwarded_to_focused_client.store(true, std::sync::atomic::Ordering::Relaxed);
FilterResult::Forward
}
(None, true) => FilterResult::Forward,
}
}

Expand Down Expand Up @@ -3612,7 +3597,6 @@ mod tests {
&screenshot_ui,
disable_power_key_handling,
is_inhibiting_shortcuts.get(),
&mut AtomicBool::new(false),
)
};

Expand All @@ -3630,7 +3614,6 @@ mod tests {
&screenshot_ui,
disable_power_key_handling,
is_inhibiting_shortcuts.get(),
&mut AtomicBool::new(false),
)
};

Expand Down