aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2023-10-07 17:45:55 +0400
committerIvan Molodetskikh <yalterz@gmail.com>2023-10-07 17:45:55 +0400
commit994bc64679a36d52e3bc0bab8d2b6042a4e12cd0 (patch)
tree94d938ada04e9c9fb279bb377e0113545ccf4433 /src
parent624b3296e927b7b71b2b2f92006cc242a9c06205 (diff)
downloadniri-994bc64679a36d52e3bc0bab8d2b6042a4e12cd0.tar.gz
niri-994bc64679a36d52e3bc0bab8d2b6042a4e12cd0.tar.bz2
niri-994bc64679a36d52e3bc0bab8d2b6042a4e12cd0.zip
Add gaps setting
The past few refactors have led up to this point, and now it's finally possible.
Diffstat (limited to 'src')
-rw-r--r--src/config.rs5
-rw-r--r--src/layout.rs54
2 files changed, 42 insertions, 17 deletions
diff --git a/src/config.rs b/src/config.rs
index bb8cfcf6..6f695c34 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -24,6 +24,8 @@ pub struct Config {
pub cursor: Cursor,
#[knuffel(child, unwrap(children), default)]
pub preset_column_widths: Vec<PresetWidth>,
+ #[knuffel(child, unwrap(argument), default = 16)]
+ pub gaps: u16,
#[knuffel(child, default)]
pub binds: Binds,
#[knuffel(child, default)]
@@ -528,6 +530,8 @@ mod tests {
fixed 1280
}
+ gaps 8
+
binds {
Mod+T { spawn "alacritty"; }
Mod+Q { close-window; }
@@ -601,6 +605,7 @@ mod tests {
PresetWidth::Fixed(960),
PresetWidth::Fixed(1280),
],
+ gaps: 8,
binds: Binds(vec![
Bind {
key: Key {
diff --git a/src/layout.rs b/src/layout.rs
index 19aebc1b..144bdf02 100644
--- a/src/layout.rs
+++ b/src/layout.rs
@@ -56,8 +56,6 @@ use smithay::wayland::shell::xdg::SurfaceCachedState;
use crate::animation::Animation;
use crate::config::{self, Color, Config, PresetWidth, SizeChange};
-const PADDING: i32 = 16;
-
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct OutputId(String);
@@ -152,7 +150,7 @@ pub struct Workspace<W: LayoutElement> {
/// Offset of the view computed from the active column.
///
- /// Any left padding, including left padding from work area left exclusive zone, is handled
+ /// Any gaps, including left padding from work area left exclusive zone, is handled
/// with this view offset (rather than added as a constant elsewhere in the code). This allows
/// for natural handling of fullscreen windows, which must ignore work area padding.
view_offset: i32,
@@ -185,6 +183,8 @@ struct FocusRing {
#[derive(Debug, PartialEq)]
struct Options {
+ /// Padding around windows in logical pixels.
+ gaps: i32,
focus_ring: config::FocusRing,
/// Column widths that `toggle_width()` switches between.
preset_widths: Vec<ColumnWidth>,
@@ -193,6 +193,7 @@ struct Options {
impl Default for Options {
fn default() -> Self {
Self {
+ gaps: 16,
focus_ring: Default::default(),
preset_widths: vec![
ColumnWidth::Proportion(1. / 3.),
@@ -218,6 +219,7 @@ impl Options {
};
Self {
+ gaps: config.gaps.into(),
focus_ring: config.focus_ring,
preset_widths,
}
@@ -363,7 +365,7 @@ impl ColumnWidth {
fn resolve(self, options: &Options, view_width: i32) -> i32 {
match self {
ColumnWidth::Proportion(proportion) => {
- ((view_width - PADDING) as f64 * proportion).floor() as i32 - PADDING
+ ((view_width - options.gaps) as f64 * proportion).floor() as i32 - options.gaps
}
ColumnWidth::Preset(idx) => options.preset_widths[idx].resolve(options, view_width),
ColumnWidth::Fixed(width) => width,
@@ -1603,12 +1605,12 @@ impl<W: LayoutElement> Workspace<W> {
pub fn configure_new_window(&self, window: &Window) {
let width = ColumnWidth::default().resolve(&self.options, self.working_area.size.w);
- let height = self.working_area.size.h - PADDING * 2;
+ let height = self.working_area.size.h - self.options.gaps * 2;
let size = Size::from((max(width, 1), max(height, 1)));
let bounds = Size::from((
- self.working_area.size.w - PADDING * 2,
- self.working_area.size.h - PADDING * 2,
+ max(self.working_area.size.w - self.options.gaps * 2, 1),
+ max(self.working_area.size.h - self.options.gaps * 2, 1),
));
window.toplevel().with_pending_state(|state| {
@@ -1635,6 +1637,7 @@ impl<W: LayoutElement> Workspace<W> {
self.working_area.size.w,
new_col_x,
self.columns[idx].width(),
+ self.options.gaps,
);
// Non-fullscreen windows are always offset at least by the working area position.
@@ -1701,7 +1704,7 @@ impl<W: LayoutElement> Workspace<W> {
let mut x = 0;
for column in self.columns.iter().take(column_idx) {
- x += column.width() + PADDING;
+ x += column.width() + self.options.gaps;
}
x
@@ -1983,7 +1986,7 @@ impl<W: LayoutElement> Workspace<W> {
}
}
- x += col.width() + PADDING;
+ x += col.width() + self.options.gaps;
}
None
@@ -2140,7 +2143,7 @@ impl Workspace<Window> {
));
}
- x += col.width() + PADDING;
+ x += col.width() + self.options.gaps;
}
rv
@@ -2181,6 +2184,8 @@ impl<W: LayoutElement> Column<W> {
}
fn update_config(&mut self, options: Rc<Options>) {
+ let mut update_sizes = false;
+
// If preset widths changed, make our width non-preset.
if self.options.preset_widths != options.preset_widths {
if let ColumnWidth::Preset(idx) = self.width {
@@ -2188,7 +2193,15 @@ impl<W: LayoutElement> Column<W> {
}
}
+ if self.options.gaps != options.gaps {
+ update_sizes = true;
+ }
+
self.options = options;
+
+ if update_sizes {
+ self.update_window_sizes();
+ }
}
fn window_count(&self) -> usize {
@@ -2250,7 +2263,8 @@ impl<W: LayoutElement> Column<W> {
let max_width = max(max_width, min_width);
let width = self.width.resolve(&self.options, self.working_area.size.w);
- let height = (self.working_area.size.h - PADDING) / self.window_count() as i32 - PADDING;
+ let height = (self.working_area.size.h - self.options.gaps) / self.window_count() as i32
+ - self.options.gaps;
let size = Size::from((max(min(width, max_width), min_width), max(height, 1)));
for win in &self.windows {
@@ -2359,8 +2373,8 @@ impl<W: LayoutElement> Column<W> {
ColumnWidth::Proportion(proportion)
}
(ColumnWidth::Fixed(_), SizeChange::AdjustProportion(delta)) => {
- let current =
- (current_px + PADDING) as f64 / (self.working_area.size.w - PADDING) as f64;
+ let current = (current_px + self.options.gaps) as f64
+ / (self.working_area.size.w - self.options.gaps) as f64;
let proportion = (current + delta / 100.).clamp(0., MAX_F);
ColumnWidth::Proportion(proportion)
}
@@ -2384,12 +2398,12 @@ impl<W: LayoutElement> Column<W> {
let mut y = 0;
if !self.is_fullscreen {
- y = self.working_area.loc.y + PADDING;
+ y = self.working_area.loc.y + self.options.gaps;
}
self.windows.iter().map(move |win| {
let pos = y;
- y += win.geometry().size.h + PADDING;
+ y += win.geometry().size.h + self.options.gaps;
pos
})
}
@@ -2405,14 +2419,20 @@ pub fn output_size(output: &Output) -> Size<i32, Logical> {
.to_logical(output_scale)
}
-fn compute_new_view_offset(cur_x: i32, view_width: i32, new_col_x: i32, new_col_width: i32) -> i32 {
+fn compute_new_view_offset(
+ cur_x: i32,
+ view_width: i32,
+ new_col_x: i32,
+ new_col_width: i32,
+ gaps: i32,
+) -> i32 {
// If the column is wider than the view, always left-align it.
if view_width <= new_col_width {
return 0;
}
// Compute the padding in case it needs to be smaller due to large window width.
- let padding = ((view_width - new_col_width) / 2).clamp(0, PADDING);
+ let padding = ((view_width - new_col_width) / 2).clamp(0, gaps);
// Compute the desired new X with padding.
let new_x = new_col_x - padding;