~gerboland/qtubuntu/enable-debug-mode

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
/*
 * Copyright (C) 2015 Canonical, Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License version 3, as published by
 * the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "debugextension.h"

#include <QDebug>

// mir client debug
#include <mir_toolkit/debug/surface.h>

UbuntuDebugExtension::UbuntuDebugExtension()
    : m_mirclientDebug(QStringLiteral("mirclient-debug-extension"), 1)
    , m_mapper(nullptr)
{
    qDebug() << "NOTICE: Loading mirclient-debug-extension";
    m_mapper = (MapperPrototype) m_mirclientDebug.resolve("mir_debug_surface_coords_to_screen");

    if (!m_mirclientDebug.isLoaded()) {
        qWarning() << "ERROR: mirclient-debug-extension failed to load:" << m_mirclientDebug.errorString();
    } else if (!m_mapper) {
        qWarning() << "ERROR: unable to find required symbols in mirclient-debug-extension:"
                   << m_mirclientDebug.errorString();
    }
}

QPoint UbuntuDebugExtension::mapSurfacePointToScreen(MirSurface *surface, const QPoint &point)
{
    if (!m_mapper) {
        return point;
    }

    QPoint mappedPoint;
    bool status = m_mapper(surface, point.x(), point.y(), &mappedPoint.rx(), &mappedPoint.ry());
    if (status) {
        return mappedPoint;
    } else {
        return point;
    }
}