core/window: ensure items are polished before setting window visible

Hacks around a bug in layouts that commonly results in popups being
wrongly sized for at least a frame.
This commit is contained in:
outfoxxed 2024-07-10 03:44:55 -07:00
parent db23c0264a
commit 497c9c4e50
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E
3 changed files with 15 additions and 1 deletions

View file

@ -37,7 +37,7 @@ qt_add_library(quickshell-core STATIC
set_source_files_properties(main.cpp PROPERTIES COMPILE_DEFINITIONS GIT_REVISION="${GIT_REVISION}")
qt_add_qml_module(quickshell-core URI Quickshell VERSION 0.1)
target_link_libraries(quickshell-core PRIVATE ${QT_DEPS})
target_link_libraries(quickshell-core PRIVATE ${QT_DEPS} Qt6::QuickPrivate)
qs_pch(quickshell-core)
target_link_libraries(quickshell PRIVATE quickshell-coreplugin)

View file

@ -11,6 +11,7 @@
#include <qtmetamacros.h>
#include <qtypes.h>
#include <qwindow.h>
#include <private/qquickwindow_p.h>
#include "generation.hpp"
#include "qmlglobal.hpp"
@ -182,6 +183,7 @@ void ProxyWindowBase::setVisibleDirect(bool visible) {
if (visible) {
this->createWindow();
this->polishItems();
this->window->setVisible(true);
emit this->backerVisibilityChanged();
} else {
@ -192,11 +194,22 @@ void ProxyWindowBase::setVisibleDirect(bool visible) {
}
}
} else if (this->window != nullptr) {
if (visible) this->polishItems();
this->window->setVisible(visible);
emit this->backerVisibilityChanged();
}
}
void ProxyWindowBase::polishItems() {
// Due to QTBUG-126704, layouts in invisible windows don't update their dimensions.
// Usually this isn't an issue, but it is when the size of a window is based on the size
// of its content, and that content is in a layout.
//
// This hack manually polishes the item tree right before showing the window so it will
// always be created with the correct size.
QQuickWindowPrivate::get(this->window)->polishItems();
}
qint32 ProxyWindowBase::x() const {
if (this->window == nullptr) return 0;
else return this->window->x();

View file

@ -133,5 +133,6 @@ protected:
bool reloadComplete = false;
private:
void polishItems();
void updateMask();
};