Dimmer: new implementation of the screen diming in a separate component.

This commit is contained in:
LemmyCook 2025-09-16 21:35:27 -04:00
parent eb26aa10f7
commit 6f1ae43d62
4 changed files with 96 additions and 2 deletions

View file

@ -0,0 +1,76 @@
import QtQuick
import QtQuick.Effects
import Quickshell
import Quickshell.Wayland
import qs.Commons
import qs.Services
import qs.Widgets
Variants {
model: Quickshell.screens
delegate: Loader {
required property ShellScreen modelData
// Dimmer is only active on the screen where the panel is currently open.
active: {
if (Settings.isLoaded && Settings.data.general.dimDesktop && modelData !== undefined && PanelService.openedPanel !== null && PanelService.openedPanel.item !== null) {
return (PanelService.openedPanel.item.screen === modelData)
}
return false
}
sourceComponent: PanelWindow {
id: panel
property real customOpacity: 0
Component.onCompleted: {
if (modelData) {
Logger.log("Dimmer", "component loaded on", modelData.name)
}
// When a NPanel opens it seems it is initialized with the primary screen for a very brief moment
// before the screen actually updates to the proper value. We use a timer to delay the fade in to avoid
// a single frame flicker on the main screen when opening a panel on another screen.
fadeInTimer.start()
}
Connections {
target: PanelService
function onWillClose() {
customOpacity = Style.opacityNone
}
}
Timer {
id: fadeInTimer
interval: 100
onTriggered: customOpacity = Style.opacityHeavy
}
screen: modelData
WlrLayershell.layer: WlrLayer.Top
WlrLayershell.exclusionMode: ExclusionMode.Ignore
WlrLayershell.keyboardFocus: WlrKeyboardFocus.None
WlrLayershell.namespace: "quickshell-dimmer"
// mask: Region {}
anchors {
top: true
bottom: true
right: true
left: true
}
color: Qt.alpha(Color.mShadow, customOpacity)
Behavior on color {
ColorAnimation {
duration: Style.animationSlow
}
}
}
}
}

View file

@ -16,6 +16,9 @@ Singleton {
property var registeredPanels: ({}) property var registeredPanels: ({})
signal willOpen
signal willClose
// Register this panel // Register this panel
function registerPanel(panel) { function registerPanel(panel) {
registeredPanels[panel.objectName] = panel registeredPanels[panel.objectName] = panel
@ -38,6 +41,14 @@ Singleton {
openedPanel.close() openedPanel.close()
} }
openedPanel = panel openedPanel = panel
// emit signal
willOpen()
}
function willClosePanel(panel) {
// emit signal
willClose()
} }
function closedPanel(panel) { function closedPanel(panel) {

View file

@ -111,6 +111,7 @@ Loader {
scaleValue = originalScale scaleValue = originalScale
opacityValue = originalOpacity opacityValue = originalOpacity
hideTimer.start() hideTimer.start()
PanelService.willClosePanel(root)
} }
// ----------------------------------------- // -----------------------------------------
@ -146,6 +147,10 @@ Loader {
readonly property bool barIsVisible: (screen !== null) && (Settings.data.bar.monitors.includes(screen.name) || (Settings.data.bar.monitors.length === 0)) readonly property bool barIsVisible: (screen !== null) && (Settings.data.bar.monitors.includes(screen.name) || (Settings.data.bar.monitors.length === 0))
readonly property real verticalBarWidth: Math.round(Style.barHeight * scaling) readonly property real verticalBarWidth: Math.round(Style.barHeight * scaling)
Component.onCompleted: {
Logger.log("NPanel", "Opened", root.objectName)
}
Connections { Connections {
target: ScalingService target: ScalingService
function onScaleChanged(screenName, scale) { function onScaleChanged(screenName, scale) {
@ -172,6 +177,7 @@ Loader {
// No dimming here // No dimming here
color: Color.transparent color: Color.transparent
WlrLayershell.layer: Settings.data.general.dimDesktop ? WlrLayer.Overlay : WlrLayer.Top
WlrLayershell.exclusionMode: ExclusionMode.Ignore WlrLayershell.exclusionMode: ExclusionMode.Ignore
WlrLayershell.namespace: "noctalia-panel" WlrLayershell.namespace: "noctalia-panel"
WlrLayershell.keyboardFocus: root.panelKeyboardFocus ? WlrKeyboardFocus.OnDemand : WlrKeyboardFocus.None WlrLayershell.keyboardFocus: root.panelKeyboardFocus ? WlrKeyboardFocus.OnDemand : WlrKeyboardFocus.None
@ -280,14 +286,14 @@ Loader {
scale: root.scaleValue scale: root.scaleValue
opacity: root.opacityValue opacity: root.opacityValue
x: calculatedX x: calculatedX
y: calculatedY y: calculatedY
// ---------------------------------------------
// --------------------------------------------- // ---------------------------------------------
// All Style.marginXXX are handled above in the PanelWindow itself. // All Style.marginXXX are handled above in the PanelWindow itself.
// Does not account for corners are they are negligible and helps keep the code clean. // Does not account for corners are they are negligible and helps keep the code clean.
// ---------------------------------------------
// --------------------------------------------- // ---------------------------------------------
property int calculatedX: { property int calculatedX: {
// Priority to fixed anchoring // Priority to fixed anchoring

View file

@ -37,6 +37,7 @@ ShellRoot {
Background {} Background {}
Overview {} Overview {}
ScreenCorners {} ScreenCorners {}
Dimmer {}
Bar {} Bar {}
Dock {} Dock {}