1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-29 07:52:50 -05:00

bar: dpr-aware canvas

This commit is contained in:
bbedward
2025-10-15 12:31:07 -04:00
parent f311b20ef7
commit 38b833c886

View File

@@ -1,5 +1,7 @@
import QtQuick import QtQuick
import Quickshell.Hyprland
import qs.Common import qs.Common
import qs.Services
Item { Item {
id: root id: root
@@ -16,6 +18,18 @@ Item {
anchors.topMargin: -(SettingsData.dankBarGothCornersEnabled && !axis.isVertical && axis.edge === "bottom" ? barWindow._wingR : 0) anchors.topMargin: -(SettingsData.dankBarGothCornersEnabled && !axis.isVertical && axis.edge === "bottom" ? barWindow._wingR : 0)
anchors.bottomMargin: -(SettingsData.dankBarGothCornersEnabled && !axis.isVertical && axis.edge === "top" ? barWindow._wingR : 0) anchors.bottomMargin: -(SettingsData.dankBarGothCornersEnabled && !axis.isVertical && axis.edge === "top" ? barWindow._wingR : 0)
readonly property real dpr: {
if (CompositorService.isNiri && barWindow.screen) {
const niriScale = NiriService.displayScales[barWindow.screen.name]
if (niriScale !== undefined) return niriScale
}
if (CompositorService.isHyprland && barWindow.screen) {
const hyprlandMonitor = Hyprland.monitors.values.find(m => m.name === barWindow.screen.name)
if (hyprlandMonitor?.scale !== undefined) return hyprlandMonitor.scale
}
return barWindow.screen?.devicePixelRatio || 1
}
function requestRepaint() { function requestRepaint() {
debounceTimer.restart() debounceTimer.restart()
} }
@@ -38,12 +52,12 @@ Item {
renderTarget: Canvas.FramebufferObject renderTarget: Canvas.FramebufferObject
renderStrategy: Canvas.Cooperative renderStrategy: Canvas.Cooperative
readonly property real correctWidth: root.width readonly property real correctWidth: Theme.px(root.width, dpr)
readonly property real correctHeight: root.height readonly property real correctHeight: Theme.px(root.height, dpr)
canvasSize: Qt.size(Math.ceil(correctWidth), Math.ceil(correctHeight)) canvasSize: Qt.size(correctWidth, correctHeight)
property real wing: SettingsData.dankBarGothCornersEnabled ? barWindow._wingR : 0 property real wing: SettingsData.dankBarGothCornersEnabled ? Theme.px(barWindow._wingR, dpr) : 0
property real rt: SettingsData.dankBarSquareCorners ? 0 : Theme.cornerRadius property real rt: SettingsData.dankBarSquareCorners ? 0 : Theme.px(Theme.cornerRadius, dpr)
onWingChanged: root.requestRepaint() onWingChanged: root.requestRepaint()
onRtChanged: root.requestRepaint() onRtChanged: root.requestRepaint()
@@ -52,6 +66,11 @@ Item {
onVisibleChanged: if (visible) root.requestRepaint() onVisibleChanged: if (visible) root.requestRepaint()
Component.onCompleted: root.requestRepaint() Component.onCompleted: root.requestRepaint()
Connections {
target: root
function onDprChanged() { root.requestRepaint() }
}
Connections { Connections {
target: barWindow target: barWindow
function on_BgColorChanged() { root.requestRepaint() } function on_BgColorChanged() { root.requestRepaint() }
@@ -101,7 +120,7 @@ Item {
} }
ctx.reset() ctx.reset()
ctx.clearRect(0, 0, Math.ceil(W), Math.ceil(H_raw)) ctx.clearRect(0, 0, W, H_raw)
ctx.save() ctx.save()
if (isBottom) { if (isBottom) {
@@ -130,12 +149,12 @@ Item {
renderTarget: Canvas.FramebufferObject renderTarget: Canvas.FramebufferObject
renderStrategy: Canvas.Cooperative renderStrategy: Canvas.Cooperative
readonly property real correctWidth: root.width readonly property real correctWidth: Theme.px(root.width, dpr)
readonly property real correctHeight: root.height readonly property real correctHeight: Theme.px(root.height, dpr)
canvasSize: Qt.size(Math.ceil(correctWidth), Math.ceil(correctHeight)) canvasSize: Qt.size(correctWidth, correctHeight)
property real wing: SettingsData.dankBarGothCornersEnabled ? barWindow._wingR : 0 property real wing: SettingsData.dankBarGothCornersEnabled ? Theme.px(barWindow._wingR, dpr) : 0
property real rt: SettingsData.dankBarSquareCorners ? 0 : Theme.cornerRadius property real rt: SettingsData.dankBarSquareCorners ? 0 : Theme.px(Theme.cornerRadius, dpr)
property real alphaTint: (barWindow._bgColor?.a ?? 1) < 0.99 ? (Theme.stateLayerOpacity ?? 0) : 0 property real alphaTint: (barWindow._bgColor?.a ?? 1) < 0.99 ? (Theme.stateLayerOpacity ?? 0) : 0
onWingChanged: root.requestRepaint() onWingChanged: root.requestRepaint()
@@ -146,6 +165,11 @@ Item {
onVisibleChanged: if (visible) root.requestRepaint() onVisibleChanged: if (visible) root.requestRepaint()
Component.onCompleted: root.requestRepaint() Component.onCompleted: root.requestRepaint()
Connections {
target: root
function onDprChanged() { root.requestRepaint() }
}
Connections { Connections {
target: barWindow target: barWindow
function on_BgColorChanged() { root.requestRepaint() } function on_BgColorChanged() { root.requestRepaint() }
@@ -195,7 +219,7 @@ Item {
} }
ctx.reset() ctx.reset()
ctx.clearRect(0, 0, Math.ceil(W), Math.ceil(H_raw)) ctx.clearRect(0, 0, W, H_raw)
ctx.save() ctx.save()
if (isBottom) { if (isBottom) {
@@ -225,12 +249,12 @@ Item {
renderTarget: Canvas.FramebufferObject renderTarget: Canvas.FramebufferObject
renderStrategy: Canvas.Cooperative renderStrategy: Canvas.Cooperative
readonly property real correctWidth: root.width readonly property real correctWidth: Theme.px(root.width, dpr)
readonly property real correctHeight: root.height readonly property real correctHeight: Theme.px(root.height, dpr)
canvasSize: Qt.size(Math.ceil(correctWidth), Math.ceil(correctHeight)) canvasSize: Qt.size(correctWidth, correctHeight)
property real wing: SettingsData.dankBarGothCornersEnabled ? barWindow._wingR : 0 property real wing: SettingsData.dankBarGothCornersEnabled ? Theme.px(barWindow._wingR, dpr) : 0
property real rt: SettingsData.dankBarSquareCorners ? 0 : Theme.cornerRadius property real rt: SettingsData.dankBarSquareCorners ? 0 : Theme.px(Theme.cornerRadius, dpr)
property bool borderEnabled: SettingsData.dankBarBorderEnabled property bool borderEnabled: SettingsData.dankBarBorderEnabled
onWingChanged: root.requestRepaint() onWingChanged: root.requestRepaint()
@@ -241,6 +265,11 @@ Item {
onVisibleChanged: if (visible) root.requestRepaint() onVisibleChanged: if (visible) root.requestRepaint()
Component.onCompleted: root.requestRepaint() Component.onCompleted: root.requestRepaint()
Connections {
target: root
function onDprChanged() { root.requestRepaint() }
}
Connections { Connections {
target: Theme target: Theme
function onIsLightModeChanged() { root.requestRepaint() } function onIsLightModeChanged() { root.requestRepaint() }
@@ -310,7 +339,7 @@ Item {
} }
ctx.reset() ctx.reset()
ctx.clearRect(0, 0, Math.ceil(W), Math.ceil(H_raw)) ctx.clearRect(0, 0, W, H_raw)
ctx.save() ctx.save()
if (isBottom) { if (isBottom) {