4 #include <QGuiApplication>
6 #include <qpa/qplatformnativeinterface.h>
13 #include <wayland-client.h>
15 #define LOC QString("Wayland: ")
31 QWindow* window = Widget->windowHandle();
34 LOG(VB_GENERAL, LOG_WARNING,
LOC +
"Failed to retrieve native window");
38 QPlatformNativeInterface*
interface = QGuiApplication::platformNativeInterface();
39 m_display =
reinterpret_cast<wl_display*
>(interface->nativeResourceForWindow(
"display", window));
40 m_surface =
reinterpret_cast<wl_surface*
>(interface->nativeResourceForWindow(
"surface", window));
41 m_compositor =
reinterpret_cast<wl_compositor*
>(interface->nativeResourceForWindow(
"compositor", window));
44 LOG(VB_GENERAL, LOG_WARNING,
LOC +
"Failed to retrieve Wayland resources");
59 wl_region* region = wl_compositor_create_region(
m_compositor);
63 wl_region_add(region, Region.left(), Region.top(), Region.width(), Region.height());
64 wl_surface_set_opaque_region(
m_surface, region);
66 wl_region_destroy(region);
68 LOG(VB_GENERAL, LOG_INFO,
LOC + QString(
"Set opaque region: %1x%2+%3+%4")
69 .arg(Region.width()).arg(Region.height()).arg(Region.left()).arg(Region.top()));
81 uint32_t
Name,
const char *Interface, uint32_t Version)
84 auto found = std::find_if(registry->begin(), registry->end(), [&](
const auto IFace)
86 return (strcmp(Interface, IFace.first->name) == 0) && (IFace.first->version == static_cast<int>(Version));
89 if (found != registry->end())
91 LOG(VB_GENERAL, LOG_INFO,
LOC + QString(
"Found interface: %1 (v%2)")
92 .arg(found->first->name).arg(found->first->version));
93 found->second = wl_registry_bind(Reg,
Name, found->first,
static_cast<uint32_t
>(found->first->version));
95 LOG(VB_GENERAL, LOG_ERR,
LOC + QString(
"Failed to bind %1").arg(found->first->name));
102 static bool s_checked =
false;
103 static bool s_available =
false;
107 auto waylanddisplay = qEnvironmentVariable(
"WAYLAND_DISPLAY");
108 const auto *name = waylanddisplay.isEmpty() ? nullptr : waylanddisplay.toLocal8Bit().constData();
109 if (
auto *display = wl_display_connect(name); display)
111 LOG(VB_GENERAL, LOG_INFO,
LOC + QString(
"Available (WAYLAND_DISPLAY: '%1')")
112 .arg(waylanddisplay));
114 wl_display_disconnect(display);