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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
/*
* Copyright © 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 2 or 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/>.
*/
#include "server_example_decoration.h"
#include "server-decoration_wrapper.h"
using mir::examples::ServerDecorationCreateCallback;
namespace mw = mir::wayland;
namespace
{
struct ServerDecoration :
mw::ServerDecoration
{
ServerDecoration(wl_resource* new_resource) :
mw::ServerDecoration::ServerDecoration(new_resource, Version<1>())
{
send_mode_event(decoration_mode);
}
void request_mode(uint32_t mode) override
{
if (mode != decoration_mode)
decoration_mode = mode;
send_mode_event(decoration_mode);
}
uint32_t decoration_mode = Mode::Server;
};
struct ServerDecorationManager : mw::ServerDecorationManager::Global
{
static int const interface_supported = 1;
ServerDecorationManager(struct wl_display* display) :
Global(display, Version<interface_supported>())
{
};
ServerDecorationManager(struct wl_display* display, ServerDecorationCreateCallback callback) :
Global(display, Version<interface_supported>()),
callback{callback}
{
};
class Instance : public mw::ServerDecorationManager
{
public:
Instance(wl_resource* new_resource, ::ServerDecorationManager* manager)
: mw::ServerDecorationManager(new_resource, Version<1>()),
manager{manager}
{
}
private:
void create(wl_resource* new_resource, wl_resource* surface) override
{
new ServerDecoration{new_resource};
manager->callback(wl_resource_get_client(resource), surface);
}
::ServerDecorationManager* const manager;
};
void bind(wl_resource* new_resource)
{
new Instance{new_resource, this};
}
ServerDecorationCreateCallback const callback = [](auto, auto) {};
};
int const ServerDecorationManager::interface_supported;
}
auto mir::examples::server_decoration_extension() -> miral::WaylandExtensions::Builder
{
return
{
wayland::ServerDecorationManager::interface_name,
[](miral::WaylandExtensions::Context const* context)
{
return std::make_shared<ServerDecorationManager>(context->display());
}
};
}
auto mir::examples::server_decoration_extension(ServerDecorationCreateCallback callback) -> miral::WaylandExtensions::Builder
{
return
{
wayland::ServerDecorationManager::interface_name,
[callback](miral::WaylandExtensions::Context const* context)
{
return std::make_shared<ServerDecorationManager>(context->display(), callback);
}
};
}
|