layout: Store view size in Columns
Browse files at this commit3ac16074063db2cccdb10d9e5b832aaec0492bb4Parent: 1bcc8891 changed file +48 -65
- src/layout.rs +48 -65
src/layout.rsmodified+48 -65
| @@ -195,6 +195,12 @@ struct Column<W: LayoutElement> { | |||
| 195 | 195 | ||
| 196 | /// Whether this column contains a single full-screened window. | 196 | /// Whether this column contains a single full-screened window. |
| 197 | is_fullscreen: bool, | 197 | is_fullscreen: bool, |
| 198 | + | ||
| 199 | + /// Latest known view size for this column's workspace. | ||
| 200 | + view_size: Size<i32, Logical>, | ||
| 201 | + | ||
| 202 | + /// Latest known working area for this column's workspace. | ||
| 203 | + working_area: Rectangle<i32, Logical>, | ||
| 198 | } | 204 | } |
| 199 | 205 | ||
| 200 | impl OutputId { | 206 | impl OutputId { |
| @@ -1472,7 +1478,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1472 | self.working_area = working_area; | 1478 | self.working_area = working_area; |
| 1473 | 1479 | ||
| 1474 | for col in &mut self.columns { | 1480 | for col in &mut self.columns { |
| 1475 | - col.update_window_sizes(self.view_size, self.working_area); | 1481 | + col.set_view_size(self.view_size, self.working_area); |
| 1476 | } | 1482 | } |
| 1477 | } | 1483 | } |
| 1478 | 1484 | ||
| @@ -1596,7 +1602,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1596 | } | 1602 | } |
| 1597 | 1603 | ||
| 1598 | column.active_window_idx = min(column.active_window_idx, column.windows.len() - 1); | 1604 | column.active_window_idx = min(column.active_window_idx, column.windows.len() - 1); |
| 1599 | - column.update_window_sizes(self.view_size, self.working_area); | 1605 | + column.update_window_sizes(); |
| 1600 | } | 1606 | } |
| 1601 | 1607 | ||
| 1602 | fn update_window(&mut self, window: &W) { | 1608 | fn update_window(&mut self, window: &W) { |
| @@ -1606,7 +1612,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1606 | .enumerate() | 1612 | .enumerate() |
| 1607 | .find(|(_, col)| col.contains(window)) | 1613 | .find(|(_, col)| col.contains(window)) |
| 1608 | .unwrap(); | 1614 | .unwrap(); |
| 1609 | - column.update_window_sizes(self.view_size, self.working_area); | 1615 | + column.update_window_sizes(); |
| 1610 | 1616 | ||
| 1611 | if idx == self.active_column_idx { | 1617 | if idx == self.active_column_idx { |
| 1612 | // We might need to move the view to ensure the resized window is still visible. | 1618 | // We might need to move the view to ensure the resized window is still visible. |
| @@ -1778,7 +1784,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1778 | self.remove_window(&window); | 1784 | self.remove_window(&window); |
| 1779 | 1785 | ||
| 1780 | let target_column = &mut self.columns[self.active_column_idx]; | 1786 | let target_column = &mut self.columns[self.active_column_idx]; |
| 1781 | - target_column.add_window(self.view_size, self.working_area, window); | 1787 | + target_column.add_window(window); |
| 1782 | } | 1788 | } |
| 1783 | 1789 | ||
| 1784 | fn expel_from_column(&mut self) { | 1790 | fn expel_from_column(&mut self) { |
| @@ -1872,7 +1878,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1872 | return; | 1878 | return; |
| 1873 | } | 1879 | } |
| 1874 | 1880 | ||
| 1875 | - self.columns[self.active_column_idx].toggle_width(self.view_size, self.working_area); | 1881 | + self.columns[self.active_column_idx].toggle_width(); |
| 1876 | } | 1882 | } |
| 1877 | 1883 | ||
| 1878 | fn toggle_full_width(&mut self) { | 1884 | fn toggle_full_width(&mut self) { |
| @@ -1880,7 +1886,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1880 | return; | 1886 | return; |
| 1881 | } | 1887 | } |
| 1882 | 1888 | ||
| 1883 | - self.columns[self.active_column_idx].toggle_full_width(self.view_size, self.working_area); | 1889 | + self.columns[self.active_column_idx].toggle_full_width(); |
| 1884 | } | 1890 | } |
| 1885 | 1891 | ||
| 1886 | fn set_column_width(&mut self, change: SizeChange) { | 1892 | fn set_column_width(&mut self, change: SizeChange) { |
| @@ -1888,11 +1894,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1888 | return; | 1894 | return; |
| 1889 | } | 1895 | } |
| 1890 | 1896 | ||
| 1891 | - self.columns[self.active_column_idx].set_column_width( | 1897 | + self.columns[self.active_column_idx].set_column_width(change); |
| 1892 | - self.view_size, | ||
| 1893 | - self.working_area, | ||
| 1894 | - change, | ||
| 1895 | - ); | ||
| 1896 | } | 1898 | } |
| 1897 | 1899 | ||
| 1898 | pub fn set_fullscreen(&mut self, window: &W, is_fullscreen: bool) { | 1900 | pub fn set_fullscreen(&mut self, window: &W, is_fullscreen: bool) { |
| @@ -1916,7 +1918,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1916 | self.active_column_idx == col_idx && col.active_window_idx == win_idx; | 1918 | self.active_column_idx == col_idx && col.active_window_idx == win_idx; |
| 1917 | let window = col.windows.remove(win_idx); | 1919 | let window = col.windows.remove(win_idx); |
| 1918 | col.active_window_idx = min(col.active_window_idx, col.windows.len() - 1); | 1920 | col.active_window_idx = min(col.active_window_idx, col.windows.len() - 1); |
| 1919 | - col.update_window_sizes(self.view_size, self.working_area); | 1921 | + col.update_window_sizes(); |
| 1920 | 1922 | ||
| 1921 | col_idx += 1; | 1923 | col_idx += 1; |
| 1922 | self.columns.insert( | 1924 | self.columns.insert( |
| @@ -1929,7 +1931,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1929 | col = &mut self.columns[col_idx]; | 1931 | col = &mut self.columns[col_idx]; |
| 1930 | } | 1932 | } |
| 1931 | 1933 | ||
| 1932 | - col.set_fullscreen(self.view_size, self.working_area, is_fullscreen); | 1934 | + col.set_fullscreen(is_fullscreen); |
| 1933 | } | 1935 | } |
| 1934 | 1936 | ||
| 1935 | pub fn toggle_fullscreen(&mut self, window: &W) { | 1937 | pub fn toggle_fullscreen(&mut self, window: &W) { |
| @@ -2050,25 +2052,33 @@ impl<W: LayoutElement> Column<W> { | |||
| 2050 | active_window_idx: 0, | 2052 | active_window_idx: 0, |
| 2051 | width: ColumnWidth::default(), | 2053 | width: ColumnWidth::default(), |
| 2052 | is_fullscreen: false, | 2054 | is_fullscreen: false, |
| 2055 | + view_size, | ||
| 2056 | + working_area, | ||
| 2053 | }; | 2057 | }; |
| 2054 | 2058 | ||
| 2055 | - rv.add_window(view_size, working_area, window); | 2059 | + rv.add_window(window); |
| 2056 | 2060 | ||
| 2057 | rv | 2061 | rv |
| 2058 | } | 2062 | } |
| 2059 | 2063 | ||
| 2064 | + fn set_view_size(&mut self, size: Size<i32, Logical>, working_area: Rectangle<i32, Logical>) { | ||
| 2065 | + if self.view_size == size && self.working_area == working_area { | ||
| 2066 | + return; | ||
| 2067 | + } | ||
| 2068 | + | ||
| 2069 | + self.view_size = size; | ||
| 2070 | + self.working_area = working_area; | ||
| 2071 | + | ||
| 2072 | + self.update_window_sizes(); | ||
| 2073 | + } | ||
| 2074 | + | ||
| 2060 | fn window_count(&self) -> usize { | 2075 | fn window_count(&self) -> usize { |
| 2061 | self.windows.len() | 2076 | self.windows.len() |
| 2062 | } | 2077 | } |
| 2063 | 2078 | ||
| 2064 | - fn set_width( | 2079 | + fn set_width(&mut self, width: ColumnWidth) { |
| 2065 | - &mut self, | ||
| 2066 | - view_size: Size<i32, Logical>, | ||
| 2067 | - working_area: Rectangle<i32, Logical>, | ||
| 2068 | - width: ColumnWidth, | ||
| 2069 | - ) { | ||
| 2070 | self.width = width; | 2080 | self.width = width; |
| 2071 | - self.update_window_sizes(view_size, working_area); | 2081 | + self.update_window_sizes(); |
| 2072 | } | 2082 | } |
| 2073 | 2083 | ||
| 2074 | fn contains(&self, window: &W) -> bool { | 2084 | fn contains(&self, window: &W) -> bool { |
| @@ -2080,24 +2090,15 @@ impl<W: LayoutElement> Column<W> { | |||
| 2080 | self.active_window_idx = idx; | 2090 | self.active_window_idx = idx; |
| 2081 | } | 2091 | } |
| 2082 | 2092 | ||
| 2083 | - fn add_window( | 2093 | + fn add_window(&mut self, window: W) { |
| 2084 | - &mut self, | ||
| 2085 | - view_size: Size<i32, Logical>, | ||
| 2086 | - working_area: Rectangle<i32, Logical>, | ||
| 2087 | - window: W, | ||
| 2088 | - ) { | ||
| 2089 | self.is_fullscreen = false; | 2094 | self.is_fullscreen = false; |
| 2090 | self.windows.push(window); | 2095 | self.windows.push(window); |
| 2091 | - self.update_window_sizes(view_size, working_area); | 2096 | + self.update_window_sizes(); |
| 2092 | } | 2097 | } |
| 2093 | 2098 | ||
| 2094 | - fn update_window_sizes( | 2099 | + fn update_window_sizes(&mut self) { |
| 2095 | - &mut self, | ||
| 2096 | - view_size: Size<i32, Logical>, | ||
| 2097 | - working_area: Rectangle<i32, Logical>, | ||
| 2098 | - ) { | ||
| 2099 | if self.is_fullscreen { | 2100 | if self.is_fullscreen { |
| 2100 | - self.windows[0].request_fullscreen(view_size); | 2101 | + self.windows[0].request_fullscreen(self.view_size); |
| 2101 | return; | 2102 | return; |
| 2102 | } | 2103 | } |
| 2103 | 2104 | ||
| @@ -2129,8 +2130,8 @@ impl<W: LayoutElement> Column<W> { | |||
| 2129 | .unwrap_or(i32::MAX); | 2130 | .unwrap_or(i32::MAX); |
| 2130 | let max_width = max(max_width, min_width); | 2131 | let max_width = max(max_width, min_width); |
| 2131 | 2132 | ||
| 2132 | - let width = self.width.resolve(working_area.size.w - PADDING) - PADDING; | 2133 | + let width = self.width.resolve(self.working_area.size.w - PADDING) - PADDING; |
| 2133 | - let height = (working_area.size.h - PADDING) / self.window_count() as i32 - PADDING; | 2134 | + let height = (self.working_area.size.h - PADDING) / self.window_count() as i32 - PADDING; |
| 2134 | let size = Size::from((max(min(width, max_width), min_width), max(height, 1))); | 2135 | let size = Size::from((max(min(width, max_width), min_width), max(height, 1))); |
| 2135 | 2136 | ||
| 2136 | for win in &self.windows { | 2137 | for win in &self.windows { |
| @@ -2189,11 +2190,7 @@ impl<W: LayoutElement> Column<W> { | |||
| 2189 | } | 2190 | } |
| 2190 | } | 2191 | } |
| 2191 | 2192 | ||
| 2192 | - fn toggle_width( | 2193 | + fn toggle_width(&mut self) { |
| 2193 | - &mut self, | ||
| 2194 | - view_size: Size<i32, Logical>, | ||
| 2195 | - working_area: Rectangle<i32, Logical>, | ||
| 2196 | - ) { | ||
| 2197 | let idx = match self.width { | 2194 | let idx = match self.width { |
| 2198 | ColumnWidth::PresetProportion(idx) => (idx + 1) % WIDTH_PROPORTIONS.len(), | 2195 | ColumnWidth::PresetProportion(idx) => (idx + 1) % WIDTH_PROPORTIONS.len(), |
| 2199 | _ => { | 2196 | _ => { |
| @@ -2201,20 +2198,16 @@ impl<W: LayoutElement> Column<W> { | |||
| 2201 | WIDTH_PROPORTIONS | 2198 | WIDTH_PROPORTIONS |
| 2202 | .into_iter() | 2199 | .into_iter() |
| 2203 | .position(|prop| { | 2200 | .position(|prop| { |
| 2204 | - prop.resolve(working_area.size.w - PADDING) - PADDING > current | 2201 | + prop.resolve(self.working_area.size.w - PADDING) - PADDING > current |
| 2205 | }) | 2202 | }) |
| 2206 | .unwrap_or(0) | 2203 | .unwrap_or(0) |
| 2207 | } | 2204 | } |
| 2208 | }; | 2205 | }; |
| 2209 | let width = ColumnWidth::PresetProportion(idx); | 2206 | let width = ColumnWidth::PresetProportion(idx); |
| 2210 | - self.set_width(view_size, working_area, width); | 2207 | + self.set_width(width); |
| 2211 | } | 2208 | } |
| 2212 | 2209 | ||
| 2213 | - fn toggle_full_width( | 2210 | + fn toggle_full_width(&mut self) { |
| 2214 | - &mut self, | ||
| 2215 | - view_size: Size<i32, Logical>, | ||
| 2216 | - working_area: Rectangle<i32, Logical>, | ||
| 2217 | - ) { | ||
| 2218 | let width = match self.width { | 2211 | let width = match self.width { |
| 2219 | ColumnWidth::Proportion(x) if x == 1. => { | 2212 | ColumnWidth::Proportion(x) if x == 1. => { |
| 2220 | // FIXME: would be good to restore to previous width here. | 2213 | // FIXME: would be good to restore to previous width here. |
| @@ -2222,16 +2215,11 @@ impl<W: LayoutElement> Column<W> { | |||
| 2222 | } | 2215 | } |
| 2223 | _ => ColumnWidth::Proportion(1.), | 2216 | _ => ColumnWidth::Proportion(1.), |
| 2224 | }; | 2217 | }; |
| 2225 | - self.set_width(view_size, working_area, width); | 2218 | + self.set_width(width); |
| 2226 | } | 2219 | } |
| 2227 | 2220 | ||
| 2228 | - fn set_column_width( | 2221 | + fn set_column_width(&mut self, change: SizeChange) { |
| 2229 | - &mut self, | 2222 | + let current_px = self.width.resolve(self.working_area.size.w - PADDING) - PADDING; |
| 2230 | - view_size: Size<i32, Logical>, | ||
| 2231 | - working_area: Rectangle<i32, Logical>, | ||
| 2232 | - change: SizeChange, | ||
| 2233 | - ) { | ||
| 2234 | - let current_px = self.width.resolve(working_area.size.w - PADDING) - PADDING; | ||
| 2235 | 2223 | ||
| 2236 | let current = match self.width { | 2224 | let current = match self.width { |
| 2237 | ColumnWidth::PresetProportion(idx) => WIDTH_PROPORTIONS[idx], | 2225 | ColumnWidth::PresetProportion(idx) => WIDTH_PROPORTIONS[idx], |
| @@ -2257,25 +2245,20 @@ impl<W: LayoutElement> Column<W> { | |||
| 2257 | } | 2245 | } |
| 2258 | (ColumnWidth::Fixed(_), SizeChange::AdjustProportion(delta)) => { | 2246 | (ColumnWidth::Fixed(_), SizeChange::AdjustProportion(delta)) => { |
| 2259 | let current = | 2247 | let current = |
| 2260 | - (current_px + PADDING) as f64 / (working_area.size.w - PADDING) as f64; | 2248 | + (current_px + PADDING) as f64 / (self.working_area.size.w - PADDING) as f64; |
| 2261 | let proportion = (current + delta / 100.).clamp(0., MAX_F); | 2249 | let proportion = (current + delta / 100.).clamp(0., MAX_F); |
| 2262 | ColumnWidth::Proportion(proportion) | 2250 | ColumnWidth::Proportion(proportion) |
| 2263 | } | 2251 | } |
| 2264 | (ColumnWidth::PresetProportion(_), _) => unreachable!(), | 2252 | (ColumnWidth::PresetProportion(_), _) => unreachable!(), |
| 2265 | }; | 2253 | }; |
| 2266 | 2254 | ||
| 2267 | - self.set_width(view_size, working_area, width); | 2255 | + self.set_width(width); |
| 2268 | } | 2256 | } |
| 2269 | 2257 | ||
| 2270 | - fn set_fullscreen( | 2258 | + fn set_fullscreen(&mut self, is_fullscreen: bool) { |
| 2271 | - &mut self, | ||
| 2272 | - view_size: Size<i32, Logical>, | ||
| 2273 | - working_area: Rectangle<i32, Logical>, | ||
| 2274 | - is_fullscreen: bool, | ||
| 2275 | - ) { | ||
| 2276 | assert_eq!(self.windows.len(), 1); | 2259 | assert_eq!(self.windows.len(), 1); |
| 2277 | self.is_fullscreen = is_fullscreen; | 2260 | self.is_fullscreen = is_fullscreen; |
| 2278 | - self.update_window_sizes(view_size, working_area); | 2261 | + self.update_window_sizes(); |
| 2279 | } | 2262 | } |
| 2280 | 2263 | ||
| 2281 | fn window_y(&self, window_idx: usize) -> i32 { | 2264 | fn window_y(&self, window_idx: usize) -> i32 { |