brightness osd: show only on focused screen

This commit is contained in:
end-4
2025-05-18 00:20:33 +02:00
parent 4df645a025
commit e0b883cc3e
@@ -12,6 +12,8 @@ import Quickshell.Wayland
Scope {
id: root
property bool showOsdValues: false
property var focusedScreen: Quickshell.screens.find(s => s.name === Hyprland.focusedMonitor?.name)
property var brightnessMonitor: Brightness.getMonitorForScreen(focusedScreen)
function triggerOsd() {
showOsdValues = true
@@ -36,81 +38,83 @@ Scope {
}
}
Variants {
model: Quickshell.screens
Connections {
target: root.brightnessMonitor
enabled: !!root.brightnessMonitor
function onBrightnessChanged() {
if (!root.brightnessMonitor.ready) return
root.triggerOsd()
}
}
Loader {
id: osdLoader
property var modelData
active: showOsdValues
property var brightnessMonitor: Brightness.getMonitorForScreen(modelData)
Loader {
id: osdLoader
active: showOsdValues
PanelWindow {
id: osdRoot
Connections {
target: brightnessMonitor
function onBrightnessChanged() {
if (!brightnessMonitor.ready) return
root.triggerOsd()
target: osdLoader
function onFocusedScreenChanged() {
osdRoot.screen = root.focusedScreen
}
}
PanelWindow {
screen: modelData
exclusionMode: ExclusionMode.Normal
WlrLayershell.namespace: "quickshell:onScreenDisplay"
WlrLayershell.layer: WlrLayer.Overlay
color: "transparent"
anchors {
top: true
}
mask: Region {
item: osdValuesWrapper
}
implicitWidth: columnLayout.implicitWidth
implicitHeight: columnLayout.implicitHeight
visible: osdLoader.active
ColumnLayout {
id: columnLayout
anchors.horizontalCenter: parent.horizontalCenter
Item {
height: 1 // Prevent Wayland protocol error
}
Item {
id: osdValuesWrapper
// Extra space for shadow
implicitHeight: true ? (osdValues.implicitHeight + Appearance.sizes.elevationMargin * 2) : 0
implicitWidth: osdValues.implicitWidth + Appearance.sizes.elevationMargin * 2
clip: true
MouseArea {
anchors.fill: parent
hoverEnabled: true
onEntered: root.showOsdValues = false
}
Behavior on implicitHeight {
NumberAnimation {
duration: Appearance.animation.menuDecel.duration
easing.type: Appearance.animation.menuDecel.type
}
}
OsdValueIndicator {
id: osdValues
anchors.centerIn: parent
value: brightnessMonitor.brightness
icon: "light_mode"
rotateIcon: true
name: qsTr("Brightness")
}
}
}
exclusionMode: ExclusionMode.Normal
WlrLayershell.namespace: "quickshell:onScreenDisplay"
WlrLayershell.layer: WlrLayer.Overlay
color: "transparent"
anchors {
top: true
}
mask: Region {
item: osdValuesWrapper
}
implicitWidth: columnLayout.implicitWidth
implicitHeight: columnLayout.implicitHeight
visible: osdLoader.active
ColumnLayout {
id: columnLayout
anchors.horizontalCenter: parent.horizontalCenter
Item {
height: 1 // Prevent Wayland protocol error
}
Item {
id: osdValuesWrapper
// Extra space for shadow
implicitHeight: true ? (osdValues.implicitHeight + Appearance.sizes.elevationMargin * 2) : 0
implicitWidth: osdValues.implicitWidth + Appearance.sizes.elevationMargin * 2
clip: true
MouseArea {
anchors.fill: parent
hoverEnabled: true
onEntered: root.showOsdValues = false
}
Behavior on implicitHeight {
NumberAnimation {
duration: Appearance.animation.menuDecel.duration
easing.type: Appearance.animation.menuDecel.type
}
}
OsdValueIndicator {
id: osdValues
anchors.centerIn: parent
value: root.brightnessMonitor.brightness
icon: "light_mode"
rotateIcon: true
name: qsTr("Brightness")
}
}
}
}
}
IpcHandler {