From 1e3a6ba5723048264e7071d34cbe81adf4d7b3fe Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 21 Feb 2021 16:49:36 +0100 Subject: [PATCH] LibVT: Avoid double relayout during interactive resize Don't fire the on_terminal_size hook while we're in relayout. This fixes the terminal window flopping around during interactive resizing. (It was mostly noticeable if something else was hogging the CPU at the same time.) --- Userland/Libraries/LibVT/TerminalWidget.cpp | 9 +++++++-- Userland/Libraries/LibVT/TerminalWidget.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibVT/TerminalWidget.cpp b/Userland/Libraries/LibVT/TerminalWidget.cpp index beb3e8f8ad..b315d4185b 100644 --- a/Userland/Libraries/LibVT/TerminalWidget.cpp +++ b/Userland/Libraries/LibVT/TerminalWidget.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -492,6 +493,8 @@ void TerminalWidget::relayout(const Gfx::IntSize& size) if (!m_scrollbar) return; + TemporaryChange change(m_in_relayout, true); + auto base_size = compute_base_size(); int new_columns = (size.width() - base_size.width()) / font().glyph_width('x'); int new_rows = (size.height() - base_size.height()) / m_line_height; @@ -953,8 +956,10 @@ void TerminalWidget::terminal_did_resize(u16 columns, u16 rows) m_pixel_width = pixel_size.width(); m_pixel_height = pixel_size.height(); - if (on_terminal_size_change) - on_terminal_size_change(Gfx::IntSize { m_pixel_width, m_pixel_height }); + if (!m_in_relayout) { + if (on_terminal_size_change) + on_terminal_size_change(Gfx::IntSize { m_pixel_width, m_pixel_height }); + } if (m_automatic_size_policy) { set_fixed_size(m_pixel_width, m_pixel_height); diff --git a/Userland/Libraries/LibVT/TerminalWidget.h b/Userland/Libraries/LibVT/TerminalWidget.h index 5550de3fe1..0972a65631 100644 --- a/Userland/Libraries/LibVT/TerminalWidget.h +++ b/Userland/Libraries/LibVT/TerminalWidget.h @@ -185,6 +185,7 @@ private: int m_ptm_fd { -1 }; bool m_has_logical_focus { false }; + bool m_in_relayout { false }; RefPtr m_notifier;