Loading...
Searching...
No Matches
foreign_display.cpp
/*
* Copyright (c) 2018-2019, Philipp Kerling
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <iostream>
#include <memory>
#include <cstdint>
#include <wayland-client.hpp>
using namespace wayland;
class foreign_display
{
private:
// global objects
wl_display* c_display = nullptr;
std::unique_ptr<display_t> display;
registry_t registry;
public:
foreign_display() = default;
foreign_display(const foreign_display&) = delete;
foreign_display(foreign_display&&) noexcept = delete;
foreign_display& operator=(const foreign_display&) = delete;
foreign_display& operator=(foreign_display&&) noexcept = delete;
~foreign_display() noexcept
{
// wl_display_disconnect destroys all remaining proxy instances implicitly,
// so we have to make sure this is already gone in order to not run into a
// double-free
registry.proxy_release();
// This is not called by the display_t destructor for foreign instances!
wl_display_disconnect(c_display);
}
void run()
{
c_display = wl_display_connect(nullptr);
if(!c_display)
{
std::cerr << "Cannot connect to Wayland display";
return;
}
display.reset(new display_t(c_display));
registry = display->get_registry();
registry.on_global() = [&] (uint32_t name, const std::string& interface, uint32_t version)
{
std::cout << "* Global interface " << interface << " (name " << name << " version " << version << ")" << std::endl;
};
display->roundtrip();
}
};
int main()
{
foreign_display d;
d.run();
return 0;
}
wayland::display_t
Represents a connection to the compositor and acts as a proxy to the display singleton object.
Definition wayland-client.hpp:479
wayland::proxy_t::proxy_release
void proxy_release()
Release the wrapped object (if any), making this an empty wrapper.
wayland::registry_t
global registry object
Definition wayland-client-protocol.hpp:132
wayland::registry_t::on_global
std::function< void(uint32_t, std::string, uint32_t)> & on_global()
announce global object
Definition wayland-client-protocol.cpp:1606
wayland-client.hpp