forge
Explore
Log in

Don't you dare go Hollow

layout: Extract Layout::monitors{,_mut}()

Browse files at this commit

c353a7dae900382893cde03a84a85add24abfc45Ivan MolodetskikhParent: e3068cd
src/layout/mod.rsmodified+54 -92
@@ -1118,10 +1118,8 @@ impl<W: LayoutElement> Layout<W> {
1118 unreachable!()1118 unreachable!()
1119 };1119 };
1120 1120
1121- if let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set {1121+ for mon in self.monitors_mut() {
1122- for mon in monitors {1122+ mon.dnd_scroll_gesture_end();
1123- mon.dnd_scroll_gesture_end();
1124- }
1125 }1123 }
1126 1124
1127 // Unlock the view on the workspaces.1125 // Unlock the view on the workspaces.
@@ -1459,11 +1457,7 @@ impl<W: LayoutElement> Layout<W> {
1459 }1457 }
1460 }1458 }
1461 1459
1462- let MonitorSet::Normal { monitors, .. } = &self.monitor_set else {1460+ for mon in self.monitors() {
1463- return 0.;
1464- };
1465-
1466- for mon in monitors {
1467 for ws in &mon.workspaces {1461 for ws in &mon.workspaces {
1468 if ws.has_window(window) {1462 if ws.has_window(window) {
1469 return ws.scroll_amount_to_activate(window);1463 return ws.scroll_amount_to_activate(window);
@@ -1744,28 +1738,36 @@ impl<W: LayoutElement> Layout<W> {
1744 Some(&monitors[*active_monitor_idx])1738 Some(&monitors[*active_monitor_idx])
1745 }1739 }
1746 1740
1747- pub fn monitor_for_output(&self, output: &Output) -> Option<&Monitor<W>> {1741+ pub fn monitors(&self) -> impl Iterator<Item = &Monitor<W>> + '_ {
1748- let MonitorSet::Normal { monitors, .. } = &self.monitor_set else {1742+ let monitors = if let MonitorSet::Normal { monitors, .. } = &self.monitor_set {
1749- return None;1743+ &monitors[..]
1744+ } else {
1745+ &[][..]
1750 };1746 };
1751 1747
1752- monitors.iter().find(|mon| &mon.output == output)1748+ monitors.iter()
1753 }1749 }
1754 1750
1755- pub fn monitor_for_output_mut(&mut self, output: &Output) -> Option<&mut Monitor<W>> {1751+ pub fn monitors_mut(&mut self) -> impl Iterator<Item = &mut Monitor<W>> + '_ {
1756- let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set else {1752+ let monitors = if let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set {
1757- return None;1753+ &mut monitors[..]
1754+ } else {
1755+ &mut [][..]
1758 };1756 };
1759 1757
1760- monitors.iter_mut().find(|mon| &mon.output == output)1758+ monitors.iter_mut()
1761 }1759 }
1762 1760
1763- pub fn monitor_for_workspace(&self, workspace_name: &str) -> Option<&Monitor<W>> {1761+ pub fn monitor_for_output(&self, output: &Output) -> Option<&Monitor<W>> {
1764- let MonitorSet::Normal { monitors, .. } = &self.monitor_set else {1762+ self.monitors().find(|mon| &mon.output == output)
1765- return None;1763+ }
1766- };
1767 1764
1768- monitors.iter().find(|monitor| {1765+ pub fn monitor_for_output_mut(&mut self, output: &Output) -> Option<&mut Monitor<W>> {
1766+ self.monitors_mut().find(|mon| &mon.output == output)
1767+ }
1768+
1769+ pub fn monitor_for_workspace(&self, workspace_name: &str) -> Option<&Monitor<W>> {
1770+ self.monitors().find(|monitor| {
1769 monitor.workspaces.iter().any(|ws| {1771 monitor.workspaces.iter().any(|ws| {
1770 ws.name1772 ws.name
1771 .as_ref()1773 .as_ref()
@@ -1775,13 +1777,7 @@ impl<W: LayoutElement> Layout<W> {
1775 }1777 }
1776 1778
1777 pub fn outputs(&self) -> impl Iterator<Item = &Output> + '_ {1779 pub fn outputs(&self) -> impl Iterator<Item = &Output> + '_ {
1778- let monitors = if let MonitorSet::Normal { monitors, .. } = &self.monitor_set {1780+ self.monitors().map(|mon| &mon.output)
1779- &monitors[..]
1780- } else {
1781- &[][..]
1782- };
1783-
1784- monitors.iter().map(|mon| &mon.output)
1785 }1781 }
1786 1782
1787 pub fn move_left(&mut self) {1783 pub fn move_left(&mut self) {
@@ -2324,11 +2320,7 @@ impl<W: LayoutElement> Layout<W> {
2324 output: &Output,2320 output: &Output,
2325 pos_within_output: Point<f64, Logical>,2321 pos_within_output: Point<f64, Logical>,
2326 ) -> Option<(&W, HitType)> {2322 ) -> Option<(&W, HitType)> {
2327- let MonitorSet::Normal { monitors, .. } = &self.monitor_set else {2323+ let mon = self.monitor_for_output(output)?;
2328- return None;
2329- };
2330-
2331- let mon = monitors.iter().find(|mon| &mon.output == output)?;
2332 mon.window_under(pos_within_output)2324 mon.window_under(pos_within_output)
2333 }2325 }
2334 2326
@@ -2337,11 +2329,7 @@ impl<W: LayoutElement> Layout<W> {
2337 output: &Output,2329 output: &Output,
2338 pos_within_output: Point<f64, Logical>,2330 pos_within_output: Point<f64, Logical>,
2339 ) -> Option<ResizeEdge> {2331 ) -> Option<ResizeEdge> {
2340- let MonitorSet::Normal { monitors, .. } = &self.monitor_set else {2332+ let mon = self.monitor_for_output(output)?;
2341- return None;
2342- };
2343-
2344- let mon = monitors.iter().find(|mon| &mon.output == output)?;
2345 mon.resize_edges_under(pos_within_output)2333 mon.resize_edges_under(pos_within_output)
2346 }2334 }
2347 2335
@@ -2358,11 +2346,7 @@ impl<W: LayoutElement> Layout<W> {
2358 return None;2346 return None;
2359 }2347 }
2360 2348
2361- let MonitorSet::Normal { monitors, .. } = &self.monitor_set else {2349+ let mon = self.monitor_for_output(output)?;
2362- return None;
2363- };
2364-
2365- let mon = monitors.iter().find(|mon| &mon.output == output)?;
2366 if extended_bounds {2350 if extended_bounds {
2367 mon.workspace_under(pos_within_output).map(|(ws, _)| ws)2351 mon.workspace_under(pos_within_output).map(|(ws, _)| ws)
2368 } else {2352 } else {
@@ -2855,11 +2839,7 @@ impl<W: LayoutElement> Layout<W> {
2855 return true;2839 return true;
2856 }2840 }
2857 2841
2858- let MonitorSet::Normal { monitors, .. } = &self.monitor_set else {2842+ for mon in self.monitors() {
2859- return false;
2860- };
2861-
2862- for mon in monitors {
2863 if output.is_some_and(|output| mon.output != *output) {2843 if output.is_some_and(|output| mon.output != *output) {
2864 continue;2844 continue;
2865 }2845 }
@@ -2932,10 +2912,8 @@ impl<W: LayoutElement> Layout<W> {
2932 fn update_insert_hint(&mut self, output: Option<&Output>) {2912 fn update_insert_hint(&mut self, output: Option<&Output>) {
2933 let _span = tracy_client::span!("Layout::update_insert_hint");2913 let _span = tracy_client::span!("Layout::update_insert_hint");
2934 2914
2935- if let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set {2915+ for mon in self.monitors_mut() {
2936- for mon in monitors {2916+ mon.insert_hint = None;
2937- mon.insert_hint = None;
2938- }
2939 }2917 }
2940 2918
2941 if !matches!(self.interactive_move, Some(InteractiveMoveState::Moving(_))) {2919 if !matches!(self.interactive_move, Some(InteractiveMoveState::Moving(_))) {
@@ -3953,11 +3931,7 @@ impl<W: LayoutElement> Layout<W> {
3953 return false;3931 return false;
3954 }3932 }
3955 3933
3956- let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set else {3934+ let Some((mon, (ws, ws_geo))) = self.monitors().find_map(|mon| {
3957- return false;
3958- };
3959-
3960- let Some((mon, (ws, ws_geo))) = monitors.iter().find_map(|mon| {
3961 mon.workspaces_with_render_geo()3935 mon.workspaces_with_render_geo()
3962 .find(|(ws, _)| ws.has_window(&window_id))3936 .find(|(ws, _)| ws.has_window(&window_id))
3963 .map(|rv| (mon, rv))3937 .map(|rv| (mon, rv))
@@ -3994,10 +3968,8 @@ impl<W: LayoutElement> Layout<W> {
3994 pointer_ratio_within_window,3968 pointer_ratio_within_window,
3995 });3969 });
3996 3970
3997- if let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set {3971+ for mon in self.monitors_mut() {
3998- for mon in monitors {3972+ mon.dnd_scroll_gesture_begin();
3999- mon.dnd_scroll_gesture_begin();
4000- }
4001 }3973 }
4002 3974
4003 // Lock the view for scrolling interactive move.3975 // Lock the view for scrolling interactive move.
@@ -4083,21 +4055,19 @@ impl<W: LayoutElement> Layout<W> {
4083 // FIXME: when and if the layout code knows about monitor positions, this will be4055 // FIXME: when and if the layout code knows about monitor positions, this will be
4084 // potentially animatable.4056 // potentially animatable.
4085 let mut tile_pos = None;4057 let mut tile_pos = None;
4086- if let MonitorSet::Normal { monitors, .. } = &self.monitor_set {4058+ if let Some((mon, (ws, ws_geo))) = self.monitors().find_map(|mon| {
4087- if let Some((mon, (ws, ws_geo))) = monitors.iter().find_map(|mon| {4059+ mon.workspaces_with_render_geo()
4088- mon.workspaces_with_render_geo()4060+ .find(|(ws, _)| ws.has_window(window))
4089- .find(|(ws, _)| ws.has_window(window))4061+ .map(|rv| (mon, rv))
4090- .map(|rv| (mon, rv))4062+ }) {
4091- }) {4063+ if mon.output() == &output {
4092- if mon.output() == &output {4064+ let (_, tile_offset, _) = ws
4093- let (_, tile_offset, _) = ws4065+ .tiles_with_render_positions()
4094- .tiles_with_render_positions()4066+ .find(|(tile, _, _)| tile.window().id() == window)
4095- .find(|(tile, _, _)| tile.window().id() == window)4067+ .unwrap();
4096- .unwrap();
4097 4068
4098- let zoom = mon.overview_zoom();4069+ let zoom = mon.overview_zoom();
4099- tile_pos = Some((ws_geo.loc + tile_offset.upscale(zoom), zoom));4070+ tile_pos = Some((ws_geo.loc + tile_offset.upscale(zoom), zoom));
4100- }
4101 }4071 }
4102 }4072 }
4103 4073
@@ -4239,10 +4209,8 @@ impl<W: LayoutElement> Layout<W> {
4239 unreachable!()4209 unreachable!()
4240 };4210 };
4241 4211
4242- if let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set {4212+ for mon in self.monitors_mut() {
4243- for mon in monitors {4213+ mon.dnd_scroll_gesture_end();
4244- mon.dnd_scroll_gesture_end();
4245- }
4246 }4214 }
4247 4215
4248 let mut ws_id = None;4216 let mut ws_id = None;
@@ -4308,10 +4276,8 @@ impl<W: LayoutElement> Layout<W> {
4308 unreachable!()4276 unreachable!()
4309 };4277 };
4310 4278
4311- if let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set {4279+ for mon in self.monitors_mut() {
4312- for mon in monitors {4280+ mon.dnd_scroll_gesture_end();
4313- mon.dnd_scroll_gesture_end();
4314- }
4315 }4281 }
4316 4282
4317 // Unlock the view on the workspaces.4283 // Unlock the view on the workspaces.
@@ -4541,10 +4507,8 @@ impl<W: LayoutElement> Layout<W> {
4541 });4507 });
4542 4508
4543 if begin_gesture {4509 if begin_gesture {
4544- if let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set {4510+ for mon in self.monitors_mut() {
4545- for mon in monitors {4511+ mon.dnd_scroll_gesture_begin();
4546- mon.dnd_scroll_gesture_begin();
4547- }
4548 }4512 }
4549 4513
4550 for ws in self.workspaces_mut() {4514 for ws in self.workspaces_mut() {
@@ -4560,10 +4524,8 @@ impl<W: LayoutElement> Layout<W> {
4560 4524
4561 self.dnd = None;4525 self.dnd = None;
4562 4526
4563- if let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set {4527+ for mon in self.monitors_mut() {
4564- for mon in monitors {4528+ mon.dnd_scroll_gesture_end();
4565- mon.dnd_scroll_gesture_end();
4566- }
4567 }4529 }
4568 4530
4569 for ws in self.workspaces_mut() {4531 for ws in self.workspaces_mut() {