diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 7b3d63fd6e..ad19523613 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -629,6 +629,13 @@ void DolphinMainWindow::togglePanelLockState() GeneralSettings::setLockPanels(newLockState); } +void DolphinMainWindow::slotTerminalPanelVisibilityChanged() +{ + if (m_terminalPanel->isHiddenInVisibleWindow()) { + m_activeViewContainer->view()->setFocus(); + } +} + void DolphinMainWindow::goBack() { KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator(); @@ -1297,6 +1304,8 @@ void DolphinMainWindow::setupDockWidgets() connect(m_terminalPanel, &TerminalPanel::changeUrl, this, &DolphinMainWindow::slotTerminalDirectoryChanged); connect(terminalDock, &DolphinDockWidget::visibilityChanged, m_terminalPanel, &TerminalPanel::dockVisibilityChanged); + connect(terminalDock, &DolphinDockWidget::visibilityChanged, + this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged); QAction* terminalAction = terminalDock->toggleViewAction(); createPanelAction(QIcon::fromTheme(QStringLiteral("utilities-terminal")), Qt::Key_F4, terminalAction, QStringLiteral("show_terminal_panel")); diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index c7a06c00a9..01746169bd 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -261,6 +261,12 @@ private slots: */ void togglePanelLockState(); + /** + * Is invoked if the Terminal panel got visible/invisible and takes care + * that the active view has the focus if the Terminal panel is invisible. + */ + void slotTerminalPanelVisibilityChanged(); + /** Goes back one step of the URL history. */ void goBack(); diff --git a/src/panels/terminal/terminalpanel.cpp b/src/panels/terminal/terminalpanel.cpp index c205374cdc..849d3f8c90 100644 --- a/src/panels/terminal/terminalpanel.cpp +++ b/src/panels/terminal/terminalpanel.cpp @@ -73,12 +73,19 @@ void TerminalPanel::terminalExited() emit hideTerminalPanel(); } +bool TerminalPanel::isHiddenInVisibleWindow() +{ + return parentWidget() + && parentWidget()->isHidden() + && m_terminal + && (m_terminal->foregroundProcessId() == -1); +} + void TerminalPanel::dockVisibilityChanged() { // Only react when the DockWidget itself (not some parent) is hidden. This way we don't // respond when e.g. Dolphin is minimized. - if (parentWidget() && parentWidget()->isHidden() && - m_terminal && (m_terminal->foregroundProcessId() == -1)) { + if (isHiddenInVisibleWindow()) { // Make sure that the following "cd /" command will not affect the view. disconnect(m_konsolePart, SIGNAL(currentDirectoryChanged(QString)), this, SLOT(slotKonsolePartCurrentDirectoryChanged(QString))); diff --git a/src/panels/terminal/terminalpanel.h b/src/panels/terminal/terminalpanel.h index 4c0b93a17a..edaa2a6f3b 100644 --- a/src/panels/terminal/terminalpanel.h +++ b/src/panels/terminal/terminalpanel.h @@ -54,6 +54,7 @@ public: */ void goHome(); QString currentWorkingDirectory(); + bool isHiddenInVisibleWindow(); public slots: void terminalExited();