+}
+
+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 (isHiddenInVisibleWindow()) {
+ // Make sure that the following "cd /" command will not affect the view.
+ disconnect(m_konsolePart, SIGNAL(currentDirectoryChanged(QString)),
+ this, SLOT(slotKonsolePartCurrentDirectoryChanged(QString)));
+
+ // Make sure this terminal does not prevent unmounting any removable drives
+ changeDir(QUrl::fromLocalFile(QStringLiteral("/")));
+
+ // Because we have disconnected from the part's currentDirectoryChanged()
+ // signal, we have to update m_konsolePartCurrentDirectory manually. If this
+ // was not done, showing the panel again might not set the part's working
+ // directory correctly.
+ m_konsolePartCurrentDirectory = '/';
+ }