From 8cd0f56b9b5120c21c03b0315fa9c88d2a5ff320 Mon Sep 17 00:00:00 2001 From: Fatih Uzunoglu <fuzun54@outlook.com> Date: Thu, 3 Apr 2025 18:27:28 +0300 Subject: [PATCH] qml: do not create csd shadow effect if it is not used This follows the approach that has been working well in a lot of places: create the item once it is necessary to be used and do not destroy it. I don't think it is worth to use `Loader` just to load and unload the effect depending on whether CSD is active, which can be changed while the application is alive. This is because it is not expected that the user switches CSD many times, and the effect is simple enough to be just kept alive instead. `Loader` is usually used for heavy items. In any case it does not make sense to create it if the window does not support CSD, or the platform handles the shadows. --- .../qt/maininterface/qml/MainInterface.qml | 72 +++++++++++-------- 1 file changed, 42 insertions(+), 30 deletions(-) diff --git a/modules/gui/qt/maininterface/qml/MainInterface.qml b/modules/gui/qt/maininterface/qml/MainInterface.qml index 57897e53e710..400a06542197 100644 --- a/modules/gui/qt/maininterface/qml/MainInterface.qml +++ b/modules/gui/qt/maininterface/qml/MainInterface.qml @@ -44,6 +44,14 @@ Item { property bool _extendedFrameVisible: MainCtx.windowSuportExtendedFrame && MainCtx.clientSideDecoration && (MainCtx.intfMainWindow.visibility === Window.Windowed) + readonly property bool _csdShadowVisible: _extendedFrameVisible && !MainCtx.platformHandlesShadowsWithCSD() + property Item _csdShadow + + on_CsdShadowVisibleChanged: { + if (root._csdShadowVisible && !root._csdShadow) { + root._csdShadow = shadowEffectComponent.createObject(root) + } + } //when exiting minimal mode, what is the page to restore property bool _minimalRestorePlayer: false @@ -325,39 +333,43 @@ Item { } } - //draw the window drop shadow ourselve when the windowing system doesn't - //provide them but support extended frame - Widgets.RectangularGlow { - id: effect - z: -1 - hollow: Window.window && (Window.window.color.a < 1.0) // the interface may be translucent if the window has backdrop blur - blending: false // stacked below everything, no need for blending even though it is not opaque - visible: _extendedFrameVisible && !MainCtx.platformHandlesShadowsWithCSD() - anchors.fill: g_mainInterface - spread: 0.0 - color: "black" - opacity: 0.5 - cornerRadius: glowRadius - states: [ - State { - when: MainCtx.intfMainWindow.active - PropertyChanges { - target: effect - glowRadius: MainCtx.windowExtendedMargin * 0.7 + Component { + id: shadowEffectComponent + + //draw the window drop shadow ourselve when the windowing system doesn't + //provide them but support extended frame + Widgets.RectangularGlow { + id: effect + z: -1 + hollow: Window.window && (Window.window.color.a < 1.0) // the interface may be translucent if the window has backdrop blur + blending: false // stacked below everything, no need for blending even though it is not opaque + visible: root._csdShadowVisible + anchors.fill: g_mainInterface + spread: 0.0 + color: "black" + opacity: 0.5 + cornerRadius: glowRadius + states: [ + State { + when: MainCtx.intfMainWindow.active + PropertyChanges { + target: effect + glowRadius: MainCtx.windowExtendedMargin * 0.7 + } + }, + State { + when: !MainCtx.intfMainWindow.active + PropertyChanges { + target: effect + glowRadius: MainCtx.windowExtendedMargin * 0.5 + } } - }, - State { - when: !MainCtx.intfMainWindow.active - PropertyChanges { - target: effect - glowRadius: MainCtx.windowExtendedMargin * 0.5 + ] + Behavior on glowRadius { + NumberAnimation { + duration: VLCStyle.duration_veryShort } } - ] - Behavior on glowRadius { - NumberAnimation { - duration: VLCStyle.duration_veryShort - } } } } -- GitLab