mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-24 02:01:18 +07:00
layout: Extract Layout::monitors{,_mut}()
This commit is contained in:
+55
-93
@@ -1118,10 +1118,8 @@ impl<W: LayoutElement> Layout<W> {
|
|||||||
unreachable!()
|
unreachable!()
|
||||||
};
|
};
|
||||||
|
|
||||||
if let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set {
|
for mon in self.monitors_mut() {
|
||||||
for mon in monitors {
|
mon.dnd_scroll_gesture_end();
|
||||||
mon.dnd_scroll_gesture_end();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unlock the view on the workspaces.
|
// Unlock the view on the workspaces.
|
||||||
@@ -1459,11 +1457,7 @@ impl<W: LayoutElement> Layout<W> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let MonitorSet::Normal { monitors, .. } = &self.monitor_set else {
|
for mon in self.monitors() {
|
||||||
return 0.;
|
|
||||||
};
|
|
||||||
|
|
||||||
for mon in monitors {
|
|
||||||
for ws in &mon.workspaces {
|
for ws in &mon.workspaces {
|
||||||
if ws.has_window(window) {
|
if ws.has_window(window) {
|
||||||
return ws.scroll_amount_to_activate(window);
|
return ws.scroll_amount_to_activate(window);
|
||||||
@@ -1744,28 +1738,36 @@ impl<W: LayoutElement> Layout<W> {
|
|||||||
Some(&monitors[*active_monitor_idx])
|
Some(&monitors[*active_monitor_idx])
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn monitor_for_output(&self, output: &Output) -> Option<&Monitor<W>> {
|
pub fn monitors(&self) -> impl Iterator<Item = &Monitor<W>> + '_ {
|
||||||
let MonitorSet::Normal { monitors, .. } = &self.monitor_set else {
|
let monitors = if let MonitorSet::Normal { monitors, .. } = &self.monitor_set {
|
||||||
return None;
|
&monitors[..]
|
||||||
|
} else {
|
||||||
|
&[][..]
|
||||||
};
|
};
|
||||||
|
|
||||||
monitors.iter().find(|mon| &mon.output == output)
|
monitors.iter()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn monitors_mut(&mut self) -> impl Iterator<Item = &mut Monitor<W>> + '_ {
|
||||||
|
let monitors = if let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set {
|
||||||
|
&mut monitors[..]
|
||||||
|
} else {
|
||||||
|
&mut [][..]
|
||||||
|
};
|
||||||
|
|
||||||
|
monitors.iter_mut()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn monitor_for_output(&self, output: &Output) -> Option<&Monitor<W>> {
|
||||||
|
self.monitors().find(|mon| &mon.output == output)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn monitor_for_output_mut(&mut self, output: &Output) -> Option<&mut Monitor<W>> {
|
pub fn monitor_for_output_mut(&mut self, output: &Output) -> Option<&mut Monitor<W>> {
|
||||||
let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set else {
|
self.monitors_mut().find(|mon| &mon.output == output)
|
||||||
return None;
|
|
||||||
};
|
|
||||||
|
|
||||||
monitors.iter_mut().find(|mon| &mon.output == output)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn monitor_for_workspace(&self, workspace_name: &str) -> Option<&Monitor<W>> {
|
pub fn monitor_for_workspace(&self, workspace_name: &str) -> Option<&Monitor<W>> {
|
||||||
let MonitorSet::Normal { monitors, .. } = &self.monitor_set else {
|
self.monitors().find(|monitor| {
|
||||||
return None;
|
|
||||||
};
|
|
||||||
|
|
||||||
monitors.iter().find(|monitor| {
|
|
||||||
monitor.workspaces.iter().any(|ws| {
|
monitor.workspaces.iter().any(|ws| {
|
||||||
ws.name
|
ws.name
|
||||||
.as_ref()
|
.as_ref()
|
||||||
@@ -1775,13 +1777,7 @@ impl<W: LayoutElement> Layout<W> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn outputs(&self) -> impl Iterator<Item = &Output> + '_ {
|
pub fn outputs(&self) -> impl Iterator<Item = &Output> + '_ {
|
||||||
let monitors = if let MonitorSet::Normal { monitors, .. } = &self.monitor_set {
|
self.monitors().map(|mon| &mon.output)
|
||||||
&monitors[..]
|
|
||||||
} else {
|
|
||||||
&[][..]
|
|
||||||
};
|
|
||||||
|
|
||||||
monitors.iter().map(|mon| &mon.output)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn move_left(&mut self) {
|
pub fn move_left(&mut self) {
|
||||||
@@ -2324,11 +2320,7 @@ impl<W: LayoutElement> Layout<W> {
|
|||||||
output: &Output,
|
output: &Output,
|
||||||
pos_within_output: Point<f64, Logical>,
|
pos_within_output: Point<f64, Logical>,
|
||||||
) -> Option<(&W, HitType)> {
|
) -> Option<(&W, HitType)> {
|
||||||
let MonitorSet::Normal { monitors, .. } = &self.monitor_set else {
|
let mon = self.monitor_for_output(output)?;
|
||||||
return None;
|
|
||||||
};
|
|
||||||
|
|
||||||
let mon = monitors.iter().find(|mon| &mon.output == output)?;
|
|
||||||
mon.window_under(pos_within_output)
|
mon.window_under(pos_within_output)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2337,11 +2329,7 @@ impl<W: LayoutElement> Layout<W> {
|
|||||||
output: &Output,
|
output: &Output,
|
||||||
pos_within_output: Point<f64, Logical>,
|
pos_within_output: Point<f64, Logical>,
|
||||||
) -> Option<ResizeEdge> {
|
) -> Option<ResizeEdge> {
|
||||||
let MonitorSet::Normal { monitors, .. } = &self.monitor_set else {
|
let mon = self.monitor_for_output(output)?;
|
||||||
return None;
|
|
||||||
};
|
|
||||||
|
|
||||||
let mon = monitors.iter().find(|mon| &mon.output == output)?;
|
|
||||||
mon.resize_edges_under(pos_within_output)
|
mon.resize_edges_under(pos_within_output)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2358,11 +2346,7 @@ impl<W: LayoutElement> Layout<W> {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let MonitorSet::Normal { monitors, .. } = &self.monitor_set else {
|
let mon = self.monitor_for_output(output)?;
|
||||||
return None;
|
|
||||||
};
|
|
||||||
|
|
||||||
let mon = monitors.iter().find(|mon| &mon.output == output)?;
|
|
||||||
if extended_bounds {
|
if extended_bounds {
|
||||||
mon.workspace_under(pos_within_output).map(|(ws, _)| ws)
|
mon.workspace_under(pos_within_output).map(|(ws, _)| ws)
|
||||||
} else {
|
} else {
|
||||||
@@ -2855,11 +2839,7 @@ impl<W: LayoutElement> Layout<W> {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
let MonitorSet::Normal { monitors, .. } = &self.monitor_set else {
|
for mon in self.monitors() {
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
for mon in monitors {
|
|
||||||
if output.is_some_and(|output| mon.output != *output) {
|
if output.is_some_and(|output| mon.output != *output) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -2932,10 +2912,8 @@ impl<W: LayoutElement> Layout<W> {
|
|||||||
fn update_insert_hint(&mut self, output: Option<&Output>) {
|
fn update_insert_hint(&mut self, output: Option<&Output>) {
|
||||||
let _span = tracy_client::span!("Layout::update_insert_hint");
|
let _span = tracy_client::span!("Layout::update_insert_hint");
|
||||||
|
|
||||||
if let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set {
|
for mon in self.monitors_mut() {
|
||||||
for mon in monitors {
|
mon.insert_hint = None;
|
||||||
mon.insert_hint = None;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !matches!(self.interactive_move, Some(InteractiveMoveState::Moving(_))) {
|
if !matches!(self.interactive_move, Some(InteractiveMoveState::Moving(_))) {
|
||||||
@@ -3953,11 +3931,7 @@ impl<W: LayoutElement> Layout<W> {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set else {
|
let Some((mon, (ws, ws_geo))) = self.monitors().find_map(|mon| {
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
let Some((mon, (ws, ws_geo))) = monitors.iter().find_map(|mon| {
|
|
||||||
mon.workspaces_with_render_geo()
|
mon.workspaces_with_render_geo()
|
||||||
.find(|(ws, _)| ws.has_window(&window_id))
|
.find(|(ws, _)| ws.has_window(&window_id))
|
||||||
.map(|rv| (mon, rv))
|
.map(|rv| (mon, rv))
|
||||||
@@ -3994,10 +3968,8 @@ impl<W: LayoutElement> Layout<W> {
|
|||||||
pointer_ratio_within_window,
|
pointer_ratio_within_window,
|
||||||
});
|
});
|
||||||
|
|
||||||
if let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set {
|
for mon in self.monitors_mut() {
|
||||||
for mon in monitors {
|
mon.dnd_scroll_gesture_begin();
|
||||||
mon.dnd_scroll_gesture_begin();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lock the view for scrolling interactive move.
|
// Lock the view for scrolling interactive move.
|
||||||
@@ -4083,21 +4055,19 @@ impl<W: LayoutElement> Layout<W> {
|
|||||||
// FIXME: when and if the layout code knows about monitor positions, this will be
|
// FIXME: when and if the layout code knows about monitor positions, this will be
|
||||||
// potentially animatable.
|
// potentially animatable.
|
||||||
let mut tile_pos = None;
|
let mut tile_pos = None;
|
||||||
if let MonitorSet::Normal { monitors, .. } = &self.monitor_set {
|
if let Some((mon, (ws, ws_geo))) = self.monitors().find_map(|mon| {
|
||||||
if let Some((mon, (ws, ws_geo))) = monitors.iter().find_map(|mon| {
|
mon.workspaces_with_render_geo()
|
||||||
mon.workspaces_with_render_geo()
|
.find(|(ws, _)| ws.has_window(window))
|
||||||
.find(|(ws, _)| ws.has_window(window))
|
.map(|rv| (mon, rv))
|
||||||
.map(|rv| (mon, rv))
|
}) {
|
||||||
}) {
|
if mon.output() == &output {
|
||||||
if mon.output() == &output {
|
let (_, tile_offset, _) = ws
|
||||||
let (_, tile_offset, _) = ws
|
.tiles_with_render_positions()
|
||||||
.tiles_with_render_positions()
|
.find(|(tile, _, _)| tile.window().id() == window)
|
||||||
.find(|(tile, _, _)| tile.window().id() == window)
|
.unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let zoom = mon.overview_zoom();
|
let zoom = mon.overview_zoom();
|
||||||
tile_pos = Some((ws_geo.loc + tile_offset.upscale(zoom), zoom));
|
tile_pos = Some((ws_geo.loc + tile_offset.upscale(zoom), zoom));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4239,10 +4209,8 @@ impl<W: LayoutElement> Layout<W> {
|
|||||||
unreachable!()
|
unreachable!()
|
||||||
};
|
};
|
||||||
|
|
||||||
if let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set {
|
for mon in self.monitors_mut() {
|
||||||
for mon in monitors {
|
mon.dnd_scroll_gesture_end();
|
||||||
mon.dnd_scroll_gesture_end();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut ws_id = None;
|
let mut ws_id = None;
|
||||||
@@ -4308,10 +4276,8 @@ impl<W: LayoutElement> Layout<W> {
|
|||||||
unreachable!()
|
unreachable!()
|
||||||
};
|
};
|
||||||
|
|
||||||
if let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set {
|
for mon in self.monitors_mut() {
|
||||||
for mon in monitors {
|
mon.dnd_scroll_gesture_end();
|
||||||
mon.dnd_scroll_gesture_end();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unlock the view on the workspaces.
|
// Unlock the view on the workspaces.
|
||||||
@@ -4541,10 +4507,8 @@ impl<W: LayoutElement> Layout<W> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if begin_gesture {
|
if begin_gesture {
|
||||||
if let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set {
|
for mon in self.monitors_mut() {
|
||||||
for mon in monitors {
|
mon.dnd_scroll_gesture_begin();
|
||||||
mon.dnd_scroll_gesture_begin();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for ws in self.workspaces_mut() {
|
for ws in self.workspaces_mut() {
|
||||||
@@ -4560,10 +4524,8 @@ impl<W: LayoutElement> Layout<W> {
|
|||||||
|
|
||||||
self.dnd = None;
|
self.dnd = None;
|
||||||
|
|
||||||
if let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set {
|
for mon in self.monitors_mut() {
|
||||||
for mon in monitors {
|
mon.dnd_scroll_gesture_end();
|
||||||
mon.dnd_scroll_gesture_end();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for ws in self.workspaces_mut() {
|
for ws in self.workspaces_mut() {
|
||||||
|
|||||||
Reference in New Issue
Block a user