diff options
| author | rustN00b <rustN00b@protonmail.com> | 2025-11-01 09:30:35 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2025-11-16 22:36:01 +0300 |
| commit | 933ffcb229e9e678b271d4043b1d4d5e2b6fa073 (patch) | |
| tree | 375c6bab6824619e476cc6fdf770d80ce51eca68 | |
| parent | b774fc1bafd3f9c612ad117986510f8710fd7cc6 (diff) | |
| download | niri-933ffcb229e9e678b271d4043b1d4d5e2b6fa073.tar.gz niri-933ffcb229e9e678b271d4043b1d4d5e2b6fa073.tar.bz2 niri-933ffcb229e9e678b271d4043b1d4d5e2b6fa073.zip | |
Implement recent windows switcher (Alt-Tab)
Historic commit description log:
The MRU actions `focus-window-mru-previous` and `focus-window-mru-next`
are used to navigate windows in most-recently-used or
least-recently-used order.
Whenever a window is focused, it records a timestamp that be used to
sort windows in MRU order. This timestamp is not updated immediately,
but only after a small delay (lock-in period) to ensure that the
focus wasn't transfered to another window in the meantime. This
strategy avoids upsetting the MRU order with focus events generated by
intermediate windows when moving between two non contiguous windows.
The lock-in delay can be configured using the `focus-lockin-ms`
configuration argument.
Calling either of the `focus-window-mru` actions starts an MRU window
traversal sequence if one isn't already in progress. When a sequence is
in progress, focus timestamps are no longer updated.
A traversal sequence ends when:
- either the `Mod` key is released, the focus then stays on the chosen
window and its timestamp is immediately refreshed,
- or if the `Escape` key is pressed, the focus returns to the window
that initially had the focus when the sequence was started.
Rename WindowMRU fields
Improve window close handling during MRU traversal
When the focused window is closed during an MRU traversal, it moves
to the previous window in MRU order instead of the default behavior.
Removed dbg! calls
Merge remote-tracking branch 'upstream/main' into window-mru
Hardcode Alt-Tab/Alt-shift-Tab for MRU window nav
- Add a `PRESET_BINDINGS` containing MRU navigation actions.
`PRESET_BINDINGS` are overridden by user configuration so these remain
available if the user needs them for another purpose
- Releasing the `Alt` key ends any in-progress MRU window traversal
Remove `focus-window-mru` actions from config
These actions are configured in presets but no longer available
for the bindings section of the configuration
Cancel MRU traversal with Alt-Esc
Had been forgotten in prior commit and was using `Mod` instead of `Alt`
Rephrase some comments
Fix Alt-Esc not cancelling window-mru
Merge remote-tracking branch 'upstream/main' into window-mru
Lock-in focus immediately on user interaction
As per suggestion by @bbb651, focus is locked-in immediately if a window
is interacted with, ie. receives key events or pointer clicks.
This change is also an opportunity to make the lockin timer less aggresive.
Merge remote-tracking branch 'upstream/main' into window-mru
Simplify WindowMRU::new
Now that there is a more general Niri::lockin_focus method, leverage
it in WindowMRU.
Replace Duration with Instant in WindowMRU timestamp
Merge remote-tracking branch 'upstream/main' into window-mru
Address PR comments - partial
- Swapped meaning of next and previous for MRU traversal
- Fixed comment that still referred to `Mod` as leader key for MRU traversal
instead of `Alt`
- Fixed doc comments that were missing a period
- Stop using BinaryHeap in `WindowMRU::new()`
- Replaced `WindowMRU::mru_with()` method with a simpler `advance()`
- Simplified `Alt` key release handling code in `State::on_keyboard()`
Simplify early-mru-commit logic
No longer perform the mru-commit/lockin_focus in the next event loop callback.
Instead it is handled directly when it is determined that an event (pointer
or kbd) is forwarded to the active window.
Handle PR comments
- `focus_lockin` variables and configuration item renamed to `mru_commit`.
- added the Esc key to `suppressed_keys` if it was used to cancel an MRU
traversal.
- removed `WindowMRU::mru_next` and `WindowMRU::mru_previous` methods
as they didn't really provide more than the generic `WindowMRU::advance`
method.
- removed obsolete `Niri::event_forwarded_to_focused_client` boolean
- added calls to `mru_commit()` (formerly `focus_lockin`) in:
- `State::on_pointer_axis()`
- `State::on_tablet_tool_axis()`
- `State::on_tablet_tool_tip()`
- `State::on_tablet_tool_proximity()`
- `State::on_tablet_tool_button()`
- `State::on_gesture_swipe_begin()`
- `State::on_gesture_pinch_begin()`
- `State::on_gesture_hold_begin()`
- `State::on_touch_down()`
Merge remote-tracking branch 'upstream/main' into window-mru
Merge remote-tracking branch 'upstream/main' into window-mru
Add MRU window navigation actions
The MRU actions `focus-window-mru-previous` and `focus-window-mru-next`
are used to navigate windows in most-recently-used or
least-recently-used order.
Whenever a window is focused, it records a timestamp that be used to
sort windows in MRU order. This timestamp is not updated immediately,
but only after a small delay (lock-in period) to ensure that the
focus wasn't transfered to another window in the meantime. This
strategy avoids upsetting the MRU order with focus events generated by
intermediate windows when moving between two non contiguous windows.
The lock-in delay can be configured using the `focus-lockin-ms`
configuration argument.
Calling either of the `focus-window-mru` actions starts an MRU window
traversal sequence if one isn't already in progress. When a sequence is
in progress, focus timestamps are no longer updated.
A traversal sequence ends when:
- either the `Mod` key is released, the focus then stays on the chosen
window and its timestamp is immediately refreshed,
- or if the `Escape` key is pressed, the focus returns to the window
that initially had the focus when the sequence was started.
Rename WindowMRU fields
Improve window close handling during MRU traversal
When the focused window is closed during an MRU traversal, it moves
to the previous window in MRU order instead of the default behavior.
Removed dbg! calls
Merge remote-tracking branch 'upstream/main' into window-mru
Hardcode Alt-Tab/Alt-shift-Tab for MRU window nav
- Add a `PRESET_BINDINGS` containing MRU navigation actions.
`PRESET_BINDINGS` are overridden by user configuration so these remain
available if the user needs them for another purpose
- Releasing the `Alt` key ends any in-progress MRU window traversal
Remove `focus-window-mru` actions from config
These actions are configured in presets but no longer available
for the bindings section of the configuration
Cancel MRU traversal with Alt-Esc
Had been forgotten in prior commit and was using `Mod` instead of `Alt`
Rephrase some comments
Fix Alt-Esc not cancelling window-mru
Merge remote-tracking branch 'upstream/main' into window-mru
Lock-in focus immediately on user interaction
As per suggestion by @bbb651, focus is locked-in immediately if a window
is interacted with, ie. receives key events or pointer clicks.
This change is also an opportunity to make the lockin timer less aggresive.
Merge remote-tracking branch 'upstream/main' into window-mru
Simplify WindowMRU::new
Now that there is a more general Niri::lockin_focus method, leverage
it in WindowMRU.
Replace Duration with Instant in WindowMRU timestamp
Merge remote-tracking branch 'upstream/main' into window-mru
Address PR comments - partial
- Swapped meaning of next and previous for MRU traversal
- Fixed comment that still referred to `Mod` as leader key for MRU traversal
instead of `Alt`
- Fixed doc comments that were missing a period
- Stop using BinaryHeap in `WindowMRU::new()`
- Replaced `WindowMRU::mru_with()` method with a simpler `advance()`
- Simplified `Alt` key release handling code in `State::on_keyboard()`
Simplify early-mru-commit logic
No longer perform the mru-commit/lockin_focus in the next event loop callback.
Instead it is handled directly when it is determined that an event (pointer
or kbd) is forwarded to the active window.
Handle PR comments
- `focus_lockin` variables and configuration item renamed to `mru_commit`.
- added the Esc key to `suppressed_keys` if it was used to cancel an MRU
traversal.
- removed `WindowMRU::mru_next` and `WindowMRU::mru_previous` methods
as they didn't really provide more than the generic `WindowMRU::advance`
method.
- removed obsolete `Niri::event_forwarded_to_focused_client` boolean
- added calls to `mru_commit()` (formerly `focus_lockin`) in:
- `State::on_pointer_axis()`
- `State::on_tablet_tool_axis()`
- `State::on_tablet_tool_tip()`
- `State::on_tablet_tool_proximity()`
- `State::on_tablet_tool_button()`
- `State::on_gesture_swipe_begin()`
- `State::on_gesture_pinch_begin()`
- `State::on_gesture_hold_begin()`
- `State::on_touch_down()`
Merge remote-tracking branch 'upstream/main' into window-mru
Merge remote-tracking branch 'upstream/main' into window-mru
Include never focused windows in MRU list
Remove mru_commit_ms from configurable options
For now the value is hard-coded to 750ms
Merge remote-tracking branch 'upstream/main' into HEAD
Add hotkey_overlay_tile for PRESET_BINDINGS
Merge remote-tracking branch 'origin/window-mru' into HEAD
Merge remote-tracking branch 'upstream/main' into window-mru
Merge remote-tracking branch 'upstream/main' into window-mru
Merge remote-tracking branch 'upstream/main' into window-mru
Firt shot an MruUi
The UI doesn't actually do anything yet. For now it just puts up thumbnails
for existing windows in MRU order.
Added MRU texture cache + simplifications
Working version
Removed previous Mru code
Tidy up Action names
Added Home/End bindings
Merge remote-tracking branch 'upstream/main' into window-mru-ui
Add scope and filtering to Mru window navigation
Feed todo list
Merge remote-tracking branch 'upstream/main' into window-mru-ui
Clippy: Boxed the focus ring
The UI object doesn't get moved around much so it isn't clear if
this actually important. Boxing keeps clippy happy because of the
size difference between an Open vs a Closed MRU UI.
Bump rust version to 1.83
Avoids getting yelled at by clippy for using features that weren't yet available in 1.80.1
Applied clippy lints
Fix MruFilter::None conversion
MruFilter variant was getting ignored
cargo fmt
Update rust tool chain in CI
Had only been updated in Cargo.toml, this causes build
failures on Github
Support changing Mru modes with the Mru UI open
Fix texture cache optimization
When the Mru parameters were changed while the MruUI was open, the
texture cache is rebuilt but attempts to reuse existing Textures
that are still usable in the updated Mru list. The index of the
retained texture could be miscalculated and resulted in the wrong
texture being used for a given window Id.
Make MruAdvance available as a Bind action
For consistency, MruAdvance bindings are carried over when the MruUI is open.
Merge remote-tracking branch 'upstream/main' into window-mru-ui
Preset binds added as a source for MRU UI binds
Surprisingly the status prior to the patch should have prevented the UI
bindings to advance through the Mru list from working properly.
Use iterators to find bindings
This allows the caller, eg. `on_keyboard` to choose the full list
of bindings that should be searched through by composing iterators.
Prior to the change the PRESET_BINDINGS were always included regardless
of caller. With this approach, `on_keyboard` can add in the MRU_UI-
specific bindings if it detects that the MRU UI is open.
Make scope and filter optional in mru-advance
This avoids unexpected behavior when navigating MRU with a filter, e.g. App-Id,
with arrow keys for instance, which would result in changing navigation
to ignore the app-id filter. With the change, mru-advance has an optional
scope and filter that allows a key bind to leave the current navigation mode
unchanged.
Add title under window thumbnails
- Reworked the texture cache to use TextureBuffer-s instead of BakedBuffer.
- Add convenience methods to access TextureCache content.
Some tidying up.
Fade title out if it doesn't fit in available size
Add bindings to change the MruScope
Fix panic rendering title when cairo surface was busy
Also avoid interpreting markup in window titles.
Bring branch in line with window-mru-ui-squashed
Add navigation animation in MRU UI
Only handles motion between thumbnails
Add thumbnail close animation
For now, the animation only tracks when the corresponding window is closed.
Add animations on filter and scope changes
Add open/close animation to MRU Ui
Merge remote-tracking branch 'upstream/main' into window-mru-ui
Fix animations on scope/filter changes
Previous implementation would evict wrong textures from the cache.
And get thumbnail animations wrong.
Merge remote-tracking branch 'upstream/main' into window-mru-ui
Fix panic on change of scope/filter when Mru list is empty.
Add doc comment to method that could trigger a panic
Simplify thumbnail ordering logic
Improve scope/filter change animations
- direction is no longer a factor when an Mru UI is opened (previously
the first thumbnail would be the currently focused window when
moving in the "forward" direction, and when moving in the "backward"
direction the focused window would have its thumbnail last in the
list. This made animations kind of confusing when switching scopes
or filtering.
The updated version always places the thumbnails in most recent
focus order. So when the MRU UI is brought up in the "backward"
direction, the last thumbnail in the MRU list starts selected.
- closing animations no longer use the view referential, but use
the output referential instead. This makes disappearing thumbnails
appear stationary on screen even if the view is moving. This tends to
look less confusing than the previous approach.
Applied clippy lints
Preserve scope during fwd/backward navigation
Change preset keybinding declarations from const to static
Add thumbnail selection animation
This is still very much a work in progress:
- the focus ring is not shown until the animation completes
- if the tile is resized during the animation, the net effect looks
pretty bad because proportions skip directly to those requested
instead of transitioning smoothly.
Both points should be addressed by using regular tile rendering to an
OffscreenBuffer but I haven't much success there.
Merge remote-tracking branch 'upstream/main' into window-mru-ui
Fix niri-config parse test
Use OffscreenBuffer to render ThumbnailSelection animation
todo: fix thumbnail destination if the target workspace is being swapped.
Handle workspace switch during thumbnail select animation
Close Overview when MRU UI is opened
Add configuration option to disable MRU UI
Make mod-key for MRU UI configurable
Avoid collecting MRU UI bindings on each input
Bindings are cached when first accessed, the cache is invalidated
whenever the configuration changes.
Close MRU UI when Overview is opened
Merge remote-tracking branch 'upstream/main' into window-mru-ui
Fix MRU UI opened bindings always active
Remove mru-advance from actions available for config keybind
Because the MRU UI assumes that all key-bindings use the mod-key
defined in for `recent-windows`, behavior can be disconcerting
if arbitrary keybindings are allowed in the configuration (e.g.
UI opens and immediately closes because the mod-key is not being
held).
Include focus timestamp in Window IPC messages
Timestamps are serialized as time::SystemTime, which in JSON form is represented
as *two* fields, secs and nanos.
Merge remote-tracking branch 'upstream/main' into window-mru-ui
Only do Thumbnail Select Anim if MRU UI stayed open long enough
Threshold is hard coded in window_mru_ui.rs (250ms).
Merge remote-tracking branch 'upstream/main' into window-mru-ui
Add a few WindowMru tests
Forward Mod-key release when closing MRU UI
Merge remote-tracking branch 'upstream/main' into window-mru-ui
Remove extraneous thumbnail motion on Mru filter change
Fix missing alpha in Mru thumbnail open animation
Add Mod+h and Mod+l bindings for MRU navigation
Change CloseWindow binding in MRU to Mod+Shift+q
Keep MRU UI on display it was initially opened on
Bump up the MRU IU selection anim threshold
Allow MRU thumbnail selection with mouse pointer
Allow MRU thumbnail selection using touch
Needs testing, Idk if this works for lack of a touchscreen.
Fix missing fade-out animation for thumbnails on MRU UI close
Merge remote-tracking branch 'upstream/main' into window-mru-ui
Make thumbnail selection animation optional
Merge remote-tracking branch 'upstream/main' into window-mru-ui
Fix niri-config parse test case
Add shortcut to cycle through MRU scopes
- added MruCycleScope action to trigger cycling
- added an indication panel to show the current scope
- recall previous scope when opening the MRU UI
Merge remote-tracking branch 'upstream/main' into window-mru-ui
Improve MRU thumbnail scaling
Prior to the commit, thumbnails were just 2x downscaling of their corresponding
window. Now they are also scaled based on the relative height of the window
on its output display. This avoids having a thumbnail taking up the entire
screen on the display where the MRU UI is displayed.
Merge remote-tracking branch 'upstream/main' into window-mru-ui
Use resolved window rules for thumbnails
Previously parameters such as the corner-radius didn't follow the general
config and used an MRU UI specific default.
Align thumbnail size and position to physical pixels
clarify param names in generate_tile_texture
Revert MSRV 1.83
Close MRU UI on click/touch outside of a thumbnail
MRU - display window title under all thumbnails
MRU - revert to pre-defined thumbnail corner radius
MRU - Removed thumb title font size adjustment
This didn't look as if it was necessary. (unscientific assesment)
MRU - reverted to Mod+Q to quit selected thumbnail
Merge remote-tracking branch 'upstream/main' into window-mru-ui
MRU - Update focus ring when moving mouse over a thumbnail
restore code that went missing
switch focus timestamp to monotonic time
We don't want the monotonicity of SystemClock here. Instant itself isn't
serializable, but our monotonic clock timestamps are, and they are
consistent across processes too.
axe thumbnail close animation
I'm still not quite convinced about it. Maybe we'll reintroduce it later
with better architecture; for now though, it causes quite a bit of
complexity.
minor cleanups
remove unnecessary option
replace open animation with delay
Avoids flashing the whole screen for quick Alt-Tabs. Duration taken from
GNOME Shell.
make mod key different in nested
replace SelectedThumbnail with MappedId
don't hide focus ring during alt tab
wip refactor everything and render live windows
rename some constants
replace focus ring with background + border
extract thumbnail constructors
reimplement title fade with a shader
reimplement ui fade out on closing
fix preview scaling
add min scale for very small windows
add keyboard focus for mru
fixes activating alt on target window
revert/simplify pointer code changes
fixes mouse not clamped to output when in alt-tab; should fix touch
going through
move touch handling to below screenshot ui
remove unneeded touch overview grab code
rename to mru.rs
move mru tests into separate file
also close mru when clicking on other outputs
roll back no longer necessary event filtering
rework mru keyboard binds
convert some regular binds to MRU binds
hide window title when blocked out
verify that mru bind uses a keyboard key
improve selection visibility & indicate urgency
freeze alt-tab view on pointer motion
add WindowFocusTimestampChanged event, separate struct for Timestamp
minor cleanups
scope panel fixes
simplify scope cycling
honor geometry corner radius
don't trigger focus-follows-mouse in the MRU
remove unnecessary argument
cache backdrop buffers
remove unnecessary mru close
allow to screenshot the mru
support bob offset
improve mru redraws
pass config instead of options
add open-delay-ms option
add highlight options
rename window-mru-ui-open-close to recent-windows-close
add preview options
fix scope change and remove window delta anim
improve unselected scope panel text contrast
move panel back up so it doesn't overlap the screenshot one
rename preview to previews in config
render highlight background with focusring
fix highlight pos rounding
add highlight corner-radius setting
remove allocation from inner render
use offscreen for mru closing fade
make scope only affect MRU open
otherwise you can't change scope at runtime easily
replace todo with fixme
include title height in thumbnail under
remove cloning from set scope/filter
remove animate close todo
update field name in mapped
remove commented out closing thumbnails
I decided not to do this for now.
rename filter from None to All and skip in knuffel
None is confusing with Option
write docs
make inactive urgent more prominent
remove reopen from scartch todo
explicitly mention app id in filter
make scroll binds work in the mru
add fixmes
don't select next window when nothing is focused
add missing anim config merge
fixes
replace click selection with pointer motion + confirm
simplify close mru ui call
rename mrucloserequest variants
mru confirm fixes
support tablet input
mru commit cleanups
remove most mru commit calls
they didn't actualy do anything as implemented. If we want to bring them
back we need to refactor a bit to join them with activate_window() call.
make regular mouse binds also work in mru
fixes
fixes
move types up
fix tracy span
| -rw-r--r-- | docs/mkdocs.yaml | 1 | ||||
| -rw-r--r-- | docs/wiki/Configuration:-Animations.md | 18 | ||||
| -rw-r--r-- | docs/wiki/Configuration:-Introduction.md | 1 | ||||
| -rw-r--r-- | docs/wiki/Configuration:-Recent-Windows.md | 166 | ||||
| -rw-r--r-- | docs/wiki/_Sidebar.md | 1 | ||||
| -rw-r--r-- | niri-config/src/animations.rs | 36 | ||||
| -rw-r--r-- | niri-config/src/binds.rs | 21 | ||||
| -rw-r--r-- | niri-config/src/lib.rs | 156 | ||||
| -rw-r--r-- | niri-config/src/recent_windows.rs | 401 | ||||
| -rw-r--r-- | src/a11y.rs | 7 | ||||
| -rw-r--r-- | src/handlers/compositor.rs | 8 | ||||
| -rw-r--r-- | src/handlers/xdg_shell.rs | 8 | ||||
| -rw-r--r-- | src/input/mod.rs | 373 | ||||
| -rw-r--r-- | src/niri.rs | 154 | ||||
| -rw-r--r-- | src/ui/mod.rs | 1 | ||||
| -rw-r--r-- | src/ui/mru.rs | 1929 | ||||
| -rw-r--r-- | src/ui/mru/tests.rs | 135 | ||||
| -rw-r--r-- | src/window/mapped.rs | 12 |
18 files changed, 3350 insertions, 78 deletions
diff --git a/docs/mkdocs.yaml b/docs/mkdocs.yaml index b79807ad..3e33a92e 100644 --- a/docs/mkdocs.yaml +++ b/docs/mkdocs.yaml @@ -103,6 +103,7 @@ nav: - Layer Rules: Configuration:-Layer-Rules.md - Animations: Configuration:-Animations.md - Gestures: Configuration:-Gestures.md + - Recent Windows: Configuration:-Recent-Windows.md - Debug Options: Configuration:-Debug-Options.md - Include: Configuration:-Include.md - Development: diff --git a/docs/wiki/Configuration:-Animations.md b/docs/wiki/Configuration:-Animations.md index 2e59d62c..58b79b5f 100644 --- a/docs/wiki/Configuration:-Animations.md +++ b/docs/wiki/Configuration:-Animations.md @@ -58,6 +58,10 @@ animations { overview-open-close { spring damping-ratio=1.0 stiffness=800 epsilon=0.0001 } + + recent-windows-close { + spring damping-ratio=1.0 stiffness=800 epsilon=0.001 + } } ``` @@ -422,6 +426,20 @@ animations { } ``` +#### `recent-windows-close` + +<sup>Since: next release</sup> + +The close fade-out animation of the recent windows switcher. + +```kdl +animations { + recent-windows-close { + spring damping-ratio=1.0 stiffness=800 epsilon=0.001 + } +} +``` + ### Synchronized Animations <sup>Since: 0.1.5</sup> diff --git a/docs/wiki/Configuration:-Introduction.md b/docs/wiki/Configuration:-Introduction.md index ba9d08d9..28fa945e 100644 --- a/docs/wiki/Configuration:-Introduction.md +++ b/docs/wiki/Configuration:-Introduction.md @@ -12,6 +12,7 @@ You can find documentation for various sections of the config on these wiki page * [`layer-rule {}`](./Configuration:-Layer-Rules.md) * [`animations {}`](./Configuration:-Animations.md) * [`gestures {}`](./Configuration:-Gestures.md) +* [`recent-windows {}`](./Configuration:-Recent-Windows.md) * [`debug {}`](./Configuration:-Debug-Options.md) * [`include "other.kdl"`](./Configuration:-Include.md) diff --git a/docs/wiki/Configuration:-Recent-Windows.md b/docs/wiki/Configuration:-Recent-Windows.md new file mode 100644 index 00000000..07b166b0 --- /dev/null +++ b/docs/wiki/Configuration:-Recent-Windows.md @@ -0,0 +1,166 @@ +### Overview + +<sup>Since: next release</sup> + +In this section you can configure the recent windows switcher (Alt-Tab). + +Here is an outline of the available settings and their default values: + +```kdl +recent-windows { + // off + open-delay-ms 150 + + highlight { + active-color "#999999ff" + urgent-color "#ff9999ff" + padding 30 + corner-radius 0 + } + + previews { + max-height 480 + max-scale 0.5 + } + + binds { + Alt+Tab { next-window; } + Alt+Shift+Tab { previous-window; } + Alt+grave { next-window filter="app-id"; } + Alt+Shift+grave { previous-window filter="app-id"; } + + Mod+Tab { next-window; } + Mod+Shift+Tab { previous-window; } + Mod+grave { next-window filter="app-id"; } + Mod+Shift+grave { previous-window filter="app-id"; } + } +} +``` + +`off` disables the recent windows switcher altogether. + +### `open-delay-ms` + +Delay, in milliseconds, between pressing the Alt-Tab bind and the recent windows switcher visually appearing on screen. + +The switcher is delayed by default so that quickly tapping Alt-Tab to switch windows wouldn't cause annoying fullscreen visual changes. + +```kdl +recent-windows { + // Make the switcher appear instantly. + open-delay-ms 0 +} +``` + +### `highlight` + +Controls the highlight behind the focused window preview in the recent windows switcher. + +- `active-color`: normal color of the focused window highlight. +- `urgent-color`: color of an urgent focused window highlight, also visible in a darker shade on unfocused windows. +- `padding`: padding of the highlight around the window preview, in logical pixels. +- `corner-radius`: corner radius of the highlight. + +```kdl +recent-windows { + // Round the corners on the highlight. + highlight { + corner-radius 14 + } +} +``` + +### `previews` + +Controls the window previews in the switcher. + +- `max-scale`: maximum scale of the window previews. +Windows cannot be scaled bigger than this value. +- `max-height`: maximum height of the window previews. +Further limits the size of the previews in order to occupy less space on large monitors. + +On smaller monitors, the previews will be primarily limited by `max-scale`, and on larger monitors they will be primarily limited by `max-height`. + +The `max-scale` limit is imposed twice: on the final window scale, and on the window height which cannot exceed `monitor height × max scale`. + +```kdl +recent-windows { + // Make the previews smaller to fit more on screen. + previews { + max-height 320 + } +} +``` + +```kdl +recent-windows { + // Make the previews larger to see the window contents. + previews { + max-height 1080 + max-scale 0.75 + } +} +``` + +### `binds` + +Configure binds that open and navigate the recent windows switcher. + +The defaults are <kbd>Alt</kbd><kbd>Tab</kbd> / <kbd>Mod</kbd><kbd>Tab</kbd> to switch across all windows, and <kbd>Alt</kbd><kbd>\`</kbd> / <kbd>Mod</kbd><kbd>\`</kbd> to switch between windows of the current application. +Adding <kbd>Shift</kbd> will switch windows backwards. + +Adding the recent windows `binds {}` section to your config removes all default binds. +You can copy the ones you need from the summary at the top of this wiki page. + +```kdl +recent-windows { + // Even an empty binds {} section will remove all default binds. + binds { + } +} +``` + +The available actions are `next-window` and `previous-window`. +They can optionally have the following properties: + +- `filter="app-id"`: filters the switcher to the windows of the currently selected application, as determined by the Wayland app ID. +- `scope="all"`, `scope="output"`, `scope="workspace"`: sets the pre-selected scope when this bind is used to open the recent windows switcher. + +```kdl +recent-windows { + // Pre-select the "Output" scope when switching windows. + binds { + Mod+Tab { next-window scope="output"; } + Mod+Shift+Tab { previous-window scope="output"; } + Mod+grave { next-window scope="output" filter="app-id"; } + Mod+Shift+grave { previous-window scope="output" filter="app-id"; } + } +} +``` + +The recent windows binds have a precedence over the [normal binds](./Configuration:-Key-Bindings.md), meaning that if you have <kbd>Alt</kbd><kbd>Tab</kbd> bound to something else in the normal binds, the `recent-windows` bind will override it. + +All binds in this section must have a modifier key like <kbd>Alt</kbd> or <kbd>Mod</kbd> because the recent windows switcher remains open only while you hold any modifier key. + +#### Bindings inside the switcher + +When the switcher is open, some hardcoded binds are available: + +- <kbd>Escape</kbd> cancels the switcher. +- <kbd>Enter</kbd> closes the switcher confirming the current window. +- <kbd>A</kbd>, <kbd>W</kbd>, <kbd>O</kbd> select a specific scope. +- <kbd>S</kbd> cycles between scopes, as indicated by the panel at the top. +- <kbd>←</kbd>, <kbd>→</kbd>, <kbd>Home</kbd>, <kbd>End</kbd> move the selection directionally. + +Additionally, certain regular binds will automatically work in the switcher: + +- focus column left/right and their variants: will move the selection left/right inside the switcher. +- focus column first/last: will move the selection to the first or last window. +- close window: will close the window currently focused in the switcher. +- screenshot: will open the screenshot UI. + +The way this works is by finding all regular binds corresponding to these actions and taking just the trigger key without modifiers. +For example, if you have <kbd>Mod</kbd><kbd>Shift</kbd><kbd>C</kbd> bound to `close-window`, in the window switcher pressing <kbd>C</kbd> on its own will close the window. + +This way we don't need to hardcode things like HJKL directional movements. +If you have, say, Colemak-DH MNEI binds instead, they will work for you in the window switcher (as long as they don't conflict with the hardcoded ones). diff --git a/docs/wiki/_Sidebar.md b/docs/wiki/_Sidebar.md index 448ec283..4b5c830d 100644 --- a/docs/wiki/_Sidebar.md +++ b/docs/wiki/_Sidebar.md @@ -33,6 +33,7 @@ * [Layer Rules](./Configuration:-Layer-Rules.md) * [Animations](./Configuration:-Animations.md) * [Gestures](./Configuration:-Gestures.md) +* [Recent Windows](./Configuration:-Recent-Windows.md) * [Debug Options](./Configuration:-Debug-Options.md) * [Include](./Configuration:-Include.md) diff --git a/niri-config/src/animations.rs b/niri-config/src/animations.rs index a3be59c9..346b6251 100644 --- a/niri-config/src/animations.rs +++ b/niri-config/src/animations.rs @@ -18,6 +18,7 @@ pub struct Animations { pub exit_confirmation_open_close: ExitConfirmationOpenCloseAnim, pub screenshot_ui_open: ScreenshotUiOpenAnim, pub overview_open_close: OverviewOpenCloseAnim, + pub recent_windows_close: RecentWindowsCloseAnim, } impl Default for Animations { @@ -35,6 +36,7 @@ impl Default for Animations { exit_confirmation_open_close: Default::default(), screenshot_ui_open: Default::default(), overview_open_close: Default::default(), + recent_windows_close: Default::default(), } } } @@ -67,6 +69,8 @@ pub struct AnimationsPart { pub screenshot_ui_open: Option<ScreenshotUiOpenAnim>, #[knuffel(child)] pub overview_open_close: Option<OverviewOpenCloseAnim>, + #[knuffel(child)] + pub recent_windows_close: Option<RecentWindowsCloseAnim>, } impl MergeWith<AnimationsPart> for Animations { @@ -92,6 +96,7 @@ impl MergeWith<AnimationsPart> for Animations { exit_confirmation_open_close, screenshot_ui_open, overview_open_close, + recent_windows_close, ); } } @@ -305,6 +310,22 @@ impl Default for OverviewOpenCloseAnim { } } +#[derive(Debug, Clone, Copy, PartialEq)] +pub struct RecentWindowsCloseAnim(pub Animation); + +impl Default for RecentWindowsCloseAnim { + fn default() -> Self { + Self(Animation { + off: false, + kind: Kind::Spring(SpringParams { + damping_ratio: 1., + stiffness: 800, + epsilon: 0.001, + }), + }) + } +} + impl<S> knuffel::Decode<S> for WorkspaceSwitchAnim where S: knuffel::traits::ErrorSpan, @@ -488,6 +509,21 @@ where } } +impl<S> knuffel::Decode<S> for RecentWindowsCloseAnim +where + S: knuffel::traits::ErrorSpan, +{ + fn decode_node( + node: &knuffel::ast::SpannedNode<S>, + ctx: &mut knuffel::decode::Context<S>, + ) -> Result<Self, DecodeError<S>> { + let default = Self::default().0; + Ok(Self(Animation::decode_node(node, ctx, default, |_, _| { + Ok(false) + })?)) + } +} + impl Animation { pub fn new_off() -> Self { Self { diff --git a/niri-config/src/binds.rs b/niri-config/src/binds.rs index 1356d40f..378ae8ed 100644 --- a/niri-config/src/binds.rs +++ b/niri-config/src/binds.rs @@ -12,6 +12,7 @@ use smithay::input::keyboard::keysyms::KEY_NoSymbol; use smithay::input::keyboard::xkb::{keysym_from_name, KEYSYM_CASE_INSENSITIVE, KEYSYM_NO_FLAGS}; use smithay::input::keyboard::Keysym; +use crate::recent_windows::{MruDirection, MruFilter, MruScope}; use crate::utils::{expect_only_children, MergeWith}; #[derive(Debug, Default, PartialEq)] @@ -364,6 +365,26 @@ pub enum Action { UnsetWindowUrgent(u64), #[knuffel(skip)] LoadConfigFile, + #[knuffel(skip)] + MruAdvance { + direction: MruDirection, + scope: Option<MruScope>, + filter: Option<MruFilter>, + }, + #[knuffel(skip)] + MruConfirm, + #[knuffel(skip)] + MruCancel, + #[knuffel(skip)] + MruCloseCurrentWindow, + #[knuffel(skip)] + MruFirst, + #[knuffel(skip)] + MruLast, + #[knuffel(skip)] + MruSetScope(MruScope), + #[knuffel(skip)] + MruCycleScope, } impl From<niri_ipc::Action> for Action { diff --git a/niri-config/src/lib.rs b/niri-config/src/lib.rs index dda7dfd6..e458da39 100644 --- a/niri-config/src/lib.rs +++ b/niri-config/src/lib.rs @@ -13,7 +13,7 @@ #[macro_use] extern crate tracing; -use std::cell::RefCell; +use std::cell::{Cell, RefCell}; use std::collections::HashSet; use std::ffi::OsStr; use std::fs::{self, File}; @@ -39,6 +39,7 @@ pub mod layer_rule; pub mod layout; pub mod misc; pub mod output; +pub mod recent_windows; pub mod utils; pub mod window_rule; pub mod workspace; @@ -54,6 +55,10 @@ pub use crate::layer_rule::LayerRule; pub use crate::layout::*; pub use crate::misc::*; pub use crate::output::{Output, OutputName, Outputs, Position, Vrr}; +use crate::recent_windows::RecentWindowsPart; +pub use crate::recent_windows::{ + MruDirection, MruFilter, MruPreviews, MruScope, RecentWindows, DEFAULT_MRU_COMMIT_MS, +}; pub use crate::utils::FloatOrInt; use crate::utils::{Flag, MergeWith as _}; pub use crate::window_rule::{FloatingPosition, RelativeTo, WindowRule}; @@ -85,6 +90,7 @@ pub struct Config { pub switch_events: SwitchBinds, pub debug: Debug, pub workspaces: Vec<Workspace>, + pub recent_windows: RecentWindows, } #[derive(Debug, Clone)] @@ -118,6 +124,7 @@ struct IncludeErrors(Vec<knuffel::Error>); // // We don't *need* it because we have a recursion limit, but it makes for nicer error messages. struct IncludeStack(HashSet<PathBuf>); +struct SawMruBinds(Rc<Cell<bool>>); // Rather than listing all fields and deriving knuffel::Decode, we implement // knuffel::DecodeChildren by hand, since we need custom logic for every field anyway: we want to @@ -140,6 +147,7 @@ where let includes = ctx.get::<Rc<RefCell<Includes>>>().unwrap().clone(); let include_errors = ctx.get::<Rc<RefCell<IncludeErrors>>>().unwrap().clone(); let recursion = ctx.get::<Recursion>().unwrap().0; + let saw_mru_binds = ctx.get::<SawMruBinds>().unwrap().0.clone(); let mut seen = HashSet::new(); @@ -269,6 +277,21 @@ where config.borrow_mut().layout.merge_with(&part); } + "recent-windows" => { + let part = RecentWindowsPart::decode_node(node, ctx)?; + + let mut config = config.borrow_mut(); + + // When an MRU binds section is encountered for the first time, clear out the + // default MRU binds. + if !saw_mru_binds.get() && part.binds.is_some() { + saw_mru_binds.set(true); + config.recent_windows.binds.clear(); + } + + config.recent_windows.merge_with(&part); + } + "include" => { let path: PathBuf = utils::parse_arg_node("include", node, ctx)?; let base = ctx.get::<BasePath>().unwrap(); @@ -331,6 +354,7 @@ where ctx.set(includes.clone()); ctx.set(include_errors.clone()); ctx.set(IncludeStack(include_stack)); + ctx.set(SawMruBinds(saw_mru_binds.clone())); ctx.set(config.clone()); }); @@ -424,6 +448,7 @@ impl Config { ctx.set(includes.clone()); ctx.set(include_errors.clone()); ctx.set(IncludeStack(include_stack)); + ctx.set(SawMruBinds(Rc::new(Cell::new(false)))); ctx.set(config.clone()); }, ); @@ -766,6 +791,10 @@ mod tests { window-close { curve "cubic-bezier" 0.05 0.7 0.1 1 } + + recent-windows-close { + off + } } gestures { @@ -848,6 +877,25 @@ mod tests { } workspace "workspace-2" workspace "workspace-3" + + recent-windows { + off + + highlight { + padding 15 + active-color "#00ff00" + } + + previews { + max-height 960 + } + + binds { + Alt+Tab { next-window; } + Alt+grave { next-window filter="app-id"; } + Super+Tab { next-window scope="output"; } + } + } "##, ); @@ -1507,6 +1555,18 @@ mod tests { ), }, ), + recent_windows_close: RecentWindowsCloseAnim( + Animation { + off: true, + kind: Spring( + SpringParams { + damping_ratio: 1.0, + stiffness: 800, + epsilon: 0.001, + }, + ), + }, + ), }, gestures: Gestures { dnd_edge_view_scroll: DndEdgeViewScroll { @@ -2119,6 +2179,100 @@ mod tests { layout: None, }, |
