Skip to content
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bin/omarchy-brightness-display
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fi
# Drop overlapping brightness key events so concurrent invocations do not race.
# Hardware key repeat present on some devices can otherwise glitch OSD rendering.
exec {lock_fd}>"${XDG_RUNTIME_DIR:-/tmp}/omarchy-brightness-display.lock"
flock -n "$lock_fd" || exit 0
flock -n "$lock_fd" || exit 1

if use_apple_display; then
if (( no_osd )); then
Expand Down Expand Up @@ -154,7 +154,7 @@ else

# Set brightness of the display device and parse the new percentage directly
# from `-m` output rather than calling brightnessctl a second time.
set_out=$(brightnessctl -d "$device" -m set "$step" 2>/dev/null)
set_out=$(brightnessctl -d "$device" -m set "$step" 2>/dev/null) || exit 1

# Show the new brightness in OSD
if (( !no_osd )); then
Expand Down
2 changes: 1 addition & 1 deletion bin/omarchy-brightness-display-apple
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ fi

if ! sudo asdcontrol "$device" -- "$step" >/dev/null; then
retry_with_fresh_device
sudo asdcontrol "$device" -- "$step" >/dev/null
sudo asdcontrol "$device" -- "$step" >/dev/null || exit 1
fi

(( no_osd )) || omarchy-osd -i brightness -p "$(current_brightness "$device")"
6 changes: 1 addition & 5 deletions bin/omarchy-brightness-display-ddc
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,5 @@ fi
(( target > 100 )) && target=100
(( raw_target = (target * maximum + 50) / 100 ))

if ! ddcutil --bus "$bus" --skip-ddc-checks --noverify setvcp 10 "$raw_target" >/dev/null 2>&1; then
rm -f "$cache_file"
exit 1
fi

ddcutil --bus "$bus" --verify setvcp 10 "$raw_target" >/dev/null 2>&1 || exit 1
Comment thread
Murderlon marked this conversation as resolved.
Resolved
printf '%s\n' "$target"
10 changes: 9 additions & 1 deletion shell/Ui/PanelSlider.qml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ Item {
signal moved(real value)
signal released(real value)

function cancelDrag() {
if (!dragging) return
mouseArea.enabled = false
dragging = false
liveValue = value
Qt.callLater(function() { mouseArea.enabled = true })
}

// Right-click is a secondary action on the whole track — audio uses it to
// mute the channel the slider belongs to. Dragging stays left-button only.
signal rightClicked()
Expand Down Expand Up @@ -142,7 +150,7 @@ Item {
root.moved(next)
}
onReleased: function(mouse) {
if (mouse.button !== Qt.LeftButton) return
if (mouse.button !== Qt.LeftButton || !root.dragging) return
root.dragging = false
root.released(root.liveValue)
root.liveValue = root.value
Expand Down
75 changes: 75 additions & 0 deletions shell/plugins/panels/monitor/BrightnessController.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import QtQuick
import Quickshell
import Quickshell.Io
import "BrightnessModel.js" as BrightnessModel

Item {
id: root

property var state: BrightnessModel.initial()
readonly property int percent: state.percent
readonly property bool available: state.available
signal verified(int percent)

function readGeneration() {
return BrightnessModel.readGeneration(state)
}

function acceptRead(monitor, raw, generation) {
var previousEpoch = state.epoch
state = BrightnessModel.acceptRead(state, monitor, raw, generation)
if (state.epoch !== previousEpoch) debounce.stop()
}

function request(value, osd = false) {
debounce.stop()
state = BrightnessModel.request(state, value, osd)
startLatest()
}

function preview(value) {
state = BrightnessModel.request(state, value, false)
debounce.restart()
}

function startLatest() {
if (writeProc.running || state.active || !state.latest) return
debounce.stop()
state = BrightnessModel.start(state)
writeProc.request = state.active
writeProc.command = ["omarchy-brightness-display", "--no-osd", "--monitor", state.active.epoch.monitor, state.active.target + "%"]
writeProc.running = true
}

function finish(request, success) {
var result = BrightnessModel.finish(state, request, success)
if (result.state === state) return
state = result.state
if (result.verified !== null) verified(result.verified)
if (state.latest) Qt.callLater(startLatest)
}

Timer {
id: debounce
interval: 180
repeat: false
onTriggered: root.startLatest()
}

Process {
id: writeProc
property var request: null
stdout: StdioCollector { waitForEnd: true }
onExited: function(exitCode, exitStatus) {
root.finish(request, exitStatus === 0 && exitCode === 0)
}
onRunningChanged: {
if (running) return
// A failed start only changes running. Let a normal exit complete first.
var completedRequest = request
Qt.callLater(function() {
if (!writeProc.running) root.finish(completedRequest, false)
})
}
}
}
88 changes: 88 additions & 0 deletions shell/plugins/panels/monitor/BrightnessModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
function initial() {
return {
epoch: { monitor: "" },
percent: 0,
confirmed: 0,
available: false,
revision: 0,
active: null,
latest: null
}
}

function copy(state, changes) {
return Object.assign({}, state, changes)
}

function readGeneration(state) {
return state.active || state.latest ? -1 : state.revision
}

function acceptRead(state, monitor, raw, generation) {
var changedMonitor = monitor !== state.epoch.monitor
if (!changedMonitor && (state.active || state.latest || generation !== state.revision)) return state

var available = raw !== "unavailable" && raw !== ""
var parsed = parseInt(raw, 10)
var percent = available && isFinite(parsed) ? Math.max(0, Math.min(100, parsed)) : 0
return copy(state, {
// A new identity also invalidates completions after switching away and back.
epoch: changedMonitor ? { monitor: monitor } : state.epoch,
percent: percent,
confirmed: available ? percent : changedMonitor ? 0 : state.confirmed,
available: available,
revision: state.revision + 1,
latest: null
})
}

function request(state, value, osd) {
var number = Number(value)
var target = isFinite(number) ? Math.max(1, Math.min(100, Math.round(number))) : 1
return copy(state, {
percent: target,
revision: state.revision + 1,
latest: {
epoch: state.epoch,
target: target,
osd: !!osd || !!(state.latest && state.latest.osd)
|| !!(state.active && state.active.epoch === state.epoch && state.active.osd)
}
})
}

function start(state) {
if (state.active || !state.latest) return state
return copy(state, { active: state.latest, latest: null })
}

function finish(state, request, success) {
if (!request || state.active !== request) return { state: state, verified: null }

var current = request.epoch === state.epoch
var latest = state.latest
if (latest && latest.epoch === request.epoch && latest.target === request.target) latest = null
var confirmed = current && success ? request.target : state.confirmed
return {
state: copy(state, {
active: null,
latest: latest,
confirmed: confirmed,
percent: current && !latest && !success ? confirmed : state.percent,
revision: state.revision + 1
}),
verified: current && success && !latest && (request.osd || (state.latest && state.latest.osd))
? request.target : null
}
}

if (typeof module !== "undefined") {
module.exports = {
initial: initial,
readGeneration: readGeneration,
acceptRead: acceptRead,
request: request,
start: start,
finish: finish
}
}
7 changes: 0 additions & 7 deletions shell/plugins/panels/monitor/Model.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
function clampBrightness(value) {
var n = Number(value)
if (!isFinite(n)) return 1
return Math.max(1, Math.min(100, Math.round(n)))
}

function normalizeScale(scale) {
var n = parseFloat(String(scale || ""))
if (!isFinite(n)) return ""
Expand Down Expand Up @@ -366,7 +360,6 @@ function parseDisplays(raw) {

if (typeof module !== "undefined") {
module.exports = {
clampBrightness: clampBrightness,
normalizeScale: normalizeScale,
cleanScale: cleanScale,
matchingScaleIndex: matchingScaleIndex,
Expand Down
Loading