Brightness implementation with IPC

This commit is contained in:
Ly-sec 2025-08-15 14:05:02 +02:00
parent 20814007be
commit 22df558e14
6 changed files with 335 additions and 392 deletions

View file

@ -12,6 +12,7 @@ Item {
// Used to avoid opening the pill on Quickshell startup
property bool firstBrightnessReceived: false
property real lastBrightness: -1
function getIcon() {
if (!BrightnessService.available) {
@ -25,18 +26,28 @@ Item {
// Connection used to open the pill when brightness changes
Connections {
target: Brightness
target: BrightnessService.focusedMonitor
function onBrightnessUpdated() {
// console.log("[Bar:Brightness] onBrightnessUpdated")
var currentBrightness = BrightnessService.brightness
// Ignore if this is the first time or if brightness hasn't actually changed
if (!firstBrightnessReceived) {
// Ignore the first brightness change
firstBrightnessReceived = true
} else {
lastBrightness = currentBrightness
return
}
// Only show pill if brightness actually changed (not just loaded from settings)
if (Math.abs(currentBrightness - lastBrightness) > 0.1) {
pill.show()
}
lastBrightness = currentBrightness
}
}
NPill {
id: pill
icon: getIcon()
@ -44,15 +55,15 @@ Item {
collapsedIconColor: Colors.mOnSurface
autoHide: true
text: Math.round(BrightnessService.brightness) + "%"
tooltipText: "Brightness: " + Math.round(BrightnessService.brightness) + "%\nMethod: " + BrightnessService.currentMethod + "\nLeft click for advanced settings.\nScroll up/down to change BrightnessService."
tooltipText: "Brightness: " + Math.round(BrightnessService.brightness) + "%\nMethod: " + BrightnessService.currentMethod + "\nLeft click for advanced settings.\nScroll up/down to change brightness."
onWheel: function (angle) {
if (!BrightnessService.available) return
if (angle > 0) {
BrightnessService.increaseBrightness(1)
BrightnessService.increaseBrightness()
} else if (angle < 0) {
BrightnessService.decreaseBrightness(1)
BrightnessService.decreaseBrightness()
}
}
onClicked: {

View file

@ -294,7 +294,7 @@ NLoader {
icon: "brightness_low"
fontPointSize: Style.fontSizeLarge * scaling
onClicked: {
Brightness.decreaseBrightness(1)
Brightness.decreaseBrightness()
}
}
NSlider {
@ -311,7 +311,7 @@ NLoader {
icon: "brightness_high"
fontPointSize: Style.fontSizeLarge * scaling
onClicked: {
Brightness.increaseBrightness(1)
Brightness.increaseBrightness()
}
}
}

View file

@ -47,6 +47,55 @@ Item {
color: Colors.mOnSurface
}
// Brightness Section
ColumnLayout {
spacing: Style.marginSmall * scaling
Layout.fillWidth: true
Layout.topMargin: Style.marginSmall * scaling
NText {
text: "Brightness Step Size"
font.weight: Style.fontWeightBold
color: Colors.mOnSurface
}
NText {
text: "Adjust the step size for brightness changes (scroll wheel, ipc bind)"
font.pointSize: Style.fontSizeSmall * scaling
color: Colors.mOnSurface
wrapMode: Text.WordWrap
Layout.fillWidth: true
}
RowLayout {
Layout.fillWidth: true
spacing: Style.marginMedium * scaling
NSlider {
Layout.fillWidth: true
from: 1
to: 50
value: Settings.data.brightness.brightnessStep
stepSize: 1
onMoved: {
Settings.data.brightness.brightnessStep = value
}
}
NText {
text: Settings.data.brightness.brightnessStep + "%"
Layout.alignment: Qt.AlignVCenter
color: Colors.mOnSurface
}
}
}
NDivider {
Layout.fillWidth: true
Layout.topMargin: Style.marginLarge * 2 * scaling
Layout.bottomMargin: Style.marginLarge * scaling
}
Repeater {
model: Quickshell.screens || []
delegate: Rectangle {