Skip to content

Commit 36db642

Browse files
committed
Fix bogus brightness changes when using dbus mode
Changing brightness value via DBUS is async and does not instantly result in actually changing the value in the underlying file. This can result in changing the value via DBUS, and then still reading the unchanged value from the file, and thinking that it's a new user value. As such, return cached "desired" value until the file was actually written after changing it via DBUS.
1 parent 4111eb8 commit 36db642

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/brightness/backlight.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub struct Backlight {
2121
current: Option<u64>,
2222
dbus: Option<Dbus>,
2323
has_write_permission: bool,
24+
pending_dbus_write: bool,
2425
}
2526

2627
impl Backlight {
@@ -89,6 +90,7 @@ impl Backlight {
8990
current: None,
9091
dbus,
9192
has_write_permission,
93+
pending_dbus_write: false,
9294
})
9395
}
9496
}
@@ -105,10 +107,11 @@ impl super::Brightness for Backlight {
105107
match (self.inotify.read_events(&mut buffer), self.current) {
106108
(_, None) => update(self),
107109
(Ok(mut events), Some(cached)) => {
108-
if events.next().is_some() {
109-
update(self)
110-
} else {
110+
if self.pending_dbus_write || events.next().is_none() {
111+
self.pending_dbus_write = false;
111112
Ok(cached)
113+
} else {
114+
update(self)
112115
}
113116
}
114117
(Err(err), Some(cached)) if err.kind() == ErrorKind::WouldBlock => Ok(cached),
@@ -125,6 +128,7 @@ impl super::Brightness for Backlight {
125128
dbus.connection
126129
.send(dbus.message.duplicate()?.append1(value as u32))
127130
.map_err(|_| "Unable to send brightness change message via dbus")?;
131+
self.pending_dbus_write = true;
128132
} else {
129133
Err(std::io::Error::from(ErrorKind::PermissionDenied))?
130134
}

0 commit comments

Comments
 (0)