mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-21 02:01:55 +07:00
tab indicator: Add position setting
This commit is contained in:
@@ -691,6 +691,8 @@ pub struct TabIndicator {
|
||||
pub width: FloatOrInt<0, 65535>,
|
||||
#[knuffel(child, default = Self::default().length)]
|
||||
pub length: TabIndicatorLength,
|
||||
#[knuffel(child, unwrap(argument), default = Self::default().position)]
|
||||
pub position: TabIndicatorPosition,
|
||||
#[knuffel(child)]
|
||||
pub active_color: Option<Color>,
|
||||
#[knuffel(child)]
|
||||
@@ -711,6 +713,7 @@ impl Default for TabIndicator {
|
||||
length: TabIndicatorLength {
|
||||
total_proportion: Some(0.5),
|
||||
},
|
||||
position: TabIndicatorPosition::Left,
|
||||
active_color: None,
|
||||
inactive_color: None,
|
||||
active_gradient: None,
|
||||
@@ -725,6 +728,14 @@ pub struct TabIndicatorLength {
|
||||
pub total_proportion: Option<f64>,
|
||||
}
|
||||
|
||||
#[derive(knuffel::DecodeScalar, Debug, Clone, Copy, PartialEq)]
|
||||
pub enum TabIndicatorPosition {
|
||||
Left,
|
||||
Right,
|
||||
Top,
|
||||
Bottom,
|
||||
}
|
||||
|
||||
#[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)]
|
||||
pub struct InsertHint {
|
||||
#[knuffel(child)]
|
||||
@@ -3555,6 +3566,7 @@ mod tests {
|
||||
|
||||
tab-indicator {
|
||||
width 10
|
||||
position "top"
|
||||
}
|
||||
|
||||
preset-column-widths {
|
||||
@@ -3819,6 +3831,7 @@ mod tests {
|
||||
},
|
||||
tab_indicator: TabIndicator {
|
||||
width: FloatOrInt(10.),
|
||||
position: TabIndicatorPosition::Top,
|
||||
..Default::default()
|
||||
},
|
||||
insert_hint: InsertHint {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use std::iter::zip;
|
||||
use std::mem;
|
||||
|
||||
use niri_config::{CornerRadius, Gradient, GradientRelativeTo};
|
||||
use niri_config::{CornerRadius, Gradient, GradientRelativeTo, TabIndicatorPosition};
|
||||
use smithay::utils::{Logical, Point, Rectangle, Size};
|
||||
|
||||
use super::tile::Tile;
|
||||
@@ -78,8 +79,12 @@ impl TabIndicator {
|
||||
let width = round(self.config.width.0);
|
||||
let gap = round(self.config.gap.0);
|
||||
|
||||
let side = match self.config.position {
|
||||
TabIndicatorPosition::Left | TabIndicatorPosition::Right => tile_size.h,
|
||||
TabIndicatorPosition::Top | TabIndicatorPosition::Bottom => tile_size.w,
|
||||
};
|
||||
let total_prop = self.config.length.total_proportion.unwrap_or(0.5);
|
||||
let min_length = round(tile_size.h * total_prop.clamp(0., 2.));
|
||||
let min_length = round(side * total_prop.clamp(0., 2.));
|
||||
|
||||
self.shaders.resize_with(count, Default::default);
|
||||
self.shader_locs.resize_with(count, Default::default);
|
||||
@@ -92,7 +97,16 @@ impl TabIndicator {
|
||||
let floored_length = count as f64 * px_per_tab;
|
||||
let mut ones_left = ((length - floored_length) / pixel).max(0.).round() as usize;
|
||||
|
||||
let mut shader_loc = Point::from((-gap - width, round((tile_size.h - length) / 2.)));
|
||||
let mut shader_loc = Point::from((-gap - width, round((side - length) / 2.)));
|
||||
match self.config.position {
|
||||
TabIndicatorPosition::Left => (),
|
||||
TabIndicatorPosition::Right => shader_loc.x = tile_size.w + gap,
|
||||
TabIndicatorPosition::Top => mem::swap(&mut shader_loc.x, &mut shader_loc.y),
|
||||
TabIndicatorPosition::Bottom => {
|
||||
shader_loc.x = shader_loc.y;
|
||||
shader_loc.y = tile_size.h + gap;
|
||||
}
|
||||
}
|
||||
|
||||
for ((shader, loc), tab) in zip(&mut self.shaders, &mut self.shader_locs).zip(tabs) {
|
||||
*loc = shader_loc;
|
||||
@@ -102,9 +116,24 @@ impl TabIndicator {
|
||||
ones_left -= 1;
|
||||
px_per_tab += pixel;
|
||||
}
|
||||
shader_loc.y += px_per_tab;
|
||||
|
||||
let shader_size = Size::from((width, px_per_tab));
|
||||
match self.config.position {
|
||||
TabIndicatorPosition::Left | TabIndicatorPosition::Right => {
|
||||
shader_loc.y += px_per_tab
|
||||
}
|
||||
TabIndicatorPosition::Top | TabIndicatorPosition::Bottom => {
|
||||
shader_loc.x += px_per_tab
|
||||
}
|
||||
}
|
||||
|
||||
let shader_size = match self.config.position {
|
||||
TabIndicatorPosition::Left | TabIndicatorPosition::Right => {
|
||||
Size::from((width, px_per_tab))
|
||||
}
|
||||
TabIndicatorPosition::Top | TabIndicatorPosition::Bottom => {
|
||||
Size::from((px_per_tab, width))
|
||||
}
|
||||
};
|
||||
|
||||
let mut gradient_area = match tab.gradient.relative_to {
|
||||
GradientRelativeTo::Window => tile_geo,
|
||||
|
||||
+15
-1
@@ -1,6 +1,9 @@
|
||||
use std::cell::Cell;
|
||||
|
||||
use niri_config::{FloatOrInt, OutputName, TabIndicatorLength, WorkspaceName, WorkspaceReference};
|
||||
use niri_config::{
|
||||
FloatOrInt, OutputName, TabIndicatorLength, TabIndicatorPosition, WorkspaceName,
|
||||
WorkspaceReference,
|
||||
};
|
||||
use proptest::prelude::*;
|
||||
use proptest_derive::Arbitrary;
|
||||
use smithay::output::{Mode, PhysicalProperties, Subpixel};
|
||||
@@ -3200,6 +3203,15 @@ fn arbitrary_center_focused_column() -> impl Strategy<Value = CenterFocusedColum
|
||||
]
|
||||
}
|
||||
|
||||
fn arbitrary_tab_indicator_position() -> impl Strategy<Value = TabIndicatorPosition> {
|
||||
prop_oneof![
|
||||
Just(TabIndicatorPosition::Left),
|
||||
Just(TabIndicatorPosition::Right),
|
||||
Just(TabIndicatorPosition::Top),
|
||||
Just(TabIndicatorPosition::Bottom),
|
||||
]
|
||||
}
|
||||
|
||||
prop_compose! {
|
||||
fn arbitrary_focus_ring()(
|
||||
off in any::<bool>(),
|
||||
@@ -3246,6 +3258,7 @@ prop_compose! {
|
||||
width in arbitrary_spacing(),
|
||||
gap in arbitrary_spacing_neg(),
|
||||
length in (0f64..2f64),
|
||||
position in arbitrary_tab_indicator_position(),
|
||||
) -> niri_config::TabIndicator {
|
||||
niri_config::TabIndicator {
|
||||
off,
|
||||
@@ -3253,6 +3266,7 @@ prop_compose! {
|
||||
width: FloatOrInt(width),
|
||||
gap: FloatOrInt(gap),
|
||||
length: TabIndicatorLength { total_proportion: Some(length) },
|
||||
position,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user