diff --git a/assets/qml/Dashboard/WidgetDelegate.qml b/assets/qml/Dashboard/WidgetDelegate.qml index 8fddbdc1..c401d96a 100644 --- a/assets/qml/Dashboard/WidgetDelegate.qml +++ b/assets/qml/Dashboard/WidgetDelegate.qml @@ -65,6 +65,7 @@ Item { minimumWidth: 640 minimumHeight: 480 title: externalLoader.widgetTitle + extraFlags: Qt.WindowStaysOnTopHint titlebarText: Cpp_ThemeManager.text titlebarColor: Cpp_ThemeManager.widgetWindowBackground backgroundColor: Cpp_ThemeManager.widgetWindowBackground diff --git a/assets/qml/FramelessWindow/CustomWindow.qml b/assets/qml/FramelessWindow/CustomWindow.qml index 0a842d24..617b1ef2 100644 --- a/assets/qml/FramelessWindow/CustomWindow.qml +++ b/assets/qml/FramelessWindow/CustomWindow.qml @@ -27,7 +27,7 @@ import QtGraphicalEffects 1.0 Window { id: root color: "transparent" - flags: root.customFlags + flags: root.customFlags | root.extraFlags // // Custom signals @@ -41,12 +41,13 @@ Window { // Window radius control // property int borderWidth: 2 - readonly property int handleSize: radius + 5 + shadowMargin + readonly property int handleSize: radius > 0 ? radius + 5 + shadowMargin : 0 readonly property int radius: ((root.visibility === Window.Maximized && maximizeEnabled) || fullScreen) ? 0 : 10 // // Visibility properties // + property int extraFlags: 0 property bool firstChange: true property bool windowMaximized: false property bool windowMinimized: false @@ -76,6 +77,13 @@ Window { // property int shadowMargin: root.radius > 0 ? 20 : 0 + // + // Titlebar left/right margins for custom controls + // + property alias leftTitlebarMargin: border.leftMargin + property alias rightTitlebarMargin: border.rightMargin + property alias showMacControls: border.showMacControls + // // Background color of the window & the titlebar // @@ -160,6 +168,14 @@ Window { // Maximize window fixes // onVisibilityChanged: { + // Hard-reset window flags on macOS to fix most glitches + if (Cpp_IsMac) + root.flags = Qt.Window + + // Ensure that correct window flags are still used + root.flags = root.customFlags | root.extraFlags + + // Window has been just maximized, update internal variables if (visibility === Window.Maximized) { if (!root.windowMaximized) root.firstChange = false @@ -168,11 +184,13 @@ Window { root.windowMaximized = true } + // Window has been just minimized, update internal variables else if (visibility === Window.Minimized) { root.fullScreen = false root.windowMaximized = false } + // Window has been just switched to full-screen, update internal variables else if (visibility === Window.FullScreen) { if (!root.fullScreen) root.firstChange = false @@ -181,6 +199,7 @@ Window { root.windowMaximized = false } + // Window was just restored to "normal" mode, recover previous geometry else if (visibility !== Window.Hidden) { if (windowMaximized || fullScreen && firstChange) { root.width = root.minimumWidth @@ -191,7 +210,6 @@ Window { root.fullScreen = false root.windowMaximized = false - root.flags = root.customFlags } } } diff --git a/assets/qml/FramelessWindow/WindowBorder.qml b/assets/qml/FramelessWindow/WindowBorder.qml index eadf0993..d6d508e1 100644 --- a/assets/qml/FramelessWindow/WindowBorder.qml +++ b/assets/qml/FramelessWindow/WindowBorder.qml @@ -49,7 +49,24 @@ Rectangle { property bool maximizeEnabled: true property bool fullscreenEnabled: false property color textColor: palette.text - readonly property bool showMacControls: Cpp_IsMac + property bool showMacControls: Cpp_IsMac + + // + // Access to titlebar button widths (e.g. for implementing custom controls over the + // window titlebar, such as the main window menubar) + // + readonly property real leftMargin: { + if (showMacControls) + return 4 + (3 * 20) + 4 + + return 8 + 24 + 8 + } + readonly property real rightMargin: { + if (showMacControls) + return 18 + 8 + 4 + + return 8 + (3 * 24) + 8 + } // // Toggle maximized diff --git a/assets/qml/Windows/About.qml b/assets/qml/Windows/About.qml index 9ea39e81..3217e047 100644 --- a/assets/qml/Windows/About.qml +++ b/assets/qml/Windows/About.qml @@ -41,6 +41,7 @@ FramelessWindow.CustomWindow { title: qsTr("About") width: minimumWidth height: minimumHeight + extraFlags: Qt.WindowStaysOnTopHint x: (Screen.desktopAvailableWidth - width) / 2 y: (Screen.desktopAvailableHeight - height) / 2 minimumWidth: column.implicitWidth + 4 * app.spacing + 2 * root.shadowMargin diff --git a/assets/qml/Windows/Acknowledgements.qml b/assets/qml/Windows/Acknowledgements.qml index 7da699d9..6f28f4e0 100644 --- a/assets/qml/Windows/Acknowledgements.qml +++ b/assets/qml/Windows/Acknowledgements.qml @@ -39,6 +39,7 @@ FramelessWindow.CustomWindow { minimizeEnabled: false maximizeEnabled: false title: qsTr("Acknowledgements") + extraFlags: Qt.WindowStaysOnTopHint titlebarText: Cpp_ThemeManager.text x: (Screen.desktopAvailableWidth - width) / 2 y: (Screen.desktopAvailableHeight - height) / 2 diff --git a/assets/qml/Windows/CsvPlayer.qml b/assets/qml/Windows/CsvPlayer.qml index 7416f6cb..61391eef 100644 --- a/assets/qml/Windows/CsvPlayer.qml +++ b/assets/qml/Windows/CsvPlayer.qml @@ -39,6 +39,7 @@ FramelessWindow.CustomWindow { minimizeEnabled: false maximizeEnabled: false title: qsTr("CSV Player") + extraFlags: Qt.WindowStaysOnTopHint titlebarText: Cpp_ThemeManager.text x: (Screen.desktopAvailableWidth - width) / 2 y: (Screen.desktopAvailableHeight - height) / 2 diff --git a/assets/qml/Windows/Donate.qml b/assets/qml/Windows/Donate.qml index 6ff41385..e21ecc4b 100644 --- a/assets/qml/Windows/Donate.qml +++ b/assets/qml/Windows/Donate.qml @@ -40,6 +40,7 @@ FramelessWindow.CustomWindow { height: minimumHeight minimizeEnabled: false maximizeEnabled: false + extraFlags: Qt.WindowStaysOnTopHint titlebarText: Cpp_ThemeManager.text x: (Screen.desktopAvailableWidth - width) / 2 y: (Screen.desktopAvailableHeight - height) / 2 diff --git a/assets/qml/Windows/MainWindow.qml b/assets/qml/Windows/MainWindow.qml index a88cf144..9ff18a8f 100644 --- a/assets/qml/Windows/MainWindow.qml +++ b/assets/qml/Windows/MainWindow.qml @@ -231,29 +231,41 @@ FramelessWindow.CustomWindow { // // Windows + Linux menubar loader // - Item { - enabled: !Cpp_IsMac - visible: !Cpp_IsMac + RowLayout { + spacing: app.spacing height: titlebar.height + enabled: !root.showMacControls + visible: !root.showMacControls anchors { top: parent.top left: parent.left right: parent.right margins: root.shadowMargin - rightMargin: root.shadowMargin + 128 + leftMargin: root.leftTitlebarMargin + root.shadowMargin + rightMargin: root.rightTitlebarMargin + root.shadowMargin } PlatformDependent.Menubar { id: menubar opacity: 0.8 - Behavior on opacity {NumberAnimation{}} - anchors { - left: parent.left - right: parent.right - leftMargin: 14 + 24 - verticalCenter: parent.verticalCenter - } + Layout.alignment: Qt.AlignVCenter + } + + FramelessWindow.WindowButton { + width: 18 + height: 18 + textColor: root.titlebarText + visible: root.fullscreenEnabled + enabled: root.fullscreenEnabled + Layout.alignment: Qt.AlignVCenter + onClicked: root.toggleFullscreen() + highlightColor: Cpp_ThemeManager.highlight + name: root.fullScreen ? "restore" : "fullscreen" + } + + Item { + Layout.fillWidth: true } } diff --git a/assets/qml/main.qml b/assets/qml/main.qml index ef48ae40..d7c9afc3 100644 --- a/assets/qml/main.qml +++ b/assets/qml/main.qml @@ -58,7 +58,10 @@ Item { Loader { asynchronous: true sourceComponent: Windows.MainWindow { - Component.onCompleted: app.mainWindow = this + Component.onCompleted: { + forceActiveFocus() + app.mainWindow = this + } } }