Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
FloatingWindow.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include <PhosphorShell/phosphorshell_export.h>
7
8#include <QQuickItem>
9#include <QString>
10
11#include <memory>
12
13QT_BEGIN_NAMESPACE
14class QQuickWindow;
15QT_END_NAMESPACE
16
17namespace PhosphorShell {
18
19// A plain xdg toplevel driven from QML (or from C++ with the same
20// surface). Children declared on it are moved into the toplevel's own
21// QQuickWindow, so the item is a description of a window rather than a
22// place in the scene.
23//
24// The compositor places, sizes and stacks it like any application window,
25// which is the point: an engine-placed shell pane (A2 §4) IS one of these,
26// with `appId` naming it to the daemon's window rules and `minimumWidth` /
27// `minimumHeight` telling tiling and scrolling how small a slot it accepts.
28class PHOSPHORSHELL_EXPORT FloatingWindow : public QQuickItem
29{
30 Q_OBJECT
31
32 Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
33 Q_PROPERTY(int windowWidth READ windowWidth WRITE setWindowWidth NOTIFY windowWidthChanged)
34 Q_PROPERTY(int windowHeight READ windowHeight WRITE setWindowHeight NOTIFY windowHeightChanged)
35 Q_PROPERTY(bool windowVisible READ isWindowVisible WRITE setWindowVisible NOTIFY windowVisibleChanged)
36 // The toplevel's Wayland app_id, set PER WINDOW through Qt's shell
37 // surface rather than process-wide through
38 // QGuiApplication::setDesktopFileName, so one process can own windows
39 // with different identities (the shell's panes each carry their own).
40 // Empty keeps Qt's default (the desktop file name, else the binary
41 // name). Applied when the window maps; changing it afterwards re-sends
42 // it, which xdg-shell permits but most compositors only read at map.
43 Q_PROPERTY(QString appId READ appId WRITE setAppId NOTIFY appIdChanged)
44 // xdg_toplevel min size hints. 0 means unconstrained on that axis.
45 Q_PROPERTY(int minimumWidth READ minimumWidth WRITE setMinimumWidth NOTIFY minimumWidthChanged)
47 // Ask the compositor for no server-side decoration: a frameless
48 // toplevel draws its own edge. A shell pane sets this so it reads as a
49 // tile, not a titled window. Applied live: a window already up has its
50 // flags reset, so this may be toggled at any point in its life.
51 Q_PROPERTY(bool frameless READ isFrameless WRITE setFrameless NOTIFY framelessChanged)
52
53public:
54 explicit FloatingWindow(QQuickItem* parent = nullptr);
55 ~FloatingWindow() override;
56
57 [[nodiscard]] QString title() const;
58 void setTitle(const QString& title);
59
60 [[nodiscard]] int windowWidth() const;
61 void setWindowWidth(int width);
62
63 [[nodiscard]] int windowHeight() const;
64 void setWindowHeight(int height);
65
66 [[nodiscard]] bool isWindowVisible() const;
67 void setWindowVisible(bool visible);
68
69 [[nodiscard]] QString appId() const;
70 void setAppId(const QString& appId);
71
72 [[nodiscard]] int minimumWidth() const;
73 void setMinimumWidth(int width);
74
75 [[nodiscard]] int minimumHeight() const;
76 void setMinimumHeight(int height);
77
78 [[nodiscard]] bool isFrameless() const;
79 void setFrameless(bool frameless);
80
81 // The toplevel itself, or null before the first show. Not named
82 // `window()`: QQuickItem::window() is the scene this ITEM lives in,
83 // which for a FloatingWindow is unrelated to the toplevel it owns.
84 [[nodiscard]] QQuickWindow* quickWindow() const;
85
86Q_SIGNALS:
95 // The compositor closed the toplevel (xdg_toplevel.close, which Qt
96 // delivers as a close event and hides the window). `windowVisible` is
97 // already false when this fires. A compositor-placed pane needs this:
98 // the engine's "close window" verb reaches it exactly this way, and
99 // without the report the owner would keep a handle for a window that
100 // is gone.
102
103protected:
104 void itemChange(ItemChange change, const ItemChangeData& value) override;
105
106private:
107 void ensureWindow();
108 void reparentChildToWindow(QQuickItem* child);
109 void applyAppId();
110 void applyMinimumSize();
111
112 QString m_title;
113 QString m_appId;
114 int m_windowWidth = 400;
115 int m_windowHeight = 300;
116 int m_minimumWidth = 0;
117 int m_minimumHeight = 0;
118 bool m_frameless = false;
119 bool m_windowVisible = false;
120 std::unique_ptr<QQuickWindow> m_window;
121};
122
123} // namespace PhosphorShell
void setFrameless(bool frameless)
void setMinimumWidth(int width)
void setWindowWidth(int width)
void setAppId(const QString &appId)
void setWindowVisible(bool visible)
void setTitle(const QString &title)
void setWindowHeight(int height)
void itemChange(ItemChange change, const ItemChangeData &value) override
FloatingWindow(QQuickItem *parent=nullptr)
QQuickWindow * quickWindow() const
void setMinimumHeight(int height)
Definition Environment.h:11