Implement tab indicators
Browse files at this commita451f75917e427a4b4c7d986ce74e5a3999e563dParent: 15154109 changed files +417 -14
- niri-config/src/lib.rs +93 -0
- src/layout/focus_ring.rs +4 -0
- src/layout/mod.rs +4 -0
- src/layout/scrolling.rs +67 -10
- src/layout/tab_indicator.rs +201 -0
- src/layout/tests.rs +20 -1
- src/layout/tile.rs +10 -2
- src/utils/mod.rs +8 -0
- src/window/mod.rs +10 -1
niri-config/src/lib.rsmodified+93 -0
| @@ -445,6 +445,8 @@ pub struct Layout { | |||
| 445 | #[knuffel(child, default)] | 445 | #[knuffel(child, default)] |
| 446 | pub shadow: Shadow, | 446 | pub shadow: Shadow, |
| 447 | #[knuffel(child, default)] | 447 | #[knuffel(child, default)] |
| 448 | + pub tab_indicator: TabIndicator, | ||
| 449 | + #[knuffel(child, default)] | ||
| 448 | pub insert_hint: InsertHint, | 450 | pub insert_hint: InsertHint, |
| 449 | #[knuffel(child, unwrap(children), default)] | 451 | #[knuffel(child, unwrap(children), default)] |
| 450 | pub preset_column_widths: Vec<PresetSize>, | 452 | pub preset_column_widths: Vec<PresetSize>, |
| @@ -472,6 +474,7 @@ impl Default for Layout { | |||
| 472 | focus_ring: Default::default(), | 474 | focus_ring: Default::default(), |
| 473 | border: Default::default(), | 475 | border: Default::default(), |
| 474 | shadow: Default::default(), | 476 | shadow: Default::default(), |
| 477 | + tab_indicator: Default::default(), | ||
| 475 | insert_hint: Default::default(), | 478 | insert_hint: Default::default(), |
| 476 | preset_column_widths: Default::default(), | 479 | preset_column_widths: Default::default(), |
| 477 | default_column_width: Default::default(), | 480 | default_column_width: Default::default(), |
| @@ -676,6 +679,49 @@ pub struct ShadowOffset { | |||
| 676 | pub y: FloatOrInt<-65535, 65535>, | 679 | pub y: FloatOrInt<-65535, 65535>, |
| 677 | } | 680 | } |
| 678 | 681 | ||
| 682 | +#[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)] | ||
| 683 | +pub struct TabIndicator { | ||
| 684 | + #[knuffel(child)] | ||
| 685 | + pub off: bool, | ||
| 686 | + #[knuffel(child, unwrap(argument), default = Self::default().gap)] | ||
| 687 | + pub gap: FloatOrInt<-65535, 65535>, | ||
| 688 | + #[knuffel(child, unwrap(argument), default = Self::default().width)] | ||
| 689 | + pub width: FloatOrInt<0, 65535>, | ||
| 690 | + #[knuffel(child, default = Self::default().length)] | ||
| 691 | + pub length: TabIndicatorLength, | ||
| 692 | + #[knuffel(child)] | ||
| 693 | + pub active_color: Option<Color>, | ||
| 694 | + #[knuffel(child)] | ||
| 695 | + pub inactive_color: Option<Color>, | ||
| 696 | + #[knuffel(child)] | ||
| 697 | + pub active_gradient: Option<Gradient>, | ||
| 698 | + #[knuffel(child)] | ||
| 699 | + pub inactive_gradient: Option<Gradient>, | ||
| 700 | +} | ||
| 701 | + | ||
| 702 | +impl Default for TabIndicator { | ||
| 703 | + fn default() -> Self { | ||
| 704 | + Self { | ||
| 705 | + off: false, | ||
| 706 | + gap: FloatOrInt(5.), | ||
| 707 | + width: FloatOrInt(4.), | ||
| 708 | + length: TabIndicatorLength { | ||
| 709 | + total_proportion: Some(0.5), | ||
| 710 | + }, | ||
| 711 | + active_color: None, | ||
| 712 | + inactive_color: None, | ||
| 713 | + active_gradient: None, | ||
| 714 | + inactive_gradient: None, | ||
| 715 | + } | ||
| 716 | + } | ||
| 717 | +} | ||
| 718 | + | ||
| 719 | +#[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)] | ||
| 720 | +pub struct TabIndicatorLength { | ||
| 721 | + #[knuffel(property)] | ||
| 722 | + pub total_proportion: Option<f64>, | ||
| 723 | +} | ||
| 724 | + | ||
| 679 | #[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)] | 725 | #[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)] |
| 680 | pub struct InsertHint { | 726 | pub struct InsertHint { |
| 681 | #[knuffel(child)] | 727 | #[knuffel(child)] |
| @@ -1101,6 +1147,8 @@ pub struct WindowRule { | |||
| 1101 | pub border: BorderRule, | 1147 | pub border: BorderRule, |
| 1102 | #[knuffel(child, default)] | 1148 | #[knuffel(child, default)] |
| 1103 | pub shadow: ShadowRule, | 1149 | pub shadow: ShadowRule, |
| 1150 | + #[knuffel(child, default)] | ||
| 1151 | + pub tab_indicator: TabIndicatorRule, | ||
| 1104 | #[knuffel(child, unwrap(argument))] | 1152 | #[knuffel(child, unwrap(argument))] |
| 1105 | pub draw_border_with_background: Option<bool>, | 1153 | pub draw_border_with_background: Option<bool>, |
| 1106 | #[knuffel(child, unwrap(argument))] | 1154 | #[knuffel(child, unwrap(argument))] |
| @@ -1202,6 +1250,18 @@ pub struct ShadowRule { | |||
| 1202 | pub inactive_color: Option<Color>, | 1250 | pub inactive_color: Option<Color>, |
| 1203 | } | 1251 | } |
| 1204 | 1252 | ||
| 1253 | +#[derive(knuffel::Decode, Debug, Default, Clone, Copy, PartialEq)] | ||
| 1254 | +pub struct TabIndicatorRule { | ||
| 1255 | + #[knuffel(child)] | ||
| 1256 | + pub active_color: Option<Color>, | ||
| 1257 | + #[knuffel(child)] | ||
| 1258 | + pub inactive_color: Option<Color>, | ||
| 1259 | + #[knuffel(child)] | ||
| 1260 | + pub active_gradient: Option<Gradient>, | ||
| 1261 | + #[knuffel(child)] | ||
| 1262 | + pub inactive_gradient: Option<Gradient>, | ||
| 1263 | +} | ||
| 1264 | + | ||
| 1205 | #[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)] | 1265 | #[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)] |
| 1206 | pub struct FloatingPosition { | 1266 | pub struct FloatingPosition { |
| 1207 | #[knuffel(property)] | 1267 | #[knuffel(property)] |
| @@ -2039,6 +2099,23 @@ impl ShadowRule { | |||
| 2039 | } | 2099 | } |
| 2040 | } | 2100 | } |
| 2041 | 2101 | ||
| 2102 | +impl TabIndicatorRule { | ||
| 2103 | + pub fn merge_with(&mut self, other: &Self) { | ||
| 2104 | + if let Some(x) = other.active_color { | ||
| 2105 | + self.active_color = Some(x); | ||
| 2106 | + } | ||
| 2107 | + if let Some(x) = other.inactive_color { | ||
| 2108 | + self.inactive_color = Some(x); | ||
| 2109 | + } | ||
| 2110 | + if let Some(x) = other.active_gradient { | ||
| 2111 | + self.active_gradient = Some(x); | ||
| 2112 | + } | ||
| 2113 | + if let Some(x) = other.inactive_gradient { | ||
| 2114 | + self.inactive_gradient = Some(x); | ||
| 2115 | + } | ||
| 2116 | + } | ||
| 2117 | +} | ||
| 2118 | + | ||
| 2042 | impl CornerRadius { | 2119 | impl CornerRadius { |
| 2043 | pub fn fit_to(self, width: f32, height: f32) -> Self { | 2120 | pub fn fit_to(self, width: f32, height: f32) -> Self { |
| 2044 | // Like in CSS: https://drafts.csswg.org/css-backgrounds/#corner-overlap | 2121 | // Like in CSS: https://drafts.csswg.org/css-backgrounds/#corner-overlap |
| @@ -3473,6 +3550,10 @@ mod tests { | |||
| 3473 | offset x=10 y=-20 | 3550 | offset x=10 y=-20 |
| 3474 | } | 3551 | } |
| 3475 | 3552 | ||
| 3553 | + tab-indicator { | ||
| 3554 | + width 10 | ||
| 3555 | + } | ||
| 3556 | + | ||
| 3476 | preset-column-widths { | 3557 | preset-column-widths { |
| 3477 | proportion 0.25 | 3558 | proportion 0.25 |
| 3478 | proportion 0.5 | 3559 | proportion 0.5 |
| @@ -3571,6 +3652,10 @@ mod tests { | |||
| 3571 | on | 3652 | on |
| 3572 | width 8.5 | 3653 | width 8.5 |
| 3573 | } | 3654 | } |
| 3655 | + | ||
| 3656 | + tab-indicator { | ||
| 3657 | + active-color "#f00" | ||
| 3658 | + } | ||
| 3574 | } | 3659 | } |
| 3575 | 3660 | ||
| 3576 | layer-rule { | 3661 | layer-rule { |
| @@ -3729,6 +3814,10 @@ mod tests { | |||
| 3729 | }, | 3814 | }, |
| 3730 | ..Default::default() | 3815 | ..Default::default() |
| 3731 | }, | 3816 | }, |
| 3817 | + tab_indicator: TabIndicator { | ||
| 3818 | + width: FloatOrInt(10.), | ||
| 3819 | + ..Default::default() | ||
| 3820 | + }, | ||
| 3732 | insert_hint: InsertHint { | 3821 | insert_hint: InsertHint { |
| 3733 | off: false, | 3822 | off: false, |
| 3734 | color: Color::from_rgba8_unpremul(255, 200, 127, 255), | 3823 | color: Color::from_rgba8_unpremul(255, 200, 127, 255), |
| @@ -3875,6 +3964,10 @@ mod tests { | |||
| 3875 | width: Some(FloatOrInt(8.5)), | 3964 | width: Some(FloatOrInt(8.5)), |
| 3876 | ..Default::default() | 3965 | ..Default::default() |
| 3877 | }, | 3966 | }, |
| 3967 | + tab_indicator: TabIndicatorRule { | ||
| 3968 | + active_color: Some(Color::from_rgba8_unpremul(255, 0, 0, 255)), | ||
| 3969 | + ..Default::default() | ||
| 3970 | + }, | ||
| 3878 | ..Default::default() | 3971 | ..Default::default() |
| 3879 | }], | 3972 | }], |
| 3880 | layer_rules: vec![ | 3973 | layer_rules: vec![ |
src/layout/focus_ring.rsmodified+4 -0
| @@ -262,4 +262,8 @@ impl FocusRing { | |||
| 262 | pub fn is_off(&self) -> bool { | 262 | pub fn is_off(&self) -> bool { |
| 263 | self.config.off | 263 | self.config.off |
| 264 | } | 264 | } |
| 265 | + | ||
| 266 | + pub fn config(&self) -> &niri_config::FocusRing { | ||
| 267 | + &self.config | ||
| 268 | + } | ||
| 265 | } | 269 | } |
src/layout/mod.rsmodified+4 -0
| @@ -80,6 +80,7 @@ pub mod monitor; | |||
| 80 | pub mod opening_window; | 80 | pub mod opening_window; |
| 81 | pub mod scrolling; | 81 | pub mod scrolling; |
| 82 | pub mod shadow; | 82 | pub mod shadow; |
| 83 | +pub mod tab_indicator; | ||
| 83 | pub mod tile; | 84 | pub mod tile; |
| 84 | pub mod workspace; | 85 | pub mod workspace; |
| 85 | 86 | ||
| @@ -312,6 +313,7 @@ pub struct Options { | |||
| 312 | pub focus_ring: niri_config::FocusRing, | 313 | pub focus_ring: niri_config::FocusRing, |
| 313 | pub border: niri_config::Border, | 314 | pub border: niri_config::Border, |
| 314 | pub shadow: niri_config::Shadow, | 315 | pub shadow: niri_config::Shadow, |
| 316 | + pub tab_indicator: niri_config::TabIndicator, | ||
| 315 | pub insert_hint: niri_config::InsertHint, | 317 | pub insert_hint: niri_config::InsertHint, |
| 316 | pub center_focused_column: CenterFocusedColumn, | 318 | pub center_focused_column: CenterFocusedColumn, |
| 317 | pub always_center_single_column: bool, | 319 | pub always_center_single_column: bool, |
| @@ -337,6 +339,7 @@ impl Default for Options { | |||
| 337 | focus_ring: Default::default(), | 339 | focus_ring: Default::default(), |
| 338 | border: Default::default(), | 340 | border: Default::default(), |
| 339 | shadow: Default::default(), | 341 | shadow: Default::default(), |
| 342 | + tab_indicator: Default::default(), | ||
| 340 | insert_hint: Default::default(), | 343 | insert_hint: Default::default(), |
| 341 | center_focused_column: Default::default(), | 344 | center_focused_column: Default::default(), |
| 342 | always_center_single_column: false, | 345 | always_center_single_column: false, |
| @@ -550,6 +553,7 @@ impl Options { | |||
| 550 | focus_ring: layout.focus_ring, | 553 | focus_ring: layout.focus_ring, |
| 551 | border: layout.border, | 554 | border: layout.border, |
| 552 | shadow: layout.shadow, | 555 | shadow: layout.shadow, |
| 556 | + tab_indicator: layout.tab_indicator, | ||
| 553 | insert_hint: layout.insert_hint, | 557 | insert_hint: layout.insert_hint, |
| 554 | center_focused_column: layout.center_focused_column, | 558 | center_focused_column: layout.center_focused_column, |
| 555 | always_center_single_column: layout.always_center_single_column, | 559 | always_center_single_column: layout.always_center_single_column, |
src/layout/scrolling.rsmodified+67 -10
| @@ -11,6 +11,7 @@ use smithay::utils::{Logical, Point, Rectangle, Scale, Serial, Size}; | |||
| 11 | 11 | ||
| 12 | use super::closing_window::{ClosingWindow, ClosingWindowRenderElement}; | 12 | use super::closing_window::{ClosingWindow, ClosingWindowRenderElement}; |
| 13 | use super::insert_hint_element::{InsertHintElement, InsertHintRenderElement}; | 13 | use super::insert_hint_element::{InsertHintElement, InsertHintRenderElement}; |
| 14 | +use super::tab_indicator::{TabIndicator, TabIndicatorRenderElement, TabInfo}; | ||
| 14 | use super::tile::{Tile, TileRenderElement, TileRenderSnapshot}; | 15 | use super::tile::{Tile, TileRenderElement, TileRenderSnapshot}; |
| 15 | use super::workspace::{InteractiveResize, ResolvedSize}; | 16 | use super::workspace::{InteractiveResize, ResolvedSize}; |
| 16 | use super::{ConfigureIntent, InteractiveResizeData, LayoutElement, Options, RemovedTile}; | 17 | use super::{ConfigureIntent, InteractiveResizeData, LayoutElement, Options, RemovedTile}; |
| @@ -94,6 +95,7 @@ niri_render_elements! { | |||
| 94 | ScrollingSpaceRenderElement<R> => { | 95 | ScrollingSpaceRenderElement<R> => { |
| 95 | Tile = TileRenderElement<R>, | 96 | Tile = TileRenderElement<R>, |
| 96 | ClosingWindow = ClosingWindowRenderElement, | 97 | ClosingWindow = ClosingWindowRenderElement, |
| 98 | + TabIndicator = TabIndicatorRenderElement, | ||
| 97 | InsertHint = InsertHintRenderElement, | 99 | InsertHint = InsertHintRenderElement, |
| 98 | } | 100 | } |
| 99 | } | 101 | } |
| @@ -174,6 +176,9 @@ pub struct Column<W: LayoutElement> { | |||
| 174 | /// How this column displays and arranges windows. | 176 | /// How this column displays and arranges windows. |
| 175 | display_mode: ColumnDisplay, | 177 | display_mode: ColumnDisplay, |
| 176 | 178 | ||
| 179 | + /// Tab indicator for the tabbed display mode. | ||
| 180 | + tab_indicator: TabIndicator, | ||
| 181 | + | ||
| 177 | /// Animation of the render offset during window swapping. | 182 | /// Animation of the render offset during window swapping. |
| 178 | move_animation: Option<Animation>, | 183 | move_animation: Option<Animation>, |
| 179 | 184 | ||
| @@ -2527,19 +2532,44 @@ impl<W: LayoutElement> ScrollingSpace<W> { | |||
| 2527 | } | 2532 | } |
| 2528 | 2533 | ||
| 2529 | let mut first = true; | 2534 | let mut first = true; |
| 2530 | - for (tile, tile_pos, visible) in self.tiles_with_render_positions() { | ||
| 2531 | - // For the active tile (which comes first), draw the focus ring. | ||
| 2532 | - let focus_ring = focus_ring && first; | ||
| 2533 | - first = false; | ||
| 2534 | 2535 | ||
| 2535 | - if !visible { | 2536 | + // This matches self.tiles_in_render_order(). |
| 2536 | - continue; | 2537 | + let view_off = Point::from((-self.view_pos(), 0.)); |
| 2538 | + for (col, col_x) in self.columns_in_render_order() { | ||
| 2539 | + let col_off = Point::from((col_x, 0.)); | ||
| 2540 | + let col_render_off = col.render_offset(); | ||
| 2541 | + | ||
| 2542 | + // Draw the tab indicator on top. | ||
| 2543 | + { | ||
| 2544 | + // This is the "static tile position" so to say: it excludes the tile offset (used | ||
| 2545 | + // for e.g. centering smaller tiles in always-center) and the tile render offset | ||
| 2546 | + // (used for tile-specific animations). | ||
| 2547 | + let pos = view_off + col_off + col_render_off + col.tiles_origin(); | ||
| 2548 | + let pos = pos.to_physical_precise_round(scale).to_logical(scale); | ||
| 2549 | + rv.extend(col.tab_indicator.render(renderer, pos).map(Into::into)); | ||
| 2537 | } | 2550 | } |
| 2538 | 2551 | ||
| 2539 | - rv.extend( | 2552 | + for (tile, tile_off, visible) in col.tiles_in_render_order() { |
| 2540 | - tile.render(renderer, tile_pos, scale, focus_ring, target) | 2553 | + let tile_pos = |
| 2541 | - .map(Into::into), | 2554 | + view_off + col_off + col_render_off + tile_off + tile.render_offset(); |
| 2542 | - ); | 2555 | + // Round to physical pixels. |
| 2556 | + let tile_pos = tile_pos.to_physical_precise_round(scale).to_logical(scale); | ||
| 2557 | + | ||
| 2558 | + // And now the drawing logic. | ||
| 2559 | + | ||
| 2560 | + // For the active tile (which comes first), draw the focus ring. | ||
| 2561 | + let focus_ring = focus_ring && first; | ||
| 2562 | + first = false; | ||
| 2563 | + | ||
| 2564 | + if !visible { | ||
| 2565 | + continue; | ||
| 2566 | + } | ||
| 2567 | + | ||
| 2568 | + rv.extend( | ||
| 2569 | + tile.render(renderer, tile_pos, scale, focus_ring, target) | ||
| 2570 | + .map(Into::into), | ||
| 2571 | + ); | ||
| 2572 | + } | ||
| 2543 | } | 2573 | } |
| 2544 | 2574 | ||
| 2545 | rv | 2575 | rv |
| @@ -3268,6 +3298,7 @@ impl<W: LayoutElement> Column<W> { | |||
| 3268 | is_full_width, | 3298 | is_full_width, |
| 3269 | is_fullscreen: false, | 3299 | is_fullscreen: false, |
| 3270 | display_mode, | 3300 | display_mode, |
| 3301 | + tab_indicator: TabIndicator::new(options.tab_indicator), | ||
| 3271 | move_animation: None, | 3302 | move_animation: None, |
| 3272 | view_size, | 3303 | view_size, |
| 3273 | working_area, | 3304 | working_area, |
| @@ -3326,6 +3357,7 @@ impl<W: LayoutElement> Column<W> { | |||
| 3326 | data.update(tile); | 3357 | data.update(tile); |
| 3327 | } | 3358 | } |
| 3328 | 3359 | ||
| 3360 | + self.tab_indicator.update_config(options.tab_indicator); | ||
| 3329 | self.view_size = view_size; | 3361 | self.view_size = view_size; |
| 3330 | self.working_area = working_area; | 3362 | self.working_area = working_area; |
| 3331 | self.scale = scale; | 3363 | self.scale = scale; |
| @@ -3361,6 +3393,31 @@ impl<W: LayoutElement> Column<W> { | |||
| 3361 | tile_view_rect.loc -= tile_off + tile.render_offset(); | 3393 | tile_view_rect.loc -= tile_off + tile.render_offset(); |
| 3362 | tile.update_render_elements(is_active, tile_view_rect); | 3394 | tile.update_render_elements(is_active, tile_view_rect); |
| 3363 | } | 3395 | } |
| 3396 | + | ||
| 3397 | + let (tile, tile_off) = self.tiles().nth(self.active_tile_idx).unwrap(); | ||
| 3398 | + let mut tile_view_rect = view_rect; | ||
| 3399 | + tile_view_rect.loc -= tile_off + tile.render_offset(); | ||
| 3400 | + | ||
| 3401 | + let config = self.tab_indicator.config(); | ||
| 3402 | + let tabs = self.tiles.iter().enumerate().map(|(tile_idx, tile)| { | ||
| 3403 | + let is_active = tile_idx == active_idx; | ||
| 3404 | + TabInfo::from_tile(tile, is_active, &config) | ||
| 3405 | + }); | ||
| 3406 | + | ||
| 3407 | + // Hide the tab indicator in fullscreen. If you have it configured to overlap the window, | ||
| 3408 | + // you don't want that to happen in fullscreen. Also, laying things out correctly when the | ||
| 3409 | + // tab indicator is within the column and the column goes fullscreen, would require too | ||
| 3410 | + // many changes to the code for too little benefit (it's mostly invisible anyway). | ||
| 3411 | + let enabled = self.display_mode == ColumnDisplay::Tabbed && !self.is_fullscreen; | ||
| 3412 | + | ||
| 3413 | + self.tab_indicator.update_render_elements( | ||
| 3414 | + enabled, | ||
| 3415 | + tile.animated_tile_size(), | ||
| 3416 | + tile_view_rect, | ||
| 3417 | + tabs, | ||
| 3418 | + is_active, | ||
| 3419 | + self.scale, | ||
| 3420 | + ); | ||
| 3364 | } | 3421 | } |
| 3365 | 3422 | ||
| 3366 | pub fn render_offset(&self) -> Point<f64, Logical> { | 3423 | pub fn render_offset(&self) -> Point<f64, Logical> { |
src/layout/tab_indicator.rsadded+201 -0
| @@ -0,0 +1,201 @@ | |||
| 1 | +use std::iter::zip; | ||
| 2 | + | ||
| 3 | +use niri_config::{CornerRadius, Gradient, GradientRelativeTo}; | ||
| 4 | +use smithay::utils::{Logical, Point, Rectangle, Size}; | ||
| 5 | + | ||
| 6 | +use super::tile::Tile; | ||
| 7 | +use super::LayoutElement; | ||
| 8 | +use crate::niri_render_elements; | ||
| 9 | +use crate::render_helpers::border::BorderRenderElement; | ||
| 10 | +use crate::render_helpers::renderer::NiriRenderer; | ||
| 11 | +use crate::utils::{floor_logical_in_physical_max1, round_logical_in_physical}; | ||
| 12 | + | ||
| 13 | +#[derive(Debug)] | ||
| 14 | +pub struct TabIndicator { | ||
| 15 | + shader_locs: Vec<Point<f64, Logical>>, | ||
| 16 | + shaders: Vec<BorderRenderElement>, | ||
| 17 | + config: niri_config::TabIndicator, | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +#[derive(Debug)] | ||
| 21 | +pub struct TabInfo { | ||
| 22 | + pub gradient: Gradient, | ||
| 23 | +} | ||
| 24 | + | ||
| 25 | +niri_render_elements! { | ||
| 26 | + TabIndicatorRenderElement => { | ||
| 27 | + Gradient = BorderRenderElement, | ||
| 28 | + } | ||
| 29 | +} | ||
| 30 | + | ||
| 31 | +impl TabIndicator { | ||
| 32 | + pub fn new(config: niri_config::TabIndicator) -> Self { | ||
| 33 | + Self { | ||
| 34 | + shader_locs: Vec::new(), | ||
| 35 | + shaders: Vec::new(), | ||
| 36 | + config, | ||
| 37 | + } | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + pub fn update_config(&mut self, config: niri_config::TabIndicator) { | ||
| 41 | + self.config = config; | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + pub fn update_shaders(&mut self) { | ||
| 45 | + for elem in &mut self.shaders { | ||
| 46 | + elem.damage_all(); | ||
| 47 | + } | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + pub fn update_render_elements( | ||
| 51 | + &mut self, | ||
| 52 | + enabled: bool, | ||
| 53 | + tile_size: Size<f64, Logical>, | ||
| 54 | + tile_view_rect: Rectangle<f64, Logical>, | ||
| 55 | + tabs: impl Iterator<Item = TabInfo> + Clone, | ||
| 56 | + // TODO: do we indicate inactive-but-selected somehow? | ||
| 57 | + _is_active: bool, | ||
| 58 | + scale: f64, | ||
| 59 | + ) { | ||
| 60 | + if !enabled || self.config.off { | ||
| 61 | + self.shader_locs.clear(); | ||
| 62 | + self.shaders.clear(); | ||
| 63 | + return; | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + // Tab indicators are rendered relative to the tile geometry. | ||
| 67 | + let tile_geo = Rectangle::new(Point::from((0., 0.)), tile_size); | ||
| 68 | + | ||
| 69 | + let round = |logical: f64| round_logical_in_physical(scale, logical); | ||
| 70 | + | ||
| 71 | + let width = round(self.config.width.0); | ||
| 72 | + let gap = round(self.config.gap.0); | ||
| 73 | + | ||
| 74 | + let total_prop = self.config.length.total_proportion.unwrap_or(0.5); | ||
| 75 | + let min_length = round(tile_size.h * total_prop.clamp(0., 2.)); | ||
| 76 | + | ||
| 77 | + let count = tabs.clone().count(); | ||
| 78 | + self.shaders.resize_with(count, Default::default); | ||
| 79 | + self.shader_locs.resize_with(count, Default::default); | ||
| 80 | + | ||
| 81 | + let pixel = 1. / scale; | ||
| 82 | + let shortest_length = count as f64 * pixel; | ||
| 83 | + let length = f64::max(min_length, shortest_length); | ||
| 84 | + let px_per_tab = length / count as f64; | ||
| 85 | + let px_per_tab = floor_logical_in_physical_max1(scale, px_per_tab); | ||
| 86 | + let floored_length = count as f64 * px_per_tab; | ||
| 87 | + let mut ones_left = ((length - floored_length) / pixel).max(0.).round() as usize; | ||
| 88 | + | ||
| 89 | + let mut shader_loc = Point::from((-gap - width, round((tile_size.h - length) / 2.))); | ||
| 90 | + | ||
| 91 | + for ((shader, loc), tab) in zip(&mut self.shaders, &mut self.shader_locs).zip(tabs) { | ||
| 92 | + *loc = shader_loc; | ||
| 93 | + | ||
| 94 | + let mut px_per_tab = px_per_tab; | ||
| 95 | + if ones_left > 0 { | ||
| 96 | + ones_left -= 1; | ||
| 97 | + px_per_tab += pixel; | ||
| 98 | + } | ||
| 99 | + shader_loc.y += px_per_tab; | ||
| 100 | + | ||
| 101 | + let shader_size = Size::from((width, px_per_tab)); | ||
| 102 | + | ||
| 103 | + let mut gradient_area = match tab.gradient.relative_to { | ||
| 104 | + GradientRelativeTo::Window => tile_geo, | ||
| 105 | + GradientRelativeTo::WorkspaceView => tile_view_rect, | ||
| 106 | + }; | ||
| 107 | + gradient_area.loc -= *loc; | ||
| 108 | + | ||
| 109 | + shader.update( | ||
| 110 | + shader_size, | ||
| 111 | + gradient_area, | ||
| 112 | + tab.gradient.in_, | ||
| 113 | + tab.gradient.from, | ||
| 114 | + tab.gradient.to, | ||
| 115 | + ((tab.gradient.angle as f32) - 90.).to_radians(), | ||
| 116 | + Rectangle::from_size(shader_size), | ||
| 117 | + 0., | ||
| 118 | + CornerRadius::default(), | ||
| 119 | + scale as f32, | ||
| 120 | + 1., | ||
| 121 | + ); | ||
| 122 | + } | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + pub fn render( | ||
| 126 | + &self, | ||
| 127 | + renderer: &mut impl NiriRenderer, | ||
| 128 | + tile_pos: Point<f64, Logical>, | ||
| 129 | + ) -> impl Iterator<Item = TabIndicatorRenderElement> + '_ { | ||
| 130 | + let has_border_shader = BorderRenderElement::has_shader(renderer); | ||
| 131 | + if !has_border_shader { | ||
| 132 | + return None.into_iter().flatten(); | ||
| 133 | + } | ||
| 134 | + | ||
| 135 | + let rv = zip(&self.shaders, &self.shader_locs) | ||
| 136 | + .map(move |(shader, loc)| shader.clone().with_location(tile_pos + *loc)) | ||
| 137 | + .map(TabIndicatorRenderElement::from); | ||
| 138 | + | ||
| 139 | + Some(rv).into_iter().flatten() | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + pub fn config(&self) -> niri_config::TabIndicator { | ||
| 143 | + self.config | ||
| 144 | + } | ||
| 145 | +} | ||
| 146 | + | ||
| 147 | +impl TabInfo { | ||
| 148 | + pub fn from_tile<W: LayoutElement>( | ||
| 149 | + tile: &Tile<W>, | ||
| 150 | + is_active: bool, | ||
| 151 | + config: &niri_config::TabIndicator, | ||
| 152 | + ) -> Self { | ||
| 153 | + let rules = tile.window().rules(); | ||
| 154 | + let rule = rules.tab_indicator; | ||
| 155 | + | ||
| 156 | + let gradient_from_rule = || { | ||
| 157 | + let (color, gradient) = if is_active { | ||
| 158 | + (rule.active_color, rule.active_gradient) | ||
| 159 | + } else { | ||
| 160 | + (rule.inactive_color, rule.inactive_gradient) | ||
| 161 | + }; | ||
| 162 | + let color = color.map(Gradient::from); | ||
| 163 | + gradient.or(color) | ||
| 164 | + }; | ||
| 165 | + | ||
| 166 | + let gradient_from_config = || { | ||
| 167 | + let (color, gradient) = if is_active { | ||
| 168 | + (config.active_color, config.active_gradient) | ||
| 169 | + } else { | ||
| 170 | + (config.inactive_color, config.inactive_gradient) | ||
| 171 | + }; | ||
| 172 | + let color = color.map(Gradient::from); | ||
| 173 | + gradient.or(color) | ||
| 174 | + }; | ||
| 175 | + | ||
| 176 | + let gradient_from_border = || { | ||
| 177 | + // Come up with tab indicator gradient matching the focus ring or the border, whichever | ||
| 178 | + // one is enabled. | ||
| 179 | + let focus_ring_config = tile.focus_ring().config(); | ||
| 180 | + let border_config = tile.border().config(); | ||
| 181 | + let config = if focus_ring_config.off { | ||
| 182 | + border_config | ||
| 183 | + } else { | ||
| 184 | + focus_ring_config | ||
| 185 | + }; | ||
| 186 | + | ||
| 187 | + let (color, gradient) = if is_active { | ||
| 188 | + (config.active_color, config.active_gradient) | ||
| 189 | + } else { | ||
| 190 | + (config.inactive_color, config.inactive_gradient) | ||
| 191 | + }; | ||
| 192 | + gradient.unwrap_or_else(|| Gradient::from(color)) | ||
| 193 | + }; | ||
| 194 | + | ||
| 195 | + let gradient = gradient_from_rule() | ||
| 196 | + .or_else(gradient_from_config) | ||
| 197 | + .unwrap_or_else(gradient_from_border); | ||
| 198 | + | ||
| 199 | + TabInfo { gradient } | ||
| 200 | + } | ||
| 201 | +} | ||
src/layout/tests.rsmodified+20 -1
| @@ -1,6 +1,6 @@ | |||
| 1 | use std::cell::Cell; | 1 | use std::cell::Cell; |
| 2 | 2 | ||
| 3 | -use niri_config::{FloatOrInt, OutputName, WorkspaceName, WorkspaceReference}; | 3 | +use niri_config::{FloatOrInt, OutputName, TabIndicatorLength, WorkspaceName, WorkspaceReference}; |
| 4 | use proptest::prelude::*; | 4 | use proptest::prelude::*; |
| 5 | use proptest_derive::Arbitrary; | 5 | use proptest_derive::Arbitrary; |
| 6 | use smithay::output::{Mode, PhysicalProperties, Subpixel}; | 6 | use smithay::output::{Mode, PhysicalProperties, Subpixel}; |
| @@ -3239,6 +3239,23 @@ prop_compose! { | |||
| 3239 | } | 3239 | } |
| 3240 | } | 3240 | } |
| 3241 | 3241 | ||
| 3242 | +prop_compose! { | ||
| 3243 | + fn arbitrary_tab_indicator()( | ||
| 3244 | + off in any::<bool>(), | ||
| 3245 | + width in arbitrary_spacing(), | ||
| 3246 | + gap in arbitrary_spacing_neg(), | ||
| 3247 | + length in (0f64..2f64), | ||
| 3248 | + ) -> niri_config::TabIndicator { | ||
| 3249 | + niri_config::TabIndicator { | ||
| 3250 | + off, | ||
| 3251 | + width: FloatOrInt(width), | ||
| 3252 | + gap: FloatOrInt(gap), | ||
| 3253 | + length: TabIndicatorLength { total_proportion: Some(length) }, | ||
| 3254 | + ..Default::default() | ||
| 3255 | + } | ||
| 3256 | + } | ||
| 3257 | +} | ||
| 3258 | + | ||
| 3242 | prop_compose! { | 3259 | prop_compose! { |
| 3243 | fn arbitrary_options()( | 3260 | fn arbitrary_options()( |
| 3244 | gaps in arbitrary_spacing(), | 3261 | gaps in arbitrary_spacing(), |
| @@ -3246,6 +3263,7 @@ prop_compose! { | |||
| 3246 | focus_ring in arbitrary_focus_ring(), | 3263 | focus_ring in arbitrary_focus_ring(), |
| 3247 | border in arbitrary_border(), | 3264 | border in arbitrary_border(), |
| 3248 | shadow in arbitrary_shadow(), | 3265 | shadow in arbitrary_shadow(), |
| 3266 | + tab_indicator in arbitrary_tab_indicator(), | ||
| 3249 | center_focused_column in arbitrary_center_focused_column(), | 3267 | center_focused_column in arbitrary_center_focused_column(), |
| 3250 | always_center_single_column in any::<bool>(), | 3268 | always_center_single_column in any::<bool>(), |
| 3251 | empty_workspace_above_first in any::<bool>(), | 3269 | empty_workspace_above_first in any::<bool>(), |
| @@ -3259,6 +3277,7 @@ prop_compose! { | |||
| 3259 | focus_ring, | 3277 | focus_ring, |
| 3260 | border, | 3278 | border, |
| 3261 | shadow, | 3279 | shadow, |
| 3280 | + tab_indicator, | ||
| 3262 | ..Default::default() | 3281 | ..Default::default() |
| 3263 | } | 3282 | } |
| 3264 | } | 3283 | } |
src/layout/tile.rsmodified+10 -2
| @@ -563,7 +563,7 @@ impl<W: LayoutElement> Tile<W> { | |||
| 563 | size | 563 | size |
| 564 | } | 564 | } |
| 565 | 565 | ||
| 566 | - fn animated_window_size(&self) -> Size<f64, Logical> { | 566 | + pub fn animated_window_size(&self) -> Size<f64, Logical> { |
| 567 | let mut size = self.window_size(); | 567 | let mut size = self.window_size(); |
| 568 | 568 | ||
| 569 | if let Some(resize) = &self.resize_animation { | 569 | if let Some(resize) = &self.resize_animation { |
| @@ -580,7 +580,7 @@ impl<W: LayoutElement> Tile<W> { | |||
| 580 | size | 580 | size |
| 581 | } | 581 | } |
| 582 | 582 | ||
| 583 | - fn animated_tile_size(&self) -> Size<f64, Logical> { | 583 | + pub fn animated_tile_size(&self) -> Size<f64, Logical> { |
| 584 | let mut size = self.animated_window_size(); | 584 | let mut size = self.animated_window_size(); |
| 585 | 585 | ||
| 586 | if self.is_fullscreen { | 586 | if self.is_fullscreen { |
| @@ -1031,6 +1031,14 @@ impl<W: LayoutElement> Tile<W> { | |||
| 1031 | self.unmap_snapshot.take() | 1031 | self.unmap_snapshot.take() |
| 1032 | } | 1032 | } |
| 1033 | 1033 | ||
| 1034 | + pub fn border(&self) -> &FocusRing { | ||
| 1035 | + &self.border | ||
| 1036 | + } | ||
| 1037 | + | ||
| 1038 | + pub fn focus_ring(&self) -> &FocusRing { | ||
| 1039 | + &self.focus_ring | ||
| 1040 | + } | ||
| 1041 | + | ||
| 1034 | pub fn options(&self) -> &Rc<Options> { | 1042 | pub fn options(&self) -> &Rc<Options> { |
| 1035 | &self.options | 1043 | &self.options |
| 1036 | } | 1044 | } |
src/utils/mod.rsmodified+8 -0
| @@ -127,6 +127,14 @@ pub fn round_logical_in_physical_max1(scale: f64, logical: f64) -> f64 { | |||
| 127 | (logical * scale).max(1.).round() / scale | 127 | (logical * scale).max(1.).round() / scale |
| 128 | } | 128 | } |
| 129 | 129 | ||
| 130 | +pub fn floor_logical_in_physical_max1(scale: f64, logical: f64) -> f64 { | ||
| 131 | + if logical == 0. { | ||
| 132 | + return 0.; | ||
| 133 | + } | ||
| 134 | + | ||
| 135 | + (logical * scale).max(1.).floor() / scale | ||
| 136 | +} | ||
| 137 | + | ||
| 130 | pub fn output_size(output: &Output) -> Size<f64, Logical> { | 138 | pub fn output_size(output: &Output) -> Size<f64, Logical> { |
| 131 | let output_scale = output.current_scale().fractional_scale(); | 139 | let output_scale = output.current_scale().fractional_scale(); |
| 132 | let output_transform = output.current_transform(); | 140 | let output_transform = output.current_transform(); |
src/window/mod.rsmodified+10 -1
| @@ -2,7 +2,7 @@ use std::cmp::{max, min}; | |||
| 2 | 2 | ||
| 3 | use niri_config::{ | 3 | use niri_config::{ |
| 4 | BlockOutFrom, BorderRule, CornerRadius, FloatingPosition, Match, PresetSize, ShadowRule, | 4 | BlockOutFrom, BorderRule, CornerRadius, FloatingPosition, Match, PresetSize, ShadowRule, |
| 5 | - WindowRule, | 5 | + TabIndicatorRule, WindowRule, |
| 6 | }; | 6 | }; |
| 7 | use niri_ipc::ColumnDisplay; | 7 | use niri_ipc::ColumnDisplay; |
| 8 | use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel; | 8 | use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel; |
| @@ -83,6 +83,8 @@ pub struct ResolvedWindowRules { | |||
| 83 | pub border: BorderRule, | 83 | pub border: BorderRule, |
| 84 | /// Shadow overrides. | 84 | /// Shadow overrides. |
| 85 | pub shadow: ShadowRule, | 85 | pub shadow: ShadowRule, |
| 86 | + /// Tab indicator overrides. | ||
| 87 | + pub tab_indicator: TabIndicatorRule, | ||
| 86 | 88 | ||
| 87 | /// Whether or not to draw the border with a solid background. | 89 | /// Whether or not to draw the border with a solid background. |
| 88 | /// | 90 | /// |
| @@ -191,6 +193,12 @@ impl ResolvedWindowRules { | |||
| 191 | color: None, | 193 | color: None, |
| 192 | inactive_color: None, | 194 | inactive_color: None, |
| 193 | }, | 195 | }, |
| 196 | + tab_indicator: TabIndicatorRule { | ||
| 197 | + active_color: None, | ||
| 198 | + inactive_color: None, | ||
| 199 | + active_gradient: None, | ||
| 200 | + inactive_gradient: None, | ||
| 201 | + }, | ||
| 194 | draw_border_with_background: None, | 202 | draw_border_with_background: None, |
| 195 | opacity: None, | 203 | opacity: None, |
| 196 | geometry_corner_radius: None, | 204 | geometry_corner_radius: None, |
| @@ -290,6 +298,7 @@ impl ResolvedWindowRules { | |||
| 290 | resolved.focus_ring.merge_with(&rule.focus_ring); | 298 | resolved.focus_ring.merge_with(&rule.focus_ring); |
| 291 | resolved.border.merge_with(&rule.border); | 299 | resolved.border.merge_with(&rule.border); |
| 292 | resolved.shadow.merge_with(&rule.shadow); | 300 | resolved.shadow.merge_with(&rule.shadow); |
| 301 | + resolved.tab_indicator.merge_with(&rule.tab_indicator); | ||
| 293 | 302 | ||
| 294 | if let Some(x) = rule.draw_border_with_background { | 303 | if let Some(x) = rule.draw_border_with_background { |
| 295 | resolved.draw_border_with_background = Some(x); | 304 | resolved.draw_border_with_background = Some(x); |