From 43efd9e3077075f3dbebc9c1cf696c1bd280901f Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Thu, 10 Jun 2021 22:18:46 +0400 Subject: [PATCH] Use custom xdg-shell for shadows on Wayland --- CMakeLists.txt | 5 ++ ui/platform/linux/ui_utility_linux.cpp | 79 +++++++++++++------------- ui/platform/mac/ui_utility_mac.h | 6 +- ui/platform/ui_platform_utility.h | 4 +- ui/platform/win/ui_utility_win.h | 6 +- 5 files changed, 51 insertions(+), 49 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 21f6acf..28b5e9f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -245,6 +245,11 @@ endif() if (DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION) remove_target_sources(Telegram ${src_loc} ui/platform/linux/ui_linux_wayland_integration.cpp) nice_target_sources(Telegram ${src_loc} PRIVATE ui/platform/linux/ui_linux_wayland_integration_dummy.cpp) +elseif(LINUX) + target_link_libraries(lib_ui + PUBLIC + desktop-app::lib_waylandshells + ) endif() target_include_directories(lib_ui diff --git a/ui/platform/linux/ui_utility_linux.cpp b/ui/platform/linux/ui_utility_linux.cpp index ceac7f6..5bc5971 100644 --- a/ui/platform/linux/ui_utility_linux.cpp +++ b/ui/platform/linux/ui_utility_linux.cpp @@ -18,11 +18,21 @@ #include "base/platform/linux/base_linux_xcb_utilities.h" #endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION +#ifndef DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION +#include "waylandshells/xdg_shell.h" +#endif // !DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION + #include #include #include #include +#include #include +#include + +#ifndef DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION +#include +#endif // !DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION Q_DECLARE_METATYPE(QMargins); @@ -285,10 +295,10 @@ std::optional XCBIsOverlapped( return false; } -bool SetXCBFrameExtents(QWindow *window, const QMargins &extents) { +void SetXCBFrameExtents(QWindow *window, const QMargins &extents) { const auto connection = base::Platform::XCB::GetConnectionFromQt(); if (!connection) { - return false; + return; } const auto frameExtentsAtom = base::Platform::XCB::GetAtom( @@ -296,7 +306,7 @@ bool SetXCBFrameExtents(QWindow *window, const QMargins &extents) { kXCBFrameExtentsAtomName.utf16()); if (!frameExtentsAtom.has_value()) { - return false; + return; } const auto extentsVector = std::vector{ @@ -315,14 +325,12 @@ bool SetXCBFrameExtents(QWindow *window, const QMargins &extents) { 32, extentsVector.size(), extentsVector.data()); - - return true; } -bool UnsetXCBFrameExtents(QWindow *window) { +void UnsetXCBFrameExtents(QWindow *window) { const auto connection = base::Platform::XCB::GetConnectionFromQt(); if (!connection) { - return false; + return; } const auto frameExtentsAtom = base::Platform::XCB::GetAtom( @@ -330,15 +338,13 @@ bool UnsetXCBFrameExtents(QWindow *window) { kXCBFrameExtentsAtomName.utf16()); if (!frameExtentsAtom.has_value()) { - return false; + return; } xcb_delete_property( connection, window->winId(), *frameExtentsAtom); - - return true; } bool ShowXCBWindowMenu(QWindow *window) { @@ -460,11 +466,16 @@ std::optional IsOverlapped( } bool WindowExtentsSupported() { -#ifdef DESKTOP_APP_QT_PATCHED +#ifndef DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION if (::Platform::IsWayland()) { - return true; + // initialize shell integration before querying + using QtWaylandClient::QWaylandIntegration; + const auto integration = static_cast( + QGuiApplicationPrivate::platformIntegration()); + integration->shellIntegration(); + return WaylandShells::XdgShell(); } -#endif // DESKTOP_APP_QT_PATCHED +#endif // !DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION #ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION namespace XCB = base::Platform::XCB; @@ -477,42 +488,32 @@ bool WindowExtentsSupported() { return false; } -bool SetWindowExtents(QWindow *window, const QMargins &extents) { +void SetWindowExtents(QWindow *window, const QMargins &extents) { if (::Platform::IsWayland()) { -#ifdef DESKTOP_APP_QT_PATCHED - window->setProperty("WaylandCustomMargins", QVariant::fromValue(extents)); - return true; -#else // DESKTOP_APP_QT_PATCHED - return false; -#endif // !DESKTOP_APP_QT_PATCHED +#ifndef DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION + window->setProperty( + "_desktopApp_waylandCustomMargins", + QVariant::fromValue(extents)); +#endif // !DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION } else if (::Platform::IsX11()) { #ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION - return SetXCBFrameExtents(window, extents); -#else // !DESKTOP_APP_DISABLE_X11_INTEGRATION - return false; -#endif // DESKTOP_APP_DISABLE_X11_INTEGRATION + SetXCBFrameExtents(window, extents); +#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION } - - return false; } -bool UnsetWindowExtents(QWindow *window) { +void UnsetWindowExtents(QWindow *window) { if (::Platform::IsWayland()) { -#ifdef DESKTOP_APP_QT_PATCHED - window->setProperty("WaylandCustomMargins", QVariant()); - return true; -#else // DESKTOP_APP_QT_PATCHED - return false; -#endif // !DESKTOP_APP_QT_PATCHED +#ifndef DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION + window->setProperty( + "_desktopApp_waylandCustomMargins", + QVariant()); +#endif // !DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION } else if (::Platform::IsX11()) { #ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION - return UnsetXCBFrameExtents(window); -#else // !DESKTOP_APP_DISABLE_X11_INTEGRATION - return false; -#endif // DESKTOP_APP_DISABLE_X11_INTEGRATION + UnsetXCBFrameExtents(window); +#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION } - - return false; } bool ShowWindowMenu(QWindow *window) { diff --git a/ui/platform/mac/ui_utility_mac.h b/ui/platform/mac/ui_utility_mac.h index 070f3ee..de4787b 100644 --- a/ui/platform/mac/ui_utility_mac.h +++ b/ui/platform/mac/ui_utility_mac.h @@ -31,12 +31,10 @@ inline bool WindowExtentsSupported() { return false; } -inline bool SetWindowExtents(QWindow *window, const QMargins &extents) { - return false; +inline void SetWindowExtents(QWindow *window, const QMargins &extents) { } -inline bool UnsetWindowExtents(QWindow *window) { - return false; +inline void UnsetWindowExtents(QWindow *window) { } inline bool ShowWindowMenu(QWindow *window) { diff --git a/ui/platform/ui_platform_utility.h b/ui/platform/ui_platform_utility.h index 8b48384..c0bb5ea 100644 --- a/ui/platform/ui_platform_utility.h +++ b/ui/platform/ui_platform_utility.h @@ -37,8 +37,8 @@ void ClearTransientParent(not_null widget); void DrainMainQueue(); // Needed only if UseMainQueueGeneric() is false. [[nodiscard]] bool WindowExtentsSupported(); -bool SetWindowExtents(QWindow *window, const QMargins &extents); -bool UnsetWindowExtents(QWindow *window); +void SetWindowExtents(QWindow *window, const QMargins &extents); +void UnsetWindowExtents(QWindow *window); bool ShowWindowMenu(QWindow *window); [[nodiscard]] TitleControls::Layout TitleControlsLayout(); diff --git a/ui/platform/win/ui_utility_win.h b/ui/platform/win/ui_utility_win.h index f298313..2870cd0 100644 --- a/ui/platform/win/ui_utility_win.h +++ b/ui/platform/win/ui_utility_win.h @@ -46,12 +46,10 @@ inline bool WindowExtentsSupported() { return false; } -inline bool SetWindowExtents(QWindow *window, const QMargins &extents) { - return false; +inline void SetWindowExtents(QWindow *window, const QMargins &extents) { } -inline bool UnsetWindowExtents(QWindow *window) { - return false; +inline void UnsetWindowExtents(QWindow *window) { } } // namespace Platform