This is an example of how to use the Wayland C++ bindings with a wl_display.
#include <iostream>
#include <memory>
using namespace wayland;
class foreign_display
{
private:
wl_display* c_display = nullptr;
std::unique_ptr<display_t> display;
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(c_display);
}
void run()
{
c_display = wl_display_connect(nullptr);
if(!c_display)
{
std::cerr << "Cannot connect to Wayland display";
return;
}
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;
}
Represents a connection to the compositor and acts as a proxy to the display singleton object.
void proxy_release()
Release the wrapped object (if any), making this an empty wrapper.
std::function< void(uint32_t, std::string, uint32_t)> & on_global()
announce global object