9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1 | //! Window organisation without smithay. Tags with per-output views, one |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 2 | //! tiling tree per output filtered by those views, floating windows, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 3 | //! scratchpads, focus, and restoring windows when an output comes back. |
57f44a63d99f | atagen | 2026-10-16 05:34 UTC | 4 | |
4cbf881c67bd | atagen | 2026-10-17 04:56 UTC | 5 | mod outputs; |
4cbf881c67bd | atagen | 2026-10-17 04:56 UTC | 6 | mod scratchpad; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 7 | mod tree; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 8 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 9 | #[cfg(test)] |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 10 | mod tests; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 11 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 12 | pub use monolith_planner::Rect; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 13 | pub use tree::{Axis, Dir, Tree}; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 14 | |
4cbf881c67bd | atagen | 2026-10-17 04:56 UTC | 15 | use outputs::Parked; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 16 | use slotmap::{SlotMap, new_key_type}; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 17 | use std::collections::HashMap; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 18 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 19 | new_key_type! { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 20 | pub struct WindowId; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 21 | pub struct TagId; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 22 | pub struct OutputId; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 23 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 24 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 25 | pub const HOMELESS: &str = "homeless"; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 26 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 27 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 28 | pub enum ExpandScope { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 29 | Window, |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 30 | Container, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 31 | All, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 32 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 33 | |
bc51c38a6fd9 | atagen | 2026-10-16 22:17 UTC | 34 | /// Space taken from an output's edges by bars and other panels. |
bc51c38a6fd9 | atagen | 2026-10-16 22:17 UTC | 35 | #[derive(Clone, Copy, Debug, PartialEq, Default)] |
bc51c38a6fd9 | atagen | 2026-10-16 22:17 UTC | 36 | pub struct Insets { |
bc51c38a6fd9 | atagen | 2026-10-16 22:17 UTC | 37 | pub top: f64, |
bc51c38a6fd9 | atagen | 2026-10-16 22:17 UTC | 38 | pub right: f64, |
bc51c38a6fd9 | atagen | 2026-10-16 22:17 UTC | 39 | pub bottom: f64, |
bc51c38a6fd9 | atagen | 2026-10-16 22:17 UTC | 40 | pub left: f64, |
bc51c38a6fd9 | atagen | 2026-10-16 22:17 UTC | 41 | } |
bc51c38a6fd9 | atagen | 2026-10-16 22:17 UTC | 42 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 43 | #[derive(Clone, Copy, Debug, PartialEq)] |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 44 | pub struct Gaps { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 45 | pub inner: f64, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 46 | pub outer: f64, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 47 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 48 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 49 | impl Default for Gaps { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 50 | fn default() -> Self { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 51 | Self { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 52 | inner: 8.0, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 53 | outer: 8.0, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 54 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 55 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 56 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 57 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 58 | #[derive(Clone, Debug)] |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 59 | pub struct Window { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 60 | pub output: Option<OutputId>, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 61 | pub tag: TagId, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 62 | pub floating: bool, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 63 | pub float_rect: Option<Rect>, |
754ca2132943 | atagen | 2026-10-19 07:29 UTC | 64 | /// `float_rect` is the layout's default, not a size the window or the |
754ca2132943 | atagen | 2026-10-19 07:29 UTC | 65 | /// user chose. |
754ca2132943 | atagen | 2026-10-19 07:29 UTC | 66 | pub float_default: bool, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 67 | pub fullscreen: bool, |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 68 | /// The window this one is a dialog or other transient of. |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 69 | pub parent: Option<WindowId>, |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 70 | /// Focus aimed at the parent goes to this window while it is mapped. |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 71 | pub modal: bool, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 72 | pub sticky: bool, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 73 | pub scratchpad: Option<usize>, |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 74 | pub urgent: bool, |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 75 | /// Its client took the buffer away, as when hiding to a tray. The entry |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 76 | /// stays for when the client maps it again, but nothing shows or focuses it. |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 77 | pub hidden: bool, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 78 | evicted_from: Option<String>, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 79 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 80 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 81 | #[derive(Clone, Debug)] |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 82 | pub struct Tag { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 83 | pub name: String, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 84 | pub urgent: bool, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 85 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 86 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 87 | #[derive(Clone, Debug)] |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 88 | pub struct Output { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 89 | pub name: String, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 90 | pub area: Rect, |
bc51c38a6fd9 | atagen | 2026-10-16 22:17 UTC | 91 | pub reserved: Insets, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 92 | pub tree: Tree<WindowId>, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 93 | /// Viewed tags besides the homeless tag, which is always viewed. |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 94 | pub viewed: Vec<TagId>, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 95 | /// Floating windows, bottom to top. |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 96 | pub floating: Vec<WindowId>, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 97 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 98 | |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 99 | impl Output { |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 100 | /// The area left once bars and panels have taken their edges. |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 101 | pub fn usable(&self) -> Rect { |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 102 | let (a, r) = (self.area, self.reserved); |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 103 | Rect::new( |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 104 | a.x + r.left, |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 105 | a.y + r.top, |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 106 | (a.w - r.left - r.right).max(0.0), |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 107 | (a.h - r.top - r.bottom).max(0.0), |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 108 | ) |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 109 | } |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 110 | } |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 111 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 112 | #[derive(Clone, Debug)] |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 113 | pub struct Scratchpad { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 114 | pub name: String, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 115 | pub windows: Vec<WindowId>, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 116 | pub shown: Option<usize>, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 117 | pub output: Option<OutputId>, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 118 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 119 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 120 | #[derive(Clone, Debug, Default)] |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 121 | pub struct Arrangement { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 122 | /// Every tiled window on the output. Hidden ones are zero-size seeds. |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 123 | pub tiled: Vec<Placed>, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 124 | /// Visible floating windows and shown scratchpads, bottom to top. |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 125 | pub floating: Vec<(WindowId, Rect)>, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 126 | pub fullscreen: Option<WindowId>, |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 127 | /// Floating transients of the fullscreen window and shown scratchpads, |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 128 | /// which stay above it. |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 129 | pub over: Vec<WindowId>, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 130 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 131 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 132 | #[derive(Clone, Copy, Debug)] |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 133 | pub struct Placed { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 134 | pub window: WindowId, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 135 | pub rect: Rect, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 136 | pub visible: bool, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 137 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 138 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 139 | #[derive(Clone, Debug)] |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 140 | pub struct Layout { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 141 | windows: SlotMap<WindowId, Window>, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 142 | tags: SlotMap<TagId, Tag>, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 143 | tag_order: Vec<TagId>, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 144 | homeless: TagId, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 145 | outputs: SlotMap<OutputId, Output>, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 146 | active: Option<OutputId>, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 147 | /// Focus history, most recent last. |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 148 | history: Vec<WindowId>, |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 149 | /// How many windows are modal, so focus lookups skip the scan for one. |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 150 | modals: usize, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 151 | scratchpads: Vec<Scratchpad>, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 152 | last_scratchpad: Option<usize>, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 153 | parked: HashMap<String, Parked>, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 154 | pub gaps: Gaps, |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 155 | pub autotile: bool, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 156 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 157 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 158 | impl Default for Layout { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 159 | fn default() -> Self { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 160 | let mut tags = SlotMap::with_key(); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 161 | let homeless = tags.insert(Tag { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 162 | name: HOMELESS.into(), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 163 | urgent: false, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 164 | }); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 165 | Self { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 166 | windows: SlotMap::with_key(), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 167 | tags, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 168 | tag_order: vec![homeless], |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 169 | homeless, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 170 | outputs: SlotMap::with_key(), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 171 | active: None, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 172 | history: Vec::new(), |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 173 | modals: 0, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 174 | scratchpads: Vec::new(), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 175 | last_scratchpad: None, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 176 | parked: HashMap::new(), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 177 | gaps: Gaps::default(), |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 178 | autotile: false, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 179 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 180 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 181 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 182 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 183 | impl Layout { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 184 | pub fn homeless(&self) -> TagId { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 185 | self.homeless |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 186 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 187 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 188 | /// Looks a tag up by name, creating it at the end of the order. |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 189 | pub fn tag(&mut self, name: &str) -> TagId { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 190 | if let Some(id) = self.tag_id(name) { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 191 | return id; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 192 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 193 | let id = self.tags.insert(Tag { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 194 | name: name.into(), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 195 | urgent: false, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 196 | }); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 197 | self.tag_order.push(id); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 198 | id |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 199 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 200 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 201 | pub fn tag_id(&self, name: &str) -> Option<TagId> { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 202 | self.tag_order |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 203 | .iter() |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 204 | .copied() |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 205 | .find(|&t| self.tags[t].name == name) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 206 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 207 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 208 | pub fn tags(&self) -> impl Iterator<Item = (TagId, &Tag)> { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 209 | self.tag_order.iter().map(|&t| (t, &self.tags[t])) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 210 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 211 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 212 | pub fn reorder_tag(&mut self, tag: TagId, index: usize) { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 213 | if let Some(i) = self.tag_order.iter().position(|&t| t == tag) { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 214 | self.tag_order.remove(i); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 215 | let index = index.min(self.tag_order.len()); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 216 | self.tag_order.insert(index, tag); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 217 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 218 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 219 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 220 | pub fn window(&self, w: WindowId) -> Option<&Window> { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 221 | self.windows.get(w) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 222 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 223 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 224 | pub fn windows(&self) -> impl Iterator<Item = (WindowId, &Window)> { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 225 | self.windows.iter() |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 226 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 227 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 228 | pub fn output(&self, o: OutputId) -> Option<&Output> { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 229 | self.outputs.get(o) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 230 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 231 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 232 | pub fn outputs(&self) -> impl Iterator<Item = (OutputId, &Output)> { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 233 | self.outputs.iter() |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 234 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 235 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 236 | pub fn scratchpads(&self) -> &[Scratchpad] { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 237 | &self.scratchpads |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 238 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 239 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 240 | pub fn active_output(&self) -> Option<OutputId> { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 241 | self.active |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 242 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 243 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 244 | pub fn set_active_output(&mut self, o: OutputId) { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 245 | if self.outputs.contains_key(o) { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 246 | self.active = Some(o); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 247 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 248 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 249 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 250 | pub fn is_viewed(&self, o: OutputId, tag: TagId) -> bool { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 251 | tag == self.homeless |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 252 | || self |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 253 | .outputs |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 254 | .get(o) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 255 | .is_some_and(|out| out.viewed.contains(&tag)) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 256 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 257 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 258 | /// Views `tag` alone, besides the homeless tag. |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 259 | pub fn view(&mut self, o: OutputId, tag: TagId) { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 260 | let Some(out) = self.outputs.get_mut(o) else { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 261 | return; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 262 | }; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 263 | out.viewed.clear(); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 264 | if tag != self.homeless { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 265 | out.viewed.push(tag); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 266 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 267 | self.tags[tag].urgent = false; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 268 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 269 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 270 | pub fn toggle_view(&mut self, o: OutputId, tag: TagId) { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 271 | if tag == self.homeless { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 272 | return; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 273 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 274 | let Some(out) = self.outputs.get_mut(o) else { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 275 | return; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 276 | }; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 277 | if let Some(i) = out.viewed.iter().position(|&t| t == tag) { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 278 | out.viewed.remove(i); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 279 | } else { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 280 | out.viewed.push(tag); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 281 | self.tags[tag].urgent = false; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 282 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 283 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 284 | |
5ab6f980c72f | atagen | 2026-10-17 10:20 UTC | 285 | /// Brings `w`'s tag into view beside the others when `w` is the only |
5ab6f980c72f | atagen | 2026-10-17 10:20 UTC | 286 | /// window on it there. |
5ab6f980c72f | atagen | 2026-10-17 10:20 UTC | 287 | pub fn view_if_alone(&mut self, w: WindowId) { |
5ab6f980c72f | atagen | 2026-10-17 10:20 UTC | 288 | let Some(win) = self.windows.get(w) else { |
5ab6f980c72f | atagen | 2026-10-17 10:20 UTC | 289 | return; |
5ab6f980c72f | atagen | 2026-10-17 10:20 UTC | 290 | }; |
5ab6f980c72f | atagen | 2026-10-17 10:20 UTC | 291 | let (Some(o), tag) = (win.output, win.tag) else { |
5ab6f980c72f | atagen | 2026-10-17 10:20 UTC | 292 | return; |
5ab6f980c72f | atagen | 2026-10-17 10:20 UTC | 293 | }; |
5ab6f980c72f | atagen | 2026-10-17 10:20 UTC | 294 | if win.scratchpad.is_some() || self.is_viewed(o, tag) { |
5ab6f980c72f | atagen | 2026-10-17 10:20 UTC | 295 | return; |
5ab6f980c72f | atagen | 2026-10-17 10:20 UTC | 296 | } |
cadf3a07a5dc | atagen | 2026-10-19 10:29 UTC | 297 | let alone = !self.windows.iter().any(|(x, v)| { |
cadf3a07a5dc | atagen | 2026-10-19 10:29 UTC | 298 | x != w && v.output == Some(o) && v.tag == tag && v.scratchpad.is_none() && !v.hidden |
cadf3a07a5dc | atagen | 2026-10-19 10:29 UTC | 299 | }); |
5ab6f980c72f | atagen | 2026-10-17 10:20 UTC | 300 | if alone { |
5ab6f980c72f | atagen | 2026-10-17 10:20 UTC | 301 | self.toggle_view(o, tag); |
5ab6f980c72f | atagen | 2026-10-17 10:20 UTC | 302 | } |
5ab6f980c72f | atagen | 2026-10-17 10:20 UTC | 303 | } |
5ab6f980c72f | atagen | 2026-10-17 10:20 UTC | 304 | |
bae1138a3e88 | atagen | 2026-10-19 11:47 UTC | 305 | /// The tag a launch from `o` belongs to, the focused window's tag or else |
bae1138a3e88 | atagen | 2026-10-19 11:47 UTC | 306 | /// homeless. |
4e5afcada08b | atagen | 2026-10-16 10:14 UTC | 307 | pub fn launch_tag(&self, o: OutputId) -> TagId { |
4e5afcada08b | atagen | 2026-10-16 10:14 UTC | 308 | self.focused_on(o) |
4e5afcada08b | atagen | 2026-10-16 10:14 UTC | 309 | .map(|w| &self.windows[w]) |
bae1138a3e88 | atagen | 2026-10-19 11:47 UTC | 310 | .filter(|w| w.scratchpad.is_none() && !w.sticky) |
bae1138a3e88 | atagen | 2026-10-19 11:47 UTC | 311 | .map_or(self.homeless, |w| w.tag) |
4e5afcada08b | atagen | 2026-10-16 10:14 UTC | 312 | } |
4e5afcada08b | atagen | 2026-10-16 10:14 UTC | 313 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 314 | pub fn view_everywhere(&mut self, tag: TagId) { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 315 | for o in self.outputs.keys().collect::<Vec<_>>() { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 316 | self.view(o, tag); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 317 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 318 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 319 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 320 | pub fn visible(&self, w: WindowId) -> bool { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 321 | let Some(win) = self.windows.get(w) else { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 322 | return false; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 323 | }; |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 324 | let Some(o) = win.output.filter(|_| !win.hidden) else { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 325 | return false; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 326 | }; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 327 | match win.scratchpad { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 328 | Some(s) => { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 329 | let sp = &self.scratchpads[s]; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 330 | sp.output == Some(o) && sp.shown.map(|i| sp.windows[i]) == Some(w) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 331 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 332 | None => win.sticky || self.is_viewed(o, win.tag), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 333 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 334 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 335 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 336 | /// Adds a window on `output` (default the active one) and `tag` (default |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 337 | /// homeless). A window landing on a tag its output is not viewing marks |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 338 | /// the tag urgent. |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 339 | pub fn add_window( |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 340 | &mut self, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 341 | output: Option<OutputId>, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 342 | tag: Option<TagId>, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 343 | floating: Option<Rect>, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 344 | ) -> WindowId { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 345 | let output = output |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 346 | .filter(|&o| self.outputs.contains_key(o)) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 347 | .or(self.active); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 348 | let tag = tag |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 349 | .filter(|&t| self.tags.contains_key(t)) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 350 | .unwrap_or(self.homeless); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 351 | let w = self.windows.insert(Window { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 352 | output, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 353 | tag, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 354 | floating: floating.is_some(), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 355 | float_rect: floating, |
754ca2132943 | atagen | 2026-10-19 07:29 UTC | 356 | float_default: false, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 357 | fullscreen: false, |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 358 | parent: None, |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 359 | modal: false, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 360 | sticky: false, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 361 | scratchpad: None, |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 362 | urgent: false, |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 363 | hidden: false, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 364 | evicted_from: None, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 365 | }); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 366 | if let Some(o) = output { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 367 | if !self.is_viewed(o, tag) { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 368 | self.tags[tag].urgent = true; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 369 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 370 | self.place(w); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 371 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 372 | w |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 373 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 374 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 375 | pub fn remove_window(&mut self, w: WindowId) { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 376 | if !self.windows.contains_key(w) { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 377 | return; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 378 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 379 | self.unplace(w); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 380 | self.history.retain(|&h| h != w); |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 381 | self.modals -= usize::from(self.windows[w].modal); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 382 | if let Some(s) = self.windows[w].scratchpad { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 383 | self.leave_scratchpad(s, w); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 384 | } |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 385 | for win in self.windows.values_mut() { |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 386 | if win.parent == Some(w) { |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 387 | win.parent = None; |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 388 | } |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 389 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 390 | self.windows.remove(w); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 391 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 392 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 393 | /// Puts a window into its output's tree or floating stack. Tiled windows |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 394 | /// go next to the focused window if both are visible, else next to the |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 395 | /// latest window of their tag, else into a new row. |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 396 | fn place(&mut self, w: WindowId) { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 397 | let win = &self.windows[w]; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 398 | let Some(o) = win.output else { return }; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 399 | if win.scratchpad.is_some() { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 400 | return; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 401 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 402 | if win.floating { |
243161cd0662 | atagen | 2026-10-19 10:41 UTC | 403 | let usable = self.outputs[o].usable(); |
243161cd0662 | atagen | 2026-10-19 10:41 UTC | 404 | let win = &mut self.windows[w]; |
243161cd0662 | atagen | 2026-10-19 10:41 UTC | 405 | match win.float_rect { |
243161cd0662 | atagen | 2026-10-19 10:41 UTC | 406 | Some(rect) => win.float_rect = Some(clamp_float(rect, usable)), |
243161cd0662 | atagen | 2026-10-19 10:41 UTC | 407 | None => { |
243161cd0662 | atagen | 2026-10-19 10:41 UTC | 408 | win.float_rect = Some(centred(usable, 0.6)); |
243161cd0662 | atagen | 2026-10-19 10:41 UTC | 409 | win.float_default = true; |
243161cd0662 | atagen | 2026-10-19 10:41 UTC | 410 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 411 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 412 | self.outputs[o].floating.push(w); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 413 | return; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 414 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 415 | let tag = win.tag; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 416 | let tree = &self.outputs[o].tree; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 417 | let focused = self |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 418 | .focused() |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 419 | .filter(|&f| tree.contains(f) && self.is_viewed(o, tag)); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 420 | let anchor = focused.or_else(|| { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 421 | self.history |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 422 | .iter() |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 423 | .rev() |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 424 | .copied() |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 425 | .find(|&h| tree.contains(h) && self.windows[h].tag == tag) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 426 | }); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 427 | let split = anchor |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 428 | .filter(|_| self.autotile) |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 429 | .and_then(|a| self.split_axis(o, a)); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 430 | let tree = &mut self.outputs[o].tree; |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 431 | match (anchor, split) { |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 432 | (Some(a), Some(axis)) => tree.insert_split(w, a, axis), |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 433 | (Some(a), None) => tree.insert_after(w, a), |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 434 | (None, _) => tree.insert_row(w), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 435 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 436 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 437 | |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 438 | /// The axis a window opening beside `anchor` should split it along, the |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 439 | /// way the anchor is laid out right now. Hidden anchors have no shape. |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 440 | fn split_axis(&self, o: OutputId, anchor: WindowId) -> Option<Axis> { |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 441 | let rect = self |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 442 | .arrange(o) |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 443 | .tiled |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 444 | .iter() |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 445 | .find(|p| p.window == anchor && p.visible)? |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 446 | .rect; |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 447 | let axis = if rect.w > rect.h { |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 448 | Axis::Horizontal |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 449 | } else { |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 450 | Axis::Vertical |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 451 | }; |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 452 | (rect.w > 0.0 && rect.h > 0.0).then_some(axis) |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 453 | } |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 454 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 455 | fn unplace(&mut self, w: WindowId) { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 456 | let Some(o) = self.windows[w].output else { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 457 | return; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 458 | }; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 459 | let out = &mut self.outputs[o]; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 460 | out.tree.remove(w); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 461 | out.floating.retain(|&f| f != w); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 462 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 463 | |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 464 | /// Focuses `w`, or the deepest modal dialog over it, which is returned. |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 465 | /// The windows between stay below it in the history, and a modal dialog |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 466 | /// focused on its own brings its parent up beneath it, so closing the |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 467 | /// dialog hands focus back to its parent. |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 468 | pub fn focus(&mut self, mut w: WindowId) -> Option<WindowId> { |
692a9dda8779 | atagen | 2026-10-20 11:44 UTC | 469 | if self.eclipsed(w) { |
692a9dda8779 | atagen | 2026-10-20 11:44 UTC | 470 | return None; |
692a9dda8779 | atagen | 2026-10-20 11:44 UTC | 471 | } |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 472 | loop { |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 473 | let win = self.windows.get(w)?; |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 474 | self.active = win.output.or(self.active); |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 475 | if let Some(o) = win.output { |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 476 | let stack = &mut self.outputs[o].floating; |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 477 | if let Some(i) = stack.iter().position(|&f| f == w) { |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 478 | stack.remove(i); |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 479 | stack.push(w); |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 480 | } |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 481 | } |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 482 | let parent = win.parent.filter(|_| win.modal); |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 483 | self.history.retain(|&h| h != w); |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 484 | self.history.push(w); |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 485 | if let Some(p) = parent { |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 486 | self.history.retain(|&h| h != p); |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 487 | self.history.insert(self.history.len() - 1, p); |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 488 | } |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 489 | self.windows[w].urgent = false; |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 490 | match self.modal_child(w) { |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 491 | Some(child) => w = child, |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 492 | None => return Some(w), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 493 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 494 | } |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 495 | } |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 496 | |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 497 | /// Marks `w` as a modal dialog of its parent, or not. |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 498 | pub fn set_modal(&mut self, w: WindowId, modal: bool) { |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 499 | if let Some(win) = self.windows.get_mut(w) |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 500 | && std::mem::replace(&mut win.modal, modal) != modal |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 501 | { |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 502 | self.modals = if modal { |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 503 | self.modals + 1 |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 504 | } else { |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 505 | self.modals - 1 |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 506 | }; |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 507 | } |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 508 | } |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 509 | |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 510 | /// The visible modal dialog of `w` on its output, the most recently |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 511 | /// focused if it has several. |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 512 | pub fn modal_child(&self, w: WindowId) -> Option<WindowId> { |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 513 | if self.modals == 0 { |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 514 | return None; |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 515 | } |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 516 | let output = self.windows.get(w)?.output; |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 517 | self.windows |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 518 | .iter() |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 519 | .filter(|&(c, win)| { |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 520 | win.modal && win.parent == Some(w) && win.output == output && self.visible(c) |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 521 | }) |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 522 | .max_by_key(|&(c, _)| self.history.iter().rposition(|&h| h == c)) |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 523 | .map(|(c, _)| c) |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 524 | } |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 525 | |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 526 | /// The window that takes focus aimed at `w`, the deepest modal dialog |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 527 | /// over it or `w` itself. |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 528 | pub fn modal_leaf(&self, mut w: WindowId) -> WindowId { |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 529 | while let Some(child) = self.modal_child(w) { |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 530 | w = child; |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 531 | } |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 532 | w |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 533 | } |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 534 | |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 535 | /// Whether focus aimed at `w` would change nothing. |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 536 | pub fn is_focused(&self, w: WindowId) -> bool { |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 537 | self.focused() == Some(self.modal_leaf(w)) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 538 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 539 | |
adcf397e4f74 | atagen | 2026-10-18 09:56 UTC | 540 | /// The most recently focused visible window on the active output. Focus |
adcf397e4f74 | atagen | 2026-10-18 09:56 UTC | 541 | /// falling back to another output would leave keybinds acting on one |
adcf397e4f74 | atagen | 2026-10-18 09:56 UTC | 542 | /// output while the keyboard and pointer sit on another. |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 543 | pub fn focused(&self) -> Option<WindowId> { |
adcf397e4f74 | atagen | 2026-10-18 09:56 UTC | 544 | self.focused_on(self.active?) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 545 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 546 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 547 | /// The most recently focused visible window on `o`. |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 548 | pub fn focused_on(&self, o: OutputId) -> Option<WindowId> { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 549 | self.history |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 550 | .iter() |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 551 | .rev() |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 552 | .copied() |
692a9dda8779 | atagen | 2026-10-20 11:44 UTC | 553 | .find(|&w| self.windows[w].output == Some(o) && self.visible(w) && !self.eclipsed(w)) |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 554 | .map(|w| self.modal_leaf(w)) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 555 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 556 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 557 | /// Focuses the nearest visible window in `dir`, crossing to the next |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 558 | /// output when there is none on this one. |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 559 | pub fn focus_dir(&mut self, dir: Dir) -> Option<WindowId> { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 560 | let o = self.active?; |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 561 | let current = self.focused_on(o); |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 562 | let from = current.and_then(|f| self.rect_of(f)); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 563 | let target = from.and_then(|from| { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 564 | let arr = self.arrange(o); |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 565 | let reachable = |w| { |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 566 | arr.fullscreen |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 567 | .is_none_or(|f| w == f || arr.over.contains(&w)) |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 568 | }; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 569 | let candidates = arr |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 570 | .tiled |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 571 | .iter() |
692a9dda8779 | atagen | 2026-10-20 11:44 UTC | 572 | .filter(|p| p.visible && !self.eclipsed(p.window)) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 573 | .map(|p| (p.window, p.rect)) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 574 | .chain(arr.floating.iter().copied()) |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 575 | .filter(|&(w, _)| Some(self.modal_leaf(w)) != current && reachable(w)); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 576 | nearest(from, dir, candidates) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 577 | }); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 578 | if let Some(w) = target { |
ecb0c8c1f31d | atagen | 2026-10-19 10:15 UTC | 579 | return self.focus(w); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 580 | } |
4e5afcada08b | atagen | 2026-10-16 10:14 UTC | 581 | let next = self.output_towards(o, dir)?; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 582 | self.active = Some(next); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 583 | let w = self.focused_on(next); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 584 | if let Some(w) = w { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 585 | self.focus(w); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 586 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 587 | w |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 588 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 589 | |
4e5afcada08b | atagen | 2026-10-16 10:14 UTC | 590 | pub fn output_towards(&self, from: OutputId, dir: Dir) -> Option<OutputId> { |
4e5afcada08b | atagen | 2026-10-16 10:14 UTC | 591 | let here = self.outputs.get(from)?.area; |
4e5afcada08b | atagen | 2026-10-16 10:14 UTC | 592 | let others = self |
4e5afcada08b | atagen | 2026-10-16 10:14 UTC | 593 | .outputs |
4e5afcada08b | atagen | 2026-10-16 10:14 UTC | 594 | .iter() |
4e5afcada08b | atagen | 2026-10-16 10:14 UTC | 595 | .filter(|&(id, _)| id != from) |
4e5afcada08b | atagen | 2026-10-16 10:14 UTC | 596 | .map(|(id, out)| (id, out.area)); |
4e5afcada08b | atagen | 2026-10-16 10:14 UTC | 597 | nearest(here, dir, others) |
4e5afcada08b | atagen | 2026-10-16 10:14 UTC | 598 | } |
4e5afcada08b | atagen | 2026-10-16 10:14 UTC | 599 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 600 | fn rect_of(&self, w: WindowId) -> Option<Rect> { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 601 | let o = self.windows.get(w)?.output?; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 602 | let arr = self.arrange(o); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 603 | arr.tiled |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 604 | .iter() |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 605 | .find(|p| p.window == w) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 606 | .map(|p| p.rect) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 607 | .or_else(|| arr.floating.iter().find(|f| f.0 == w).map(|f| f.1)) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 608 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 609 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 610 | fn vis_on(&self, o: OutputId) -> impl Fn(WindowId) -> bool + '_ { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 611 | move |w| self.windows[w].output == Some(o) && self.visible(w) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 612 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 613 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 614 | fn focused_tiled(&self) -> Option<(WindowId, OutputId)> { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 615 | let w = self.focused()?; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 616 | let o = self.windows[w].output?; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 617 | self.outputs[o].tree.contains(w).then_some((w, o)) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 618 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 619 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 620 | pub fn move_window(&mut self, dir: Dir) -> bool { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 621 | let Some((w, o)) = self.focused_tiled() else { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 622 | return false; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 623 | }; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 624 | let mut tree = std::mem::take(&mut self.outputs[o].tree); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 625 | let moved = tree.move_window(w, dir, self.vis_on(o)); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 626 | self.outputs[o].tree = tree; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 627 | moved |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 628 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 629 | |
21e8e8e5aa3d | atagen | 2026-10-20 11:44 UTC | 630 | pub fn move_container(&mut self, dir: Dir, merge: bool) -> bool { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 631 | let Some((w, o)) = self.focused_tiled() else { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 632 | return false; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 633 | }; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 634 | let mut tree = std::mem::take(&mut self.outputs[o].tree); |
21e8e8e5aa3d | atagen | 2026-10-20 11:44 UTC | 635 | let moved = tree.move_container(w, dir, merge, self.vis_on(o)); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 636 | self.outputs[o].tree = tree; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 637 | moved |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 638 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 639 | |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 640 | pub fn merge_window(&mut self, dir: Dir) -> bool { |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 641 | let Some((w, o)) = self.focused_tiled() else { |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 642 | return false; |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 643 | }; |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 644 | let mut tree = std::mem::take(&mut self.outputs[o].tree); |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 645 | let merged = tree.merge_window(w, dir, self.vis_on(o)); |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 646 | self.outputs[o].tree = tree; |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 647 | merged |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 648 | } |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 649 | |
406db966344c | atagen | 2026-10-20 11:44 UTC | 650 | /// Whether a tiled window is extended over others sharing its container. |
406db966344c | atagen | 2026-10-20 11:44 UTC | 651 | pub fn grouped(&self, w: WindowId) -> bool { |
406db966344c | atagen | 2026-10-20 11:44 UTC | 652 | let Some(o) = self.windows.get(w).and_then(|w| w.output) else { |
406db966344c | atagen | 2026-10-20 11:44 UTC | 653 | return false; |
406db966344c | atagen | 2026-10-20 11:44 UTC | 654 | }; |
406db966344c | atagen | 2026-10-20 11:44 UTC | 655 | self.outputs[o].tree.grouped(w, self.vis_on(o)) |
406db966344c | atagen | 2026-10-20 11:44 UTC | 656 | } |
406db966344c | atagen | 2026-10-20 11:44 UTC | 657 | |
692a9dda8779 | atagen | 2026-10-20 11:44 UTC | 658 | /// Whether another window is extended over the tiled window `w`, which |
692a9dda8779 | atagen | 2026-10-20 11:44 UTC | 659 | /// leaves it no room and takes it out of reach of focus. |
692a9dda8779 | atagen | 2026-10-20 11:44 UTC | 660 | pub fn eclipsed(&self, w: WindowId) -> bool { |
692a9dda8779 | atagen | 2026-10-20 11:44 UTC | 661 | let Some(o) = self |
692a9dda8779 | atagen | 2026-10-20 11:44 UTC | 662 | .windows |
692a9dda8779 | atagen | 2026-10-20 11:44 UTC | 663 | .get(w) |
692a9dda8779 | atagen | 2026-10-20 11:44 UTC | 664 | .filter(|w| !w.fullscreen) |
692a9dda8779 | atagen | 2026-10-20 11:44 UTC | 665 | .and_then(|w| w.output) |
692a9dda8779 | atagen | 2026-10-20 11:44 UTC | 666 | else { |
692a9dda8779 | atagen | 2026-10-20 11:44 UTC | 667 | return false; |
692a9dda8779 | atagen | 2026-10-20 11:44 UTC | 668 | }; |
692a9dda8779 | atagen | 2026-10-20 11:44 UTC | 669 | self.outputs[o].tree.eclipsed(w, self.vis_on(o)) |
692a9dda8779 | atagen | 2026-10-20 11:44 UTC | 670 | } |
692a9dda8779 | atagen | 2026-10-20 11:44 UTC | 671 | |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 672 | /// Whether a tiled window fills its output through expansion. |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 673 | pub fn maximized(&self, w: WindowId) -> bool { |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 674 | let Some(o) = self.windows.get(w).and_then(|w| w.output) else { |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 675 | return false; |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 676 | }; |
54559daf11c3 | atagen | 2026-10-17 13:38 UTC | 677 | self.outputs[o].tree.maximized(w, self.vis_on(o)) |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 678 | } |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 679 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 680 | pub fn resize(&mut self, axis: Axis, delta: f64) -> bool { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 681 | let Some((w, o)) = self.focused_tiled() else { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 682 | return false; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 683 | }; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 684 | let mut tree = std::mem::take(&mut self.outputs[o].tree); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 685 | let done = tree.resize(w, axis, delta, self.vis_on(o)); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 686 | self.outputs[o].tree = tree; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 687 | done |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 688 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 689 | |
abe5e42a95d6 | atagen | 2026-10-19 07:52 UTC | 690 | /// Whether `w` is tiled with a visible window across the split on side `dir`. |
abe5e42a95d6 | atagen | 2026-10-19 07:52 UTC | 691 | pub fn has_split(&self, w: WindowId, dir: Dir) -> bool { |
abe5e42a95d6 | atagen | 2026-10-19 07:52 UTC | 692 | let Some(o) = self.windows.get(w).and_then(|w| w.output) else { |
abe5e42a95d6 | atagen | 2026-10-19 07:52 UTC | 693 | return false; |
abe5e42a95d6 | atagen | 2026-10-19 07:52 UTC | 694 | }; |
abe5e42a95d6 | atagen | 2026-10-19 07:52 UTC | 695 | self.outputs[o].tree.has_split(w, dir, self.vis_on(o)) |
abe5e42a95d6 | atagen | 2026-10-19 07:52 UTC | 696 | } |
abe5e42a95d6 | atagen | 2026-10-19 07:52 UTC | 697 | |
abe5e42a95d6 | atagen | 2026-10-19 07:52 UTC | 698 | /// Moves the split on side `dir` of the tiled window `w` by `px`, positive |
abe5e42a95d6 | atagen | 2026-10-19 07:52 UTC | 699 | /// toward the right or bottom. |
abe5e42a95d6 | atagen | 2026-10-19 07:52 UTC | 700 | pub fn move_split(&mut self, w: WindowId, dir: Dir, px: f64) -> bool { |
abe5e42a95d6 | atagen | 2026-10-19 07:52 UTC | 701 | let Some(o) = self.windows.get(w).and_then(|w| w.output) else { |
abe5e42a95d6 | atagen | 2026-10-19 07:52 UTC | 702 | return false; |
abe5e42a95d6 | atagen | 2026-10-19 07:52 UTC | 703 | }; |
abe5e42a95d6 | atagen | 2026-10-19 07:52 UTC | 704 | let area = inset(self.outputs[o].usable(), self.gaps.outer); |
abe5e42a95d6 | atagen | 2026-10-19 07:52 UTC | 705 | let mut tree = std::mem::take(&mut self.outputs[o].tree); |
abe5e42a95d6 | atagen | 2026-10-19 07:52 UTC | 706 | let moved = tree.move_split(w, dir, px, area, self.gaps.inner, self.vis_on(o)); |
abe5e42a95d6 | atagen | 2026-10-19 07:52 UTC | 707 | self.outputs[o].tree = tree; |
abe5e42a95d6 | atagen | 2026-10-19 07:52 UTC | 708 | moved |
abe5e42a95d6 | atagen | 2026-10-19 07:52 UTC | 709 | } |
abe5e42a95d6 | atagen | 2026-10-19 07:52 UTC | 710 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 711 | pub fn expand(&mut self, scope: ExpandScope) -> bool { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 712 | let Some((w, o)) = self.focused_tiled() else { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 713 | return false; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 714 | }; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 715 | let (skip, count) = match scope { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 716 | ExpandScope::Window => (0, 1), |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 717 | ExpandScope::Container => (1, 1), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 718 | ExpandScope::All => (0, usize::MAX), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 719 | }; |
54559daf11c3 | atagen | 2026-10-17 13:38 UTC | 720 | let mut tree = std::mem::take(&mut self.outputs[o].tree); |
54559daf11c3 | atagen | 2026-10-17 13:38 UTC | 721 | let expanded = tree.toggle_expand(w, skip, count, self.vis_on(o)); |
54559daf11c3 | atagen | 2026-10-17 13:38 UTC | 722 | self.outputs[o].tree = tree; |
54559daf11c3 | atagen | 2026-10-17 13:38 UTC | 723 | expanded |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 724 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 725 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 726 | pub fn flip(&mut self, o: OutputId) { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 727 | if let Some(out) = self.outputs.get_mut(o) { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 728 | out.tree.flip(); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 729 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 730 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 731 | |
1c1f70798e98 | atagen | 2026-10-22 05:39 UTC | 732 | /// Retags a window along with the windows it is extended over. They keep |
1c1f70798e98 | atagen | 2026-10-22 05:39 UTC | 733 | /// their slots and disappear if the new tag is not viewed. |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 734 | pub fn set_tag(&mut self, w: WindowId, tag: TagId) { |
1c1f70798e98 | atagen | 2026-10-22 05:39 UTC | 735 | let Some(win) = self.windows.get(w) else { |
1c1f70798e98 | atagen | 2026-10-22 05:39 UTC | 736 | return; |
1c1f70798e98 | atagen | 2026-10-22 05:39 UTC | 737 | }; |
1c1f70798e98 | atagen | 2026-10-22 05:39 UTC | 738 | if !self.tags.contains_key(tag) { |
1c1f70798e98 | atagen | 2026-10-22 05:39 UTC | 739 | return; |
1c1f70798e98 | atagen | 2026-10-22 05:39 UTC | 740 | } |
1c1f70798e98 | atagen | 2026-10-22 05:39 UTC | 741 | let group = match win.output { |
1c1f70798e98 | atagen | 2026-10-22 05:39 UTC | 742 | Some(o) => self.outputs[o].tree.group_windows(w, self.vis_on(o)), |
1c1f70798e98 | atagen | 2026-10-22 05:39 UTC | 743 | None => vec![w], |
1c1f70798e98 | atagen | 2026-10-22 05:39 UTC | 744 | }; |
1c1f70798e98 | atagen | 2026-10-22 05:39 UTC | 745 | for g in group { |
1c1f70798e98 | atagen | 2026-10-22 05:39 UTC | 746 | self.windows[g].tag = tag; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 747 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 748 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 749 | |
02d5a5d5b17e | atagen | 2026-10-16 22:24 UTC | 750 | /// Moves a window to `tag` on `o`, marking the tag urgent when the window |
02d5a5d5b17e | atagen | 2026-10-16 22:24 UTC | 751 | /// ends up out of sight. |
02d5a5d5b17e | atagen | 2026-10-16 22:24 UTC | 752 | pub fn relocate(&mut self, w: WindowId, o: Option<OutputId>, tag: TagId) { |
02d5a5d5b17e | atagen | 2026-10-16 22:24 UTC | 753 | if let Some(o) = o { |
02d5a5d5b17e | atagen | 2026-10-16 22:24 UTC | 754 | self.send_to_output(w, o); |
02d5a5d5b17e | atagen | 2026-10-16 22:24 UTC | 755 | } |
02d5a5d5b17e | atagen | 2026-10-16 22:24 UTC | 756 | self.set_tag(w, tag); |
02d5a5d5b17e | atagen | 2026-10-16 22:24 UTC | 757 | self.mark_urgent(w); |
02d5a5d5b17e | atagen | 2026-10-16 22:24 UTC | 758 | } |
02d5a5d5b17e | atagen | 2026-10-16 22:24 UTC | 759 | |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 760 | /// Flags a window that wants attention unless it already has the focus, |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 761 | /// and its tag too when the window is out of sight. |
02d5a5d5b17e | atagen | 2026-10-16 22:24 UTC | 762 | pub fn mark_urgent(&mut self, w: WindowId) { |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 763 | if self.windows.get(w).is_none_or(|win| win.hidden) { |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 764 | return; |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 765 | } |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 766 | if self.focused() != Some(w) { |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 767 | self.windows[w].urgent = true; |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 768 | } |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 769 | if !self.visible(w) { |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 770 | let tag = self.windows[w].tag; |
02d5a5d5b17e | atagen | 2026-10-16 22:24 UTC | 771 | self.tags[tag].urgent = true; |
02d5a5d5b17e | atagen | 2026-10-16 22:24 UTC | 772 | } |
02d5a5d5b17e | atagen | 2026-10-16 22:24 UTC | 773 | } |
02d5a5d5b17e | atagen | 2026-10-16 22:24 UTC | 774 | |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 775 | /// Drops the flag of the window holding the focus, which can reach it |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 776 | /// without `focus`, when the window before it closes or its tag is viewed. |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 777 | pub fn clear_focused_urgent(&mut self) { |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 778 | if let Some(w) = self.focused() { |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 779 | self.windows[w].urgent = false; |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 780 | } |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 781 | } |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 782 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 783 | pub fn send_to_output(&mut self, w: WindowId, o: OutputId) { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 784 | let Some(win) = self.windows.get(w) else { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 785 | return; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 786 | }; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 787 | if !self.outputs.contains_key(o) || win.output == Some(o) || win.scratchpad.is_some() { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 788 | return; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 789 | } |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 790 | let from = win.output.map(|f| self.outputs[f].usable()); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 791 | self.unplace(w); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 792 | let win = &mut self.windows[w]; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 793 | if let (Some(from), Some(rect)) = (from, win.float_rect) { |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 794 | win.float_rect = Some(translate(rect, from, self.outputs[o].usable())); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 795 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 796 | win.output = Some(o); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 797 | win.evicted_from = None; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 798 | self.place(w); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 799 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 800 | |
48af562d968b | atagen | 2026-10-16 12:39 UTC | 801 | /// Switches a window between tiled and floating. A scratchpad window |
48af562d968b | atagen | 2026-10-16 12:39 UTC | 802 | /// leaves its scratchpad and tiles on the tag being viewed, since its own |
48af562d968b | atagen | 2026-10-16 12:39 UTC | 803 | /// tag may well be hidden. |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 804 | pub fn toggle_floating(&mut self, w: WindowId) { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 805 | let Some(win) = self.windows.get(w) else { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 806 | return; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 807 | }; |
48af562d968b | atagen | 2026-10-16 12:39 UTC | 808 | if let Some(s) = win.scratchpad { |
48af562d968b | atagen | 2026-10-16 12:39 UTC | 809 | let o = win.output.or(self.active); |
bae1138a3e88 | atagen | 2026-10-19 11:47 UTC | 810 | let tag = o |
bae1138a3e88 | atagen | 2026-10-19 11:47 UTC | 811 | .and_then(|o| self.outputs.get(o)?.viewed.first().copied()) |
bae1138a3e88 | atagen | 2026-10-19 11:47 UTC | 812 | .unwrap_or(self.homeless); |
48af562d968b | atagen | 2026-10-16 12:39 UTC | 813 | self.leave_scratchpad(s, w); |
48af562d968b | atagen | 2026-10-16 12:39 UTC | 814 | let win = &mut self.windows[w]; |
48af562d968b | atagen | 2026-10-16 12:39 UTC | 815 | win.output = o; |
48af562d968b | atagen | 2026-10-16 12:39 UTC | 816 | win.tag = tag; |
48af562d968b | atagen | 2026-10-16 12:39 UTC | 817 | win.floating = false; |
48af562d968b | atagen | 2026-10-16 12:39 UTC | 818 | self.place(w); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 819 | return; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 820 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 821 | self.unplace(w); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 822 | let win = &mut self.windows[w]; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 823 | win.floating = !win.floating; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 824 | self.place(w); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 825 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 826 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 827 | pub fn set_float_rect(&mut self, w: WindowId, rect: Rect) { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 828 | if let Some(win) = self.windows.get_mut(w) { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 829 | win.float_rect = Some(rect); |
754ca2132943 | atagen | 2026-10-19 07:29 UTC | 830 | win.float_default = false; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 831 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 832 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 833 | |
fd834695f723 | atagen | 2026-10-19 07:49 UTC | 834 | /// Places a float without settling its size, so a window still deciding |
fd834695f723 | atagen | 2026-10-19 07:49 UTC | 835 | /// on one is asked again after being tiled. |
fd834695f723 | atagen | 2026-10-19 07:49 UTC | 836 | pub fn hold_float_rect(&mut self, w: WindowId, rect: Rect) { |
fd834695f723 | atagen | 2026-10-19 07:49 UTC | 837 | if let Some(win) = self.windows.get_mut(w) { |
fd834695f723 | atagen | 2026-10-19 07:49 UTC | 838 | win.float_rect = Some(rect); |
fd834695f723 | atagen | 2026-10-19 07:49 UTC | 839 | } |
fd834695f723 | atagen | 2026-10-19 07:49 UTC | 840 | } |
fd834695f723 | atagen | 2026-10-19 07:49 UTC | 841 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 842 | pub fn toggle_fullscreen(&mut self, w: WindowId) { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 843 | if let Some(win) = self.windows.get_mut(w) { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 844 | win.fullscreen = !win.fullscreen; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 845 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 846 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 847 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 848 | pub fn toggle_sticky(&mut self, w: WindowId) { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 849 | if let Some(win) = self.windows.get_mut(w) { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 850 | win.sticky = !win.sticky; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 851 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 852 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 853 | |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 854 | /// Hides `w` or shows it again, keeping everything else about it. |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 855 | pub fn set_hidden(&mut self, w: WindowId, hidden: bool) { |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 856 | if let Some(win) = self.windows.get_mut(w) { |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 857 | win.hidden = hidden; |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 858 | win.urgent &= !hidden; |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 859 | } |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 860 | } |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 861 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 862 | /// Target geometry for everything on `o`, in output-local logical |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 863 | /// coordinates offset by the output's area. |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 864 | pub fn arrange(&self, o: OutputId) -> Arrangement { |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 865 | self.arrange_hiding(o, &[]) |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 866 | } |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 867 | |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 868 | /// Like `arrange` with `hide` treated as hidden, which places them on the |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 869 | /// seeds they would grow from. |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 870 | pub fn arrange_hiding(&self, o: OutputId, hide: &[WindowId]) -> Arrangement { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 871 | let Some(out) = self.outputs.get(o) else { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 872 | return Arrangement::default(); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 873 | }; |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 874 | let area = inset(out.usable(), self.gaps.outer); |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 875 | let shown = self.vis_on(o); |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 876 | let vis = &|w: WindowId| shown(w) && !hide.contains(&w); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 877 | let tiled = out |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 878 | .tree |
2af1d8c55876 | atagen | 2026-10-16 11:05 UTC | 879 | .arrange(area, self.gaps.inner, vis) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 880 | .into_iter() |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 881 | .map(|(window, rect)| Placed { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 882 | window, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 883 | rect, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 884 | visible: vis(window), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 885 | }) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 886 | .collect(); |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 887 | let floating = self.floating_on(o, out, vis); |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 888 | let fullscreen = self.fullscreen_in(vis); |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 889 | let over = fullscreen.map_or_else(Vec::new, |f| self.above_fullscreen(f, &floating)); |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 890 | Arrangement { |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 891 | tiled, |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 892 | floating, |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 893 | fullscreen, |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 894 | over, |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 895 | } |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 896 | } |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 897 | |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 898 | fn floating_on( |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 899 | &self, |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 900 | o: OutputId, |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 901 | out: &Output, |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 902 | vis: &dyn Fn(WindowId) -> bool, |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 903 | ) -> Vec<(WindowId, Rect)> { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 904 | let mut floating: Vec<(WindowId, Rect)> = out |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 905 | .floating |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 906 | .iter() |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 907 | .copied() |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 908 | .filter(|&w| vis(w)) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 909 | .filter_map(|w| Some((w, self.windows[w].float_rect?))) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 910 | .collect(); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 911 | for sp in &self.scratchpads { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 912 | if let Some(i) = sp.shown |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 913 | && sp.output == Some(o) |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 914 | && !self.windows[sp.windows[i]].hidden |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 915 | && let Some(r) = self.windows[sp.windows[i]].float_rect |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 916 | { |
b001ce7817ed | atagen | 2026-10-19 09:23 UTC | 917 | floating.push((sp.windows[i], centre_in(out.usable(), r.w, r.h))); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 918 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 919 | } |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 920 | floating |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 921 | } |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 922 | |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 923 | fn fullscreen_in(&self, vis: &dyn Fn(WindowId) -> bool) -> Option<WindowId> { |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 924 | let is_fullscreen = |w: WindowId| self.windows[w].fullscreen && vis(w); |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 925 | self.history |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 926 | .iter() |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 927 | .rev() |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 928 | .copied() |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 929 | .find(|&w| is_fullscreen(w)) |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 930 | .or_else(|| self.windows.keys().find(|&w| is_fullscreen(w))) |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 931 | } |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 932 | |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 933 | fn above_fullscreen(&self, f: WindowId, floating: &[(WindowId, Rect)]) -> Vec<WindowId> { |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 934 | floating |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 935 | .iter() |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 936 | .map(|&(w, _)| w) |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 937 | .filter(|&w| w != f && (self.descends(w, f) || self.windows[w].scratchpad.is_some())) |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 938 | .collect() |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 939 | } |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 940 | |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 941 | /// The fullscreen window of the output under (x, y), with the floating |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 942 | /// transients that stay above it. Cheaper than arranging the output. |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 943 | pub fn fullscreen_at(&self, x: f64, y: f64) -> Option<(WindowId, Vec<WindowId>)> { |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 944 | let (o, out) = self |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 945 | .outputs |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 946 | .iter() |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 947 | .find(|(_, out)| out.area.contains(x, y))?; |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 948 | let vis = self.vis_on(o); |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 949 | let f = self.fullscreen_in(&vis)?; |
5c459f657de6 | atagen | 2026-10-19 10:37 UTC | 950 | Some((f, self.above_fullscreen(f, &self.floating_on(o, out, &vis)))) |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 951 | } |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 952 | |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 953 | /// Records that `w` is a transient of `parent`. |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 954 | pub fn set_parent(&mut self, w: WindowId, parent: Option<WindowId>) { |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 955 | if parent.is_some_and(|p| p == w || self.descends(p, w)) { |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 956 | return; |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 957 | } |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 958 | if let Some(win) = self.windows.get_mut(w) { |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 959 | win.parent = parent; |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 960 | } |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 961 | } |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 962 | |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 963 | fn descends(&self, mut w: WindowId, of: WindowId) -> bool { |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 964 | for _ in 0..self.windows.len() { |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 965 | match self.windows.get(w).and_then(|x| x.parent) { |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 966 | Some(p) if p == of => return true, |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 967 | Some(p) => w = p, |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 968 | None => return false, |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 969 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 970 | } |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 971 | false |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 972 | } |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 973 | |
f50ebc6999a6 | atagen | 2026-10-19 07:51 UTC | 974 | /// Moves focus to a fullscreen `w` when it covers the focused window, |
f50ebc6999a6 | atagen | 2026-10-19 07:51 UTC | 975 | /// unless that is one of its own transients. |
f50ebc6999a6 | atagen | 2026-10-19 07:51 UTC | 976 | pub fn focus_if_covering(&mut self, w: WindowId) { |
f50ebc6999a6 | atagen | 2026-10-19 07:51 UTC | 977 | let Some(win) = self.windows.get(w).filter(|win| win.fullscreen) else { |
f50ebc6999a6 | atagen | 2026-10-19 07:51 UTC | 978 | return; |
f50ebc6999a6 | atagen | 2026-10-19 07:51 UTC | 979 | }; |
f50ebc6999a6 | atagen | 2026-10-19 07:51 UTC | 980 | let covers = self.focused().is_some_and(|f| { |
f50ebc6999a6 | atagen | 2026-10-19 07:51 UTC | 981 | f != w && self.windows[f].output == win.output && !self.descends(f, w) |
f50ebc6999a6 | atagen | 2026-10-19 07:51 UTC | 982 | }); |
f50ebc6999a6 | atagen | 2026-10-19 07:51 UTC | 983 | if covers && self.visible(w) { |
f50ebc6999a6 | atagen | 2026-10-19 07:51 UTC | 984 | self.focus(w); |
f50ebc6999a6 | atagen | 2026-10-19 07:51 UTC | 985 | } |
f50ebc6999a6 | atagen | 2026-10-19 07:51 UTC | 986 | } |
f50ebc6999a6 | atagen | 2026-10-19 07:51 UTC | 987 | |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 988 | /// Focuses `w` unless it is out of sight or a fullscreen window hides it, |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 989 | /// flagging it urgent then. Returns whether it took the focus. |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 990 | pub fn focus_unless_covered(&mut self, w: WindowId) -> bool { |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 991 | if self.visible(w) && !self.covered(w) { |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 992 | self.focus(w); |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 993 | return true; |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 994 | } |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 995 | self.mark_urgent(w); |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 996 | false |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 997 | } |
1c7e3075e57f | atagen | 2026-10-19 10:28 UTC | 998 | |
692a9dda8779 | atagen | 2026-10-20 11:44 UTC | 999 | /// Whether a fullscreen or extended window on `w`'s output hides it. The |
692a9dda8779 | atagen | 2026-10-20 11:44 UTC | 1000 | /// fullscreen window's transients and shown scratchpads are not hidden, |
692a9dda8779 | atagen | 2026-10-20 11:44 UTC | 1001 | /// and a window that is itself fullscreen takes over. |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 1002 | pub fn covered(&self, w: WindowId) -> bool { |
692a9dda8779 | atagen | 2026-10-20 11:44 UTC | 1003 | if self.eclipsed(w) { |
692a9dda8779 | atagen | 2026-10-20 11:44 UTC | 1004 | return true; |
692a9dda8779 | atagen | 2026-10-20 11:44 UTC | 1005 | } |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 1006 | let Some(win) = self.windows.get(w) else { |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 1007 | return false; |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 1008 | }; |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 1009 | let Some(o) = win.output else { |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 1010 | return false; |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 1011 | }; |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 1012 | let arr = self.arrange(o); |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 1013 | !win.fullscreen && arr.fullscreen.is_some_and(|f| f != w) && !arr.over.contains(&w) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1014 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1015 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1016 | #[cfg(test)] |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1017 | pub(crate) fn check(&self) { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1018 | for (o, out) in &self.outputs { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1019 | out.tree.check(); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1020 | for w in out.tree.windows() { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1021 | let win = &self.windows[w]; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1022 | assert_eq!(win.output, Some(o)); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1023 | assert!(!win.floating && win.scratchpad.is_none()); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1024 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1025 | for &w in &out.floating { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1026 | assert_eq!(self.windows[w].output, Some(o)); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1027 | assert!(self.windows[w].floating); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1028 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1029 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1030 | for (w, win) in &self.windows { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1031 | let homes = self |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1032 | .outputs |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1033 | .values() |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1034 | .filter(|out| out.tree.contains(w) || out.floating.contains(&w)) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1035 | .count(); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1036 | let expected = usize::from(win.output.is_some() && win.scratchpad.is_none()); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1037 | assert_eq!(homes, expected, "window placed {homes} times"); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1038 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1039 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1040 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1041 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1042 | fn nearest<K: Copy>( |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1043 | from: Rect, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1044 | dir: Dir, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1045 | candidates: impl Iterator<Item = (K, Rect)>, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1046 | ) -> Option<K> { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1047 | const TOL: f64 = 0.5; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1048 | let score = |r: Rect| -> Option<(bool, f64, f64)> { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1049 | let (gap, overlap, offset) = match dir { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1050 | Dir::Right => ( |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1051 | r.x - from.right(), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1052 | span_overlap(from.y, from.h, r.y, r.h), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1053 | r.center_y() - from.center_y(), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1054 | ), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1055 | Dir::Left => ( |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1056 | from.x - r.right(), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1057 | span_overlap(from.y, from.h, r.y, r.h), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1058 | r.center_y() - from.center_y(), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1059 | ), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1060 | Dir::Down => ( |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1061 | r.y - from.bottom(), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1062 | span_overlap(from.x, from.w, r.x, r.w), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1063 | r.center_x() - from.center_x(), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1064 | ), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1065 | Dir::Up => ( |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1066 | from.y - r.bottom(), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1067 | span_overlap(from.x, from.w, r.x, r.w), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1068 | r.center_x() - from.center_x(), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1069 | ), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1070 | }; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1071 | (gap > -TOL).then_some((overlap <= 0.0, gap.max(0.0), offset.abs())) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1072 | }; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1073 | candidates |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1074 | .filter_map(|(k, r)| score(r).map(|s| (k, s))) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1075 | .min_by(|a, b| a.1.partial_cmp(&b.1).unwrap_or(std::cmp::Ordering::Equal)) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1076 | .map(|(k, _)| k) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1077 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1078 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1079 | fn span_overlap(a: f64, al: f64, b: f64, bl: f64) -> f64 { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1080 | (a + al).min(b + bl) - a.max(b) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1081 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1082 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1083 | fn inset(r: Rect, by: f64) -> Rect { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1084 | Rect::new( |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1085 | r.x + by, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1086 | r.y + by, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1087 | (r.w - 2.0 * by).max(0.0), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1088 | (r.h - 2.0 * by).max(0.0), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1089 | ) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1090 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1091 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1092 | fn centred(area: Rect, frac: f64) -> Rect { |
b001ce7817ed | atagen | 2026-10-19 09:23 UTC | 1093 | centre_in(area, area.w * frac, area.h * frac) |
b001ce7817ed | atagen | 2026-10-19 09:23 UTC | 1094 | } |
b001ce7817ed | atagen | 2026-10-19 09:23 UTC | 1095 | |
b001ce7817ed | atagen | 2026-10-19 09:23 UTC | 1096 | /// A w by h rect centred in area, shrunk to fit it. |
b001ce7817ed | atagen | 2026-10-19 09:23 UTC | 1097 | pub(crate) fn centre_in(area: Rect, w: f64, h: f64) -> Rect { |
b001ce7817ed | atagen | 2026-10-19 09:23 UTC | 1098 | let (w, h) = (w.min(area.w), h.min(area.h)); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1099 | Rect::new( |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1100 | area.x + (area.w - w) / 2.0, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1101 | area.y + (area.h - h) / 2.0, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1102 | w, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1103 | h, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1104 | ) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1105 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1106 | |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 1107 | /// The smallest a floating window gets when dragged or rescaled. |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 1108 | pub const MIN_FLOAT_SIZE: f64 = 32.0; |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 1109 | |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 1110 | /// How much of a floating window stays reachable when it is larger than |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 1111 | /// the area it lives in. |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 1112 | const STRIP: f64 = 64.0; |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 1113 | |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 1114 | /// Moves a floating rect to keep it reachable inside bounds. A window that |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 1115 | /// fits stays whole inside, a larger one keeps its top edge and a strip. |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 1116 | pub fn clamp_float(r: Rect, bounds: Rect) -> Rect { |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 1117 | let x = if r.w <= bounds.w { |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 1118 | r.x.clamp(bounds.x, bounds.right() - r.w) |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 1119 | } else { |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 1120 | let strip = STRIP.min(bounds.w); |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 1121 | r.x.clamp(bounds.x + strip - r.w, bounds.right() - strip) |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 1122 | }; |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 1123 | let y = if r.h <= bounds.h { |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 1124 | r.y.clamp(bounds.y, bounds.bottom() - r.h) |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 1125 | } else { |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 1126 | r.y.clamp(bounds.y, bounds.bottom() - STRIP.min(bounds.h)) |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 1127 | }; |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 1128 | Rect::new(x, y, r.w, r.h) |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 1129 | } |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 1130 | |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 1131 | /// Keeps a floating rect at the same relative spot and size when the area |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 1132 | /// it lives in changes. |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1133 | fn translate(r: Rect, from: Rect, to: Rect) -> Rect { |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 1134 | if to.w <= 0.0 || to.h <= 0.0 { |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 1135 | return r; |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 1136 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1137 | let sx = if from.w > 0.0 { to.w / from.w } else { 1.0 }; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1138 | let sy = if from.h > 0.0 { to.h / from.h } else { 1.0 }; |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 1139 | let scaled = Rect::new( |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1140 | to.x + (r.x - from.x) * sx, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1141 | to.y + (r.y - from.y) * sy, |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 1142 | (r.w * sx).max(MIN_FLOAT_SIZE), |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 1143 | (r.h * sy).max(MIN_FLOAT_SIZE), |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 1144 | ); |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 1145 | clamp_float(scaled, to) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1146 | } |