From 96b2e26f4265920dd7221afcff0a659d3ca84067 Mon Sep 17 00:00:00 2001 From: mid-kid Date: Thu, 12 Nov 2020 00:18:18 +0100 Subject: [PATCH] Build wayland support optionally --- Telegram/CMakeLists.txt | 28 +++-- .../linux/linux_wayland_integration.cpp | 116 ++++++++++++++++++ .../linux/linux_wayland_integration.h | 27 ++++ .../linux/linux_wayland_integration_dummy.cpp | 34 +++++ .../platform/linux/specific_linux.cpp | 96 ++------------- cmake | 2 +- 6 files changed, 207 insertions(+), 96 deletions(-) create mode 100644 Telegram/SourceFiles/platform/linux/linux_wayland_integration.cpp create mode 100644 Telegram/SourceFiles/platform/linux/linux_wayland_integration.h create mode 100644 Telegram/SourceFiles/platform/linux/linux_wayland_integration_dummy.cpp diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index b2b7236a35..2320bd52c7 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -70,7 +70,6 @@ PRIVATE if (LINUX) target_link_libraries(Telegram PRIVATE - desktop-app::external_materialdecoration desktop-app::external_nimf_qt5 desktop-app::external_qt5ct_support desktop-app::external_xcb_screensaver @@ -89,14 +88,22 @@ if (LINUX) ) endif() - if (DESKTOP_APP_USE_PACKAGED AND Qt5WaylandClient_VERSION VERSION_LESS 5.13.0) - find_package(PkgConfig REQUIRED) - pkg_check_modules(WAYLAND_CLIENT REQUIRED wayland-client) - - target_include_directories(Telegram + if (NOT DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION) + target_link_libraries(Telegram PRIVATE - ${WAYLAND_CLIENT_INCLUDE_DIRS} + desktop-app::external_materialdecoration ) + + if (DESKTOP_APP_USE_PACKAGED + AND Qt5WaylandClient_VERSION VERSION_LESS 5.13.0) + find_package(PkgConfig REQUIRED) + pkg_check_modules(WAYLAND_CLIENT REQUIRED wayland-client) + + target_include_directories(Telegram + PRIVATE + ${WAYLAND_CLIENT_INCLUDE_DIRS} + ) + endif() endif() if (NOT TDESKTOP_DISABLE_GTK_INTEGRATION) @@ -803,6 +810,8 @@ PRIVATE platform/linux/linux_gdk_helper.h platform/linux/linux_libs.cpp platform/linux/linux_libs.h + platform/linux/linux_wayland_integration.cpp + platform/linux/linux_wayland_integration.h platform/linux/linux_xlib_helper.cpp platform/linux/linux_xlib_helper.h platform/linux/file_utilities_linux.cpp @@ -1088,6 +1097,11 @@ if (NOT LINUX) ) endif() +if (LINUX AND DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION) + remove_target_sources(Telegram ${src_loc} platform/linux/linux_wayland_integration.cpp) + nice_target_sources(Telegram ${src_loc} PRIVATE platform/linux/linux_wayland_integration_dummy.cpp) +endif() + if (NOT DESKTOP_APP_USE_PACKAGED) nice_target_sources(Telegram ${src_loc} PRIVATE platform/mac/mac_iconv_helper.c) endif() diff --git a/Telegram/SourceFiles/platform/linux/linux_wayland_integration.cpp b/Telegram/SourceFiles/platform/linux/linux_wayland_integration.cpp new file mode 100644 index 0000000000..1df54e3da5 --- /dev/null +++ b/Telegram/SourceFiles/platform/linux/linux_wayland_integration.cpp @@ -0,0 +1,116 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "platform/linux/linux_wayland_integration.h" + +#include "base/platform/base_platform_info.h" + +#include + +#include +#include +#include + +#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0) && !defined DESKTOP_APP_QT_PATCHED +#include +#endif // Qt < 5.13 && !DESKTOP_APP_QT_PATCHED + +using QtWaylandClient::QWaylandWindow; + +namespace Platform { +namespace internal { + +namespace { + +#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0) && !defined DESKTOP_APP_QT_PATCHED +enum wl_shell_surface_resize WlResizeFromEdges(Qt::Edges edges) { + if (edges == (Qt::TopEdge | Qt::LeftEdge)) + return WL_SHELL_SURFACE_RESIZE_TOP_LEFT; + if (edges == Qt::TopEdge) + return WL_SHELL_SURFACE_RESIZE_TOP; + if (edges == (Qt::TopEdge | Qt::RightEdge)) + return WL_SHELL_SURFACE_RESIZE_TOP_RIGHT; + if (edges == Qt::RightEdge) + return WL_SHELL_SURFACE_RESIZE_RIGHT; + if (edges == (Qt::RightEdge | Qt::BottomEdge)) + return WL_SHELL_SURFACE_RESIZE_BOTTOM_RIGHT; + if (edges == Qt::BottomEdge) + return WL_SHELL_SURFACE_RESIZE_BOTTOM; + if (edges == (Qt::BottomEdge | Qt::LeftEdge)) + return WL_SHELL_SURFACE_RESIZE_BOTTOM_LEFT; + if (edges == Qt::LeftEdge) + return WL_SHELL_SURFACE_RESIZE_LEFT; + + return WL_SHELL_SURFACE_RESIZE_NONE; +} +#endif // Qt < 5.13 && !DESKTOP_APP_QT_PATCHED + +} // namespace + +WaylandIntegration::WaylandIntegration() { +} + +WaylandIntegration *WaylandIntegration::Instance() { + static WaylandIntegration instance; + return &instance; +} + +bool WaylandIntegration::startMove(QWindow *window) { + // There are startSystemMove on Qt 5.15 +#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) && !defined DESKTOP_APP_QT_PATCHED + if (const auto waylandWindow = static_cast( + window->handle())) { + if (const auto seat = waylandWindow->display()->lastInputDevice()) { + if (const auto shellSurface = waylandWindow->shellSurface()) { + return shellSurface->move(seat); + } + } + } +#endif // Qt < 5.15 && !DESKTOP_APP_QT_PATCHED + + return false; +} + +bool WaylandIntegration::startResize(QWindow *window, Qt::Edges edges) { + // There are startSystemResize on Qt 5.15 +#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) && !defined DESKTOP_APP_QT_PATCHED + if (const auto waylandWindow = static_cast( + window->handle())) { + if (const auto seat = waylandWindow->display()->lastInputDevice()) { + if (const auto shellSurface = waylandWindow->shellSurface()) { +#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0) + shellSurface->resize(seat, edges); + return true; +#else // Qt >= 5.13 + shellSurface->resize(seat, WlResizeFromEdges(edges)); + return true; +#endif // Qt < 5.13 + } + } + } +#endif // Qt < 5.15 && !DESKTOP_APP_QT_PATCHED + + return false; +} + +bool WaylandIntegration::showWindowMenu(QWindow *window) { +#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0) || defined DESKTOP_APP_QT_PATCHED + if (const auto waylandWindow = static_cast( + window->handle())) { + if (const auto seat = waylandWindow->display()->lastInputDevice()) { + if (const auto shellSurface = waylandWindow->shellSurface()) { + return shellSurface->showWindowMenu(seat); + } + } + } +#endif // Qt >= 5.13 || DESKTOP_APP_QT_PATCHED + + return false; +} + +} // namespace internal +} // namespace Platform diff --git a/Telegram/SourceFiles/platform/linux/linux_wayland_integration.h b/Telegram/SourceFiles/platform/linux/linux_wayland_integration.h new file mode 100644 index 0000000000..73486fef7b --- /dev/null +++ b/Telegram/SourceFiles/platform/linux/linux_wayland_integration.h @@ -0,0 +1,27 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +class QWindow; + +namespace Platform { +namespace internal { + +class WaylandIntegration { +public: + static WaylandIntegration *Instance(); + bool startMove(QWindow *window); + bool startResize(QWindow *window, Qt::Edges edges); + bool showWindowMenu(QWindow *window); + +private: + WaylandIntegration(); +}; + +} // namespace internal +} // namespace Platform diff --git a/Telegram/SourceFiles/platform/linux/linux_wayland_integration_dummy.cpp b/Telegram/SourceFiles/platform/linux/linux_wayland_integration_dummy.cpp new file mode 100644 index 0000000000..f6c6b39fe5 --- /dev/null +++ b/Telegram/SourceFiles/platform/linux/linux_wayland_integration_dummy.cpp @@ -0,0 +1,34 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "platform/linux/linux_wayland_integration.h" + +namespace Platform { +namespace internal { + +WaylandIntegration::WaylandIntegration() { +} + +WaylandIntegration *WaylandIntegration::Instance() { + static WaylandIntegration instance; + return &instance; +} + +bool WaylandIntegration::startMove(QWindow *window) { + return false; +} + +bool WaylandIntegration::startResize(QWindow *window, Qt::Edges edges) { + return false; +} + +bool WaylandIntegration::showWindowMenu(QWindow *window) { + return false; +} + +} // namespace internal +} // namespace Platform diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.cpp b/Telegram/SourceFiles/platform/linux/specific_linux.cpp index ec80da17a5..6cb1d00f37 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp @@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwindow.h" #include "platform/linux/linux_desktop_environment.h" #include "platform/linux/file_utilities_linux.h" +#include "platform/linux/linux_wayland_integration.h" #include "platform/platform_notifications_manager.h" #include "storage/localstorage.h" #include "core/crash_reports.h" @@ -31,10 +32,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include -#include -#include -#include - #ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION #include #include @@ -47,10 +44,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include -#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0) && !defined DESKTOP_APP_QT_PATCHED -#include -#endif // Qt < 5.13 && !DESKTOP_APP_QT_PATCHED - #include extern "C" { @@ -70,7 +63,7 @@ extern "C" { using namespace Platform; using Platform::File::internal::EscapeShell; -using QtWaylandClient::QWaylandWindow; +using Platform::internal::WaylandIntegration; namespace Platform { namespace { @@ -367,29 +360,6 @@ uint XCBMoveResizeFromEdges(Qt::Edges edges) { return 0; } -#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0) && !defined DESKTOP_APP_QT_PATCHED -enum wl_shell_surface_resize WlResizeFromEdges(Qt::Edges edges) { - if (edges == (Qt::TopEdge | Qt::LeftEdge)) - return WL_SHELL_SURFACE_RESIZE_TOP_LEFT; - if (edges == Qt::TopEdge) - return WL_SHELL_SURFACE_RESIZE_TOP; - if (edges == (Qt::TopEdge | Qt::RightEdge)) - return WL_SHELL_SURFACE_RESIZE_TOP_RIGHT; - if (edges == Qt::RightEdge) - return WL_SHELL_SURFACE_RESIZE_RIGHT; - if (edges == (Qt::RightEdge | Qt::BottomEdge)) - return WL_SHELL_SURFACE_RESIZE_BOTTOM_RIGHT; - if (edges == Qt::BottomEdge) - return WL_SHELL_SURFACE_RESIZE_BOTTOM; - if (edges == (Qt::BottomEdge | Qt::LeftEdge)) - return WL_SHELL_SURFACE_RESIZE_BOTTOM_LEFT; - if (edges == Qt::LeftEdge) - return WL_SHELL_SURFACE_RESIZE_LEFT; - - return WL_SHELL_SURFACE_RESIZE_NONE; -} -#endif // Qt < 5.13 && !DESKTOP_APP_QT_PATCHED - bool StartXCBMoveResize(QWindow *window, int edges) { const auto connection = base::Platform::XCB::GetConnectionFromQt(); if (!connection) { @@ -482,59 +452,6 @@ bool ShowXCBWindowMenu(QWindow *window) { return true; } -bool StartWaylandMove(QWindow *window) { - // There are startSystemMove on Qt 5.15 -#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) && !defined DESKTOP_APP_QT_PATCHED - if (const auto waylandWindow = static_cast( - window->handle())) { - if (const auto seat = waylandWindow->display()->lastInputDevice()) { - if (const auto shellSurface = waylandWindow->shellSurface()) { - return shellSurface->move(seat); - } - } - } -#endif // Qt < 5.15 && !DESKTOP_APP_QT_PATCHED - - return false; -} - -bool StartWaylandResize(QWindow *window, Qt::Edges edges) { - // There are startSystemResize on Qt 5.15 -#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) && !defined DESKTOP_APP_QT_PATCHED - if (const auto waylandWindow = static_cast( - window->handle())) { - if (const auto seat = waylandWindow->display()->lastInputDevice()) { - if (const auto shellSurface = waylandWindow->shellSurface()) { -#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0) - shellSurface->resize(seat, edges); - return true; -#else // Qt >= 5.13 - shellSurface->resize(seat, WlResizeFromEdges(edges)); - return true; -#endif // Qt < 5.13 - } - } - } -#endif // Qt < 5.15 && !DESKTOP_APP_QT_PATCHED - - return false; -} - -bool ShowWaylandWindowMenu(QWindow *window) { -#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0) || defined DESKTOP_APP_QT_PATCHED - if (const auto waylandWindow = static_cast( - window->handle())) { - if (const auto seat = waylandWindow->display()->lastInputDevice()) { - if (const auto shellSurface = waylandWindow->shellSurface()) { - return shellSurface->showWindowMenu(seat); - } - } - } -#endif // Qt >= 5.13 || DESKTOP_APP_QT_PATCHED - - return false; -} - bool XCBFrameExtentsSupported() { const auto connection = base::Platform::XCB::GetConnectionFromQt(); if (!connection) { @@ -893,7 +810,8 @@ bool SkipTaskbarSupported() { bool StartSystemMove(QWindow *window) { if (IsWayland()) { - return StartWaylandMove(window); + const auto integration = WaylandIntegration::Instance(); + return integration->startMove(window); } else { return StartXCBMoveResize(window, 16); } @@ -901,7 +819,8 @@ bool StartSystemMove(QWindow *window) { bool StartSystemResize(QWindow *window, Qt::Edges edges) { if (IsWayland()) { - return StartWaylandResize(window, edges); + const auto integration = WaylandIntegration::Instance(); + return integration->startResize(window, edges); } else { return StartXCBMoveResize(window, edges); } @@ -909,7 +828,8 @@ bool StartSystemResize(QWindow *window, Qt::Edges edges) { bool ShowWindowMenu(QWindow *window) { if (IsWayland()) { - return ShowWaylandWindowMenu(window); + const auto integration = WaylandIntegration::Instance(); + return integration->showWindowMenu(window); } else { return ShowXCBWindowMenu(window); } diff --git a/cmake b/cmake index d9e8a608c2..4436815d19 160000 --- a/cmake +++ b/cmake @@ -1 +1 @@ -Subproject commit d9e8a608c21ca175ed118955d83010580fb46e65 +Subproject commit 4436815d19035aaba79cb69b7e2d599ae286297d