forge
Explore
Log in

Don't you dare go Hollow

tab indicator: Add position setting

Browse files at this commit

64544a572698b2df5520783203f9723a2dfcac12Ivan MolodetskikhParent: d7d5a7f
niri-config/src/lib.rsmodified+13 -0
@@ -691,6 +691,8 @@ pub struct TabIndicator {
691691 pub width: FloatOrInt<0, 65535>,
692692 #[knuffel(child, default = Self::default().length)]
693693 pub length: TabIndicatorLength,
694+ #[knuffel(child, unwrap(argument), default = Self::default().position)]
695+ pub position: TabIndicatorPosition,
694696 #[knuffel(child)]
695697 pub active_color: Option<Color>,
696698 #[knuffel(child)]
@@ -711,6 +713,7 @@ impl Default for TabIndicator {
711713 length: TabIndicatorLength {
712714 total_proportion: Some(0.5),
713715 },
716+ position: TabIndicatorPosition::Left,
714717 active_color: None,
715718 inactive_color: None,
716719 active_gradient: None,
@@ -725,6 +728,14 @@ pub struct TabIndicatorLength {
725728 pub total_proportion: Option<f64>,
726729 }
727730
731+#[derive(knuffel::DecodeScalar, Debug, Clone, Copy, PartialEq)]
732+pub enum TabIndicatorPosition {
733+ Left,
734+ Right,
735+ Top,
736+ Bottom,
737+}
738+
728739 #[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)]
729740 pub struct InsertHint {
730741 #[knuffel(child)]
@@ -3555,6 +3566,7 @@ mod tests {
35553566
35563567 tab-indicator {
35573568 width 10
3569+ position "top"
35583570 }
35593571
35603572 preset-column-widths {
@@ -3819,6 +3831,7 @@ mod tests {
38193831 },
38203832 tab_indicator: TabIndicator {
38213833 width: FloatOrInt(10.),
3834+ position: TabIndicatorPosition::Top,
38223835 ..Default::default()
38233836 },
38243837 insert_hint: InsertHint {
src/layout/tab_indicator.rsmodified+34 -5
@@ -1,6 +1,7 @@
11 use std::iter::zip;
2+use std::mem;
23
3-use niri_config::{CornerRadius, Gradient, GradientRelativeTo};
4+use niri_config::{CornerRadius, Gradient, GradientRelativeTo, TabIndicatorPosition};
45 use smithay::utils::{Logical, Point, Rectangle, Size};
56
67 use super::tile::Tile;
@@ -78,8 +79,12 @@ impl TabIndicator {
7879 let width = round(self.config.width.0);
7980 let gap = round(self.config.gap.0);
8081
82+ let side = match self.config.position {
83+ TabIndicatorPosition::Left | TabIndicatorPosition::Right => tile_size.h,
84+ TabIndicatorPosition::Top | TabIndicatorPosition::Bottom => tile_size.w,
85+ };
8186 let total_prop = self.config.length.total_proportion.unwrap_or(0.5);
82- let min_length = round(tile_size.h * total_prop.clamp(0., 2.));
87+ let min_length = round(side * total_prop.clamp(0., 2.));
8388
8489 self.shaders.resize_with(count, Default::default);
8590 self.shader_locs.resize_with(count, Default::default);
@@ -92,7 +97,16 @@ impl TabIndicator {
9297 let floored_length = count as f64 * px_per_tab;
9398 let mut ones_left = ((length - floored_length) / pixel).max(0.).round() as usize;
9499
95- let mut shader_loc = Point::from((-gap - width, round((tile_size.h - length) / 2.)));
100+ let mut shader_loc = Point::from((-gap - width, round((side - length) / 2.)));
101+ match self.config.position {
102+ TabIndicatorPosition::Left => (),
103+ TabIndicatorPosition::Right => shader_loc.x = tile_size.w + gap,
104+ TabIndicatorPosition::Top => mem::swap(&mut shader_loc.x, &mut shader_loc.y),
105+ TabIndicatorPosition::Bottom => {
106+ shader_loc.x = shader_loc.y;
107+ shader_loc.y = tile_size.h + gap;
108+ }
109+ }
96110
97111 for ((shader, loc), tab) in zip(&mut self.shaders, &mut self.shader_locs).zip(tabs) {
98112 *loc = shader_loc;
@@ -102,9 +116,24 @@ impl TabIndicator {
102116 ones_left -= 1;
103117 px_per_tab += pixel;
104118 }
105- shader_loc.y += px_per_tab;
106119
107- let shader_size = Size::from((width, px_per_tab));
120+ match self.config.position {
121+ TabIndicatorPosition::Left | TabIndicatorPosition::Right => {
122+ shader_loc.y += px_per_tab
123+ }
124+ TabIndicatorPosition::Top | TabIndicatorPosition::Bottom => {
125+ shader_loc.x += px_per_tab
126+ }
127+ }
128+
129+ let shader_size = match self.config.position {
130+ TabIndicatorPosition::Left | TabIndicatorPosition::Right => {
131+ Size::from((width, px_per_tab))
132+ }
133+ TabIndicatorPosition::Top | TabIndicatorPosition::Bottom => {
134+ Size::from((px_per_tab, width))
135+ }
136+ };
108137
109138 let mut gradient_area = match tab.gradient.relative_to {
110139 GradientRelativeTo::Window => tile_geo,
src/layout/tests.rsmodified+15 -1
@@ -1,6 +1,9 @@
11 use std::cell::Cell;
22
3-use niri_config::{FloatOrInt, OutputName, TabIndicatorLength, WorkspaceName, WorkspaceReference};
3+use niri_config::{
4+ FloatOrInt, OutputName, TabIndicatorLength, TabIndicatorPosition, WorkspaceName,
5+ WorkspaceReference,
6+};
47 use proptest::prelude::*;
58 use proptest_derive::Arbitrary;
69 use smithay::output::{Mode, PhysicalProperties, Subpixel};
@@ -3200,6 +3203,15 @@ fn arbitrary_center_focused_column() -> impl Strategy<Value = CenterFocusedColum
32003203 ]
32013204 }
32023205
3206+fn arbitrary_tab_indicator_position() -> impl Strategy<Value = TabIndicatorPosition> {
3207+ prop_oneof![
3208+ Just(TabIndicatorPosition::Left),
3209+ Just(TabIndicatorPosition::Right),
3210+ Just(TabIndicatorPosition::Top),
3211+ Just(TabIndicatorPosition::Bottom),
3212+ ]
3213+}
3214+
32033215 prop_compose! {
32043216 fn arbitrary_focus_ring()(
32053217 off in any::<bool>(),
@@ -3246,6 +3258,7 @@ prop_compose! {
32463258 width in arbitrary_spacing(),
32473259 gap in arbitrary_spacing_neg(),
32483260 length in (0f64..2f64),
3261+ position in arbitrary_tab_indicator_position(),
32493262 ) -> niri_config::TabIndicator {
32503263 niri_config::TabIndicator {
32513264 off,
@@ -3253,6 +3266,7 @@ prop_compose! {
32533266 width: FloatOrInt(width),
32543267 gap: FloatOrInt(gap),
32553268 length: TabIndicatorLength { total_proportion: Some(length) },
3269+ position,
32563270 ..Default::default()
32573271 }
32583272 }