forge
Explore
Log in

Don't you dare go Hollow

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