~alan-griffiths/mir/0.21-hacks

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
/*
 * Copyright © 2013 Canonical Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU 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 warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authored By: Robert Carr <racarr@canonical.com>
 */

#ifndef MIR_SHELL_APPLICATION_SESSION_H_
#define MIR_SHELL_APPLICATION_SESSION_H_

#include "mir/shell/session.h"

#include <map>

namespace mir
{
class EventSink;

namespace shell
{
class SurfaceFactory;
class Surface;
class InputTargetListener;

class ApplicationSession : public Session
{
public:
    explicit ApplicationSession(std::shared_ptr<SurfaceFactory> const& surface_factory, 
        std::shared_ptr<InputTargetListener> const& input_target_listener, std::string const& session_name);
    ~ApplicationSession();

    frontend::SurfaceId create_surface(frontend::SurfaceCreationParameters const& params);
    void destroy_surface(frontend::SurfaceId surface);
    std::shared_ptr<frontend::Surface> get_surface(frontend::SurfaceId surface) const;

    std::shared_ptr<Surface> default_surface() const;

    std::string name() const;

    void force_requests_to_complete();

    void hide();
    void show();

    int configure_surface(frontend::SurfaceId id, MirSurfaceAttrib attrib, int value);

    void set_event_sink(std::shared_ptr<mir::EventSink> const& sink);

protected:
    ApplicationSession(ApplicationSession const&) = delete;
    ApplicationSession& operator=(ApplicationSession const&) = delete;

private:
    std::shared_ptr<SurfaceFactory> const surface_factory;
    std::shared_ptr<InputTargetListener> const input_target_listener;
    std::string const session_name;

    frontend::SurfaceId next_id();

    std::atomic<int> next_surface_id;

    typedef std::map<frontend::SurfaceId, std::shared_ptr<Surface>> Surfaces;
    Surfaces::const_iterator checked_find(frontend::SurfaceId id) const;
    std::mutex mutable surfaces_mutex;
    Surfaces surfaces;

    std::shared_ptr<EventSink> event_sink;
};

}
} // namespace mir

#endif // MIR_SHELL_APPLICATION_SESSION_H_