Let macOS WM draw frameless window shadow

This commit is contained in:
Alex Spataru 2021-11-25 02:31:44 -06:00
parent 441bc2788f
commit a12fdc3c6d

View File

@ -42,7 +42,7 @@ Window {
// Window radius control // Window radius control
// //
property int borderWidth: 2 property int borderWidth: 2
readonly property int handleSize: radius > 0 ? radius + 10 + shadowMargin : 0 readonly property int handleSize: radius > 0 ? radius + 10 : 0
readonly property int radius: ((root.visibility === Window.Maximized && maximizeEnabled) || isFullscreen) ? 0 : 10 readonly property int radius: ((root.visibility === Window.Maximized && maximizeEnabled) || isFullscreen) ? 0 : 10
// //
@ -54,12 +54,29 @@ Window {
property bool isMinimized: false property bool isMinimized: false
property alias showIcon: _title.showIcon property alias showIcon: _title.showIcon
property alias isFullscreen: _title.isFullscreen property alias isFullscreen: _title.isFullscreen
readonly property int customFlags: Qt.Window | readonly property int customFlags: {
Qt.CustomizeWindowHint | // Setup frameless window flags
Qt.FramelessWindowHint | var flags = Qt.Window |
Qt.WindowSystemMenuHint | Qt.CustomizeWindowHint |
Qt.NoDropShadowWindowHint | Qt.FramelessWindowHint |
Qt.WindowMinMaxButtonsHint Qt.WindowSystemMenuHint |
Qt.WindowMinMaxButtonsHint
//
// The macOS window manager is able to generate shadows for Qt frameless
// windows. Other operating systems have varied mileage, so we draw the
// shadow ourselves to avoid ugly surprises.
//
// Also, disabling the custom shadow on macOS is a good idea so that users can
// move the window freely over all the desktop without being blocked by the
// menubar or dock due to the custom shadow border.
//
if (!Cpp_IsMac)
flags |= Qt.NoDropShadowWindowHint
// Return "calculated" window flags
return flags
}
// //
// Toggle fullscreen state // Toggle fullscreen state
@ -80,7 +97,7 @@ Window {
// //
// Size of the shadow object // Size of the shadow object
// //
property int shadowMargin: root.radius > 0 ? 20 : 0 property int shadowMargin: Cpp_IsMac ? 0 : (root.radius > 0 ? 20 : 0)
// //
// Titlebar left/right margins for custom controls // Titlebar left/right margins for custom controls
@ -134,7 +151,8 @@ Window {
} }
// //
// Shadow implementation // Custom shadow implementation for non-macOS systems. The shadow shall be disabled
// when the window is maximized.
// //
Widgets.Shadow { Widgets.Shadow {
opacity: 0.2 opacity: 0.2