tab indicator: Add corner-radius setting
Browse files at this commit7e552333a993e83a2dba52392109617e486f5f60Parent: 213eafa3 changed files +68 -1
- niri-config/src/lib.rs +14 -0
- src/layout/tab_indicator.rs +50 -1
- wiki/Configuration:-Layout.md +4 -0
niri-config/src/lib.rsmodified+14 -0
| @@ -697,6 +697,8 @@ pub struct TabIndicator { | |||
| 697 | pub position: TabIndicatorPosition, | 697 | pub position: TabIndicatorPosition, |
| 698 | #[knuffel(child, unwrap(argument), default = Self::default().gaps_between_tabs)] | 698 | #[knuffel(child, unwrap(argument), default = Self::default().gaps_between_tabs)] |
| 699 | pub gaps_between_tabs: FloatOrInt<0, 65535>, | 699 | pub gaps_between_tabs: FloatOrInt<0, 65535>, |
| 700 | + #[knuffel(child, unwrap(argument), default = Self::default().corner_radius)] | ||
| 701 | + pub corner_radius: FloatOrInt<0, 65535>, | ||
| 700 | #[knuffel(child)] | 702 | #[knuffel(child)] |
| 701 | pub active_color: Option<Color>, | 703 | pub active_color: Option<Color>, |
| 702 | #[knuffel(child)] | 704 | #[knuffel(child)] |
| @@ -720,6 +722,7 @@ impl Default for TabIndicator { | |||
| 720 | }, | 722 | }, |
| 721 | position: TabIndicatorPosition::Left, | 723 | position: TabIndicatorPosition::Left, |
| 722 | gaps_between_tabs: FloatOrInt(0.), | 724 | gaps_between_tabs: FloatOrInt(0.), |
| 725 | + corner_radius: FloatOrInt(0.), | ||
| 723 | active_color: None, | 726 | active_color: None, |
| 724 | inactive_color: None, | 727 | inactive_color: None, |
| 725 | active_gradient: None, | 728 | active_gradient: None, |
| @@ -1234,6 +1237,17 @@ impl From<CornerRadius> for [f32; 4] { | |||
| 1234 | } | 1237 | } |
| 1235 | } | 1238 | } |
| 1236 | 1239 | ||
| 1240 | +impl From<f32> for CornerRadius { | ||
| 1241 | + fn from(value: f32) -> Self { | ||
| 1242 | + Self { | ||
| 1243 | + top_left: value, | ||
| 1244 | + top_right: value, | ||
| 1245 | + bottom_right: value, | ||
| 1246 | + bottom_left: value, | ||
| 1247 | + } | ||
| 1248 | + } | ||
| 1249 | +} | ||
| 1250 | + | ||
| 1237 | #[derive(knuffel::DecodeScalar, Debug, Clone, Copy, PartialEq, Eq)] | 1251 | #[derive(knuffel::DecodeScalar, Debug, Clone, Copy, PartialEq, Eq)] |
| 1238 | pub enum BlockOutFrom { | 1252 | pub enum BlockOutFrom { |
| 1239 | Screencast, | 1253 | Screencast, |
src/layout/tab_indicator.rsmodified+50 -1
| @@ -180,6 +180,11 @@ impl TabIndicator { | |||
| 180 | self.shaders.resize_with(count, Default::default); | 180 | self.shaders.resize_with(count, Default::default); |
| 181 | self.shader_locs.resize_with(count, Default::default); | 181 | self.shader_locs.resize_with(count, Default::default); |
| 182 | 182 | ||
| 183 | + let position = self.config.position; | ||
| 184 | + let radius = self.config.corner_radius.0 as f32; | ||
| 185 | + let shared_rounded_corners = self.config.gaps_between_tabs.0 == 0.; | ||
| 186 | + let mut tabs_left = tab_count; | ||
| 187 | + | ||
| 183 | let rects = self.tab_rects(area, count, scale); | 188 | let rects = self.tab_rects(area, count, scale); |
| 184 | for ((shader, loc), (tab, rect)) in zip( | 189 | for ((shader, loc), (tab, rect)) in zip( |
| 185 | zip(&mut self.shaders, &mut self.shader_locs), | 190 | zip(&mut self.shaders, &mut self.shader_locs), |
| @@ -200,6 +205,50 @@ impl TabIndicator { | |||
| 200 | color_to *= 0.5; | 205 | color_to *= 0.5; |
| 201 | } | 206 | } |
| 202 | 207 | ||
| 208 | + let radius = if shared_rounded_corners && tab_count > 1 { | ||
| 209 | + if tabs_left == tab_count { | ||
| 210 | + // First tab. | ||
| 211 | + match position { | ||
| 212 | + TabIndicatorPosition::Left | TabIndicatorPosition::Right => CornerRadius { | ||
| 213 | + top_left: radius, | ||
| 214 | + top_right: radius, | ||
| 215 | + bottom_right: 0., | ||
| 216 | + bottom_left: 0., | ||
| 217 | + }, | ||
| 218 | + TabIndicatorPosition::Top | TabIndicatorPosition::Bottom => CornerRadius { | ||
| 219 | + top_left: radius, | ||
| 220 | + top_right: 0., | ||
| 221 | + bottom_right: 0., | ||
| 222 | + bottom_left: radius, | ||
| 223 | + }, | ||
| 224 | + } | ||
| 225 | + } else if tabs_left == 1 { | ||
| 226 | + // Last tab. | ||
| 227 | + match position { | ||
| 228 | + TabIndicatorPosition::Left | TabIndicatorPosition::Right => CornerRadius { | ||
| 229 | + top_left: 0., | ||
| 230 | + top_right: 0., | ||
| 231 | + bottom_right: radius, | ||
| 232 | + bottom_left: radius, | ||
| 233 | + }, | ||
| 234 | + TabIndicatorPosition::Top | TabIndicatorPosition::Bottom => CornerRadius { | ||
| 235 | + top_left: 0., | ||
| 236 | + top_right: radius, | ||
| 237 | + bottom_right: radius, | ||
| 238 | + bottom_left: 0., | ||
| 239 | + }, | ||
| 240 | + } | ||
| 241 | + } else { | ||
| 242 | + // Tab in the middle. | ||
| 243 | + CornerRadius::default() | ||
| 244 | + } | ||
| 245 | + } else { | ||
| 246 | + // Separate tabs, or the only tab. | ||
| 247 | + CornerRadius::from(radius) | ||
| 248 | + }; | ||
| 249 | + let radius = radius.fit_to(rect.size.w as f32, rect.size.h as f32); | ||
| 250 | + tabs_left -= 1; | ||
| 251 | + | ||
| 203 | shader.update( | 252 | shader.update( |
| 204 | rect.size, | 253 | rect.size, |
| 205 | gradient_area, | 254 | gradient_area, |
| @@ -209,7 +258,7 @@ impl TabIndicator { | |||
| 209 | ((tab.gradient.angle as f32) - 90.).to_radians(), | 258 | ((tab.gradient.angle as f32) - 90.).to_radians(), |
| 210 | Rectangle::from_size(rect.size), | 259 | Rectangle::from_size(rect.size), |
| 211 | 0., | 260 | 0., |
| 212 | - CornerRadius::default(), | 261 | + radius, |
| 213 | scale as f32, | 262 | scale as f32, |
| 214 | 1., | 263 | 1., |
| 215 | ); | 264 | ); |
wiki/Configuration:-Layout.mdmodified+4 -0
| @@ -63,6 +63,7 @@ layout { | |||
| 63 | length total-proportion=1.0 | 63 | length total-proportion=1.0 |
| 64 | position "right" | 64 | position "right" |
| 65 | gaps-between-tabs 2 | 65 | gaps-between-tabs 2 |
| 66 | + corner-radius 8 | ||
| 66 | active-color "red" | 67 | active-color "red" |
| 67 | inactive-color "gray" | 68 | inactive-color "gray" |
| 68 | // active-gradient from="#80c8ff" to="#bbddff" angle=45 | 69 | // active-gradient from="#80c8ff" to="#bbddff" angle=45 |
| @@ -439,6 +440,9 @@ It can be `left`, `right`, `top`, or `bottom`. | |||
| 439 | 440 | ||
| 440 | `gaps-between-tabs` controls the gap between individual tabs in logical pixels. | 441 | `gaps-between-tabs` controls the gap between individual tabs in logical pixels. |
| 441 | 442 | ||
| 443 | +`corner-radius` sets the rounded corner radius for tabs in the indicator in logical pixels. | ||
| 444 | +When `gaps-between-tabs` is zero, only the first and the last tabs have rounded corners, otherwise all tabs do. | ||
| 445 | + | ||
| 442 | `active-color`, `inactive-color`, `active-gradient`, `inactive-gradient` let you override the colors for the tabs. | 446 | `active-color`, `inactive-color`, `active-gradient`, `inactive-gradient` let you override the colors for the tabs. |
| 443 | They have the same semantics as the border and focus ring colors and gradients. | 447 | They have the same semantics as the border and focus ring colors and gradients. |
| 444 | 448 | ||