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 {
691 pub width: FloatOrInt<0, 65535>,691 pub width: FloatOrInt<0, 65535>,
692 #[knuffel(child, default = Self::default().length)]692 #[knuffel(child, default = Self::default().length)]
693 pub length: TabIndicatorLength,693 pub length: TabIndicatorLength,
694+ #[knuffel(child, unwrap(argument), default = Self::default().position)]
695+ pub position: TabIndicatorPosition,
694 #[knuffel(child)]696 #[knuffel(child)]
695 pub active_color: Option<Color>,697 pub active_color: Option<Color>,
696 #[knuffel(child)]698 #[knuffel(child)]
@@ -711,6 +713,7 @@ impl Default for TabIndicator {
711 length: TabIndicatorLength {713 length: TabIndicatorLength {
712 total_proportion: Some(0.5),714 total_proportion: Some(0.5),
713 },715 },
716+ position: TabIndicatorPosition::Left,
714 active_color: None,717 active_color: None,
715 inactive_color: None,718 inactive_color: None,
716 active_gradient: None,719 active_gradient: None,
@@ -725,6 +728,14 @@ pub struct TabIndicatorLength {
725 pub total_proportion: Option<f64>,728 pub total_proportion: Option<f64>,
726 }729 }
727 730
731+#[derive(knuffel::DecodeScalar, Debug, Clone, Copy, PartialEq)]
732+pub enum TabIndicatorPosition {
733+ Left,
734+ Right,
735+ Top,
736+ Bottom,
737+}
738+
728 #[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)]739 #[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)]
729 pub struct InsertHint {740 pub struct InsertHint {
730 #[knuffel(child)]741 #[knuffel(child)]
@@ -3555,6 +3566,7 @@ mod tests {
3555 3566
3556 tab-indicator {3567 tab-indicator {
3557 width 103568 width 10
3569+ position "top"
3558 }3570 }
3559 3571
3560 preset-column-widths {3572 preset-column-widths {
@@ -3819,6 +3831,7 @@ mod tests {
3819 },3831 },
3820 tab_indicator: TabIndicator {3832 tab_indicator: TabIndicator {
3821 width: FloatOrInt(10.),3833 width: FloatOrInt(10.),
3834+ position: TabIndicatorPosition::Top,
3822 ..Default::default()3835 ..Default::default()
3823 },3836 },
3824 insert_hint: InsertHint {3837 insert_hint: InsertHint {
src/layout/tab_indicator.rsmodified+34 -5
@@ -1,6 +1,7 @@
1 use std::iter::zip;1 use std::iter::zip;
2+use std::mem;
2 3
3-use niri_config::{CornerRadius, Gradient, GradientRelativeTo};4+use niri_config::{CornerRadius, Gradient, GradientRelativeTo, TabIndicatorPosition};
4 use smithay::utils::{Logical, Point, Rectangle, Size};5 use smithay::utils::{Logical, Point, Rectangle, Size};
5 6
6 use super::tile::Tile;7 use super::tile::Tile;
@@ -78,8 +79,12 @@ impl TabIndicator {
78 let width = round(self.config.width.0);79 let width = round(self.config.width.0);
79 let gap = round(self.config.gap.0);80 let gap = round(self.config.gap.0);
80 81
82+ let side = match self.config.position {
83+ TabIndicatorPosition::Left | TabIndicatorPosition::Right => tile_size.h,
84+ TabIndicatorPosition::Top | TabIndicatorPosition::Bottom => tile_size.w,
85+ };
81 let total_prop = self.config.length.total_proportion.unwrap_or(0.5);86 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.));
83 88
84 self.shaders.resize_with(count, Default::default);89 self.shaders.resize_with(count, Default::default);
85 self.shader_locs.resize_with(count, Default::default);90 self.shader_locs.resize_with(count, Default::default);
@@ -92,7 +97,16 @@ impl TabIndicator {
92 let floored_length = count as f64 * px_per_tab;97 let floored_length = count as f64 * px_per_tab;
93 let mut ones_left = ((length - floored_length) / pixel).max(0.).round() as usize;98 let mut ones_left = ((length - floored_length) / pixel).max(0.).round() as usize;
94 99
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+ }
96 110
97 for ((shader, loc), tab) in zip(&mut self.shaders, &mut self.shader_locs).zip(tabs) {111 for ((shader, loc), tab) in zip(&mut self.shaders, &mut self.shader_locs).zip(tabs) {
98 *loc = shader_loc;112 *loc = shader_loc;
@@ -102,9 +116,24 @@ impl TabIndicator {
102 ones_left -= 1;116 ones_left -= 1;
103 px_per_tab += pixel;117 px_per_tab += pixel;
104 }118 }
105- shader_loc.y += px_per_tab;
106 119
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+ };
108 137
109 let mut gradient_area = match tab.gradient.relative_to {138 let mut gradient_area = match tab.gradient.relative_to {
110 GradientRelativeTo::Window => tile_geo,139 GradientRelativeTo::Window => tile_geo,
src/layout/tests.rsmodified+15 -1
@@ -1,6 +1,9 @@
1 use std::cell::Cell;1 use std::cell::Cell;
2 2
3-use niri_config::{FloatOrInt, OutputName, TabIndicatorLength, WorkspaceName, WorkspaceReference};3+use niri_config::{
4+ FloatOrInt, OutputName, TabIndicatorLength, TabIndicatorPosition, WorkspaceName,
5+ WorkspaceReference,
6+};
4 use proptest::prelude::*;7 use proptest::prelude::*;
5 use proptest_derive::Arbitrary;8 use proptest_derive::Arbitrary;
6 use smithay::output::{Mode, PhysicalProperties, Subpixel};9 use smithay::output::{Mode, PhysicalProperties, Subpixel};
@@ -3200,6 +3203,15 @@ fn arbitrary_center_focused_column() -> impl Strategy<Value = CenterFocusedColum
3200 ]3203 ]
3201 }3204 }
3202 3205
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+
3203 prop_compose! {3215 prop_compose! {
3204 fn arbitrary_focus_ring()(3216 fn arbitrary_focus_ring()(
3205 off in any::<bool>(),3217 off in any::<bool>(),
@@ -3246,6 +3258,7 @@ prop_compose! {
3246 width in arbitrary_spacing(),3258 width in arbitrary_spacing(),
3247 gap in arbitrary_spacing_neg(),3259 gap in arbitrary_spacing_neg(),
3248 length in (0f64..2f64),3260 length in (0f64..2f64),
3261+ position in arbitrary_tab_indicator_position(),
3249 ) -> niri_config::TabIndicator {3262 ) -> niri_config::TabIndicator {
3250 niri_config::TabIndicator {3263 niri_config::TabIndicator {
3251 off,3264 off,
@@ -3253,6 +3266,7 @@ prop_compose! {
3253 width: FloatOrInt(width),3266 width: FloatOrInt(width),
3254 gap: FloatOrInt(gap),3267 gap: FloatOrInt(gap),
3255 length: TabIndicatorLength { total_proportion: Some(length) },3268 length: TabIndicatorLength { total_proportion: Some(length) },
3269+ position,
3256 ..Default::default()3270 ..Default::default()
3257 }3271 }
3258 }3272 }