diff options
author | Scott Murray <scott.murray@konsulko.com> | 2021-02-01 18:13:28 -0500 |
---|---|---|
committer | Scott Murray <scott.murray@konsulko.com> | 2021-02-04 16:58:37 +0000 |
commit | 8c5393ebb1f867796d817c3e218371860c2733cf (patch) | |
tree | 7d5a85092f2c2adc76c486530be2d2ca78598fb1 /app | |
parent | 8d4d7b9f636543c361d1d289baca4ee59e33f9ec (diff) |
Tweak things to center the windowkoi_11.0.5koi_11.0.4koi_11.0.3koi_11.0.2koi_11.0.1koi_11.0.0koi_10.93.1koi/11.0.5koi/11.0.4koi/11.0.3koi/11.0.2koi/11.0.1koi/11.0.0koi/10.93.111.0.511.0.411.0.311.0.211.0.111.0.010.93.1koi
Add a onCompleted hook in Main.qml to set it's x and y coordinates to
center the window, and rework instantiation of the qml in main.cpp so
that the resulting x and y values can be queried and used in a call to
set_window_props to actually position the window.
Bug-AGL: SPEC-3784
Signed-off-by: Scott Murray <scott.murray@konsulko.com>
Change-Id: I46e2dfac7c62c9afd379fd6bf7b7fa3277422cbc
(cherry picked from commit b587bf9d453f29656c2a52bc486881c0e3cb67c6)
Diffstat (limited to 'app')
-rw-r--r-- | app/Main.qml | 6 | ||||
-rw-r--r-- | app/main.cpp | 13 |
2 files changed, 18 insertions, 1 deletions
diff --git a/app/Main.qml b/app/Main.qml index 4011107..0b60d5c 100644 --- a/app/Main.qml +++ b/app/Main.qml @@ -29,6 +29,12 @@ Window { visible: true flags: Qt.FramelessWindowHint + Component.onCompleted: { + // Center window + root.x = root.screen.virtualX + root.screen.width / 2 - root.width / 2; + root.y = root.screen.virtualY + root.screen.height / 2 - root.height / 2; + } + BodyTemplateDialog { id: bodyTemplate anchors.centerIn: parent diff --git a/app/main.cpp b/app/main.cpp index 3c8792c..3751862 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -24,6 +24,8 @@ #include <QtQml/QQmlContext> #include <QtQml/qqml.h> #include <QQuickWindow> +#include <QQmlComponent> +#include <QQmlProperty> #include <QtQuickControls2/QQuickStyle> #include <qpa/qplatformnativeinterface.h> @@ -291,7 +293,16 @@ int main(int argc, char *argv[]) QQmlContext *context = engine.rootContext(); context->setContextProperty("homescreen", aglShell); context->setContextProperty("GuiMetadata", new GuiMetadata(bindingAddress, context)); - engine.load(QUrl(QStringLiteral("qrc:/Main.qml"))); + QQmlComponent component(&engine, + QUrl(QStringLiteral("qrc:/Main.qml"))); + QObject *object = component.create(); + + // Update window position based on component (x, y) + int x = QQmlProperty::read(object, "x").toInt(); + int y = QQmlProperty::read(object, "y").toInt(); + aglShell->set_window_props(nullptr, my_app_id, + AGL_SHELL_DESKTOP_APP_ROLE_POPUP, + x, y, 0, 0, 0, 0); // Create app framework client to handle events when window is not visible AfbClient client(port, token.toStdString()); |