2
* Copyright © 2014 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 3,
6
* as published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Robert Carr <robert.carr@canonical.com>
19
#include "legacy_surface_change_notification.h"
21
#include "mir/scene/legacy_scene_change_notification.h"
22
#include "mir/scene/surface.h"
24
#include <boost/throw_exception.hpp>
26
namespace ms = mir::scene;
28
ms::LegacySceneChangeNotification::LegacySceneChangeNotification(
29
std::function<void()> const& scene_notify_change,
30
std::function<void(int)> const& buffer_notify_change)
31
: scene_notify_change(scene_notify_change),
32
buffer_notify_change(buffer_notify_change)
37
ms::LegacySceneChangeNotification::~LegacySceneChangeNotification()
42
void ms::LegacySceneChangeNotification::add_surface_observer(ms::Surface* surface)
44
auto observer = std::make_shared<ms::LegacySurfaceChangeNotification>(
45
scene_notify_change, buffer_notify_change);
46
surface->add_observer(observer);
49
std::unique_lock<decltype(surface_observers_guard)> lg(surface_observers_guard);
50
surface_observers[surface] = observer;
53
scene_notify_change();
56
void ms::LegacySceneChangeNotification::surface_added(ms::Surface* surface)
58
add_surface_observer(surface);
61
void ms::LegacySceneChangeNotification::surface_exists(ms::Surface* surface)
63
add_surface_observer(surface);
66
void ms::LegacySceneChangeNotification::surface_removed(ms::Surface* surface)
69
std::unique_lock<decltype(surface_observers_guard)> lg(surface_observers_guard);
70
auto it = surface_observers.find(surface);
71
if (it != surface_observers.end())
73
surface->remove_observer(it->second);
74
surface_observers.erase(it);
77
scene_notify_change();
80
void ms::LegacySceneChangeNotification::surfaces_reordered()
82
scene_notify_change();
85
void ms::LegacySceneChangeNotification::end_observation()
87
std::unique_lock<decltype(surface_observers_guard)> lg(surface_observers_guard);
88
for (auto &kv : surface_observers)
90
auto surface = kv.first;
92
surface->remove_observer(kv.second);
94
surface_observers.clear();