UI: Check for Expose and PlatformSurface events to create display
This is a workaround for QWaylandWindow never becoming exposed, or receiving the QEvent::Expose [1]. [1] https://bugreports.qt.io/browse/QTBUG-86176
This commit is contained in:
parent
226cc22669
commit
e67fdbca79
@ -10,6 +10,56 @@
|
|||||||
|
|
||||||
#ifdef ENABLE_WAYLAND
|
#ifdef ENABLE_WAYLAND
|
||||||
#include <obs-nix-platform.h>
|
#include <obs-nix-platform.h>
|
||||||
|
|
||||||
|
class SurfaceEventFilter : public QObject {
|
||||||
|
OBSQTDisplay *display;
|
||||||
|
int mTimerId;
|
||||||
|
|
||||||
|
public:
|
||||||
|
SurfaceEventFilter(OBSQTDisplay *src) : display(src), mTimerId(0) {}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool eventFilter(QObject *obj, QEvent *event) override
|
||||||
|
{
|
||||||
|
bool result = QObject::eventFilter(obj, event);
|
||||||
|
QPlatformSurfaceEvent *surfaceEvent;
|
||||||
|
|
||||||
|
switch (event->type()) {
|
||||||
|
case QEvent::PlatformSurface:
|
||||||
|
surfaceEvent =
|
||||||
|
static_cast<QPlatformSurfaceEvent *>(event);
|
||||||
|
if (surfaceEvent->surfaceEventType() !=
|
||||||
|
QPlatformSurfaceEvent::SurfaceCreated)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
if (display->windowHandle()->isExposed())
|
||||||
|
createOBSDisplay();
|
||||||
|
else
|
||||||
|
mTimerId = startTimer(67); // Arbitrary
|
||||||
|
break;
|
||||||
|
case QEvent::Expose:
|
||||||
|
createOBSDisplay();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void timerEvent(QTimerEvent *) { createOBSDisplay(true); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
void createOBSDisplay(bool force = false)
|
||||||
|
{
|
||||||
|
display->CreateDisplay(force);
|
||||||
|
if (mTimerId > 0) {
|
||||||
|
killTimer(mTimerId);
|
||||||
|
mTimerId = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static inline long long color_to_int(const QColor &color)
|
static inline long long color_to_int(const QColor &color)
|
||||||
@ -65,6 +115,12 @@ OBSQTDisplay::OBSQTDisplay(QWidget *parent, Qt::WindowFlags flags)
|
|||||||
|
|
||||||
connect(windowHandle(), &QWindow::visibleChanged, windowVisible);
|
connect(windowHandle(), &QWindow::visibleChanged, windowVisible);
|
||||||
connect(windowHandle(), &QWindow::screenChanged, screenChanged);
|
connect(windowHandle(), &QWindow::screenChanged, screenChanged);
|
||||||
|
|
||||||
|
#ifdef ENABLE_WAYLAND
|
||||||
|
if (obs_get_nix_platform() == OBS_NIX_PLATFORM_WAYLAND)
|
||||||
|
windowHandle()->installEventFilter(
|
||||||
|
new SurfaceEventFilter(this));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor OBSQTDisplay::GetDisplayBackgroundColor() const
|
QColor OBSQTDisplay::GetDisplayBackgroundColor() const
|
||||||
|
Loading…
x
Reference in New Issue
Block a user