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 "ui/platform/linux/ui_linux_wayland_integration.h"
#include "base/platform/base_platform_info.h" #include "base/platform/base_platform_info.h"
#include "waylandshells/xdg_shell.h"
#include <QtGui/QWindow> #include <QtGui/QWindow>
@ -17,10 +18,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#define slots Q_SLOTS #define slots Q_SLOTS
#endif // QT_NO_KEYWORDS #endif // QT_NO_KEYWORDS
#include <private/qguiapplication_p.h>
#include <private/qwaylandintegration_p.h>
#include <private/qwaylanddisplay_p.h> #include <private/qwaylanddisplay_p.h>
#include <private/qwaylandwindow_p.h> #include <private/qwaylandwindow_p.h>
#include <private/qwaylandshellsurface_p.h> #include <private/qwaylandshellsurface_p.h>
Q_DECLARE_METATYPE(QMargins);
using QtWaylandClient::QWaylandIntegration;
using QtWaylandClient::QWaylandWindow; using QtWaylandClient::QWaylandWindow;
namespace Ui { namespace Ui {
@ -35,6 +41,29 @@ WaylandIntegration *WaylandIntegration::Instance() {
return &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) { bool WaylandIntegration::showWindowMenu(QWindow *window) {
if (const auto waylandWindow = static_cast<QWaylandWindow*>( if (const auto waylandWindow = static_cast<QWaylandWindow*>(
window->handle())) { window->handle())) {

View file

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

View file

@ -21,6 +21,18 @@ WaylandIntegration *WaylandIntegration::Instance() {
return &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) { bool WaylandIntegration::showWindowMenu(QWindow *window) {
return false; return false;
} }

View file

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