~alan-griffiths/miral/fix-1645284

« back to all changes in this revision

Viewing changes to miral-qt/src/platforms/mirserver/surfaceobserver.cpp

  • Committer: Alan Griffiths
  • Date: 2016-11-07 17:59:19 UTC
  • mfrom: (436.1.1 miral2)
  • Revision ID: alan@octopull.co.uk-20161107175919-stbb64i7j1htgog2
[miral-qt] delete all as qtmir work on MirAL has shifted to lp:~unity-team/qtmir/miral-qt-integration and this is a needless distration

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2014-2016 Canonical, Ltd.
3
 
 *
4
 
 * This program is free software: you can redistribute it and/or modify it under
5
 
 * the terms of the GNU Lesser General Public License version 3, as published by
6
 
 * the Free Software Foundation.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 
 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10
 
 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
 
 * Lesser General Public License for more details.
12
 
 *
13
 
 * You should have received a copy of the GNU Lesser General Public License
14
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 
 */
16
 
 
17
 
#include "surfaceobserver.h"
18
 
 
19
 
#include <QHash>
20
 
#include <QMutexLocker>
21
 
#include <QMutex>
22
 
 
23
 
#include <miral/window_specification.h>
24
 
#include <mir/geometry/size.h>
25
 
 
26
 
 
27
 
namespace {
28
 
 
29
 
QRect calculateBoundingRect(const std::vector<mir::geometry::Rectangle> &rectVector)
30
 
{
31
 
    QRect boundingRect;
32
 
    for (auto mirRect : rectVector) {
33
 
        boundingRect |= QRect(mirRect.top_left.x.as_int(),
34
 
                mirRect.top_left.y.as_int(),
35
 
                mirRect.size.width.as_int(),
36
 
                mirRect.size.height.as_int());
37
 
    }
38
 
    return boundingRect;
39
 
}
40
 
 
41
 
QHash<const mir::scene::Surface*, SurfaceObserver*> surfaceToObserverMap;
42
 
QMutex mutex;
43
 
} // anonymous namespace
44
 
 
45
 
 
46
 
SurfaceObserver::~SurfaceObserver()
47
 
{
48
 
    QMutexLocker locker(&mutex);
49
 
    QMutableHashIterator<const mir::scene::Surface*, SurfaceObserver*> i(surfaceToObserverMap);
50
 
    while (i.hasNext()) {
51
 
        i.next();
52
 
        if (i.value() == this) {
53
 
            i.remove();
54
 
            return;
55
 
        }
56
 
    }
57
 
}
58
 
 
59
 
void SurfaceObserver::notifySurfaceModifications(const miral::WindowSpecification &modifications)
60
 
{
61
 
    if (modifications.min_width().is_set()) {
62
 
        Q_EMIT minimumWidthChanged(modifications.min_width().value().as_int());
63
 
    }
64
 
    if (modifications.min_height().is_set()) {
65
 
        Q_EMIT minimumHeightChanged(modifications.min_height().value().as_int());
66
 
    }
67
 
    if (modifications.max_width().is_set()) {
68
 
        Q_EMIT maximumWidthChanged(modifications.max_width().value().as_int());
69
 
    }
70
 
    if (modifications.max_height().is_set()) {
71
 
        Q_EMIT maximumHeightChanged(modifications.max_height().value().as_int());
72
 
    }
73
 
    if (modifications.width_inc().is_set()) {
74
 
        Q_EMIT widthIncrementChanged(modifications.width_inc().value().as_int());
75
 
    }
76
 
    if (modifications.height_inc().is_set()) {
77
 
        Q_EMIT heightIncrementChanged(modifications.height_inc().value().as_int());
78
 
    }
79
 
    if (modifications.shell_chrome().is_set()) {
80
 
        Q_EMIT shellChromeChanged(modifications.shell_chrome().value());
81
 
    }
82
 
    if (modifications.input_shape().is_set()) {
83
 
        QRect qRect = calculateBoundingRect(modifications.input_shape().value());
84
 
        Q_EMIT inputBoundsChanged(qRect);
85
 
    }
86
 
    if (modifications.confine_pointer().is_set()) {
87
 
        Q_EMIT confinesMousePointerChanged(modifications.confine_pointer().value() == mir_pointer_confined_to_surface);
88
 
    }
89
 
}
90
 
 
91
 
SurfaceObserver *SurfaceObserver::observerForSurface(const mir::scene::Surface *surface)
92
 
{
93
 
    if (surfaceToObserverMap.contains(surface)) {
94
 
        return surfaceToObserverMap.value(surface);
95
 
    } else {
96
 
        return nullptr;
97
 
    }
98
 
}
99
 
 
100
 
void SurfaceObserver::registerObserverForSurface(SurfaceObserver *observer, const mir::scene::Surface *surface)
101
 
{
102
 
    QMutexLocker locker(&mutex);
103
 
    surfaceToObserverMap[surface] = observer;
104
 
}