Skip to content

Commit

Permalink
monitor: Use sorted outputs for querying next one
Browse files Browse the repository at this point in the history
  • Loading branch information
julianschuler committed Dec 16, 2024
1 parent f72fe07 commit 4a30596
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/niri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ pub struct Niri {
// according to their global position.
pub global_space: Space<Window>,

/// Mapped outputs, sorted by their name and position.
pub sorted_outputs: Vec<Output>,

// Windows which don't have a buffer attached yet.
pub unmapped_windows: HashMap<WlSurface, Unmapped>,

Expand Down Expand Up @@ -1918,6 +1921,7 @@ impl Niri {

layout,
global_space: Space::default(),
sorted_outputs: Vec::default(),
output_state: HashMap::new(),
unmapped_windows: HashMap::new(),
unmapped_layer_surfaces: HashSet::new(),
Expand Down Expand Up @@ -2103,6 +2107,11 @@ impl Niri {
outputs.iter().map(|d| &d.name.connector)
);

self.sorted_outputs = outputs
.iter()
.map(|Data { output, .. }| output.clone())
.collect();

for data in outputs.into_iter() {
let Data {
output,
Expand Down Expand Up @@ -2604,11 +2613,11 @@ impl Niri {
pub fn output_next(&self) -> Option<Output> {
let active = self.layout.active_output()?;

self.global_space
.outputs()
self.sorted_outputs
.iter()
.skip_while(|&output| output != active)
.nth(1)
.or(self.global_space.outputs().next())
.or(self.sorted_outputs.first())
.cloned()
}

Expand Down

0 comments on commit 4a30596

Please sign in to comment.