diff --git a/src/client/mod.rs b/src/client/mod.rs index f639dcae..5eeee338 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -51,6 +51,7 @@ use smithay_client_toolkit::shm::slot::SlotPool; use smithay_client_toolkit::shm::Shm; use crate::client_utils::SeatObject; +use crate::constants; use crate::filtering; use crate::prelude::*; use crate::serialization::geometry::Point; @@ -498,13 +499,18 @@ impl RemoteSurface { "attaching a buffer failed, this probably means we're leaking buffers", )?; if let Some(damage_rects) = self.frame_damage.take() { - for damage_rect in damage_rects { - wl_surface.damage_buffer( - damage_rect.loc.x, - damage_rect.loc.y, - damage_rect.size.w, - damage_rect.size.h, - ); + // avoid overwhelming wayland connection + if damage_rects.len() < constants::SENT_DAMAGE_LIMIT { + for damage_rect in damage_rects { + wl_surface.damage_buffer( + damage_rect.loc.x, + damage_rect.loc.y, + damage_rect.size.w, + damage_rect.size.h, + ); + } + } else { + wl_surface.damage_buffer(0, 0, i32::MAX, i32::MAX); } } else { wl_surface.damage_buffer(0, 0, i32::MAX, i32::MAX); diff --git a/src/constants.rs b/src/constants.rs new file mode 100644 index 00000000..720b27c7 --- /dev/null +++ b/src/constants.rs @@ -0,0 +1,2 @@ +// limit used to avoid overwhelming wayland connection +pub const SENT_DAMAGE_LIMIT: usize = 256; diff --git a/src/lib.rs b/src/lib.rs index 24200fcf..4c7fc516 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,6 +19,7 @@ pub mod channel_utils; pub mod client; pub mod client_utils; pub mod compositor_utils; +pub mod constants; pub mod control_server; pub mod error_utils; pub mod fallible_entry; diff --git a/src/xwayland_xdg_shell/mod.rs b/src/xwayland_xdg_shell/mod.rs index 23d50852..ad763323 100644 --- a/src/xwayland_xdg_shell/mod.rs +++ b/src/xwayland_xdg_shell/mod.rs @@ -47,6 +47,7 @@ use tracing::Span; use crate::args; use crate::compositor_utils; +use crate::constants; use crate::prelude::*; use crate::serialization::geometry::Point; use crate::serialization::geometry::Rectangle; @@ -153,13 +154,18 @@ impl XWaylandSurface { // ignore. _ = buffer.active_buffer.attach_to(&surface); if let Some(damage_rects) = &self.damage.take() { - for damage_rect in damage_rects { - surface.damage_buffer( - damage_rect.loc.x, - damage_rect.loc.y, - damage_rect.size.w, - damage_rect.size.h, - ); + // avoid overwhelming wayland connection + if damage_rects.len() < constants::SENT_DAMAGE_LIMIT { + for damage_rect in damage_rects { + surface.damage_buffer( + damage_rect.loc.x, + damage_rect.loc.y, + damage_rect.size.w, + damage_rect.size.h, + ); + } + } else { + surface.damage_buffer(0, 0, i32::MAX, i32::MAX); } } else { surface.damage_buffer(0, 0, i32::MAX, i32::MAX);