mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-22 02:01:55 +07:00
implement always_center_single_column layout option
This commit is contained in:
committed by
Ivan Molodetskikh
parent
952916fd1c
commit
fd8ebb9d06
@@ -397,6 +397,8 @@ pub struct Layout {
|
|||||||
pub default_column_width: Option<DefaultColumnWidth>,
|
pub default_column_width: Option<DefaultColumnWidth>,
|
||||||
#[knuffel(child, unwrap(argument), default)]
|
#[knuffel(child, unwrap(argument), default)]
|
||||||
pub center_focused_column: CenterFocusedColumn,
|
pub center_focused_column: CenterFocusedColumn,
|
||||||
|
#[knuffel(child)]
|
||||||
|
pub always_center_single_column: bool,
|
||||||
#[knuffel(child, unwrap(argument), default = Self::default().gaps)]
|
#[knuffel(child, unwrap(argument), default = Self::default().gaps)]
|
||||||
pub gaps: FloatOrInt<0, 65535>,
|
pub gaps: FloatOrInt<0, 65535>,
|
||||||
#[knuffel(child, default)]
|
#[knuffel(child, default)]
|
||||||
@@ -411,6 +413,7 @@ impl Default for Layout {
|
|||||||
preset_column_widths: Default::default(),
|
preset_column_widths: Default::default(),
|
||||||
default_column_width: Default::default(),
|
default_column_width: Default::default(),
|
||||||
center_focused_column: Default::default(),
|
center_focused_column: Default::default(),
|
||||||
|
always_center_single_column: false,
|
||||||
gaps: FloatOrInt(16.),
|
gaps: FloatOrInt(16.),
|
||||||
struts: Default::default(),
|
struts: Default::default(),
|
||||||
}
|
}
|
||||||
@@ -3057,6 +3060,7 @@ mod tests {
|
|||||||
bottom: FloatOrInt(0.),
|
bottom: FloatOrInt(0.),
|
||||||
},
|
},
|
||||||
center_focused_column: CenterFocusedColumn::OnOverflow,
|
center_focused_column: CenterFocusedColumn::OnOverflow,
|
||||||
|
always_center_single_column: false,
|
||||||
},
|
},
|
||||||
spawn_at_startup: vec![SpawnAtStartup {
|
spawn_at_startup: vec![SpawnAtStartup {
|
||||||
command: vec!["alacritty".to_owned(), "-e".to_owned(), "fish".to_owned()],
|
command: vec!["alacritty".to_owned(), "-e".to_owned(), "fish".to_owned()],
|
||||||
|
|||||||
@@ -236,6 +236,7 @@ pub struct Options {
|
|||||||
pub focus_ring: niri_config::FocusRing,
|
pub focus_ring: niri_config::FocusRing,
|
||||||
pub border: niri_config::Border,
|
pub border: niri_config::Border,
|
||||||
pub center_focused_column: CenterFocusedColumn,
|
pub center_focused_column: CenterFocusedColumn,
|
||||||
|
pub always_center_single_column: bool,
|
||||||
/// Column widths that `toggle_width()` switches between.
|
/// Column widths that `toggle_width()` switches between.
|
||||||
pub preset_widths: Vec<ColumnWidth>,
|
pub preset_widths: Vec<ColumnWidth>,
|
||||||
/// Initial width for new columns.
|
/// Initial width for new columns.
|
||||||
@@ -255,6 +256,7 @@ impl Default for Options {
|
|||||||
focus_ring: Default::default(),
|
focus_ring: Default::default(),
|
||||||
border: Default::default(),
|
border: Default::default(),
|
||||||
center_focused_column: Default::default(),
|
center_focused_column: Default::default(),
|
||||||
|
always_center_single_column: false,
|
||||||
preset_widths: vec![
|
preset_widths: vec![
|
||||||
ColumnWidth::Proportion(1. / 3.),
|
ColumnWidth::Proportion(1. / 3.),
|
||||||
ColumnWidth::Proportion(0.5),
|
ColumnWidth::Proportion(0.5),
|
||||||
@@ -297,6 +299,7 @@ impl Options {
|
|||||||
focus_ring: layout.focus_ring,
|
focus_ring: layout.focus_ring,
|
||||||
border: layout.border,
|
border: layout.border,
|
||||||
center_focused_column: layout.center_focused_column,
|
center_focused_column: layout.center_focused_column,
|
||||||
|
always_center_single_column: layout.always_center_single_column,
|
||||||
preset_widths,
|
preset_widths,
|
||||||
default_width,
|
default_width,
|
||||||
animations: config.animations.clone(),
|
animations: config.animations.clone(),
|
||||||
@@ -4455,11 +4458,13 @@ mod tests {
|
|||||||
focus_ring in arbitrary_focus_ring(),
|
focus_ring in arbitrary_focus_ring(),
|
||||||
border in arbitrary_border(),
|
border in arbitrary_border(),
|
||||||
center_focused_column in arbitrary_center_focused_column(),
|
center_focused_column in arbitrary_center_focused_column(),
|
||||||
|
always_center_single_column in any::<bool>(),
|
||||||
) -> Options {
|
) -> Options {
|
||||||
Options {
|
Options {
|
||||||
gaps,
|
gaps,
|
||||||
struts,
|
struts,
|
||||||
center_focused_column,
|
center_focused_column,
|
||||||
|
always_center_single_column,
|
||||||
focus_ring,
|
focus_ring,
|
||||||
border,
|
border,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|||||||
+18
-4
@@ -459,6 +459,11 @@ impl<W: LayoutElement> Workspace<W> {
|
|||||||
self.scale
|
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) {
|
pub fn advance_animations(&mut self, current_time: Duration) {
|
||||||
if let Some(ViewOffsetAdjustment::Animation(anim)) = &mut self.view_offset_adj {
|
if let Some(ViewOffsetAdjustment::Animation(anim)) = &mut self.view_offset_adj {
|
||||||
anim.set_current_time(current_time);
|
anim.set_current_time(current_time);
|
||||||
@@ -750,6 +755,10 @@ impl<W: LayoutElement> Workspace<W> {
|
|||||||
idx: usize,
|
idx: usize,
|
||||||
prev_idx: Option<usize>,
|
prev_idx: Option<usize>,
|
||||||
) -> f64 {
|
) -> 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 {
|
match self.options.center_focused_column {
|
||||||
CenterFocusedColumn::Always => {
|
CenterFocusedColumn::Always => {
|
||||||
self.compute_new_view_offset_for_column_centered(current_x, idx)
|
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 let Some(resize) = resize {
|
||||||
// If this is an interactive resize commit of an active window, then we need to
|
// If this is an interactive resize commit of an active window, then we need to
|
||||||
// either preserve the view offset or adjust it accordingly.
|
// 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 width = self.data[col_idx].width;
|
||||||
let offset = if centered {
|
let offset = if centered {
|
||||||
@@ -2550,7 +2559,7 @@ impl<W: LayoutElement> Workspace<W> {
|
|||||||
let left_strut = self.working_area.loc.x;
|
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;
|
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.;
|
let mut col_x = 0.;
|
||||||
for (col_idx, col) in self.columns.iter().enumerate() {
|
for (col_idx, col) in self.columns.iter().enumerate() {
|
||||||
let col_w = col.width();
|
let col_w = col.width();
|
||||||
@@ -2651,7 +2660,7 @@ impl<W: LayoutElement> Workspace<W> {
|
|||||||
|
|
||||||
let mut new_col_idx = target_snap.col_idx;
|
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.
|
// Focus the furthest window towards the direction of the gesture.
|
||||||
if target_view_offset >= current_view_offset {
|
if target_view_offset >= current_view_offset {
|
||||||
for col_idx in (new_col_idx + 1)..self.columns.len() {
|
for col_idx in (new_col_idx + 1)..self.columns.len() {
|
||||||
@@ -2768,6 +2777,8 @@ impl<W: LayoutElement> Workspace<W> {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let is_centering = self.is_centering_focused_column();
|
||||||
|
|
||||||
let col = self
|
let col = self
|
||||||
.columns
|
.columns
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
@@ -2786,7 +2797,7 @@ impl<W: LayoutElement> Workspace<W> {
|
|||||||
dx = -dx;
|
dx = -dx;
|
||||||
};
|
};
|
||||||
|
|
||||||
if self.options.center_focused_column == CenterFocusedColumn::Always {
|
if is_centering {
|
||||||
dx *= 2.;
|
dx *= 2.;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3637,6 +3648,9 @@ impl<W: LayoutElement> Column<W> {
|
|||||||
&self,
|
&self,
|
||||||
data: impl Iterator<Item = TileData>,
|
data: impl Iterator<Item = TileData>,
|
||||||
) -> impl Iterator<Item = Point<f64, Logical>> {
|
) -> 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 center = self.options.center_focused_column == CenterFocusedColumn::Always;
|
||||||
let gaps = self.options.gaps;
|
let gaps = self.options.gaps;
|
||||||
let col_width = self.width();
|
let col_width = self.width();
|
||||||
|
|||||||
Reference in New Issue
Block a user