backlight: add OSD notification on brightness change

parent 5d2211c4
using GLib; using GLib;
namespace XimperShellNotificationCenter.Widgets { namespace XimperShellNotificationCenter.Widgets {
[DBus (name = "ru.ximperlinux.shell.OSD")]
interface OsdService : Object {
public abstract void show_brightness_osd (double percent) throws DBusError, IOError;
}
[GtkTemplate (ui = "/ru/ximperlinux/shell/NotificationCenter/ui/widgets/backlight.ui")] [GtkTemplate (ui = "/ru/ximperlinux/shell/NotificationCenter/ui/widgets/backlight.ui")]
public class Backlight : BaseWidget { public class Backlight : BaseWidget {
public override string widget_name { public override string widget_name {
...@@ -39,6 +45,7 @@ namespace XimperShellNotificationCenter.Widgets { ...@@ -39,6 +45,7 @@ namespace XimperShellNotificationCenter.Widgets {
unowned Gtk.Box single_source_box; unowned Gtk.Box single_source_box;
int min_brightness = 0; int min_brightness = 0;
OsdService? osd_proxy = null;
public Backlight (string suffix) { public Backlight (string suffix) {
base (suffix); base (suffix);
...@@ -48,6 +55,14 @@ namespace XimperShellNotificationCenter.Widgets { ...@@ -48,6 +55,14 @@ namespace XimperShellNotificationCenter.Widgets {
min_brightness = int.max (0, get_prop<int> (config, "min")); min_brightness = int.max (0, get_prop<int> (config, "min"));
} }
try {
osd_proxy = Bus.get_proxy_sync (BusType.SESSION,
"ru.ximperlinux.shell.OSD",
"/ru/ximperlinux/shell/OSD");
} catch (Error e) {
debug ("OSD service not available: %s", e.message);
}
detect_sources (); detect_sources ();
int total = display_sources.length + kbd_sources.length; int total = display_sources.length + kbd_sources.length;
...@@ -203,6 +218,7 @@ namespace XimperShellNotificationCenter.Widgets { ...@@ -203,6 +218,7 @@ namespace XimperShellNotificationCenter.Widgets {
(float) scl.get_value ()); (float) scl.get_value ());
scl.tooltip_text = scl.tooltip_text =
((int) scl.get_value ()).to_string (); ((int) scl.get_value ()).to_string ();
notify_osd (scl.get_value ());
}); });
} }
#if HAVE_DDC #if HAVE_DDC
...@@ -221,6 +237,7 @@ namespace XimperShellNotificationCenter.Widgets { ...@@ -221,6 +237,7 @@ namespace XimperShellNotificationCenter.Widgets {
(float) scl.get_value ()); (float) scl.get_value ());
scl.tooltip_text = scl.tooltip_text =
((int) scl.get_value ()).to_string (); ((int) scl.get_value ()).to_string ();
notify_osd (scl.get_value ());
}); });
} }
#endif #endif
...@@ -295,6 +312,15 @@ namespace XimperShellNotificationCenter.Widgets { ...@@ -295,6 +312,15 @@ namespace XimperShellNotificationCenter.Widgets {
} }
} }
private void notify_osd (double percent) {
if (osd_proxy == null) return;
try {
osd_proxy.show_brightness_osd (percent);
} catch (Error e) {
debug ("OSD call failed: %s", e.message);
}
}
public override void on_cc_visibility_change (bool val) { public override void on_cc_visibility_change (bool val) {
for (int i = 0; i < display_sources.length; i++) { for (int i = 0; i < display_sources.length; i++) {
if (display_sources[i].sysfs != null) { if (display_sources[i].sysfs != null) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment