From 57a5d8e1ed90507a6f7d1571bae6147388b5a533 Mon Sep 17 00:00:00 2001
From: outfoxxed <outfoxxed@outfoxxed.me>
Date: Fri, 22 Nov 2024 20:18:04 -0800
Subject: [PATCH] core/reloader: wrap QQuickItem root nodes in a floating
 window

Useful for testing
---
 src/core/rootwrapper.cpp | 11 +++++++++++
 src/core/shell.hpp       |  2 +-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/core/rootwrapper.cpp b/src/core/rootwrapper.cpp
index 76b3d3ce..b394af58 100644
--- a/src/core/rootwrapper.cpp
+++ b/src/core/rootwrapper.cpp
@@ -8,9 +8,11 @@
 #include <qobject.h>
 #include <qqmlcomponent.h>
 #include <qqmlengine.h>
+#include <qquickitem.h>
 #include <qtmetamacros.h>
 #include <qurl.h>
 
+#include "../window/floatingwindow.hpp"
 #include "generation.hpp"
 #include "qmlglobal.hpp"
 #include "scan.hpp"
@@ -73,6 +75,15 @@ void RootWrapper::reloadGraph(bool hard) {
 		return;
 	}
 
+	if (auto* item = qobject_cast<QQuickItem*>(newRoot)) {
+		auto* window = new FloatingWindowInterface();
+		item->setParent(window);
+		item->setParentItem(window->contentItem());
+		window->setWidth(static_cast<int>(item->width()));
+		window->setHeight(static_cast<int>(item->height()));
+		newRoot = window;
+	}
+
 	generation->root = newRoot;
 
 	component.completeCreate();
diff --git a/src/core/shell.hpp b/src/core/shell.hpp
index 807f0275..66b6ef6a 100644
--- a/src/core/shell.hpp
+++ b/src/core/shell.hpp
@@ -8,7 +8,7 @@
 #include "qmlglobal.hpp"
 #include "reload.hpp"
 
-///! Root config element
+///! Optional root config element, allowing some settings to be specified inline.
 class ShellRoot: public ReloadPropagator {
 	Q_OBJECT;
 	Q_PROPERTY(QuickshellSettings* settings READ settings CONSTANT);