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 {
106106 // fixed 1920
107107 }
108108
109+// Set gaps around windows in logical pixels.
110+gaps 16
111+
109112 binds {
110113 // Keys consist of modifiers separated by + signs, followed by an XKB key name
111114 // 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 {
2424 pub cursor: Cursor,
2525 #[knuffel(child, unwrap(children), default)]
2626 pub preset_column_widths: Vec<PresetWidth>,
27+ #[knuffel(child, unwrap(argument), default = 16)]
28+ pub gaps: u16,
2729 #[knuffel(child, default)]
2830 pub binds: Binds,
2931 #[knuffel(child, default)]
@@ -528,6 +530,8 @@ mod tests {
528530 fixed 1280
529531 }
530532
533+ gaps 8
534+
531535 binds {
532536 Mod+T { spawn "alacritty"; }
533537 Mod+Q { close-window; }
@@ -601,6 +605,7 @@ mod tests {
601605 PresetWidth::Fixed(960),
602606 PresetWidth::Fixed(1280),
603607 ],
608+ gaps: 8,
604609 binds: Binds(vec![
605610 Bind {
606611 key: Key {
src/layout.rsmodified+37 -17
@@ -56,8 +56,6 @@ use smithay::wayland::shell::xdg::SurfaceCachedState;
5656 use crate::animation::Animation;
5757 use crate::config::{self, Color, Config, PresetWidth, SizeChange};
5858
59-const PADDING: i32 = 16;
60-
6159 #[derive(Debug, Clone, PartialEq, Eq)]
6260 pub struct OutputId(String);
6361
@@ -152,7 +150,7 @@ pub struct Workspace<W: LayoutElement> {
152150
153151 /// Offset of the view computed from the active column.
154152 ///
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
156154 /// with this view offset (rather than added as a constant elsewhere in the code). This allows
157155 /// for natural handling of fullscreen windows, which must ignore work area padding.
158156 view_offset: i32,
@@ -185,6 +183,8 @@ struct FocusRing {
185183
186184 #[derive(Debug, PartialEq)]
187185 struct Options {
186+ /// Padding around windows in logical pixels.
187+ gaps: i32,
188188 focus_ring: config::FocusRing,
189189 /// Column widths that `toggle_width()` switches between.
190190 preset_widths: Vec<ColumnWidth>,
@@ -193,6 +193,7 @@ struct Options {
193193 impl Default for Options {
194194 fn default() -> Self {
195195 Self {
196+ gaps: 16,
196197 focus_ring: Default::default(),
197198 preset_widths: vec![
198199 ColumnWidth::Proportion(1. / 3.),
@@ -218,6 +219,7 @@ impl Options {
218219 };
219220
220221 Self {
222+ gaps: config.gaps.into(),
221223 focus_ring: config.focus_ring,
222224 preset_widths,
223225 }
@@ -363,7 +365,7 @@ impl ColumnWidth {
363365 fn resolve(self, options: &Options, view_width: i32) -> i32 {
364366 match self {
365367 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
367369 }
368370 ColumnWidth::Preset(idx) => options.preset_widths[idx].resolve(options, view_width),
369371 ColumnWidth::Fixed(width) => width,
@@ -1603,12 +1605,12 @@ impl<W: LayoutElement> Workspace<W> {
16031605
16041606 pub fn configure_new_window(&self, window: &Window) {
16051607 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;
16071609 let size = Size::from((max(width, 1), max(height, 1)));
16081610
16091611 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),
16121614 ));
16131615
16141616 window.toplevel().with_pending_state(|state| {
@@ -1635,6 +1637,7 @@ impl<W: LayoutElement> Workspace<W> {
16351637 self.working_area.size.w,
16361638 new_col_x,
16371639 self.columns[idx].width(),
1640+ self.options.gaps,
16381641 );
16391642
16401643 // Non-fullscreen windows are always offset at least by the working area position.
@@ -1701,7 +1704,7 @@ impl<W: LayoutElement> Workspace<W> {
17011704 let mut x = 0;
17021705
17031706 for column in self.columns.iter().take(column_idx) {
1704- x += column.width() + PADDING;
1707+ x += column.width() + self.options.gaps;
17051708 }
17061709
17071710 x
@@ -1983,7 +1986,7 @@ impl<W: LayoutElement> Workspace<W> {
19831986 }
19841987 }
19851988
1986- x += col.width() + PADDING;
1989+ x += col.width() + self.options.gaps;
19871990 }
19881991
19891992 None
@@ -2140,7 +2143,7 @@ impl Workspace<Window> {
21402143 ));
21412144 }
21422145
2143- x += col.width() + PADDING;
2146+ x += col.width() + self.options.gaps;
21442147 }
21452148
21462149 rv
@@ -2181,6 +2184,8 @@ impl<W: LayoutElement> Column<W> {
21812184 }
21822185
21832186 fn update_config(&mut self, options: Rc<Options>) {
2187+ let mut update_sizes = false;
2188+
21842189 // If preset widths changed, make our width non-preset.
21852190 if self.options.preset_widths != options.preset_widths {
21862191 if let ColumnWidth::Preset(idx) = self.width {
@@ -2188,7 +2193,15 @@ impl<W: LayoutElement> Column<W> {
21882193 }
21892194 }
21902195
2196+ if self.options.gaps != options.gaps {
2197+ update_sizes = true;
2198+ }
2199+
21912200 self.options = options;
2201+
2202+ if update_sizes {
2203+ self.update_window_sizes();
2204+ }
21922205 }
21932206
21942207 fn window_count(&self) -> usize {
@@ -2250,7 +2263,8 @@ impl<W: LayoutElement> Column<W> {
22502263 let max_width = max(max_width, min_width);
22512264
22522265 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;
22542268 let size = Size::from((max(min(width, max_width), min_width), max(height, 1)));
22552269
22562270 for win in &self.windows {
@@ -2359,8 +2373,8 @@ impl<W: LayoutElement> Column<W> {
23592373 ColumnWidth::Proportion(proportion)
23602374 }
23612375 (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;
23642378 let proportion = (current + delta / 100.).clamp(0., MAX_F);
23652379 ColumnWidth::Proportion(proportion)
23662380 }
@@ -2384,12 +2398,12 @@ impl<W: LayoutElement> Column<W> {
23842398 let mut y = 0;
23852399
23862400 if !self.is_fullscreen {
2387- y = self.working_area.loc.y + PADDING;
2401+ y = self.working_area.loc.y + self.options.gaps;
23882402 }
23892403
23902404 self.windows.iter().map(move |win| {
23912405 let pos = y;
2392- y += win.geometry().size.h + PADDING;
2406+ y += win.geometry().size.h + self.options.gaps;
23932407 pos
23942408 })
23952409 }
@@ -2405,14 +2419,20 @@ pub fn output_size(output: &Output) -> Size<i32, Logical> {
24052419 .to_logical(output_scale)
24062420 }
24072421
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 {
24092429 // If the column is wider than the view, always left-align it.
24102430 if view_width <= new_col_width {
24112431 return 0;
24122432 }
24132433
24142434 // 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);
24162436
24172437 // Compute the desired new X with padding.
24182438 let new_x = new_col_x - padding;