From b7e551b164ffb4e1de71fb7fe3ca99b6364c728d Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 7 Jul 2021 01:10:40 +0200 Subject: [PATCH] LibGUI: Make Widget ignore paint events that don't intersect it LibGUI widgets fully contain their child widgets, so there's no pass the paint event on to our children if we get a paint event that doesn't intersect with our rect. While Gfx::Painter was already dutifully clipping out any attempts at painting, this avoids even more pointless work. --- Userland/Libraries/LibGUI/Widget.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Userland/Libraries/LibGUI/Widget.cpp b/Userland/Libraries/LibGUI/Widget.cpp index 491040d082..b4b07aea5e 100644 --- a/Userland/Libraries/LibGUI/Widget.cpp +++ b/Userland/Libraries/LibGUI/Widget.cpp @@ -318,6 +318,13 @@ void Widget::handle_keydown_event(KeyEvent& event) void Widget::handle_paint_event(PaintEvent& event) { VERIFY(is_visible()); + + if (!rect().intersects(event.rect())) { + // This widget is not inside the paint event rect. + // Since widgets fully contain their children, we don't need to recurse further. + return; + } + if (fill_with_background_color()) { Painter painter(*this); painter.fill_rect(event.rect(), palette().color(background_role()));