Add UnsetWindowExtents method

This commit is contained in:
Ilya Fedin 2020-08-29 01:00:09 +04:00 committed by John Preston
parent 3c8c059447
commit c77f1bf082
4 changed files with 60 additions and 5 deletions

View file

@ -720,6 +720,35 @@ bool SetXCBFrameExtents(QWindow *window, const QMargins &extents) {
return true;
}
bool UnsetXCBFrameExtents(QWindow *window) {
const auto native = QGuiApplication::platformNativeInterface();
if (!native) {
return false;
}
const auto connection = reinterpret_cast<xcb_connection_t*>(
native->nativeResourceForIntegration(QByteArray("connection")));
if (!connection) {
return false;
}
const auto frameExtentsAtom = GetXCBAtom(
connection,
kXCBFrameExtentsAtomName.utf16());
if (!frameExtentsAtom.has_value()) {
return false;
}
xcb_delete_property(
connection,
window->winId(),
*frameExtentsAtom);
return true;
}
bool SetWaylandWindowGeometry(QWindow *window, const QRect &geometry) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0) || defined DESKTOP_APP_QT_PATCHED
if (const auto waylandWindow = static_cast<QWaylandWindow*>(
@ -1091,6 +1120,15 @@ bool SetWindowExtents(QWindow *window, const QMargins &extents) {
}
}
bool UnsetWindowExtents(QWindow *window) {
if (IsWayland()) {
const auto geometry = QRect(QPoint(), window->size());
return SetWaylandWindowGeometry(window, geometry);
} else {
return UnsetXCBFrameExtents(window);
}
}
bool WindowsNeedShadow() {
#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0) || defined DESKTOP_APP_QT_PATCHED
if (IsWayland()) {

View file

@ -58,6 +58,7 @@ bool StartSystemResize(QWindow *window, Qt::Edges edges);
bool ShowWindowMenu(QWindow *window);
bool WindowsNeedShadow();
bool SetWindowExtents(QWindow *window, const QMargins &extents);
bool UnsetWindowExtents(QWindow *window);
Window::ControlsLayout WindowControlsLayout();
namespace ThirdParty {

View file

@ -85,10 +85,14 @@ TitleWidgetQt::TitleWidgetQt(QWidget *parent)
TitleWidgetQt::~TitleWidgetQt() {
restoreCursor();
if (!_windowWasFrameless) {
toggleFramelessWindow(false);
}
Platform::SetWindowExtents(window()->windowHandle(), QMargins());
if (_extentsSet) {
Platform::UnsetWindowExtents(window()->windowHandle());
}
}
void TitleWidgetQt::toggleFramelessWindow(bool enabled) {
@ -137,10 +141,21 @@ void TitleWidgetQt::paintEvent(QPaintEvent *e) {
}
void TitleWidgetQt::updateWindowExtents() {
if (hasShadow() && !_maximizedState) {
Platform::SetWindowExtents(window()->windowHandle(), ShadowExtents());
} else {
Platform::SetWindowExtents(window()->windowHandle(), QMargins());
if (hasShadow()) {
if (!_maximizedState) {
Platform::SetWindowExtents(
window()->windowHandle(),
ShadowExtents());
} else {
Platform::SetWindowExtents(
window()->windowHandle(),
QMargins());
}
_extentsSet = true;
} else if (_extentsSet) {
Platform::UnsetWindowExtents(window()->windowHandle());
_extentsSet = false;
}
}

View file

@ -66,6 +66,7 @@ private:
bool _activeState = false;
bool _windowWasFrameless = false;
bool _cursorOverriden = false;
bool _extentsSet = false;
};