aboutsummaryrefslogtreecommitdiffstats
path: root/src/aglextras/hmi/aglwindow.cpp
blob: f1f55e67e1b7cd8b08c060358e0f1b66debcc069 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
 * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
 * Copyright (C) 2017 The Qt Company Ltd.
 * Copyright (c) 2017 Panasonic Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include "aglwindow.h"
#include "aglwindow_p.h"

#include <QtQuick/QQuickWindow>
#include <QtQml/QQmlApplicationEngine>

QT_BEGIN_NAMESPACE

AGLWindowPrivate::AGLWindowPrivate (AGLWindow*)
{
    ;
}

AGLWindowPrivate::~AGLWindowPrivate (void)
{
    ;
}

void AGLWindow::activate_surface (void)
{
    qDebug("Disconnect!! SLOT activate_surface()");
    QLibWindowmanager::disconnect(d_ptr->loading);

    activateSurface(QString(d_ptr->layout));
}

void AGLWindow::attach (QQmlApplicationEngine* engine)
{
    if (d_ptr->binding) {
        QQuickWindow *window = qobject_cast<QQuickWindow *>(engine->rootObjects().first());

        qDebug("Connect!! frameSapped! (activate_surface())");
        d_ptr->loading = QLibWindowmanager::connect(window, SIGNAL(frameSwapped()),
                                                    this, SLOT(activate_surface()));
    }
}

AGLWindow::AGLWindow (const QString& layout, int port, QString secret)
        : QLibWindowmanager(nullptr),
          d_ptr(new AGLWindowPrivate(this))

{
    if (port == -1) {
        qDebug("This is not AGL binding application");
        return;
    }

    if (QLibWindowmanager::init(port, secret) != 0 ||
        LibHomeScreen::init(port, secret.toStdString().c_str()) != 0) {
        qDebug("Cannot get binding API");
        return;
    }

    d_ptr->layout = layout;

    // Request a surface as described in layers.json windowmanager’s file
    if (requestSurface(d_ptr->layout) != 0) {
        qDebug("Cannot get surface for %s", qPrintable(d_ptr->layout));
        return;
    }

    d_ptr->binding = true;

    // Create an event callback against an event type. Here a lambda is called when SyncDraw event occurs
    QLibWindowmanager::set_event_handler (
        QLibWindowmanager::Event_SyncDraw,
        [this](json_object*) {
            qDebug("Surface got syncDraw!\n");
            endDraw(d_ptr->layout);
        }
        );

        // Set the event handler for Event_TapShortcut which will activate the surface for windowmanager
    LibHomeScreen::set_event_handler (
        LibHomeScreen::Event_TapShortcut,
        [this](json_object* object) {
            json_object *jo_app_name = nullptr;
            if(json_object_object_get_ex(object, "application_name", &jo_app_name)) {
                QString name(QLatin1String(json_object_get_string(jo_app_name)));
                if(d_ptr->layout == name) {
                    qDebug("Surface %s got tapShortcut\n", qPrintable(name));
                    activateSurface(d_ptr->layout);
                }
            }
        }
        );
}

QT_END_NAMESPACE