forge
Explore
Log in

Don't you dare go Hollow

Implement place-within-backdrop layer rule

Browse files at this commit

3e31c134a602dd876f2b446071e5802fa4a0c3ecIvan MolodetskikhParent: fe68293
niri-config/src/layer_rule.rsmodified+2 -0
@@ -15,6 +15,8 @@ pub struct LayerRule {
15 pub shadow: ShadowRule,15 pub shadow: ShadowRule,
16 #[knuffel(child)]16 #[knuffel(child)]
17 pub geometry_corner_radius: Option<CornerRadius>,17 pub geometry_corner_radius: Option<CornerRadius>,
18+ #[knuffel(child, unwrap(argument))]
19+ pub place_within_backdrop: Option<bool>,
18 }20 }
19 21
20 #[derive(knuffel::Decode, Debug, Default, Clone, PartialEq)]22 #[derive(knuffel::Decode, Debug, Default, Clone, PartialEq)]
niri-config/src/lib.rsmodified+1 -0
@@ -4888,6 +4888,7 @@ mod tests {
4888 inactive_color: None,4888 inactive_color: None,
4889 },4889 },
4890 geometry_corner_radius: None,4890 geometry_corner_radius: None,
4891+ place_within_backdrop: None,
4891 },4892 },
4892 ],4893 ],
4893 binds: Binds(4894 binds: Binds(
src/handlers/xdg_shell.rsmodified+11 -4
@@ -319,10 +319,17 @@ impl XdgShellHandler for State {
319 // FIXME: somewhere here we probably need to check is_overview_open to match the logic319 // FIXME: somewhere here we probably need to check is_overview_open to match the logic
320 // in update_keyboard_focus().320 // in update_keyboard_focus().
321 321
322- if layers322+ if let Some(layer) = layers.layer_for_surface(&root, WindowSurfaceType::TOPLEVEL) {
323- .layer_for_surface(&root, WindowSurfaceType::TOPLEVEL)323+ // This is a grab for a layer surface.
324- .is_none()324+
325- {325+ if let Some(mapped) = self.niri.mapped_layer_surfaces.get(layer) {
326+ if mapped.place_within_backdrop() {
327+ trace!("ignoring popup grab for a layer surface within overview backdrop");
328+ let _ = PopupManager::dismiss_popup(&root, &popup);
329+ return;
330+ }
331+ }
332+ } else {
326 // This is a grab for a regular window; check that there's no layer surface with a333 // This is a grab for a regular window; check that there's no layer surface with a
327 // higher input priority.334 // higher input priority.
328 335
src/layer/mapped.rsmodified+18 -0
@@ -6,6 +6,7 @@ use smithay::backend::renderer::element::surface::{
6 use smithay::backend::renderer::element::Kind;6 use smithay::backend::renderer::element::Kind;
7 use smithay::desktop::{LayerSurface, PopupManager};7 use smithay::desktop::{LayerSurface, PopupManager};
8 use smithay::utils::{Logical, Point, Scale, Size};8 use smithay::utils::{Logical, Point, Scale, Size};
9+use smithay::wayland::shell::wlr_layer::{ExclusiveZone, Layer};
9 10
10 use super::ResolvedLayerRules;11 use super::ResolvedLayerRules;
11 use crate::layout::shadow::Shadow;12 use crate::layout::shadow::Shadow;
@@ -96,6 +97,23 @@ impl MappedLayer {
96 true97 true
97 }98 }
98 99
100+ pub fn place_within_backdrop(&self) -> bool {
101+ if !self.rules.place_within_backdrop {
102+ return false;
103+ }
104+
105+ if self.surface.layer() != Layer::Background {
106+ return false;
107+ }
108+
109+ let state = self.surface.cached_state();
110+ if state.exclusive_zone != ExclusiveZone::DontCare {
111+ return false;
112+ }
113+
114+ true
115+ }
116+
99 pub fn render<R: NiriRenderer>(117 pub fn render<R: NiriRenderer>(
100 &self,118 &self,
101 renderer: &mut R,119 renderer: &mut R,
src/layer/mod.rsmodified+7 -0
@@ -19,6 +19,9 @@ pub struct ResolvedLayerRules {
19 19
20 /// Corner radius to assume this layer surface has.20 /// Corner radius to assume this layer surface has.
21 pub geometry_corner_radius: Option<CornerRadius>,21 pub geometry_corner_radius: Option<CornerRadius>,
22+
23+ /// Whether to place this layer surface within the overview backdrop.
24+ pub place_within_backdrop: bool,
22 }25 }
23 26
24 impl ResolvedLayerRules {27 impl ResolvedLayerRules {
@@ -37,6 +40,7 @@ impl ResolvedLayerRules {
37 inactive_color: None,40 inactive_color: None,
38 },41 },
39 geometry_corner_radius: None,42 geometry_corner_radius: None,
43+ place_within_backdrop: false,
40 }44 }
41 }45 }
42 46
@@ -73,6 +77,9 @@ impl ResolvedLayerRules {
73 if let Some(x) = rule.geometry_corner_radius {77 if let Some(x) = rule.geometry_corner_radius {
74 resolved.geometry_corner_radius = Some(x);78 resolved.geometry_corner_radius = Some(x);
75 }79 }
80+ if let Some(x) = rule.place_within_backdrop {
81+ resolved.place_within_backdrop = x;
82+ }
76 83
77 resolved.shadow.merge_with(&rule.shadow);84 resolved.shadow.merge_with(&rule.shadow);
78 }85 }
src/niri.rsmodified+58 -17
@@ -992,9 +992,19 @@ impl State {
992 // Clean up on-demand layer surface focus if necessary.992 // Clean up on-demand layer surface focus if necessary.
993 if let Some(surface) = &self.niri.layer_shell_on_demand_focus {993 if let Some(surface) = &self.niri.layer_shell_on_demand_focus {
994 // Still alive and has on-demand interactivity.994 // Still alive and has on-demand interactivity.
995- let good = surface.alive()995+ let mut good = surface.alive()
996 && surface.cached_state().keyboard_interactivity996 && surface.cached_state().keyboard_interactivity
997 == wlr_layer::KeyboardInteractivity::OnDemand;997 == wlr_layer::KeyboardInteractivity::OnDemand;
998+
999+ // Check if it moved to the overview backdrop.
1000+ if let Some(mapped) = self.niri.mapped_layer_surfaces.get(surface) {
1001+ if mapped.place_within_backdrop() {
1002+ good = false;
1003+ }
1004+ } else {
1005+ good = false;
1006+ }
1007+
998 if !good {1008 if !good {
999 self.niri.layer_shell_on_demand_focus = None;1009 self.niri.layer_shell_on_demand_focus = None;
1000 }1010 }
@@ -1042,6 +1052,11 @@ impl State {
1042 return None;1052 return None;
1043 }1053 }
1044 1054
1055+ let mapped = self.niri.mapped_layer_surfaces.get(surface)?;
1056+ if mapped.place_within_backdrop() {
1057+ return None;
1058+ }
1059+
1045 let surface = surface.wl_surface().clone();1060 let surface = surface.wl_surface().clone();
1046 Some(KeyboardFocus::LayerShell { surface })1061 Some(KeyboardFocus::LayerShell { surface })
1047 })1062 })
@@ -1513,11 +1528,10 @@ impl State {
1513 resized_outputs.push(output.clone());1528 resized_outputs.push(output.clone());
1514 }1529 }
1515 1530
1516- let mut background_color = config1531+ let background_color = config
1517 .map(|c| c.background_color)1532 .map(|c| c.background_color)
1518 .unwrap_or(DEFAULT_BACKGROUND_COLOR)1533 .unwrap_or(DEFAULT_BACKGROUND_COLOR)
1519 .to_array_unpremul();1534 .to_array_unpremul();
1520- background_color[3] = 1.;
1521 let background_color = Color32F::from(background_color);1535 let background_color = Color32F::from(background_color);
1522 1536
1523 let mut backdrop_color = config1537 let mut backdrop_color = config
@@ -2710,11 +2724,10 @@ impl Niri {
2710 .map(|c| ipc_transform_to_smithay(c.transform))2724 .map(|c| ipc_transform_to_smithay(c.transform))
2711 .unwrap_or(Transform::Normal);2725 .unwrap_or(Transform::Normal);
2712 2726
2713- let mut background_color = c2727+ let background_color = c
2714 .map(|c| c.background_color)2728 .map(|c| c.background_color)
2715 .unwrap_or(DEFAULT_BACKGROUND_COLOR)2729 .unwrap_or(DEFAULT_BACKGROUND_COLOR)
2716 .to_array_unpremul();2730 .to_array_unpremul();
2717- background_color[3] = 1.;
2718 2731
2719 let mut backdrop_color = c2732 let mut backdrop_color = c
2720 .and_then(|c| c.backdrop_color)2733 .and_then(|c| c.backdrop_color)
@@ -2991,6 +3004,11 @@ impl Niri {
2991 .layers_on(layer)3004 .layers_on(layer)
2992 .rev()3005 .rev()
2993 .find_map(|layer_surface| {3006 .find_map(|layer_surface| {
3007+ let mapped = self.mapped_layer_surfaces.get(layer_surface)?;
3008+ if mapped.place_within_backdrop() {
3009+ return None;
3010+ }
3011+
2994 let mut layer_pos_within_output =3012 let mut layer_pos_within_output =
2995 layers.layer_geometry(layer_surface).unwrap().loc.to_f64();3013 layers.layer_geometry(layer_surface).unwrap().loc.to_f64();
2996 3014
@@ -3141,6 +3159,11 @@ impl Niri {
3141 .layers_on(layer)3159 .layers_on(layer)
3142 .rev()3160 .rev()
3143 .find_map(|layer_surface| {3161 .find_map(|layer_surface| {
3162+ let mapped = self.mapped_layer_surfaces.get(layer_surface)?;
3163+ if mapped.place_within_backdrop() {
3164+ return None;
3165+ }
3166+
3144 let mut layer_pos_within_output =3167 let mut layer_pos_within_output =
3145 layers.layer_geometry(layer_surface).unwrap().loc.to_f64();3168 layers.layer_geometry(layer_surface).unwrap().loc.to_f64();
3146 3169
@@ -4021,19 +4044,27 @@ impl Niri {
4021 4044
4022 // Get layer-shell elements.4045 // Get layer-shell elements.
4023 let layer_map = layer_map_for_output(output);4046 let layer_map = layer_map_for_output(output);
4024- let mut extend_from_layer = |elements: &mut SplitElements<LayerSurfaceRenderElement<R>>,4047+ let mut extend_from_layer =
4025- layer| {4048+ |elements: &mut SplitElements<LayerSurfaceRenderElement<R>>, layer, for_backdrop| {
4026- self.render_layer(renderer, target, output_scale, &layer_map, layer, elements);4049+ self.render_layer(
4027- };4050+ renderer,
4051+ target,
4052+ output_scale,
4053+ &layer_map,
4054+ layer,
4055+ elements,
4056+ for_backdrop,
4057+ );
4058+ };
4028 4059
4029 // The overlay layer elements go next.4060 // The overlay layer elements go next.
4030 let mut layer_elems = SplitElements::default();4061 let mut layer_elems = SplitElements::default();
4031- extend_from_layer(&mut layer_elems, Layer::Overlay);4062+ extend_from_layer(&mut layer_elems, Layer::Overlay, false);
4032 elements.extend(layer_elems.into_iter().map(OutputRenderElements::from));4063 elements.extend(layer_elems.into_iter().map(OutputRenderElements::from));
4033 4064
4034 // Collect the top layer elements.4065 // Collect the top layer elements.
4035 let mut layer_elems = SplitElements::default();4066 let mut layer_elems = SplitElements::default();
4036- extend_from_layer(&mut layer_elems, Layer::Top);4067+ extend_from_layer(&mut layer_elems, Layer::Top, false);
4037 let top_layer = layer_elems;4068 let top_layer = layer_elems;
4038 4069
4039 // When rendering above the top layer, we put the regular monitor elements first.4070 // When rendering above the top layer, we put the regular monitor elements first.
@@ -4041,8 +4072,8 @@ impl Niri {
4041 if mon.render_above_top_layer() {4072 if mon.render_above_top_layer() {
4042 // Collect all other layer-shell elements.4073 // Collect all other layer-shell elements.
4043 let mut layer_elems = SplitElements::default();4074 let mut layer_elems = SplitElements::default();
4044- extend_from_layer(&mut layer_elems, Layer::Bottom);4075+ extend_from_layer(&mut layer_elems, Layer::Bottom, false);
4045- extend_from_layer(&mut layer_elems, Layer::Background);4076+ extend_from_layer(&mut layer_elems, Layer::Background, false);
4046 4077
4047 elements.extend(4078 elements.extend(
4048 int_move_elements4079 int_move_elements
@@ -4062,8 +4093,7 @@ impl Niri {
4062 );4093 );
4063 4094
4064 elements.extend(top_layer.into_iter().map(OutputRenderElements::from));4095 elements.extend(top_layer.into_iter().map(OutputRenderElements::from));
4065- elements.extend(layer_elems.popups.drain(..).map(OutputRenderElements::from));4096+ elements.extend(layer_elems.into_iter().map(OutputRenderElements::from));
4066- elements.extend(layer_elems.normal.drain(..).map(OutputRenderElements::from));
4067 4097
4068 elements.push(OutputRenderElements::from(background));4098 elements.push(OutputRenderElements::from(background));
4069 4099
@@ -4090,8 +4120,8 @@ impl Niri {
4090 for (ws_geo, ws_elements) in monitor_elements {4120 for (ws_geo, ws_elements) in monitor_elements {
4091 // Collect all other layer-shell elements.4121 // Collect all other layer-shell elements.
4092 let mut layer_elems = SplitElements::default();4122 let mut layer_elems = SplitElements::default();
4093- extend_from_layer(&mut layer_elems, Layer::Bottom);4123+ extend_from_layer(&mut layer_elems, Layer::Bottom, false);
4094- extend_from_layer(&mut layer_elems, Layer::Background);4124+ extend_from_layer(&mut layer_elems, Layer::Background, false);
4095 4125
4096 elements.extend(4126 elements.extend(
4097 layer_elems4127 layer_elems
@@ -4126,6 +4156,10 @@ impl Niri {
4126 }4156 }
4127 4157
4128 // Then the backdrop.4158 // Then the backdrop.
4159+ let mut layer_elems = SplitElements::default();
4160+ extend_from_layer(&mut layer_elems, Layer::Background, true);
4161+ elements.extend(layer_elems.into_iter().map(OutputRenderElements::from));
4162+
4129 elements.push(backdrop);4163 elements.push(backdrop);
4130 4164
4131 if self.debug_draw_opaque_regions {4165 if self.debug_draw_opaque_regions {
@@ -4135,6 +4169,7 @@ impl Niri {
4135 elements4169 elements
4136 }4170 }
4137 4171
4172+ #[allow(clippy::too_many_arguments)]
4138 fn render_layer<R: NiriRenderer>(4173 fn render_layer<R: NiriRenderer>(
4139 &self,4174 &self,
4140 renderer: &mut R,4175 renderer: &mut R,
@@ -4143,10 +4178,16 @@ impl Niri {
4143 layer_map: &LayerMap,4178 layer_map: &LayerMap,
4144 layer: Layer,4179 layer: Layer,
4145 elements: &mut SplitElements<LayerSurfaceRenderElement<R>>,4180 elements: &mut SplitElements<LayerSurfaceRenderElement<R>>,
4181+ for_backdrop: bool,
4146 ) {4182 ) {
4147 // LayerMap returns layers in reverse stacking order.4183 // LayerMap returns layers in reverse stacking order.
4148 let iter = layer_map.layers_on(layer).rev().filter_map(|surface| {4184 let iter = layer_map.layers_on(layer).rev().filter_map(|surface| {
4149 let mapped = self.mapped_layer_surfaces.get(surface)?;4185 let mapped = self.mapped_layer_surfaces.get(surface)?;
4186+
4187+ if for_backdrop != mapped.place_within_backdrop() {
4188+ return None;
4189+ }
4190+
4150 let geo = layer_map.layer_geometry(surface)?;4191 let geo = layer_map.layer_geometry(surface)?;
4151 Some((mapped, geo))4192 Some((mapped, geo))
4152 });4193 });
wiki/Configuration:-Layer-Rules.mdmodified+22 -1
@@ -32,6 +32,8 @@ layer-rule {
32 }32 }
33 33
34 geometry-corner-radius 1234 geometry-corner-radius 12
35+
36+ place-within-backdrop true
35 }37 }
36 ```38 ```
37 39
@@ -129,7 +131,7 @@ That is, enabling shadows in the layout config section won't automatically enabl
129 // Add a shadow for fuzzel.131 // Add a shadow for fuzzel.
130 layer-rule {132 layer-rule {
131 match namespace="^launcher$"133 match namespace="^launcher$"
132- 134+
133 shadow {135 shadow {
134 on136 on
135 }137 }
@@ -149,6 +151,25 @@ This setting will only affect the shadow—it will round its corners to match th
149 151
150 ```kdl152 ```kdl
151 layer-rule {153 layer-rule {
154+ match namespace="^launcher$"
155+
152 geometry-corner-radius 12156 geometry-corner-radius 12
153 }157 }
154 ```158 ```
159+
160+#### `place-within-backdrop`
161+
162+<sup>Since: next release</sup>
163+
164+Set to `true` to place the surface into the backdrop visible in the [Overview](./Overview.md) and between workspaces.
165+
166+This will only work for *background* layer surfaces that ignore exclusive zones (typical for wallpaper tools).
167+
168+```kdl
169+// Put swaybg inside the overview backdrop.
170+layer-rule {
171+ match namespace="^wallpaper$"
172+
173+ place-within-backdrop true
174+}
175+```
wiki/Overview.mdmodified+18 -1
@@ -14,7 +14,7 @@ While in the overview, all keyboard binds keep working, while pointing devices g
14 14
15 > [!TIP]15 > [!TIP]
16 > The overview needs to draw a background under every workspace.16 > The overview needs to draw a background under every workspace.
17-> So, layer-shell surfaces work this way: the *background* and *bottom* layers zoom out and remain under workspaces, while the *top* and *overlay* layers remain on top of the overview.17+> So, layer-shell surfaces work this way: the *background* and *bottom* layers zoom out and remain on the workspaces, while the *top* and *overlay* layers remain on top of the overview.
18 >18 >
19 > Put your bar on the *top* layer.19 > Put your bar on the *top* layer.
20 20
@@ -59,3 +59,20 @@ gestures {
59 }59 }
60 }60 }
61 ```61 ```
62+
63+### Backdrop customization
64+
65+Apart from setting a custom backdrop color like described above, you can also put a layer-shell wallpaper into the backdrop with a [layer rule](./Configuration:-Layer-Rules.md#place-within-backdrop), for example:
66+
67+```kdl
68+// Put swaybg inside the overview backdrop.
69+layer-rule {
70+ match namespace="^wallpaper$"
71+ place-within-backdrop true
72+}
73+```
74+
75+This will only work for *background* layer surfaces that ignore exclusive zones (typical for wallpaper tools).
76+
77+You can run two different wallpaper tools (like swaybg and swww), one for the backdrop and one for the normal workspace background.
78+This way you could set the backdrop one to a blurred version of the wallpaper for a nice effect.