Use new Qt 6.4 API for window extents on Wayland

This commit is contained in:
Ilya Fedin 2022-09-01 16:37:51 +04:00 committed by John Preston
parent 47268d21ce
commit f6e875c748
2 changed files with 35 additions and 12 deletions

View file

@ -295,7 +295,6 @@ elseif(LINUX)
target_link_libraries(lib_ui target_link_libraries(lib_ui
PUBLIC PUBLIC
desktop-app::lib_waylandshells
desktop-app::external_wayland_client desktop-app::external_wayland_client
) )
endif() endif()

View file

@ -9,7 +9,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/platform/base_platform_info.h" #include "base/platform/base_platform_info.h"
#include "base/qt_signal_producer.h" #include "base/qt_signal_producer.h"
#include "waylandshells/xdg_shell.h"
#include "qwayland-xdg-shell.h" #include "qwayland-xdg-shell.h"
#include <QtGui/QGuiApplication> #include <QtGui/QGuiApplication>
@ -17,7 +16,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <qpa/qplatformnativeinterface.h> #include <qpa/qplatformnativeinterface.h>
#include <wayland-client.h> #include <wayland-client.h>
Q_DECLARE_METATYPE(QMargins); typedef void (*SetWindowMarginsFunc)(
QWindow *window,
const QMargins &margins);
namespace Ui { namespace Ui {
namespace Platform { namespace Platform {
@ -141,7 +142,20 @@ bool WaylandIntegration::xdgDecorationSupported() {
} }
bool WaylandIntegration::windowExtentsSupported() { bool WaylandIntegration::windowExtentsSupported() {
return WaylandShells::XdgShell(); const auto native = QGuiApplication::platformNativeInterface();
if (!native) {
return false;
}
const auto setWindowMargins = reinterpret_cast<SetWindowMarginsFunc>(
reinterpret_cast<void*>(
native->nativeResourceFunctionForWindow("setmargins")));
if (!setWindowMargins) {
return false;
}
return true;
} }
void WaylandIntegration::setWindowExtents( void WaylandIntegration::setWindowExtents(
@ -152,10 +166,15 @@ void WaylandIntegration::setWindowExtents(
return; return;
} }
native->setWindowProperty( const auto setWindowMargins = reinterpret_cast<SetWindowMarginsFunc>(
widget->windowHandle()->handle(), reinterpret_cast<void*>(
"_desktopApp_waylandCustomMargins", native->nativeResourceFunctionForWindow("setmargins")));
QVariant::fromValue<QMargins>(extents));
if (!setWindowMargins) {
return;
}
setWindowMargins(widget->windowHandle(), extents);
} }
void WaylandIntegration::unsetWindowExtents(not_null<QWidget*> widget) { void WaylandIntegration::unsetWindowExtents(not_null<QWidget*> widget) {
@ -164,10 +183,15 @@ void WaylandIntegration::unsetWindowExtents(not_null<QWidget*> widget) {
return; return;
} }
native->setWindowProperty( const auto setWindowMargins = reinterpret_cast<SetWindowMarginsFunc>(
widget->windowHandle()->handle(), reinterpret_cast<void*>(
"_desktopApp_waylandCustomMargins", native->nativeResourceFunctionForWindow("setmargins")));
QVariant());
if (!setWindowMargins) {
return;
}
setWindowMargins(widget->windowHandle(), QMargins());
} }
void WaylandIntegration::showWindowMenu( void WaylandIntegration::showWindowMenu(