~vanvugt/mir/log-level

« back to all changes in this revision

Viewing changes to src/server/scene/session_manager.cpp

  • Committer: Daniel van Vugt
  • Date: 2015-01-23 03:08:41 UTC
  • mfrom: (2201.2.50 development-branch)
  • Revision ID: daniel.van.vugt@canonical.com-20150123030841-zn39cao9um2o9x0p
Merge latest trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include "session_container.h"
22
22
#include "mir/scene/surface.h"
23
23
#include "mir/scene/surface_coordinator.h"
24
 
#include "mir/shell/focus_setter.h"
25
24
#include "mir/scene/session.h"
26
25
#include "mir/scene/session_listener.h"
27
26
#include "mir/scene/prompt_session.h"
41
40
 
42
41
ms::SessionManager::SessionManager(std::shared_ptr<SurfaceCoordinator> const& surface_factory,
43
42
    std::shared_ptr<SessionContainer> const& container,
44
 
    std::shared_ptr<msh::FocusSetter> const& focus_setter,
45
43
    std::shared_ptr<SnapshotStrategy> const& snapshot_strategy,
46
44
    std::shared_ptr<SessionEventSink> const& session_event_sink,
47
45
    std::shared_ptr<SessionListener> const& session_listener,
48
46
    std::shared_ptr<PromptSessionManager> const& prompt_session_manager) :
49
47
    surface_coordinator(surface_factory),
50
48
    app_container(container),
51
 
    focus_setter(focus_setter),
52
49
    snapshot_strategy(snapshot_strategy),
53
50
    session_event_sink(session_event_sink),
54
51
    session_listener(session_listener),
56
53
{
57
54
    assert(surface_factory);
58
55
    assert(container);
59
 
    assert(focus_setter);
60
56
    assert(session_listener);
61
57
}
62
58
 
80
76
        close_session(session);
81
77
}
82
78
 
83
 
std::shared_ptr<mf::Session> ms::SessionManager::open_session(
 
79
std::shared_ptr<ms::Session> ms::SessionManager::open_session(
84
80
    pid_t client_pid,
85
81
    std::string const& name,
86
82
    std::shared_ptr<mf::EventSink> const& sender)
93
89
 
94
90
    session_listener->starting(new_session);
95
91
 
96
 
    set_focus_to(new_session);
97
 
 
98
92
    return new_session;
99
93
}
100
94
 
101
 
inline void ms::SessionManager::set_focus_to_locked(std::unique_lock<std::mutex> const&, std::shared_ptr<Session> const& session)
102
 
{
103
 
    auto old_focus = focus_application.lock();
104
 
 
105
 
    focus_application = session;
106
 
 
107
 
    focus_setter->set_focus_to(session);
108
 
    if (session)
109
 
    {
110
 
        session_event_sink->handle_focus_change(session);
111
 
        session_listener->focused(session);
112
 
    }
113
 
    else
114
 
    {
115
 
        session_event_sink->handle_no_focus();
116
 
        session_listener->unfocused();
117
 
    }
118
 
}
119
 
 
120
95
void ms::SessionManager::set_focus_to(std::shared_ptr<Session> const& session)
121
96
{
122
 
    std::unique_lock<std::mutex> lg(mutex);
123
 
    set_focus_to_locked(lg, session);
124
 
}
125
 
 
126
 
void ms::SessionManager::close_session(std::shared_ptr<mf::Session> const& session)
 
97
    session_event_sink->handle_focus_change(session);
 
98
    session_listener->focused(session);
 
99
}
 
100
 
 
101
void ms::SessionManager::unset_focus()
 
102
{
 
103
    session_event_sink->handle_no_focus();
 
104
    session_listener->unfocused();
 
105
}
 
106
 
 
107
void ms::SessionManager::close_session(std::shared_ptr<Session> const& session)
127
108
{
128
109
    auto scene_session = std::dynamic_pointer_cast<Session>(session);
129
110
 
136
117
    session_listener->stopping(scene_session);
137
118
 
138
119
    app_container->remove_session(scene_session);
139
 
 
140
 
    std::unique_lock<std::mutex> lock(mutex);
141
 
    set_focus_to_locked(lock, app_container->successor_of(std::shared_ptr<Session>()));
142
 
}
143
 
 
144
 
void ms::SessionManager::focus_next()
145
 
{
146
 
    std::unique_lock<std::mutex> lock(mutex);
147
 
    auto focus = focus_application.lock();
148
 
    if (!focus)
149
 
    {
150
 
        focus = app_container->successor_of(std::shared_ptr<Session>());
151
 
    }
152
 
    else
153
 
    {
154
 
        focus = app_container->successor_of(focus);
155
 
    }
156
 
    set_focus_to_locked(lock, focus);
157
 
}
158
 
 
159
 
std::weak_ptr<ms::Session> ms::SessionManager::focussed_application() const
160
 
{
161
 
    return focus_application;
162
 
}
163
 
 
164
 
void ms::SessionManager::handle_surface_created(std::shared_ptr<mf::Session> const& session)
165
 
{
166
 
    set_focus_to(std::dynamic_pointer_cast<Session>(session));
167
 
}
168
 
 
169
 
std::shared_ptr<mf::PromptSession> ms::SessionManager::start_prompt_session_for(std::shared_ptr<mf::Session> const& session,
 
120
}
 
121
 
 
122
std::shared_ptr<ms::PromptSession> ms::SessionManager::start_prompt_session_for(std::shared_ptr<Session> const& session,
170
123
    PromptSessionCreationParameters const& params)
171
124
{
172
125
    auto shell_session = std::dynamic_pointer_cast<Session>(session);
177
130
}
178
131
 
179
132
void ms::SessionManager::add_prompt_provider_for(
180
 
    std::shared_ptr<mf::PromptSession> const& prompt_session,
181
 
    std::shared_ptr<frontend::Session> const& session)
 
133
    std::shared_ptr<PromptSession> const& prompt_session,
 
134
    std::shared_ptr<Session> const& session)
182
135
{
183
136
    auto scene_prompt_session = std::dynamic_pointer_cast<PromptSession>(prompt_session);
184
137
    auto scene_session = std::dynamic_pointer_cast<Session>(session);
186
139
    prompt_session_manager->add_prompt_provider(scene_prompt_session, scene_session);
187
140
}
188
141
 
189
 
void ms::SessionManager::stop_prompt_session(std::shared_ptr<mf::PromptSession> const& prompt_session)
 
142
void ms::SessionManager::stop_prompt_session(std::shared_ptr<PromptSession> const& prompt_session)
190
143
{
191
144
    auto scene_prompt_session = std::dynamic_pointer_cast<PromptSession>(prompt_session);
192
145
    prompt_session_manager->stop_prompt_session(scene_prompt_session);
193
146
}
194
147
 
195
 
mf::SurfaceId ms::SessionManager::create_surface(std::shared_ptr<mf::Session> const& session, scene::SurfaceCreationParameters const& params)
196
 
{
197
 
    // TODO this downcasting is clunky, but is temporary wiring of the new interaction route to the old implementation
198
 
    if (auto const sess = std::dynamic_pointer_cast<Session>(session))
199
 
    {
200
 
        return sess->create_surface(params);
201
 
    }
202
 
 
203
 
    BOOST_THROW_EXCEPTION(std::logic_error("invalid session"));
204
 
}
205
 
 
206
 
void ms::SessionManager::destroy_surface(std::shared_ptr<mf::Session> const& session, mf::SurfaceId surface)
207
 
{
208
 
    // TODO this downcasting is clunky, but is temporary wiring of the new interaction route to the old implementation
209
 
    if (auto const sess = std::dynamic_pointer_cast<Session>(session))
210
 
    {
211
 
        return sess->destroy_surface(surface);
212
 
    }
213
 
 
214
 
    BOOST_THROW_EXCEPTION(std::logic_error("invalid session"));
215
 
}
216
 
 
217
 
int ms::SessionManager::set_surface_attribute(
218
 
    std::shared_ptr<mf::Session> const& session,
219
 
    mf::SurfaceId surface_id,
220
 
    MirSurfaceAttrib attrib,
221
 
    int value)
222
 
{
223
 
    // TODO this downcasting is clunky, but is temporary wiring of the new interaction route to the old implementation
224
 
    if (!session)
225
 
        BOOST_THROW_EXCEPTION(std::logic_error("invalid session"));
226
 
 
227
 
    auto const surface = std::dynamic_pointer_cast<Surface>(session->get_surface(surface_id));
228
 
 
229
 
    if (!surface)
230
 
        BOOST_THROW_EXCEPTION(std::logic_error("invalid surface id"));
231
 
 
232
 
    return surface->configure(attrib, value);
233
 
}
234
 
 
235
 
int ms::SessionManager::get_surface_attribute(
236
 
    std::shared_ptr<mf::Session> const& session,
237
 
    mf::SurfaceId surface_id,
238
 
    MirSurfaceAttrib attrib)
239
 
{
240
 
    // TODO this downcasting is clunky, but is temporary wiring of the new interaction route to the old implementation
241
 
    if (!session)
242
 
        BOOST_THROW_EXCEPTION(std::logic_error("invalid session"));
243
 
 
244
 
    auto const surface = std::dynamic_pointer_cast<Surface>(session->get_surface(surface_id));
245
 
 
246
 
    if (!surface)
247
 
        BOOST_THROW_EXCEPTION(std::logic_error("invalid surface id"));
248
 
 
249
 
    return surface->query(attrib);
 
148
std::shared_ptr<ms::Session> ms::SessionManager::successor_of(
 
149
    std::shared_ptr<Session> const& session) const
 
150
{
 
151
    return app_container->successor_of(session);
250
152
}