Skip to content

Commit 86dae5d

Browse files
committed
core/window: add parentWindow property to FloatingWindow
1 parent 3918290 commit 86dae5d

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

src/window/floatingwindow.cpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <qnamespace.h>
44
#include <qobject.h>
55
#include <qqmlengine.h>
6-
#include <qqmllist.h>
6+
#include <qqmlinfo.h>
77
#include <qtmetamacros.h>
88
#include <qtypes.h>
99
#include <qwindow.h>
@@ -19,6 +19,13 @@ void ProxyFloatingWindow::connectWindow() {
1919
this->window->setMaximumSize(this->bMaximumSize);
2020
}
2121

22+
void ProxyFloatingWindow::postCompleteWindow() {
23+
auto* parentBacking =
24+
this->mParentProxyWindow ? this->mParentProxyWindow->backingWindow() : nullptr;
25+
26+
this->window->setTransientParent(parentBacking);
27+
}
28+
2229
void ProxyFloatingWindow::trySetWidth(qint32 implicitWidth) {
2330
if (!this->window->isVisible()) {
2431
this->ProxyWindowBase::trySetWidth(implicitWidth);
@@ -46,6 +53,28 @@ void ProxyFloatingWindow::onMaximumSizeChanged() {
4653
emit this->maximumSizeChanged();
4754
}
4855

56+
QObject* ProxyFloatingWindow::parentWindow() const { return this->mParentWindow; }
57+
58+
void ProxyFloatingWindow::setParentWindow(QObject* window) {
59+
if (window == this->mParentWindow) return;
60+
61+
if (window) {
62+
if (auto* proxy = qobject_cast<ProxyWindowBase*>(window)) {
63+
this->mParentProxyWindow = proxy;
64+
} else if (auto* interface = qobject_cast<WindowInterface*>(window)) {
65+
this->mParentProxyWindow = interface->proxyWindow();
66+
} else {
67+
qmlWarning(this) << "parentWindow must be a quickshell window.";
68+
return;
69+
}
70+
71+
this->mParentWindow = window;
72+
} else {
73+
this->mParentWindow = nullptr;
74+
this->mParentProxyWindow = nullptr;
75+
}
76+
}
77+
4978
// FloatingWindowInterface
5079

5180
FloatingWindowInterface::FloatingWindowInterface(QObject* parent)
@@ -169,3 +198,9 @@ bool FloatingWindowInterface::startSystemResize(Qt::Edges edges) const {
169198
if (!qw) return false;
170199
return qw->startSystemResize(edges);
171200
}
201+
202+
QObject* FloatingWindowInterface::parentWindow() const { return this->window->parentWindow(); }
203+
204+
void FloatingWindowInterface::setParentWindow(QObject* window) {
205+
this->window->setParentWindow(window);
206+
}

src/window/floatingwindow.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ class ProxyFloatingWindow: public ProxyWindowBase {
1919
explicit ProxyFloatingWindow(QObject* parent = nullptr): ProxyWindowBase(parent) {}
2020

2121
void connectWindow() override;
22+
void postCompleteWindow() override;
23+
24+
[[nodiscard]] QObject* parentWindow() const;
25+
void setParentWindow(QObject* window);
2226

2327
// Setting geometry while the window is visible makes the content item shrink but not the window
2428
// which is awful so we disable it for floating windows.
@@ -35,6 +39,9 @@ class ProxyFloatingWindow: public ProxyWindowBase {
3539
void onMaximumSizeChanged();
3640
void onTitleChanged();
3741

42+
QObject* mParentWindow = nullptr;
43+
ProxyWindowBase* mParentProxyWindow = nullptr;
44+
3845
public:
3946
Q_OBJECT_BINDABLE_PROPERTY(
4047
ProxyFloatingWindow,
@@ -75,6 +82,11 @@ class FloatingWindowInterface: public WindowInterface {
7582
Q_PROPERTY(bool maximized READ isMaximized WRITE setMaximized NOTIFY maximizedChanged);
7683
/// Whether the window is currently fullscreen.
7784
Q_PROPERTY(bool fullscreen READ isFullscreen WRITE setFullscreen NOTIFY fullscreenChanged);
85+
/// The parent window of this window. Setting this makes the window a child of the parent,
86+
/// which affects window stacking behavior.
87+
///
88+
/// > [!NOTE] This property cannot be changed after the window is visible.
89+
Q_PROPERTY(QObject* parentWindow READ parentWindow WRITE setParentWindow);
7890
// clang-format on
7991
QML_NAMED_ELEMENT(FloatingWindow);
8092

@@ -101,6 +113,9 @@ class FloatingWindowInterface: public WindowInterface {
101113
/// Start a system resize operation. Must be called during a pointer press/drag.
102114
Q_INVOKABLE [[nodiscard]] bool startSystemResize(Qt::Edges edges) const;
103115

116+
[[nodiscard]] QObject* parentWindow() const;
117+
void setParentWindow(QObject* window);
118+
104119
signals:
105120
void minimumSizeChanged();
106121
void maximumSizeChanged();

0 commit comments

Comments
 (0)