Skip to content

Commit

Permalink
Fix brightness slider choppiness (#372)
Browse files Browse the repository at this point in the history
* Fix brightness slider choppiness

Make setting the brightness function async to prevent stutter on some devices.

* Fix implicit .begin deprecation warning

---------

Co-authored-by: Amir Dahan <[email protected]>
Co-authored-by: Erik Reider <[email protected]>
  • Loading branch information
3 people authored Mar 7, 2024
1 parent 7e4a8a1 commit ee046a0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/controlCenter/widgets/backlight/backlight.vala
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace SwayNotificationCenter.Widgets {
slider.set_draw_value (false);
slider.set_round_digits (0);
slider.value_changed.connect (() => {
this.client.set_brightness ((float) slider.get_value ());
this.client.set_brightness.begin ((float) slider.get_value ());
slider.tooltip_text = ((int) slider.get_value ()).to_string ();
});

Expand Down
8 changes: 4 additions & 4 deletions src/controlCenter/widgets/backlight/backlightUtil.vala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace SwayNotificationCenter.Widgets {

[DBus (name = "org.freedesktop.login1.Session")]
interface Login1 : Object {
public abstract void set_brightness (string subsystem,
public abstract async void set_brightness (string subsystem,
string name, uint32 brightness) throws GLib.Error;
}

Expand Down Expand Up @@ -77,14 +77,14 @@ namespace SwayNotificationCenter.Widgets {
if (monitor != null) monitor.cancel ();
}

public void set_brightness (float percent) {
public async void set_brightness (float percent) {
this.close ();
try {
if (subsystem == "backlight") {
int actual = calc_actual (percent);
login1.set_brightness (subsystem, device, actual);
login1.set_brightness.begin (subsystem, device, actual);
} else {
login1.set_brightness (subsystem, device, (uint32) percent);
login1.set_brightness.begin (subsystem, device, (uint32) percent);
}
} catch (Error e) {
error ("Error %s\n", e.message);
Expand Down

0 comments on commit ee046a0

Please sign in to comment.