Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle sound confirmations in the wingpanel indicator #1816

Closed
wants to merge 1 commit into from
Closed
Changes from all 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
41 changes: 37 additions & 4 deletions src/MediaFeedback.vala
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@
//

namespace Gala {
[DBus (name = "io.elementary.wingpanel.sound")]
public interface WingpanelSound : GLib.Object {
public abstract void handle_osd () throws DBusError, IOError;
}

[DBus (name = "org.freedesktop.Notifications")]
interface DBusNotifications : GLib.Object {
public interface DBusNotifications : GLib.Object {
public abstract uint32 notify (string app_name, uint32 replaces_id, string app_icon, string summary,
string body, string[] actions, HashTable<string, Variant> hints, int32 expire_timeout) throws DBusError, IOError;
}
Expand All @@ -36,6 +41,7 @@ namespace Gala {

private static MediaFeedback? instance = null;
private static ThreadPool<Feedback>? pool = null;
private static WingpanelSound wingpanel_sound = null;

public static void init () {
if (instance == null)
Expand Down Expand Up @@ -66,13 +72,14 @@ namespace Gala {
}

try {
Bus.watch_name (BusType.SESSION, "org.freedesktop.Notifications", BusNameWatcherFlags.NONE, on_watch, on_unwatch);
Bus.watch_name (SESSION, "org.freedesktop.Notifications", NONE, on_notifications_watch, on_notifications_unwatch);
Bus.watch_name (SESSION, "io.elementary.wingpanel.sound", NONE, on_wingpanel_sound_watch, on_wingpanel_sound_unwatch);
} catch (IOError e) {
debug (e.message);
}
}

private void on_watch (DBusConnection conn) {
private void on_notifications_watch (DBusConnection conn) {
conn.get_proxy.begin<DBusNotifications> ("org.freedesktop.Notifications",
"/org/freedesktop/Notifications", DBusProxyFlags.NONE, null, (obj, res) => {
try {
Expand All @@ -84,11 +91,37 @@ namespace Gala {
});
}

private void on_unwatch (DBusConnection conn) {
private void on_wingpanel_sound_watch (DBusConnection conn) {
conn.get_proxy.begin<WingpanelSound> ("io.elementary.wingpanel.sound",
"/io/elementary/wingpanel/sound", DBusProxyFlags.NONE, null, (obj, res) => {
try {
wingpanel_sound = ((DBusConnection) obj).get_proxy.end<WingpanelSound> (res);
} catch (Error e) {
warning (e.message);
wingpanel_sound = null;
}
});
}

private void on_notifications_unwatch (DBusConnection conn) {
notifications = null;
}

private void on_wingpanel_sound_unwatch (DBusConnection conn) {
wingpanel_sound = null;
}

private void send_feedback (owned Feedback feedback) {
if (feedback.icon.contains ("audio") && wingpanel_sound != null) {
try {
wingpanel_sound.handle_osd ();
} catch (Error e) {
warning (e.message);
}

return;
}

if (notifications == null) {
return;
}
Expand Down