2
* Copyright (C) 2014-2016 Canonical, Ltd.
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.
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.
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/>.
17
#include "surfaceobserver.h"
20
#include <QMutexLocker>
23
#include <miral/window_specification.h>
24
#include <mir/geometry/size.h>
29
QRect calculateBoundingRect(const std::vector<mir::geometry::Rectangle> &rectVector)
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());
41
QHash<const mir::scene::Surface*, SurfaceObserver*> surfaceToObserverMap;
43
} // anonymous namespace
46
SurfaceObserver::~SurfaceObserver()
48
QMutexLocker locker(&mutex);
49
QMutableHashIterator<const mir::scene::Surface*, SurfaceObserver*> i(surfaceToObserverMap);
52
if (i.value() == this) {
59
void SurfaceObserver::notifySurfaceModifications(const miral::WindowSpecification &modifications)
61
if (modifications.min_width().is_set()) {
62
Q_EMIT minimumWidthChanged(modifications.min_width().value().as_int());
64
if (modifications.min_height().is_set()) {
65
Q_EMIT minimumHeightChanged(modifications.min_height().value().as_int());
67
if (modifications.max_width().is_set()) {
68
Q_EMIT maximumWidthChanged(modifications.max_width().value().as_int());
70
if (modifications.max_height().is_set()) {
71
Q_EMIT maximumHeightChanged(modifications.max_height().value().as_int());
73
if (modifications.width_inc().is_set()) {
74
Q_EMIT widthIncrementChanged(modifications.width_inc().value().as_int());
76
if (modifications.height_inc().is_set()) {
77
Q_EMIT heightIncrementChanged(modifications.height_inc().value().as_int());
79
if (modifications.shell_chrome().is_set()) {
80
Q_EMIT shellChromeChanged(modifications.shell_chrome().value());
82
if (modifications.input_shape().is_set()) {
83
QRect qRect = calculateBoundingRect(modifications.input_shape().value());
84
Q_EMIT inputBoundsChanged(qRect);
86
if (modifications.confine_pointer().is_set()) {
87
Q_EMIT confinesMousePointerChanged(modifications.confine_pointer().value() == mir_pointer_confined_to_surface);
91
SurfaceObserver *SurfaceObserver::observerForSurface(const mir::scene::Surface *surface)
93
if (surfaceToObserverMap.contains(surface)) {
94
return surfaceToObserverMap.value(surface);
100
void SurfaceObserver::registerObserverForSurface(SurfaceObserver *observer, const mir::scene::Surface *surface)
102
QMutexLocker locker(&mutex);
103
surfaceToObserverMap[surface] = observer;