mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-07 05:55:37 -05:00
support multi-brightness devices
This commit is contained in:
@@ -9,221 +9,248 @@ import qs.Services
|
|||||||
import qs.Widgets
|
import qs.Widgets
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
id: displayTab
|
id: displayTab
|
||||||
|
|
||||||
property var brightnessDebounceTimer
|
property var brightnessDebounceTimer
|
||||||
|
|
||||||
brightnessDebounceTimer: Timer {
|
DankFlickable {
|
||||||
property int pendingValue: 0
|
anchors.fill: parent
|
||||||
|
clip: true
|
||||||
|
contentHeight: mainColumn.height
|
||||||
|
contentWidth: width
|
||||||
|
|
||||||
interval: BrightnessService.ddcAvailable ? 500 : 50
|
Column {
|
||||||
repeat: false
|
id: mainColumn
|
||||||
onTriggered: {
|
|
||||||
BrightnessService.setBrightnessInternal(pendingValue)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DankFlickable {
|
width: parent.width
|
||||||
anchors.fill: parent
|
spacing: Theme.spacingL
|
||||||
clip: true
|
|
||||||
contentHeight: mainColumn.height
|
|
||||||
contentWidth: width
|
|
||||||
|
|
||||||
Column {
|
Loader {
|
||||||
id: mainColumn
|
width: parent.width
|
||||||
width: parent.width
|
sourceComponent: brightnessComponent
|
||||||
spacing: Theme.spacingL
|
|
||||||
|
|
||||||
Loader {
|
|
||||||
width: parent.width
|
|
||||||
sourceComponent: brightnessComponent
|
|
||||||
}
|
|
||||||
|
|
||||||
Loader {
|
|
||||||
width: parent.width
|
|
||||||
sourceComponent: settingsComponent
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Process {
|
|
||||||
id: nightModeEnableProcess
|
|
||||||
command: ["bash", "-c", "if command -v wlsunset > /dev/null; then pkill wlsunset; wlsunset -t 3000 & elif command -v redshift > /dev/null; then pkill redshift; redshift -P -O 3000 & else echo 'No night mode tool available'; fi"]
|
|
||||||
running: false
|
|
||||||
onExited: exitCode => {
|
|
||||||
if (exitCode !== 0) {
|
|
||||||
SettingsData.setNightModeEnabled(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Process {
|
|
||||||
id: nightModeDisableProcess
|
|
||||||
command: ["bash", "-c", "pkill wlsunset; pkill redshift; if command -v wlsunset > /dev/null; then wlsunset -t 6500 -T 6500 & sleep 1; pkill wlsunset; elif command -v redshift > /dev/null; then redshift -P -O 6500; redshift -x; fi"]
|
|
||||||
running: false
|
|
||||||
onExited: exitCode => {
|
|
||||||
if (exitCode !== 0) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Component {
|
|
||||||
id: brightnessComponent
|
|
||||||
Column {
|
|
||||||
width: parent.width
|
|
||||||
spacing: Theme.spacingM
|
|
||||||
visible: BrightnessService.brightnessAvailable
|
|
||||||
|
|
||||||
StyledText {
|
|
||||||
text: "Brightness"
|
|
||||||
font.pixelSize: Theme.fontSizeLarge
|
|
||||||
color: Theme.surfaceText
|
|
||||||
font.weight: Font.Medium
|
|
||||||
}
|
|
||||||
|
|
||||||
DankSlider {
|
|
||||||
width: parent.width
|
|
||||||
value: BrightnessService.brightnessLevel
|
|
||||||
leftIcon: "brightness_low"
|
|
||||||
rightIcon: "brightness_high"
|
|
||||||
enabled: BrightnessService.brightnessAvailable
|
|
||||||
onSliderValueChanged: function (newValue) {
|
|
||||||
brightnessDebounceTimer.pendingValue = newValue
|
|
||||||
brightnessDebounceTimer.restart()
|
|
||||||
}
|
|
||||||
onSliderDragFinished: function (finalValue) {
|
|
||||||
brightnessDebounceTimer.stop()
|
|
||||||
BrightnessService.setBrightnessInternal(finalValue)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
StyledText {
|
|
||||||
text: "using ddc - changes may take a moment to apply"
|
|
||||||
font.pixelSize: Theme.fontSizeSmall
|
|
||||||
color: Theme.surfaceVariantText
|
|
||||||
visible: BrightnessService.ddcAvailable
|
|
||||||
&& !BrightnessService.laptopBacklightAvailable
|
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Component {
|
|
||||||
id: settingsComponent
|
|
||||||
Column {
|
|
||||||
width: parent.width
|
|
||||||
spacing: Theme.spacingM
|
|
||||||
|
|
||||||
StyledText {
|
|
||||||
text: "Display Settings"
|
|
||||||
font.pixelSize: Theme.fontSizeLarge
|
|
||||||
color: Theme.surfaceText
|
|
||||||
font.weight: Font.Medium
|
|
||||||
}
|
|
||||||
|
|
||||||
Row {
|
|
||||||
width: parent.width
|
|
||||||
spacing: Theme.spacingM
|
|
||||||
|
|
||||||
Rectangle {
|
|
||||||
width: (parent.width - Theme.spacingM) / 2
|
|
||||||
height: 80
|
|
||||||
radius: Theme.cornerRadius
|
|
||||||
color: SettingsData.nightModeEnabled ? Qt.rgba(
|
|
||||||
Theme.primary.r,
|
|
||||||
Theme.primary.g,
|
|
||||||
Theme.primary.b,
|
|
||||||
0.12) : (nightModeToggle.containsMouse ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.08) : Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.08))
|
|
||||||
border.color: SettingsData.nightModeEnabled ? Theme.primary : "transparent"
|
|
||||||
border.width: SettingsData.nightModeEnabled ? 1 : 0
|
|
||||||
|
|
||||||
Column {
|
|
||||||
anchors.centerIn: parent
|
|
||||||
spacing: Theme.spacingS
|
|
||||||
|
|
||||||
DankIcon {
|
|
||||||
name: SettingsData.nightModeEnabled ? "nightlight" : "dark_mode"
|
|
||||||
size: Theme.iconSizeLarge
|
|
||||||
color: SettingsData.nightModeEnabled ? Theme.primary : Theme.surfaceText
|
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loader {
|
||||||
|
width: parent.width
|
||||||
|
sourceComponent: settingsComponent
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Process {
|
||||||
|
id: nightModeEnableProcess
|
||||||
|
|
||||||
|
command: ["bash", "-c", "if command -v wlsunset > /dev/null; then pkill wlsunset; wlsunset -t 3000 & elif command -v redshift > /dev/null; then pkill redshift; redshift -P -O 3000 & else echo 'No night mode tool available'; fi"]
|
||||||
|
running: false
|
||||||
|
onExited: (exitCode) => {
|
||||||
|
if (exitCode !== 0)
|
||||||
|
SettingsData.setNightModeEnabled(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Process {
|
||||||
|
id: nightModeDisableProcess
|
||||||
|
|
||||||
|
command: ["bash", "-c", "pkill wlsunset; pkill redshift; if command -v wlsunset > /dev/null; then wlsunset -t 6500 -T 6500 & sleep 1; pkill wlsunset; elif command -v redshift > /dev/null; then redshift -P -O 6500; redshift -x; fi"]
|
||||||
|
running: false
|
||||||
|
onExited: (exitCode) => {
|
||||||
|
if (exitCode !== 0) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: brightnessComponent
|
||||||
|
|
||||||
|
Column {
|
||||||
|
width: parent.width
|
||||||
|
spacing: Theme.spacingS
|
||||||
|
visible: BrightnessService.brightnessAvailable
|
||||||
|
|
||||||
StyledText {
|
StyledText {
|
||||||
text: "Night Mode"
|
text: "Brightness"
|
||||||
font.pixelSize: Theme.fontSizeMedium
|
font.pixelSize: Theme.fontSizeLarge
|
||||||
color: SettingsData.nightModeEnabled ? Theme.primary : Theme.surfaceText
|
color: Theme.surfaceText
|
||||||
font.weight: Font.Medium
|
font.weight: Font.Medium
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
MouseArea {
|
DankDropdown {
|
||||||
id: nightModeToggle
|
width: parent.width
|
||||||
anchors.fill: parent
|
height: 40
|
||||||
hoverEnabled: true
|
visible: BrightnessService.devices.length > 1
|
||||||
cursorShape: Qt.PointingHandCursor
|
text: "Device"
|
||||||
onClicked: {
|
description: ""
|
||||||
if (SettingsData.nightModeEnabled) {
|
currentValue: BrightnessService.currentDevice
|
||||||
nightModeDisableProcess.running = true
|
options: BrightnessService.devices.map(function(d) {
|
||||||
SettingsData.setNightModeEnabled(false)
|
return d.name;
|
||||||
} else {
|
})
|
||||||
nightModeEnableProcess.running = true
|
optionIcons: BrightnessService.devices.map(function(d) {
|
||||||
SettingsData.setNightModeEnabled(true)
|
if (d.class === "backlight")
|
||||||
}
|
return "desktop_windows";
|
||||||
|
|
||||||
|
if (d.name.includes("kbd"))
|
||||||
|
return "keyboard";
|
||||||
|
|
||||||
|
return "lightbulb";
|
||||||
|
})
|
||||||
|
onValueChanged: function(value) {
|
||||||
|
BrightnessService.setCurrentDevice(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
DankSlider {
|
||||||
|
width: parent.width
|
||||||
|
value: BrightnessService.brightnessLevel
|
||||||
|
leftIcon: "brightness_low"
|
||||||
|
rightIcon: "brightness_high"
|
||||||
|
enabled: BrightnessService.brightnessAvailable
|
||||||
|
onSliderValueChanged: function(newValue) {
|
||||||
|
brightnessDebounceTimer.pendingValue = newValue;
|
||||||
|
brightnessDebounceTimer.restart();
|
||||||
|
}
|
||||||
|
onSliderDragFinished: function(finalValue) {
|
||||||
|
brightnessDebounceTimer.stop();
|
||||||
|
BrightnessService.setBrightnessInternal(finalValue, BrightnessService.currentDevice);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
}
|
||||||
width: (parent.width - Theme.spacingM) / 2
|
|
||||||
height: 80
|
|
||||||
radius: Theme.cornerRadius
|
|
||||||
color: Theme.isLightMode ? Qt.rgba(
|
|
||||||
Theme.primary.r, Theme.primary.g,
|
|
||||||
Theme.primary.b,
|
|
||||||
0.12) : (lightModeToggle.containsMouse ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.08) : Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.08))
|
|
||||||
border.color: Theme.isLightMode ? Theme.primary : "transparent"
|
|
||||||
border.width: Theme.isLightMode ? 1 : 0
|
|
||||||
|
|
||||||
Column {
|
Component {
|
||||||
anchors.centerIn: parent
|
id: settingsComponent
|
||||||
spacing: Theme.spacingS
|
|
||||||
|
|
||||||
DankIcon {
|
Column {
|
||||||
name: Theme.isLightMode ? "light_mode" : "palette"
|
width: parent.width
|
||||||
size: Theme.iconSizeLarge
|
spacing: Theme.spacingM
|
||||||
color: Theme.isLightMode ? Theme.primary : Theme.surfaceText
|
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
|
||||||
}
|
|
||||||
|
|
||||||
StyledText {
|
StyledText {
|
||||||
text: Theme.isLightMode ? "Light Mode" : "Dark Mode"
|
text: "Display Settings"
|
||||||
font.pixelSize: Theme.fontSizeMedium
|
font.pixelSize: Theme.fontSizeLarge
|
||||||
color: Theme.isLightMode ? Theme.primary : Theme.surfaceText
|
color: Theme.surfaceText
|
||||||
font.weight: Font.Medium
|
font.weight: Font.Medium
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
MouseArea {
|
Row {
|
||||||
id: lightModeToggle
|
width: parent.width
|
||||||
anchors.fill: parent
|
spacing: Theme.spacingM
|
||||||
hoverEnabled: true
|
|
||||||
cursorShape: Qt.PointingHandCursor
|
Rectangle {
|
||||||
onClicked: {
|
width: (parent.width - Theme.spacingM) / 2
|
||||||
Theme.toggleLightMode()
|
height: 80
|
||||||
}
|
radius: Theme.cornerRadius
|
||||||
}
|
color: SettingsData.nightModeEnabled ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.12) : (nightModeToggle.containsMouse ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.08) : Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.08))
|
||||||
|
border.color: SettingsData.nightModeEnabled ? Theme.primary : "transparent"
|
||||||
|
border.width: SettingsData.nightModeEnabled ? 1 : 0
|
||||||
|
|
||||||
|
Column {
|
||||||
|
anchors.centerIn: parent
|
||||||
|
spacing: Theme.spacingS
|
||||||
|
|
||||||
|
DankIcon {
|
||||||
|
name: SettingsData.nightModeEnabled ? "nightlight" : "dark_mode"
|
||||||
|
size: Theme.iconSizeLarge
|
||||||
|
color: SettingsData.nightModeEnabled ? Theme.primary : Theme.surfaceText
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledText {
|
||||||
|
text: "Night Mode"
|
||||||
|
font.pixelSize: Theme.fontSizeMedium
|
||||||
|
color: SettingsData.nightModeEnabled ? Theme.primary : Theme.surfaceText
|
||||||
|
font.weight: Font.Medium
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
MouseArea {
|
||||||
|
id: nightModeToggle
|
||||||
|
|
||||||
|
anchors.fill: parent
|
||||||
|
hoverEnabled: true
|
||||||
|
cursorShape: Qt.PointingHandCursor
|
||||||
|
onClicked: {
|
||||||
|
if (SettingsData.nightModeEnabled) {
|
||||||
|
nightModeDisableProcess.running = true;
|
||||||
|
SettingsData.setNightModeEnabled(false);
|
||||||
|
} else {
|
||||||
|
nightModeEnableProcess.running = true;
|
||||||
|
SettingsData.setNightModeEnabled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
width: (parent.width - Theme.spacingM) / 2
|
||||||
|
height: 80
|
||||||
|
radius: Theme.cornerRadius
|
||||||
|
color: Theme.isLightMode ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.12) : (lightModeToggle.containsMouse ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.08) : Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.08))
|
||||||
|
border.color: Theme.isLightMode ? Theme.primary : "transparent"
|
||||||
|
border.width: Theme.isLightMode ? 1 : 0
|
||||||
|
|
||||||
|
Column {
|
||||||
|
anchors.centerIn: parent
|
||||||
|
spacing: Theme.spacingS
|
||||||
|
|
||||||
|
DankIcon {
|
||||||
|
name: Theme.isLightMode ? "light_mode" : "palette"
|
||||||
|
size: Theme.iconSizeLarge
|
||||||
|
color: Theme.isLightMode ? Theme.primary : Theme.surfaceText
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledText {
|
||||||
|
text: Theme.isLightMode ? "Light Mode" : "Dark Mode"
|
||||||
|
font.pixelSize: Theme.fontSizeMedium
|
||||||
|
color: Theme.isLightMode ? Theme.primary : Theme.surfaceText
|
||||||
|
font.weight: Font.Medium
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
MouseArea {
|
||||||
|
id: lightModeToggle
|
||||||
|
|
||||||
|
anchors.fill: parent
|
||||||
|
hoverEnabled: true
|
||||||
|
cursorShape: Qt.PointingHandCursor
|
||||||
|
onClicked: {
|
||||||
|
Theme.toggleLightMode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Behavior on color {
|
||||||
|
ColorAnimation {
|
||||||
|
duration: Theme.shortDuration
|
||||||
|
easing.type: Theme.standardEasing
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Behavior on color {
|
|
||||||
ColorAnimation {
|
|
||||||
duration: Theme.shortDuration
|
|
||||||
easing.type: Theme.standardEasing
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
brightnessDebounceTimer: Timer {
|
||||||
|
property int pendingValue: 0
|
||||||
|
|
||||||
|
interval: 50
|
||||||
|
repeat: false
|
||||||
|
onTriggered: {
|
||||||
|
BrightnessService.setBrightnessInternal(pendingValue, BrightnessService.currentDevice);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
12
README.md
12
README.md
@@ -164,11 +164,11 @@ make && sudo make install
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Arch Linux
|
# Arch Linux
|
||||||
pacman -S cava wl-clipboard cliphist ddcutil brightnessctl
|
pacman -S cava wl-clipboard cliphist brightnessctl
|
||||||
paru -S matugen dgop-git
|
paru -S matugen dgop-git
|
||||||
|
|
||||||
# Fedora
|
# Fedora
|
||||||
sudo dnf install cava wl-clipboard ddcutil brightnessctl
|
sudo dnf install cava wl-clipboard brightnessctl
|
||||||
sudo dnf copr enable wef/cliphist && sudo dnf install cliphist
|
sudo dnf copr enable wef/cliphist && sudo dnf install cliphist
|
||||||
sudo dnf copr enable heus-sueh/packages && sudo dnf install matugen
|
sudo dnf copr enable heus-sueh/packages && sudo dnf install matugen
|
||||||
```
|
```
|
||||||
@@ -177,8 +177,7 @@ sudo dnf copr enable heus-sueh/packages && sudo dnf install matugen
|
|||||||
|
|
||||||
- `dgop-git`: Ability to have system resource widgets, process list modal, and temperature monitoring.
|
- `dgop-git`: Ability to have system resource widgets, process list modal, and temperature monitoring.
|
||||||
- `matugen`: Wallpaper-based dynamic theming
|
- `matugen`: Wallpaper-based dynamic theming
|
||||||
- `ddcutil`: External monitor brightness control
|
- `brightnessctl`: Backlight and LED brightness control
|
||||||
- `brightnessctl`: Laptop display brightness
|
|
||||||
- `wl-clipboard`: Required for copying various elements to clipboard.
|
- `wl-clipboard`: Required for copying various elements to clipboard.
|
||||||
- `cava`: Audio visualizer
|
- `cava`: Audio visualizer
|
||||||
- `cliphist`: Clipboard history
|
- `cliphist`: Clipboard history
|
||||||
@@ -239,10 +238,11 @@ binds {
|
|||||||
spawn "qs" "-c" "DankMaterialShell" "ipc" "call" "audio" "micmute";
|
spawn "qs" "-c" "DankMaterialShell" "ipc" "call" "audio" "micmute";
|
||||||
}
|
}
|
||||||
XF86MonBrightnessUp allow-when-locked=true {
|
XF86MonBrightnessUp allow-when-locked=true {
|
||||||
spawn "qs" "-c" "DankMaterialShell" "ipc" "call" "brightness" "increment" "5";
|
spawn "qs" "-c" "DankMaterialShell" "ipc" "call" "brightness" "increment" "5" "";
|
||||||
}
|
}
|
||||||
|
// You can override the default device for e.g. keyboards by adding the device name to the last param
|
||||||
XF86MonBrightnessDown allow-when-locked=true {
|
XF86MonBrightnessDown allow-when-locked=true {
|
||||||
spawn "qs" "-c" "DankMaterialShell" "ipc" "call" "brightness" "decrement" "5";
|
spawn "qs" "-c" "DankMaterialShell" "ipc" "call" "brightness" "decrement" "5" "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -1,211 +1,207 @@
|
|||||||
pragma Singleton
|
|
||||||
|
|
||||||
pragma ComponentBehavior
|
|
||||||
|
|
||||||
import QtQuick
|
import QtQuick
|
||||||
import Quickshell
|
import Quickshell
|
||||||
import Quickshell.Io
|
import Quickshell.Io
|
||||||
|
pragma Singleton
|
||||||
|
pragma ComponentBehavior
|
||||||
|
|
||||||
Singleton {
|
Singleton {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
property bool brightnessAvailable: laptopBacklightAvailable || ddcAvailable
|
property bool brightnessAvailable: devices.length > 0
|
||||||
property bool laptopBacklightAvailable: false
|
property var devices: []
|
||||||
property bool ddcAvailable: false
|
property string currentDevice: ""
|
||||||
property int brightnessLevel: 50
|
property int brightnessLevel: 50
|
||||||
property int maxBrightness: 100
|
property int maxBrightness: 100
|
||||||
property int currentRawBrightness: 0
|
property bool brightnessInitialized: false
|
||||||
property bool brightnessInitialized: false
|
|
||||||
|
|
||||||
signal brightnessChanged
|
signal brightnessChanged()
|
||||||
|
|
||||||
function setBrightnessInternal(percentage) {
|
function setBrightnessInternal(percentage, device) {
|
||||||
brightnessLevel = Math.max(1, Math.min(100, percentage))
|
const clampedValue = Math.max(1, Math.min(100, percentage));
|
||||||
|
brightnessLevel = clampedValue;
|
||||||
if (laptopBacklightAvailable) {
|
if (device)
|
||||||
laptopBrightnessProcess.command = ["brightnessctl", "set", brightnessLevel + "%"]
|
brightnessSetProcess.command = ["brightnessctl", "-d", device, "set", clampedValue + "%"];
|
||||||
laptopBrightnessProcess.running = true
|
else
|
||||||
} else if (ddcAvailable) {
|
brightnessSetProcess.command = ["brightnessctl", "set", clampedValue + "%"];
|
||||||
|
brightnessSetProcess.running = true;
|
||||||
Quickshell.execDetached(
|
|
||||||
["ddcutil", "setvcp", "10", brightnessLevel.toString()])
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function setBrightness(percentage) {
|
function setBrightness(percentage, device) {
|
||||||
setBrightnessInternal(percentage)
|
setBrightnessInternal(percentage, device);
|
||||||
brightnessChanged()
|
brightnessChanged();
|
||||||
}
|
|
||||||
|
|
||||||
Component.onCompleted: {
|
|
||||||
ddcAvailabilityChecker.running = true
|
|
||||||
laptopBacklightChecker.running = true
|
|
||||||
}
|
|
||||||
|
|
||||||
onLaptopBacklightAvailableChanged: {
|
|
||||||
if (laptopBacklightAvailable && !brightnessInitialized) {
|
|
||||||
laptopBrightnessInitProcess.running = true
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
onDdcAvailableChanged: {
|
function setCurrentDevice(deviceName) {
|
||||||
if (ddcAvailable && !laptopBacklightAvailable && !brightnessInitialized) {
|
if (currentDevice === deviceName)
|
||||||
ddcBrightnessInitProcess.running = true
|
return ;
|
||||||
|
|
||||||
|
currentDevice = deviceName;
|
||||||
|
brightnessGetProcess.command = ["brightnessctl", "-m", "-d", deviceName, "get"];
|
||||||
|
brightnessGetProcess.running = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Process {
|
function refreshDevices() {
|
||||||
id: ddcAvailabilityChecker
|
deviceListProcess.running = true;
|
||||||
command: ["which", "ddcutil"]
|
|
||||||
onExited: function (exitCode) {
|
|
||||||
ddcAvailable = (exitCode === 0)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Process {
|
Component.onCompleted: {
|
||||||
id: laptopBacklightChecker
|
refreshDevices();
|
||||||
command: ["brightnessctl", "--list"]
|
|
||||||
onExited: function (exitCode) {
|
|
||||||
laptopBacklightAvailable = (exitCode === 0)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Process {
|
Process {
|
||||||
id: laptopBrightnessProcess
|
id: deviceListProcess
|
||||||
running: false
|
|
||||||
|
|
||||||
onExited: function (exitCode) {
|
command: ["brightnessctl", "-m", "-l"]
|
||||||
if (exitCode !== 0) {
|
onExited: function(exitCode) {
|
||||||
|
if (exitCode !== 0) {
|
||||||
}
|
console.warn("BrightnessService: Failed to list devices:", exitCode);
|
||||||
}
|
brightnessAvailable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Process {
|
|
||||||
id: laptopBrightnessInitProcess
|
|
||||||
command: ["brightnessctl", "get"]
|
|
||||||
running: false
|
|
||||||
|
|
||||||
stdout: StdioCollector {
|
|
||||||
onStreamFinished: {
|
|
||||||
if (text.trim()) {
|
|
||||||
currentRawBrightness = parseInt(text.trim())
|
|
||||||
laptopMaxBrightnessProcess.running = true
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onExited: function (exitCode) {
|
stdout: StdioCollector {
|
||||||
if (exitCode !== 0) {
|
onStreamFinished: {
|
||||||
console.warn("BrightnessService: Failed to read current brightness:",
|
if (!text.trim()) {
|
||||||
exitCode)
|
console.warn("BrightnessService: No devices found");
|
||||||
}
|
return ;
|
||||||
}
|
}
|
||||||
}
|
const lines = text.trim().split("\n");
|
||||||
|
const newDevices = [];
|
||||||
|
for (const line of lines) {
|
||||||
|
const parts = line.split(",");
|
||||||
|
if (parts.length >= 5)
|
||||||
|
newDevices.push({
|
||||||
|
"name": parts[0],
|
||||||
|
"class": parts[1],
|
||||||
|
"current": parseInt(parts[2]),
|
||||||
|
"percentage": parseInt(parts[3]),
|
||||||
|
"max": parseInt(parts[4])
|
||||||
|
});
|
||||||
|
|
||||||
Process {
|
}
|
||||||
id: laptopMaxBrightnessProcess
|
newDevices.sort((a, b) => {
|
||||||
command: ["brightnessctl", "max"]
|
if (a.class === "backlight" && b.class !== "backlight")
|
||||||
running: false
|
return -1;
|
||||||
|
|
||||||
stdout: StdioCollector {
|
if (a.class !== "backlight" && b.class === "backlight")
|
||||||
onStreamFinished: {
|
return 1;
|
||||||
if (text.trim()) {
|
|
||||||
maxBrightness = parseInt(text.trim())
|
return a.name.localeCompare(b.name);
|
||||||
brightnessLevel = Math.round(
|
});
|
||||||
(currentRawBrightness / maxBrightness) * 100)
|
devices = newDevices;
|
||||||
brightnessInitialized = true
|
if (devices.length > 0 && !currentDevice)
|
||||||
console.log("BrightnessService: Initialized with brightness level:",
|
setCurrentDevice(devices[0].name);
|
||||||
brightnessLevel + "%")
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onExited: function (exitCode) {
|
Process {
|
||||||
if (exitCode !== 0) {
|
id: brightnessSetProcess
|
||||||
console.warn("BrightnessService: Failed to read max brightness:",
|
|
||||||
exitCode)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Process {
|
running: false
|
||||||
id: ddcBrightnessInitProcess
|
onExited: function(exitCode) {
|
||||||
command: ["ddcutil", "getvcp", "10", "--brief"]
|
if (exitCode !== 0)
|
||||||
running: false
|
console.warn("BrightnessService: Failed to set brightness:", exitCode);
|
||||||
|
|
||||||
stdout: StdioCollector {
|
|
||||||
onStreamFinished: {
|
|
||||||
if (text.trim()) {
|
|
||||||
const parts = text.trim().split(" ")
|
|
||||||
if (parts.length >= 5) {
|
|
||||||
const current = parseInt(parts[3]) || 50
|
|
||||||
const max = parseInt(parts[4]) || 100
|
|
||||||
brightnessLevel = Math.round((current / max) * 100)
|
|
||||||
brightnessInitialized = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onExited: function (exitCode) {
|
Process {
|
||||||
if (exitCode !== 0) {
|
id: brightnessGetProcess
|
||||||
if (!laptopBacklightAvailable) {
|
|
||||||
console.warn("BrightnessService: DDC brightness read failed:",
|
running: false
|
||||||
exitCode)
|
onExited: function(exitCode) {
|
||||||
|
if (exitCode !== 0)
|
||||||
|
console.warn("BrightnessService: Failed to get brightness:", exitCode);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// IPC Handler for external control
|
stdout: StdioCollector {
|
||||||
IpcHandler {
|
onStreamFinished: {
|
||||||
target: "brightness"
|
if (!text.trim())
|
||||||
|
return ;
|
||||||
|
|
||||||
function set(percentage: string): string {
|
const parts = text.trim().split(",");
|
||||||
if (!root.brightnessAvailable) {
|
if (parts.length >= 5) {
|
||||||
return "Brightness control not available"
|
const current = parseInt(parts[2]);
|
||||||
}
|
const max = parseInt(parts[4]);
|
||||||
|
maxBrightness = max;
|
||||||
|
brightnessLevel = Math.round((current / max) * 100);
|
||||||
|
brightnessInitialized = true;
|
||||||
|
console.log("BrightnessService: Device", currentDevice, "brightness:", brightnessLevel + "%");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const value = parseInt(percentage)
|
|
||||||
const clampedValue = Math.max(1, Math.min(100, value))
|
|
||||||
root.setBrightness(clampedValue)
|
|
||||||
return "Brightness set to " + clampedValue + "%"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function increment(step: string): string {
|
// IPC Handler for external control
|
||||||
if (!root.brightnessAvailable) {
|
IpcHandler {
|
||||||
return "Brightness control not available"
|
function set(percentage: string, device: string) : string {
|
||||||
}
|
if (!root.brightnessAvailable)
|
||||||
|
return "Brightness control not available";
|
||||||
|
|
||||||
const currentLevel = root.brightnessLevel
|
const value = parseInt(percentage);
|
||||||
const newLevel = Math.max(1,
|
const clampedValue = Math.max(1, Math.min(100, value));
|
||||||
Math.min(100,
|
const targetDevice = device || "";
|
||||||
currentLevel + parseInt(step || "10")))
|
root.setBrightness(clampedValue, targetDevice);
|
||||||
root.setBrightness(newLevel)
|
if (targetDevice)
|
||||||
return "Brightness increased to " + newLevel + "%"
|
return "Brightness set to " + clampedValue + "% on " + targetDevice;
|
||||||
|
else
|
||||||
|
return "Brightness set to " + clampedValue + "%";
|
||||||
|
}
|
||||||
|
|
||||||
|
function increment(step: string, device: string) : string {
|
||||||
|
if (!root.brightnessAvailable)
|
||||||
|
return "Brightness control not available";
|
||||||
|
|
||||||
|
const currentLevel = root.brightnessLevel;
|
||||||
|
const stepValue = parseInt(step || "10");
|
||||||
|
const newLevel = Math.max(1, Math.min(100, currentLevel + stepValue));
|
||||||
|
const targetDevice = device || "";
|
||||||
|
root.setBrightness(newLevel, targetDevice);
|
||||||
|
if (targetDevice)
|
||||||
|
return "Brightness increased to " + newLevel + "% on " + targetDevice;
|
||||||
|
else
|
||||||
|
return "Brightness increased to " + newLevel + "%";
|
||||||
|
}
|
||||||
|
|
||||||
|
function decrement(step: string, device: string) : string {
|
||||||
|
if (!root.brightnessAvailable)
|
||||||
|
return "Brightness control not available";
|
||||||
|
|
||||||
|
const currentLevel = root.brightnessLevel;
|
||||||
|
const stepValue = parseInt(step || "10");
|
||||||
|
const newLevel = Math.max(1, Math.min(100, currentLevel - stepValue));
|
||||||
|
const targetDevice = device || "";
|
||||||
|
root.setBrightness(newLevel, targetDevice);
|
||||||
|
if (targetDevice)
|
||||||
|
return "Brightness decreased to " + newLevel + "% on " + targetDevice;
|
||||||
|
else
|
||||||
|
return "Brightness decreased to " + newLevel + "%";
|
||||||
|
}
|
||||||
|
|
||||||
|
function status() : string {
|
||||||
|
if (!root.brightnessAvailable)
|
||||||
|
return "Brightness control not available";
|
||||||
|
|
||||||
|
return "Device: " + root.currentDevice + " - Brightness: " + root.brightnessLevel + "%";
|
||||||
|
}
|
||||||
|
|
||||||
|
function list() : string {
|
||||||
|
if (!root.brightnessAvailable)
|
||||||
|
return "No brightness devices available";
|
||||||
|
|
||||||
|
let result = "Available devices:\n";
|
||||||
|
for (const device of root.devices) {
|
||||||
|
result += device.name + " (" + device.class + ")\n";
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
target: "brightness"
|
||||||
}
|
}
|
||||||
|
|
||||||
function decrement(step: string): string {
|
|
||||||
if (!root.brightnessAvailable) {
|
|
||||||
return "Brightness control not available"
|
|
||||||
}
|
|
||||||
|
|
||||||
const currentLevel = root.brightnessLevel
|
|
||||||
const newLevel = Math.max(1,
|
|
||||||
Math.min(100,
|
|
||||||
currentLevel - parseInt(step || "10")))
|
|
||||||
root.setBrightness(newLevel)
|
|
||||||
return "Brightness decreased to " + newLevel + "%"
|
|
||||||
}
|
|
||||||
|
|
||||||
function status(): string {
|
|
||||||
if (!root.brightnessAvailable) {
|
|
||||||
return "Brightness control not available"
|
|
||||||
}
|
|
||||||
|
|
||||||
return "Brightness: " + root.brightnessLevel + "% ("
|
|
||||||
+ (root.laptopBacklightAvailable ? "laptop backlight" : "DDC") + ")"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user