From 9e63fc5acda8af86ae4418861fe20ce824f1983d Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Wed, 3 Aug 2022 20:40:24 +0400 Subject: [PATCH] Let PiP have custom buffer size on Wayland --- .../SourceFiles/media/view/media_view_pip.cpp | 54 +++++++++++++++++++ .../SourceFiles/media/view/media_view_pip.h | 1 + .../platform/linux/specific_linux.cpp | 8 +++ Telegram/lib_ui | 2 +- cmake | 2 +- 5 files changed, 65 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/media/view/media_view_pip.cpp b/Telegram/SourceFiles/media/view/media_view_pip.cpp index faa564f25..b9fe00bad 100644 --- a/Telegram/SourceFiles/media/view/media_view_pip.cpp +++ b/Telegram/SourceFiles/media/view/media_view_pip.cpp @@ -38,6 +38,17 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include #include +#include + +#ifdef QT_WAYLAND_EGL_CLIENT_HW_INTEGRATION_LIB +// private QtWaylandClient headers are using keywords :( +#ifdef QT_NO_KEYWORDS +#define signals Q_SIGNALS +#define slots Q_SLOTS +#endif // QT_NO_KEYWORDS + +#include +#endif // QT_WAYLAND_EGL_CLIENT_HW_INTEGRATION_LIB namespace Media { namespace View { @@ -572,6 +583,44 @@ void PipPanel::setGeometry(QRect geometry) { widget()->setGeometry(geometry); } +void PipPanel::handleResize(QSize size) { + if (!Platform::IsWayland()) { + return; + } + + const auto d = dynamic_cast(rp()->rpPrivate()); + if (!d) { + return; + } + + // Apply aspect ratio. + const auto max = std::max(size.width(), size.height()); + const auto scaled = (_ratio.width() > _ratio.height()) + ? QSize(max, max * _ratio.height() / _ratio.width()) + : QSize(max * _ratio.width() / _ratio.height(), max); + + // Buffer can't be bigger than surface size. + const auto byWidth = (scaled.width() * size.height()) + > (scaled.height() * size.width()); + const auto normalized = (byWidth && scaled.width() > size.width()) + ? QSize(size.width(), size.width() * scaled.height() / scaled.width()) + : (!byWidth && scaled.height() > size.height()) + ? QSize( + size.height() * scaled.width() / scaled.height(), + size.height()) + : scaled; + + d->data.crect = QRect(d->data.crect.topLeft(), normalized); + +#ifdef QT_WAYLAND_EGL_CLIENT_HW_INTEGRATION_LIB + using QtWaylandClient::QWaylandEglWindow; + if (const auto waylandEglWindow = dynamic_cast( + widget()->windowHandle()->handle())) { + waylandEglWindow->ensureSize(); + } +#endif // QT_WAYLAND_EGL_CLIENT_HW_INTEGRATION_LIB +} + void PipPanel::handleMousePress(QPoint position, Qt::MouseButton button) { if (button != Qt::LeftButton) { return; @@ -904,6 +953,11 @@ void Pip::setupPanel() { break; } }, _panel.rp()->lifetime()); + + _panel.rp()->sizeValue( + ) | rpl::start_with_next([=](QSize size) { + _panel.handleResize(size); + }, _panel.rp()->lifetime()); } void Pip::handleClose() { diff --git a/Telegram/SourceFiles/media/view/media_view_pip.h b/Telegram/SourceFiles/media/view/media_view_pip.h index ec65ed206..0af3e9c22 100644 --- a/Telegram/SourceFiles/media/view/media_view_pip.h +++ b/Telegram/SourceFiles/media/view/media_view_pip.h @@ -76,6 +76,7 @@ public: void setDragDisabled(bool disabled); [[nodiscard]] bool dragging() const; + void handleResize(QSize size); void handleMousePress(QPoint position, Qt::MouseButton button); void handleMouseRelease(QPoint position, Qt::MouseButton button); void handleMouseMove(QPoint position); diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.cpp b/Telegram/SourceFiles/platform/linux/specific_linux.cpp index 73d7e7c20..56b04763b 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp @@ -491,6 +491,7 @@ void start() { LOG(("Launcher filename: %1").arg(QGuiApplication::desktopFileName())); #ifndef DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION + qputenv("QT_WAYLAND_CLIENT_BUFFER_INTEGRATION", "desktop-app-wayland-egl"); qputenv("QT_WAYLAND_SHELL_INTEGRATION", "desktop-app-xdg-shell;xdg-shell"); #endif // !DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION @@ -627,6 +628,13 @@ namespace ThirdParty { void start() { LOG(("Icon theme: %1").arg(QIcon::themeName())); LOG(("Fallback icon theme: %1").arg(QIcon::fallbackThemeName())); + +#ifndef DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION + InvokeQueued(qApp, [] { + qunsetenv("QT_WAYLAND_CLIENT_BUFFER_INTEGRATION"); + qunsetenv("QT_WAYLAND_SHELL_INTEGRATION"); + }); +#endif // !DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION } void finish() { diff --git a/Telegram/lib_ui b/Telegram/lib_ui index f27d756bc..303947c78 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit f27d756bcd7508250a3f7ff73bf6053308c18cd6 +Subproject commit 303947c78c27d8322dd1b9a6796a2eb13c0ba78a diff --git a/cmake b/cmake index d8442d4d9..3e6a8fc19 160000 --- a/cmake +++ b/cmake @@ -1 +1 @@ -Subproject commit d8442d4d968f55e8804fea3cc2d2d84f60595982 +Subproject commit 3e6a8fc1924bea4d886867515b56003c88287867