summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/qnx/qqnxbpseventfilter.cpp
blob: f5185e3eb7504845936d706328fa2d6fc71924e0 (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/***************************************************************************
**
** Copyright (C) 2012 Research In Motion
** Contact: http://www.qt-project.org/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qqnxbpseventfilter.h"
#include "qqnxnavigatoreventhandler.h"
#include "qqnxscreen.h"
#include "qqnxscreeneventhandler.h"
#include "qqnxvirtualkeyboardbps.h"

#include <QAbstractEventDispatcher>
#include <QDebug>

#include <bps/event.h>
#include <bps/navigator.h>
#include <bps/screen.h>

#ifdef QQNXBPSEVENTFILTER_DEBUG
#define qBpsEventFilterDebug qDebug
#else
#define qBpsEventFilterDebug QT_NO_QDEBUG_MACRO
#endif

QT_BEGIN_NAMESPACE

static QQnxBpsEventFilter *s_instance = 0;

QQnxBpsEventFilter::QQnxBpsEventFilter(QQnxNavigatorEventHandler *navigatorEventHandler,
                                       QQnxScreenEventHandler *screenEventHandler,
                                       QQnxVirtualKeyboardBps *virtualKeyboard, QObject *parent)
    : QObject(parent)
    , m_navigatorEventHandler(navigatorEventHandler)
    , m_screenEventHandler(screenEventHandler)
    , m_virtualKeyboard(virtualKeyboard)
{
    Q_ASSERT(s_instance == 0);

    s_instance = this;
}

QQnxBpsEventFilter::~QQnxBpsEventFilter()
{
    Q_ASSERT(s_instance == this);

    s_instance = 0;
}

void QQnxBpsEventFilter::installOnEventDispatcher(QAbstractEventDispatcher *dispatcher)
{
    qBpsEventFilterDebug() << Q_FUNC_INFO << "dispatcher=" << dispatcher;

    if (navigator_request_events(0) != BPS_SUCCESS)
        qWarning("QQNX: failed to register for navigator events");

    QAbstractEventDispatcher::EventFilter previousEventFilter = dispatcher->setEventFilter(dispatcherEventFilter);

    // the QPA plugin creates the event dispatcher so we are the first event
    // filter assert on that just in case somebody adds another event filter
    // in the QQnxIntegration constructor instead of adding a new section in here
    Q_ASSERT(previousEventFilter == 0);
    Q_UNUSED(previousEventFilter);
}

void QQnxBpsEventFilter::registerForScreenEvents(QQnxScreen *screen)
{
    if (screen_request_events(screen->nativeContext()) != BPS_SUCCESS)
        qWarning("QQNX: failed to register for screen events on screen %p", screen->nativeContext());
}

void QQnxBpsEventFilter::unregisterForScreenEvents(QQnxScreen *screen)
{
    if (screen_stop_events(screen->nativeContext()) != BPS_SUCCESS)
        qWarning("QQNX: failed to unregister for screen events on screen %p", screen->nativeContext());
}

bool QQnxBpsEventFilter::dispatcherEventFilter(void *message)
{
    qBpsEventFilterDebug() << Q_FUNC_INFO;

    if (s_instance == 0)
        return false;

    bps_event_t *event = static_cast<bps_event_t *>(message);
    return s_instance->bpsEventFilter(event);
}

bool QQnxBpsEventFilter::bpsEventFilter(bps_event_t *event)
{
    const int eventDomain = bps_event_get_domain(event);
    qBpsEventFilterDebug() << Q_FUNC_INFO << "event=" << event << "domain=" << eventDomain;

    if (eventDomain == screen_get_domain()) {
        screen_event_t screenEvent = screen_event_get_event(event);
        return m_screenEventHandler->handleEvent(screenEvent);
    }

    if (eventDomain == navigator_get_domain())
        return handleNavigatorEvent(event);

    if (m_virtualKeyboard->handleEvent(event))
        return true;

    return false;
}

bool QQnxBpsEventFilter::handleNavigatorEvent(bps_event_t *event)
{
    switch (bps_event_get_code(event)) {
    case NAVIGATOR_ORIENTATION_CHECK: {
        const int angle = navigator_event_get_orientation_angle(event);
        qBpsEventFilterDebug() << Q_FUNC_INFO << "ORIENTATION CHECK event. angle=" << angle;

        const bool result = m_navigatorEventHandler->handleOrientationCheck(angle);
        qBpsEventFilterDebug() << Q_FUNC_INFO << "ORIENTATION CHECK event. result=" << result;

        // reply to navigator whether orientation is acceptable
        navigator_orientation_check_response(event, result);
        break;
    }

    case NAVIGATOR_ORIENTATION: {
        const int angle = navigator_event_get_orientation_angle(event);
        qBpsEventFilterDebug() << Q_FUNC_INFO << "ORIENTATION event. angle=" << angle;
        m_navigatorEventHandler->handleOrientationChange(angle);

        navigator_done_orientation(event);
        break;
    }

    case NAVIGATOR_SWIPE_DOWN:
        qBpsEventFilterDebug() << Q_FUNC_INFO << "SWIPE DOWN event";
        m_navigatorEventHandler->handleSwipeDown();
        break;

    case NAVIGATOR_EXIT:
        qBpsEventFilterDebug() << Q_FUNC_INFO << "EXIT event";
        m_navigatorEventHandler->handleExit();
        break;

    case NAVIGATOR_WINDOW_ACTIVE: {
        qBpsEventFilterDebug() << Q_FUNC_INFO << "WINDOW ACTIVE event";
        const QByteArray id(navigator_event_get_groupid(event));
        m_navigatorEventHandler->handleWindowGroupActivated(id);
        break;
    }

    case NAVIGATOR_WINDOW_INACTIVE: {
        qBpsEventFilterDebug() << Q_FUNC_INFO << "WINDOW INACTIVE event";
        const QByteArray id(navigator_event_get_groupid(event));
        m_navigatorEventHandler->handleWindowGroupDeactivated(id);
        break;
    }

    default:
        qBpsEventFilterDebug() << Q_FUNC_INFO << "Unhandled navigator event. code=" << bps_event_get_code(event);
        return false;
    }

    return true;
}

QT_END_NAMESPACE