Skip to content

Commit 90cfb24

Browse files
committed
feat: support ext-background-effect-v1
draft
1 parent 4248a0d commit 90cfb24

9 files changed

Lines changed: 185 additions & 33 deletions

File tree

iced_layershell/src/actions.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::reexport::{Anchor, Layer, WlRegion};
22
use iced_core::window::Id as IcedId;
3+
use layershellev::blur::BlurOption;
34
use layershellev::reexport::xdg_positioner::{
45
Anchor as PopupAnchor, ConstraintAdjustment as PopupConstraintAdjustment,
56
Gravity as PopupGravity,
@@ -139,6 +140,7 @@ pub enum LayerShellCustomAction {
139140
VirtualKeyboardPressed {
140141
key: u32,
141142
},
143+
BlurOptionChange(BlurOption),
142144
// settings, info, single_tone
143145
NewLayerShell {
144146
settings: NewLayerShellSettings,

iced_layershell/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ pub mod reexport {
1717
pub use layershellev::OutputOption;
1818
pub use layershellev::PopupPlacement;
1919
pub use layershellev::WithConnection;
20+
pub use layershellev::blur::BlurOption;
21+
pub use layershellev::blur::BlurRegion;
2022
pub use layershellev::reexport::Anchor;
2123
pub use layershellev::reexport::KeyboardInteractivity;
2224
pub use layershellev::reexport::Layer;

iced_layershell/src/multi_window.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ where
110110
.with_exclusive_zone(settings.layer_settings.exclusive_zone)
111111
.with_margin(settings.layer_settings.margin)
112112
.with_keyboard_interacivity(settings.layer_settings.keyboard_interactivity)
113+
.with_blur_option(settings.layer_settings.blur_option)
113114
.with_connection(settings.with_connection)
114115
.build()
115116
.expect("Cannot create layershell");
@@ -681,7 +682,7 @@ where
681682
action: LayerShellCustomAction,
682683
) {
683684
let layer_shell_window;
684-
macro_rules! ref_layer_shell_window {
685+
macro_rules! ref_mut_layer_shell_window {
685686
($ev: ident, $iced_id: ident, $layer_shell_id: ident, $layer_shell_window: ident) => {
686687
if $iced_id.is_none() {
687688
// Make application also works
@@ -696,8 +697,8 @@ where
696697
return;
697698
}
698699
}
699-
if let Some(ls_window) =
700-
$layer_shell_id.and_then(|layer_shell_id| $ev.get_unit_with_id(layer_shell_id))
700+
if let Some(ls_window) = $layer_shell_id
701+
.and_then(|layer_shell_id| $ev.get_mut_unit_with_id(layer_shell_id))
701702
{
702703
layer_shell_window = ls_window;
703704
} else {
@@ -716,35 +717,39 @@ where
716717
}
717718
match action {
718719
LayerShellCustomAction::AnchorChange(anchor) => {
719-
ref_layer_shell_window!(ev, iced_id, layer_shell_id, layer_shell_window);
720+
ref_mut_layer_shell_window!(ev, iced_id, layer_shell_id, layer_shell_window);
720721
layer_shell_window.set_anchor(anchor);
721722
}
723+
LayerShellCustomAction::BlurOptionChange(option) => {
724+
ref_mut_layer_shell_window!(ev, iced_id, layer_shell_id, layer_shell_window);
725+
layer_shell_window.set_blur_option(option);
726+
}
722727
LayerShellCustomAction::AnchorSizeChange(anchor, size) => {
723-
ref_layer_shell_window!(ev, iced_id, layer_shell_id, layer_shell_window);
728+
ref_mut_layer_shell_window!(ev, iced_id, layer_shell_id, layer_shell_window);
724729
layer_shell_window.set_anchor_with_size(anchor, size);
725730
}
726731
LayerShellCustomAction::LayerChange(layer) => {
727-
ref_layer_shell_window!(ev, iced_id, layer_shell_id, layer_shell_window);
732+
ref_mut_layer_shell_window!(ev, iced_id, layer_shell_id, layer_shell_window);
728733
layer_shell_window.set_layer(layer);
729734
}
730735
LayerShellCustomAction::MarginChange(margin) => {
731-
ref_layer_shell_window!(ev, iced_id, layer_shell_id, layer_shell_window);
736+
ref_mut_layer_shell_window!(ev, iced_id, layer_shell_id, layer_shell_window);
732737
layer_shell_window.set_margin(margin);
733738
}
734739
LayerShellCustomAction::SizeChange((width, height)) => {
735-
ref_layer_shell_window!(ev, iced_id, layer_shell_id, layer_shell_window);
740+
ref_mut_layer_shell_window!(ev, iced_id, layer_shell_id, layer_shell_window);
736741
layer_shell_window.set_size((width, height));
737742
}
738743
LayerShellCustomAction::ExclusiveZoneChange(zone_size) => {
739-
ref_layer_shell_window!(ev, iced_id, layer_shell_id, layer_shell_window);
744+
ref_mut_layer_shell_window!(ev, iced_id, layer_shell_id, layer_shell_window);
740745
layer_shell_window.set_exclusive_zone(zone_size);
741746
}
742747
LayerShellCustomAction::KeyboardInteractivityChange(keyboard_interactivity) => {
743-
ref_layer_shell_window!(ev, iced_id, layer_shell_id, layer_shell_window);
748+
ref_mut_layer_shell_window!(ev, iced_id, layer_shell_id, layer_shell_window);
744749
layer_shell_window.set_keyboard_interactivity(keyboard_interactivity);
745750
}
746751
LayerShellCustomAction::SetInputRegion(set_region) => {
747-
ref_layer_shell_window!(ev, iced_id, layer_shell_id, layer_shell_window);
752+
ref_mut_layer_shell_window!(ev, iced_id, layer_shell_id, layer_shell_window);
748753
let set_region = set_region.0;
749754
let Some(region) = &self.wl_input_region else {
750755
tracing::warn!(

iced_layershell/src/settings.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::reexport::{Anchor, KeyboardInteractivity, Layer, WithConnection};
66

77
pub use layershellev::StartMode;
88

9-
use layershellev::reexport::wayland_client::wl_keyboard::KeymapFormat;
9+
use layershellev::{blur::BlurOption, reexport::wayland_client::wl_keyboard::KeymapFormat};
1010

1111
#[derive(Debug)]
1212
pub struct VirtualKeyboardSettings {
@@ -81,6 +81,7 @@ pub struct LayerShellSettings {
8181
pub margin: (i32, i32, i32, i32),
8282
pub keyboard_interactivity: KeyboardInteractivity,
8383
pub start_mode: StartMode,
84+
pub blur_option: BlurOption,
8485
pub events_transparent: bool,
8586
}
8687

@@ -94,6 +95,7 @@ impl Default for LayerShellSettings {
9495
margin: (0, 0, 0, 0),
9596
keyboard_interactivity: KeyboardInteractivity::OnDemand,
9697
events_transparent: false,
98+
blur_option: BlurOption::None,
9799
start_mode: StartMode::default(),
98100
}
99101
}
@@ -159,6 +161,7 @@ mod tests {
159161
margin: (10, 10, 10, 10),
160162
keyboard_interactivity: KeyboardInteractivity::None,
161163
start_mode: StartMode::TargetScreen("HDMI-1".to_string()),
164+
blur_option: BlurOption::None,
162165
events_transparent: false,
163166
};
164167

iced_layershell_macros/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub fn to_layer_message(attr: TokenStream2, input: TokenStream2) -> manyhow::Res
4343
LayerChange{id: iced_layershell::reexport::IcedId, layer:iced_layershell::reexport::Layer},
4444
/// Margin: top, left, bottom, right
4545
MarginChange{id: iced_layershell::reexport::IcedId, margin: (i32, i32, i32, i32)},
46+
BlurOptionChange{id: iced_layershell::reexport::IcedId, option: iced_layershell::reexport::BlurOption},
4647
SizeChange{id: iced_layershell::reexport::IcedId, size: (u32, u32)},
4748
ExclusiveZoneChange{id: iced_layershell::reexport::IcedId, zone_size: i32},
4849
KeyboardInteractivityChange{id: iced_layershell::reexport::IcedId, keyboard_interactivity: iced_layershell::reexport::KeyboardInteractivity},
@@ -120,6 +121,7 @@ pub fn to_layer_message(attr: TokenStream2, input: TokenStream2) -> manyhow::Res
120121
Self::NewInputPanel {settings, id } => Ok(LayerShellCustomActionWithId::new(None, LayerShellCustomAction::NewInputPanel { settings, id })),
121122
Self::RemoveWindow(id) => Ok(LayerShellCustomActionWithId::new(Some(id), LayerShellCustomAction::RemoveWindow)),
122123
Self::ForgetLastOutput => Ok(LayerShellCustomActionWithId::new(None, LayerShellCustomAction::ForgetLastOutput)),
124+
Self::BlurOptionChange {id, option} => Ok(LayerShellCustomActionWithId::new(Some(id), LayerShellCustomAction::BlurOption(option))),
123125
_ => Err(self)
124126
}
125127
}
@@ -142,6 +144,7 @@ pub fn to_layer_message(attr: TokenStream2, input: TokenStream2) -> manyhow::Res
142144
VirtualKeyboardPressed {
143145
key: u32,
144146
},
147+
BlurOptionChange(iced_layershell::reexport::BlurOptionChange),
145148
};
146149
let impl_quote = quote! {
147150
impl #impl_gen TryInto<iced_layershell::actions::LayerShellCustomActionWithId> for #ident #ty_gen #where_gen {
@@ -164,6 +167,8 @@ pub fn to_layer_message(attr: TokenStream2, input: TokenStream2) -> manyhow::Res
164167
Self::VirtualKeyboardPressed { key } => Ok(LayerShellCustomActionWithId::new(None, LayerShellCustomAction::VirtualKeyboardPressed {
165168
key
166169
})),
170+
171+
Self::BlurOptionChange(option) => Ok(LayerShellCustomActionWithId::new(None, LayerShellCustomAction::BlurOption(option))),
167172
_ => Err(self)
168173
}
169174
}

layershellev/src/blur.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use super::WindowState;
2+
use wayland_client::delegate_noop;
3+
use wayland_protocols::ext::background_effect::v1::client::{
4+
ext_background_effect_manager_v1::ExtBackgroundEffectManagerV1,
5+
ext_background_effect_surface_v1::ExtBackgroundEffectSurfaceV1,
6+
};
7+
// TODO: handle callback
8+
delegate_noop!(@<T> WindowState<T>: ignore ExtBackgroundEffectSurfaceV1);
9+
delegate_noop!(@<T> WindowState<T>: ignore ExtBackgroundEffectManagerV1);
10+
11+
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
12+
pub struct BlurRegion {
13+
pub x: i32,
14+
pub y: i32,
15+
pub width: i32,
16+
pub height: i32,
17+
}
18+
19+
#[derive(Debug, Default, Clone, PartialEq, Eq)]
20+
pub enum BlurOption {
21+
#[default]
22+
None,
23+
FullRegion,
24+
Region(Vec<BlurRegion>),
25+
}

layershellev/src/events.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use wayland_client::{
2020
},
2121
};
2222

23-
use crate::{id, xkb_keyboard::KeyEvent};
23+
use crate::{blur::BlurOption, id, xkb_keyboard::KeyEvent};
2424

2525
use crate::keyboard::ModifiersState;
2626

@@ -103,6 +103,7 @@ pub struct NewLayerShellSettings {
103103
/// follow the last output of the activated surface, used to create some thing like mako, who
104104
/// will show on the same window, only when the notifications is cleared, it will change the
105105
/// wl_output.
106+
pub blur_option: BlurOption,
106107
pub output_option: OutputOption,
107108
pub events_transparent: bool,
108109
pub namespace: Option<String>,
@@ -167,6 +168,7 @@ impl Default for NewLayerShellSettings {
167168
size: None,
168169
margin: Some((0, 0, 0, 0)),
169170
keyboard_interactivity: KeyboardInteractivity::OnDemand,
171+
blur_option: BlurOption::None,
170172
output_option: OutputOption::Active,
171173
events_transparent: false,
172174
namespace: None,

0 commit comments

Comments
 (0)