Skip to content

Commit 7debc85

Browse files
committed
feat: make custom background clip widget content
Uses a shader effect to prevent the widget content from rendering beyond the custom background shape
1 parent 6ca187b commit 7debc85

File tree

4 files changed

+85
-0
lines changed

4 files changed

+85
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import QtQuick
2+
3+
ShaderEffect {
4+
required property var source
5+
required property var mask
6+
property real sourceOpacity: 1.0
7+
property bool enabled: false
8+
supportsAtlasTextures: true
9+
fragmentShader: enabled ? Qt.resolvedUrl("../shaders/badge.frag.qsb") : ""
10+
}

package/contents/ui/main.qml

+56
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import org.kde.plasma.core as PlasmaCore
1010
import org.kde.plasma.plasmoid
1111
import QtQuick.Effects
1212
import Qt5Compat.GraphicalEffects
13+
import "components" as Components
1314

1415
import "code/utils.js" as Utils
1516
import "code/globals.js" as Globals
@@ -1121,6 +1122,61 @@ PlasmoidItem {
11211122
position = Utils.getGlobalPosition(borderRec, panelElement);
11221123
panelColorizer.updatePanelMask(maskIndex, borderRec, rect.corners.topLeftRadius, rect.corners.topRightRadius, rect.corners.bottomLeftRadius, rect.corners.bottomRightRadius, Qt.point(rect.positionX - moveX, rect.positionY - moveY), 5, visible && blurBehind);
11231124
}
1125+
1126+
Kirigami.ShadowedRectangle {
1127+
id: backgroundMaskSource
1128+
anchors.fill: parent
1129+
corners {
1130+
topLeftRadius: topLeftRadius
1131+
topRightRadius: topRightRadius
1132+
bottomLeftRadius: bottomLeftRadius
1133+
bottomRightRadius: bottomRightRadius
1134+
}
1135+
}
1136+
1137+
Components.MaskEffect {
1138+
id: backgroundMask
1139+
anchors.fill: parent
1140+
source: targetShaderSource
1141+
mask: maskShaderSource
1142+
enabled: rect.isWidget && !panelBgItem.bgEnabled || true
1143+
sourceOpacity: 1
1144+
}
1145+
1146+
Components.MaskEffect {
1147+
id: dropShadowMask
1148+
anchors.fill: parent
1149+
source: shadowShaderSource
1150+
mask: maskShaderSource
1151+
enabled: rect.isWidget && !panelBgItem.bgEnabled || true
1152+
sourceOpacity: 1
1153+
}
1154+
1155+
ShaderEffectSource {
1156+
id: targetShaderSource
1157+
sourceItem: {
1158+
if (rect.isPanel && panelBgItem.bgEnabled) {
1159+
return rect.target.visibleChildren[0];
1160+
}
1161+
return rect.target?.applet ?? null;
1162+
}
1163+
live: true
1164+
hideSource: true
1165+
}
1166+
1167+
ShaderEffectSource {
1168+
id: shadowShaderSource
1169+
sourceItem: dropShadow
1170+
live: true
1171+
hideSource: true
1172+
}
1173+
1174+
ShaderEffectSource {
1175+
id: maskShaderSource
1176+
sourceItem: backgroundMaskSource
1177+
hideSource: true
1178+
live: true
1179+
}
11241180
}
11251181

11261182
// Search the actual gridLayout of the panel
1.39 KB
Binary file not shown.

shaders/badge.frag

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#version 440
2+
3+
layout(location = 0) in vec2 qt_TexCoord0;
4+
layout(location = 0) out vec4 fragColor;
5+
6+
layout(std140, binding = 0) uniform buf {
7+
mat4 qt_Matrix;
8+
float qt_Opacity;
9+
float sourceOpacity;
10+
};
11+
12+
layout(binding = 1) uniform sampler2D source;
13+
layout(binding = 2) uniform sampler2D mask;
14+
15+
void main() {
16+
vec4 srcColor = texture(source, qt_TexCoord0);
17+
vec4 maskColor = texture(mask, qt_TexCoord0);
18+
fragColor = srcColor * maskColor.a * sourceOpacity;
19+
}

0 commit comments

Comments
 (0)