From 4a6fc56556b1b6708ec0eb0d7b7536bbb2578777 Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Tue, 7 Jan 2025 09:39:06 +0100 Subject: [PATCH] Terminal: Fix resize logic When a terminal window is resized (e.g. on first show) it needs to communicate its size to the PTY process. If the process is not yet running we need to make sure that the size is set again once it is running. Adding a bool return value to "resizePty" allows us to detect if the size change was applied, which allows us to update the surface size only if the pty was also changed. With this we can use the "liveSize" of the surface to check if a resizeEvent needs to be passed on to the PTY, which will be triggered by the Process::started signal once the process is started. Fixes: QTCREATORBUG-32290 Change-Id: I613275e75d343ccb357c2a797d096f0e1f96fed7 Reviewed-by: Cristian Adam --- src/libs/solutions/terminal/terminalview.cpp | 7 ++++--- src/libs/solutions/terminal/terminalview.h | 7 ++++++- src/plugins/terminal/terminalwidget.cpp | 9 ++++++--- src/plugins/terminal/terminalwidget.h | 2 +- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/libs/solutions/terminal/terminalview.cpp b/src/libs/solutions/terminal/terminalview.cpp index 1010e546d97..88b5a34c029 100644 --- a/src/libs/solutions/terminal/terminalview.cpp +++ b/src/libs/solutions/terminal/terminalview.cpp @@ -977,9 +977,10 @@ void TerminalView::applySizeChange() if (d->m_surface->liveSize() == newLiveSize) return; - resizePty(newLiveSize); - d->m_surface->resize(newLiveSize); - flushVTerm(true); + if (resizePty(newLiveSize)) { + d->m_surface->resize(newLiveSize); + flushVTerm(true); + } } void TerminalView::updateScrollBars() diff --git a/src/libs/solutions/terminal/terminalview.h b/src/libs/solutions/terminal/terminalview.h index fcc5994a75e..daddda01e23 100644 --- a/src/libs/solutions/terminal/terminalview.h +++ b/src/libs/solutions/terminal/terminalview.h @@ -123,7 +123,12 @@ public: return noHits; } - virtual void resizePty(QSize newSize) { Q_UNUSED(newSize); } + virtual bool resizePty(QSize newSize) + { + Q_UNUSED(newSize); + return false; + } + virtual void setClipboard(const QString &text) { Q_UNUSED(text); } virtual std::optional toLink(const QString &text) { diff --git a/src/plugins/terminal/terminalwidget.cpp b/src/plugins/terminal/terminalwidget.cpp index 3ca0cfd8d25..05ba69457b8 100644 --- a/src/plugins/terminal/terminalwidget.cpp +++ b/src/plugins/terminal/terminalwidget.cpp @@ -336,10 +336,13 @@ qint64 TerminalWidget::writeToPty(const QByteArray &data) return data.size(); } -void TerminalWidget::resizePty(QSize newSize) +bool TerminalWidget::resizePty(QSize newSize) { - if (m_process && m_process->ptyData() && m_process->isRunning()) - m_process->ptyData()->resize(newSize); + if (!m_process || !m_process->ptyData() || !m_process->isRunning()) + return false; + + m_process->ptyData()->resize(newSize); + return true; } void TerminalWidget::surfaceChanged() diff --git a/src/plugins/terminal/terminalwidget.h b/src/plugins/terminal/terminalwidget.h index 351ae457205..2017f712aef 100644 --- a/src/plugins/terminal/terminalwidget.h +++ b/src/plugins/terminal/terminalwidget.h @@ -77,7 +77,7 @@ protected: void contextMenuRequested(const QPoint &pos) override; qint64 writeToPty(const QByteArray &data) override; - void resizePty(QSize newSize) override; + bool resizePty(QSize newSize) override; void setClipboard(const QString &text) override; std::optional toLink(const QString &text) override;