Refactor window handling code

Currently when we want to show/raise the window in reaction to the tray icon/notification being clicked etc we do this by emitting a signal on the controller.
This is connected to in main.qml, which does some things, then calls back to controller to do more things.

This is quite convoluted. Instead introduce a new class WindowController that is responsible for all things window, in particular showing/raising and config saving
This commit is contained in:
Nicolas Fella
2022-09-01 22:58:43 +02:00
committed by Tobias Fella
parent 736c4b02ed
commit 55847cb9cc
10 changed files with 106 additions and 84 deletions

View File

@@ -75,6 +75,7 @@
#include "userdirectorylistmodel.h"
#include "userlistmodel.h"
#include "webshortcutmodel.h"
#include "windowcontroller.h"
#include <room.h>
#ifdef HAVE_COLORSCHEME
#include "colorschemer.h"
@@ -95,21 +96,6 @@ class NetworkAccessManagerFactory : public QQmlNetworkAccessManagerFactory
}
};
#ifdef HAVE_WINDOWSYSTEM
static void raiseWindow(QWindow *window)
{
#if KWINDOWSYSTEM_VERSION >= QT_VERSION_CHECK(5, 91, 0)
KWindowSystem::updateStartupId(window);
#else
if (KWindowSystem::isPlatformWayland()) {
KWindowSystem::setCurrentXdgActivationToken(qEnvironmentVariable("XDG_ACTIVATION_TOKEN"));
}
#endif
KWindowSystem::activateWindow(window->winId());
window->raise();
}
#endif
static QWindow *windowFromEngine(QQmlApplicationEngine *engine)
{
const auto rootObjects = engine->rootObjects();
@@ -238,12 +224,6 @@ int main(int argc, char *argv[])
qRegisterMetaType<GetRoomEventsJob *>("GetRoomEventsJob*");
qRegisterMetaType<QMimeType>("QMimeType");
#ifdef HAVE_WINDOWSYSTEM
qmlRegisterSingletonType<KWindowSystem>("org.kde.kwindowsystem.private", 1, 0, "KWindowSystem", [](QQmlEngine *, QJSEngine *) -> QObject * {
return KWindowSystem::self();
});
#endif
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
qRegisterMetaTypeStreamOperators<Emoji>();
#endif
@@ -291,12 +271,9 @@ int main(int argc, char *argv[])
Q_UNUSED(workingDirectory);
QWindow *window = windowFromEngine(&engine);
KWindowSystem::updateStartupId(window);
if (!window->isVisible()) {
window->show();
}
raiseWindow(window);
WindowController::instance().showAndRaiseWindow(QString());
// Open matrix uri
if (arguments.isEmpty()) {
@@ -312,9 +289,8 @@ int main(int argc, char *argv[])
QWindow *window = windowFromEngine(&engine);
if (window->isVisible()) {
Controller::instance().restoreWindowGeometry(window);
}
WindowController::instance().setWindow(window);
WindowController::instance().restoreGeometry();
return app.exec();
}