aboutsummaryrefslogtreecommitdiff
path: root/src/volume-control.vala
diff options
context:
space:
mode:
Diffstat (limited to 'src/volume-control.vala')
-rw-r--r--src/volume-control.vala92
1 files changed, 91 insertions, 1 deletions
diff --git a/src/volume-control.vala b/src/volume-control.vala
index 29c49f6..6f48c5d 100644
--- a/src/volume-control.vala
+++ b/src/volume-control.vala
@@ -19,6 +19,7 @@
*/
using PulseAudio;
+using Notify;
using Gee;
[CCode(cname="pa_cvolume_set", cheader_filename = "pulse/volume.h")]
@@ -67,6 +68,9 @@ public class VolumeControl : Object
private uint _accountservice_volume_timer = 0;
private bool _send_next_local_volume = false;
private double _account_service_volume = 0.0;
+ private Notify.Notification _notification;
+
+ private bool _active_port_headphone = false;
public signal void volume_changed (double v);
public signal void mic_volume_changed (double v);
@@ -77,6 +81,9 @@ public class VolumeControl : Object
/** true when a microphone is active **/
public bool active_mic { get; private set; default = false; }
+ /** true when high volume warnings should be shown */
+ public bool high_volume { get; set; }
+
public VolumeControl ()
{
if (loop == null)
@@ -84,6 +91,13 @@ public class VolumeControl : Object
_mute_cancellable = new Cancellable ();
_volume_cancellable = new Cancellable ();
+
+ Notify.init ("Volume");
+ _notification = new Notify.Notification(_("Volume"), "", "audio-volume-muted");
+ _notification.set_hint ("value", 0);
+ _notification.set_hint ("x-canonical-private-synchronous", "true");
+ _notification.set_hint ("x-canonical-non-shaped-icon", "true");
+
setup_accountsservice.begin ();
this.reconnect_to_pulse ();
@@ -149,6 +163,8 @@ public class VolumeControl : Object
private void sink_info_cb_for_props (Context c, SinkInfo? i, int eol)
{
+ bool old_active_port_headphone = this._active_port_headphone;
+
if (i == null)
return;
@@ -165,11 +181,27 @@ public class VolumeControl : Object
this.notify_property ("is-playing");
}
+ /* Check if the current active port is headset/headphone */
+ /* There is not easy way to check if the port is a headset/headphone besides
+ * checking for the port name. On touch (with the pulseaudio droid element)
+ * the headset/headphone port is called 'output-headset' and 'output-headphone'.
+ * On the desktop this is usually called 'analog-output-headphones' */
+ if (i.active_port.name == "output-wired_headset" ||
+ i.active_port.name == "output-wired_headphone" ||
+ i.active_port.name == "analog-output-headphones") {
+ _active_port_headphone = true;
+ } else {
+ _active_port_headphone = false;
+ }
+
if (_pulse_use_stream_restore == false &&
_volume != volume_to_double (i.volume.max ()))
{
_volume = volume_to_double (i.volume.max ());
volume_changed (_volume);
+ start_local_volume_timer();
+ } else if (this._active_port_headphone != old_active_port_headphone) {
+ volume_changed (_volume);
}
}
@@ -238,6 +270,7 @@ public class VolumeControl : Object
/* Someone else changed the volume for this role, reflect on the indicator */
_volume = volume_to_double (volume);
volume_changed (_volume);
+ start_local_volume_timer();
}
}
}
@@ -280,6 +313,7 @@ public class VolumeControl : Object
_volume = volume_to_double (volume);
volume_changed (_volume);
+ start_local_volume_timer();
} catch (GLib.Error e) {
warning ("unable to get volume for active role %s (%s)", sink_input_objp, e.message);
}
@@ -569,8 +603,64 @@ public class VolumeControl : Object
public void set_volume (double volume)
{
- if (set_volume_internal (volume))
+ /* Using this to detect whether we're on the phone or not */
+ if (_pulse_use_stream_restore) {
+ /* Watch for extreme */
+ if (volume > 0.75 && _active_port_headphone)
+ high_volume = true;
+ else
+ high_volume = false;
+
+ /* Determine Label */
+ string volume_label = "";
+ if (high_volume)
+ volume_label = _("High volume");
+
+ /* Choose an icon */
+ string icon = "audio-volume-muted";
+ if (volume <= 0.0)
+ icon = "audio-volume-muted";
+ else if (volume <= 0.3)
+ icon = "audio-volume-low";
+ else if (volume <= 0.7)
+ icon = "audio-volume-medium";
+ else
+ icon = "audio-volume-high";
+
+ /* Choose a sound */
+ string? sound = null;
+ if (!((_active_sink_input >= 0) && (_active_sink_input < _valid_roles.length)
+ && (_valid_roles[_active_sink_input] == "multimedia")))
+ sound = "/usr/share/sounds/ubuntu/stereo/message.ogg";
+
+ /* Check tint */
+ string tint = "false";
+ if (high_volume)
+ tint = "true";
+
+ /* Put it all into the notification */
+ _notification.clear_hints ();
+ _notification.update (_("Volume"), volume_label, icon);
+ _notification.set_hint ("value", (int32)(volume * 100.0));
+ /* TODO: Removing sound until we can get all the roles cleaned up for
+ when to play it. We expect this to come back, but in another landing.
+ _notification.set_hint ("sound-file", sound);
+ */
+ _notification.set_hint ("x-canonical-value-bar-tint", tint);
+ _notification.set_hint ("x-canonical-private-synchronous", "true");
+ _notification.set_hint ("x-canonical-non-shaped-icon", "true");
+
+ /* Show it */
+ try {
+ _notification.show ();
+ } catch (GLib.Error e) {
+ warning("Unable to send volume change notification: %s", e.message);
+ }
+ }
+
+ if (set_volume_internal (volume)) {
start_local_volume_timer();
+ }
}
void set_mic_volume_success_cb (Context c, int success)