mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-21 02:01:55 +07:00
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
This commit is contained in:
committed by
Ivan Molodetskikh
parent
b774fc1baf
commit
933ffcb229
@@ -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:
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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).
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+155
-1
@@ -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,
|
||||
},
|
||||
],
|
||||
recent_windows: RecentWindows {
|
||||
on: false,
|
||||
open_delay_ms: 150,
|
||||
highlight: MruHighlight {
|
||||
active_color: Color {
|
||||
r: 0.0,
|
||||
g: 1.0,
|
||||
b: 0.0,
|
||||
a: 1.0,
|
||||
},
|
||||
urgent_color: Color {
|
||||
r: 1.0,
|
||||
g: 0.6,
|
||||
b: 0.6,
|
||||
a: 1.0,
|
||||
},
|
||||
padding: 15.0,
|
||||
corner_radius: 0.0,
|
||||
},
|
||||
previews: MruPreviews {
|
||||
max_height: 960.0,
|
||||
max_scale: 0.5,
|
||||
},
|
||||
binds: [
|
||||
Bind {
|
||||
key: Key {
|
||||
trigger: Keysym(
|
||||
XK_Tab,
|
||||
),
|
||||
modifiers: Modifiers(
|
||||
ALT,
|
||||
),
|
||||
},
|
||||
action: MruAdvance {
|
||||
direction: Forward,
|
||||
scope: None,
|
||||
filter: Some(
|
||||
All,
|
||||
),
|
||||
},
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
allow_inhibiting: true,
|
||||
hotkey_overlay_title: None,
|
||||
},
|
||||
Bind {
|
||||
key: Key {
|
||||
trigger: Keysym(
|
||||
XK_grave,
|
||||
),
|
||||
modifiers: Modifiers(
|
||||
ALT,
|
||||
),
|
||||
},
|
||||
action: MruAdvance {
|
||||
direction: Forward,
|
||||
scope: None,
|
||||
filter: Some(
|
||||
AppId,
|
||||
),
|
||||
},
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
allow_inhibiting: true,
|
||||
hotkey_overlay_title: None,
|
||||
},
|
||||
Bind {
|
||||
key: Key {
|
||||
trigger: Keysym(
|
||||
XK_Tab,
|
||||
),
|
||||
modifiers: Modifiers(
|
||||
SUPER,
|
||||
),
|
||||
},
|
||||
action: MruAdvance {
|
||||
direction: Forward,
|
||||
scope: Some(
|
||||
Output,
|
||||
),
|
||||
filter: Some(
|
||||
All,
|
||||
),
|
||||
},
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
allow_inhibiting: true,
|
||||
hotkey_overlay_title: None,
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
"#);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,401 @@
|
||||
use std::collections::HashSet;
|
||||
|
||||
use knuffel::errors::DecodeError;
|
||||
use smithay::input::keyboard::Keysym;
|
||||
|
||||
use crate::utils::{expect_only_children, MergeWith};
|
||||
use crate::{Action, Bind, Color, FloatOrInt, Key, Modifiers, Trigger};
|
||||
|
||||
/// Delay before the window focus is considered to be locked-in for Window
|
||||
/// MRU ordering. For now the delay is not configurable.
|
||||
pub const DEFAULT_MRU_COMMIT_MS: u64 = 750;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct RecentWindows {
|
||||
pub on: bool,
|
||||
pub open_delay_ms: u16,
|
||||
pub highlight: MruHighlight,
|
||||
pub previews: MruPreviews,
|
||||
pub binds: Vec<Bind>,
|
||||
}
|
||||
|
||||
impl Default for RecentWindows {
|
||||
fn default() -> Self {
|
||||
RecentWindows {
|
||||
on: true,
|
||||
open_delay_ms: 150,
|
||||
highlight: MruHighlight::default(),
|
||||
previews: MruPreviews::default(),
|
||||
binds: default_binds(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(knuffel::Decode, Debug, Default, PartialEq)]
|
||||
pub struct RecentWindowsPart {
|
||||
#[knuffel(child)]
|
||||
pub on: bool,
|
||||
#[knuffel(child)]
|
||||
pub off: bool,
|
||||
#[knuffel(child, unwrap(argument))]
|
||||
pub open_delay_ms: Option<u16>,
|
||||
#[knuffel(child)]
|
||||
pub highlight: Option<MruHighlightPart>,
|
||||
#[knuffel(child)]
|
||||
pub previews: Option<MruPreviewsPart>,
|
||||
#[knuffel(child)]
|
||||
pub binds: Option<MruBinds>,
|
||||
}
|
||||
|
||||
impl MergeWith<RecentWindowsPart> for RecentWindows {
|
||||
fn merge_with(&mut self, part: &RecentWindowsPart) {
|
||||
self.on |= part.on;
|
||||
if part.off {
|
||||
self.on = false;
|
||||
}
|
||||
|
||||
merge_clone!((self, part), open_delay_ms);
|
||||
merge!((self, part), highlight, previews);
|
||||
|
||||
if let Some(part) = &part.binds {
|
||||
// Remove existing binds matching any new bind.
|
||||
self.binds
|
||||
.retain(|bind| !part.0.iter().any(|new| new.key == bind.key));
|
||||
// Add all new binds.
|
||||
self.binds.extend(part.0.iter().cloned().map(Bind::from));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct MruHighlight {
|
||||
pub active_color: Color,
|
||||
pub urgent_color: Color,
|
||||
pub padding: f64,
|
||||
pub corner_radius: f64,
|
||||
}
|
||||
|
||||
impl Default for MruHighlight {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
active_color: Color::new_unpremul(0.6, 0.6, 0.6, 1.),
|
||||
urgent_color: Color::new_unpremul(1., 0.6, 0.6, 1.),
|
||||
padding: 30.,
|
||||
corner_radius: 0.,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(knuffel::Decode, Debug, Default, PartialEq)]
|
||||
pub struct MruHighlightPart {
|
||||
#[knuffel(child)]
|
||||
pub active_color: Option<Color>,
|
||||
#[knuffel(child)]
|
||||
pub urgent_color: Option<Color>,
|
||||
#[knuffel(child, unwrap(argument))]
|
||||
pub padding: Option<FloatOrInt<0, 65535>>,
|
||||
#[knuffel(child, unwrap(argument))]
|
||||
pub corner_radius: Option<FloatOrInt<0, 65535>>,
|
||||
}
|
||||
|
||||
impl MergeWith<MruHighlightPart> for MruHighlight {
|
||||
fn merge_with(&mut self, part: &MruHighlightPart) {
|
||||
merge_clone!((self, part), active_color, urgent_color);
|
||||
merge!((self, part), padding, corner_radius);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct MruPreviews {
|
||||
pub max_height: f64,
|
||||
pub max_scale: f64,
|
||||
}
|
||||
|
||||
impl Default for MruPreviews {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
max_height: 480.,
|
||||
max_scale: 0.5,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(knuffel::Decode, Debug, Default, PartialEq)]
|
||||
pub struct MruPreviewsPart {
|
||||
#[knuffel(child, unwrap(argument))]
|
||||
pub max_height: Option<FloatOrInt<1, 65535>>,
|
||||
#[knuffel(child, unwrap(argument))]
|
||||
pub max_scale: Option<FloatOrInt<0, 1>>,
|
||||
}
|
||||
|
||||
impl MergeWith<MruPreviewsPart> for MruPreviews {
|
||||
fn merge_with(&mut self, part: &MruPreviewsPart) {
|
||||
merge!((self, part), max_height, max_scale);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct MruBind {
|
||||
// MRU bind keys must have a modifier, this is enforced during parsing. The switcher will close
|
||||
// once all modifiers are released.
|
||||
pub key: Key,
|
||||
pub action: MruAction,
|
||||
pub allow_inhibiting: bool,
|
||||
pub hotkey_overlay_title: Option<Option<String>>,
|
||||
}
|
||||
|
||||
impl From<MruBind> for Bind {
|
||||
fn from(x: MruBind) -> Self {
|
||||
Self {
|
||||
key: x.key,
|
||||
action: Action::from(x.action),
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
allow_inhibiting: x.allow_inhibiting,
|
||||
hotkey_overlay_title: x.hotkey_overlay_title,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
||||
pub enum MruDirection {
|
||||
/// Most recently used to least.
|
||||
#[default]
|
||||
Forward,
|
||||
/// Least recently used to most.
|
||||
Backward,
|
||||
}
|
||||
|
||||
#[derive(knuffel::DecodeScalar, Clone, Copy, Debug, Default, PartialEq)]
|
||||
pub enum MruScope {
|
||||
/// All windows.
|
||||
#[default]
|
||||
All,
|
||||
/// Windows on the active output.
|
||||
Output,
|
||||
/// Windows on the active workspace.
|
||||
Workspace,
|
||||
}
|
||||
|
||||
#[derive(knuffel::DecodeScalar, Clone, Copy, Debug, Default, PartialEq)]
|
||||
pub enum MruFilter {
|
||||
/// All windows.
|
||||
#[default]
|
||||
#[knuffel(skip)]
|
||||
All,
|
||||
/// Windows with the same app id as the active window.
|
||||
AppId,
|
||||
}
|
||||
|
||||
#[derive(knuffel::Decode, Debug, Clone, PartialEq)]
|
||||
pub enum MruAction {
|
||||
NextWindow(
|
||||
#[knuffel(property(name = "scope"))] Option<MruScope>,
|
||||
#[knuffel(property(name = "filter"), default)] MruFilter,
|
||||
),
|
||||
PreviousWindow(
|
||||
#[knuffel(property(name = "scope"))] Option<MruScope>,
|
||||
#[knuffel(property(name = "filter"), default)] MruFilter,
|
||||
),
|
||||
}
|
||||
|
||||
impl From<MruAction> for Action {
|
||||
fn from(x: MruAction) -> Self {
|
||||
match x {
|
||||
MruAction::NextWindow(scope, filter) => Self::MruAdvance {
|
||||
direction: MruDirection::Forward,
|
||||
scope,
|
||||
filter: Some(filter),
|
||||
},
|
||||
MruAction::PreviousWindow(scope, filter) => Self::MruAdvance {
|
||||
direction: MruDirection::Backward,
|
||||
scope,
|
||||
filter: Some(filter),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, PartialEq)]
|
||||
pub struct MruBinds(pub Vec<MruBind>);
|
||||
|
||||
fn default_binds() -> Vec<Bind> {
|
||||
let mut rv = Vec::new();
|
||||
|
||||
let mut push = |trigger, base_mod, filter| {
|
||||
rv.push(Bind::from(MruBind {
|
||||
key: Key {
|
||||
trigger: Trigger::Keysym(trigger),
|
||||
modifiers: base_mod,
|
||||
},
|
||||
action: MruAction::NextWindow(None, filter),
|
||||
allow_inhibiting: true,
|
||||
hotkey_overlay_title: None,
|
||||
}));
|
||||
rv.push(Bind::from(MruBind {
|
||||
key: Key {
|
||||
trigger: Trigger::Keysym(trigger),
|
||||
modifiers: base_mod | Modifiers::SHIFT,
|
||||
},
|
||||
action: MruAction::PreviousWindow(None, filter),
|
||||
allow_inhibiting: true,
|
||||
hotkey_overlay_title: None,
|
||||
}));
|
||||
};
|
||||
|
||||
for base_mod in [Modifiers::ALT, Modifiers::COMPOSITOR] {
|
||||
push(Keysym::Tab, base_mod, MruFilter::All);
|
||||
push(Keysym::grave, base_mod, MruFilter::AppId);
|
||||
}
|
||||
|
||||
rv
|
||||
}
|
||||
|
||||
impl<S> knuffel::Decode<S> for MruBinds
|
||||
where
|
||||
S: knuffel::traits::ErrorSpan,
|
||||
{
|
||||
fn decode_node(
|
||||
node: &knuffel::ast::SpannedNode<S>,
|
||||
ctx: &mut knuffel::decode::Context<S>,
|
||||
) -> Result<Self, DecodeError<S>> {
|
||||
expect_only_children(node, ctx);
|
||||
|
||||
let mut seen_keys = HashSet::new();
|
||||
|
||||
let mut binds = Vec::new();
|
||||
|
||||
for child in node.children() {
|
||||
match MruBind::decode_node(child, ctx) {
|
||||
Ok(bind) => {
|
||||
if !seen_keys.insert(bind.key) {
|
||||
ctx.emit_error(DecodeError::unexpected(
|
||||
&child.node_name,
|
||||
"keybind",
|
||||
"duplicate keybind",
|
||||
));
|
||||
continue;
|
||||
}
|
||||
|
||||
binds.push(bind);
|
||||
}
|
||||
Err(e) => {
|
||||
ctx.emit_error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Self(binds))
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> knuffel::Decode<S> for MruBind
|
||||
where
|
||||
S: knuffel::traits::ErrorSpan,
|
||||
{
|
||||
fn decode_node(
|
||||
node: &knuffel::ast::SpannedNode<S>,
|
||||
ctx: &mut knuffel::decode::Context<S>,
|
||||
) -> Result<Self, DecodeError<S>> {
|
||||
if let Some(type_name) = &node.type_name {
|
||||
ctx.emit_error(DecodeError::unexpected(
|
||||
type_name,
|
||||
"type name",
|
||||
"no type name expected for this node",
|
||||
));
|
||||
}
|
||||
|
||||
for val in node.arguments.iter() {
|
||||
ctx.emit_error(DecodeError::unexpected(
|
||||
&val.literal,
|
||||
"argument",
|
||||
"no arguments expected for this node",
|
||||
));
|
||||
}
|
||||
|
||||
let key = node
|
||||
.node_name
|
||||
.parse::<Key>()
|
||||
.map_err(|e| DecodeError::conversion(&node.node_name, e.wrap_err("invalid keybind")))?;
|
||||
|
||||
// A modifier is required because MRU remains on screen as long as any modifier is held.
|
||||
if key.modifiers.is_empty() {
|
||||
ctx.emit_error(DecodeError::unexpected(
|
||||
&node.node_name,
|
||||
"keybind",
|
||||
"keybind must have a modifier key",
|
||||
));
|
||||
}
|
||||
|
||||
// FIXME: To support this, all the mods_with_mouse_binds()/mods_with_wheel_binds()/etc.
|
||||
// will need to learn about recent-windows bindings.
|
||||
if !matches!(key.trigger, Trigger::Keysym(_)) {
|
||||
ctx.emit_error(DecodeError::unexpected(
|
||||
&node.node_name,
|
||||
"key",
|
||||
"key must be a keyboard key (others are unsupported here for now)",
|
||||
));
|
||||
}
|
||||
|
||||
let mut allow_inhibiting = true;
|
||||
let mut hotkey_overlay_title = None;
|
||||
for (name, val) in &node.properties {
|
||||
match &***name {
|
||||
"allow-inhibiting" => {
|
||||
allow_inhibiting = knuffel::traits::DecodeScalar::decode(val, ctx)?;
|
||||
}
|
||||
"hotkey-overlay-title" => {
|
||||
hotkey_overlay_title = Some(knuffel::traits::DecodeScalar::decode(val, ctx)?);
|
||||
}
|
||||
name_str => {
|
||||
ctx.emit_error(DecodeError::unexpected(
|
||||
name,
|
||||
"property",
|
||||
format!("unexpected property `{}`", name_str.escape_default()),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut children = node.children();
|
||||
|
||||
// If the action is invalid but the key is fine, we still want to return something.
|
||||
// That way, the parent can handle the existence of duplicate keybinds,
|
||||
// even if their contents are not valid.
|
||||
let dummy = Self {
|
||||
key,
|
||||
action: MruAction::NextWindow(None, MruFilter::All),
|
||||
allow_inhibiting: true,
|
||||
hotkey_overlay_title: None,
|
||||
};
|
||||
|
||||
if let Some(child) = children.next() {
|
||||
for unwanted_child in children {
|
||||
ctx.emit_error(DecodeError::unexpected(
|
||||
unwanted_child,
|
||||
"node",
|
||||
"only one action is allowed per keybind",
|
||||
));
|
||||
}
|
||||
match MruAction::decode_node(child, ctx) {
|
||||
Ok(action) => Ok(Self {
|
||||
key,
|
||||
action,
|
||||
allow_inhibiting,
|
||||
hotkey_overlay_title,
|
||||
}),
|
||||
Err(e) => {
|
||||
ctx.emit_error(e);
|
||||
Ok(dummy)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ctx.emit_error(DecodeError::missing(
|
||||
node,
|
||||
"expected an action for this keybind",
|
||||
));
|
||||
Ok(dummy)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ const ID_ANNOUNCEMENT: NodeId = NodeId(1);
|
||||
const ID_SCREENSHOT_UI: NodeId = NodeId(2);
|
||||
const ID_EXIT_CONFIRM_DIALOG: NodeId = NodeId(3);
|
||||
const ID_OVERVIEW: NodeId = NodeId(4);
|
||||
const ID_MRU: NodeId = NodeId(5);
|
||||
|
||||
pub struct A11y {
|
||||
event_loop: LoopHandle<'static, State>,
|
||||
@@ -205,6 +206,7 @@ impl Niri {
|
||||
KeyboardFocus::ScreenshotUi => ID_SCREENSHOT_UI,
|
||||
KeyboardFocus::ExitConfirmDialog => ID_EXIT_CONFIRM_DIALOG,
|
||||
KeyboardFocus::Overview => ID_OVERVIEW,
|
||||
KeyboardFocus::Mru => ID_MRU,
|
||||
_ => ID_ROOT,
|
||||
}
|
||||
}
|
||||
@@ -237,12 +239,16 @@ impl Niri {
|
||||
let mut overview = Node::new(Role::Group);
|
||||
overview.set_label("Overview");
|
||||
|
||||
let mut mru = Node::new(Role::Group);
|
||||
mru.set_label("Recent windows");
|
||||
|
||||
let mut root = Node::new(Role::Window);
|
||||
root.set_children(vec![
|
||||
ID_ANNOUNCEMENT,
|
||||
ID_SCREENSHOT_UI,
|
||||
ID_EXIT_CONFIRM_DIALOG,
|
||||
ID_OVERVIEW,
|
||||
ID_MRU,
|
||||
]);
|
||||
|
||||
let tree = Tree {
|
||||
@@ -260,6 +266,7 @@ impl Niri {
|
||||
(ID_SCREENSHOT_UI, screenshot_ui),
|
||||
(ID_EXIT_CONFIRM_DIALOG, exit_confirm_dialog),
|
||||
(ID_OVERVIEW, overview),
|
||||
(ID_MRU, mru),
|
||||
],
|
||||
tree: Some(tree),
|
||||
focus,
|
||||
|
||||
@@ -291,6 +291,7 @@ impl CompositorHandler for State {
|
||||
self.niri
|
||||
.stop_casts_for_target(CastTarget::Window { id: id.get() });
|
||||
|
||||
self.niri.window_mru_ui.remove_window(id);
|
||||
self.niri.layout.remove_window(&window, transaction.clone());
|
||||
self.add_default_dmabuf_pre_commit_hook(surface);
|
||||
|
||||
@@ -311,6 +312,7 @@ impl CompositorHandler for State {
|
||||
|
||||
if let Some(output) = output {
|
||||
self.niri.queue_redraw(&output);
|
||||
self.niri.queue_redraw_mru_output();
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -337,6 +339,7 @@ impl CompositorHandler for State {
|
||||
}
|
||||
|
||||
// The toplevel remains mapped.
|
||||
self.niri.window_mru_ui.update_window(&self.niri.layout, id);
|
||||
self.niri.layout.update_window(&window, serial);
|
||||
|
||||
// Move the toplevel according to the attach offset.
|
||||
@@ -357,6 +360,7 @@ impl CompositorHandler for State {
|
||||
|
||||
if let Some(output) = output {
|
||||
self.niri.queue_redraw(&output);
|
||||
self.niri.queue_redraw_mru_output();
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -370,9 +374,13 @@ impl CompositorHandler for State {
|
||||
let window = mapped.window.clone();
|
||||
let output = output.cloned();
|
||||
window.on_commit();
|
||||
self.niri
|
||||
.window_mru_ui
|
||||
.update_window(&self.niri.layout, mapped.id());
|
||||
self.niri.layout.update_window(&window, None);
|
||||
if let Some(output) = output {
|
||||
self.niri.queue_redraw(&output);
|
||||
self.niri.queue_redraw_mru_output();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -864,9 +864,9 @@ impl XdgShellHandler for State {
|
||||
let window = mapped.window.clone();
|
||||
let output = output.cloned();
|
||||
|
||||
self.niri.stop_casts_for_target(CastTarget::Window {
|
||||
id: mapped.id().get(),
|
||||
});
|
||||
let id = mapped.id();
|
||||
self.niri
|
||||
.stop_casts_for_target(CastTarget::Window { id: id.get() });
|
||||
|
||||
self.backend.with_primary_renderer(|renderer| {
|
||||
self.niri.layout.store_unmap_snapshot(renderer, &window);
|
||||
@@ -883,6 +883,7 @@ impl XdgShellHandler for State {
|
||||
let active_window = self.niri.layout.focus().map(|m| &m.window);
|
||||
let was_active = active_window == Some(&window);
|
||||
|
||||
self.niri.window_mru_ui.remove_window(id);
|
||||
self.niri.layout.remove_window(&window, transaction.clone());
|
||||
self.add_default_dmabuf_pre_commit_hook(surface.wl_surface());
|
||||
|
||||
@@ -898,6 +899,7 @@ impl XdgShellHandler for State {
|
||||
|
||||
if let Some(output) = output {
|
||||
self.niri.queue_redraw(&output);
|
||||
self.niri.queue_redraw_mru_output();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+303
-70
@@ -6,7 +6,9 @@ use std::time::Duration;
|
||||
|
||||
use calloop::timer::{TimeoutAction, Timer};
|
||||
use input::event::gesture::GestureEventCoordinates as _;
|
||||
use niri_config::{Action, Bind, Binds, Key, ModKey, Modifiers, SwitchBinds, Trigger};
|
||||
use niri_config::{
|
||||
Action, Bind, Binds, Config, Key, ModKey, Modifiers, MruDirection, SwitchBinds, Trigger,
|
||||
};
|
||||
use niri_ipc::LayoutSwitchTarget;
|
||||
use smithay::backend::input::{
|
||||
AbsolutePositionEvent, Axis, AxisSource, ButtonState, Device, DeviceCapability, Event,
|
||||
@@ -43,6 +45,7 @@ use self::spatial_movement_grab::SpatialMovementGrab;
|
||||
use crate::layout::scrolling::ScrollDirection;
|
||||
use crate::layout::{ActivateWindow, LayoutElement as _};
|
||||
use crate::niri::{CastTarget, PointerVisibility, State};
|
||||
use crate::ui::mru::{WindowMru, WindowMruUi};
|
||||
use crate::ui::screenshot_ui::ScreenshotUi;
|
||||
use crate::utils::spawning::{spawn, spawn_sh};
|
||||
use crate::utils::{center, get_monotonic_time, ResizeEdge};
|
||||
@@ -385,6 +388,7 @@ impl State {
|
||||
let key_code = event.key_code();
|
||||
let modified = keysym.modified_sym();
|
||||
let raw = keysym.raw_latin_sym_or_raw_current_sym();
|
||||
let modifiers = modifiers_from_state(*mods);
|
||||
|
||||
if this.niri.exit_confirm_dialog.is_open() && pressed {
|
||||
if raw == Some(Keysym::Return) {
|
||||
@@ -397,6 +401,18 @@ impl State {
|
||||
return FilterResult::Intercept(None);
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
if this.niri.suppressed_keys.remove(&key_code) {
|
||||
return FilterResult::Intercept(None);
|
||||
} else {
|
||||
return FilterResult::Forward;
|
||||
}
|
||||
}
|
||||
|
||||
if pressed
|
||||
&& raw == Some(Keysym::Escape)
|
||||
&& (this.niri.pick_window.is_some() || this.niri.pick_color.is_some())
|
||||
@@ -416,20 +432,25 @@ impl State {
|
||||
this.niri.screenshot_ui.set_space_down(pressed);
|
||||
}
|
||||
|
||||
let bindings = &this.niri.config.borrow().binds;
|
||||
let res = should_intercept_key(
|
||||
&mut this.niri.suppressed_keys,
|
||||
&bindings.0,
|
||||
mod_key,
|
||||
key_code,
|
||||
modified,
|
||||
raw,
|
||||
pressed,
|
||||
*mods,
|
||||
&this.niri.screenshot_ui,
|
||||
this.niri.config.borrow().input.disable_power_key_handling,
|
||||
is_inhibiting_shortcuts,
|
||||
);
|
||||
let res = {
|
||||
let config = this.niri.config.borrow();
|
||||
let bindings =
|
||||
make_binds_iter(&config, &mut this.niri.window_mru_ui, modifiers);
|
||||
|
||||
should_intercept_key(
|
||||
&mut this.niri.suppressed_keys,
|
||||
bindings,
|
||||
mod_key,
|
||||
key_code,
|
||||
modified,
|
||||
raw,
|
||||
pressed,
|
||||
*mods,
|
||||
&this.niri.screenshot_ui,
|
||||
this.niri.config.borrow().input.disable_power_key_handling,
|
||||
is_inhibiting_shortcuts,
|
||||
)
|
||||
};
|
||||
|
||||
if matches!(res, FilterResult::Forward) {
|
||||
// If we didn't find any bind, try other hardcoded keys.
|
||||
@@ -440,6 +461,10 @@ impl State {
|
||||
return FilterResult::Intercept(Some(bind));
|
||||
}
|
||||
}
|
||||
|
||||
// Interaction with the active window, immediately update the active window's
|
||||
// focus timestamp without waiting for a possible pending MRU lock-in delay.
|
||||
this.niri.mru_apply_keyboard_commit();
|
||||
}
|
||||
|
||||
res
|
||||
@@ -641,6 +666,7 @@ impl State {
|
||||
}
|
||||
Action::Screenshot(show_cursor, path) => {
|
||||
self.open_screenshot_ui(show_cursor, path);
|
||||
self.niri.cancel_mru();
|
||||
}
|
||||
Action::ScreenshotWindow(write_to_disk, path) => {
|
||||
let focus = self.niri.layout.focus_with_output();
|
||||
@@ -2179,6 +2205,90 @@ impl State {
|
||||
watcher.load_config();
|
||||
}
|
||||
}
|
||||
Action::MruConfirm => {
|
||||
self.confirm_mru();
|
||||
}
|
||||
Action::MruCancel => {
|
||||
self.niri.cancel_mru();
|
||||
}
|
||||
Action::MruAdvance {
|
||||
direction,
|
||||
scope,
|
||||
filter,
|
||||
} => {
|
||||
if self.niri.window_mru_ui.is_open() {
|
||||
self.niri.window_mru_ui.advance(direction, filter);
|
||||
self.niri.queue_redraw_mru_output();
|
||||
} else if self.niri.config.borrow().recent_windows.on {
|
||||
self.niri.mru_apply_keyboard_commit();
|
||||
|
||||
let config = self.niri.config.borrow();
|
||||
let scope = scope.unwrap_or(self.niri.window_mru_ui.scope());
|
||||
|
||||
let mut wmru = WindowMru::new(&self.niri);
|
||||
if !wmru.is_empty() {
|
||||
wmru.set_scope(scope);
|
||||
if let Some(filter) = filter {
|
||||
wmru.set_filter(filter);
|
||||
}
|
||||
|
||||
if let Some(output) = self.niri.layout.active_output() {
|
||||
self.niri.window_mru_ui.open(
|
||||
self.niri.clock.clone(),
|
||||
wmru,
|
||||
output.clone(),
|
||||
);
|
||||
|
||||
// Only select the *next* window if some window (which should be the
|
||||
// first one) is already focused. If nothing is focused, keep the first
|
||||
// window (which is logically the "previously selected" one).
|
||||
let keep_first = direction == MruDirection::Forward
|
||||
&& self.niri.layout.focus().is_none();
|
||||
if !keep_first {
|
||||
self.niri.window_mru_ui.advance(direction, None);
|
||||
}
|
||||
|
||||
drop(config);
|
||||
self.niri.queue_redraw_all();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Action::MruCloseCurrentWindow => {
|
||||
if self.niri.window_mru_ui.is_open() {
|
||||
if let Some(id) = self.niri.window_mru_ui.current_window_id() {
|
||||
if let Some(w) = self.niri.find_window_by_id(id) {
|
||||
if let Some(tl) = w.toplevel() {
|
||||
tl.send_close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Action::MruFirst => {
|
||||
if self.niri.window_mru_ui.is_open() {
|
||||
self.niri.window_mru_ui.first();
|
||||
self.niri.queue_redraw_mru_output();
|
||||
}
|
||||
}
|
||||
Action::MruLast => {
|
||||
if self.niri.window_mru_ui.is_open() {
|
||||
self.niri.window_mru_ui.last();
|
||||
self.niri.queue_redraw_mru_output();
|
||||
}
|
||||
}
|
||||
Action::MruSetScope(scope) => {
|
||||
if self.niri.window_mru_ui.is_open() {
|
||||
self.niri.window_mru_ui.set_scope(scope);
|
||||
self.niri.queue_redraw_mru_output();
|
||||
}
|
||||
}
|
||||
Action::MruCycleScope => {
|
||||
if self.niri.window_mru_ui.is_open() {
|
||||
self.niri.window_mru_ui.cycle_scope();
|
||||
self.niri.queue_redraw_mru_output();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2301,6 +2411,14 @@ impl State {
|
||||
self.niri.screenshot_ui.pointer_motion(point, None);
|
||||
}
|
||||
|
||||
if let Some(mru_output) = self.niri.window_mru_ui.output() {
|
||||
if let Some((output, pos_within_output)) = self.niri.output_under(new_pos) {
|
||||
if mru_output == output {
|
||||
self.niri.window_mru_ui.pointer_motion(pos_within_output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let under = self.niri.contents_under(new_pos);
|
||||
|
||||
// Handle confined pointer.
|
||||
@@ -2431,6 +2549,14 @@ impl State {
|
||||
self.niri.screenshot_ui.pointer_motion(point, None);
|
||||
}
|
||||
|
||||
if let Some(mru_output) = self.niri.window_mru_ui.output() {
|
||||
if let Some((output, pos_within_output)) = self.niri.output_under(pos) {
|
||||
if mru_output == output {
|
||||
self.niri.window_mru_ui.pointer_motion(pos_within_output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let under = self.niri.contents_under(pos);
|
||||
|
||||
self.niri.handle_focus_follows_mouse(&under);
|
||||
@@ -2509,7 +2635,29 @@ impl State {
|
||||
let mods = self.niri.seat.get_keyboard().unwrap().modifier_state();
|
||||
let modifiers = modifiers_from_state(mods);
|
||||
|
||||
if self.niri.mods_with_mouse_binds.contains(&modifiers) {
|
||||
let mut is_mru_open = false;
|
||||
if let Some(mru_output) = self.niri.window_mru_ui.output() {
|
||||
is_mru_open = true;
|
||||
if let Some(MouseButton::Left) = button {
|
||||
let location = pointer.current_location();
|
||||
let (output, pos_within_output) = self.niri.output_under(location).unwrap();
|
||||
if mru_output == output {
|
||||
let id = self.niri.window_mru_ui.pointer_motion(pos_within_output);
|
||||
if id.is_some() {
|
||||
self.confirm_mru();
|
||||
} else {
|
||||
self.niri.cancel_mru();
|
||||
}
|
||||
} else {
|
||||
self.niri.cancel_mru();
|
||||
}
|
||||
|
||||
self.niri.suppressed_buttons.insert(button_code);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if is_mru_open || self.niri.mods_with_mouse_binds.contains(&modifiers) {
|
||||
if let Some(bind) = match button {
|
||||
Some(MouseButton::Left) => Some(Trigger::MouseLeft),
|
||||
Some(MouseButton::Right) => Some(Trigger::MouseRight),
|
||||
@@ -2520,7 +2668,8 @@ impl State {
|
||||
}
|
||||
.and_then(|trigger| {
|
||||
let config = self.niri.config.borrow();
|
||||
let bindings = &config.binds.0;
|
||||
let bindings =
|
||||
make_binds_iter(&config, &mut self.niri.window_mru_ui, modifiers);
|
||||
find_configured_bind(bindings, mod_key, trigger, mods)
|
||||
}) {
|
||||
self.niri.suppressed_buttons.insert(button_code);
|
||||
@@ -2824,59 +2973,66 @@ impl State {
|
||||
false
|
||||
};
|
||||
|
||||
let is_mru_open = self.niri.window_mru_ui.is_open();
|
||||
|
||||
// Handle wheel scroll bindings.
|
||||
if source == AxisSource::Wheel {
|
||||
// If we have a scroll bind with current modifiers, then accumulate and don't pass to
|
||||
// Wayland. If there's no bind, reset the accumulator.
|
||||
let mods = self.niri.seat.get_keyboard().unwrap().modifier_state();
|
||||
let modifiers = modifiers_from_state(mods);
|
||||
let should_handle =
|
||||
should_handle_in_overview || self.niri.mods_with_wheel_binds.contains(&modifiers);
|
||||
let should_handle = should_handle_in_overview
|
||||
|| is_mru_open
|
||||
|| self.niri.mods_with_wheel_binds.contains(&modifiers);
|
||||
if should_handle {
|
||||
let horizontal = horizontal_amount_v120.unwrap_or(0.);
|
||||
let ticks = self.niri.horizontal_wheel_tracker.accumulate(horizontal);
|
||||
if ticks != 0 {
|
||||
let (bind_left, bind_right) = if should_handle_in_overview
|
||||
&& modifiers.is_empty()
|
||||
{
|
||||
let bind_left = Some(Bind {
|
||||
key: Key {
|
||||
trigger: Trigger::WheelScrollLeft,
|
||||
modifiers: Modifiers::empty(),
|
||||
},
|
||||
action: Action::FocusColumnLeftUnderMouse,
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
allow_inhibiting: false,
|
||||
hotkey_overlay_title: None,
|
||||
});
|
||||
let bind_right = Some(Bind {
|
||||
key: Key {
|
||||
trigger: Trigger::WheelScrollRight,
|
||||
modifiers: Modifiers::empty(),
|
||||
},
|
||||
action: Action::FocusColumnRightUnderMouse,
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
allow_inhibiting: false,
|
||||
hotkey_overlay_title: None,
|
||||
});
|
||||
(bind_left, bind_right)
|
||||
} else {
|
||||
let config = self.niri.config.borrow();
|
||||
let bindings = &config.binds.0;
|
||||
let bind_left =
|
||||
find_configured_bind(bindings, mod_key, Trigger::WheelScrollLeft, mods);
|
||||
let bind_right = find_configured_bind(
|
||||
bindings,
|
||||
mod_key,
|
||||
Trigger::WheelScrollRight,
|
||||
mods,
|
||||
);
|
||||
(bind_left, bind_right)
|
||||
};
|
||||
let (bind_left, bind_right) =
|
||||
if should_handle_in_overview && modifiers.is_empty() {
|
||||
let bind_left = Some(Bind {
|
||||
key: Key {
|
||||
trigger: Trigger::WheelScrollLeft,
|
||||
modifiers: Modifiers::empty(),
|
||||
},
|
||||
action: Action::FocusColumnLeftUnderMouse,
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
allow_inhibiting: false,
|
||||
hotkey_overlay_title: None,
|
||||
});
|
||||
let bind_right = Some(Bind {
|
||||
key: Key {
|
||||
trigger: Trigger::WheelScrollRight,
|
||||
modifiers: Modifiers::empty(),
|
||||
},
|
||||
action: Action::FocusColumnRightUnderMouse,
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
allow_inhibiting: false,
|
||||
hotkey_overlay_title: None,
|
||||
});
|
||||
(bind_left, bind_right)
|
||||
} else {
|
||||
let config = self.niri.config.borrow();
|
||||
let bindings =
|
||||
make_binds_iter(&config, &mut self.niri.window_mru_ui, modifiers);
|
||||
let bind_left = find_configured_bind(
|
||||
bindings.clone(),
|
||||
mod_key,
|
||||
Trigger::WheelScrollLeft,
|
||||
mods,
|
||||
);
|
||||
let bind_right = find_configured_bind(
|
||||
bindings,
|
||||
mod_key,
|
||||
Trigger::WheelScrollRight,
|
||||
mods,
|
||||
);
|
||||
(bind_left, bind_right)
|
||||
};
|
||||
|
||||
if let Some(right) = bind_right {
|
||||
for _ in 0..ticks {
|
||||
@@ -2948,9 +3104,14 @@ impl State {
|
||||
(bind_up, bind_down)
|
||||
} else {
|
||||
let config = self.niri.config.borrow();
|
||||
let bindings = &config.binds.0;
|
||||
let bind_up =
|
||||
find_configured_bind(bindings, mod_key, Trigger::WheelScrollUp, mods);
|
||||
let bindings =
|
||||
make_binds_iter(&config, &mut self.niri.window_mru_ui, modifiers);
|
||||
let bind_up = find_configured_bind(
|
||||
bindings.clone(),
|
||||
mod_key,
|
||||
Trigger::WheelScrollUp,
|
||||
mods,
|
||||
);
|
||||
let bind_down =
|
||||
find_configured_bind(bindings, mod_key, Trigger::WheelScrollDown, mods);
|
||||
(bind_up, bind_down)
|
||||
@@ -3081,16 +3242,21 @@ impl State {
|
||||
}
|
||||
}
|
||||
|
||||
if self.niri.mods_with_finger_scroll_binds.contains(&modifiers) {
|
||||
if is_mru_open || self.niri.mods_with_finger_scroll_binds.contains(&modifiers) {
|
||||
let ticks = self
|
||||
.niri
|
||||
.horizontal_finger_scroll_tracker
|
||||
.accumulate(horizontal);
|
||||
if ticks != 0 {
|
||||
let config = self.niri.config.borrow();
|
||||
let bindings = &config.binds.0;
|
||||
let bind_left =
|
||||
find_configured_bind(bindings, mod_key, Trigger::TouchpadScrollLeft, mods);
|
||||
let bindings =
|
||||
make_binds_iter(&config, &mut self.niri.window_mru_ui, modifiers);
|
||||
let bind_left = find_configured_bind(
|
||||
bindings.clone(),
|
||||
mod_key,
|
||||
Trigger::TouchpadScrollLeft,
|
||||
mods,
|
||||
);
|
||||
let bind_right =
|
||||
find_configured_bind(bindings, mod_key, Trigger::TouchpadScrollRight, mods);
|
||||
drop(config);
|
||||
@@ -3113,9 +3279,14 @@ impl State {
|
||||
.accumulate(vertical);
|
||||
if ticks != 0 {
|
||||
let config = self.niri.config.borrow();
|
||||
let bindings = &config.binds.0;
|
||||
let bind_up =
|
||||
find_configured_bind(bindings, mod_key, Trigger::TouchpadScrollUp, mods);
|
||||
let bindings =
|
||||
make_binds_iter(&config, &mut self.niri.window_mru_ui, modifiers);
|
||||
let bind_up = find_configured_bind(
|
||||
bindings.clone(),
|
||||
mod_key,
|
||||
Trigger::TouchpadScrollUp,
|
||||
mods,
|
||||
);
|
||||
let bind_down =
|
||||
find_configured_bind(bindings, mod_key, Trigger::TouchpadScrollDown, mods);
|
||||
drop(config);
|
||||
@@ -3234,6 +3405,14 @@ impl State {
|
||||
self.niri.screenshot_ui.pointer_motion(point, None);
|
||||
}
|
||||
|
||||
if let Some(mru_output) = self.niri.window_mru_ui.output() {
|
||||
if let Some((output, pos_within_output)) = self.niri.output_under(pos) {
|
||||
if mru_output == output {
|
||||
self.niri.window_mru_ui.pointer_motion(pos_within_output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let under = self.niri.contents_under(pos);
|
||||
|
||||
let tablet_seat = self.niri.seat.tablet_seat();
|
||||
@@ -3311,6 +3490,19 @@ impl State {
|
||||
self.niri.queue_redraw_all();
|
||||
}
|
||||
}
|
||||
} else if let Some(mru_output) = self.niri.window_mru_ui.output() {
|
||||
if let Some((output, pos_within_output)) = self.niri.output_under(pos) {
|
||||
if mru_output == output {
|
||||
let id = self.niri.window_mru_ui.pointer_motion(pos_within_output);
|
||||
if id.is_some() {
|
||||
self.confirm_mru();
|
||||
} else {
|
||||
self.niri.cancel_mru();
|
||||
}
|
||||
} else {
|
||||
self.niri.cancel_mru();
|
||||
}
|
||||
}
|
||||
} else if let Some((window, _)) = under.window {
|
||||
if let Some(output) = is_overview_open.then_some(under.output).flatten() {
|
||||
let mut workspaces = self.niri.layout.workspaces();
|
||||
@@ -3425,6 +3617,11 @@ impl State {
|
||||
}
|
||||
|
||||
fn on_gesture_swipe_begin<I: InputBackend>(&mut self, event: I::GestureSwipeBeginEvent) {
|
||||
if self.niri.window_mru_ui.is_open() {
|
||||
// Don't start swipe gestures while in the MRU.
|
||||
return;
|
||||
}
|
||||
|
||||
if event.fingers() == 3 {
|
||||
self.niri.gesture_swipe_3f_cumulative = Some((0., 0.));
|
||||
|
||||
@@ -3772,6 +3969,19 @@ impl State {
|
||||
self.niri.queue_redraw_all();
|
||||
}
|
||||
}
|
||||
} else if let Some(mru_output) = self.niri.window_mru_ui.output() {
|
||||
if let Some((output, pos_within_output)) = self.niri.output_under(pos) {
|
||||
if mru_output == output {
|
||||
let id = self.niri.window_mru_ui.pointer_motion(pos_within_output);
|
||||
if id.is_some() {
|
||||
self.confirm_mru();
|
||||
} else {
|
||||
self.niri.cancel_mru();
|
||||
}
|
||||
} else {
|
||||
self.niri.cancel_mru();
|
||||
}
|
||||
}
|
||||
} else if !handle.is_grabbed() {
|
||||
let mods = self.niri.seat.get_keyboard().unwrap().modifier_state();
|
||||
let mods = modifiers_from_state(mods);
|
||||
@@ -4696,6 +4906,29 @@ fn grab_allows_hot_corner(grab: &(dyn PointerGrab<State> + 'static)) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
/// Returns an iterator over bindings.
|
||||
///
|
||||
/// Includes dynamically populated bindings like the MRU UI.
|
||||
fn make_binds_iter<'a>(
|
||||
config: &'a Config,
|
||||
mru: &'a mut WindowMruUi,
|
||||
mods: Modifiers,
|
||||
) -> impl Iterator<Item = &'a Bind> + Clone {
|
||||
// Figure out the binds to use depending on whether the MRU is enabled and/or open.
|
||||
let general_binds = (!mru.is_open()).then_some(config.binds.0.iter());
|
||||
let general_binds = general_binds.into_iter().flatten();
|
||||
|
||||
let mru_binds =
|
||||
(config.recent_windows.on || mru.is_open()).then_some(config.recent_windows.binds.iter());
|
||||
let mru_binds = mru_binds.into_iter().flatten();
|
||||
|
||||
let mru_open_binds = mru.is_open().then(|| mru.opened_bindings(mods));
|
||||
let mru_open_binds = mru_open_binds.into_iter().flatten();
|
||||
|
||||
// MRU binds take precedence over general ones.
|
||||
mru_binds.chain(mru_open_binds).chain(general_binds)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::cell::Cell;
|
||||
|
||||
+150
-4
@@ -16,7 +16,7 @@ use calloop::futures::Scheduler;
|
||||
use niri_config::debug::PreviewRender;
|
||||
use niri_config::{
|
||||
Config, FloatOrInt, Key, Modifiers, OutputName, TrackLayout, WarpMouseToFocusMode,
|
||||
WorkspaceReference, Xkb,
|
||||
WorkspaceReference, Xkb, DEFAULT_MRU_COMMIT_MS,
|
||||
};
|
||||
use smithay::backend::allocator::Fourcc;
|
||||
use smithay::backend::input::Keycode;
|
||||
@@ -165,6 +165,7 @@ use crate::render_helpers::{
|
||||
use crate::ui::config_error_notification::ConfigErrorNotification;
|
||||
use crate::ui::exit_confirm_dialog::{ExitConfirmDialog, ExitConfirmDialogRenderElement};
|
||||
use crate::ui::hotkey_overlay::HotkeyOverlay;
|
||||
use crate::ui::mru::{MruCloseRequest, WindowMruUi, WindowMruUiRenderElement};
|
||||
use crate::ui::screen_transition::{self, ScreenTransition};
|
||||
use crate::ui::screenshot_ui::{OutputScreenshot, ScreenshotUi, ScreenshotUiRenderElement};
|
||||
use crate::utils::scale::{closest_representable_scale, guess_monitor_scale};
|
||||
@@ -384,6 +385,9 @@ pub struct Niri {
|
||||
pub hotkey_overlay: HotkeyOverlay,
|
||||
pub exit_confirm_dialog: ExitConfirmDialog,
|
||||
|
||||
pub window_mru_ui: WindowMruUi,
|
||||
pub pending_mru_commit: Option<PendingMruCommit>,
|
||||
|
||||
pub pick_window: Option<async_channel::Sender<Option<MappedId>>>,
|
||||
pub pick_color: Option<async_channel::Sender<Option<niri_ipc::PickedColor>>>,
|
||||
|
||||
@@ -520,6 +524,7 @@ pub enum KeyboardFocus {
|
||||
ScreenshotUi,
|
||||
ExitConfirmDialog,
|
||||
Overview,
|
||||
Mru,
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, PartialEq)]
|
||||
@@ -582,6 +587,14 @@ pub enum CastTarget {
|
||||
Window { id: u64 },
|
||||
}
|
||||
|
||||
/// Pending update to a window's focus timestamp.
|
||||
#[derive(Debug)]
|
||||
pub struct PendingMruCommit {
|
||||
id: MappedId,
|
||||
token: RegistrationToken,
|
||||
stamp: Duration,
|
||||
}
|
||||
|
||||
impl RedrawState {
|
||||
fn queue_redraw(self) -> Self {
|
||||
match self {
|
||||
@@ -620,6 +633,7 @@ impl KeyboardFocus {
|
||||
KeyboardFocus::ScreenshotUi => None,
|
||||
KeyboardFocus::ExitConfirmDialog => None,
|
||||
KeyboardFocus::Overview => None,
|
||||
KeyboardFocus::Mru => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -631,6 +645,7 @@ impl KeyboardFocus {
|
||||
KeyboardFocus::ScreenshotUi => None,
|
||||
KeyboardFocus::ExitConfirmDialog => None,
|
||||
KeyboardFocus::Overview => None,
|
||||
KeyboardFocus::Mru => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -939,6 +954,12 @@ impl State {
|
||||
self.niri.queue_redraw_all();
|
||||
}
|
||||
|
||||
pub fn confirm_mru(&mut self) {
|
||||
if let Some(window) = self.niri.close_mru(MruCloseRequest::Confirm) {
|
||||
self.focus_window(&window);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn maybe_warp_cursor_to_focus(&mut self) -> bool {
|
||||
let focused = match self.niri.config.borrow().input.warp_mouse_to_focus {
|
||||
None => return false,
|
||||
@@ -1099,6 +1120,8 @@ impl State {
|
||||
}
|
||||
} else if self.niri.screenshot_ui.is_open() {
|
||||
KeyboardFocus::ScreenshotUi
|
||||
} else if self.niri.window_mru_ui.is_open() {
|
||||
KeyboardFocus::Mru
|
||||
} else if let Some(output) = self.niri.layout.active_output() {
|
||||
let mon = self.niri.layout.monitor_for_output(output).unwrap();
|
||||
let layers = layer_map_for_output(output);
|
||||
@@ -1225,6 +1248,38 @@ impl State {
|
||||
{
|
||||
if let Some((mapped, _)) = self.niri.layout.find_window_and_output_mut(surface) {
|
||||
mapped.set_is_focused(true);
|
||||
|
||||
// If `mapped` does not have a focus timestamp, then the window is newly
|
||||
// created/mapped and a timestamp is unconditionally created.
|
||||
//
|
||||
// If `mapped` already has a timestamp only update it after the focus lock-in
|
||||
// period has gone by without the focus having elsewhere.
|
||||
let stamp = get_monotonic_time();
|
||||
|
||||
if mapped.get_focus_timestamp().is_none() {
|
||||
mapped.set_focus_timestamp(stamp);
|
||||
} else {
|
||||
let timer =
|
||||
Timer::from_duration(Duration::from_millis(DEFAULT_MRU_COMMIT_MS));
|
||||
|
||||
let focus_token = self
|
||||
.niri
|
||||
.event_loop
|
||||
.insert_source(timer, move |_, _, state| {
|
||||
state.niri.mru_apply_keyboard_commit();
|
||||
TimeoutAction::Drop
|
||||
})
|
||||
.unwrap();
|
||||
if let Some(PendingMruCommit { token, .. }) =
|
||||
self.niri.pending_mru_commit.replace(PendingMruCommit {
|
||||
id: mapped.id(),
|
||||
token: focus_token,
|
||||
stamp,
|
||||
})
|
||||
{
|
||||
self.niri.event_loop.remove(token);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1411,6 +1466,7 @@ impl State {
|
||||
let mut layer_rules_changed = false;
|
||||
let mut shaders_changed = false;
|
||||
let mut cursor_inactivity_timeout_changed = false;
|
||||
let mut recent_windows_changed = false;
|
||||
let mut xwls_changed = false;
|
||||
let mut old_config = self.niri.config.borrow_mut();
|
||||
|
||||
@@ -1459,8 +1515,9 @@ impl State {
|
||||
preserved_output_config = Some(mem::take(&mut old_config.outputs));
|
||||
}
|
||||
|
||||
let binds_changed = config.binds != old_config.binds;
|
||||
let new_mod_key = self.backend.mod_key(&config);
|
||||
if new_mod_key != self.backend.mod_key(&old_config) || config.binds != old_config.binds {
|
||||
if new_mod_key != self.backend.mod_key(&old_config) || binds_changed {
|
||||
self.niri
|
||||
.hotkey_overlay
|
||||
.on_hotkey_config_updated(new_mod_key);
|
||||
@@ -1530,6 +1587,10 @@ impl State {
|
||||
output_config_changed = true;
|
||||
}
|
||||
|
||||
if config.recent_windows != old_config.recent_windows {
|
||||
recent_windows_changed = true;
|
||||
}
|
||||
|
||||
if config.xwayland_satellite != old_config.xwayland_satellite {
|
||||
xwls_changed = true;
|
||||
}
|
||||
@@ -1600,6 +1661,14 @@ impl State {
|
||||
self.niri.reset_pointer_inactivity_timer();
|
||||
}
|
||||
|
||||
if binds_changed {
|
||||
self.niri.window_mru_ui.update_binds();
|
||||
}
|
||||
|
||||
if recent_windows_changed {
|
||||
self.niri.window_mru_ui.update_config();
|
||||
}
|
||||
|
||||
if xwls_changed {
|
||||
// If xwl-s was previously working and is now off, we don't try to kill it or stop
|
||||
// watching the sockets, for simplicity's sake.
|
||||
@@ -2552,6 +2621,7 @@ impl Niri {
|
||||
let mods_with_finger_scroll_binds = mods_with_finger_scroll_binds(mod_key, &config_.binds);
|
||||
|
||||
let screenshot_ui = ScreenshotUi::new(animation_clock.clone(), config.clone());
|
||||
let window_mru_ui = WindowMruUi::new(config.clone());
|
||||
let config_error_notification =
|
||||
ConfigErrorNotification::new(animation_clock.clone(), config.clone());
|
||||
|
||||
@@ -2753,6 +2823,9 @@ impl Niri {
|
||||
hotkey_overlay,
|
||||
exit_confirm_dialog,
|
||||
|
||||
window_mru_ui,
|
||||
pending_mru_commit: None,
|
||||
|
||||
pick_window: None,
|
||||
pick_color: None,
|
||||
|
||||
@@ -3109,6 +3182,10 @@ impl Niri {
|
||||
.set_cursor_image(CursorImageStatus::default_named());
|
||||
self.queue_redraw_all();
|
||||
}
|
||||
|
||||
if self.window_mru_ui.output() == Some(output) {
|
||||
self.cancel_mru();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn output_resized(&mut self, output: &Output) {
|
||||
@@ -3376,7 +3453,11 @@ impl Niri {
|
||||
/// The cursor may be inside the window's activation region, but not within the window's input
|
||||
/// region.
|
||||
pub fn window_under(&self, pos: Point<f64, Logical>) -> Option<&Mapped> {
|
||||
if self.exit_confirm_dialog.is_open() || self.is_locked() || self.screenshot_ui.is_open() {
|
||||
if self.exit_confirm_dialog.is_open()
|
||||
|| self.is_locked()
|
||||
|| self.screenshot_ui.is_open()
|
||||
|| self.window_mru_ui.is_open()
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
@@ -3455,7 +3536,7 @@ impl Niri {
|
||||
return rv;
|
||||
}
|
||||
|
||||
if self.screenshot_ui.is_open() {
|
||||
if self.screenshot_ui.is_open() || self.window_mru_ui.is_open() {
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -3732,6 +3813,13 @@ impl Niri {
|
||||
Some((target_output.cloned(), target_workspace_index))
|
||||
}
|
||||
|
||||
pub fn find_window_by_id(&self, id: MappedId) -> Option<Window> {
|
||||
self.layout
|
||||
.windows()
|
||||
.find(|(_, m)| m.id() == id)
|
||||
.map(|(_, m)| m.window.clone())
|
||||
}
|
||||
|
||||
pub fn output_for_tablet(&self) -> Option<&Output> {
|
||||
let config = self.config.borrow();
|
||||
let map_to_output = config.input.tablet.map_to_output.as_ref();
|
||||
@@ -4059,6 +4147,7 @@ impl Niri {
|
||||
KeyboardFocus::ScreenshotUi => true,
|
||||
KeyboardFocus::ExitConfirmDialog => true,
|
||||
KeyboardFocus::Overview => true,
|
||||
KeyboardFocus::Mru => true,
|
||||
};
|
||||
|
||||
self.layout.refresh(layout_is_active);
|
||||
@@ -4190,6 +4279,7 @@ impl Niri {
|
||||
self.config_error_notification.advance_animations();
|
||||
self.exit_confirm_dialog.advance_animations();
|
||||
self.screenshot_ui.advance_animations();
|
||||
self.window_mru_ui.advance_animations();
|
||||
|
||||
for state in self.output_state.values_mut() {
|
||||
if let Some(transition) = &mut state.screen_transition {
|
||||
@@ -4346,6 +4436,15 @@ impl Niri {
|
||||
elements.push(element.into());
|
||||
}
|
||||
|
||||
// Then, the Alt-Tab switcher.
|
||||
let mru_elements = self
|
||||
.window_mru_ui
|
||||
.render_output(self, output, renderer, target)
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.map(OutputRenderElements::from);
|
||||
elements.extend(mru_elements);
|
||||
|
||||
// Don't draw the focus ring on the workspaces while interactively moving above those
|
||||
// workspaces, since the interactively-moved window already has a focus ring.
|
||||
let focus_ring = !self.layout.interactive_move_is_moving_above_output(output);
|
||||
@@ -4537,6 +4636,7 @@ impl Niri {
|
||||
self.config_error_notification.are_animations_ongoing();
|
||||
state.unfinished_animations_remain |= self.exit_confirm_dialog.are_animations_ongoing();
|
||||
state.unfinished_animations_remain |= self.screenshot_ui.are_animations_ongoing();
|
||||
state.unfinished_animations_remain |= self.window_mru_ui.are_animations_ongoing();
|
||||
state.unfinished_animations_remain |= state.screen_transition.is_some();
|
||||
|
||||
// Also keep redrawing if the current cursor is animated.
|
||||
@@ -5923,6 +6023,7 @@ impl Niri {
|
||||
self.screenshot_ui.close();
|
||||
self.cursor_manager
|
||||
.set_cursor_image(CursorImageStatus::default_named());
|
||||
self.cancel_mru();
|
||||
|
||||
if self.output_state.is_empty() {
|
||||
// There are no outputs, lock the session right away.
|
||||
@@ -6181,6 +6282,10 @@ impl Niri {
|
||||
return;
|
||||
}
|
||||
|
||||
if self.window_mru_ui.is_open() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Recompute the current pointer focus because we don't update it during animations.
|
||||
let current_focus = self.contents_under(pointer.current_location());
|
||||
|
||||
@@ -6407,6 +6512,46 @@ impl Niri {
|
||||
|
||||
self.notified_activity_this_iteration = true;
|
||||
}
|
||||
|
||||
pub fn close_mru(&mut self, close_request: MruCloseRequest) -> Option<Window> {
|
||||
if !self.window_mru_ui.is_open() {
|
||||
return None;
|
||||
}
|
||||
self.queue_redraw_all();
|
||||
|
||||
let id = self.window_mru_ui.close(close_request)?;
|
||||
self.find_window_by_id(id)
|
||||
}
|
||||
|
||||
pub fn cancel_mru(&mut self) {
|
||||
self.close_mru(MruCloseRequest::Cancel);
|
||||
}
|
||||
|
||||
/// Apply a pending MRU commit immediately.
|
||||
///
|
||||
/// Called for example on keyboard events that reach the active window, which immediately adds
|
||||
/// it to the MRU.
|
||||
pub fn mru_apply_keyboard_commit(&mut self) {
|
||||
let Some(pending) = self.pending_mru_commit.take() else {
|
||||
return;
|
||||
};
|
||||
self.event_loop.remove(pending.token);
|
||||
|
||||
if let Some(window) = self
|
||||
.layout
|
||||
.workspaces_mut()
|
||||
.flat_map(|ws| ws.windows_mut())
|
||||
.find(|w| w.id() == pending.id)
|
||||
{
|
||||
window.set_focus_timestamp(pending.stamp);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn queue_redraw_mru_output(&mut self) {
|
||||
if let Some(output) = self.window_mru_ui.output().cloned() {
|
||||
self.queue_redraw(&output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct NewClient {
|
||||
@@ -6454,6 +6599,7 @@ niri_render_elements! {
|
||||
NamedPointer = MemoryRenderBufferRenderElement<R>,
|
||||
SolidColor = SolidColorRenderElement,
|
||||
ScreenshotUi = ScreenshotUiRenderElement,
|
||||
WindowMruUi = WindowMruUiRenderElement<R>,
|
||||
ExitConfirmDialog = ExitConfirmDialogRenderElement,
|
||||
Texture = PrimaryGpuTextureRenderElement,
|
||||
// Used for the CPU-rendered panels.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
pub mod config_error_notification;
|
||||
pub mod exit_confirm_dialog;
|
||||
pub mod hotkey_overlay;
|
||||
pub mod mru;
|
||||
pub mod screen_transition;
|
||||
pub mod screenshot_ui;
|
||||
|
||||
+1929
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,135 @@
|
||||
use proptest::prelude::*;
|
||||
use proptest_derive::Arbitrary;
|
||||
|
||||
use super::*;
|
||||
|
||||
fn create_thumbnail() -> Thumbnail {
|
||||
Thumbnail {
|
||||
id: MappedId::next(),
|
||||
timestamp: None,
|
||||
on_current_output: false,
|
||||
on_current_workspace: false,
|
||||
app_id: None,
|
||||
size: Size::new(100, 100),
|
||||
clock: Clock::with_time(Duration::ZERO),
|
||||
config: niri_config::MruPreviews::default(),
|
||||
open_animation: None,
|
||||
move_animation: None,
|
||||
title_texture: Default::default(),
|
||||
background: RefCell::new(FocusRing::new(Default::default())),
|
||||
border: RefCell::new(FocusRing::new(Default::default())),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_last_window_out_of_two() {
|
||||
let ops = [Op::Backward, Op::Remove(1)];
|
||||
|
||||
let thumbnails = vec![create_thumbnail(), create_thumbnail()];
|
||||
let current_id = thumbnails.first().map(|t| t.id);
|
||||
let mut mru = WindowMru {
|
||||
thumbnails,
|
||||
current_id,
|
||||
scope: MruScope::All,
|
||||
app_id_filter: None,
|
||||
};
|
||||
|
||||
check_ops(&mut mru, &ops);
|
||||
}
|
||||
|
||||
fn arbitrary_scope() -> impl Strategy<Value = MruScope> {
|
||||
prop_oneof![
|
||||
Just(MruScope::All),
|
||||
Just(MruScope::Output),
|
||||
Just(MruScope::Workspace),
|
||||
]
|
||||
}
|
||||
|
||||
fn arbitrary_filter() -> impl Strategy<Value = MruFilter> {
|
||||
prop_oneof![Just(MruFilter::All), Just(MruFilter::AppId)]
|
||||
}
|
||||
|
||||
fn arbitrary_app_id() -> impl Strategy<Value = Option<String>> {
|
||||
prop_oneof![Just(None), Just(Some(1)), Just(Some(2))]
|
||||
.prop_map(|id| id.map(|id| format!("app-{id}")))
|
||||
}
|
||||
|
||||
prop_compose! {
|
||||
fn arbitrary_thumbnail()(
|
||||
timestamp: Option<Duration>,
|
||||
on_current_output: bool,
|
||||
on_current_workspace: bool,
|
||||
app_id in arbitrary_app_id(),
|
||||
) -> Thumbnail {
|
||||
let mut thumbnail = create_thumbnail();
|
||||
thumbnail.timestamp = timestamp;
|
||||
thumbnail.on_current_workspace = on_current_workspace;
|
||||
thumbnail.on_current_output = on_current_output;
|
||||
thumbnail.app_id = app_id;
|
||||
thumbnail
|
||||
}
|
||||
}
|
||||
|
||||
prop_compose! {
|
||||
fn arbitrary_mru()(
|
||||
thumbnails in proptest::collection::vec(arbitrary_thumbnail(), 1..10),
|
||||
) -> WindowMru {
|
||||
let current_id = thumbnails.first().map(|t| t.id);
|
||||
WindowMru {
|
||||
thumbnails,
|
||||
current_id,
|
||||
scope: MruScope::All,
|
||||
app_id_filter: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Arbitrary)]
|
||||
enum Op {
|
||||
Forward,
|
||||
Backward,
|
||||
First,
|
||||
Last,
|
||||
SetScope(#[proptest(strategy = "arbitrary_scope()")] MruScope),
|
||||
SetFilter(#[proptest(strategy = "arbitrary_filter()")] MruFilter),
|
||||
Remove(#[proptest(strategy = "1..10usize")] usize),
|
||||
}
|
||||
|
||||
impl Op {
|
||||
fn apply(&self, mru: &mut WindowMru) {
|
||||
match self {
|
||||
Op::Forward => mru.forward(),
|
||||
Op::Backward => mru.backward(),
|
||||
Op::First => mru.first(),
|
||||
Op::Last => mru.last(),
|
||||
Op::SetScope(scope) => {
|
||||
mru.set_scope(*scope);
|
||||
}
|
||||
Op::SetFilter(filter) => {
|
||||
mru.set_filter(*filter);
|
||||
}
|
||||
Op::Remove(idx) => {
|
||||
if *idx < mru.thumbnails.len() {
|
||||
mru.remove_by_idx(*idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn check_ops(mru: &mut WindowMru, ops: &[Op]) {
|
||||
for op in ops {
|
||||
op.apply(mru);
|
||||
mru.verify_invariants();
|
||||
}
|
||||
}
|
||||
|
||||
proptest! {
|
||||
#[test]
|
||||
fn random_operations_dont_panic(
|
||||
mut mru in arbitrary_mru(),
|
||||
ops: Vec<Op>,
|
||||
) {
|
||||
check_ops(&mut mru, &ops);
|
||||
}
|
||||
}
|
||||
@@ -183,6 +183,9 @@ pub struct Mapped {
|
||||
/// These have been "sent" to the window in form of configures, but the window hadn't committed
|
||||
/// in response yet.
|
||||
uncommitted_maximized: Vec<(Serial, bool)>,
|
||||
|
||||
/// Most recent monotonic time when the window had the focus.
|
||||
focus_timestamp: Option<Duration>,
|
||||
}
|
||||
|
||||
niri_render_elements! {
|
||||
@@ -279,6 +282,7 @@ impl Mapped {
|
||||
is_maximized: false,
|
||||
is_pending_maximized: false,
|
||||
uncommitted_maximized: Vec::new(),
|
||||
focus_timestamp: None,
|
||||
};
|
||||
|
||||
rv.is_maximized = rv.sizing_mode().is_maximized();
|
||||
@@ -515,6 +519,14 @@ impl Mapped {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_focus_timestamp(&self) -> Option<Duration> {
|
||||
self.focus_timestamp
|
||||
}
|
||||
|
||||
pub fn set_focus_timestamp(&mut self, timestamp: Duration) {
|
||||
self.focus_timestamp.replace(timestamp);
|
||||
}
|
||||
|
||||
pub fn send_frame<T, F>(
|
||||
&mut self,
|
||||
output: &Output,
|
||||
|
||||
Reference in New Issue
Block a user