forge
Explore
Log in

Don't you dare go Hollow

Add gradient support for the insert hint

Browse files at this commit

05d218113c1209f58b0dcdd415f1e095d4ff2b46Ivan MolodetskikhParent: ef6af6a
Implement it via FocusRing which already handles SolidColor vs. Border
render element.
niri-config/src/lib.rsmodified+14 -0
@@ -597,6 +597,8 @@ pub struct InsertHint {
597 pub off: bool,597 pub off: bool,
598 #[knuffel(child, default = Self::default().color)]598 #[knuffel(child, default = Self::default().color)]
599 pub color: Color,599 pub color: Color,
600+ #[knuffel(child)]
601+ pub gradient: Option<Gradient>,
600 }602 }
601 603
602 impl Default for InsertHint {604 impl Default for InsertHint {
@@ -604,6 +606,7 @@ impl Default for InsertHint {
604 Self {606 Self {
605 off: false,607 off: false,
606 color: Color::from_rgba8_unpremul(127, 200, 255, 128),608 color: Color::from_rgba8_unpremul(127, 200, 255, 128),
609+ gradient: None,
607 }610 }
608 }611 }
609 }612 }
@@ -3051,6 +3054,7 @@ mod tests {
3051 3054
3052 insert-hint {3055 insert-hint {
3053 color "rgb(255, 200, 127)"3056 color "rgb(255, 200, 127)"
3057+ gradient from="rgba(10, 20, 30, 1.0)" to="#0080ffff" relative-to="workspace-view"
3054 }3058 }
3055 }3059 }
3056 3060
@@ -3253,6 +3257,16 @@ mod tests {
3253 insert_hint: InsertHint {3257 insert_hint: InsertHint {
3254 off: false,3258 off: false,
3255 color: Color::from_rgba8_unpremul(255, 200, 127, 255),3259 color: Color::from_rgba8_unpremul(255, 200, 127, 255),
3260+ gradient: Some(Gradient {
3261+ from: Color::from_rgba8_unpremul(10, 20, 30, 255),
3262+ to: Color::from_rgba8_unpremul(0, 128, 255, 255),
3263+ angle: 180,
3264+ relative_to: GradientRelativeTo::WorkspaceView,
3265+ in_: GradientInterpolation {
3266+ color_space: GradientColorSpace::Srgb,
3267+ hue_interpolation: HueInterpolation::Shorter,
3268+ },
3269+ }),
3256 },3270 },
3257 preset_column_widths: vec![3271 preset_column_widths: vec![
3258 PresetSize::Proportion(0.25),3272 PresetSize::Proportion(0.25),
src/layout/insert_hint_element.rsadded+61 -0
@@ -0,0 +1,61 @@
1+use niri_config::{CornerRadius, FloatOrInt};
2+use smithay::utils::{Logical, Point, Rectangle, Size};
3+
4+use super::focus_ring::{FocusRing, FocusRingRenderElement};
5+use crate::render_helpers::renderer::NiriRenderer;
6+
7+#[derive(Debug)]
8+pub struct InsertHintElement {
9+ inner: FocusRing,
10+}
11+
12+pub type InsertHintRenderElement = FocusRingRenderElement;
13+
14+impl InsertHintElement {
15+ pub fn new(config: niri_config::InsertHint) -> Self {
16+ Self {
17+ inner: FocusRing::new(niri_config::FocusRing {
18+ off: config.off,
19+ width: FloatOrInt(0.),
20+ active_color: config.color,
21+ inactive_color: config.color,
22+ active_gradient: config.gradient,
23+ inactive_gradient: config.gradient,
24+ }),
25+ }
26+ }
27+
28+ pub fn update_config(&mut self, config: niri_config::InsertHint) {
29+ self.inner.update_config(niri_config::FocusRing {
30+ off: config.off,
31+ width: FloatOrInt(0.),
32+ active_color: config.color,
33+ inactive_color: config.color,
34+ active_gradient: config.gradient,
35+ inactive_gradient: config.gradient,
36+ });
37+ }
38+
39+ pub fn update_shaders(&mut self) {
40+ self.inner.update_shaders();
41+ }
42+
43+ pub fn update_render_elements(
44+ &mut self,
45+ size: Size<f64, Logical>,
46+ view_rect: Rectangle<f64, Logical>,
47+ radius: CornerRadius,
48+ scale: f64,
49+ ) {
50+ self.inner
51+ .update_render_elements(size, true, false, view_rect, radius, scale);
52+ }
53+
54+ pub fn render(
55+ &self,
56+ renderer: &mut impl NiriRenderer,
57+ location: Point<f64, Logical>,
58+ ) -> impl Iterator<Item = FocusRingRenderElement> {
59+ self.inner.render(renderer, location)
60+ }
61+}
src/layout/mod.rsmodified+1 -0
@@ -64,6 +64,7 @@ use crate::window::ResolvedWindowRules;
64 64
65 pub mod closing_window;65 pub mod closing_window;
66 pub mod focus_ring;66 pub mod focus_ring;
67+pub mod insert_hint_element;
67 pub mod monitor;68 pub mod monitor;
68 pub mod opening_window;69 pub mod opening_window;
69 pub mod tile;70 pub mod tile;
src/layout/workspace.rsmodified+21 -16
@@ -8,7 +8,6 @@ use niri_config::{
8 };8 };
9 use niri_ipc::SizeChange;9 use niri_ipc::SizeChange;
10 use ordered_float::NotNan;10 use ordered_float::NotNan;
11-use smithay::backend::renderer::element::Kind;
12 use smithay::backend::renderer::gles::GlesRenderer;11 use smithay::backend::renderer::gles::GlesRenderer;
13 use smithay::desktop::{layer_map_for_output, Window};12 use smithay::desktop::{layer_map_for_output, Window};
14 use smithay::output::Output;13 use smithay::output::Output;
@@ -17,13 +16,13 @@ use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
17 use smithay::utils::{Logical, Point, Rectangle, Scale, Serial, Size, Transform};16 use smithay::utils::{Logical, Point, Rectangle, Scale, Serial, Size, Transform};
18 17
19 use super::closing_window::{ClosingWindow, ClosingWindowRenderElement};18 use super::closing_window::{ClosingWindow, ClosingWindowRenderElement};
19+use super::insert_hint_element::{InsertHintElement, InsertHintRenderElement};
20 use super::tile::{Tile, TileRenderElement, TileRenderSnapshot};20 use super::tile::{Tile, TileRenderElement, TileRenderSnapshot};
21 use super::{ConfigureIntent, InteractiveResizeData, LayoutElement, Options, RemovedTile};21 use super::{ConfigureIntent, InteractiveResizeData, LayoutElement, Options, RemovedTile};
22 use crate::animation::Animation;22 use crate::animation::Animation;
23 use crate::input::swipe_tracker::SwipeTracker;23 use crate::input::swipe_tracker::SwipeTracker;
24 use crate::niri_render_elements;24 use crate::niri_render_elements;
25 use crate::render_helpers::renderer::NiriRenderer;25 use crate::render_helpers::renderer::NiriRenderer;
26-use crate::render_helpers::solid_color::{SolidColorBuffer, SolidColorRenderElement};
27 use crate::render_helpers::RenderTarget;26 use crate::render_helpers::RenderTarget;
28 use crate::utils::id::IdCounter;27 use crate::utils::id::IdCounter;
29 use crate::utils::transaction::{Transaction, TransactionBlocker};28 use crate::utils::transaction::{Transaction, TransactionBlocker};
@@ -111,8 +110,8 @@ pub struct Workspace<W: LayoutElement> {
111 /// Indication where an interactively-moved window is about to be placed.110 /// Indication where an interactively-moved window is about to be placed.
112 insert_hint: Option<InsertHint>,111 insert_hint: Option<InsertHint>,
113 112
114- /// Buffer for the insert hint.113+ /// Insert hint element for rendering.
115- insert_hint_buffer: SolidColorBuffer,114+ insert_hint_element: InsertHintElement,
116 115
117 /// Configurable properties of the layout as received from the parent monitor.116 /// Configurable properties of the layout as received from the parent monitor.
118 pub(super) base_options: Rc<Options>,117 pub(super) base_options: Rc<Options>,
@@ -173,6 +172,7 @@ niri_render_elements! {
173 WorkspaceRenderElement<R> => {172 WorkspaceRenderElement<R> => {
174 Tile = TileRenderElement<R>,173 Tile = TileRenderElement<R>,
175 ClosingWindow = ClosingWindowRenderElement,174 ClosingWindow = ClosingWindowRenderElement,
175+ InsertHint = InsertHintRenderElement,
176 }176 }
177 }177 }
178 178
@@ -440,7 +440,7 @@ impl<W: LayoutElement> Workspace<W> {
440 view_offset_before_fullscreen: None,440 view_offset_before_fullscreen: None,
441 closing_windows: vec![],441 closing_windows: vec![],
442 insert_hint: None,442 insert_hint: None,
443- insert_hint_buffer: SolidColorBuffer::new((0., 0.), [0., 0., 0., 1.]),443+ insert_hint_element: InsertHintElement::new(options.insert_hint),
444 base_options,444 base_options,
445 options,445 options,
446 name: config.map(|c| c.name.0),446 name: config.map(|c| c.name.0),
@@ -480,7 +480,7 @@ impl<W: LayoutElement> Workspace<W> {
480 view_offset_before_fullscreen: None,480 view_offset_before_fullscreen: None,
481 closing_windows: vec![],481 closing_windows: vec![],
482 insert_hint: None,482 insert_hint: None,
483- insert_hint_buffer: SolidColorBuffer::new((0., 0.), [0., 0., 0., 1.]),483+ insert_hint_element: InsertHintElement::new(options.insert_hint),
484 base_options,484 base_options,
485 options,485 options,
486 name: config.map(|c| c.name.0),486 name: config.map(|c| c.name.0),
@@ -562,8 +562,13 @@ impl<W: LayoutElement> Workspace<W> {
562 562
563 if let Some(insert_hint) = &self.insert_hint {563 if let Some(insert_hint) = &self.insert_hint {
564 if let Some(area) = self.insert_hint_area(insert_hint) {564 if let Some(area) = self.insert_hint_area(insert_hint) {
565- self.insert_hint_buffer565+ let view_rect = Rectangle::from_loc_and_size(area.loc.upscale(-1.), view_size);
566- .update(area.size, self.options.insert_hint.color.to_array_premul());566+ self.insert_hint_element.update_render_elements(
567+ area.size,
568+ view_rect,
569+ Default::default(),
570+ self.scale.fractional_scale(),
571+ );
567 }572 }
568 }573 }
569 }574 }
@@ -577,6 +582,8 @@ impl<W: LayoutElement> Workspace<W> {
577 data.update(column);582 data.update(column);
578 }583 }
579 584
585+ self.insert_hint_element.update_config(options.insert_hint);
586+
580 self.base_options = base_options;587 self.base_options = base_options;
581 self.options = options;588 self.options = options;
582 }589 }
@@ -587,6 +594,8 @@ impl<W: LayoutElement> Workspace<W> {
587 tile.update_shaders();594 tile.update_shaders();
588 }595 }
589 }596 }
597+
598+ self.insert_hint_element.update_shaders();
590 }599 }
591 600
592 pub fn windows(&self) -> impl Iterator<Item = &W> + '_ {601 pub fn windows(&self) -> impl Iterator<Item = &W> + '_ {
@@ -2672,14 +2681,10 @@ impl<W: LayoutElement> Workspace<W> {
2672 // Draw the insert hint.2681 // Draw the insert hint.
2673 if let Some(insert_hint) = &self.insert_hint {2682 if let Some(insert_hint) = &self.insert_hint {
2674 if let Some(area) = self.insert_hint_area(insert_hint) {2683 if let Some(area) = self.insert_hint_area(insert_hint) {
2675- rv.push(2684+ rv.extend(
2676- TileRenderElement::SolidColor(SolidColorRenderElement::from_buffer(2685+ self.insert_hint_element
2677- &self.insert_hint_buffer,2686+ .render(renderer, area.loc)
2678- area.loc,2687+ .map(WorkspaceRenderElement::InsertHint),
2679- 1.,
2680- Kind::Unspecified,
2681- ))
2682- .into(),
2683 );2688 );
2684 }2689 }
2685 }2690 }
wiki/Configuration:-Layout.mdmodified+3 -1
@@ -45,6 +45,7 @@ layout {
45 insert-hint {45 insert-hint {
46 // off46 // off
47 color "#ffc87f80"47 color "#ffc87f80"
48+ // gradient from="#ffbb6680" to="#ffc88080" angle=45 relative-to="workspace-view"
48 }49 }
49 50
50 struts {51 struts {
@@ -316,13 +317,14 @@ Settings for the window insert position hint during an interactive window move.
316 317
317 `off` disables the insert hint altogether.318 `off` disables the insert hint altogether.
318 319
319-`color` lets you change the color of the hint and has the same syntax as colors in border and focus ring.320+`color` and `gradient` let you change the color of the hint and have the same syntax as colors and gradients in border and focus ring.
320 321
321 ```kdl322 ```kdl
322 layout {323 layout {
323 insert-hint {324 insert-hint {
324 // off325 // off
325 color "#ffc87f80"326 color "#ffc87f80"
327+ gradient from="#ffbb6680" to="#ffc88080" angle=45 relative-to="workspace-view"
326 }328 }
327 }329 }
328 ```330 ```