/*
 * AUTOGENERATED - DO NOT EDIT
 *
 * This file is generated from wayland.xml
 * To regenerate, run the “refresh-wayland-wrapper” target.
 */

#include "wayland_wrapper.h"

#include <boost/throw_exception.hpp>
#include <boost/exception/diagnostic_information.hpp>

#include <wayland-server-core.h>

#include "mir/log.h"

namespace mir
{
namespace wayland
{
extern struct wl_interface const wl_buffer_interface_data;
extern struct wl_interface const wl_callback_interface_data;
extern struct wl_interface const wl_compositor_interface_data;
extern struct wl_interface const wl_data_device_interface_data;
extern struct wl_interface const wl_data_device_manager_interface_data;
extern struct wl_interface const wl_data_offer_interface_data;
extern struct wl_interface const wl_data_source_interface_data;
extern struct wl_interface const wl_keyboard_interface_data;
extern struct wl_interface const wl_output_interface_data;
extern struct wl_interface const wl_pointer_interface_data;
extern struct wl_interface const wl_region_interface_data;
extern struct wl_interface const wl_seat_interface_data;
extern struct wl_interface const wl_shell_interface_data;
extern struct wl_interface const wl_shell_surface_interface_data;
extern struct wl_interface const wl_shm_interface_data;
extern struct wl_interface const wl_shm_pool_interface_data;
extern struct wl_interface const wl_subcompositor_interface_data;
extern struct wl_interface const wl_subsurface_interface_data;
extern struct wl_interface const wl_surface_interface_data;
extern struct wl_interface const wl_touch_interface_data;
}
}

namespace mw = mir::wayland;

namespace
{
struct wl_interface const* all_null_types [] {
    nullptr,
    nullptr,
    nullptr,
    nullptr,
    nullptr,
    nullptr};
}

// Callback

mw::Callback* mw::Callback::from(struct wl_resource* resource)
{
    return static_cast<Callback*>(wl_resource_get_user_data(resource));
}

struct mw::Callback::Thunks
{
    static int const supported_version;

    static struct wl_message const event_messages[];
};

int const mw::Callback::Thunks::supported_version = 1;

mw::Callback::Callback(struct wl_resource* resource, Version<1>)
    : client{wl_resource_get_client(resource)},
      resource{resource}
{
    if (resource == nullptr)
    {
        BOOST_THROW_EXCEPTION((std::bad_alloc{}));
    }
}

void mw::Callback::send_done_event(uint32_t callback_data) const
{
    wl_resource_post_event(resource, Opcode::done, callback_data);
}

void mw::Callback::destroy_wayland_object() const
{
    wl_resource_destroy(resource);
}

struct wl_message const mw::Callback::Thunks::event_messages[] {
    {"done", "u", all_null_types}};

// Compositor

mw::Compositor* mw::Compositor::from(struct wl_resource* resource)
{
    return static_cast<Compositor*>(wl_resource_get_user_data(resource));
}

struct mw::Compositor::Thunks
{
    static int const supported_version;

    static void create_surface_thunk(struct wl_client* client, struct wl_resource* resource, uint32_t id)
    {
        auto me = static_cast<Compositor*>(wl_resource_get_user_data(resource));
        wl_resource* id_resolved{
            wl_resource_create(client, &wl_surface_interface_data, wl_resource_get_version(resource), id)};
        if (id_resolved == nullptr)
        {
            wl_client_post_no_memory(client);
            BOOST_THROW_EXCEPTION((std::bad_alloc{}));
        }
        try
        {
            me->create_surface(id_resolved);
        }
        catch(...)
        {
            internal_error_processing_request(client, "Compositor::create_surface()");
        }
    }

    static void create_region_thunk(struct wl_client* client, struct wl_resource* resource, uint32_t id)
    {
        auto me = static_cast<Compositor*>(wl_resource_get_user_data(resource));
        wl_resource* id_resolved{
            wl_resource_create(client, &wl_region_interface_data, wl_resource_get_version(resource), id)};
        if (id_resolved == nullptr)
        {
            wl_client_post_no_memory(client);
            BOOST_THROW_EXCEPTION((std::bad_alloc{}));
        }
        try
        {
            me->create_region(id_resolved);
        }
        catch(...)
        {
            internal_error_processing_request(client, "Compositor::create_region()");
        }
    }

    static void resource_destroyed_thunk(wl_resource* resource)
    {
        delete static_cast<Compositor*>(wl_resource_get_user_data(resource));
    }

    static void bind_thunk(struct wl_client* client, void* data, uint32_t version, uint32_t id)
    {
        auto me = static_cast<Compositor::Global*>(data);
        auto resource = wl_resource_create(
            client,
            &wl_compositor_interface_data,
            std::min((int)version, Thunks::supported_version),
            id);
        if (resource == nullptr)
        {
            wl_client_post_no_memory(client);
            BOOST_THROW_EXCEPTION((std::bad_alloc{}));
        }
        try
        {
            me->bind(resource);
        }
        catch(...)
        {
            internal_error_processing_request(client, "Compositor global bind");
        }
    }

    static struct wl_interface const* create_surface_types[];
    static struct wl_interface const* create_region_types[];
    static struct wl_message const request_messages[];
    static void const* request_vtable[];
};

int const mw::Compositor::Thunks::supported_version = 4;

mw::Compositor::Compositor(struct wl_resource* resource, Version<4>)
    : client{wl_resource_get_client(resource)},
      resource{resource}
{
    if (resource == nullptr)
    {
        BOOST_THROW_EXCEPTION((std::bad_alloc{}));
    }
    wl_resource_set_implementation(resource, Thunks::request_vtable, this, &Thunks::resource_destroyed_thunk);
}

bool mw::Compositor::is_instance(wl_resource* resource)
{
    return wl_resource_instance_of(resource, &wl_compositor_interface_data, Thunks::request_vtable);
}

void mw::Compositor::destroy_wayland_object() const
{
    wl_resource_destroy(resource);
}

mw::Compositor::Global::Global(wl_display* display, Version<4>)
    : wayland::Global{
          wl_global_create(
              display,
              &wl_compositor_interface_data,
              Thunks::supported_version,
              this,
              &Thunks::bind_thunk)}
{}

auto mw::Compositor::Global::interface_name() const -> char const*
{
    return Compositor::interface_name;
}

struct wl_interface const* mw::Compositor::Thunks::create_surface_types[] {
    &wl_surface_interface_data};

struct wl_interface const* mw::Compositor::Thunks::create_region_types[] {
    &wl_region_interface_data};

struct wl_message const mw::Compositor::Thunks::request_messages[] {
    {"create_surface", "n", create_surface_types},
    {"create_region", "n", create_region_types}};

void const* mw::Compositor::Thunks::request_vtable[] {
    (void*)Thunks::create_surface_thunk,
    (void*)Thunks::create_region_thunk};

// ShmPool

mw::ShmPool* mw::ShmPool::from(struct wl_resource* resource)
{
    return static_cast<ShmPool*>(wl_resource_get_user_data(resource));
}

struct mw::ShmPool::Thunks
{
    static int const supported_version;

    static void create_buffer_thunk(struct wl_client* client, struct wl_resource* resource, uint32_t id, int32_t offset, int32_t width, int32_t height, int32_t stride, uint32_t format)
    {
        auto me = static_cast<ShmPool*>(wl_resource_get_user_data(resource));
        wl_resource* id_resolved{
            wl_resource_create(client, &wl_buffer_interface_data, wl_resource_get_version(resource), id)};
        if (id_resolved == nullptr)
        {
            wl_client_post_no_memory(client);
            BOOST_THROW_EXCEPTION((std::bad_alloc{}));
        }
        try
        {
            me->create_buffer(id_resolved, offset, width, height, stride, format);
        }
        catch(...)
        {
            internal_error_processing_request(client, "ShmPool::create_buffer()");
        }
    }

    static void destroy_thunk(struct wl_client* client, struct wl_resource* resource)
    {
        auto me = static_cast<ShmPool*>(wl_resource_get_user_data(resource));
        try
        {
            me->destroy();
        }
        catch(...)
        {
            internal_error_processing_request(client, "ShmPool::destroy()");
        }
    }

    static void resize_thunk(struct wl_client* client, struct wl_resource* resource, int32_t size)
    {
        auto me = static_cast<ShmPool*>(wl_resource_get_user_data(resource));
        try
        {
            me->resize(size);
        }
        catch(...)
        {
            internal_error_processing_request(client, "ShmPool::resize()");
        }
    }

    static void resource_destroyed_thunk(wl_resource* resource)
    {
        delete static_cast<ShmPool*>(wl_resource_get_user_data(resource));
    }

    static struct wl_interface const* create_buffer_types[];
    static struct wl_message const request_messages[];
    static void const* request_vtable[];
};

int const mw::ShmPool::Thunks::supported_version = 1;

mw::ShmPool::ShmPool(struct wl_resource* resource, Version<1>)
    : client{wl_resource_get_client(resource)},
      resource{resource}
{
    if (resource == nullptr)
    {
        BOOST_THROW_EXCEPTION((std::bad_alloc{}));
    }
    wl_resource_set_implementation(resource, Thunks::request_vtable, this, &Thunks::resource_destroyed_thunk);
}

bool mw::ShmPool::is_instance(wl_resource* resource)
{
    return wl_resource_instance_of(resource, &wl_shm_pool_interface_data, Thunks::request_vtable);
}

void mw::ShmPool::destroy_wayland_object() const
{
    wl_resource_destroy(resource);
}

struct wl_interface const* mw::ShmPool::Thunks::create_buffer_types[] {
    &wl_buffer_interface_data,
    nullptr,
    nullptr,
    nullptr,
    nullptr,
    nullptr};

struct wl_message const mw::ShmPool::Thunks::request_messages[] {
    {"create_buffer", "niiiiu", create_buffer_types},
    {"destroy", "", all_null_types},
    {"resize", "i", all_null_types}};

void const* mw::ShmPool::Thunks::request_vtable[] {
    (void*)Thunks::create_buffer_thunk,
    (void*)Thunks::destroy_thunk,
    (void*)Thunks::resize_thunk};

// Shm

mw::Shm* mw::Shm::from(struct wl_resource* resource)
{
    return static_cast<Shm*>(wl_resource_get_user_data(resource));
}

struct mw::Shm::Thunks
{
    static int const supported_version;

    static void create_pool_thunk(struct wl_client* client, struct wl_resource* resource, uint32_t id, int32_t fd, int32_t size)
    {
        auto me = static_cast<Shm*>(wl_resource_get_user_data(resource));
        wl_resource* id_resolved{
            wl_resource_create(client, &wl_shm_pool_interface_data, wl_resource_get_version(resource), id)};
        if (id_resolved == nullptr)
        {
            wl_client_post_no_memory(client);
            BOOST_THROW_EXCEPTION((std::bad_alloc{}));
        }
        mir::Fd fd_resolved{fd};
        try
        {
            me->create_pool(id_resolved, fd_resolved, size);
        }
        catch(...)
        {
            internal_error_processing_request(client, "Shm::create_pool()");
        }
    }

    static void resource_destroyed_thunk(wl_resource* resource)
    {
        delete static_cast<Shm*>(wl_resource_get_user_data(resource));
    }

    static void bind_thunk(struct wl_client* client, void* data, uint32_t version, uint32_t id)
    {
        auto me = static_cast<Shm::Global*>(data);
        auto resource = wl_resource_create(
            client,
            &wl_shm_interface_data,
            std::min((int)version, Thunks::supported_version),
            id);
        if (resource == nullptr)
        {
            wl_client_post_no_memory(client);
            BOOST_THROW_EXCEPTION((std::bad_alloc{}));
        }
        try
        {
            me->bind(resource);
        }
        catch(...)
        {
            internal_error_processing_request(client, "Shm global bind");
        }
    }

    static struct wl_interface const* create_pool_types[];
    static struct wl_message const request_messages[];
    static struct wl_message const event_messages[];
    static void const* request_vtable[];
};

int const mw::Shm::Thunks::supported_version = 1;

mw::Shm::Shm(struct wl_resource* resource, Version<1>)
    : client{wl_resource_get_client(resource)},
      resource{resource}
{
    if (resource == nullptr)
    {
        BOOST_THROW_EXCEPTION((std::bad_alloc{}));
    }
    wl_resource_set_implementation(resource, Thunks::request_vtable, this, &Thunks::resource_destroyed_thunk);
}

void mw::Shm::send_format_event(uint32_t format) const
{
    wl_resource_post_event(resource, Opcode::format, format);
}

bool mw::Shm::is_instance(wl_resource* resource)
{
    return wl_resource_instance_of(resource, &wl_shm_interface_data, Thunks::request_vtable);
}

void mw::Shm::destroy_wayland_object() const
{
    wl_resource_destroy(resource);
}

mw::Shm::Global::Global(wl_display* display, Version<1>)
    : wayland::Global{
          wl_global_create(
              display,
              &wl_shm_interface_data,
              Thunks::supported_version,
              this,
              &Thunks::bind_thunk)}
{}

auto mw::Shm::Global::interface_name() const -> char const*
{
    return Shm::interface_name;
}

struct wl_interface const* mw::Shm::Thunks::create_pool_types[] {
    &wl_shm_pool_interface_data,
    nullptr,
    nullptr};

struct wl_message const mw::Shm::Thunks::request_messages[] {
    {"create_pool", "nhi", create_pool_types}};

struct wl_message const mw::Shm::Thunks::event_messages[] {
    {"format", "u", all_null_types}};

void const* mw::Shm::Thunks::request_vtable[] {
    (void*)Thunks::create_pool_thunk};

// Buffer

mw::Buffer* mw::Buffer::from(struct wl_resource* resource)
{
    return static_cast<Buffer*>(wl_resource_get_user_data(resource));
}

struct mw::Buffer::Thunks
{
    static int const supported_version;

    static void destroy_thunk(struct wl_client* client, struct wl_resource* resource)
    {
        auto me = static_cast<Buffer*>(wl_resource_get_user_data(resource));
        try
        {
            me->destroy();
        }
        catch(...)
        {
            internal_error_processing_request(client, "Buffer::destroy()");
        }
    }

    static void resource_destroyed_thunk(wl_resource* resource)
    {
        delete static_cast<Buffer*>(wl_resource_get_user_data(resource));
    }

    static struct wl_message const request_messages[];
    static struct wl_message const event_messages[];
    static void const* request_vtable[];
};

int const mw::Buffer::Thunks::supported_version = 1;

mw::Buffer::Buffer(struct wl_resource* resource, Version<1>)
    : client{wl_resource_get_client(resource)},
      resource{resource}
{
    if (resource == nullptr)
    {
        BOOST_THROW_EXCEPTION((std::bad_alloc{}));
    }
    wl_resource_set_implementation(resource, Thunks::request_vtable, this, &Thunks::resource_destroyed_thunk);
}

void mw::Buffer::send_release_event() const
{
    wl_resource_post_event(resource, Opcode::release);
}

bool mw::Buffer::is_instance(wl_resource* resource)
{
    return wl_resource_instance_of(resource, &wl_buffer_interface_data, Thunks::request_vtable);
}

void mw::Buffer::destroy_wayland_object() const
{
    wl_resource_destroy(resource);
}

struct wl_message const mw::Buffer::Thunks::request_messages[] {
    {"destroy", "", all_null_types}};

struct wl_message const mw::Buffer::Thunks::event_messages[] {
    {"release", "", all_null_types}};

void const* mw::Buffer::Thunks::request_vtable[] {
    (void*)Thunks::destroy_thunk};

// DataOffer

mw::DataOffer* mw::DataOffer::from(struct wl_resource* resource)
{
    return static_cast<DataOffer*>(wl_resource_get_user_data(resource));
}

struct mw::DataOffer::Thunks
{
    static int const supported_version;

    static void accept_thunk(struct wl_client* client, struct wl_resource* resource, uint32_t serial, char const* mime_type)
    {
        auto me = static_cast<DataOffer*>(wl_resource_get_user_data(resource));
        std::experimental::optional<std::string> mime_type_resolved;
        if (mime_type != nullptr)
        {
            mime_type_resolved = {mime_type};
        }
        try
        {
            me->accept(serial, mime_type_resolved);
        }
        catch(...)
        {
            internal_error_processing_request(client, "DataOffer::accept()");
        }
    }

    static void receive_thunk(struct wl_client* client, struct wl_resource* resource, char const* mime_type, int32_t fd)
    {
        auto me = static_cast<DataOffer*>(wl_resource_get_user_data(resource));
        mir::Fd fd_resolved{fd};
        try
        {
            me->receive(mime_type, fd_resolved);
        }
        catch(...)
        {
            internal_error_processing_request(client, "DataOffer::receive()");
        }
    }

    static void destroy_thunk(struct wl_client* client, struct wl_resource* resource)
    {
        auto me = static_cast<DataOffer*>(wl_resource_get_user_data(resource));
        try
        {
            me->destroy();
        }
        catch(...)
        {
            internal_error_processing_request(client, "DataOffer::destroy()");
        }
    }

    static void finish_thunk(struct wl_client* client, struct wl_resource* resource)
    {
        auto me = static_cast<DataOffer*>(wl_resource_get_user_data(resource));
        try
        {
            me->finish();
        }
        catch(...)
        {
            internal_error_processing_request(client, "DataOffer::finish()");
        }
    }

    static void set_actions_thunk(struct wl_client* client, struct wl_resource* resource, uint32_t dnd_actions, uint32_t preferred_action)
    {
        auto me = static_cast<DataOffer*>(wl_resource_get_user_data(resource));
        try
        {
            me->set_actions(dnd_actions, preferred_action);
        }
        catch(...)
        {
            internal_error_processing_request(client, "DataOffer::set_actions()");
        }
    }

    static void resource_destroyed_thunk(wl_resource* resource)
    {
        delete static_cast<DataOffer*>(wl_resource_get_user_data(resource));
    }

    static struct wl_message const request_messages[];
    static struct wl_message const event_messages[];
    static void const* request_vtable[];
};

int const mw::DataOffer::Thunks::supported_version = 3;

mw::DataOffer::DataOffer(DataDevice const& parent)
    : client{wl_resource_get_client(parent.resource)},
      resource{wl_resource_create(client, &wl_data_offer_interface_data, wl_resource_get_version(parent.resource), 0)}
{
    if (resource == nullptr)
    {
        BOOST_THROW_EXCEPTION((std::bad_alloc{}));
    }
    wl_resource_set_implementation(resource, Thunks::request_vtable, this, &Thunks::resource_destroyed_thunk);
}

void mw::DataOffer::send_offer_event(std::string const& mime_type) const
{
    const char* mime_type_resolved = mime_type.c_str();
    wl_resource_post_event(resource, Opcode::offer, mime_type_resolved);
}

bool mw::DataOffer::version_supports_source_actions()
{
    return wl_resource_get_version(resource) >= 3;
}

void mw::DataOffer::send_source_actions_event(uint32_t source_actions) const
{
    wl_resource_post_event(resource, Opcode::source_actions, source_actions);
}

bool mw::DataOffer::version_supports_action()
{
    return wl_resource_get_version(resource) >= 3;
}

void mw::DataOffer::send_action_event(uint32_t dnd_action) const
{
    wl_resource_post_event(resource, Opcode::action, dnd_action);
}

bool mw::DataOffer::is_instance(wl_resource* resource)
{
    return wl_resource_instance_of(resource, &wl_data_offer_interface_data, Thunks::request_vtable);
}

void mw::DataOffer::destroy_wayland_object() const
{
    wl_resource_destroy(resource);
}

struct wl_message const mw::DataOffer::Thunks::request_messages[] {
    {"accept", "u?s", all_null_types},
    {"receive", "sh", all_null_types},
    {"destroy", "", all_null_types},
    {"finish", "3", all_null_types},
    {"set_actions", "3uu", all_null_types}};

struct wl_message const mw::DataOffer::Thunks::event_messages[] {
    {"offer", "s", all_null_types},
    {"source_actions", "3u", all_null_types},
    {"action", "3u", all_null_types}};

void const* mw::DataOffer::Thunks::request_vtable[] {
    (void*)Thunks::accept_thunk,
    (void*)Thunks::receive_thunk,
    (void*)Thunks::destroy_thunk,
    (void*)Thunks::finish_thunk,
    (void*)Thunks::set_actions_thunk};

// DataSource

mw::DataSource* mw::DataSource::from(struct wl_resource* resource)
{
    return static_cast<DataSource*>(wl_resource_get_user_data(resource));
}

struct mw::DataSource::Thunks
{
    static int const supported_version;

    static void offer_thunk(struct wl_client* client, struct wl_resource* resource, char const* mime_type)
    {
        auto me = static_cast<DataSource*>(wl_resource_get_user_data(resource));
        try
        {
            me->offer(mime_type);
        }
        catch(...)
        {
            internal_error_processing_request(client, "DataSource::offer()");
        }
    }

    static void destroy_thunk(struct wl_client* client, struct wl_resource* resource)
    {
        auto me = static_cast<DataSource*>(wl_resource_get_user_data(resource));
        try
        {
            me->destroy();
        }
        catch(...)
        {
            internal_error_processing_request(client, "DataSource::destroy()");
        }
    }

    static void set_actions_thunk(struct wl_client* client, struct wl_resource* resource, uint32_t dnd_actions)
    {
        auto me = static_cast<DataSource*>(wl_resource_get_user_data(resource));
        try
        {
            me->set_actions(dnd_actions);
        }
        catch(...)
        {
            internal_error_processing_request(client, "DataSource::set_actions()");
        }
    }

    static void resource_destroyed_thunk(wl_resource* resource)
    {
        delete static_cast<DataSource*>(wl_resource_get_user_data(resource));
    }

    static struct wl_message const request_messages[];
    static struct wl_message const event_messages[];
    static void const* request_vtable[];
};

int const mw::DataSource::Thunks::supported_version = 3;

mw::DataSource::DataSource(struct wl_resource* resource, Version<3>)
    : client{wl_resource_get_client(resource)},
      resource{resource}
{
    if (resource == nullptr)
    {
        BOOST_THROW_EXCEPTION((std::bad_alloc{}));
    }
    wl_resource_set_implementation(resource, Thunks::request_vtable, this, &Thunks::resource_destroyed_thunk);
}

void mw::DataSource::send_target_event(std::experimental::optional<std::string> const& mime_type) const
{
    const char* mime_type_resolved = nullptr;
    if (mime_type)
    {
        mime_type_resolved = mime_type.value().c_str();
    }
    wl_resource_post_event(resource, Opcode::target, mime_type_resolved);
}

void mw::DataSource::send_send_event(std::string const& mime_type, mir::Fd fd) const
{
    const char* mime_type_resolved = mime_type.c_str();
    int32_t fd_resolved{fd};
    wl_resource_post_event(resource, Opcode::send, mime_type_resolved, fd_resolved);
}

void mw::DataSource::send_cancelled_event() const
{
    wl_resource_post_event(resource, Opcode::cancelled);
}

bool mw::DataSource::version_supports_dnd_drop_performed()
{
    return wl_resource_get_version(resource) >= 3;
}

void mw::DataSource::send_dnd_drop_performed_event() const
{
    wl_resource_post_event(resource, Opcode::dnd_drop_performed);
}

bool mw::DataSource::version_supports_dnd_finished()
{
    return wl_resource_get_version(resource) >= 3;
}

void mw::DataSource::send_dnd_finished_event() const
{
    wl_resource_post_event(resource, Opcode::dnd_finished);
}

bool mw::DataSource::version_supports_action()
{
    return wl_resource_get_version(resource) >= 3;
}

void mw::DataSource::send_action_event(uint32_t dnd_action) const
{
    wl_resource_post_event(resource, Opcode::action, dnd_action);
}

bool mw::DataSource::is_instance(wl_resource* resource)
{
    return wl_resource_instance_of(resource, &wl_data_source_interface_data, Thunks::request_vtable);
}

void mw::DataSource::destroy_wayland_object() const
{
    wl_resource_destroy(resource);
}

struct wl_message const mw::DataSource::Thunks::request_messages[] {
    {"offer", "s", all_null_types},
    {"destroy", "", all_null_types},
    {"set_actions", "3u", all_null_types}};

struct wl_message const mw::DataSource::Thunks::event_messages[] {
    {"target", "?s", all_null_types},
    {"send", "sh", all_null_types},
    {"cancelled", "", all_null_types},
    {"dnd_drop_performed", "3", all_null_types},
    {"dnd_finished", "3", all_null_types},
    {"action", "3u", all_null_types}};

void const* mw::DataSource::Thunks::request_vtable[] {
    (void*)Thunks::offer_thunk,
    (void*)Thunks::destroy_thunk,
    (void*)Thunks::set_actions_thunk};

// DataDevice

mw::DataDevice* mw::DataDevice::from(struct wl_resource* resource)
{
    return static_cast<DataDevice*>(wl_resource_get_user_data(resource));
}

struct mw::DataDevice::Thunks
{
    static int const supported_version;

    static void start_drag_thunk(struct wl_client* client, struct wl_resource* resource, struct wl_resource* source, struct wl_resource* origin, struct wl_resource* icon, uint32_t serial)
    {
        auto me = static_cast<DataDevice*>(wl_resource_get_user_data(resource));
        std::experimental::optional<struct wl_resource*> source_resolved;
        if (source != nullptr)
        {
            source_resolved = {source};
        }
        std::experimental::optional<struct wl_resource*> icon_resolved;
        if (icon != nullptr)
        {
            icon_resolved = {icon};
        }
        try
        {
            me->start_drag(source_resolved, origin, icon_resolved, serial);
        }
        catch(...)
        {
            internal_error_processing_request(client, "DataDevice::start_drag()");
        }
    }

    static void set_selection_thunk(struct wl_client* client, struct wl_resource* resource, struct wl_resource* source, uint32_t serial)
    {
        auto me = static_cast<DataDevice*>(wl_resource_get_user_data(resource));
        std::experimental::optional<struct wl_resource*> source_resolved;
        if (source != nullptr)
        {
            source_resolved = {source};
        }
        try
        {
            me->set_selection(source_resolved, serial);
        }
        catch(...)
        {
            internal_error_processing_request(client, "DataDevice::set_selection()");
        }
    }

    static void release_thunk(struct wl_client* client, struct wl_resource* resource)
    {
        auto me = static_cast<DataDevice*>(wl_resource_get_user_data(resource));
        try
        {
            me->release();
        }
        catch(...)
        {
            internal_error_processing_request(client, "DataDevice::release()");
        }
    }

    static void resource_destroyed_thunk(wl_resource* resource)
    {
        delete static_cast<DataDevice*>(wl_resource_get_user_data(resource));
    }

    static struct wl_interface const* start_drag_types[];
    static struct wl_interface const* set_selection_types[];
    static struct wl_interface const* data_offer_types[];
    static struct wl_interface const* enter_types[];
    static struct wl_interface const* selection_types[];
    static struct wl_message const request_messages[];
    static struct wl_message const event_messages[];
    static void const* request_vtable[];
};

int const mw::DataDevice::Thunks::supported_version = 3;

mw::DataDevice::DataDevice(struct wl_resource* resource, Version<3>)
    : client{wl_resource_get_client(resource)},
      resource{resource}
{
    if (resource == nullptr)
    {
        BOOST_THROW_EXCEPTION((std::bad_alloc{}));
    }
    wl_resource_set_implementation(resource, Thunks::request_vtable, this, &Thunks::resource_destroyed_thunk);
}

void mw::DataDevice::send_data_offer_event(struct wl_resource* id) const
{
    wl_resource_post_event(resource, Opcode::data_offer, id);
}

void mw::DataDevice::send_enter_event(uint32_t serial, struct wl_resource* surface, double x, double y, std::experimental::optional<struct wl_resource*> const& id) const
{
    wl_fixed_t x_resolved{wl_fixed_from_double(x)};
    wl_fixed_t y_resolved{wl_fixed_from_double(y)};
    struct wl_resource* id_resolved = nullptr;
    if (id)
    {
        id_resolved = id.value();
    }
    wl_resource_post_event(resource, Opcode::enter, serial, surface, x_resolved, y_resolved, id_resolved);
}

void mw::DataDevice::send_leave_event() const
{
    wl_resource_post_event(resource, Opcode::leave);
}

void mw::DataDevice::send_motion_event(uint32_t time, double x, double y) const
{
    wl_fixed_t x_resolved{wl_fixed_from_double(x)};
    wl_fixed_t y_resolved{wl_fixed_from_double(y)};
    wl_resource_post_event(resource, Opcode::motion, time, x_resolved, y_resolved);
}

void mw::DataDevice::send_drop_event() const
{
    wl_resource_post_event(resource, Opcode::drop);
}

void mw::DataDevice::send_selection_event(std::experimental::optional<struct wl_resource*> const& id) const
{
    struct wl_resource* id_resolved = nullptr;
    if (id)
    {
        id_resolved = id.value();
    }
    wl_resource_post_event(resource, Opcode::selection, id_resolved);
}

bool mw::DataDevice::is_instance(wl_resource* resource)
{
    return wl_resource_instance_of(resource, &wl_data_device_interface_data, Thunks::request_vtable);
}

void mw::DataDevice::destroy_wayland_object() const
{
    wl_resource_destroy(resource);
}

struct wl_interface const* mw::DataDevice::Thunks::start_drag_types[] {
    &wl_data_source_interface_data,
    &wl_surface_interface_data,
    &wl_surface_interface_data,
    nullptr};

struct wl_interface const* mw::DataDevice::Thunks::set_selection_types[] {
    &wl_data_source_interface_data,
    nullptr};

struct wl_interface const* mw::DataDevice::Thunks::data_offer_types[] {
    &wl_data_offer_interface_data};

struct wl_interface const* mw::DataDevice::Thunks::enter_types[] {
    nullptr,
    &wl_surface_interface_data,
    nullptr,
    nullptr,
    &wl_data_offer_interface_data};

struct wl_interface const* mw::DataDevice::Thunks::selection_types[] {
    &wl_data_offer_interface_data};

struct wl_message const mw::DataDevice::Thunks::request_messages[] {
    {"start_drag", "?oo?ou", start_drag_types},
    {"set_selection", "?ou", set_selection_types},
    {"release", "2", all_null_types}};

struct wl_message const mw::DataDevice::Thunks::event_messages[] {
    {"data_offer", "n", data_offer_types},
    {"enter", "uoff?o", enter_types},
    {"leave", "", all_null_types},
    {"motion", "uff", all_null_types},
    {"drop", "", all_null_types},
    {"selection", "?o", selection_types}};

void const* mw::DataDevice::Thunks::request_vtable[] {
    (void*)Thunks::start_drag_thunk,
    (void*)Thunks::set_selection_thunk,
    (void*)Thunks::release_thunk};

// DataDeviceManager

mw::DataDeviceManager* mw::DataDeviceManager::from(struct wl_resource* resource)
{
    return static_cast<DataDeviceManager*>(wl_resource_get_user_data(resource));
}

struct mw::DataDeviceManager::Thunks
{
    static int const supported_version;

    static void create_data_source_thunk(struct wl_client* client, struct wl_resource* resource, uint32_t id)
    {
        auto me = static_cast<DataDeviceManager*>(wl_resource_get_user_data(resource));
        wl_resource* id_resolved{
            wl_resource_create(client, &wl_data_source_interface_data, wl_resource_get_version(resource), id)};
        if (id_resolved == nullptr)
        {
            wl_client_post_no_memory(client);
            BOOST_THROW_EXCEPTION((std::bad_alloc{}));
        }
        try
        {
            me->create_data_source(id_resolved);
        }
        catch(...)
        {
            internal_error_processing_request(client, "DataDeviceManager::create_data_source()");
        }
    }

    static void get_data_device_thunk(struct wl_client* client, struct wl_resource* resource, uint32_t id, struct wl_resource* seat)
    {
        auto me = static_cast<DataDeviceManager*>(wl_resource_get_user_data(resource));
        wl_resource* id_resolved{
            wl_resource_create(client, &wl_data_device_interface_data, wl_resource_get_version(resource), id)};
        if (id_resolved == nullptr)
        {
            wl_client_post_no_memory(client);
            BOOST_THROW_EXCEPTION((std::bad_alloc{}));
        }
        try
        {
            me->get_data_device(id_resolved, seat);
        }
        catch(...)
        {
            internal_error_processing_request(client, "DataDeviceManager::get_data_device()");
        }
    }

    static void resource_destroyed_thunk(wl_resource* resource)
    {
        delete static_cast<DataDeviceManager*>(wl_resource_get_user_data(resource));
    }

    static void bind_thunk(struct wl_client* client, void* data, uint32_t version, uint32_t id)
    {
        auto me = static_cast<DataDeviceManager::Global*>(data);
        auto resource = wl_resource_create(
            client,
            &wl_data_device_manager_interface_data,
            std::min((int)version, Thunks::supported_version),
            id);
        if (resource == nullptr)
        {
            wl_client_post_no_memory(client);
            BOOST_THROW_EXCEPTION((std::bad_alloc{}));
        }
        try
        {
            me->bind(resource);
        }
        catch(...)
        {
            internal_error_processing_request(client, "DataDeviceManager global bind");
        }
    }

    static struct wl_interface const* create_data_source_types[];
    static struct wl_interface const* get_data_device_types[];
    static struct wl_message const request_messages[];
    static void const* request_vtable[];
};

int const mw::DataDeviceManager::Thunks::supported_version = 3;

mw::DataDeviceManager::DataDeviceManager(struct wl_resource* resource, Version<3>)
    : client{wl_resource_get_client(resource)},
      resource{resource}
{
    if (resource == nullptr)
    {
        BOOST_THROW_EXCEPTION((std::bad_alloc{}));
    }
    wl_resource_set_implementation(resource, Thunks::request_vtable, this, &Thunks::resource_destroyed_thunk);
}

bool mw::DataDeviceManager::is_instance(wl_resource* resource)
{
    return wl_resource_instance_of(resource, &wl_data_device_manager_interface_data, Thunks::request_vtable);
}

void mw::DataDeviceManager::destroy_wayland_object() const
{
    wl_resource_destroy(resource);
}

mw::DataDeviceManager::Global::Global(wl_display* display, Version<3>)
    : wayland::Global{
          wl_global_create(
              display,
              &wl_data_device_manager_interface_data,
              Thunks::supported_version,
              this,
              &Thunks::bind_thunk)}
{}

auto mw::DataDeviceManager::Global::interface_name() const -> char const*
{
    return DataDeviceManager::interface_name;
}

struct wl_interface const* mw::DataDeviceManager::Thunks::create_data_source_types[] {
    &wl_data_source_interface_data};

struct wl_interface const* mw::DataDeviceManager::Thunks::get_data_device_types[] {
    &wl_data_device_interface_data,
    &wl_seat_interface_data};

struct wl_message const mw::DataDeviceManager::Thunks::request_messages[] {
    {"create_data_source", "n", create_data_source_types},
    {"get_data_device", "no", get_data_device_types}};

void const* mw::DataDeviceManager::Thunks::request_vtable[] {
    (void*)Thunks::create_data_source_thunk,
    (void*)Thunks::get_data_device_thunk};

// Shell

mw::Shell* mw::Shell::from(struct wl_resource* resource)
{
    return static_cast<Shell*>(wl_resource_get_user_data(resource));
}

struct mw::Shell::Thunks
{
    static int const supported_version;

    static void get_shell_surface_thunk(struct wl_client* client, struct wl_resource* resource, uint32_t id, struct wl_resource* surface)
    {
        auto me = static_cast<Shell*>(wl_resource_get_user_data(resource));
        wl_resource* id_resolved{
            wl_resource_create(client, &wl_shell_surface_interface_data, wl_resource_get_version(resource), id)};
        if (id_resolved == nullptr)
        {
            wl_client_post_no_memory(client);
            BOOST_THROW_EXCEPTION((std::bad_alloc{}));
        }
        try
        {
            me->get_shell_surface(id_resolved, surface);
        }
        catch(...)
        {
            internal_error_processing_request(client, "Shell::get_shell_surface()");
        }
    }

    static void resource_destroyed_thunk(wl_resource* resource)
    {
        delete static_cast<Shell*>(wl_resource_get_user_data(resource));
    }

    static void bind_thunk(struct wl_client* client, void* data, uint32_t version, uint32_t id)
    {
        auto me = static_cast<Shell::Global*>(data);
        auto resource = wl_resource_create(
            client,
            &wl_shell_interface_data,
            std::min((int)version, Thunks::supported_version),
            id);
        if (resource == nullptr)
        {
            wl_client_post_no_memory(client);
            BOOST_THROW_EXCEPTION((std::bad_alloc{}));
        }
        try
        {
            me->bind(resource);
        }
        catch(...)
        {
            internal_error_processing_request(client, "Shell global bind");
        }
    }

    static struct wl_interface const* get_shell_surface_types[];
    static struct wl_message const request_messages[];
    static void const* request_vtable[];
};

int const mw::Shell::Thunks::supported_version = 1;

mw::Shell::Shell(struct wl_resource* resource, Version<1>)
    : client{wl_resource_get_client(resource)},
      resource{resource}
{
    if (resource == nullptr)
    {
        BOOST_THROW_EXCEPTION((std::bad_alloc{}));
    }
    wl_resource_set_implementation(resource, Thunks::request_vtable, this, &Thunks::resource_destroyed_thunk);
}

bool mw::Shell::is_instance(wl_resource* resource)
{
    return wl_resource_instance_of(resource, &wl_shell_interface_data, Thunks::request_vtable);
}

void mw::Shell::destroy_wayland_object() const
{
    wl_resource_destroy(resource);
}

mw::Shell::Global::Global(wl_display* display, Version<1>)
    : wayland::Global{
          wl_global_create(
              display,
              &wl_shell_interface_data,
              Thunks::supported_version,
              this,
              &Thunks::bind_thunk)}
{}

auto mw::Shell::Global::interface_name() const -> char const*
{
    return Shell::interface_name;
}

struct wl_interface const* mw::Shell::Thunks::get_shell_surface_types[] {
    &wl_shell_surface_interface_data,
    &wl_surface_interface_data};

struct wl_message const mw::Shell::Thunks::request_messages[] {
    {"get_shell_surface", "no", get_shell_surface_types}};

void const* mw::Shell::Thunks::request_vtable[] {
    (void*)Thunks::get_shell_surface_thunk};

// ShellSurface

mw::ShellSurface* mw::ShellSurface::from(struct wl_resource* resource)
{
    return static_cast<ShellSurface*>(wl_resource_get_user_data(resource));
}

struct mw::ShellSurface::Thunks
{
    static int const supported_version;

    static void pong_thunk(struct wl_client* client, struct wl_resource* resource, uint32_t serial)
    {
        auto me = static_cast<ShellSurface*>(wl_resource_get_user_data(resource));
        try
        {
            me->pong(serial);
        }
        catch(...)
        {
            internal_error_processing_request(client, "ShellSurface::pong()");
        }
    }

    static void move_thunk(struct wl_client* client, struct wl_resource* resource, struct wl_resource* seat, uint32_t serial)
    {
        auto me = static_cast<ShellSurface*>(wl_resource_get_user_data(resource));
        try
        {
            me->move(seat, serial);
        }
        catch(...)
        {
            internal_error_processing_request(client, "ShellSurface::move()");
        }
    }

    static void resize_thunk(struct wl_client* client, struct wl_resource* resource, struct wl_resource* seat, uint32_t serial, uint32_t edges)
    {
        auto me = static_cast<ShellSurface*>(wl_resource_get_user_data(resource));
        try
        {
            me->resize(seat, serial, edges);
        }
        catch(...)
        {
            internal_error_processing_request(client, "ShellSurface::resize()");
        }
    }

    static void set_toplevel_thunk(struct wl_client* client, struct wl_resource* resource)
    {
        auto me = static_cast<ShellSurface*>(wl_resource_get_user_data(resource));
        try
        {
            me->set_toplevel();
        }
        catch(...)
        {
            internal_error_processing_request(client, "ShellSurface::set_toplevel()");
        }
    }

    static void set_transient_thunk(struct wl_client* client, struct wl_resource* resource, struct wl_resource* parent, int32_t x, int32_t y, uint32_t flags)
    {
        auto me = static_cast<ShellSurface*>(wl_resource_get_user_data(resource));
        try
        {
            me->set_transient(parent, x, y, flags);
        }
        catch(...)
        {
            internal_error_processing_request(client, "ShellSurface::set_transient()");
        }
    }

    static void set_fullscreen_thunk(struct wl_client* client, struct wl_resource* resource, uint32_t method, uint32_t framerate, struct wl_resource* output)
    {
        auto me = static_cast<ShellSurface*>(wl_resource_get_user_data(resource));
        std::experimental::optional<struct wl_resource*> output_resolved;
        if (output != nullptr)
        {
            output_resolved = {output};
        }
        try
        {
            me->set_fullscreen(method, framerate, output_resolved);
        }
        catch(...)
        {
            internal_error_processing_request(client, "ShellSurface::set_fullscreen()");
        }
    }

    static void set_popup_thunk(struct wl_client* client, struct wl_resource* resource, struct wl_resource* seat, uint32_t serial, struct wl_resource* parent, int32_t x, int32_t y, uint32_t flags)
    {
        auto me = static_cast<ShellSurface*>(wl_resource_get_user_data(resource));
        try
        {
            me->set_popup(seat, serial, parent, x, y, flags);
        }
        catch(...)
        {
            internal_error_processing_request(client, "ShellSurface::set_popup()");
        }
    }

    static void set_maximized_thunk(struct wl_client* client, struct wl_resource* resource, struct wl_resource* output)
    {
        auto me = static_cast<ShellSurface*>(wl_resource_get_user_data(resource));
        std::experimental::optional<struct wl_resource*> output_resolved;
        if (output != nullptr)
        {
            output_resolved = {output};
        }
        try
        {
            me->set_maximized(output_resolved);
        }
        catch(...)
        {
            internal_error_processing_request(client, "ShellSurface::set_maximized()");
        }
    }

    static void set_title_thunk(struct wl_client* client, struct wl_resource* resource, char const* title)
    {
        auto me = static_cast<ShellSurface*>(wl_resource_get_user_data(resource));
        try
        {
            me->set_title(title);
        }
        catch(...)
        {
            internal_error_processing_request(client, "ShellSurface::set_title()");
        }
    }

    static void set_class_thunk(struct wl_client* client, struct wl_resource* resource, char const* class_)
    {
        auto me = static_cast<ShellSurface*>(wl_resource_get_user_data(resource));
        try
        {
            me->set_class(class_);
        }
        catch(...)
        {
            internal_error_processing_request(client, "ShellSurface::set_class()");
        }
    }

    static void resource_destroyed_thunk(wl_resource* resource)
    {
        delete static_cast<ShellSurface*>(wl_resource_get_user_data(resource));
    }

    static struct wl_interface const* move_types[];
    static struct wl_interface const* resize_types[];
    static struct wl_interface const* set_transient_types[];
    static struct wl_interface const* set_fullscreen_types[];
    static struct wl_interface const* set_popup_types[];
    static struct wl_interface const* set_maximized_types[];
    static struct wl_message const request_messages[];
    static struct wl_message const event_messages[];
    static void const* request_vtable[];
};

int const mw::ShellSurface::Thunks::supported_version = 1;

mw::ShellSurface::ShellSurface(struct wl_resource* resource, Version<1>)
    : client{wl_resource_get_client(resource)},
      resource{resource}
{
    if (resource == nullptr)
    {
        BOOST_THROW_EXCEPTION((std::bad_alloc{}));
    }
    wl_resource_set_implementation(resource, Thunks::request_vtable, this, &Thunks::resource_destroyed_thunk);
}

void mw::ShellSurface::send_ping_event(uint32_t serial) const
{
    wl_resource_post_event(resource, Opcode::ping, serial);
}

void mw::ShellSurface::send_configure_event(uint32_t edges, int32_t width, int32_t height) const
{
    wl_resource_post_event(resource, Opcode::configure, edges, width, height);
}

void mw::ShellSurface::send_popup_done_event() const
{
    wl_resource_post_event(resource, Opcode::popup_done);
}

bool mw::ShellSurface::is_instance(wl_resource* resource)
{
    return wl_resource_instance_of(resource, &wl_shell_surface_interface_data, Thunks::request_vtable);
}

void mw::ShellSurface::destroy_wayland_object() const
{
    wl_resource_destroy(resource);
}

struct wl_interface const* mw::ShellSurface::Thunks::move_types[] {
    &wl_seat_interface_data,
    nullptr};

struct wl_interface const* mw::ShellSurface::Thunks::resize_types[] {
    &wl_seat_interface_data,
    nullptr,
    nullptr};

struct wl_interface const* mw::ShellSurface::Thunks::set_transient_types[] {
    &wl_surface_interface_data,
    nullptr,
    nullptr,
    nullptr};

struct wl_interface const* mw::ShellSurface::Thunks::set_fullscreen_types[] {
    nullptr,
    nullptr,
    &wl_output_interface_data};

struct wl_interface const* mw::ShellSurface::Thunks::set_popup_types[] {
    &wl_seat_interface_data,
    nullptr,
    &wl_surface_interface_data,
    nullptr,
    nullptr,
    nullptr};

struct wl_interface const* mw::ShellSurface::Thunks::set_maximized_types[] {
    &wl_output_interface_data};

struct wl_message const mw::ShellSurface::Thunks::request_messages[] {
    {"pong", "u", all_null_types},
    {"move", "ou", move_types},
    {"resize", "ouu", resize_types},
    {"set_toplevel", "", all_null_types},
    {"set_transient", "oiiu", set_transient_types},
    {"set_fullscreen", "uu?o", set_fullscreen_types},
    {"set_popup", "ouoiiu", set_popup_types},
    {"set_maximized", "?o", set_maximized_types},
    {"set_title", "s", all_null_types},
    {"set_class", "s", all_null_types}};

struct wl_message const mw::ShellSurface::Thunks::event_messages[] {
    {"ping", "u", all_null_types},
    {"configure", "uii", all_null_types},
    {"popup_done", "", all_null_types}};

void const* mw::ShellSurface::Thunks::request_vtable[] {
    (void*)Thunks::pong_thunk,
    (void*)Thunks::move_thunk,
    (void*)Thunks::resize_thunk,
    (void*)Thunks::set_toplevel_thunk,
    (void*)Thunks::set_transient_thunk,
    (void*)Thunks::set_fullscreen_thunk,
    (void*)Thunks::set_popup_thunk,
    (void*)Thunks::set_maximized_thunk,
    (void*)Thunks::set_title_thunk,
    (void*)Thunks::set_class_thunk};

// Surface

mw::Surface* mw::Surface::from(struct wl_resource* resource)
{
    return static_cast<Surface*>(wl_resource_get_user_data(resource));
}

struct mw::Surface::Thunks
{
    static int const supported_version;

    static void destroy_thunk(struct wl_client* client, struct wl_resource* resource)
    {
        auto me = static_cast<Surface*>(wl_resource_get_user_data(resource));
        try
        {
            me->destroy();
        }
        catch(...)
        {
            internal_error_processing_request(client, "Surface::destroy()");
        }
    }

    static void attach_thunk(struct wl_client* client, struct wl_resource* resource, struct wl_resource* buffer, int32_t x, int32_t y)
    {
        auto me = static_cast<Surface*>(wl_resource_get_user_data(resource));
        std::experimental::optional<struct wl_resource*> buffer_resolved;
        if (buffer != nullptr)
        {
            buffer_resolved = {buffer};
        }
        try
        {
            me->attach(buffer_resolved, x, y);
        }
        catch(...)
        {
            internal_error_processing_request(client, "Surface::attach()");
        }
    }

    static void damage_thunk(struct wl_client* client, struct wl_resource* resource, int32_t x, int32_t y, int32_t width, int32_t height)
    {
        auto me = static_cast<Surface*>(wl_resource_get_user_data(resource));
        try
        {
            me->damage(x, y, width, height);
        }
        catch(...)
        {
            internal_error_processing_request(client, "Surface::damage()");
        }
    }

    static void frame_thunk(struct wl_client* client, struct wl_resource* resource, uint32_t callback)
    {
        auto me = static_cast<Surface*>(wl_resource_get_user_data(resource));
        wl_resource* callback_resolved{
            wl_resource_create(client, &wl_callback_interface_data, wl_resource_get_version(resource), callback)};
        if (callback_resolved == nullptr)
        {
            wl_client_post_no_memory(client);
            BOOST_THROW_EXCEPTION((std::bad_alloc{}));
        }
        try
        {
            me->frame(callback_resolved);
        }
        catch(...)
        {
            internal_error_processing_request(client, "Surface::frame()");
        }
    }

    static void set_opaque_region_thunk(struct wl_client* client, struct wl_resource* resource, struct wl_resource* region)
    {
        auto me = static_cast<Surface*>(wl_resource_get_user_data(resource));
        std::experimental::optional<struct wl_resource*> region_resolved;
        if (region != nullptr)
        {
            region_resolved = {region};
        }
        try
        {
            me->set_opaque_region(region_resolved);
        }
        catch(...)
        {
            internal_error_processing_request(client, "Surface::set_opaque_region()");
        }
    }

    static void set_input_region_thunk(struct wl_client* client, struct wl_resource* resource, struct wl_resource* region)
    {
        auto me = static_cast<Surface*>(wl_resource_get_user_data(resource));
        std::experimental::optional<struct wl_resource*> region_resolved;
        if (region != nullptr)
        {
            region_resolved = {region};
        }
        try
        {
            me->set_input_region(region_resolved);
        }
        catch(...)
        {
            internal_error_processing_request(client, "Surface::set_input_region()");
        }
    }

    static void commit_thunk(struct wl_client* client, struct wl_resource* resource)
    {
        auto me = static_cast<Surface*>(wl_resource_get_user_data(resource));
        try
        {
            me->commit();
        }
        catch(...)
        {
            internal_error_processing_request(client, "Surface::commit()");
        }
    }

    static void set_buffer_transform_thunk(struct wl_client* client, struct wl_resource* resource, int32_t transform)
    {
        auto me = static_cast<Surface*>(wl_resource_get_user_data(resource));
        try
        {
            me->set_buffer_transform(transform);
        }
        catch(...)
        {
            internal_error_processing_request(client, "Surface::set_buffer_transform()");
        }
    }

    static void set_buffer_scale_thunk(struct wl_client* client, struct wl_resource* resource, int32_t scale)
    {
        auto me = static_cast<Surface*>(wl_resource_get_user_data(resource));
        try
        {
            me->set_buffer_scale(scale);
        }
        catch(...)
        {
            internal_error_processing_request(client, "Surface::set_buffer_scale()");
        }
    }

    static void damage_buffer_thunk(struct wl_client* client, struct wl_resource* resource, int32_t x, int32_t y, int32_t width, int32_t height)
    {
        auto me = static_cast<Surface*>(wl_resource_get_user_data(resource));
        try
        {
            me->damage_buffer(x, y, width, height);
        }
        catch(...)
        {
            internal_error_processing_request(client, "Surface::damage_buffer()");
        }
    }

    static void resource_destroyed_thunk(wl_resource* resource)
    {
        delete static_cast<Surface*>(wl_resource_get_user_data(resource));
    }

    static struct wl_interface const* attach_types[];
    static struct wl_interface const* frame_types[];
    static struct wl_interface const* set_opaque_region_types[];
    static struct wl_interface const* set_input_region_types[];
    static struct wl_interface const* enter_types[];
    static struct wl_interface const* leave_types[];
    static struct wl_message const request_messages[];
    static struct wl_message const event_messages[];
    static void const* request_vtable[];
};

int const mw::Surface::Thunks::supported_version = 4;

mw::Surface::Surface(struct wl_resource* resource, Version<4>)
    : client{wl_resource_get_client(resource)},
      resource{resource}
{
    if (resource == nullptr)
    {
        BOOST_THROW_EXCEPTION((std::bad_alloc{}));
    }
    wl_resource_set_implementation(resource, Thunks::request_vtable, this, &Thunks::resource_destroyed_thunk);
}

void mw::Surface::send_enter_event(struct wl_resource* output) const
{
    wl_resource_post_event(resource, Opcode::enter, output);
}

void mw::Surface::send_leave_event(struct wl_resource* output) const
{
    wl_resource_post_event(resource, Opcode::leave, output);
}

bool mw::Surface::is_instance(wl_resource* resource)
{
    return wl_resource_instance_of(resource, &wl_surface_interface_data, Thunks::request_vtable);
}

void mw::Surface::destroy_wayland_object() const
{
    wl_resource_destroy(resource);
}

struct wl_interface const* mw::Surface::Thunks::attach_types[] {
    &wl_buffer_interface_data,
    nullptr,
    nullptr};

struct wl_interface const* mw::Surface::Thunks::frame_types[] {
    &wl_callback_interface_data};

struct wl_interface const* mw::Surface::Thunks::set_opaque_region_types[] {
    &wl_region_interface_data};

struct wl_interface const* mw::Surface::Thunks::set_input_region_types[] {
    &wl_region_interface_data};

struct wl_interface const* mw::Surface::Thunks::enter_types[] {
    &wl_output_interface_data};

struct wl_interface const* mw::Surface::Thunks::leave_types[] {
    &wl_output_interface_data};

struct wl_message const mw::Surface::Thunks::request_messages[] {
    {"destroy", "", all_null_types},
    {"attach", "?oii", attach_types},
    {"damage", "iiii", all_null_types},
    {"frame", "n", frame_types},
    {"set_opaque_region", "?o", set_opaque_region_types},
    {"set_input_region", "?o", set_input_region_types},
    {"commit", "", all_null_types},
    {"set_buffer_transform", "2i", all_null_types},
    {"set_buffer_scale", "3i", all_null_types},
    {"damage_buffer", "4iiii", all_null_types}};

struct wl_message const mw::Surface::Thunks::event_messages[] {
    {"enter", "o", enter_types},
    {"leave", "o", leave_types}};

void const* mw::Surface::Thunks::request_vtable[] {
    (void*)Thunks::destroy_thunk,
    (void*)Thunks::attach_thunk,
    (void*)Thunks::damage_thunk,
    (void*)Thunks::frame_thunk,
    (void*)Thunks::set_opaque_region_thunk,
    (void*)Thunks::set_input_region_thunk,
    (void*)Thunks::commit_thunk,
    (void*)Thunks::set_buffer_transform_thunk,
    (void*)Thunks::set_buffer_scale_thunk,
    (void*)Thunks::damage_buffer_thunk};

// Seat

mw::Seat* mw::Seat::from(struct wl_resource* resource)
{
    return static_cast<Seat*>(wl_resource_get_user_data(resource));
}

struct mw::Seat::Thunks
{
    static int const supported_version;

    static void get_pointer_thunk(struct wl_client* client, struct wl_resource* resource, uint32_t id)
    {
        auto me = static_cast<Seat*>(wl_resource_get_user_data(resource));
        wl_resource* id_resolved{
            wl_resource_create(client, &wl_pointer_interface_data, wl_resource_get_version(resource), id)};
        if (id_resolved == nullptr)
        {
            wl_client_post_no_memory(client);
            BOOST_THROW_EXCEPTION((std::bad_alloc{}));
        }
        try
        {
            me->get_pointer(id_resolved);
        }
        catch(...)
        {
            internal_error_processing_request(client, "Seat::get_pointer()");
        }
    }

    static void get_keyboard_thunk(struct wl_client* client, struct wl_resource* resource, uint32_t id)
    {
        auto me = static_cast<Seat*>(wl_resource_get_user_data(resource));
        wl_resource* id_resolved{
            wl_resource_create(client, &wl_keyboard_interface_data, wl_resource_get_version(resource), id)};
        if (id_resolved == nullptr)
        {
            wl_client_post_no_memory(client);
            BOOST_THROW_EXCEPTION((std::bad_alloc{}));
        }
        try
        {
            me->get_keyboard(id_resolved);
        }
        catch(...)
        {
            internal_error_processing_request(client, "Seat::get_keyboard()");
        }
    }

    static void get_touch_thunk(struct wl_client* client, struct wl_resource* resource, uint32_t id)
    {
        auto me = static_cast<Seat*>(wl_resource_get_user_data(resource));
        wl_resource* id_resolved{
            wl_resource_create(client, &wl_touch_interface_data, wl_resource_get_version(resource), id)};
        if (id_resolved == nullptr)
        {
            wl_client_post_no_memory(client);
            BOOST_THROW_EXCEPTION((std::bad_alloc{}));
        }
        try
        {
            me->get_touch(id_resolved);
        }
        catch(...)
        {
            internal_error_processing_request(client, "Seat::get_touch()");
        }
    }

    static void release_thunk(struct wl_client* client, struct wl_resource* resource)
    {
        auto me = static_cast<Seat*>(wl_resource_get_user_data(resource));
        try
        {
            me->release();
        }
        catch(...)
        {
            internal_error_processing_request(client, "Seat::release()");
        }
    }

    static void resource_destroyed_thunk(wl_resource* resource)
    {
        delete static_cast<Seat*>(wl_resource_get_user_data(resource));
    }

    static void bind_thunk(struct wl_client* client, void* data, uint32_t version, uint32_t id)
    {
        auto me = static_cast<Seat::Global*>(data);
        auto resource = wl_resource_create(
            client,
            &wl_seat_interface_data,
            std::min((int)version, Thunks::supported_version),
            id);
        if (resource == nullptr)
        {
            wl_client_post_no_memory(client);
            BOOST_THROW_EXCEPTION((std::bad_alloc{}));
        }
        try
        {
            me->bind(resource);
        }
        catch(...)
        {
            internal_error_processing_request(client, "Seat global bind");
        }
    }

    static struct wl_interface const* get_pointer_types[];
    static struct wl_interface const* get_keyboard_types[];
    static struct wl_interface const* get_touch_types[];
    static struct wl_message const request_messages[];
    static struct wl_message const event_messages[];
    static void const* request_vtable[];
};

int const mw::Seat::Thunks::supported_version = 6;

mw::Seat::Seat(struct wl_resource* resource, Version<6>)
    : client{wl_resource_get_client(resource)},
      resource{resource}
{
    if (resource == nullptr)
    {
        BOOST_THROW_EXCEPTION((std::bad_alloc{}));
    }
    wl_resource_set_implementation(resource, Thunks::request_vtable, this, &Thunks::resource_destroyed_thunk);
}

void mw::Seat::send_capabilities_event(uint32_t capabilities) const
{
    wl_resource_post_event(resource, Opcode::capabilities, capabilities);
}

bool mw::Seat::version_supports_name()
{
    return wl_resource_get_version(resource) >= 2;
}

void mw::Seat::send_name_event(std::string const& name) const
{
    const char* name_resolved = name.c_str();
    wl_resource_post_event(resource, Opcode::name, name_resolved);
}

bool mw::Seat::is_instance(wl_resource* resource)
{
    return wl_resource_instance_of(resource, &wl_seat_interface_data, Thunks::request_vtable);
}

void mw::Seat::destroy_wayland_object() const
{
    wl_resource_destroy(resource);
}

mw::Seat::Global::Global(wl_display* display, Version<6>)
    : wayland::Global{
          wl_global_create(
              display,
              &wl_seat_interface_data,
              Thunks::supported_version,
              this,
              &Thunks::bind_thunk)}
{}

auto mw::Seat::Global::interface_name() const -> char const*
{
    return Seat::interface_name;
}

struct wl_interface const* mw::Seat::Thunks::get_pointer_types[] {
    &wl_pointer_interface_data};

struct wl_interface const* mw::Seat::Thunks::get_keyboard_types[] {
    &wl_keyboard_interface_data};

struct wl_interface const* mw::Seat::Thunks::get_touch_types[] {
    &wl_touch_interface_data};

struct wl_message const mw::Seat::Thunks::request_messages[] {
    {"get_pointer", "n", get_pointer_types},
    {"get_keyboard", "n", get_keyboard_types},
    {"get_touch", "n", get_touch_types},
    {"release", "5", all_null_types}};

struct wl_message const mw::Seat::Thunks::event_messages[] {
    {"capabilities", "u", all_null_types},
    {"name", "2s", all_null_types}};

void const* mw::Seat::Thunks::request_vtable[] {
    (void*)Thunks::get_pointer_thunk,
    (void*)Thunks::get_keyboard_thunk,
    (void*)Thunks::get_touch_thunk,
    (void*)Thunks::release_thunk};

// Pointer

mw::Pointer* mw::Pointer::from(struct wl_resource* resource)
{
    return static_cast<Pointer*>(wl_resource_get_user_data(resource));
}

struct mw::Pointer::Thunks
{
    static int const supported_version;

    static void set_cursor_thunk(struct wl_client* client, struct wl_resource* resource, uint32_t serial, struct wl_resource* surface, int32_t hotspot_x, int32_t hotspot_y)
    {
        auto me = static_cast<Pointer*>(wl_resource_get_user_data(resource));
        std::experimental::optional<struct wl_resource*> surface_resolved;
        if (surface != nullptr)
        {
            surface_resolved = {surface};
        }
        try
        {
            me->set_cursor(serial, surface_resolved, hotspot_x, hotspot_y);
        }
        catch(...)
        {
            internal_error_processing_request(client, "Pointer::set_cursor()");
        }
    }

    static void release_thunk(struct wl_client* client, struct wl_resource* resource)
    {
        auto me = static_cast<Pointer*>(wl_resource_get_user_data(resource));
        try
        {
            me->release();
        }
        catch(...)
        {
            internal_error_processing_request(client, "Pointer::release()");
        }
    }

    static void resource_destroyed_thunk(wl_resource* resource)
    {
        delete static_cast<Pointer*>(wl_resource_get_user_data(resource));
    }

    static struct wl_interface const* set_cursor_types[];
    static struct wl_interface const* enter_types[];
    static struct wl_interface const* leave_types[];
    static struct wl_message const request_messages[];
    static struct wl_message const event_messages[];
    static void const* request_vtable[];
};

int const mw::Pointer::Thunks::supported_version = 6;

mw::Pointer::Pointer(struct wl_resource* resource, Version<6>)
    : client{wl_resource_get_client(resource)},
      resource{resource}
{
    if (resource == nullptr)
    {
        BOOST_THROW_EXCEPTION((std::bad_alloc{}));
    }
    wl_resource_set_implementation(resource, Thunks::request_vtable, this, &Thunks::resource_destroyed_thunk);
}

void mw::Pointer::send_enter_event(uint32_t serial, struct wl_resource* surface, double surface_x, double surface_y) const
{
    wl_fixed_t surface_x_resolved{wl_fixed_from_double(surface_x)};
    wl_fixed_t surface_y_resolved{wl_fixed_from_double(surface_y)};
    wl_resource_post_event(resource, Opcode::enter, serial, surface, surface_x_resolved, surface_y_resolved);
}

void mw::Pointer::send_leave_event(uint32_t serial, struct wl_resource* surface) const
{
    wl_resource_post_event(resource, Opcode::leave, serial, surface);
}

void mw::Pointer::send_motion_event(uint32_t time, double surface_x, double surface_y) const
{
    wl_fixed_t surface_x_resolved{wl_fixed_from_double(surface_x)};
    wl_fixed_t surface_y_resolved{wl_fixed_from_double(surface_y)};
    wl_resource_post_event(resource, Opcode::motion, time, surface_x_resolved, surface_y_resolved);
}

void mw::Pointer::send_button_event(uint32_t serial, uint32_t time, uint32_t button, uint32_t state) const
{
    wl_resource_post_event(resource, Opcode::button, serial, time, button, state);
}

void mw::Pointer::send_axis_event(uint32_t time, uint32_t axis, double value) const
{
    wl_fixed_t value_resolved{wl_fixed_from_double(value)};
    wl_resource_post_event(resource, Opcode::axis, time, axis, value_resolved);
}

bool mw::Pointer::version_supports_frame()
{
    return wl_resource_get_version(resource) >= 5;
}

void mw::Pointer::send_frame_event() const
{
    wl_resource_post_event(resource, Opcode::frame);
}

bool mw::Pointer::version_supports_axis_source()
{
    return wl_resource_get_version(resource) >= 5;
}

void mw::Pointer::send_axis_source_event(uint32_t axis_source) const
{
    wl_resource_post_event(resource, Opcode::axis_source, axis_source);
}

bool mw::Pointer::version_supports_axis_stop()
{
    return wl_resource_get_version(resource) >= 5;
}

void mw::Pointer::send_axis_stop_event(uint32_t time, uint32_t axis) const
{
    wl_resource_post_event(resource, Opcode::axis_stop, time, axis);
}

bool mw::Pointer::version_supports_axis_discrete()
{
    return wl_resource_get_version(resource) >= 5;
}

void mw::Pointer::send_axis_discrete_event(uint32_t axis, int32_t discrete) const
{
    wl_resource_post_event(resource, Opcode::axis_discrete, axis, discrete);
}

bool mw::Pointer::is_instance(wl_resource* resource)
{
    return wl_resource_instance_of(resource, &wl_pointer_interface_data, Thunks::request_vtable);
}

void mw::Pointer::destroy_wayland_object() const
{
    wl_resource_destroy(resource);
}

struct wl_interface const* mw::Pointer::Thunks::set_cursor_types[] {
    nullptr,
    &wl_surface_interface_data,
    nullptr,
    nullptr};

struct wl_interface const* mw::Pointer::Thunks::enter_types[] {
    nullptr,
    &wl_surface_interface_data,
    nullptr,
    nullptr};

struct wl_interface const* mw::Pointer::Thunks::leave_types[] {
    nullptr,
    &wl_surface_interface_data};

struct wl_message const mw::Pointer::Thunks::request_messages[] {
    {"set_cursor", "u?oii", set_cursor_types},
    {"release", "3", all_null_types}};

struct wl_message const mw::Pointer::Thunks::event_messages[] {
    {"enter", "uoff", enter_types},
    {"leave", "uo", leave_types},
    {"motion", "uff", all_null_types},
    {"button", "uuuu", all_null_types},
    {"axis", "uuf", all_null_types},
    {"frame", "5", all_null_types},
    {"axis_source", "5u", all_null_types},
    {"axis_stop", "5uu", all_null_types},
    {"axis_discrete", "5ui", all_null_types}};

void const* mw::Pointer::Thunks::request_vtable[] {
    (void*)Thunks::set_cursor_thunk,
    (void*)Thunks::release_thunk};

// Keyboard

mw::Keyboard* mw::Keyboard::from(struct wl_resource* resource)
{
    return static_cast<Keyboard*>(wl_resource_get_user_data(resource));
}

struct mw::Keyboard::Thunks
{
    static int const supported_version;

    static void release_thunk(struct wl_client* client, struct wl_resource* resource)
    {
        auto me = static_cast<Keyboard*>(wl_resource_get_user_data(resource));
        try
        {
            me->release();
        }
        catch(...)
        {
            internal_error_processing_request(client, "Keyboard::release()");
        }
    }

    static void resource_destroyed_thunk(wl_resource* resource)
    {
        delete static_cast<Keyboard*>(wl_resource_get_user_data(resource));
    }

    static struct wl_interface const* enter_types[];
    static struct wl_interface const* leave_types[];
    static struct wl_message const request_messages[];
    static struct wl_message const event_messages[];
    static void const* request_vtable[];
};

int const mw::Keyboard::Thunks::supported_version = 6;

mw::Keyboard::Keyboard(struct wl_resource* resource, Version<6>)
    : client{wl_resource_get_client(resource)},
      resource{resource}
{
    if (resource == nullptr)
    {
        BOOST_THROW_EXCEPTION((std::bad_alloc{}));
    }
    wl_resource_set_implementation(resource, Thunks::request_vtable, this, &Thunks::resource_destroyed_thunk);
}

void mw::Keyboard::send_keymap_event(uint32_t format, mir::Fd fd, uint32_t size) const
{
    int32_t fd_resolved{fd};
    wl_resource_post_event(resource, Opcode::keymap, format, fd_resolved, size);
}

void mw::Keyboard::send_enter_event(uint32_t serial, struct wl_resource* surface, struct wl_array* keys) const
{
    wl_resource_post_event(resource, Opcode::enter, serial, surface, keys);
}

void mw::Keyboard::send_leave_event(uint32_t serial, struct wl_resource* surface) const
{
    wl_resource_post_event(resource, Opcode::leave, serial, surface);
}

void mw::Keyboard::send_key_event(uint32_t serial, uint32_t time, uint32_t key, uint32_t state) const
{
    wl_resource_post_event(resource, Opcode::key, serial, time, key, state);
}

void mw::Keyboard::send_modifiers_event(uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group) const
{
    wl_resource_post_event(resource, Opcode::modifiers, serial, mods_depressed, mods_latched, mods_locked, group);
}

bool mw::Keyboard::version_supports_repeat_info()
{
    return wl_resource_get_version(resource) >= 4;
}

void mw::Keyboard::send_repeat_info_event(int32_t rate, int32_t delay) const
{
    wl_resource_post_event(resource, Opcode::repeat_info, rate, delay);
}

bool mw::Keyboard::is_instance(wl_resource* resource)
{
    return wl_resource_instance_of(resource, &wl_keyboard_interface_data, Thunks::request_vtable);
}

void mw::Keyboard::destroy_wayland_object() const
{
    wl_resource_destroy(resource);
}

struct wl_interface const* mw::Keyboard::Thunks::enter_types[] {
    nullptr,
    &wl_surface_interface_data,
    nullptr};

struct wl_interface const* mw::Keyboard::Thunks::leave_types[] {
    nullptr,
    &wl_surface_interface_data};

struct wl_message const mw::Keyboard::Thunks::request_messages[] {
    {"release", "3", all_null_types}};

struct wl_message const mw::Keyboard::Thunks::event_messages[] {
    {"keymap", "uhu", all_null_types},
    {"enter", "uoa", enter_types},
    {"leave", "uo", leave_types},
    {"key", "uuuu", all_null_types},
    {"modifiers", "uuuuu", all_null_types},
    {"repeat_info", "4ii", all_null_types}};

void const* mw::Keyboard::Thunks::request_vtable[] {
    (void*)Thunks::release_thunk};

// Touch

mw::Touch* mw::Touch::from(struct wl_resource* resource)
{
    return static_cast<Touch*>(wl_resource_get_user_data(resource));
}

struct mw::Touch::Thunks
{
    static int const supported_version;

    static void release_thunk(struct wl_client* client, struct wl_resource* resource)
    {
        auto me = static_cast<Touch*>(wl_resource_get_user_data(resource));
        try
        {
            me->release();
        }
        catch(...)
        {
            internal_error_processing_request(client, "Touch::release()");
        }
    }

    static void resource_destroyed_thunk(wl_resource* resource)
    {
        delete static_cast<Touch*>(wl_resource_get_user_data(resource));
    }

    static struct wl_interface const* down_types[];
    static struct wl_message const request_messages[];
    static struct wl_message const event_messages[];
    static void const* request_vtable[];
};

int const mw::Touch::Thunks::supported_version = 6;

mw::Touch::Touch(struct wl_resource* resource, Version<6>)
    : client{wl_resource_get_client(resource)},
      resource{resource}
{
    if (resource == nullptr)
    {
        BOOST_THROW_EXCEPTION((std::bad_alloc{}));
    }
    wl_resource_set_implementation(resource, Thunks::request_vtable, this, &Thunks::resource_destroyed_thunk);
}

void mw::Touch::send_down_event(uint32_t serial, uint32_t time, struct wl_resource* surface, int32_t id, double x, double y) const
{
    wl_fixed_t x_resolved{wl_fixed_from_double(x)};
    wl_fixed_t y_resolved{wl_fixed_from_double(y)};
    wl_resource_post_event(resource, Opcode::down, serial, time, surface, id, x_resolved, y_resolved);
}

void mw::Touch::send_up_event(uint32_t serial, uint32_t time, int32_t id) const
{
    wl_resource_post_event(resource, Opcode::up, serial, time, id);
}

void mw::Touch::send_motion_event(uint32_t time, int32_t id, double x, double y) const
{
    wl_fixed_t x_resolved{wl_fixed_from_double(x)};
    wl_fixed_t y_resolved{wl_fixed_from_double(y)};
    wl_resource_post_event(resource, Opcode::motion, time, id, x_resolved, y_resolved);
}

void mw::Touch::send_frame_event() const
{
    wl_resource_post_event(resource, Opcode::frame);
}

void mw::Touch::send_cancel_event() const
{
    wl_resource_post_event(resource, Opcode::cancel);
}

bool mw::Touch::version_supports_shape()
{
    return wl_resource_get_version(resource) >= 6;
}

void mw::Touch::send_shape_event(int32_t id, double major, double minor) const
{
    wl_fixed_t major_resolved{wl_fixed_from_double(major)};
    wl_fixed_t minor_resolved{wl_fixed_from_double(minor)};
    wl_resource_post_event(resource, Opcode::shape, id, major_resolved, minor_resolved);
}

bool mw::Touch::version_supports_orientation()
{
    return wl_resource_get_version(resource) >= 6;
}

void mw::Touch::send_orientation_event(int32_t id, double orientation) const
{
    wl_fixed_t orientation_resolved{wl_fixed_from_double(orientation)};
    wl_resource_post_event(resource, Opcode::orientation, id, orientation_resolved);
}

bool mw::Touch::is_instance(wl_resource* resource)
{
    return wl_resource_instance_of(resource, &wl_touch_interface_data, Thunks::request_vtable);
}

void mw::Touch::destroy_wayland_object() const
{
    wl_resource_destroy(resource);
}

struct wl_interface const* mw::Touch::Thunks::down_types[] {
    nullptr,
    nullptr,
    &wl_surface_interface_data,
    nullptr,
    nullptr,
    nullptr};

struct wl_message const mw::Touch::Thunks::request_messages[] {
    {"release", "3", all_null_types}};

struct wl_message const mw::Touch::Thunks::event_messages[] {
    {"down", "uuoiff", down_types},
    {"up", "uui", all_null_types},
    {"motion", "uiff", all_null_types},
    {"frame", "", all_null_types},
    {"cancel", "", all_null_types},
    {"shape", "6iff", all_null_types},
    {"orientation", "6if", all_null_types}};

void const* mw::Touch::Thunks::request_vtable[] {
    (void*)Thunks::release_thunk};

// Output

mw::Output* mw::Output::from(struct wl_resource* resource)
{
    return static_cast<Output*>(wl_resource_get_user_data(resource));
}

struct mw::Output::Thunks
{
    static int const supported_version;

    static void release_thunk(struct wl_client* client, struct wl_resource* resource)
    {
        auto me = static_cast<Output*>(wl_resource_get_user_data(resource));
        try
        {
            me->release();
        }
        catch(...)
        {
            internal_error_processing_request(client, "Output::release()");
        }
    }

    static void resource_destroyed_thunk(wl_resource* resource)
    {
        delete static_cast<Output*>(wl_resource_get_user_data(resource));
    }

    static void bind_thunk(struct wl_client* client, void* data, uint32_t version, uint32_t id)
    {
        auto me = static_cast<Output::Global*>(data);
        auto resource = wl_resource_create(
            client,
            &wl_output_interface_data,
            std::min((int)version, Thunks::supported_version),
            id);
        if (resource == nullptr)
        {
            wl_client_post_no_memory(client);
            BOOST_THROW_EXCEPTION((std::bad_alloc{}));
        }
        try
        {
            me->bind(resource);
        }
        catch(...)
        {
            internal_error_processing_request(client, "Output global bind");
        }
    }

    static struct wl_interface const* geometry_types[];
    static struct wl_message const request_messages[];
    static struct wl_message const event_messages[];
    static void const* request_vtable[];
};

int const mw::Output::Thunks::supported_version = 3;

mw::Output::Output(struct wl_resource* resource, Version<3>)
    : client{wl_resource_get_client(resource)},
      resource{resource}
{
    if (resource == nullptr)
    {
        BOOST_THROW_EXCEPTION((std::bad_alloc{}));
    }
    wl_resource_set_implementation(resource, Thunks::request_vtable, this, &Thunks::resource_destroyed_thunk);
}

void mw::Output::send_geometry_event(int32_t x, int32_t y, int32_t physical_width, int32_t physical_height, int32_t subpixel, std::string const& make, std::string const& model, int32_t transform) const
{
    const char* make_resolved = make.c_str();
    const char* model_resolved = model.c_str();
    wl_resource_post_event(resource, Opcode::geometry, x, y, physical_width, physical_height, subpixel, make_resolved, model_resolved, transform);
}

void mw::Output::send_mode_event(uint32_t flags, int32_t width, int32_t height, int32_t refresh) const
{
    wl_resource_post_event(resource, Opcode::mode, flags, width, height, refresh);
}

bool mw::Output::version_supports_done()
{
    return wl_resource_get_version(resource) >= 2;
}

void mw::Output::send_done_event() const
{
    wl_resource_post_event(resource, Opcode::done);
}

bool mw::Output::version_supports_scale()
{
    return wl_resource_get_version(resource) >= 2;
}

void mw::Output::send_scale_event(int32_t factor) const
{
    wl_resource_post_event(resource, Opcode::scale, factor);
}

bool mw::Output::is_instance(wl_resource* resource)
{
    return wl_resource_instance_of(resource, &wl_output_interface_data, Thunks::request_vtable);
}

void mw::Output::destroy_wayland_object() const
{
    wl_resource_destroy(resource);
}

mw::Output::Global::Global(wl_display* display, Version<3>)
    : wayland::Global{
          wl_global_create(
              display,
              &wl_output_interface_data,
              Thunks::supported_version,
              this,
              &Thunks::bind_thunk)}
{}

auto mw::Output::Global::interface_name() const -> char const*
{
    return Output::interface_name;
}

struct wl_interface const* mw::Output::Thunks::geometry_types[] {
    nullptr,
    nullptr,
    nullptr,
    nullptr,
    nullptr,
    nullptr,
    nullptr,
    nullptr};

struct wl_message const mw::Output::Thunks::request_messages[] {
    {"release", "3", all_null_types}};

struct wl_message const mw::Output::Thunks::event_messages[] {
    {"geometry", "iiiiissi", geometry_types},
    {"mode", "uiii", all_null_types},
    {"done", "2", all_null_types},
    {"scale", "2i", all_null_types}};

void const* mw::Output::Thunks::request_vtable[] {
    (void*)Thunks::release_thunk};

// Region

mw::Region* mw::Region::from(struct wl_resource* resource)
{
    return static_cast<Region*>(wl_resource_get_user_data(resource));
}

struct mw::Region::Thunks
{
    static int const supported_version;

    static void destroy_thunk(struct wl_client* client, struct wl_resource* resource)
    {
        auto me = static_cast<Region*>(wl_resource_get_user_data(resource));
        try
        {
            me->destroy();
        }
        catch(...)
        {
            internal_error_processing_request(client, "Region::destroy()");
        }
    }

    static void add_thunk(struct wl_client* client, struct wl_resource* resource, int32_t x, int32_t y, int32_t width, int32_t height)
    {
        auto me = static_cast<Region*>(wl_resource_get_user_data(resource));
        try
        {
            me->add(x, y, width, height);
        }
        catch(...)
        {
            internal_error_processing_request(client, "Region::add()");
        }
    }

    static void subtract_thunk(struct wl_client* client, struct wl_resource* resource, int32_t x, int32_t y, int32_t width, int32_t height)
    {
        auto me = static_cast<Region*>(wl_resource_get_user_data(resource));
        try
        {
            me->subtract(x, y, width, height);
        }
        catch(...)
        {
            internal_error_processing_request(client, "Region::subtract()");
        }
    }

    static void resource_destroyed_thunk(wl_resource* resource)
    {
        delete static_cast<Region*>(wl_resource_get_user_data(resource));
    }

    static struct wl_message const request_messages[];
    static void const* request_vtable[];
};

int const mw::Region::Thunks::supported_version = 1;

mw::Region::Region(struct wl_resource* resource, Version<1>)
    : client{wl_resource_get_client(resource)},
      resource{resource}
{
    if (resource == nullptr)
    {
        BOOST_THROW_EXCEPTION((std::bad_alloc{}));
    }
    wl_resource_set_implementation(resource, Thunks::request_vtable, this, &Thunks::resource_destroyed_thunk);
}

bool mw::Region::is_instance(wl_resource* resource)
{
    return wl_resource_instance_of(resource, &wl_region_interface_data, Thunks::request_vtable);
}

void mw::Region::destroy_wayland_object() const
{
    wl_resource_destroy(resource);
}

struct wl_message const mw::Region::Thunks::request_messages[] {
    {"destroy", "", all_null_types},
    {"add", "iiii", all_null_types},
    {"subtract", "iiii", all_null_types}};

void const* mw::Region::Thunks::request_vtable[] {
    (void*)Thunks::destroy_thunk,
    (void*)Thunks::add_thunk,
    (void*)Thunks::subtract_thunk};

// Subcompositor

mw::Subcompositor* mw::Subcompositor::from(struct wl_resource* resource)
{
    return static_cast<Subcompositor*>(wl_resource_get_user_data(resource));
}

struct mw::Subcompositor::Thunks
{
    static int const supported_version;

    static void destroy_thunk(struct wl_client* client, struct wl_resource* resource)
    {
        auto me = static_cast<Subcompositor*>(wl_resource_get_user_data(resource));
        try
        {
            me->destroy();
        }
        catch(...)
        {
            internal_error_processing_request(client, "Subcompositor::destroy()");
        }
    }

    static void get_subsurface_thunk(struct wl_client* client, struct wl_resource* resource, uint32_t id, struct wl_resource* surface, struct wl_resource* parent)
    {
        auto me = static_cast<Subcompositor*>(wl_resource_get_user_data(resource));
        wl_resource* id_resolved{
            wl_resource_create(client, &wl_subsurface_interface_data, wl_resource_get_version(resource), id)};
        if (id_resolved == nullptr)
        {
            wl_client_post_no_memory(client);
            BOOST_THROW_EXCEPTION((std::bad_alloc{}));
        }
        try
        {
            me->get_subsurface(id_resolved, surface, parent);
        }
        catch(...)
        {
            internal_error_processing_request(client, "Subcompositor::get_subsurface()");
        }
    }

    static void resource_destroyed_thunk(wl_resource* resource)
    {
        delete static_cast<Subcompositor*>(wl_resource_get_user_data(resource));
    }

    static void bind_thunk(struct wl_client* client, void* data, uint32_t version, uint32_t id)
    {
        auto me = static_cast<Subcompositor::Global*>(data);
        auto resource = wl_resource_create(
            client,
            &wl_subcompositor_interface_data,
            std::min((int)version, Thunks::supported_version),
            id);
        if (resource == nullptr)
        {
            wl_client_post_no_memory(client);
            BOOST_THROW_EXCEPTION((std::bad_alloc{}));
        }
        try
        {
            me->bind(resource);
        }
        catch(...)
        {
            internal_error_processing_request(client, "Subcompositor global bind");
        }
    }

    static struct wl_interface const* get_subsurface_types[];
    static struct wl_message const request_messages[];
    static void const* request_vtable[];
};

int const mw::Subcompositor::Thunks::supported_version = 1;

mw::Subcompositor::Subcompositor(struct wl_resource* resource, Version<1>)
    : client{wl_resource_get_client(resource)},
      resource{resource}
{
    if (resource == nullptr)
    {
        BOOST_THROW_EXCEPTION((std::bad_alloc{}));
    }
    wl_resource_set_implementation(resource, Thunks::request_vtable, this, &Thunks::resource_destroyed_thunk);
}

bool mw::Subcompositor::is_instance(wl_resource* resource)
{
    return wl_resource_instance_of(resource, &wl_subcompositor_interface_data, Thunks::request_vtable);
}

void mw::Subcompositor::destroy_wayland_object() const
{
    wl_resource_destroy(resource);
}

mw::Subcompositor::Global::Global(wl_display* display, Version<1>)
    : wayland::Global{
          wl_global_create(
              display,
              &wl_subcompositor_interface_data,
              Thunks::supported_version,
              this,
              &Thunks::bind_thunk)}
{}

auto mw::Subcompositor::Global::interface_name() const -> char const*
{
    return Subcompositor::interface_name;
}

struct wl_interface const* mw::Subcompositor::Thunks::get_subsurface_types[] {
    &wl_subsurface_interface_data,
    &wl_surface_interface_data,
    &wl_surface_interface_data};

struct wl_message const mw::Subcompositor::Thunks::request_messages[] {
    {"destroy", "", all_null_types},
    {"get_subsurface", "noo", get_subsurface_types}};

void const* mw::Subcompositor::Thunks::request_vtable[] {
    (void*)Thunks::destroy_thunk,
    (void*)Thunks::get_subsurface_thunk};

// Subsurface

mw::Subsurface* mw::Subsurface::from(struct wl_resource* resource)
{
    return static_cast<Subsurface*>(wl_resource_get_user_data(resource));
}

struct mw::Subsurface::Thunks
{
    static int const supported_version;

    static void destroy_thunk(struct wl_client* client, struct wl_resource* resource)
    {
        auto me = static_cast<Subsurface*>(wl_resource_get_user_data(resource));
        try
        {
            me->destroy();
        }
        catch(...)
        {
            internal_error_processing_request(client, "Subsurface::destroy()");
        }
    }

    static void set_position_thunk(struct wl_client* client, struct wl_resource* resource, int32_t x, int32_t y)
    {
        auto me = static_cast<Subsurface*>(wl_resource_get_user_data(resource));
        try
        {
            me->set_position(x, y);
        }
        catch(...)
        {
            internal_error_processing_request(client, "Subsurface::set_position()");
        }
    }

    static void place_above_thunk(struct wl_client* client, struct wl_resource* resource, struct wl_resource* sibling)
    {
        auto me = static_cast<Subsurface*>(wl_resource_get_user_data(resource));
        try
        {
            me->place_above(sibling);
        }
        catch(...)
        {
            internal_error_processing_request(client, "Subsurface::place_above()");
        }
    }

    static void place_below_thunk(struct wl_client* client, struct wl_resource* resource, struct wl_resource* sibling)
    {
        auto me = static_cast<Subsurface*>(wl_resource_get_user_data(resource));
        try
        {
            me->place_below(sibling);
        }
        catch(...)
        {
            internal_error_processing_request(client, "Subsurface::place_below()");
        }
    }

    static void set_sync_thunk(struct wl_client* client, struct wl_resource* resource)
    {
        auto me = static_cast<Subsurface*>(wl_resource_get_user_data(resource));
        try
        {
            me->set_sync();
        }
        catch(...)
        {
            internal_error_processing_request(client, "Subsurface::set_sync()");
        }
    }

    static void set_desync_thunk(struct wl_client* client, struct wl_resource* resource)
    {
        auto me = static_cast<Subsurface*>(wl_resource_get_user_data(resource));
        try
        {
            me->set_desync();
        }
        catch(...)
        {
            internal_error_processing_request(client, "Subsurface::set_desync()");
        }
    }

    static void resource_destroyed_thunk(wl_resource* resource)
    {
        delete static_cast<Subsurface*>(wl_resource_get_user_data(resource));
    }

    static struct wl_interface const* place_above_types[];
    static struct wl_interface const* place_below_types[];
    static struct wl_message const request_messages[];
    static void const* request_vtable[];
};

int const mw::Subsurface::Thunks::supported_version = 1;

mw::Subsurface::Subsurface(struct wl_resource* resource, Version<1>)
    : client{wl_resource_get_client(resource)},
      resource{resource}
{
    if (resource == nullptr)
    {
        BOOST_THROW_EXCEPTION((std::bad_alloc{}));
    }
    wl_resource_set_implementation(resource, Thunks::request_vtable, this, &Thunks::resource_destroyed_thunk);
}

bool mw::Subsurface::is_instance(wl_resource* resource)
{
    return wl_resource_instance_of(resource, &wl_subsurface_interface_data, Thunks::request_vtable);
}

void mw::Subsurface::destroy_wayland_object() const
{
    wl_resource_destroy(resource);
}

struct wl_interface const* mw::Subsurface::Thunks::place_above_types[] {
    &wl_surface_interface_data};

struct wl_interface const* mw::Subsurface::Thunks::place_below_types[] {
    &wl_surface_interface_data};

struct wl_message const mw::Subsurface::Thunks::request_messages[] {
    {"destroy", "", all_null_types},
    {"set_position", "ii", all_null_types},
    {"place_above", "o", place_above_types},
    {"place_below", "o", place_below_types},
    {"set_sync", "", all_null_types},
    {"set_desync", "", all_null_types}};

void const* mw::Subsurface::Thunks::request_vtable[] {
    (void*)Thunks::destroy_thunk,
    (void*)Thunks::set_position_thunk,
    (void*)Thunks::place_above_thunk,
    (void*)Thunks::place_below_thunk,
    (void*)Thunks::set_sync_thunk,
    (void*)Thunks::set_desync_thunk};

namespace mir
{
namespace wayland
{

struct wl_interface const wl_callback_interface_data {
    mw::Callback::interface_name,
    mw::Callback::Thunks::supported_version,
    0, nullptr,
    1, mw::Callback::Thunks::event_messages};

struct wl_interface const wl_compositor_interface_data {
    mw::Compositor::interface_name,
    mw::Compositor::Thunks::supported_version,
    2, mw::Compositor::Thunks::request_messages,
    0, nullptr};

struct wl_interface const wl_shm_pool_interface_data {
    mw::ShmPool::interface_name,
    mw::ShmPool::Thunks::supported_version,
    3, mw::ShmPool::Thunks::request_messages,
    0, nullptr};

struct wl_interface const wl_shm_interface_data {
    mw::Shm::interface_name,
    mw::Shm::Thunks::supported_version,
    1, mw::Shm::Thunks::request_messages,
    1, mw::Shm::Thunks::event_messages};

struct wl_interface const wl_buffer_interface_data {
    mw::Buffer::interface_name,
    mw::Buffer::Thunks::supported_version,
    1, mw::Buffer::Thunks::request_messages,
    1, mw::Buffer::Thunks::event_messages};

struct wl_interface const wl_data_offer_interface_data {
    mw::DataOffer::interface_name,
    mw::DataOffer::Thunks::supported_version,
    5, mw::DataOffer::Thunks::request_messages,
    3, mw::DataOffer::Thunks::event_messages};

struct wl_interface const wl_data_source_interface_data {
    mw::DataSource::interface_name,
    mw::DataSource::Thunks::supported_version,
    3, mw::DataSource::Thunks::request_messages,
    6, mw::DataSource::Thunks::event_messages};

struct wl_interface const wl_data_device_interface_data {
    mw::DataDevice::interface_name,
    mw::DataDevice::Thunks::supported_version,
    3, mw::DataDevice::Thunks::request_messages,
    6, mw::DataDevice::Thunks::event_messages};

struct wl_interface const wl_data_device_manager_interface_data {
    mw::DataDeviceManager::interface_name,
    mw::DataDeviceManager::Thunks::supported_version,
    2, mw::DataDeviceManager::Thunks::request_messages,
    0, nullptr};

struct wl_interface const wl_shell_interface_data {
    mw::Shell::interface_name,
    mw::Shell::Thunks::supported_version,
    1, mw::Shell::Thunks::request_messages,
    0, nullptr};

struct wl_interface const wl_shell_surface_interface_data {
    mw::ShellSurface::interface_name,
    mw::ShellSurface::Thunks::supported_version,
    10, mw::ShellSurface::Thunks::request_messages,
    3, mw::ShellSurface::Thunks::event_messages};

struct wl_interface const wl_surface_interface_data {
    mw::Surface::interface_name,
    mw::Surface::Thunks::supported_version,
    10, mw::Surface::Thunks::request_messages,
    2, mw::Surface::Thunks::event_messages};

struct wl_interface const wl_seat_interface_data {
    mw::Seat::interface_name,
    mw::Seat::Thunks::supported_version,
    4, mw::Seat::Thunks::request_messages,
    2, mw::Seat::Thunks::event_messages};

struct wl_interface const wl_pointer_interface_data {
    mw::Pointer::interface_name,
    mw::Pointer::Thunks::supported_version,
    2, mw::Pointer::Thunks::request_messages,
    9, mw::Pointer::Thunks::event_messages};

struct wl_interface const wl_keyboard_interface_data {
    mw::Keyboard::interface_name,
    mw::Keyboard::Thunks::supported_version,
    1, mw::Keyboard::Thunks::request_messages,
    6, mw::Keyboard::Thunks::event_messages};

struct wl_interface const wl_touch_interface_data {
    mw::Touch::interface_name,
    mw::Touch::Thunks::supported_version,
    1, mw::Touch::Thunks::request_messages,
    7, mw::Touch::Thunks::event_messages};

struct wl_interface const wl_output_interface_data {
    mw::Output::interface_name,
    mw::Output::Thunks::supported_version,
    1, mw::Output::Thunks::request_messages,
    4, mw::Output::Thunks::event_messages};

struct wl_interface const wl_region_interface_data {
    mw::Region::interface_name,
    mw::Region::Thunks::supported_version,
    3, mw::Region::Thunks::request_messages,
    0, nullptr};

struct wl_interface const wl_subcompositor_interface_data {
    mw::Subcompositor::interface_name,
    mw::Subcompositor::Thunks::supported_version,
    2, mw::Subcompositor::Thunks::request_messages,
    0, nullptr};

struct wl_interface const wl_subsurface_interface_data {
    mw::Subsurface::interface_name,
    mw::Subsurface::Thunks::supported_version,
    6, mw::Subsurface::Thunks::request_messages,
    0, nullptr};

}
}
