2
* Copyright (C) 2013 Canonical Ltd
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License version 3 as
6
* 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 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/>.
16
* Authored by: Robert Carr <robert.carr@canonical.com>
19
#include "application_instance_mirserver_priv.h"
21
#include "mircommon/application_description_mir_priv.h"
22
#include "mircommon/application_options_mir_priv.h"
23
#include "mircommon/application_id_mir_priv.h"
25
#include <mir/scene/surface.h>
26
#include <mir/scene/surface_coordinator.h>
27
#include <mir/scene/session.h>
28
#include <mir/scene/session_listener.h>
29
#include <mir/scene/surface_creation_parameters.h>
30
#include <mir/scene/snapshot.h>
32
namespace uam = ubuntu::application::mir;
33
namespace uams = uam::server;
35
namespace mf = mir::frontend;
36
namespace ms = mir::scene;
40
/* A Mir in-process client does not have an associated Session by default. However it is
41
* useful for the shell to be able to position and identify its own surface, so need to
42
* create a mock implementation of Session for that respective Surface.
44
class InProcessClientSession : public ms::Session
47
virtual void force_requests_to_complete() override {}
48
virtual pid_t process_id() const override { return 0; }
49
virtual void take_snapshot(ms::SnapshotCallback const&) override {}
50
virtual std::shared_ptr<ms::Surface> default_surface() const override { return surface; }
51
virtual void set_lifecycle_state(MirLifecycleState) override {}
53
virtual mf::SurfaceId create_surface(ms::SurfaceCreationParameters const& ) override { return mf::SurfaceId(0); }
54
virtual void destroy_surface(mf::SurfaceId) override {}
55
virtual std::shared_ptr<mf::Surface> get_surface(mf::SurfaceId) const override { return surface; }
56
virtual std::string name() const override { return "Shell"; }
57
virtual void hide() override {}
58
virtual void show() override {}
59
virtual void send_display_config(mir::graphics::DisplayConfiguration const&) override {}
61
virtual void start_prompt_session() override {}
62
virtual void stop_prompt_session() override {}
64
std::shared_ptr<ms::Surface> const surface;
67
InProcessClientSession& global_session()
69
static InProcessClientSession session;
74
uams::Instance::Instance(std::shared_ptr<ms::SurfaceCoordinator> const &surface_coordinator,
75
std::shared_ptr<ms::SessionListener> const &session_listener,
76
uam::Description* description_,
77
uam::Options *options_)
78
: surface_coordinator(surface_coordinator),
79
session_listener(session_listener),
82
description = DescriptionPtr(description_,
83
[] (uam::Description* p)
87
options = OptionsPtr(options_,
94
UApplicationInstance* uams::Instance::as_u_application_instance()
96
return static_cast<UApplicationInstance*>(this);
99
uams::Instance* uams::Instance::from_u_application_instance(UApplicationInstance *u_instance)
101
return static_cast<uams::Instance*>(u_instance);
104
void uams::Instance::ref()
109
void uams::Instance::unref()
116
std::shared_ptr<ms::Surface> uams::Instance::create_surface(ms::SurfaceCreationParameters const& parameters)
118
ms::Session& session = global_session();
119
auto surface = surface_coordinator->add_surface(parameters, &session);
120
// Need to call the SessionListener ourselves, else shell not notified of this surface creation
121
session_listener->surface_created(session, surface);