This fixes two minor inconveniences: - When closing the chat window and re-showing it from the systray icon, the geometry was not properly restored. The window was always shown in the middle of the screen. Now, one gets the window back with it's actual last position and size. - It is now possible to not only show the window from the systray icon, but also to close it. This is the way other chat programs do it (Kopete back in the day, Konversation, Quassel IRC etc.)
75 lines
1.8 KiB
C++
75 lines
1.8 KiB
C++
// SPDX-FileCopyrightText: 2022 Nicolas Fella <nicolas.fella@gmx.de>
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#include "windowcontroller.h"
|
|
|
|
#include <KConfig>
|
|
#include <KWindowConfig>
|
|
|
|
#ifdef HAVE_WINDOWSYSTEM
|
|
#if HAVE_X11
|
|
#include <KStartupInfo>
|
|
#endif
|
|
#include <KWindowSystem>
|
|
#endif
|
|
|
|
#include <QStandardPaths>
|
|
|
|
WindowController &WindowController::instance()
|
|
{
|
|
static WindowController instance;
|
|
return instance;
|
|
}
|
|
|
|
void WindowController::setWindow(QWindow *window)
|
|
{
|
|
m_window = window;
|
|
|
|
Q_EMIT windowChanged();
|
|
}
|
|
|
|
QWindow *WindowController::window() const
|
|
{
|
|
return m_window;
|
|
}
|
|
|
|
void WindowController::restoreGeometry()
|
|
{
|
|
KConfig dataResource(QStringLiteral("data"), KConfig::SimpleConfig, QStandardPaths::AppDataLocation);
|
|
KConfigGroup windowGroup(&dataResource, QStringLiteral("Window"));
|
|
KWindowConfig::restoreWindowSize(m_window, windowGroup);
|
|
KWindowConfig::restoreWindowPosition(m_window, windowGroup);
|
|
}
|
|
|
|
void WindowController::saveGeometry()
|
|
{
|
|
KConfig dataResource(QStringLiteral("data"), KConfig::SimpleConfig, QStandardPaths::AppDataLocation);
|
|
KConfigGroup windowGroup(&dataResource, QStringLiteral("Window"));
|
|
KWindowConfig::saveWindowPosition(m_window, windowGroup);
|
|
KWindowConfig::saveWindowSize(m_window, windowGroup);
|
|
}
|
|
|
|
void WindowController::showAndRaiseWindow(const QString &startupId)
|
|
{
|
|
if (!m_window->isVisible()) {
|
|
m_window->show();
|
|
restoreGeometry();
|
|
}
|
|
|
|
#ifdef HAVE_WINDOWSYSTEM
|
|
if (!startupId.isEmpty()) {
|
|
if (KWindowSystem::isPlatformX11()) {
|
|
#if HAVE_X11
|
|
KStartupInfo::setNewStartupId(m_window, startupId.toUtf8());
|
|
#endif
|
|
} else if (KWindowSystem::isPlatformWayland()) {
|
|
KWindowSystem::setCurrentXdgActivationToken(startupId);
|
|
}
|
|
}
|
|
|
|
KWindowSystem::activateWindow(m_window);
|
|
#endif
|
|
}
|
|
|
|
#include "moc_windowcontroller.cpp"
|