Skip to content

Commit 71b68d5

Browse files
committed
core/window: add minimize, use windowStates
1 parent 1e92496 commit 71b68d5

File tree

2 files changed

+44
-19
lines changed

2 files changed

+44
-19
lines changed

src/window/floatingwindow.cpp

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <qqmllist.h>
77
#include <qtmetamacros.h>
88
#include <qtypes.h>
9-
#include <qwindow.h>
109

1110
#include "proxywindow.hpp"
1211
#include "windowinterface.hpp"
@@ -72,10 +71,16 @@ ProxyWindowBase* FloatingWindowInterface::proxyWindow() const { return this->win
7271

7372
void FloatingWindowInterface::onVisibilityChanged() {
7473
auto* qw = this->window->backingWindow();
75-
auto visibility = qw ? qw->visibility() : QWindow::Hidden;
74+
auto states = qw ? qw->windowStates() : Qt::WindowStates();
7675

77-
auto maximized = visibility == QWindow::Maximized;
78-
auto fullscreen = visibility == QWindow::FullScreen;
76+
auto minimized = states.testFlag(Qt::WindowMinimized);
77+
auto maximized = states.testFlag(Qt::WindowMaximized);
78+
auto fullscreen = states.testFlag(Qt::WindowFullScreen);
79+
80+
if (minimized != this->mMinimized) {
81+
this->mMinimized = minimized;
82+
emit this->minimizedChanged();
83+
}
7984

8085
if (maximized != this->mMaximized) {
8186
this->mMaximized = maximized;
@@ -88,8 +93,23 @@ void FloatingWindowInterface::onVisibilityChanged() {
8893
}
8994
}
9095

91-
bool FloatingWindowInterface::maximized() const { return this->mMaximized; }
92-
bool FloatingWindowInterface::fullscreen() const { return this->mFullscreen; }
96+
bool FloatingWindowInterface::isMinimized() const {
97+
auto* qw = this->window->backingWindow();
98+
if (!qw) return this->mMinimized;
99+
return qw->windowStates().testFlag(Qt::WindowMinimized);
100+
}
101+
102+
bool FloatingWindowInterface::isMaximized() const {
103+
auto* qw = this->window->backingWindow();
104+
if (!qw) return this->mMaximized;
105+
return qw->windowStates().testFlag(Qt::WindowMaximized);
106+
}
107+
108+
bool FloatingWindowInterface::isFullscreen() const {
109+
auto* qw = this->window->backingWindow();
110+
if (!qw) return this->mFullscreen;
111+
return qw->windowStates().testFlag(Qt::WindowFullScreen);
112+
}
93113

94114
bool FloatingWindowInterface::startSystemMove() const {
95115
auto* qw = this->window->backingWindow();
@@ -107,14 +127,14 @@ void FloatingWindowInterface::showNormal() const {
107127
if (auto* qw = this->window->backingWindow()) qw->showNormal();
108128
}
109129

110-
void FloatingWindowInterface::showMaximized() const {
130+
void FloatingWindowInterface::maximize() const {
111131
if (auto* qw = this->window->backingWindow()) qw->showMaximized();
112132
}
113133

114-
void FloatingWindowInterface::showMinimized() const {
134+
void FloatingWindowInterface::minimize() const {
115135
if (auto* qw = this->window->backingWindow()) qw->showMinimized();
116136
}
117137

118-
void FloatingWindowInterface::showFullScreen() const {
138+
void FloatingWindowInterface::fullscreen() const {
119139
if (auto* qw = this->window->backingWindow()) qw->showFullScreen();
120140
}

src/window/floatingwindow.hpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,12 @@ class FloatingWindowInterface: public WindowInterface {
6969
Q_PROPERTY(QSize minimumSize READ default WRITE default NOTIFY minimumSizeChanged BINDABLE bindableMinimumSize);
7070
/// Maximum window size given to the window system.
7171
Q_PROPERTY(QSize maximumSize READ default WRITE default NOTIFY maximumSizeChanged BINDABLE bindableMaximumSize);
72+
/// Whether the window is currently minimized.
73+
Q_PROPERTY(bool minimized READ isMinimized NOTIFY minimizedChanged);
7274
/// Whether the window is currently maximized.
73-
Q_PROPERTY(bool maximized READ maximized NOTIFY maximizedChanged);
75+
Q_PROPERTY(bool maximized READ isMaximized NOTIFY maximizedChanged);
7476
/// Whether the window is currently fullscreen.
75-
Q_PROPERTY(bool fullscreen READ fullscreen NOTIFY fullscreenChanged);
77+
Q_PROPERTY(bool fullscreen READ isFullscreen NOTIFY fullscreenChanged);
7678
// clang-format on
7779
QML_NAMED_ELEMENT(FloatingWindow);
7880

@@ -87,8 +89,9 @@ class FloatingWindowInterface: public WindowInterface {
8789
[[nodiscard]] QBindable<QSize> bindableMaximumSize() { return &this->window->bMaximumSize; }
8890
[[nodiscard]] QBindable<QString> bindableTitle() { return &this->window->bTitle; }
8991

90-
[[nodiscard]] bool maximized() const;
91-
[[nodiscard]] bool fullscreen() const;
92+
[[nodiscard]] bool isMinimized() const;
93+
[[nodiscard]] bool isMaximized() const;
94+
[[nodiscard]] bool isFullscreen() const;
9295

9396
/// Start a system move operation. Must be called during a pointer press/drag.
9497
Q_INVOKABLE [[nodiscard]] bool startSystemMove() const;
@@ -97,17 +100,18 @@ class FloatingWindowInterface: public WindowInterface {
97100

98101
/// Show the window in normal (restored) state.
99102
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;
103+
/// Maximize the window.
104+
Q_INVOKABLE void maximize() const;
105+
/// Minimize the window.
106+
Q_INVOKABLE void minimize() const;
107+
/// Fullscreen the window.
108+
Q_INVOKABLE void fullscreen() const;
106109

107110
signals:
108111
void minimumSizeChanged();
109112
void maximumSizeChanged();
110113
void titleChanged();
114+
void minimizedChanged();
111115
void maximizedChanged();
112116
void fullscreenChanged();
113117

@@ -116,6 +120,7 @@ private slots:
116120

117121
private:
118122
ProxyFloatingWindow* window;
123+
bool mMinimized = false;
119124
bool mMaximized = false;
120125
bool mFullscreen = false;
121126
};

0 commit comments

Comments
 (0)