forked from Shinonome/dots-hyprland
use brightness service from caelestia-dots/shell
This commit is contained in:
@@ -26,7 +26,8 @@ Scope {
|
|||||||
PanelWindow { // Bar window
|
PanelWindow { // Bar window
|
||||||
id: barRoot
|
id: barRoot
|
||||||
|
|
||||||
property var modelData
|
property ShellScreen modelData
|
||||||
|
property var brightnessMonitor: Brightness.getMonitorForScreen(modelData)
|
||||||
|
|
||||||
screen: modelData
|
screen: modelData
|
||||||
WlrLayershell.namespace: "quickshell:bar"
|
WlrLayershell.namespace: "quickshell:bar"
|
||||||
@@ -79,9 +80,9 @@ Scope {
|
|||||||
WheelHandler {
|
WheelHandler {
|
||||||
onWheel: (event) => {
|
onWheel: (event) => {
|
||||||
if (event.angleDelta.y < 0)
|
if (event.angleDelta.y < 0)
|
||||||
Brightness.increment = -1;
|
barRoot.brightnessMonitor.setBrightness(barRoot.brightnessMonitor.brightness - 0.05);
|
||||||
else if (event.angleDelta.y > 0)
|
else if (event.angleDelta.y > 0)
|
||||||
Brightness.increment = 1;
|
barRoot.brightnessMonitor.setBrightness(barRoot.brightnessMonitor.brightness + 0.05);
|
||||||
// Store the mouse position and start tracking
|
// Store the mouse position and start tracking
|
||||||
barLeftSideMouseArea.lastScrollX = event.x;
|
barLeftSideMouseArea.lastScrollX = event.x;
|
||||||
barLeftSideMouseArea.lastScrollY = event.y;
|
barLeftSideMouseArea.lastScrollY = event.y;
|
||||||
|
|||||||
@@ -28,14 +28,6 @@ Scope {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Connections {
|
|
||||||
target: Brightness ?? null
|
|
||||||
function onValueChanged() {
|
|
||||||
if (!Brightness.ready) return
|
|
||||||
root.triggerOsd()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
target: Audio.sink?.audio ?? null
|
target: Audio.sink?.audio ?? null
|
||||||
function onVolumeChanged() {
|
function onVolumeChanged() {
|
||||||
@@ -51,6 +43,15 @@ Scope {
|
|||||||
id: osdLoader
|
id: osdLoader
|
||||||
property var modelData
|
property var modelData
|
||||||
active: showOsdValues
|
active: showOsdValues
|
||||||
|
property var brightnessMonitor: Brightness.getMonitorForScreen(modelData)
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
target: brightnessMonitor
|
||||||
|
function onBrightnessChanged() {
|
||||||
|
if (!brightnessMonitor.ready) return
|
||||||
|
root.triggerOsd()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PanelWindow {
|
PanelWindow {
|
||||||
property var modelData
|
property var modelData
|
||||||
@@ -101,7 +102,7 @@ Scope {
|
|||||||
OsdValueIndicator {
|
OsdValueIndicator {
|
||||||
id: osdValues
|
id: osdValues
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
value: Brightness.value
|
value: brightnessMonitor.brightness
|
||||||
icon: "light_mode"
|
icon: "light_mode"
|
||||||
name: qsTr("Brightness")
|
name: qsTr("Brightness")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,13 @@ Scope {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
target: Brightness
|
||||||
|
function onBrightnessChanged() {
|
||||||
|
showOsdValues = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
target: Audio.sink?.audio ?? null
|
target: Audio.sink?.audio ?? null
|
||||||
function onVolumeChanged() {
|
function onVolumeChanged() {
|
||||||
@@ -40,14 +47,6 @@ Scope {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Connections {
|
|
||||||
target: Brightness ?? null
|
|
||||||
function onValueChanged() {
|
|
||||||
if (!Brightness.ready) return
|
|
||||||
root.showOsdValues = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Variants {
|
Variants {
|
||||||
model: Quickshell.screens
|
model: Quickshell.screens
|
||||||
|
|
||||||
|
|||||||
@@ -1,92 +1,135 @@
|
|||||||
pragma Singleton
|
pragma Singleton
|
||||||
pragma ComponentBehavior: Bound
|
pragma ComponentBehavior: Bound
|
||||||
|
|
||||||
import Quickshell
|
import Quickshell
|
||||||
import Quickshell.Io
|
import Quickshell.Io
|
||||||
import Quickshell.Hyprland
|
import Quickshell.Hyprland
|
||||||
|
import QtQuick
|
||||||
|
|
||||||
Singleton {
|
Singleton {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
property bool ready: false
|
signal brightnessChanged()
|
||||||
property real value
|
|
||||||
property int increment: 0
|
|
||||||
|
|
||||||
function refresh() {
|
property var ddcMonitors: []
|
||||||
getBrightness.running = true;
|
readonly property list<BrightnessMonitor> monitors: Quickshell.screens.map(screen => monitorComp.createObject(root, {
|
||||||
|
screen
|
||||||
|
}))
|
||||||
|
|
||||||
|
function getMonitorForScreen(screen: ShellScreen): var {
|
||||||
|
return monitors.find(m => m.screen === screen);
|
||||||
}
|
}
|
||||||
|
|
||||||
onIncrementChanged: () => {
|
function increaseBrightness(): void {
|
||||||
if (increment > 0) {
|
console.log("increaseBrightness");
|
||||||
increaseBrightness.running = true;
|
const focusedName = Hyprland.focusedMonitor.name;
|
||||||
root.increment = 0;
|
const monitor = monitors.find(m => focusedName === m.screen.name);
|
||||||
} else if (increment < 0) {
|
if (monitor)
|
||||||
decreaseBrightness.running = true;
|
monitor.setBrightness(monitor.brightness + 0.1);
|
||||||
root.increment = 0;
|
}
|
||||||
}
|
|
||||||
|
function decreaseBrightness(): void {
|
||||||
|
const focusedName = Hyprland.focusedMonitor.name;
|
||||||
|
const monitor = monitors.find(m => focusedName === m.screen.name);
|
||||||
|
if (monitor)
|
||||||
|
monitor.setBrightness(monitor.brightness - 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
reloadableId: "brightness"
|
||||||
|
|
||||||
|
onMonitorsChanged: {
|
||||||
|
ddcMonitors = [];
|
||||||
|
ddcProc.running = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Process {
|
Process {
|
||||||
id: getBrightness
|
id: ddcProc
|
||||||
|
|
||||||
command: ["sh", "-c", "brightnessctl -m i | cut -d, -f4"]
|
|
||||||
running: true
|
|
||||||
onExited: {
|
|
||||||
if (!ready) ready = true
|
|
||||||
}
|
|
||||||
|
|
||||||
|
command: ["ddcutil", "detect", "--brief"]
|
||||||
stdout: SplitParser {
|
stdout: SplitParser {
|
||||||
onRead: (data) => {
|
splitMarker: "\n\n"
|
||||||
root.value = parseFloat(data.replace("%", "")) / 100;
|
onRead: data => {
|
||||||
if (root.value < 0.01) {
|
if (data.startsWith("Display ")) {
|
||||||
preventPitchBlack.running = true;
|
const lines = data.split("\n").map(l => l.trim());
|
||||||
|
root.ddcMonitors.push({
|
||||||
|
model: lines.find(l => l.startsWith("Monitor:")).split(":")[2],
|
||||||
|
busNum: lines.find(l => l.startsWith("I2C bus:")).split("/dev/i2c-")[1]
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
onExited: root.ddcMonitorsChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
Process {
|
Process {
|
||||||
id: decreaseBrightness
|
id: setProc
|
||||||
|
|
||||||
command: ["brightnessctl", "set", "5%-", "-e"]
|
|
||||||
running: false
|
|
||||||
onExited: {
|
|
||||||
running = false;
|
|
||||||
getBrightness.running = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Process {
|
|
||||||
id: increaseBrightness
|
|
||||||
|
|
||||||
command: ["brightnessctl", "set", "5%+", "-e"]
|
|
||||||
running: false
|
|
||||||
onExited: {
|
|
||||||
running = false;
|
|
||||||
getBrightness.running = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Process {
|
|
||||||
id: preventPitchBlack
|
|
||||||
|
|
||||||
command: ["brightnessctl", "set", "1%+", "-e"]
|
|
||||||
running: false
|
|
||||||
onExited: {
|
|
||||||
running = false;
|
|
||||||
getBrightness.running = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IpcHandler {
|
IpcHandler {
|
||||||
target: "brightness"
|
target: "brightness"
|
||||||
|
|
||||||
function increment() {
|
function increment() {
|
||||||
root.increment = 1
|
onPressed: root.increaseBrightness()
|
||||||
}
|
}
|
||||||
|
|
||||||
function decrement() {
|
function decrement() {
|
||||||
root.increment = -1
|
onPressed: root.decreaseBrightness()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
component BrightnessMonitor: QtObject {
|
||||||
|
id: monitor
|
||||||
|
|
||||||
|
required property ShellScreen screen
|
||||||
|
readonly property bool isDdc: root.ddcMonitors.some(m => m.model === screen.model)
|
||||||
|
readonly property string busNum: root.ddcMonitors.find(m => m.model === screen.model)?.busNum ?? ""
|
||||||
|
property real brightness
|
||||||
|
property bool ready: false
|
||||||
|
|
||||||
|
onBrightnessChanged: {
|
||||||
|
if (monitor.ready) {
|
||||||
|
root.brightnessChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function initialize() {
|
||||||
|
monitor.ready = false;
|
||||||
|
initProc.command = isDdc ? ["ddcutil", "-b", busNum, "getvcp", "10", "--brief"] : ["sh", "-c", `echo "a b c $(brightnessctl g) $(brightnessctl m)"`];
|
||||||
|
initProc.running = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
readonly property Process initProc: Process {
|
||||||
|
stdout: SplitParser {
|
||||||
|
onRead: data => {
|
||||||
|
const [, , , current, max] = data.split(" ");
|
||||||
|
monitor.brightness = parseInt(current) / parseInt(max);
|
||||||
|
monitor.ready = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setBrightness(value: real): void {
|
||||||
|
value = Math.max(0.01, Math.min(1, value));
|
||||||
|
const rounded = Math.round(value * 100);
|
||||||
|
if (Math.round(brightness * 100) === rounded)
|
||||||
|
return;
|
||||||
|
brightness = value;
|
||||||
|
setProc.command = isDdc ? ["ddcutil", "-b", busNum, "setvcp", "10", rounded] : ["brightnessctl", "s", `${rounded}%`];
|
||||||
|
setProc.startDetached();
|
||||||
|
}
|
||||||
|
|
||||||
|
Component.onCompleted: {
|
||||||
|
initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
onBusNumChanged: {
|
||||||
|
initialize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: monitorComp
|
||||||
|
|
||||||
|
BrightnessMonitor {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user