Commit 89e43dba authored by Friedrich W. H. Kossebau's avatar Friedrich W. H. Kossebau
Browse files

Hide window to systray using SNI, for consistent storing of any window info

parent 162e99df
......@@ -14,6 +14,7 @@
#include "scriptlauncher.h"
#include "transfermanager.h"
#include "viewcontainer.h"
#include "trayicon.h"
#include "urlcatcher.h"
#include "highlight.h"
#include "sound.h"
......@@ -208,7 +209,7 @@ QT_WARNING_POP
if (restoreMode == WindowRestore)
mainWindow->restore();
else if (Preferences::self()->showTrayIcon() && Preferences::self()->hideToTrayOnStartup())
mainWindow->hide();
mainWindow->systemTrayIcon()->hideWindow();
else
mainWindow->show();
......
......@@ -621,7 +621,7 @@ void MainWindow::activateAndRaiseWindow()
if (isMinimized())
KWindowSystem::unminimizeWindow(winId());
else if (Preferences::self()->showTrayIcon() && !isVisible())
m_trayIcon->restore();
m_trayIcon->restoreWindow();
KWindowSystem::setOnDesktop(winId(), KWindowSystem::currentDesktop());
KWindowSystem::activateWindow(winId());
......@@ -658,7 +658,7 @@ bool MainWindow::queryClose()
KStandardGuiItem::cancel(),
QStringLiteral("HideOnCloseInfo")) == KMessageBox::Continue;
if (doit)
hide();
m_trayIcon->hideWindow();
return false;
}
......@@ -680,6 +680,8 @@ bool MainWindow::restore()
KConfigGroup config(KConfigGui::sessionConfig(), QStringLiteral("1"));
const bool show = !config.readEntry("docked", false);
// TODO: also save & restore any TrayIcon state, needs API in KStatusNotifierItem
return KXmlGuiWindow::restore(1, show);
}
......@@ -940,7 +942,7 @@ void MainWindow::toggleVisibility()
if (isActiveWindow())
{
if (Preferences::self()->showTrayIcon())
hide();
m_trayIcon->hideWindow();
else
KWindowSystem::minimizeWindow(winId());
}
......
......@@ -27,8 +27,30 @@ namespace Konversation
{
}
void TrayIcon::restore()
void TrayIcon::hideWindow()
{
QWidget *window = associatedWidget();
if (window->isHidden())
return;
// hiding via the KStatusNotifierItem also stores any window system info, like "Show on all desktops"
// TODO: KStatusNotifierItem only hides if not minimized, needs new API in KStatusNotifierItem
// unminimizing instead as work-around needs to wait until the state is reached, not simple to do
// For now just doing a plain hide and losing any such info, as after all
// hiding a minimized window might not be done by many users
if (window->isMinimized())
{
window->hide();
return;
}
// activating when the window is visible hides it
activate(QPoint());
}
void TrayIcon::restoreWindow()
{
if (associatedWidget()->isVisible())
return;
activate(QPoint());
}
......
......@@ -24,7 +24,8 @@ namespace Konversation
bool notificationEnabled() { return m_notificationEnabled; }
void restore();
void restoreWindow();
void hideWindow();
public Q_SLOTS:
void startNotification();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment