From 8e9a6e13e8f5cececc42e7d2b59beb75a0112739 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Mon, 24 Feb 2014 20:55:53 -0500 Subject: First pass at volume sharing --- src/volume-control.vala | 106 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 105 insertions(+), 1 deletion(-) (limited to 'src/volume-control.vala') diff --git a/src/volume-control.vala b/src/volume-control.vala index e994922..a735057 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -34,6 +34,10 @@ public class VolumeControl : Object private double _volume = 0.0; private double _mic_volume = 0.0; + private DBusProxy _user_proxy; + private DBusProxy _greeter_proxy; + private bool _greeter_mode = false; + public signal void volume_changed (double v); public signal void mic_volume_changed (double v); @@ -48,6 +52,10 @@ public class VolumeControl : Object if (loop == null) loop = new PulseAudio.GLibMainLoop (); + _greeter_mode = Environment.get_variable ("XDG_SESSION_CLASS") == "greeter"; + if (_greeter_mode) + watch_greeter_user.begin (); + this.reconnect_to_pulse (); } @@ -101,6 +109,7 @@ public class VolumeControl : Object { _volume = volume_to_double (i.volume.values[0]); volume_changed (_volume); + sync_volume_to_accountsservice.begin (); } } @@ -250,8 +259,10 @@ public class VolumeControl : Object private void set_volume_success_cb (Context c, int success) { - if ((bool)success) + if ((bool)success) { volume_changed (_volume); + sync_volume_to_accountsservice.begin (); + } } private void sink_info_set_volume_cb (Context c, SinkInfo? i, int eol) @@ -315,4 +326,97 @@ public class VolumeControl : Object { return _mic_volume; } + + private async DBusProxy? get_user_proxy (string? username = null) + { + if (username == null) + username = Environment.get_variable ("USER"); + if (username == "" || username == null) + return null; + + DBusProxy accounts_proxy; + try { + accounts_proxy = yield DBusProxy.create_for_bus (BusType.SYSTEM, DBusProxyFlags.DO_NOT_LOAD_PROPERTIES | DBusProxyFlags.DO_NOT_CONNECT_SIGNALS, null, "org.freedesktop.Accounts", "/org/freedesktop/Accounts", "org.freedesktop.Accounts"); + } catch (GLib.Error e) { + warning ("unable to get greeter proxy: %s", e.message); + return null; + } + + try { + var user_path_variant = yield accounts_proxy.call ("FindUserByName", new Variant ("(s)", username), DBusCallFlags.NONE, -1); + string user_path; + user_path_variant.get ("(&s)", out user_path); + return yield DBusProxy.create_for_bus (BusType.SYSTEM, DBusProxyFlags.NONE, null, "org.freedesktop.Accounts", user_path, "org.freedesktop.DBus.Properties"); + } catch (GLib.Error e) { + warning ("unable to find Accounts path for user %s: %s", username, e.message); + return null; + } + } + + private async void sync_volume_from_accountsservice (string? username = null) + { + if (!_greeter_mode) + return; // skip sync if we are not in greeter + + if (username == null) { + try { + var username_variant = yield _greeter_proxy.call ("GetActiveEntry", null, DBusCallFlags.NONE, -1); + username = username_variant.get_string (); + if (username == "" || username == null) + return; + } catch (GLib.Error e) { + warning ("unable to find Accounts path for user %s: %s", username, e.message); + return; + } + } + + var user_proxy = yield get_user_proxy (username); + if (user_proxy == null) + return; + + try { + var volume_outer_variant = yield user_proxy.call ("Get", new Variant ("(ss)", "com.ubuntu.touch.AccountsService.Sound", "Volume"), DBusCallFlags.NONE, -1); + Variant volume_variant; + volume_outer_variant.get ("(v)", out volume_variant); + set_volume (volume_variant.get_double ()); + } catch (GLib.Error e) { + warning ("unable to sync volume from AccountsService: %s", e.message); + } + } + + private void greeter_user_changed (string username) + { + sync_volume_from_accountsservice.begin (username); + } + + private async void watch_greeter_user () + { + try { + _greeter_proxy = yield DBusProxy.create_for_bus (BusType.SESSION, DBusProxyFlags.NONE, null, "com.canonical.UnityGreeter", "/list", "com.canonical.UnityGreeter.List"); + } catch (GLib.Error e) { + warning ("unable to get greeter proxy: %s", e.message); + return; + } + + _greeter_proxy.connect ("EntrySelected", greeter_user_changed); + yield sync_volume_from_accountsservice (); + } + + private async void sync_volume_to_accountsservice () + { + if (_greeter_mode) + return; // skip sync if we are in greeter + + if (_user_proxy == null) { + _user_proxy = yield get_user_proxy (); + if (_user_proxy == null) + return; + } + + try { + yield _user_proxy.call ("Set", new Variant ("(ssv)", "com.ubuntu.touch.AccountsService.Sound", "Volume", new Variant ("d", _volume)), DBusCallFlags.NONE, -1); + } catch (GLib.Error e) { + warning ("unable to sync volume to AccountsService: %s", e.message); + } + } } -- cgit v1.2.3 From f8615b9d75069b11cda2c3c2356c59526f978dd4 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Mon, 3 Mar 2014 11:23:29 -0500 Subject: Fix a typo --- src/volume-control.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/volume-control.vala') diff --git a/src/volume-control.vala b/src/volume-control.vala index a735057..211bf0c 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -345,7 +345,7 @@ public class VolumeControl : Object try { var user_path_variant = yield accounts_proxy.call ("FindUserByName", new Variant ("(s)", username), DBusCallFlags.NONE, -1); string user_path; - user_path_variant.get ("(&s)", out user_path); + user_path_variant.get ("(o)", out user_path); return yield DBusProxy.create_for_bus (BusType.SYSTEM, DBusProxyFlags.NONE, null, "org.freedesktop.Accounts", user_path, "org.freedesktop.DBus.Properties"); } catch (GLib.Error e) { warning ("unable to find Accounts path for user %s: %s", username, e.message); -- cgit v1.2.3 From f164f96ee50fe7669510cc59e6e119cc4c2e0f70 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Mon, 3 Mar 2014 14:39:49 -0500 Subject: Write to accountsservice even when in greeter mode; drop greeter mode in general, both sessions should act similarly usually --- src/volume-control.vala | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'src/volume-control.vala') diff --git a/src/volume-control.vala b/src/volume-control.vala index 211bf0c..23404db 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -1,4 +1,5 @@ /* + * -*- Mode:Vala; indent-tabs-mode:t; tab-width:4; encoding:utf8 -*- * Copyright 2013 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify @@ -36,7 +37,6 @@ public class VolumeControl : Object private DBusProxy _user_proxy; private DBusProxy _greeter_proxy; - private bool _greeter_mode = false; public signal void volume_changed (double v); public signal void mic_volume_changed (double v); @@ -52,9 +52,7 @@ public class VolumeControl : Object if (loop == null) loop = new PulseAudio.GLibMainLoop (); - _greeter_mode = Environment.get_variable ("XDG_SESSION_CLASS") == "greeter"; - if (_greeter_mode) - watch_greeter_user.begin (); + watch_greeter_user.begin (); this.reconnect_to_pulse (); } @@ -355,9 +353,6 @@ public class VolumeControl : Object private async void sync_volume_from_accountsservice (string? username = null) { - if (!_greeter_mode) - return; // skip sync if we are not in greeter - if (username == null) { try { var username_variant = yield _greeter_proxy.call ("GetActiveEntry", null, DBusCallFlags.NONE, -1); @@ -378,7 +373,9 @@ public class VolumeControl : Object var volume_outer_variant = yield user_proxy.call ("Get", new Variant ("(ss)", "com.ubuntu.touch.AccountsService.Sound", "Volume"), DBusCallFlags.NONE, -1); Variant volume_variant; volume_outer_variant.get ("(v)", out volume_variant); - set_volume (volume_variant.get_double ()); + var volume = volume_variant.get_double (); + if (volume >= 0) + set_volume (volume); } catch (GLib.Error e) { warning ("unable to sync volume from AccountsService: %s", e.message); } @@ -398,15 +395,14 @@ public class VolumeControl : Object return; } - _greeter_proxy.connect ("EntrySelected", greeter_user_changed); - yield sync_volume_from_accountsservice (); + if (_greeter_proxy.get_name_owner () != null) { + _greeter_proxy.connect ("EntrySelected", greeter_user_changed); + yield sync_volume_from_accountsservice (); + } } private async void sync_volume_to_accountsservice () { - if (_greeter_mode) - return; // skip sync if we are in greeter - if (_user_proxy == null) { _user_proxy = yield get_user_proxy (); if (_user_proxy == null) -- cgit v1.2.3 From 9db2149b146ddbf66aacb29d88ba1d7c1b58148f Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Mon, 3 Mar 2014 15:20:05 -0500 Subject: Always use class's shared user proxy --- src/volume-control.vala | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'src/volume-control.vala') diff --git a/src/volume-control.vala b/src/volume-control.vala index 23404db..d48d2af 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -107,7 +107,6 @@ public class VolumeControl : Object { _volume = volume_to_double (i.volume.values[0]); volume_changed (_volume); - sync_volume_to_accountsservice.begin (); } } @@ -365,12 +364,12 @@ public class VolumeControl : Object } } - var user_proxy = yield get_user_proxy (username); - if (user_proxy == null) + _user_proxy = yield get_user_proxy (username); + if (_user_proxy == null) return; try { - var volume_outer_variant = yield user_proxy.call ("Get", new Variant ("(ss)", "com.ubuntu.touch.AccountsService.Sound", "Volume"), DBusCallFlags.NONE, -1); + var volume_outer_variant = yield _user_proxy.call ("Get", new Variant ("(ss)", "com.ubuntu.touch.AccountsService.Sound", "Volume"), DBusCallFlags.NONE, -1); Variant volume_variant; volume_outer_variant.get ("(v)", out volume_variant); var volume = volume_variant.get_double (); @@ -398,16 +397,16 @@ public class VolumeControl : Object if (_greeter_proxy.get_name_owner () != null) { _greeter_proxy.connect ("EntrySelected", greeter_user_changed); yield sync_volume_from_accountsservice (); + } else { + // We are in a user session. We just need our own proxy + _user_proxy = yield get_user_proxy (Environment.get_variable ("USER")); } } private async void sync_volume_to_accountsservice () { - if (_user_proxy == null) { - _user_proxy = yield get_user_proxy (); - if (_user_proxy == null) - return; - } + if (_user_proxy == null) + return; try { yield _user_proxy.call ("Set", new Variant ("(ssv)", "com.ubuntu.touch.AccountsService.Sound", "Volume", new Variant ("d", _volume)), DBusCallFlags.NONE, -1); -- cgit v1.2.3 From 7be9787340f18f59820803dd70899a134499e781 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Mon, 3 Mar 2014 16:28:45 -0500 Subject: Listen for changes to Volume --- src/volume-control.vala | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) (limited to 'src/volume-control.vala') diff --git a/src/volume-control.vala b/src/volume-control.vala index d48d2af..83c3b56 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -256,10 +256,8 @@ public class VolumeControl : Object private void set_volume_success_cb (Context c, int success) { - if ((bool)success) { + if ((bool)success) volume_changed (_volume); - sync_volume_to_accountsservice.begin (); - } } private void sink_info_set_volume_cb (Context c, SinkInfo? i, int eol) @@ -282,13 +280,21 @@ public class VolumeControl : Object context.get_sink_info_by_name (i.default_sink_name, sink_info_set_volume_cb); } - public void set_volume (double volume) + bool set_volume_internal (double volume) { - return_if_fail (context.get_state () == Context.State.READY); + return_val_if_fail (context.get_state () == Context.State.READY, false); _volume = volume; context.get_server_info (server_info_cb_for_set_volume); + + return true; + } + + public void set_volume (double volume) + { + if (set_volume_internal (volume)) + sync_volume_to_accountsservice.begin (); } void set_mic_volume_success_cb (Context c, int success) @@ -324,13 +330,8 @@ public class VolumeControl : Object return _mic_volume; } - private async DBusProxy? get_user_proxy (string? username = null) + private async DBusProxy? get_user_proxy (string username) { - if (username == null) - username = Environment.get_variable ("USER"); - if (username == "" || username == null) - return null; - DBusProxy accounts_proxy; try { accounts_proxy = yield DBusProxy.create_for_bus (BusType.SYSTEM, DBusProxyFlags.DO_NOT_LOAD_PROPERTIES | DBusProxyFlags.DO_NOT_CONNECT_SIGNALS, null, "org.freedesktop.Accounts", "/org/freedesktop/Accounts", "org.freedesktop.Accounts"); @@ -343,19 +344,29 @@ public class VolumeControl : Object var user_path_variant = yield accounts_proxy.call ("FindUserByName", new Variant ("(s)", username), DBusCallFlags.NONE, -1); string user_path; user_path_variant.get ("(o)", out user_path); - return yield DBusProxy.create_for_bus (BusType.SYSTEM, DBusProxyFlags.NONE, null, "org.freedesktop.Accounts", user_path, "org.freedesktop.DBus.Properties"); + return yield DBusProxy.create_for_bus (BusType.SYSTEM, DBusProxyFlags.GET_INVALIDATED_PROPERTIES, null, "org.freedesktop.Accounts", user_path, "org.freedesktop.DBus.Properties"); } catch (GLib.Error e) { warning ("unable to find Accounts path for user %s: %s", username, e.message); return null; } } + private void accountsservice_props_changed_cb (DBusProxy proxy, Variant changed_properties, string[] invalidated_properties) + { + Variant volume_variant = changed_properties.lookup_value ("Volume", new VariantType ("d")); + if (volume_variant != null) { + var volume = volume_variant.get_double (); + if (volume >= 0) + set_volume_internal (volume); + } + } + private async void sync_volume_from_accountsservice (string? username = null) { if (username == null) { try { var username_variant = yield _greeter_proxy.call ("GetActiveEntry", null, DBusCallFlags.NONE, -1); - username = username_variant.get_string (); + username_variant.get ("(s)", out username); if (username == "" || username == null) return; } catch (GLib.Error e) { @@ -368,16 +379,20 @@ public class VolumeControl : Object if (_user_proxy == null) return; + // Get current volume try { var volume_outer_variant = yield _user_proxy.call ("Get", new Variant ("(ss)", "com.ubuntu.touch.AccountsService.Sound", "Volume"), DBusCallFlags.NONE, -1); Variant volume_variant; volume_outer_variant.get ("(v)", out volume_variant); var volume = volume_variant.get_double (); if (volume >= 0) - set_volume (volume); + set_volume_internal (volume); } catch (GLib.Error e) { warning ("unable to sync volume from AccountsService: %s", e.message); } + + // Listen for future changes + _user_proxy.g_properties_changed.connect (accountsservice_props_changed_cb); } private void greeter_user_changed (string username) @@ -399,7 +414,9 @@ public class VolumeControl : Object yield sync_volume_from_accountsservice (); } else { // We are in a user session. We just need our own proxy - _user_proxy = yield get_user_proxy (Environment.get_variable ("USER")); + var username = Environment.get_variable ("USER"); + if (username != "" && username != null) + yield sync_volume_from_accountsservice (username); } } -- cgit v1.2.3 From abdeca516d52dbb80b725173ab99f08d31c23844 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Mon, 3 Mar 2014 17:34:19 -0500 Subject: Support proxying mute settings too; allow cancelling previous Set calls --- src/volume-control.vala | 106 +++++++++++++++++++++++++++++------------------- 1 file changed, 64 insertions(+), 42 deletions(-) (limited to 'src/volume-control.vala') diff --git a/src/volume-control.vala b/src/volume-control.vala index 83c3b56..4135d5f 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -37,6 +37,8 @@ public class VolumeControl : Object private DBusProxy _user_proxy; private DBusProxy _greeter_proxy; + private Cancellable _mute_cancellable; + private Cancellable _volume_cancellable; public signal void volume_changed (double v); public signal void mic_volume_changed (double v); @@ -52,7 +54,9 @@ public class VolumeControl : Object if (loop == null) loop = new PulseAudio.GLibMainLoop (); - watch_greeter_user.begin (); + _mute_cancellable = new Cancellable (); + _volume_cancellable = new Cancellable (); + setup_accountsservice.begin (); this.reconnect_to_pulse (); } @@ -218,14 +222,22 @@ public class VolumeControl : Object } /* Mute operations */ - public void set_mute (bool mute) + bool set_mute_internal (bool mute) { - return_if_fail (context.get_state () == Context.State.READY); + return_val_if_fail (context.get_state () == Context.State.READY, false); if (mute) context.get_sink_info_list (sink_info_list_callback_set_mute); else context.get_sink_info_list (sink_info_list_callback_unset_mute); + + return true; + } + + public void set_mute (bool mute) + { + if (set_mute_internal (mute)) + sync_mute_to_accountsservice.begin (); } public void toggle_mute () @@ -330,27 +342,7 @@ public class VolumeControl : Object return _mic_volume; } - private async DBusProxy? get_user_proxy (string username) - { - DBusProxy accounts_proxy; - try { - accounts_proxy = yield DBusProxy.create_for_bus (BusType.SYSTEM, DBusProxyFlags.DO_NOT_LOAD_PROPERTIES | DBusProxyFlags.DO_NOT_CONNECT_SIGNALS, null, "org.freedesktop.Accounts", "/org/freedesktop/Accounts", "org.freedesktop.Accounts"); - } catch (GLib.Error e) { - warning ("unable to get greeter proxy: %s", e.message); - return null; - } - - try { - var user_path_variant = yield accounts_proxy.call ("FindUserByName", new Variant ("(s)", username), DBusCallFlags.NONE, -1); - string user_path; - user_path_variant.get ("(o)", out user_path); - return yield DBusProxy.create_for_bus (BusType.SYSTEM, DBusProxyFlags.GET_INVALIDATED_PROPERTIES, null, "org.freedesktop.Accounts", user_path, "org.freedesktop.DBus.Properties"); - } catch (GLib.Error e) { - warning ("unable to find Accounts path for user %s: %s", username, e.message); - return null; - } - } - + /* accountsservice operations */ private void accountsservice_props_changed_cb (DBusProxy proxy, Variant changed_properties, string[] invalidated_properties) { Variant volume_variant = changed_properties.lookup_value ("Volume", new VariantType ("d")); @@ -359,10 +351,17 @@ public class VolumeControl : Object if (volume >= 0) set_volume_internal (volume); } + + Variant mute_variant = changed_properties.lookup_value ("Mute", new VariantType ("b")); + if (mute_variant != null) + set_mute_internal (mute_variant.get_boolean ()); } - private async void sync_volume_from_accountsservice (string? username = null) + private async void setup_user_proxy (string? username = null) { + _user_proxy = null; + + // Look up currently selected greeter user, if asked if (username == null) { try { var username_variant = yield _greeter_proxy.call ("GetActiveEntry", null, DBusCallFlags.NONE, -1); @@ -375,32 +374,36 @@ public class VolumeControl : Object } } - _user_proxy = yield get_user_proxy (username); - if (_user_proxy == null) + // Get master AccountsService object + DBusProxy accounts_proxy; + try { + accounts_proxy = yield DBusProxy.create_for_bus (BusType.SYSTEM, DBusProxyFlags.DO_NOT_LOAD_PROPERTIES | DBusProxyFlags.DO_NOT_CONNECT_SIGNALS, null, "org.freedesktop.Accounts", "/org/freedesktop/Accounts", "org.freedesktop.Accounts"); + } catch (GLib.Error e) { + warning ("unable to get greeter proxy: %s", e.message); return; + } - // Get current volume + // Find user's AccountsService object try { - var volume_outer_variant = yield _user_proxy.call ("Get", new Variant ("(ss)", "com.ubuntu.touch.AccountsService.Sound", "Volume"), DBusCallFlags.NONE, -1); - Variant volume_variant; - volume_outer_variant.get ("(v)", out volume_variant); - var volume = volume_variant.get_double (); - if (volume >= 0) - set_volume_internal (volume); + var user_path_variant = yield accounts_proxy.call ("FindUserByName", new Variant ("(s)", username), DBusCallFlags.NONE, -1); + string user_path; + user_path_variant.get ("(o)", out user_path); + _user_proxy = yield DBusProxy.create_for_bus (BusType.SYSTEM, DBusProxyFlags.GET_INVALIDATED_PROPERTIES, null, "org.freedesktop.Accounts", user_path, "com.ubuntu.touch.AccountsService.Sound"); } catch (GLib.Error e) { - warning ("unable to sync volume from AccountsService: %s", e.message); + warning ("unable to find Accounts path for user %s: %s", username, e.message); + return; } - // Listen for future changes + // Listen for property changes, this will get current volume (since getting proxy loads properties) _user_proxy.g_properties_changed.connect (accountsservice_props_changed_cb); } private void greeter_user_changed (string username) { - sync_volume_from_accountsservice.begin (username); + setup_user_proxy.begin (username); } - private async void watch_greeter_user () + private async void setup_accountsservice () { try { _greeter_proxy = yield DBusProxy.create_for_bus (BusType.SESSION, DBusProxyFlags.NONE, null, "com.canonical.UnityGreeter", "/list", "com.canonical.UnityGreeter.List"); @@ -411,12 +414,28 @@ public class VolumeControl : Object if (_greeter_proxy.get_name_owner () != null) { _greeter_proxy.connect ("EntrySelected", greeter_user_changed); - yield sync_volume_from_accountsservice (); + yield setup_user_proxy (); } else { // We are in a user session. We just need our own proxy var username = Environment.get_variable ("USER"); - if (username != "" && username != null) - yield sync_volume_from_accountsservice (username); + if (username != "" && username != null) { + yield setup_user_proxy (username); + } + } + } + + private async void sync_mute_to_accountsservice () + { + if (_user_proxy == null) + return; + + _mute_cancellable.cancel (); + _mute_cancellable.reset (); + + try { + yield _user_proxy.get_connection ().call (_user_proxy.get_name (), _user_proxy.get_object_path (), "org.freedesktop.DBus.Properties", "Set", new Variant ("(ssv)", _user_proxy.get_interface_name (), "Mute", new Variant ("b", _mute)), null, DBusCallFlags.NONE, -1, _mute_cancellable); + } catch (GLib.Error e) { + warning ("unable to sync mute to AccountsService: %s", e.message); } } @@ -425,8 +444,11 @@ public class VolumeControl : Object if (_user_proxy == null) return; + _volume_cancellable.cancel (); + _volume_cancellable.reset (); + try { - yield _user_proxy.call ("Set", new Variant ("(ssv)", "com.ubuntu.touch.AccountsService.Sound", "Volume", new Variant ("d", _volume)), DBusCallFlags.NONE, -1); + yield _user_proxy.get_connection ().call (_user_proxy.get_name (), _user_proxy.get_object_path (), "org.freedesktop.DBus.Properties", "Set", new Variant ("(ssv)", _user_proxy.get_interface_name (), "Volume", new Variant ("d", _volume)), null, DBusCallFlags.NONE, -1, _volume_cancellable); } catch (GLib.Error e) { warning ("unable to sync volume to AccountsService: %s", e.message); } -- cgit v1.2.3 From 882dcd9193224c8df467a6b95283d5e3f61d1841 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Mon, 3 Mar 2014 17:58:23 -0500 Subject: Fix Mute/Muted typo; only sync to AS if value changed --- src/volume-control.vala | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'src/volume-control.vala') diff --git a/src/volume-control.vala b/src/volume-control.vala index 4135d5f..cb81f08 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -226,12 +226,15 @@ public class VolumeControl : Object { return_val_if_fail (context.get_state () == Context.State.READY, false); - if (mute) - context.get_sink_info_list (sink_info_list_callback_set_mute); - else - context.get_sink_info_list (sink_info_list_callback_unset_mute); - - return true; + if (_mute != mute) { + if (mute) + context.get_sink_info_list (sink_info_list_callback_set_mute); + else + context.get_sink_info_list (sink_info_list_callback_unset_mute); + return true; + } else { + return false; + } } public void set_mute (bool mute) @@ -296,11 +299,13 @@ public class VolumeControl : Object { return_val_if_fail (context.get_state () == Context.State.READY, false); - _volume = volume; - - context.get_server_info (server_info_cb_for_set_volume); - - return true; + if (_volume == volume) { + _volume = volume; + context.get_server_info (server_info_cb_for_set_volume); + return true; + } else { + return false; + } } public void set_volume (double volume) @@ -352,9 +357,11 @@ public class VolumeControl : Object set_volume_internal (volume); } - Variant mute_variant = changed_properties.lookup_value ("Mute", new VariantType ("b")); - if (mute_variant != null) - set_mute_internal (mute_variant.get_boolean ()); + Variant mute_variant = changed_properties.lookup_value ("Muted", new VariantType ("b")); + if (mute_variant != null) { + var mute = mute_variant.get_boolean (); + set_mute_internal (mute); + } } private async void setup_user_proxy (string? username = null) @@ -433,7 +440,7 @@ public class VolumeControl : Object _mute_cancellable.reset (); try { - yield _user_proxy.get_connection ().call (_user_proxy.get_name (), _user_proxy.get_object_path (), "org.freedesktop.DBus.Properties", "Set", new Variant ("(ssv)", _user_proxy.get_interface_name (), "Mute", new Variant ("b", _mute)), null, DBusCallFlags.NONE, -1, _mute_cancellable); + yield _user_proxy.get_connection ().call (_user_proxy.get_name (), _user_proxy.get_object_path (), "org.freedesktop.DBus.Properties", "Set", new Variant ("(ssv)", _user_proxy.get_interface_name (), "Muted", new Variant ("b", _mute)), null, DBusCallFlags.NONE, -1, _mute_cancellable); } catch (GLib.Error e) { warning ("unable to sync mute to AccountsService: %s", e.message); } -- cgit v1.2.3 From 0b3b6c5d2e66b5372df6a34ee2beb995e5c697e7 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Mon, 3 Mar 2014 18:22:03 -0500 Subject: Fix typo --- src/volume-control.vala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/volume-control.vala') diff --git a/src/volume-control.vala b/src/volume-control.vala index cb81f08..b9c6399 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -299,7 +299,7 @@ public class VolumeControl : Object { return_val_if_fail (context.get_state () == Context.State.READY, false); - if (_volume == volume) { + if (_volume != volume) { _volume = volume; context.get_server_info (server_info_cb_for_set_volume); return true; @@ -347,7 +347,7 @@ public class VolumeControl : Object return _mic_volume; } - /* accountsservice operations */ + /* AccountsService operations */ private void accountsservice_props_changed_cb (DBusProxy proxy, Variant changed_properties, string[] invalidated_properties) { Variant volume_variant = changed_properties.lookup_value ("Volume", new VariantType ("d")); -- cgit v1.2.3 From 754ce6a412d782a24ad763a481af412a615ad951 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Mon, 3 Mar 2014 19:00:30 -0500 Subject: Set AS with new values --- src/volume-control.vala | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/volume-control.vala') diff --git a/src/volume-control.vala b/src/volume-control.vala index b9c6399..f83d29d 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -240,7 +240,7 @@ public class VolumeControl : Object public void set_mute (bool mute) { if (set_mute_internal (mute)) - sync_mute_to_accountsservice.begin (); + sync_mute_to_accountsservice.begin (mute); } public void toggle_mute () @@ -311,7 +311,7 @@ public class VolumeControl : Object public void set_volume (double volume) { if (set_volume_internal (volume)) - sync_volume_to_accountsservice.begin (); + sync_volume_to_accountsservice.begin (volume); } void set_mic_volume_success_cb (Context c, int success) @@ -431,7 +431,7 @@ public class VolumeControl : Object } } - private async void sync_mute_to_accountsservice () + private async void sync_mute_to_accountsservice (bool mute) { if (_user_proxy == null) return; @@ -440,13 +440,13 @@ public class VolumeControl : Object _mute_cancellable.reset (); try { - yield _user_proxy.get_connection ().call (_user_proxy.get_name (), _user_proxy.get_object_path (), "org.freedesktop.DBus.Properties", "Set", new Variant ("(ssv)", _user_proxy.get_interface_name (), "Muted", new Variant ("b", _mute)), null, DBusCallFlags.NONE, -1, _mute_cancellable); + yield _user_proxy.get_connection ().call (_user_proxy.get_name (), _user_proxy.get_object_path (), "org.freedesktop.DBus.Properties", "Set", new Variant ("(ssv)", _user_proxy.get_interface_name (), "Muted", new Variant ("b", mute)), null, DBusCallFlags.NONE, -1, _mute_cancellable); } catch (GLib.Error e) { warning ("unable to sync mute to AccountsService: %s", e.message); } } - private async void sync_volume_to_accountsservice () + private async void sync_volume_to_accountsservice (double volume) { if (_user_proxy == null) return; @@ -455,7 +455,7 @@ public class VolumeControl : Object _volume_cancellable.reset (); try { - yield _user_proxy.get_connection ().call (_user_proxy.get_name (), _user_proxy.get_object_path (), "org.freedesktop.DBus.Properties", "Set", new Variant ("(ssv)", _user_proxy.get_interface_name (), "Volume", new Variant ("d", _volume)), null, DBusCallFlags.NONE, -1, _volume_cancellable); + yield _user_proxy.get_connection ().call (_user_proxy.get_name (), _user_proxy.get_object_path (), "org.freedesktop.DBus.Properties", "Set", new Variant ("(ssv)", _user_proxy.get_interface_name (), "Volume", new Variant ("d", volume)), null, DBusCallFlags.NONE, -1, _volume_cancellable); } catch (GLib.Error e) { warning ("unable to sync volume to AccountsService: %s", e.message); } -- cgit v1.2.3 From 9d812a8e5f4e079e19135ceebfcef22bafdfb0a1 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Tue, 4 Mar 2014 15:15:20 -0500 Subject: Remove touch namespace for sound settings --- src/volume-control.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/volume-control.vala') diff --git a/src/volume-control.vala b/src/volume-control.vala index f83d29d..c5c11ca 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -395,7 +395,7 @@ public class VolumeControl : Object var user_path_variant = yield accounts_proxy.call ("FindUserByName", new Variant ("(s)", username), DBusCallFlags.NONE, -1); string user_path; user_path_variant.get ("(o)", out user_path); - _user_proxy = yield DBusProxy.create_for_bus (BusType.SYSTEM, DBusProxyFlags.GET_INVALIDATED_PROPERTIES, null, "org.freedesktop.Accounts", user_path, "com.ubuntu.touch.AccountsService.Sound"); + _user_proxy = yield DBusProxy.create_for_bus (BusType.SYSTEM, DBusProxyFlags.GET_INVALIDATED_PROPERTIES, null, "org.freedesktop.Accounts", user_path, "com.ubuntu.AccountsService.Sound"); } catch (GLib.Error e) { warning ("unable to find Accounts path for user %s: %s", username, e.message); return; -- cgit v1.2.3 From 01e47b1cc1c8fd60f335a15207642022a701b33d Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Thu, 13 Mar 2014 17:23:55 -0400 Subject: Check XDG_SESSION_CLASS to determine if we're in greeter; use native vala dbus interface for greeter list --- src/volume-control.vala | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'src/volume-control.vala') diff --git a/src/volume-control.vala b/src/volume-control.vala index c5c11ca..899cc35 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -23,6 +23,13 @@ using PulseAudio; [CCode(cname="pa_cvolume_set", cheader_filename = "pulse/volume.h")] extern unowned PulseAudio.CVolume? vol_set (PulseAudio.CVolume? cv, uint channels, PulseAudio.Volume v); +[DBus (name="com.canonical.UnityGreeter.List")] +interface GreeterListInterface : Object +{ + public abstract async string get_active_entry () throws IOError; + public signal void entry_selected (string entry_name); +} + public class VolumeControl : Object { /* this is static to ensure it being freed after @context (loop does not have ref counting) */ @@ -36,7 +43,7 @@ public class VolumeControl : Object private double _mic_volume = 0.0; private DBusProxy _user_proxy; - private DBusProxy _greeter_proxy; + private GreeterListInterface _greeter_proxy; private Cancellable _mute_cancellable; private Cancellable _volume_cancellable; @@ -364,15 +371,15 @@ public class VolumeControl : Object } } - private async void setup_user_proxy (string? username = null) + private async void setup_user_proxy (string? username_in = null) { + var username = username_in; _user_proxy = null; // Look up currently selected greeter user, if asked if (username == null) { try { - var username_variant = yield _greeter_proxy.call ("GetActiveEntry", null, DBusCallFlags.NONE, -1); - username_variant.get ("(s)", out username); + username = yield _greeter_proxy.get_active_entry (); if (username == "" || username == null) return; } catch (GLib.Error e) { @@ -412,15 +419,14 @@ public class VolumeControl : Object private async void setup_accountsservice () { - try { - _greeter_proxy = yield DBusProxy.create_for_bus (BusType.SESSION, DBusProxyFlags.NONE, null, "com.canonical.UnityGreeter", "/list", "com.canonical.UnityGreeter.List"); - } catch (GLib.Error e) { - warning ("unable to get greeter proxy: %s", e.message); - return; - } - - if (_greeter_proxy.get_name_owner () != null) { - _greeter_proxy.connect ("EntrySelected", greeter_user_changed); + if (Environment.get_variable ("XDG_SESSION_CLASS") == "greeter") { + try { + _greeter_proxy = yield Bus.get_proxy (BusType.SESSION, "com.canonical.UnityGreeter", "/list"); + } catch (GLib.Error e) { + warning ("unable to get greeter proxy: %s", e.message); + return; + } + _greeter_proxy.entry_selected.connect (greeter_user_changed); yield setup_user_proxy (); } else { // We are in a user session. We just need our own proxy -- cgit v1.2.3 From ae015c18810749385a302da75d1de91c3a7d2052 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Fri, 14 Mar 2014 10:32:33 -0400 Subject: Fix bug where we weren't asking for volume settings on startup --- src/volume-control.vala | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/volume-control.vala') diff --git a/src/volume-control.vala b/src/volume-control.vala index 899cc35..97d980c 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -408,8 +408,12 @@ public class VolumeControl : Object return; } - // Listen for property changes, this will get current volume (since getting proxy loads properties) + // Get current values and listen for changes _user_proxy.g_properties_changed.connect (accountsservice_props_changed_cb); + var props_variant = yield _user_proxy.get_connection ().call (_user_proxy.get_name (), _user_proxy.get_object_path (), "org.freedesktop.DBus.Properties", "GetAll", new Variant ("(s)", _user_proxy.get_interface_name ()), null, DBusCallFlags.NONE, -1); + Variant props; + props_variant.get ("(@a{sv})", out props); + accountsservice_props_changed_cb(_user_proxy, props, null); } private void greeter_user_changed (string username) -- cgit v1.2.3