forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on a6baef7b68fcb60dfc57a9fc04e983cfd8a028acFiltered to src/layout/monitor.rsClear filter

2025-12-25

Refactor rendering to push-based instead of pull-based (#3113)Ivan Molodetskikh · Unverified7f132ec
Refactor rendering to push-based instead of pull-based (#3113)

Our current rendering code constructs and returns complex
`-> impl Iterator<Item = SomeRenderElement>` types that are collected
into a vector at the top level Niri::render(). This causes some
problems:
- It's hard to write logic around returning iterators. Especially things
  like conditions, since the returned iterator must have a single type,
  you can't branch and return different iterators. This will be solved
  by gen fn but alas it's not here yet.
- In many cases, the returned `-> impl Iterator` will borrow from &self
  leading to complex lifetimes. In certain cases, it is also desirable
  for it to borrow the &mut NiriRenderer, which causes a lot of issues
  because it's exclusive (&mut).
- Sometimes those issues are too hard to deal with, leading to the
  escape hatch of allocating and returning a temporary
  Vec<SomeRenderElement>, like in
  Scrolling/FloatingSpace::render_elements(). These allocations are
  unfortunate because they are not really necessary.
- It's impossible to use some downstream combinators with this
  `-> impl Iterator` approach, leading to functions like Smithay's
  render_elements_from_surface_tree() returning a Vec. This is extra
  unfortunate because it results in a temporary allocation per Wayland
  toplevel/popup.
- It's hard to properly create profiling spans for the rendering
  functions since the spans are dropped when the (lazy) iterator is
  returned and not when all the code actually completes.
- The code compiles down to complex state machines in generated iterator
  types with logic located in Iterator::next(), which makes it annoying
  to follow in debuggers and profiling tools.

This refactor changes the code to push-based iteration: rendering
functions receive a push() closure that they call to push their render
elements. It solves all of the aforementioned problems:
- The logic becomes simpler. Just use conditionals and loops as normal.
- No borrowing and lifetimes since we're not returning anything.
- All temporary Vecs are removed because the problems they worked around
  no longer exist.
- The new push_elements_from_surface_tree() helper is the same as
  render_elements_from_surface_tree() but doesn't allocate a temporary
  Vec since it's not necessary; the push() closure can be passed down.
- Profiling spans work normally since the function returns when it ran
  all of the logic.
- The code compiles down to normal functions and calls as expected.

Generally, the iterator approach gives these advantages:
- You can wrap the returned items in the upstream logic. This is
  possible in exactly the same way with the push closure.
- You can decide to cut the iterator short in the upstream logic. This
  is not possible with push-based iteration, but we don't actually use
  it anywhere.

I chose the push closure type to be &mut dyn FnMut(SomeRenderElement).
It's deliberately not a generic impl FnMut() to avoid duplicating the
rendering logic when it's called from several different places. But it's
still a normal closure that can capture the outside context.

While my original idea for this refactor was to simplify the logic while
getting rid of temporary Vecs, it also appears to have brought a
consistent 2-3x speedup to the whole render list construction. On an old
Eee PC laptop I even observed a 8x speedup.

The refactor also results in smaller binary size, presumably due to
removing many iterator combinators and state tracking.

2025-12-23

2025-12-18

Use is_none_or()Ivan Molodetskikh · f913219Browse files

2025-10-05

layout/monitor: Make between-workspace insert hint narrowerIvan Molodetskikh · e5d4e7c
layout/monitor: Make between-workspace insert hint narrower

I've got feedback that full-width hint looks like the window will be
maximized on the new workspace.

2025-09-30

2025-09-26

layout: Move scrolling width resolution to workspaceIvan Molodetskikh · 67ca2cb
layout: Move scrolling width resolution to workspace

This is required now with per-output and per-workspace options.

2025-09-25

2025-09-21

Move background rendering to WorkspaceIvan Molodetskikh · a5e2858
Move background rendering to Workspace

Per-output background-color doesn't work yet.

2025-09-25

2025-09-26

2025-09-25

2025-09-20

2025-06-16

2025-05-13

layout: Fix workspace swipe to same workspace forgetting previous idIvan Molodetskikh · 6d083ea
layout: Fix workspace swipe to same workspace forgetting previous id

This manifested much more prominently in the overview.

2025-05-01

2025-04-26

2025-04-25

Fix panic when interactively moving to invisible workspaceIvan Molodetskikh · d2a1cf5
Fix panic when interactively moving to invisible workspace

Introduced in the interactive move between workspaces commit.
Implement an OverviewIvan Molodetskikh · af1fca3Browse files
Render workspaces separately with gaps betweenIvan Molodetskikh · 9571d14
Render workspaces separately with gaps between

This design makes more sense spatially, and is required for the
Overview. Gaps also make it clear how clipping windows to workspace
bounds works.

Background and bottom layer-shell surfaces get duplicated for each
workspace, while top and overlay stay "on top".

2025-04-24

layout/monitor: Don't consider workspace switch in active_tile_visual_rectangle()Ivan Molodetskikh · 7671a5d
layout/monitor: Don't consider workspace switch in active_tile_visual_rectangle()

This only did something when in the middle of a touchpad gesture, and it
didn't really make sense for that edge case.

2025-04-18

2025-04-17

2025-04-04

2025-04-22

layout/monitor: Keep track of workspace switch gesture start idxIvan Molodetskikh · cee11dc
layout/monitor: Keep track of workspace switch gesture start idx

Fixes jump when "catching" an animation with a gesture.

2025-04-20

Remove cancellation from swipe gesturesIvan Molodetskikh · 59a4224
Remove cancellation from swipe gestures

It only worked for workspace switch, and even there it was more confusing than
helpful.

2025-04-25

Add missing bounds checks to move-workspace actionsIvan Molodetskikh · 74b0162
Add missing bounds checks to move-workspace actions

Fixes panics.

2025-04-17

2025-04-04

layout: Take into account idle time between last gesture event and endIvan Molodetskikh · df94662
layout: Take into account idle time between last gesture event and end

Fixes cases like: do a quick movement with mouse, then hold it in-place for a
while (no events generated), then release the gesture (it uses all that
built-up speed). This also happens with DnD scroll and makes it go further than
intended.

2025-03-29

Add focus argument to move-window-to-workspace (#1332)nyx · Unverified0db48e2
Add focus argument to move-window-to-workspace (#1332)

* layout: add focus flag to move-window-to-workspace

* lib: update comment

* misc: minor dup refactor

* input: format code

* layout: minor nit

* layout: update comment

* input: remove unnecessary conditionals

* misc: replace boolean

* tests: fix the failing one

* layout: change to smart

* ipc: Option<bool> -> bool

* lib: format code

* Rewrite focus doc comment

---------

Co-authored-by: Ivan Molodetskikh <yalterz@gmail.com>

2025-02-27

2025-02-17

2025-02-06

2025-02-01

2025-02-10

Account for border in contents_under()Ivan Molodetskikh · 1d88393
Account for border in contents_under()

Fixes pointer clicks going through window borders to a layer surface below,
also fixes window not getting activated in all cases from a border click.

2025-02-05