Files
neochat/src/windowcontroller.cpp
Laurent Montel 6d45d126f8 Add explicit moc includes to sources for moc-covered headers
Add missing #pragma once + missing include

* speeds up incremental builds as changes to a header will not always
  need the full mocs_compilation.cpp for all the target's headers rebuild,
  while having a moc file sourced into a source file only adds minor
  extra costs, due to small own code and the used headers usually
  already covered by the source file, being for the same class/struct
* seems to not slow down clean builds, due to empty mocs_compilation.cpp
  resulting in those quickly processed, while the minor extra cost of the
  sourced moc files does not outweigh that in summary.
  Measured times actually improved by some percent points.
  (ideally CMake would just skip empty mocs_compilation.cpp & its object
  file one day)
* enables compiler to see all methods of a class in same compilation unit
  to do some sanity checks
* potentially more inlining in general, due to more in the compilation unit
* allows to keep using more forward declarations in the header, as with the
  moc code being sourced into the cpp file there definitions can be ensured
  and often are already for the needs of the normal class methods
2023-07-12 13:15:19 +00:00

74 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("data", KConfig::SimpleConfig, QStandardPaths::AppDataLocation);
KConfigGroup windowGroup(&dataResource, "Window");
KWindowConfig::restoreWindowSize(m_window, windowGroup);
KWindowConfig::restoreWindowPosition(m_window, windowGroup);
}
void WindowController::saveGeometry()
{
KConfig dataResource("data", KConfig::SimpleConfig, QStandardPaths::AppDataLocation);
KConfigGroup windowGroup(&dataResource, "Window");
KWindowConfig::saveWindowPosition(m_window, windowGroup);
KWindowConfig::saveWindowSize(m_window, windowGroup);
}
void WindowController::showAndRaiseWindow(const QString &startupId)
{
if (!m_window->isVisible()) {
m_window->show();
}
#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"