nova-shell/modules/ScreenCorners.qml

93 lines
2.3 KiB
QML

import QtQuick
import Quickshell
import Quickshell.Wayland
import "." as M
// Draws rounded black corners at the edges of each screen.
// Disabled when screenRadius is 0.
Item {
id: root
required property var screen
readonly property int _r: M.Theme.screenRadius
component Corner: PanelWindow {
id: win
property int corner: 0
screen: root.screen
visible: root._r > 0
color: "transparent"
WlrLayershell.layer: WlrLayer.Overlay
WlrLayershell.exclusiveZone: -1
WlrLayershell.namespace: "nova-corners"
mask: Region {}
implicitWidth: root._r
implicitHeight: root._r
Canvas {
anchors.fill: parent
onPaint: {
const r = root._r;
const ctx = getContext("2d");
ctx.clearRect(0, 0, r, r);
ctx.fillStyle = "black";
ctx.beginPath();
switch (win.corner) {
case 0: // top-left
ctx.moveTo(0, 0);
ctx.lineTo(r, 0);
ctx.arc(r, r, r, -Math.PI / 2, Math.PI, true);
ctx.closePath();
break;
case 1: // top-right
ctx.moveTo(r, 0);
ctx.lineTo(0, 0);
ctx.arc(0, r, r, -Math.PI / 2, 0, false);
ctx.closePath();
break;
case 2: // bottom-left
ctx.moveTo(0, r);
ctx.lineTo(0, 0);
ctx.arc(r, 0, r, Math.PI, Math.PI / 2, true);
ctx.closePath();
break;
case 3: // bottom-right
ctx.moveTo(r, r);
ctx.lineTo(r, 0);
ctx.arc(0, 0, r, 0, Math.PI / 2, false);
ctx.closePath();
break;
}
ctx.fill();
}
}
}
Corner {
corner: 0
anchors.top: true
anchors.left: true
}
Corner {
corner: 1
anchors.top: true
anchors.right: true
}
Corner {
corner: 2
anchors.bottom: true
anchors.left: true
}
Corner {
corner: 3
anchors.bottom: true
anchors.right: true
}
}