Add gaps setting
Browse files at this commit994bc64679a36d52e3bc0bab8d2b6042a4e12cd0Parent: 624b3293 changed files +45 -17
- resources/default-config.kdl +3 -0
- src/config.rs +5 -0
- src/layout.rs +37 -17
resources/default-config.kdlmodified+3 -0
| @@ -106,6 +106,9 @@ preset-column-widths { | ||
| 106 | 106 | // fixed 1920 |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | +// Set gaps around windows in logical pixels. | |
| 110 | +gaps 16 | |
| 111 | + | |
| 109 | 112 | binds { |
| 110 | 113 | // Keys consist of modifiers separated by + signs, followed by an XKB key name |
| 111 | 114 | // in the end. To find an XKB name for a particular key, you may use a program |
src/config.rsmodified+5 -0
| @@ -24,6 +24,8 @@ pub struct Config { | ||
| 24 | 24 | pub cursor: Cursor, |
| 25 | 25 | #[knuffel(child, unwrap(children), default)] |
| 26 | 26 | pub preset_column_widths: Vec<PresetWidth>, |
| 27 | + #[knuffel(child, unwrap(argument), default = 16)] | |
| 28 | + pub gaps: u16, | |
| 27 | 29 | #[knuffel(child, default)] |
| 28 | 30 | pub binds: Binds, |
| 29 | 31 | #[knuffel(child, default)] |
| @@ -528,6 +530,8 @@ mod tests { | ||
| 528 | 530 | fixed 1280 |
| 529 | 531 | } |
| 530 | 532 | |
| 533 | + gaps 8 | |
| 534 | + | |
| 531 | 535 | binds { |
| 532 | 536 | Mod+T { spawn "alacritty"; } |
| 533 | 537 | Mod+Q { close-window; } |
| @@ -601,6 +605,7 @@ mod tests { | ||
| 601 | 605 | PresetWidth::Fixed(960), |
| 602 | 606 | PresetWidth::Fixed(1280), |
| 603 | 607 | ], |
| 608 | + gaps: 8, | |
| 604 | 609 | binds: Binds(vec![ |
| 605 | 610 | Bind { |
| 606 | 611 | key: Key { |
src/layout.rsmodified+37 -17
| @@ -56,8 +56,6 @@ use smithay::wayland::shell::xdg::SurfaceCachedState; | ||
| 56 | 56 | use crate::animation::Animation; |
| 57 | 57 | use crate::config::{self, Color, Config, PresetWidth, SizeChange}; |
| 58 | 58 | |
| 59 | -const PADDING: i32 = 16; | |
| 60 | - | |
| 61 | 59 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 62 | 60 | pub struct OutputId(String); |
| 63 | 61 | |
| @@ -152,7 +150,7 @@ pub struct Workspace<W: LayoutElement> { | ||
| 152 | 150 | |
| 153 | 151 | /// Offset of the view computed from the active column. |
| 154 | 152 | /// |
| 155 | - /// Any left padding, including left padding from work area left exclusive zone, is handled | |
| 153 | + /// Any gaps, including left padding from work area left exclusive zone, is handled | |
| 156 | 154 | /// with this view offset (rather than added as a constant elsewhere in the code). This allows |
| 157 | 155 | /// for natural handling of fullscreen windows, which must ignore work area padding. |
| 158 | 156 | view_offset: i32, |
| @@ -185,6 +183,8 @@ struct FocusRing { | ||
| 185 | 183 | |
| 186 | 184 | #[derive(Debug, PartialEq)] |
| 187 | 185 | struct Options { |
| 186 | + /// Padding around windows in logical pixels. | |
| 187 | + gaps: i32, | |
| 188 | 188 | focus_ring: config::FocusRing, |
| 189 | 189 | /// Column widths that `toggle_width()` switches between. |
| 190 | 190 | preset_widths: Vec<ColumnWidth>, |
| @@ -193,6 +193,7 @@ struct Options { | ||
| 193 | 193 | impl Default for Options { |
| 194 | 194 | fn default() -> Self { |
| 195 | 195 | Self { |
| 196 | + gaps: 16, | |
| 196 | 197 | focus_ring: Default::default(), |
| 197 | 198 | preset_widths: vec![ |
| 198 | 199 | ColumnWidth::Proportion(1. / 3.), |
| @@ -218,6 +219,7 @@ impl Options { | ||
| 218 | 219 | }; |
| 219 | 220 | |
| 220 | 221 | Self { |
| 222 | + gaps: config.gaps.into(), | |
| 221 | 223 | focus_ring: config.focus_ring, |
| 222 | 224 | preset_widths, |
| 223 | 225 | } |
| @@ -363,7 +365,7 @@ impl ColumnWidth { | ||
| 363 | 365 | fn resolve(self, options: &Options, view_width: i32) -> i32 { |
| 364 | 366 | match self { |
| 365 | 367 | ColumnWidth::Proportion(proportion) => { |
| 366 | - ((view_width - PADDING) as f64 * proportion).floor() as i32 - PADDING | |
| 368 | + ((view_width - options.gaps) as f64 * proportion).floor() as i32 - options.gaps | |
| 367 | 369 | } |
| 368 | 370 | ColumnWidth::Preset(idx) => options.preset_widths[idx].resolve(options, view_width), |
| 369 | 371 | ColumnWidth::Fixed(width) => width, |
| @@ -1603,12 +1605,12 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 1603 | 1605 | |
| 1604 | 1606 | pub fn configure_new_window(&self, window: &Window) { |
| 1605 | 1607 | let width = ColumnWidth::default().resolve(&self.options, self.working_area.size.w); |
| 1606 | - let height = self.working_area.size.h - PADDING * 2; | |
| 1608 | + let height = self.working_area.size.h - self.options.gaps * 2; | |
| 1607 | 1609 | let size = Size::from((max(width, 1), max(height, 1))); |
| 1608 | 1610 | |
| 1609 | 1611 | let bounds = Size::from(( |
| 1610 | - self.working_area.size.w - PADDING * 2, | |
| 1611 | - self.working_area.size.h - PADDING * 2, | |
| 1612 | + max(self.working_area.size.w - self.options.gaps * 2, 1), | |
| 1613 | + max(self.working_area.size.h - self.options.gaps * 2, 1), | |
| 1612 | 1614 | )); |
| 1613 | 1615 | |
| 1614 | 1616 | window.toplevel().with_pending_state(|state| { |
| @@ -1635,6 +1637,7 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 1635 | 1637 | self.working_area.size.w, |
| 1636 | 1638 | new_col_x, |
| 1637 | 1639 | self.columns[idx].width(), |
| 1640 | + self.options.gaps, | |
| 1638 | 1641 | ); |
| 1639 | 1642 | |
| 1640 | 1643 | // Non-fullscreen windows are always offset at least by the working area position. |
| @@ -1701,7 +1704,7 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 1701 | 1704 | let mut x = 0; |
| 1702 | 1705 | |
| 1703 | 1706 | for column in self.columns.iter().take(column_idx) { |
| 1704 | - x += column.width() + PADDING; | |
| 1707 | + x += column.width() + self.options.gaps; | |
| 1705 | 1708 | } |
| 1706 | 1709 | |
| 1707 | 1710 | x |
| @@ -1983,7 +1986,7 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 1983 | 1986 | } |
| 1984 | 1987 | } |
| 1985 | 1988 | |
| 1986 | - x += col.width() + PADDING; | |
| 1989 | + x += col.width() + self.options.gaps; | |
| 1987 | 1990 | } |
| 1988 | 1991 | |
| 1989 | 1992 | None |
| @@ -2140,7 +2143,7 @@ impl Workspace<Window> { | ||
| 2140 | 2143 | )); |
| 2141 | 2144 | } |
| 2142 | 2145 | |
| 2143 | - x += col.width() + PADDING; | |
| 2146 | + x += col.width() + self.options.gaps; | |
| 2144 | 2147 | } |
| 2145 | 2148 | |
| 2146 | 2149 | rv |
| @@ -2181,6 +2184,8 @@ impl<W: LayoutElement> Column<W> { | ||
| 2181 | 2184 | } |
| 2182 | 2185 | |
| 2183 | 2186 | fn update_config(&mut self, options: Rc<Options>) { |
| 2187 | + let mut update_sizes = false; | |
| 2188 | + | |
| 2184 | 2189 | // If preset widths changed, make our width non-preset. |
| 2185 | 2190 | if self.options.preset_widths != options.preset_widths { |
| 2186 | 2191 | if let ColumnWidth::Preset(idx) = self.width { |
| @@ -2188,7 +2193,15 @@ impl<W: LayoutElement> Column<W> { | ||
| 2188 | 2193 | } |
| 2189 | 2194 | } |
| 2190 | 2195 | |
| 2196 | + if self.options.gaps != options.gaps { | |
| 2197 | + update_sizes = true; | |
| 2198 | + } | |
| 2199 | + | |
| 2191 | 2200 | self.options = options; |
| 2201 | + | |
| 2202 | + if update_sizes { | |
| 2203 | + self.update_window_sizes(); | |
| 2204 | + } | |
| 2192 | 2205 | } |
| 2193 | 2206 | |
| 2194 | 2207 | fn window_count(&self) -> usize { |
| @@ -2250,7 +2263,8 @@ impl<W: LayoutElement> Column<W> { | ||
| 2250 | 2263 | let max_width = max(max_width, min_width); |
| 2251 | 2264 | |
| 2252 | 2265 | let width = self.width.resolve(&self.options, self.working_area.size.w); |
| 2253 | - let height = (self.working_area.size.h - PADDING) / self.window_count() as i32 - PADDING; | |
| 2266 | + let height = (self.working_area.size.h - self.options.gaps) / self.window_count() as i32 | |
| 2267 | + - self.options.gaps; | |
| 2254 | 2268 | let size = Size::from((max(min(width, max_width), min_width), max(height, 1))); |
| 2255 | 2269 | |
| 2256 | 2270 | for win in &self.windows { |
| @@ -2359,8 +2373,8 @@ impl<W: LayoutElement> Column<W> { | ||
| 2359 | 2373 | ColumnWidth::Proportion(proportion) |
| 2360 | 2374 | } |
| 2361 | 2375 | (ColumnWidth::Fixed(_), SizeChange::AdjustProportion(delta)) => { |
| 2362 | - let current = | |
| 2363 | - (current_px + PADDING) as f64 / (self.working_area.size.w - PADDING) as f64; | |
| 2376 | + let current = (current_px + self.options.gaps) as f64 | |
| 2377 | + / (self.working_area.size.w - self.options.gaps) as f64; | |
| 2364 | 2378 | let proportion = (current + delta / 100.).clamp(0., MAX_F); |
| 2365 | 2379 | ColumnWidth::Proportion(proportion) |
| 2366 | 2380 | } |
| @@ -2384,12 +2398,12 @@ impl<W: LayoutElement> Column<W> { | ||
| 2384 | 2398 | let mut y = 0; |
| 2385 | 2399 | |
| 2386 | 2400 | if !self.is_fullscreen { |
| 2387 | - y = self.working_area.loc.y + PADDING; | |
| 2401 | + y = self.working_area.loc.y + self.options.gaps; | |
| 2388 | 2402 | } |
| 2389 | 2403 | |
| 2390 | 2404 | self.windows.iter().map(move |win| { |
| 2391 | 2405 | let pos = y; |
| 2392 | - y += win.geometry().size.h + PADDING; | |
| 2406 | + y += win.geometry().size.h + self.options.gaps; | |
| 2393 | 2407 | pos |
| 2394 | 2408 | }) |
| 2395 | 2409 | } |
| @@ -2405,14 +2419,20 @@ pub fn output_size(output: &Output) -> Size<i32, Logical> { | ||
| 2405 | 2419 | .to_logical(output_scale) |
| 2406 | 2420 | } |
| 2407 | 2421 | |
| 2408 | -fn compute_new_view_offset(cur_x: i32, view_width: i32, new_col_x: i32, new_col_width: i32) -> i32 { | |
| 2422 | +fn compute_new_view_offset( | |
| 2423 | + cur_x: i32, | |
| 2424 | + view_width: i32, | |
| 2425 | + new_col_x: i32, | |
| 2426 | + new_col_width: i32, | |
| 2427 | + gaps: i32, | |
| 2428 | +) -> i32 { | |
| 2409 | 2429 | // If the column is wider than the view, always left-align it. |
| 2410 | 2430 | if view_width <= new_col_width { |
| 2411 | 2431 | return 0; |
| 2412 | 2432 | } |
| 2413 | 2433 | |
| 2414 | 2434 | // Compute the padding in case it needs to be smaller due to large window width. |
| 2415 | - let padding = ((view_width - new_col_width) / 2).clamp(0, PADDING); | |
| 2435 | + let padding = ((view_width - new_col_width) / 2).clamp(0, gaps); | |
| 2416 | 2436 | |
| 2417 | 2437 | // Compute the desired new X with padding. |
| 2418 | 2438 | let new_x = new_col_x - padding; |