Move custom xdg-shell integration code to wayland integration

This commit is contained in:
Ilya Fedin 2021-06-11 11:51:18 +04:00 committed by John Preston
parent f58fd1b927
commit b600b6a3b3
4 changed files with 51 additions and 33 deletions

View file

@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/platform/linux/ui_linux_wayland_integration.h"
#include "base/platform/base_platform_info.h"
#include "waylandshells/xdg_shell.h"
#include <QtGui/QWindow>
@ -17,10 +18,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#define slots Q_SLOTS
#endif // QT_NO_KEYWORDS
#include <private/qguiapplication_p.h>
#include <private/qwaylandintegration_p.h>
#include <private/qwaylanddisplay_p.h>
#include <private/qwaylandwindow_p.h>
#include <private/qwaylandshellsurface_p.h>
Q_DECLARE_METATYPE(QMargins);
using QtWaylandClient::QWaylandIntegration;
using QtWaylandClient::QWaylandWindow;
namespace Ui {
@ -35,6 +41,29 @@ WaylandIntegration *WaylandIntegration::Instance() {
return &instance;
}
bool WaylandIntegration::windowExtentsSupported() {
// initialize shell integration before querying
if (const auto integration = static_cast<QWaylandIntegration*>(
QGuiApplicationPrivate::platformIntegration())) {
integration->shellIntegration();
}
return WaylandShells::XdgShell();
}
void WaylandIntegration::setWindowExtents(
QWindow *window,
const QMargins &extents) {
window->setProperty(
"_desktopApp_waylandCustomMargins",
QVariant::fromValue<QMargins>(extents));
}
void WaylandIntegration::unsetWindowExtents(QWindow *window) {
window->setProperty(
"_desktopApp_waylandCustomMargins",
QVariant());
}
bool WaylandIntegration::showWindowMenu(QWindow *window) {
if (const auto waylandWindow = static_cast<QWaylandWindow*>(
window->handle())) {

View file

@ -15,6 +15,10 @@ namespace Platform {
class WaylandIntegration {
public:
static WaylandIntegration *Instance();
bool windowExtentsSupported();
void setWindowExtents(QWindow *window, const QMargins &extents);
void unsetWindowExtents(QWindow *window);
bool showWindowMenu(QWindow *window);
private:

View file

@ -21,6 +21,18 @@ WaylandIntegration *WaylandIntegration::Instance() {
return &instance;
}
bool WaylandIntegration::windowExtentsSupported() {
return false;
}
void WaylandIntegration::setWindowExtents(
QWindow *window,
const QMargins &extents) {
}
void WaylandIntegration::unsetWindowExtents(QWindow *window) {
}
bool WaylandIntegration::showWindowMenu(QWindow *window) {
return false;
}

View file

@ -18,23 +18,11 @@
#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 <QtCore/QPoint>
#include <QtGui/QScreen>
#include <QtGui/QWindow>
#include <QtWidgets/QApplication>
#include <private/qguiapplication_p.h>
#include <qpa/qplatformnativeinterface.h>
#include <qpa/qplatformintegration.h>
#ifndef DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION
#include <private/qwaylandintegration_p.h>
#endif // !DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION
Q_DECLARE_METATYPE(QMargins);
namespace Ui {
namespace Platform {
@ -466,16 +454,9 @@ std::optional<bool> IsOverlapped(
}
bool WindowExtentsSupported() {
#ifndef DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION
if (::Platform::IsWayland()) {
// initialize shell integration before querying
using QtWaylandClient::QWaylandIntegration;
const auto integration = static_cast<QWaylandIntegration*>(
QGuiApplicationPrivate::platformIntegration());
integration->shellIntegration();
return WaylandShells::XdgShell();
if (const auto integration = WaylandIntegration::Instance()) {
return integration->windowExtentsSupported();
}
#endif // !DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
namespace XCB = base::Platform::XCB;
@ -489,12 +470,8 @@ bool WindowExtentsSupported() {
}
void SetWindowExtents(QWindow *window, const QMargins &extents) {
if (::Platform::IsWayland()) {
#ifndef DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION
window->setProperty(
"_desktopApp_waylandCustomMargins",
QVariant::fromValue<QMargins>(extents));
#endif // !DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION
if (const auto integration = WaylandIntegration::Instance()) {
integration->setWindowExtents(window, extents);
} else if (::Platform::IsX11()) {
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
SetXCBFrameExtents(window, extents);
@ -503,12 +480,8 @@ void SetWindowExtents(QWindow *window, const QMargins &extents) {
}
void UnsetWindowExtents(QWindow *window) {
if (::Platform::IsWayland()) {
#ifndef DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION
window->setProperty(
"_desktopApp_waylandCustomMargins",
QVariant());
#endif // !DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION
if (const auto integration = WaylandIntegration::Instance()) {
integration->unsetWindowExtents(window);
} else if (::Platform::IsX11()) {
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
UnsetXCBFrameExtents(window);