Skip to content

Commit 09b3822

Browse files
committed
core/window: add startSystemMove, startSystemResize, maximize, and fullscreen to FloatingWindow
1 parent e9bad67 commit 09b3822

File tree

4 files changed

+85
-3
lines changed

4 files changed

+85
-3
lines changed

src/window/floatingwindow.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <qqmllist.h>
66
#include <qtmetamacros.h>
77
#include <qtypes.h>
8+
#include <qwindow.h>
89

910
#include "proxywindow.hpp"
1011
#include "windowinterface.hpp"
@@ -55,6 +56,7 @@ FloatingWindowInterface::FloatingWindowInterface(QObject* parent)
5556
QObject::connect(this->window, &ProxyFloatingWindow::titleChanged, this, &FloatingWindowInterface::titleChanged);
5657
QObject::connect(this->window, &ProxyFloatingWindow::minimumSizeChanged, this, &FloatingWindowInterface::minimumSizeChanged);
5758
QObject::connect(this->window, &ProxyFloatingWindow::maximumSizeChanged, this, &FloatingWindowInterface::maximumSizeChanged);
59+
QObject::connect(this->window, &ProxyWindowBase::windowVisibilityChanged, this, &FloatingWindowInterface::onVisibilityChanged);
5860
// clang-format on
5961
}
6062

@@ -66,3 +68,52 @@ void FloatingWindowInterface::onReload(QObject* oldInstance) {
6668
}
6769

6870
ProxyWindowBase* FloatingWindowInterface::proxyWindow() const { return this->window; }
71+
72+
void FloatingWindowInterface::onVisibilityChanged() {
73+
auto* qw = this->window->backingWindow();
74+
auto visibility = qw ? qw->visibility() : QWindow::Hidden;
75+
76+
auto maximized = visibility == QWindow::Maximized;
77+
auto fullscreen = visibility == QWindow::FullScreen;
78+
79+
if (maximized != this->mMaximized) {
80+
this->mMaximized = maximized;
81+
emit this->maximizedChanged();
82+
}
83+
84+
if (fullscreen != this->mFullscreen) {
85+
this->mFullscreen = fullscreen;
86+
emit this->fullscreenChanged();
87+
}
88+
}
89+
90+
bool FloatingWindowInterface::maximized() const { return this->mMaximized; }
91+
bool FloatingWindowInterface::fullscreen() const { return this->mFullscreen; }
92+
93+
bool FloatingWindowInterface::startSystemMove() const {
94+
auto* qw = this->window->backingWindow();
95+
if (!qw) return false;
96+
return qw->startSystemMove();
97+
}
98+
99+
bool FloatingWindowInterface::startSystemResize(Qt::Edges edges) const {
100+
auto* qw = this->window->backingWindow();
101+
if (!qw) return false;
102+
return qw->startSystemResize(edges);
103+
}
104+
105+
void FloatingWindowInterface::showNormal() const {
106+
if (auto* qw = this->window->backingWindow()) qw->showNormal();
107+
}
108+
109+
void FloatingWindowInterface::showMaximized() const {
110+
if (auto* qw = this->window->backingWindow()) qw->showMaximized();
111+
}
112+
113+
void FloatingWindowInterface::showMinimized() const {
114+
if (auto* qw = this->window->backingWindow()) qw->showMinimized();
115+
}
116+
117+
void FloatingWindowInterface::showFullScreen() const {
118+
if (auto* qw = this->window->backingWindow()) qw->showFullScreen();
119+
}

src/window/floatingwindow.hpp

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <qnamespace.h>
34
#include <qobject.h>
45
#include <qproperty.h>
56
#include <qsize.h>
@@ -68,6 +69,10 @@ class FloatingWindowInterface: public WindowInterface {
6869
Q_PROPERTY(QSize minimumSize READ default WRITE default NOTIFY minimumSizeChanged BINDABLE bindableMinimumSize);
6970
/// Maximum window size given to the window system.
7071
Q_PROPERTY(QSize maximumSize READ default WRITE default NOTIFY maximumSizeChanged BINDABLE bindableMaximumSize);
72+
/// Whether the window is currently maximized.
73+
Q_PROPERTY(bool maximized READ maximized NOTIFY maximizedChanged);
74+
/// Whether the window is currently fullscreen.
75+
Q_PROPERTY(bool fullscreen READ fullscreen NOTIFY fullscreenChanged);
7176
// clang-format on
7277
QML_NAMED_ELEMENT(FloatingWindow);
7378

@@ -78,15 +83,39 @@ class FloatingWindowInterface: public WindowInterface {
7883

7984
[[nodiscard]] ProxyWindowBase* proxyWindow() const override;
8085

81-
QBindable<QSize> bindableMinimumSize() { return &this->window->bMinimumSize; }
82-
QBindable<QSize> bindableMaximumSize() { return &this->window->bMaximumSize; }
83-
QBindable<QString> bindableTitle() { return &this->window->bTitle; }
86+
[[nodiscard]] QBindable<QSize> bindableMinimumSize() { return &this->window->bMinimumSize; }
87+
[[nodiscard]] QBindable<QSize> bindableMaximumSize() { return &this->window->bMaximumSize; }
88+
[[nodiscard]] QBindable<QString> bindableTitle() { return &this->window->bTitle; }
89+
90+
[[nodiscard]] bool maximized() const;
91+
[[nodiscard]] bool fullscreen() const;
92+
93+
/// Start a system move operation. Must be called during a pointer press/drag.
94+
Q_INVOKABLE [[nodiscard]] bool startSystemMove() const;
95+
/// Start a system resize operation. Must be called during a pointer press/drag.
96+
Q_INVOKABLE [[nodiscard]] bool startSystemResize(Qt::Edges edges) const;
97+
98+
/// Show the window in normal (restored) state.
99+
Q_INVOKABLE void showNormal() const;
100+
/// Show the window maximized.
101+
Q_INVOKABLE void showMaximized() const;
102+
/// Show the window minimized.
103+
Q_INVOKABLE void showMinimized() const;
104+
/// Show the window fullscreen.
105+
Q_INVOKABLE void showFullScreen() const;
84106

85107
signals:
86108
void minimumSizeChanged();
87109
void maximumSizeChanged();
88110
void titleChanged();
111+
void maximizedChanged();
112+
void fullscreenChanged();
113+
114+
private slots:
115+
void onVisibilityChanged();
89116

90117
private:
91118
ProxyFloatingWindow* window;
119+
bool mMaximized = false;
120+
bool mFullscreen = false;
92121
};

src/window/proxywindow.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ void ProxyWindowBase::onVisibleChanged() {
248248
}
249249

250250
emit this->visibleChanged();
251+
emit this->windowVisibilityChanged();
251252
}
252253

253254
bool ProxyWindowBase::deleteOnInvisible() const { return false; }

src/window/proxywindow.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ class ProxyWindowBase: public Reloadable {
147147
void windowDestroyed();
148148
void visibleChanged();
149149
void backerVisibilityChanged();
150+
void windowVisibilityChanged();
150151
void xChanged();
151152
void yChanged();
152153
void implicitWidthChanged();

0 commit comments

Comments
 (0)