aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/terminal/terminalwidget.cpp
diff options
context:
space:
mode:
authorOrgad Shaneh <[email protected]>2023-07-03 12:21:30 +0300
committerOrgad Shaneh <[email protected]>2023-07-05 08:26:39 +0000
commit9a7f45cc460e178d983287bd1cb3c45efe1d8c3c (patch)
tree3742e4fff774c44c015251a01cf1faaf1898221f /src/plugins/terminal/terminalwidget.cpp
parent1bd2e84f9aa6cc0ab2e407d53fd2905d820bf2af (diff)
Terminal: Allow the underlying application to set title
Change-Id: I3530d645f16047df2546902d900e5e2fee8d071c Reviewed-by: Marcus Tillmanns <[email protected]>
Diffstat (limited to 'src/plugins/terminal/terminalwidget.cpp')
-rw-r--r--src/plugins/terminal/terminalwidget.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/plugins/terminal/terminalwidget.cpp b/src/plugins/terminal/terminalwidget.cpp
index de464b326cb..d232bfee277 100644
--- a/src/plugins/terminal/terminalwidget.cpp
+++ b/src/plugins/terminal/terminalwidget.cpp
@@ -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())