aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavi Garcia Mena <xavi.garcia.mena@canonical.com>2015-10-05 12:10:49 +0200
committerXavi Garcia Mena <xavi.garcia.mena@canonical.com>2015-10-05 12:10:49 +0200
commit24ab28edf43e3ec188d110d08c810567539d8eb4 (patch)
tree04f8fa51e3ba9b6a69484f5bbe17b9eef155b309
parente49548a7edb0d4d8a3420cc6c0be2b0e15f57bcf (diff)
downloadayatana-indicator-sound-24ab28edf43e3ec188d110d08c810567539d8eb4.tar.gz
ayatana-indicator-sound-24ab28edf43e3ec188d110d08c810567539d8eb4.tar.bz2
ayatana-indicator-sound-24ab28edf43e3ec188d110d08c810567539d8eb4.zip
Added USB and HDMI active outputs
-rw-r--r--src/service.vala133
-rw-r--r--src/volume-control-pulse.vala80
-rw-r--r--src/volume-control.vala7
3 files changed, 187 insertions, 33 deletions
diff --git a/src/service.vala b/src/service.vala
index 15fd97e..e3e91f5 100644
--- a/src/service.vala
+++ b/src/service.vala
@@ -313,6 +313,56 @@ public class IndicatorSound.Service: Object {
else
icon = "audio-volume-high";
break;
+ case VolumeControl.ActiveOutput.BLUETOOTH_SPEAKER:
+ 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";
+ break;
+ case VolumeControl.ActiveOutput.USB_SPEAKER:
+ 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";
+ break;
+ case VolumeControl.ActiveOutput.USB_HEADPHONES:
+ 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";
+ break;
+ case VolumeControl.ActiveOutput.HDMI_SPEAKER:
+ 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";
+ break;
+ case VolumeControl.ActiveOutput.HDMI_HEADPHONES:
+ 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";
+ break;
}
return icon;
}
@@ -331,6 +381,21 @@ public class IndicatorSound.Service: Object {
case VolumeControl.ActiveOutput.BLUETOOTH_HEADPHONES:
icon = "audio-volume-high";
break;
+ case VolumeControl.ActiveOutput.BLUETOOTH_SPEAKER:
+ icon = "audio-volume-high";
+ break;
+ case VolumeControl.ActiveOutput.USB_SPEAKER:
+ icon = "audio-volume-high";
+ break;
+ case VolumeControl.ActiveOutput.USB_HEADPHONES:
+ icon = "audio-volume-high";
+ break;
+ case VolumeControl.ActiveOutput.HDMI_SPEAKER:
+ icon = "audio-volume-high";
+ break;
+ case VolumeControl.ActiveOutput.HDMI_HEADPHONES:
+ icon = "audio-volume-high";
+ break;
}
} else {
icon = get_volume_icon (volume, active_output);
@@ -366,6 +431,46 @@ public class IndicatorSound.Service: Object {
else
icon = get_volume_icon (volume, active_output);
break;
+ case VolumeControl.ActiveOutput.BLUETOOTH_SPEAKER:
+ if (mute || volume <= 0.0)
+ icon = this.mute_blocks_sound ? "audio-volume-muted-blocking-panel" : "audio-volume-muted-panel";
+ else if (this.accounts_service != null && this.accounts_service.silentMode)
+ icon = "audio-volume-muted-panel";
+ else
+ icon = get_volume_icon (volume, active_output);
+ break;
+ case VolumeControl.ActiveOutput.USB_SPEAKER:
+ if (mute || volume <= 0.0)
+ icon = this.mute_blocks_sound ? "audio-volume-muted-blocking-panel" : "audio-volume-muted-panel";
+ else if (this.accounts_service != null && this.accounts_service.silentMode)
+ icon = "audio-volume-muted-panel";
+ else
+ icon = get_volume_icon (volume, active_output);
+ break;
+ case VolumeControl.ActiveOutput.USB_HEADPHONES:
+ if (mute || volume <= 0.0)
+ icon = this.mute_blocks_sound ? "audio-volume-muted-blocking-panel" : "audio-volume-muted-panel";
+ else if (this.accounts_service != null && this.accounts_service.silentMode)
+ icon = "audio-volume-muted-panel";
+ else
+ icon = get_volume_icon (volume, active_output);
+ break;
+ case VolumeControl.ActiveOutput.HDMI_SPEAKER:
+ if (mute || volume <= 0.0)
+ icon = this.mute_blocks_sound ? "audio-volume-muted-blocking-panel" : "audio-volume-muted-panel";
+ else if (this.accounts_service != null && this.accounts_service.silentMode)
+ icon = "audio-volume-muted-panel";
+ else
+ icon = get_volume_icon (volume, active_output);
+ break;
+ case VolumeControl.ActiveOutput.HDMI_HEADPHONES:
+ if (mute || volume <= 0.0)
+ icon = this.mute_blocks_sound ? "audio-volume-muted-blocking-panel" : "audio-volume-muted-panel";
+ else if (this.accounts_service != null && this.accounts_service.silentMode)
+ icon = "audio-volume-muted-panel";
+ else
+ icon = get_volume_icon (volume, active_output);
+ break;
}
return icon;
}
@@ -421,12 +526,32 @@ public class IndicatorSound.Service: Object {
}
if (volume_control.active_output == VolumeControl.ActiveOutput.HEADPHONES) {
- volume_label = _("Headphones");
- }
+ volume_label = _("Headphones");
+ }
if (volume_control.active_output == VolumeControl.ActiveOutput.BLUETOOTH_HEADPHONES) {
- volume_label = _("Bluetooth");
- }
+ volume_label = _("Bluetooth headphones");
+ }
+
+ if (volume_control.active_output == VolumeControl.ActiveOutput.BLUETOOTH_SPEAKER) {
+ volume_label = _("Bluetooth speaker");
+ }
+
+ if (volume_control.active_output == VolumeControl.ActiveOutput.USB_SPEAKER) {
+ volume_label = _("Usb speaker");
+ }
+
+ if (volume_control.active_output == VolumeControl.ActiveOutput.USB_HEADPHONES) {
+ volume_label = _("Usb headphones");
+ }
+
+ if (volume_control.active_output == VolumeControl.ActiveOutput.HDMI_SPEAKER) {
+ volume_label = _("HDMI speaker");
+ }
+
+ if (volume_control.active_output == VolumeControl.ActiveOutput.HDMI_HEADPHONES) {
+ volume_label = _("HDMI headphones");
+ }
}
/* Choose an icon */
diff --git a/src/volume-control-pulse.vala b/src/volume-control-pulse.vala
index 54fa18a..a1f743b 100644
--- a/src/volume-control-pulse.vala
+++ b/src/volume-control-pulse.vala
@@ -87,7 +87,7 @@ public class VolumeControlPulse : VolumeControl
private bool _send_next_local_volume = false;
private double _account_service_volume = 0.0;
private bool _active_port_headphone = false;
- private bool _active_port_headphone_bluetooth = false;
+ private VolumeControl.ActiveOutput _active_output = VolumeControl.ActiveOutput.SPEAKERS;
/** true when connected to the pulse server */
public override bool ready { get; private set; }
@@ -136,6 +136,52 @@ public class VolumeControlPulse : VolumeControl
stop_high_volume_approved_timer();
}
+ private VolumeControl.ActiveOutput calculate_active_output (SinkInfo? sink) {
+
+ VolumeControl.ActiveOutput ret_output = VolumeControl.ActiveOutput.SPEAKERS;
+ /* 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 (sink.active_port != null) {
+ // look if it's a headset/headphones
+ if (sink.active_port.name.contains("headset") ||
+ sink.active_port.name.contains("headphone")) {
+ _active_port_headphone = true;
+ // check if it's a bluetooth device
+ var device_bus = sink.proplist.gets ("device.bus");
+ if (device_bus != null && device_bus == "bluetooth") {
+ ret_output = VolumeControl.ActiveOutput.BLUETOOTH_HEADPHONES;
+ } else if (device_bus != null && device_bus == "usb") {
+ ret_output = VolumeControl.ActiveOutput.USB_HEADPHONES;
+ } else if (device_bus != null && device_bus == "hdmi") {
+ ret_output = VolumeControl.ActiveOutput.HDMI_HEADPHONES;
+ } else {
+ ret_output = VolumeControl.ActiveOutput.HEADPHONES;
+ }
+ } else {
+ // speaker
+ _active_port_headphone = false;
+ var device_bus = sink.proplist.gets ("device.bus");
+ if (device_bus != null && device_bus == "bluetooth") {
+ ret_output = VolumeControl.ActiveOutput.BLUETOOTH_SPEAKER;
+ } else if (device_bus != null && device_bus == "usb") {
+ ret_output = VolumeControl.ActiveOutput.USB_SPEAKER;
+ } else if (device_bus != null && device_bus == "hdmi") {
+ ret_output = VolumeControl.ActiveOutput.HDMI_SPEAKER;
+ } else {
+ ret_output = VolumeControl.ActiveOutput.SPEAKERS;
+ }
+ }
+ } else {
+ _active_port_headphone = false;
+ ret_output = VolumeControl.ActiveOutput.SPEAKERS;
+ }
+
+ return ret_output;
+ }
+
/* PulseAudio logic*/
private void context_events_cb (Context c, Context.SubscriptionEventType t, uint32 index)
{
@@ -205,28 +251,10 @@ public class VolumeControlPulse : VolumeControl
// store the current status of the active output
VolumeControl.ActiveOutput active_output_before = active_output;
- /* 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 != null &&
- (i.active_port.name.contains("headset") ||
- i.active_port.name.contains("headphone"))) {
- _active_port_headphone = true;
- // check if it's a bluetooth device
- var device_bus = i.proplist.gets ("device.bus");
- if (device_bus != null && device_bus == "bluetooth") {
- _active_port_headphone_bluetooth = true;
-
- } else {
- _active_port_headphone_bluetooth = false;
- }
- } else {
- _active_port_headphone = false;
- _active_port_headphone_bluetooth = false;
- }
-
+ // calculate the output
+ _active_output = calculate_active_output (i);
+
+ // check if the output has changed, if so... emit a signal
VolumeControl.ActiveOutput active_output_now = active_output;
if (active_output_now != active_output_before) {
this.active_output_changed (active_output_now);
@@ -560,11 +588,7 @@ public class VolumeControlPulse : VolumeControl
{
get
{
- if (_active_port_headphone_bluetooth)
- return VolumeControl.ActiveOutput.BLUETOOTH_HEADPHONES;
- if (_active_port_headphone)
- return VolumeControl.ActiveOutput.HEADPHONES;
- return VolumeControl.ActiveOutput.SPEAKERS;
+ return _active_output;
}
}
diff --git a/src/volume-control.vala b/src/volume-control.vala
index 738bdcd..8e615ea 100644
--- a/src/volume-control.vala
+++ b/src/volume-control.vala
@@ -31,7 +31,12 @@ public abstract class VolumeControl : Object
public enum ActiveOutput {
SPEAKERS,
HEADPHONES,
- BLUETOOTH_HEADPHONES
+ BLUETOOTH_HEADPHONES,
+ BLUETOOTH_SPEAKER,
+ USB_SPEAKER,
+ USB_HEADPHONES,
+ HDMI_SPEAKER,
+ HDMI_HEADPHONES
}
public class Volume : Object {