Skip to content

Recency heuristic for ambiguous output selection#3952

Open
ccjmne wants to merge 2 commits into
niri-wm:mainfrom
ccjmne:recency-heuristic-for-ambiguous-output-focus
Open

Recency heuristic for ambiguous output selection#3952
ccjmne wants to merge 2 commits into
niri-wm:mainfrom
ccjmne:recency-heuristic-for-ambiguous-output-focus

Conversation

@ccjmne
Copy link
Copy Markdown

@ccjmne ccjmne commented May 1, 2026

Discussed in: #2897

This Pull Request changes the algorithm to determine which output to target when going up, down, left or right: it implements some MRU heuristic for all the commands that have to do with choosing an output up, down, left or right.

I also considered making it opt-in, with, say:

Mod+Shift+Left  { focus-monitor-left  use-focus-history=true; }

But there are so many such functions; at least all of these, in 4 directions:

Mod+Ctrl+Down          { move-window-down-or-to-workspace-down; }
Mod+Ctrl+WheelScrollUp { move-column-to-workspace-up;           }
Mod+Shift+Ctrl+Left    { move-window-to-monitor-left;           }
Mod+Shift+Left         { focus-monitor-left                     }
Mod+Up                 { focus-window-or-workspace-up;          }

And I figured people would generally want to have a single selection scheme for all their output selection commands. In any case, we can discuss this and think about it some more, but I think there's something pretty usable here as is it.


Just like before, the candidate outputs are:

  • in the correct direction, and
  • they are at least partially in the (virtually) infinite "strip"
    obtained from extending the active output either vertically, for up
    and down motions, or horizontally for horizontal movements.

Unlike before, we now rank the candidate outputs by their nearbymost
vertical (or horizontal) edge: this allows us to more reasonably end up
with ties, where the ambiguity that is natural to the human user also
becomes effective in the code.

We curate a stack of the most recently used monitors and use it to
resolve the ties against the candidates that share the closest edge to
the currently active output.

If none of the candidates were ever visited, we fall back to the
previous heuristic, which would find the closest candidate, according
to the distance between their geometric centre and that of the active
output.

ccjmne added 2 commits May 1, 2026 05:46
Change the algorithm to determine which output to target when going up,
down, left or right.

Just like before, the candidate outputs are:

- in the correct direction, and
- they are at least partially in the (virtually) infinite "strip"
  obtained from extending the active output either vertically, for up
  and down motions, or horizontally for horizontal movements.

Unlike before, we now rank the candidate outputs by their nearbymost
vertical (or horizontal) edge: this allows us to more reasonably end up
with ties, where the ambiguity that is natural to the human user also
becomes effective in the code.

We curate a stack of the most recently used monitors and use it to
resolve the ties against the candidates that share the closest edge to
the currently active output.

If none of the candidates were ever visited, we fall back to the
previous heuristic, which would find the closest candidate, according
to the distance between their geometric centre and that of the active
output.

Ref: niri-wm#2897
@ccjmne ccjmne changed the title Recency heuristic for ambiguous output focus Recency heuristic for ambiguous output selection May 1, 2026
@Sempyos Sempyos added area:layout Columns, workspaces, scrolling, fullscreen, resize area:config Config parsing, default config, new settings pr kind:feature New features and functionality labels May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:config Config parsing, default config, new settings area:layout Columns, workspaces, scrolling, fullscreen, resize pr kind:feature New features and functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants