Fix brightness slider choppiness (#372)

* 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 <amirdahan24@gmail.com>
Co-authored-by: Erik Reider <35975961+ErikReider@users.noreply.github.com>
This commit is contained in:
System64
2024-03-07 20:44:15 +02:00
committed by GitHub
parent 7e4a8a1c5e
commit ee046a027e
2 changed files with 5 additions and 5 deletions

View File

@@ -52,7 +52,7 @@ namespace SwayNotificationCenter.Widgets {
slider.set_draw_value (false); slider.set_draw_value (false);
slider.set_round_digits (0); slider.set_round_digits (0);
slider.value_changed.connect (() => { 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 (); slider.tooltip_text = ((int) slider.get_value ()).to_string ();
}); });

View File

@@ -3,7 +3,7 @@ namespace SwayNotificationCenter.Widgets {
[DBus (name = "org.freedesktop.login1.Session")] [DBus (name = "org.freedesktop.login1.Session")]
interface Login1 : Object { 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; string name, uint32 brightness) throws GLib.Error;
} }
@@ -77,14 +77,14 @@ namespace SwayNotificationCenter.Widgets {
if (monitor != null) monitor.cancel (); if (monitor != null) monitor.cancel ();
} }
public void set_brightness (float percent) { public async void set_brightness (float percent) {
this.close (); this.close ();
try { try {
if (subsystem == "backlight") { if (subsystem == "backlight") {
int actual = calc_actual (percent); int actual = calc_actual (percent);
login1.set_brightness (subsystem, device, actual); login1.set_brightness.begin (subsystem, device, actual);
} else { } else {
login1.set_brightness (subsystem, device, (uint32) percent); login1.set_brightness.begin (subsystem, device, (uint32) percent);
} }
} catch (Error e) { } catch (Error e) {
error ("Error %s\n", e.message); error ("Error %s\n", e.message);