fix(StatusWindow): fix changing the window state(s)
- since the window can be a combination of several states (e.g. maximized + fullscreen + minimized), use the newer `windowStates()` to track and toggle them - call `makeStatusAppActive()` in all the identical codepaths (clicking tray icon, activating a mac or win instance, running a second instance, etc) - fixes restoring the window to its previous state(s) when activating from the tray or dock icon - use some more standard keyboard shortcuts Fixes #14132
This commit is contained in:
parent
ba98fca516
commit
523e0490fe
|
@ -1,28 +1,19 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QQuickWindow>
|
#include <QQuickWindow>
|
||||||
#include <QScreen>
|
|
||||||
|
|
||||||
class StatusWindow: public QQuickWindow
|
class StatusWindow: public QQuickWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
Q_PROPERTY(bool isFullScreen READ isFullScreen NOTIFY isFullScreenChanged)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit StatusWindow(QWindow *parent = nullptr);
|
explicit StatusWindow(QWindow *parent = nullptr);
|
||||||
|
|
||||||
Q_INVOKABLE void toggleFullScreen();
|
Q_INVOKABLE void toggleFullScreen();
|
||||||
Q_INVOKABLE void updatePosition();
|
Q_INVOKABLE void toggleMinimize();
|
||||||
|
Q_INVOKABLE void restoreWindowState();
|
||||||
bool isFullScreen() const;
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void isFullScreenChanged();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void removeTitleBar();
|
void removeTitleBar();
|
||||||
void showTitleBar();
|
void showTitleBar();
|
||||||
|
|
||||||
bool m_isFullScreen;
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,43 +1,31 @@
|
||||||
#include "StatusQ/statuswindow.h"
|
#include "StatusQ/statuswindow.h"
|
||||||
|
|
||||||
StatusWindow::StatusWindow(QWindow *parent)
|
StatusWindow::StatusWindow(QWindow *parent)
|
||||||
: QQuickWindow(parent),
|
: QQuickWindow(parent)
|
||||||
m_isFullScreen(false)
|
|
||||||
{
|
{
|
||||||
removeTitleBar();
|
if (!windowStates().testFlag(Qt::WindowFullScreen))
|
||||||
|
removeTitleBar();
|
||||||
|
|
||||||
connect(this, &QQuickWindow::windowStateChanged, [&](Qt::WindowState windowState) {
|
connect(this, &QQuickWindow::windowStateChanged, [&](Qt::WindowState windowState) {
|
||||||
if (windowState == Qt::WindowNoState) {
|
if (windowState == Qt::WindowFullScreen) {
|
||||||
removeTitleBar();
|
|
||||||
m_isFullScreen = false;
|
|
||||||
emit isFullScreenChanged();
|
|
||||||
} else if (windowState == Qt::WindowFullScreen) {
|
|
||||||
m_isFullScreen = true;
|
|
||||||
emit isFullScreenChanged();
|
|
||||||
showTitleBar();
|
showTitleBar();
|
||||||
|
} else {
|
||||||
|
removeTitleBar();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void StatusWindow::updatePosition()
|
void StatusWindow::restoreWindowState()
|
||||||
{
|
{
|
||||||
auto point = QPoint(screen()->geometry().center().x() - geometry().width() / 2,
|
setWindowStates(windowStates() & ~Qt::WindowMinimized);
|
||||||
screen()->geometry().center().y() - geometry().height() / 2);
|
|
||||||
if (point != this->position()) {
|
|
||||||
this->setPosition(point);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void StatusWindow::toggleFullScreen()
|
void StatusWindow::toggleFullScreen()
|
||||||
{
|
{
|
||||||
if (m_isFullScreen) {
|
setWindowStates(windowStates() ^ Qt::WindowFullScreen);
|
||||||
showNormal();
|
|
||||||
} else {
|
|
||||||
showFullScreen();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StatusWindow::isFullScreen() const
|
void StatusWindow::toggleMinimize()
|
||||||
{
|
{
|
||||||
return m_isFullScreen;
|
setWindowStates(windowStates() ^ Qt::WindowMinimized);
|
||||||
}
|
}
|
||||||
|
|
36
ui/main.qml
36
ui/main.qml
|
@ -122,28 +122,16 @@ StatusWindow {
|
||||||
|
|
||||||
Action {
|
Action {
|
||||||
shortcut: StandardKey.FullScreen
|
shortcut: StandardKey.FullScreen
|
||||||
onTriggered: {
|
onTriggered: applicationWindow.toggleFullScreen()
|
||||||
if (applicationWindow.visibility === Window.FullScreen) {
|
|
||||||
showNormal()
|
|
||||||
} else {
|
|
||||||
showFullScreen()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Action {
|
Action {
|
||||||
shortcut: "Ctrl+M"
|
shortcut: "Ctrl+M"
|
||||||
onTriggered: {
|
onTriggered: applicationWindow.toggleMinimize()
|
||||||
if (applicationWindow.visibility === Window.Minimized) {
|
|
||||||
showNormal()
|
|
||||||
} else {
|
|
||||||
showMinimized()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Action {
|
Action {
|
||||||
shortcut: "Ctrl+W"
|
shortcut: StandardKey.Close
|
||||||
enabled: loader.item && !!loader.item.appLayout && loader.item.appLayout.appView ? loader.item.appLayout.appView.currentIndex === Constants.appViewStackIndex.browser
|
enabled: loader.item && !!loader.item.appLayout && loader.item.appLayout.appView ? loader.item.appLayout.appView.currentIndex === Constants.appViewStackIndex.browser
|
||||||
: true
|
: true
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
|
@ -152,7 +140,7 @@ StatusWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
Action {
|
Action {
|
||||||
shortcut: "Ctrl+Q"
|
shortcut: StandardKey.Quit
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
Qt.quit()
|
Qt.quit()
|
||||||
}
|
}
|
||||||
|
@ -259,23 +247,20 @@ StatusWindow {
|
||||||
function onStateChanged() {
|
function onStateChanged() {
|
||||||
if (Qt.application.state == d.previousApplicationState
|
if (Qt.application.state == d.previousApplicationState
|
||||||
&& Qt.application.state == Qt.ApplicationActive) {
|
&& Qt.application.state == Qt.ApplicationActive) {
|
||||||
applicationWindow.visible = true
|
makeStatusAppActive()
|
||||||
applicationWindow.showNormal()
|
|
||||||
}
|
}
|
||||||
d.previousApplicationState = Qt.application.state
|
d.previousApplicationState = Qt.application.state
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO remove direct backend access
|
//TODO remove direct backend access
|
||||||
Connections {
|
Connections {
|
||||||
target: singleInstance
|
target: singleInstance
|
||||||
|
|
||||||
function onSecondInstanceDetected() {
|
function onSecondInstanceDetected() {
|
||||||
console.log("User attempted to run the second instance of the application")
|
console.log("User attempted to run the second instance of the application")
|
||||||
// activating this instance to give user visual feedback
|
// activating this instance to give user visual feedback
|
||||||
applicationWindow.show()
|
makeStatusAppActive()
|
||||||
applicationWindow.raise()
|
|
||||||
applicationWindow.requestActivate()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -304,7 +289,8 @@ StatusWindow {
|
||||||
signal navigateTo(string path)
|
signal navigateTo(string path)
|
||||||
|
|
||||||
function makeStatusAppActive() {
|
function makeStatusAppActive() {
|
||||||
applicationWindow.show()
|
applicationWindow.restoreWindowState()
|
||||||
|
applicationWindow.visible = true
|
||||||
applicationWindow.raise()
|
applicationWindow.raise()
|
||||||
applicationWindow.requestActivate()
|
applicationWindow.requestActivate()
|
||||||
}
|
}
|
||||||
|
@ -402,7 +388,7 @@ StatusWindow {
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
anchors.margins: 13
|
anchors.margins: 13
|
||||||
|
|
||||||
visible: Qt.platform.os === Constants.mac && !applicationWindow.isFullScreen
|
visible: Qt.platform.os === Constants.mac && applicationWindow.visibility !== Window.FullScreen
|
||||||
|
|
||||||
onClose: {
|
onClose: {
|
||||||
if (loader.sourceComponent != app) {
|
if (loader.sourceComponent != app) {
|
||||||
|
@ -419,7 +405,7 @@ StatusWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
onMinimised: {
|
onMinimised: {
|
||||||
applicationWindow.showMinimized()
|
applicationWindow.toggleMinimize()
|
||||||
}
|
}
|
||||||
|
|
||||||
onMaximized: {
|
onMaximized: {
|
||||||
|
|
Loading…
Reference in New Issue