Terminal: Allow the underlying application to set title

Change-Id: I3530d645f16047df2546902d900e5e2fee8d071c
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
Orgad Shaneh
2023-07-03 12:21:30 +03:00
committed by Orgad Shaneh
parent 1bd2e84f9a
commit 9a7f45cc46
6 changed files with 35 additions and 11 deletions

View File

@@ -399,6 +399,18 @@ void TerminalWidget::setupSurface()
if (TerminalSettings::instance().audibleBell.value())
QApplication::beep();
});
connect(m_surface.get(),
&Internal::TerminalSurface::titleChanged,
this,
[this](const QString &title) {
const FilePath titleFile = FilePath::fromUserInput(title);
if (!m_title.isEmpty()
|| m_openParameters.shellCommand.value_or(CommandLine{}).executable()
!= titleFile) {
m_title = titleFile.isFile() ? titleFile.baseName() : title;
}
emit titleChanged();
});
if (m_shellIntegration) {
connect(m_shellIntegration.get(),
@@ -442,6 +454,17 @@ QColor TerminalWidget::toQColor(std::variant<int, QColor> color) const
return std::get<QColor>(color);
}
QString TerminalWidget::title() const
{
const FilePath dir = cwd();
QString title = m_title;
if (title.isEmpty())
title = currentCommand().isEmpty() ? shellName() : currentCommand().executable().fileName();
if (dir.isEmpty())
return title;
return title + " - " + dir.fileName();
}
void TerminalWidget::updateCopyState()
{
if (!hasFocus())