4#include <QGuiApplication>
7#include <qpa/qplatformnativeinterface.h>
14#include <wayland-client.h>
16#define LOC QString("Wayland: ")
32 QWindow* window = Widget->windowHandle();
35 LOG(VB_GENERAL, LOG_WARNING,
LOC +
"Failed to retrieve native window");
39 QPlatformNativeInterface*
interface = QGuiApplication::platformNativeInterface();
40 m_display =
reinterpret_cast<wl_display*
>(interface->nativeResourceForWindow(
"display", window));
41 m_surface =
reinterpret_cast<wl_surface*
>(interface->nativeResourceForWindow(
"surface", window));
42 m_compositor =
reinterpret_cast<wl_compositor*
>(interface->nativeResourceForWindow(
"compositor", window));
45 LOG(VB_GENERAL, LOG_WARNING,
LOC +
"Failed to retrieve Wayland resources");
60 wl_region* region = wl_compositor_create_region(
m_compositor);
64 wl_region_add(region, Region.left(), Region.top(), Region.width(), Region.height());
65 wl_surface_set_opaque_region(
m_surface, region);
67 wl_region_destroy(region);
69 LOG(VB_GENERAL, LOG_INFO,
LOC + QString(
"Set opaque region: %1x%2+%3+%4")
70 .arg(Region.width()).arg(Region.height()).arg(Region.left()).arg(Region.top()));
83 uint32_t
Name,
const char *Interface, uint32_t Version)
86 auto found = std::ranges::find_if(*registry, [&](
const auto IFace)
88 return (strcmp(Interface, IFace.first->name) == 0) && (IFace.first->version ==
static_cast<int>(Version));
91 if (found != registry->end())
93 LOG(VB_GENERAL, LOG_INFO,
LOC + QString(
"Found interface: %1 (v%2)")
94 .arg(found->first->name).arg(found->first->version));
95 found->second = wl_registry_bind(Reg,
Name, found->first,
static_cast<uint32_t
>(found->first->version));
97 LOG(VB_GENERAL, LOG_ERR,
LOC + QString(
"Failed to bind %1").arg(found->first->name));
104 static bool s_checked =
false;
105 static bool s_available =
false;
109 auto waylanddisplay = qEnvironmentVariable(
"WAYLAND_DISPLAY");
110 const auto *name = waylanddisplay.isEmpty() ? nullptr : waylanddisplay.toLocal8Bit().constData();
111 if (
auto *display = wl_display_connect(name); display)
113 LOG(VB_GENERAL, LOG_INFO,
LOC + QString(
"Available (WAYLAND_DISPLAY: '%1')")
114 .arg(waylanddisplay));
116 wl_display_disconnect(display);
bool SetOpaqueRegion(QRect Region) const
Provide a rendering optimisation hint to the compositor.
static bool IsAvailable()
Check whether we can connect to a Wayland server.
wl_compositor * m_compositor
MythWaylandDevice(QWidget *Widget)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
std::map< const wl_interface *, void * > MythWaylandRegistry
static void AnnounceGlobal(void *Opaque, struct wl_registry *Reg, uint32_t Name, const char *Interface, uint32_t Version)
MythTV implementation of the Wayland registry callback.