From ec1a0c2543a590dd5bd49c3dfe27f77a27fcb05f Mon Sep 17 00:00:00 2001 From: Andrey Yashkin Date: Sun, 11 Aug 2019 13:11:37 +0200 Subject: [PATCH] Fix an issue with focus lost after closing terminal panel Summary: After leaving terminal with Ctrl-D or exit commands the input focus isn't set back to the folder view. The problem appears, because `TerminalPanel::isHiddenInVisibleWindow` returns not what it supposed to return, since when the terminal process exits, `m_terminal` is set to nullptr. I moved unwanted checks from it inside `TerminalPanel::dockVisibilityChanged` This change also exposes a crash in `DolphinMainWindow::slotTerminalPanelVisibilityChanged()`, which was previously working only by luck. Now we check whether `m_activeViewContainer` is not null before using it. BUG: 407979 FIXED-IN: 19.11.80 Test Plan: 1. Open Dolphin 2. Press F4 to open the terminal panel 3. Type exit or press Ctrl-D 4. Check current focus widget Reviewers: #dolphin Subscribers: ngraham, elvisangelaccio, kfm-devel Tags: #dolphin Differential Revision: https://phabricator.kde.org/D22420 --- src/dolphinmainwindow.cpp | 2 +- src/panels/terminal/terminalpanel.cpp | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 19f7906629..ad193b0517 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -751,7 +751,7 @@ void DolphinMainWindow::togglePanelLockState() void DolphinMainWindow::slotTerminalPanelVisibilityChanged() { - if (m_terminalPanel->isHiddenInVisibleWindow()) { + if (m_terminalPanel->isHiddenInVisibleWindow() && m_activeViewContainer) { m_activeViewContainer->view()->setFocus(); } } diff --git a/src/panels/terminal/terminalpanel.cpp b/src/panels/terminal/terminalpanel.cpp index 52d2a77df7..86974d200e 100644 --- a/src/panels/terminal/terminalpanel.cpp +++ b/src/panels/terminal/terminalpanel.cpp @@ -82,16 +82,14 @@ void TerminalPanel::terminalExited() bool TerminalPanel::isHiddenInVisibleWindow() const { return parentWidget() - && parentWidget()->isHidden() - && m_terminal - && !hasProgramRunning(); + && parentWidget()->isHidden(); } 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 (isHiddenInVisibleWindow()) { + if (isHiddenInVisibleWindow() && m_terminal && !hasProgramRunning()) { // Make sure that the following "cd /" command will not affect the view. disconnect(m_konsolePart, SIGNAL(currentDirectoryChanged(QString)), this, SLOT(slotKonsolePartCurrentDirectoryChanged(QString)));