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 <cristian.adam@qt.io>
This commit is contained in:
Marcus Tillmanns
2025-01-07 09:39:06 +01:00
parent f28fe261f4
commit 4a6fc56556
4 changed files with 17 additions and 8 deletions

View File

@@ -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()

View File

@@ -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<Link> toLink(const QString &text)
{

View File

@@ -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()

View File

@@ -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<TerminalView::Link> toLink(const QString &text) override;