Build wayland support optionally

This commit is contained in:
mid-kid 2020-11-12 00:18:18 +01:00 committed by John Preston
parent c0142726f8
commit 96b2e26f42
6 changed files with 207 additions and 96 deletions

View File

@ -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()

View File

@ -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 <QtGui/QWindow>
#include <private/qwaylanddisplay_p.h>
#include <private/qwaylandwindow_p.h>
#include <private/qwaylandshellsurface_p.h>
#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0) && !defined DESKTOP_APP_QT_PATCHED
#include <wayland-client.h>
#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<QWaylandWindow*>(
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<QWaylandWindow*>(
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<QWaylandWindow*>(
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

View File

@ -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

View File

@ -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

View File

@ -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 <QtCore/QLibraryInfo>
#include <QtGui/QWindow>
#include <private/qwaylanddisplay_p.h>
#include <private/qwaylandwindow_p.h>
#include <private/qwaylandshellsurface_p.h>
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
#include <QtDBus/QDBusInterface>
#include <QtDBus/QDBusConnection>
@ -47,10 +44,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <xcb/xcb.h>
#include <xcb/screensaver.h>
#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0) && !defined DESKTOP_APP_QT_PATCHED
#include <wayland-client.h>
#endif // Qt < 5.13 && !DESKTOP_APP_QT_PATCHED
#include <glib.h>
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<QWaylandWindow*>(
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<QWaylandWindow*>(
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<QWaylandWindow*>(
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);
}

2
cmake

@ -1 +1 @@
Subproject commit d9e8a608c21ca175ed118955d83010580fb46e65
Subproject commit 4436815d19035aaba79cb69b7e2d599ae286297d