From 7bb1693e86233e4f87ce28a952c2ceebb5341418 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 13 Mar 2025 19:04:28 +0100 Subject: [PATCH] graphics/graphics-ipc: Fix Damage::clip --- graphics/graphics-ipc/src/v1.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/graphics/graphics-ipc/src/v1.rs b/graphics/graphics-ipc/src/v1.rs index 39226f2b31..ddebae9c1a 100644 --- a/graphics/graphics-ipc/src/v1.rs +++ b/graphics/graphics-ipc/src/v1.rs @@ -126,13 +126,16 @@ impl Damage { #[must_use] pub fn clip(mut self, width: u32, height: u32) -> Self { // Clip damage + let x2 = self.x + self.width; self.x = cmp::min(self.x, width); - if self.x + self.width > width { - self.width -= cmp::min(self.width, width - self.x); + if x2 > width { + self.width = width - self.x; } + + let y2 = self.y + self.height; self.y = cmp::min(self.y, height); - if self.y + self.height > height { - self.height = cmp::min(self.height, height - self.y); + if y2 > height { + self.height = height - self.y; } self }