forked from quickshell/quickshell
		
	fix(wayland): layershell windows are recreated if attach fails
Usually this happens if the namespace changes
This commit is contained in:
		
							parent
							
								
									c2930783ea
								
							
						
					
					
						commit
						13c5d7c7a9
					
				
					 5 changed files with 41 additions and 13 deletions
				
			
		| 
						 | 
					@ -28,14 +28,7 @@ ProxyWindowBase::~ProxyWindowBase() {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void ProxyWindowBase::onReload(QObject* oldInstance) {
 | 
					void ProxyWindowBase::onReload(QObject* oldInstance) {
 | 
				
			||||||
	auto* old = qobject_cast<ProxyWindowBase*>(oldInstance);
 | 
						this->window = this->createWindow(oldInstance);
 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (old == nullptr || old->window == nullptr) {
 | 
					 | 
				
			||||||
		this->window = new QQuickWindow();
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		this->window = old->disownWindow();
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	this->setupWindow();
 | 
						this->setupWindow();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Reloadable::reloadRecursive(this->mContentItem, oldInstance);
 | 
						Reloadable::reloadRecursive(this->mContentItem, oldInstance);
 | 
				
			||||||
| 
						 | 
					@ -52,6 +45,16 @@ void ProxyWindowBase::onReload(QObject* oldInstance) {
 | 
				
			||||||
	this->window->setVisible(this->mVisible);
 | 
						this->window->setVisible(this->mVisible);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					QQuickWindow* ProxyWindowBase::createWindow(QObject* oldInstance) {
 | 
				
			||||||
 | 
						auto* old = qobject_cast<ProxyWindowBase*>(oldInstance);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (old == nullptr || old->window == nullptr) {
 | 
				
			||||||
 | 
							return new QQuickWindow();
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							return old->disownWindow();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void ProxyWindowBase::setupWindow() {
 | 
					void ProxyWindowBase::setupWindow() {
 | 
				
			||||||
	// clang-format off
 | 
						// clang-format off
 | 
				
			||||||
	QObject::connect(this->window, &QWindow::visibilityChanged, this, &ProxyWindowBase::visibleChanged);
 | 
						QObject::connect(this->window, &QWindow::visibilityChanged, this, &ProxyWindowBase::visibleChanged);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -55,6 +55,7 @@ public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void onReload(QObject* oldInstance) override;
 | 
						void onReload(QObject* oldInstance) override;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						virtual QQuickWindow* createWindow(QObject* oldInstance);
 | 
				
			||||||
	virtual void setupWindow();
 | 
						virtual void setupWindow();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Disown the backing window and delete all its children.
 | 
						// Disown the backing window and delete all its children.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,7 +13,6 @@ pkg_check_modules(wayland REQUIRED IMPORTED_TARGET wayland-client wayland-protoc
 | 
				
			||||||
find_package(Qt6 REQUIRED COMPONENTS WaylandClient)
 | 
					find_package(Qt6 REQUIRED COMPONENTS WaylandClient)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
target_link_libraries(quickshell-wayland PRIVATE ${QT_DEPS} wayland-client)
 | 
					target_link_libraries(quickshell-wayland PRIVATE ${QT_DEPS} wayland-client)
 | 
				
			||||||
message(STATUS Qt6::WaylandClient)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
# wayland protocols
 | 
					# wayland protocols
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,6 +5,7 @@
 | 
				
			||||||
#include <qobject.h>
 | 
					#include <qobject.h>
 | 
				
			||||||
#include <qqmllist.h>
 | 
					#include <qqmllist.h>
 | 
				
			||||||
#include <qquickitem.h>
 | 
					#include <qquickitem.h>
 | 
				
			||||||
 | 
					#include <qquickwindow.h>
 | 
				
			||||||
#include <qtmetamacros.h>
 | 
					#include <qtmetamacros.h>
 | 
				
			||||||
#include <qtypes.h>
 | 
					#include <qtypes.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -17,6 +18,31 @@ WaylandLayershell::WaylandLayershell(QObject* parent)
 | 
				
			||||||
    : ProxyWindowBase(parent)
 | 
					    : ProxyWindowBase(parent)
 | 
				
			||||||
    , ext(new LayershellWindowExtension(this)) {}
 | 
					    , ext(new LayershellWindowExtension(this)) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					QQuickWindow* WaylandLayershell::createWindow(QObject* oldInstance) {
 | 
				
			||||||
 | 
						auto* old = qobject_cast<WaylandLayershell*>(oldInstance);
 | 
				
			||||||
 | 
						QQuickWindow* window = nullptr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (old == nullptr || old->window == nullptr) {
 | 
				
			||||||
 | 
							window = new QQuickWindow();
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							window = old->disownWindow();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (this->ext->attach(window)) {
 | 
				
			||||||
 | 
								return window;
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								window->deleteLater();
 | 
				
			||||||
 | 
								window = new QQuickWindow();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!this->ext->attach(window)) {
 | 
				
			||||||
 | 
							qWarning() << "Could not attach Layershell extension to new QQUickWindow. Layer will not "
 | 
				
			||||||
 | 
							              "behave correctly.";
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return window;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void WaylandLayershell::setupWindow() {
 | 
					void WaylandLayershell::setupWindow() {
 | 
				
			||||||
	this->ProxyWindowBase::setupWindow();
 | 
						this->ProxyWindowBase::setupWindow();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -32,10 +58,6 @@ void WaylandLayershell::setupWindow() {
 | 
				
			||||||
	QObject::connect(this, &WaylandLayershell::anchorsChanged, this, &WaylandLayershell::updateAutoExclusion);
 | 
						QObject::connect(this, &WaylandLayershell::anchorsChanged, this, &WaylandLayershell::updateAutoExclusion);
 | 
				
			||||||
	QObject::connect(this, &WaylandLayershell::marginsChanged, this, &WaylandLayershell::updateAutoExclusion);
 | 
						QObject::connect(this, &WaylandLayershell::marginsChanged, this, &WaylandLayershell::updateAutoExclusion);
 | 
				
			||||||
	// clang-format on
 | 
						// clang-format on
 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (!this->ext->attach(this->window)) {
 | 
					 | 
				
			||||||
		// todo: discard window
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void WaylandLayershell::setWidth(qint32 width) {
 | 
					void WaylandLayershell::setWidth(qint32 width) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,6 +2,8 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <qobject.h>
 | 
					#include <qobject.h>
 | 
				
			||||||
#include <qqmlintegration.h>
 | 
					#include <qqmlintegration.h>
 | 
				
			||||||
 | 
					#include <qquickitem.h>
 | 
				
			||||||
 | 
					#include <qquickwindow.h>
 | 
				
			||||||
#include <qtmetamacros.h>
 | 
					#include <qtmetamacros.h>
 | 
				
			||||||
#include <qtypes.h>
 | 
					#include <qtypes.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -30,6 +32,7 @@ class WaylandLayershell: public ProxyWindowBase {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
	explicit WaylandLayershell(QObject* parent = nullptr);
 | 
						explicit WaylandLayershell(QObject* parent = nullptr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						QQuickWindow* createWindow(QObject* oldInstance) override;
 | 
				
			||||||
	void setupWindow() override;
 | 
						void setupWindow() override;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void setWidth(qint32 width) override;
 | 
						void setWidth(qint32 width) override;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue