aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/layout/mod.rs5
-rw-r--r--src/layout/workspace.rs22
2 files changed, 23 insertions, 4 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs
index 734512dd..fd1c5f7e 100644
--- a/src/layout/mod.rs
+++ b/src/layout/mod.rs
@@ -236,6 +236,7 @@ pub struct Options {
pub focus_ring: niri_config::FocusRing,
pub border: niri_config::Border,
pub center_focused_column: CenterFocusedColumn,
+ pub always_center_single_column: bool,
/// Column widths that `toggle_width()` switches between.
pub preset_widths: Vec<ColumnWidth>,
/// Initial width for new columns.
@@ -255,6 +256,7 @@ impl Default for Options {
focus_ring: Default::default(),
border: Default::default(),
center_focused_column: Default::default(),
+ always_center_single_column: false,
preset_widths: vec![
ColumnWidth::Proportion(1. / 3.),
ColumnWidth::Proportion(0.5),
@@ -297,6 +299,7 @@ impl Options {
focus_ring: layout.focus_ring,
border: layout.border,
center_focused_column: layout.center_focused_column,
+ always_center_single_column: layout.always_center_single_column,
preset_widths,
default_width,
animations: config.animations.clone(),
@@ -4455,11 +4458,13 @@ mod tests {
focus_ring in arbitrary_focus_ring(),
border in arbitrary_border(),
center_focused_column in arbitrary_center_focused_column(),
+ always_center_single_column in any::<bool>(),
) -> Options {
Options {
gaps,
struts,
center_focused_column,
+ always_center_single_column,
focus_ring,
border,
..Default::default()
diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs
index fbcb800b..b80cb95c 100644
--- a/src/layout/workspace.rs
+++ b/src/layout/workspace.rs
@@ -459,6 +459,11 @@ impl<W: LayoutElement> Workspace<W> {
self.scale
}
+ pub fn is_centering_focused_column(&self) -> bool {
+ self.options.center_focused_column == CenterFocusedColumn::Always
+ || (self.options.always_center_single_column && self.columns.len() <= 1)
+ }
+
pub fn advance_animations(&mut self, current_time: Duration) {
if let Some(ViewOffsetAdjustment::Animation(anim)) = &mut self.view_offset_adj {
anim.set_current_time(current_time);
@@ -750,6 +755,10 @@ impl<W: LayoutElement> Workspace<W> {
idx: usize,
prev_idx: Option<usize>,
) -> f64 {
+ if self.is_centering_focused_column() {
+ return self.compute_new_view_offset_for_column_centered(current_x, idx);
+ }
+
match self.options.center_focused_column {
CenterFocusedColumn::Always => {
self.compute_new_view_offset_for_column_centered(current_x, idx)
@@ -1399,7 +1408,7 @@ impl<W: LayoutElement> Workspace<W> {
if let Some(resize) = resize {
// If this is an interactive resize commit of an active window, then we need to
// either preserve the view offset or adjust it accordingly.
- let centered = self.options.center_focused_column == CenterFocusedColumn::Always;
+ let centered = self.is_centering_focused_column();
let width = self.data[col_idx].width;
let offset = if centered {
@@ -2550,7 +2559,7 @@ impl<W: LayoutElement> Workspace<W> {
let left_strut = self.working_area.loc.x;
let right_strut = self.view_size.w - self.working_area.size.w - self.working_area.loc.x;
- if self.options.center_focused_column == CenterFocusedColumn::Always {
+ if self.is_centering_focused_column() {
let mut col_x = 0.;
for (col_idx, col) in self.columns.iter().enumerate() {
let col_w = col.width();
@@ -2651,7 +2660,7 @@ impl<W: LayoutElement> Workspace<W> {
let mut new_col_idx = target_snap.col_idx;
- if self.options.center_focused_column != CenterFocusedColumn::Always {
+ if !self.is_centering_focused_column() {
// Focus the furthest window towards the direction of the gesture.
if target_view_offset >= current_view_offset {
for col_idx in (new_col_idx + 1)..self.columns.len() {
@@ -2768,6 +2777,8 @@ impl<W: LayoutElement> Workspace<W> {
return false;
}
+ let is_centering = self.is_centering_focused_column();
+
let col = self
.columns
.iter_mut()
@@ -2786,7 +2797,7 @@ impl<W: LayoutElement> Workspace<W> {
dx = -dx;
};
- if self.options.center_focused_column == CenterFocusedColumn::Always {
+ if is_centering {
dx *= 2.;
}
@@ -3637,6 +3648,9 @@ impl<W: LayoutElement> Column<W> {
&self,
data: impl Iterator<Item = TileData>,
) -> impl Iterator<Item = Point<f64, Logical>> {
+ // FIXME: this should take into account always-center-single-column, which means that
+ // Column should somehow know when it is being centered due to being the single column on
+ // the workspace or some other reason.
let center = self.options.center_focused_column == CenterFocusedColumn::Always;
let gaps = self.options.gaps;
let col_width = self.width();