Merge lp:~xavi-garcia-mena/indicator-sound/bluetooth-icons-bug-1415480 into lp:indicator-sound/15.10

Proposed by Xavi Garcia
Status: Merged
Approved by: Charles Kerr
Approved revision: 510
Merged at revision: 508
Proposed branch: lp:~xavi-garcia-mena/indicator-sound/bluetooth-icons-bug-1415480
Merge into: lp:indicator-sound/15.10
Diff against target: 614 lines (+437/-40)
6 files modified
src/CMakeLists.txt (+1/-0)
src/service.vala (+329/-27)
src/sound-menu.vala (+23/-0)
src/volume-control-pulse.vala (+69/-12)
src/volume-control.vala (+14/-0)
tests/notifications-test.cc (+1/-1)
To merge this branch: bzr merge lp:~xavi-garcia-mena/indicator-sound/bluetooth-icons-bug-1415480
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+272735@code.launchpad.net

Commit message

Added the code to change the icons and label when a bluetooth headset is connected

Description of the change

Added the code to change the icons and label when a bluetooth headset is connected

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

So many possible states!

Writing coverage test for this will be fun... :-)

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
508. By Xavi Garcia

Updated to show a label stating the active output

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
509. By Xavi Garcia

Added USB and HDMI active outputs

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
510. By Xavi Garcia

fixed panel root panel icons

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) :
review: Approve
Revision history for this message
Sebastien Bacher (seb128) wrote :

that seems to have broken unity7 notifications (when scrolling over the indicator)

Revision history for this message
Xavi Garcia (xavi-garcia-mena) wrote :

As discussed with Lars Uebernickel, a fix for unity7 is ready to go.
This branch adds a new string to the notification.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 2015-02-19 16:23:01 +0000
+++ src/CMakeLists.txt 2015-10-05 12:20:39 +0000
@@ -103,6 +103,7 @@
103 sound-menu.vala103 sound-menu.vala
104 DEPENDS104 DEPENDS
105 media-player105 media-player
106 volume-control
106)107)
107vala_add(indicator-sound-service108vala_add(indicator-sound-service
108 accounts-service-user.vala109 accounts-service-user.vala
109110
=== modified file 'src/service.vala'
--- src/service.vala 2015-08-27 11:42:21 +0000
+++ src/service.vala 2015-10-05 12:20:39 +0000
@@ -52,6 +52,8 @@
52 this.notify["visible"].connect ( () => this.update_root_icon () );52 this.notify["visible"].connect ( () => this.update_root_icon () );
5353
54 this.volume_control = volume;54 this.volume_control = volume;
55 this.volume_control.active_output_changed.connect (this.update_root_icon);
56 this.volume_control.active_output_changed.connect (this.update_notification);
5557
56 this.accounts_service = accounts;58 this.accounts_service = accounts;
57 /* If we're on the greeter, don't export */59 /* If we're on the greeter, don't export */
@@ -90,6 +92,10 @@
90 this.volume_control.bind_property ("high-volume", menu, "show-high-volume-warning", BindingFlags.SYNC_CREATE);92 this.volume_control.bind_property ("high-volume", menu, "show-high-volume-warning", BindingFlags.SYNC_CREATE);
91 });93 });
9294
95 this.menus.@foreach ( (profile, menu) => {
96 this.volume_control.active_output_changed.connect (menu.update_volume_slider);
97 });
98
93 this.sync_preferred_players ();99 this.sync_preferred_players ();
94 this.settings.changed["interested-media-players"].connect ( () => {100 this.settings.changed["interested-media-players"].connect ( () => {
95 this.sync_preferred_players ();101 this.sync_preferred_players ();
@@ -245,17 +251,7 @@
245251
246 void update_root_icon () {252 void update_root_icon () {
247 double volume = this.volume_control.volume.volume;253 double volume = this.volume_control.volume.volume;
248 string icon;254 string icon = get_volume_root_icon (volume, this.volume_control.mute, volume_control.active_output);
249 if (this.volume_control.mute || volume <= 0.0)
250 icon = this.mute_blocks_sound ? "audio-volume-muted-blocking-panel" : "audio-volume-muted-panel";
251 else if (this.accounts_service != null && this.accounts_service.silentMode)
252 icon = "audio-volume-muted-panel";
253 else if (volume <= 0.3)
254 icon = "audio-volume-low-panel";
255 else if (volume <= 0.7)
256 icon = "audio-volume-medium-panel";
257 else
258 icon = "audio-volume-high-panel";
259255
260 string accessible_name;256 string accessible_name;
261 if (this.volume_control.mute) {257 if (this.volume_control.mute) {
@@ -282,6 +278,292 @@
282 private bool notify_server_supports_sync = false;278 private bool notify_server_supports_sync = false;
283 private bool block_info_notifications = false;279 private bool block_info_notifications = false;
284280
281 private string get_volume_icon (double volume, VolumeControl.ActiveOutput active_output)
282 {
283 string icon = "";
284 switch (active_output)
285 {
286 case VolumeControl.ActiveOutput.SPEAKERS:
287 if (volume <= 0.0)
288 icon = "audio-volume-muted";
289 else if (volume <= 0.3)
290 icon = "audio-volume-low";
291 else if (volume <= 0.7)
292 icon = "audio-volume-medium";
293 else
294 icon = "audio-volume-high";
295 break;
296 case VolumeControl.ActiveOutput.HEADPHONES:
297 if (volume <= 0.0)
298 icon = "audio-volume-muted";
299 else if (volume <= 0.3)
300 icon = "audio-volume-low";
301 else if (volume <= 0.7)
302 icon = "audio-volume-medium";
303 else
304 icon = "audio-volume-high";
305 break;
306 case VolumeControl.ActiveOutput.BLUETOOTH_HEADPHONES:
307 if (volume <= 0.0)
308 icon = "audio-volume-muted";
309 else if (volume <= 0.3)
310 icon = "audio-volume-low";
311 else if (volume <= 0.7)
312 icon = "audio-volume-medium";
313 else
314 icon = "audio-volume-high";
315 break;
316 case VolumeControl.ActiveOutput.BLUETOOTH_SPEAKER:
317 if (volume <= 0.0)
318 icon = "audio-volume-muted";
319 else if (volume <= 0.3)
320 icon = "audio-volume-low";
321 else if (volume <= 0.7)
322 icon = "audio-volume-medium";
323 else
324 icon = "audio-volume-high";
325 break;
326 case VolumeControl.ActiveOutput.USB_SPEAKER:
327 if (volume <= 0.0)
328 icon = "audio-volume-muted";
329 else if (volume <= 0.3)
330 icon = "audio-volume-low";
331 else if (volume <= 0.7)
332 icon = "audio-volume-medium";
333 else
334 icon = "audio-volume-high";
335 break;
336 case VolumeControl.ActiveOutput.USB_HEADPHONES:
337 if (volume <= 0.0)
338 icon = "audio-volume-muted";
339 else if (volume <= 0.3)
340 icon = "audio-volume-low";
341 else if (volume <= 0.7)
342 icon = "audio-volume-medium";
343 else
344 icon = "audio-volume-high";
345 break;
346 case VolumeControl.ActiveOutput.HDMI_SPEAKER:
347 if (volume <= 0.0)
348 icon = "audio-volume-muted";
349 else if (volume <= 0.3)
350 icon = "audio-volume-low";
351 else if (volume <= 0.7)
352 icon = "audio-volume-medium";
353 else
354 icon = "audio-volume-high";
355 break;
356 case VolumeControl.ActiveOutput.HDMI_HEADPHONES:
357 if (volume <= 0.0)
358 icon = "audio-volume-muted";
359 else if (volume <= 0.3)
360 icon = "audio-volume-low";
361 else if (volume <= 0.7)
362 icon = "audio-volume-medium";
363 else
364 icon = "audio-volume-high";
365 break;
366 }
367 return icon;
368 }
369
370 private string get_volume_root_icon_by_volume (double volume, VolumeControl.ActiveOutput active_output)
371 {
372 string icon = "";
373 switch (active_output)
374 {
375 case VolumeControl.ActiveOutput.SPEAKERS:
376 if (volume <= 0.0)
377 icon = "audio-volume-muted-panel";
378 else if (volume <= 0.3)
379 icon = "audio-volume-low-panel";
380 else if (volume <= 0.7)
381 icon = "audio-volume-medium-panel";
382 else
383 icon = "audio-volume-high-panel";
384 break;
385 case VolumeControl.ActiveOutput.HEADPHONES:
386 if (volume <= 0.0)
387 icon = "audio-volume-muted-panel";
388 else if (volume <= 0.3)
389 icon = "audio-volume-low-panel";
390 else if (volume <= 0.7)
391 icon = "audio-volume-medium-panel";
392 else
393 icon = "audio-volume-high-panel";
394 break;
395 case VolumeControl.ActiveOutput.BLUETOOTH_HEADPHONES:
396 if (volume <= 0.0)
397 icon = "audio-volume-muted-panel";
398 else if (volume <= 0.3)
399 icon = "audio-volume-low-panel";
400 else if (volume <= 0.7)
401 icon = "audio-volume-medium-panel";
402 else
403 icon = "audio-volume-high-panel";
404 break;
405 case VolumeControl.ActiveOutput.BLUETOOTH_SPEAKER:
406 if (volume <= 0.0)
407 icon = "audio-volume-muted-panel";
408 else if (volume <= 0.3)
409 icon = "audio-volume-low-panel";
410 else if (volume <= 0.7)
411 icon = "audio-volume-medium-panel";
412 else
413 icon = "audio-volume-high-panel";
414 break;
415 case VolumeControl.ActiveOutput.USB_SPEAKER:
416 if (volume <= 0.0)
417 icon = "audio-volume-muted-panel";
418 else if (volume <= 0.3)
419 icon = "audio-volume-low-panel";
420 else if (volume <= 0.7)
421 icon = "audio-volume-medium-panel";
422 else
423 icon = "audio-volume-high-panel";
424 break;
425 case VolumeControl.ActiveOutput.USB_HEADPHONES:
426 if (volume <= 0.0)
427 icon = "audio-volume-muted-panel";
428 else if (volume <= 0.3)
429 icon = "audio-volume-low-panel";
430 else if (volume <= 0.7)
431 icon = "audio-volume-medium-panel";
432 else
433 icon = "audio-volume-high-panel";
434 break;
435 case VolumeControl.ActiveOutput.HDMI_SPEAKER:
436 if (volume <= 0.0)
437 icon = "audio-volume-muted-panel";
438 else if (volume <= 0.3)
439 icon = "audio-volume-low-panel";
440 else if (volume <= 0.7)
441 icon = "audio-volume-medium-panel";
442 else
443 icon = "audio-volume-high-panel";
444 break;
445 case VolumeControl.ActiveOutput.HDMI_HEADPHONES:
446 if (volume <= 0.0)
447 icon = "audio-volume-muted-panel";
448 else if (volume <= 0.3)
449 icon = "audio-volume-low-panel";
450 else if (volume <= 0.7)
451 icon = "audio-volume-medium-panel";
452 else
453 icon = "audio-volume-high-panel";
454 break;
455 }
456 return icon;
457 }
458
459 private string get_volume_notification_icon (double volume, bool loud, VolumeControl.ActiveOutput active_output) {
460 string icon = "";
461 if (loud) {
462 switch (active_output)
463 {
464 case VolumeControl.ActiveOutput.SPEAKERS:
465 icon = "audio-volume-high";
466 break;
467 case VolumeControl.ActiveOutput.HEADPHONES:
468 icon = "audio-volume-high";
469 break;
470 case VolumeControl.ActiveOutput.BLUETOOTH_HEADPHONES:
471 icon = "audio-volume-high";
472 break;
473 case VolumeControl.ActiveOutput.BLUETOOTH_SPEAKER:
474 icon = "audio-volume-high";
475 break;
476 case VolumeControl.ActiveOutput.USB_SPEAKER:
477 icon = "audio-volume-high";
478 break;
479 case VolumeControl.ActiveOutput.USB_HEADPHONES:
480 icon = "audio-volume-high";
481 break;
482 case VolumeControl.ActiveOutput.HDMI_SPEAKER:
483 icon = "audio-volume-high";
484 break;
485 case VolumeControl.ActiveOutput.HDMI_HEADPHONES:
486 icon = "audio-volume-high";
487 break;
488 }
489 } else {
490 icon = get_volume_icon (volume, active_output);
491 }
492 return icon;
493 }
494
495 private string get_volume_root_icon (double volume, bool mute, VolumeControl.ActiveOutput active_output) {
496 string icon = "";
497 switch (active_output)
498 {
499 case VolumeControl.ActiveOutput.SPEAKERS:
500 if (mute || volume <= 0.0)
501 icon = this.mute_blocks_sound ? "audio-volume-muted-blocking-panel" : "audio-volume-muted-panel";
502 else if (this.accounts_service != null && this.accounts_service.silentMode)
503 icon = "audio-volume-muted-panel";
504 else
505 icon = get_volume_root_icon_by_volume (volume, active_output);
506 break;
507 case VolumeControl.ActiveOutput.HEADPHONES:
508 if (mute || volume <= 0.0)
509 icon = this.mute_blocks_sound ? "audio-volume-muted-blocking-panel" : "audio-volume-muted-panel";
510 else if (this.accounts_service != null && this.accounts_service.silentMode)
511 icon = "audio-volume-muted-panel";
512 else
513 icon = get_volume_root_icon_by_volume (volume, active_output);
514 break;
515 case VolumeControl.ActiveOutput.BLUETOOTH_HEADPHONES:
516 if (mute || volume <= 0.0)
517 icon = this.mute_blocks_sound ? "audio-volume-muted-blocking-panel" : "audio-volume-muted-panel";
518 else if (this.accounts_service != null && this.accounts_service.silentMode)
519 icon = "audio-volume-muted-panel";
520 else
521 icon = get_volume_root_icon_by_volume (volume, active_output);
522 break;
523 case VolumeControl.ActiveOutput.BLUETOOTH_SPEAKER:
524 if (mute || volume <= 0.0)
525 icon = this.mute_blocks_sound ? "audio-volume-muted-blocking-panel" : "audio-volume-muted-panel";
526 else if (this.accounts_service != null && this.accounts_service.silentMode)
527 icon = "audio-volume-muted-panel";
528 else
529 icon = get_volume_root_icon_by_volume (volume, active_output);
530 break;
531 case VolumeControl.ActiveOutput.USB_SPEAKER:
532 if (mute || volume <= 0.0)
533 icon = this.mute_blocks_sound ? "audio-volume-muted-blocking-panel" : "audio-volume-muted-panel";
534 else if (this.accounts_service != null && this.accounts_service.silentMode)
535 icon = "audio-volume-muted-panel";
536 else
537 icon = get_volume_root_icon_by_volume (volume, active_output);
538 break;
539 case VolumeControl.ActiveOutput.USB_HEADPHONES:
540 if (mute || volume <= 0.0)
541 icon = this.mute_blocks_sound ? "audio-volume-muted-blocking-panel" : "audio-volume-muted-panel";
542 else if (this.accounts_service != null && this.accounts_service.silentMode)
543 icon = "audio-volume-muted-panel";
544 else
545 icon = get_volume_root_icon_by_volume (volume, active_output);
546 break;
547 case VolumeControl.ActiveOutput.HDMI_SPEAKER:
548 if (mute || volume <= 0.0)
549 icon = this.mute_blocks_sound ? "audio-volume-muted-blocking-panel" : "audio-volume-muted-panel";
550 else if (this.accounts_service != null && this.accounts_service.silentMode)
551 icon = "audio-volume-muted-panel";
552 else
553 icon = get_volume_root_icon_by_volume (volume, active_output);
554 break;
555 case VolumeControl.ActiveOutput.HDMI_HEADPHONES:
556 if (mute || volume <= 0.0)
557 icon = this.mute_blocks_sound ? "audio-volume-muted-blocking-panel" : "audio-volume-muted-panel";
558 else if (this.accounts_service != null && this.accounts_service.silentMode)
559 icon = "audio-volume-muted-panel";
560 else
561 icon = get_volume_root_icon_by_volume (volume, active_output);
562 break;
563 }
564 return icon;
565 }
566
285 private void update_notification () {567 private void update_notification () {
286568
287 if (!notify_server_caps_checked) {569 if (!notify_server_caps_checked) {
@@ -323,26 +605,46 @@
323 if (notify_server_supports_sync && !block_info_notifications) {605 if (notify_server_supports_sync && !block_info_notifications) {
324606
325 /* Determine Label */607 /* Determine Label */
326 unowned string volume_label = loud608 string volume_label = loud
327 ? _("High volume can damage your hearing.")609 ? _("High volume can damage your hearing.")
328 : "";610 : "";
611
612 if (volume_label == "") {
613 if (volume_control.active_output == VolumeControl.ActiveOutput.SPEAKERS) {
614 volume_label = _("Speakers");
615 }
616
617 if (volume_control.active_output == VolumeControl.ActiveOutput.HEADPHONES) {
618 volume_label = _("Headphones");
619 }
620
621 if (volume_control.active_output == VolumeControl.ActiveOutput.BLUETOOTH_HEADPHONES) {
622 volume_label = _("Bluetooth headphones");
623 }
624
625 if (volume_control.active_output == VolumeControl.ActiveOutput.BLUETOOTH_SPEAKER) {
626 volume_label = _("Bluetooth speaker");
627 }
628
629 if (volume_control.active_output == VolumeControl.ActiveOutput.USB_SPEAKER) {
630 volume_label = _("Usb speaker");
631 }
632
633 if (volume_control.active_output == VolumeControl.ActiveOutput.USB_HEADPHONES) {
634 volume_label = _("Usb headphones");
635 }
636
637 if (volume_control.active_output == VolumeControl.ActiveOutput.HDMI_SPEAKER) {
638 volume_label = _("HDMI speaker");
639 }
640
641 if (volume_control.active_output == VolumeControl.ActiveOutput.HDMI_HEADPHONES) {
642 volume_label = _("HDMI headphones");
643 }
644 }
329645
330 /* Choose an icon */646 /* Choose an icon */
331 unowned string icon;647 string icon = get_volume_notification_icon (volume_control.volume.volume, loud, volume_control.active_output);
332 if (loud) {
333 icon = "audio-volume-high";
334 } else {
335 var volume = volume_control.volume.volume;
336
337 if (volume <= 0.0)
338 icon = "audio-volume-muted";
339 else if (volume <= 0.3)
340 icon = "audio-volume-low";
341 else if (volume <= 0.7)
342 icon = "audio-volume-medium";
343 else
344 icon = "audio-volume-high";
345 }
346648
347 /* Reset the notification */649 /* Reset the notification */
348 var n = this.info_notification;650 var n = this.info_notification;
349651
=== modified file 'src/sound-menu.vala'
--- src/sound-menu.vala 2015-02-12 00:44:34 +0000
+++ src/sound-menu.vala 2015-10-05 12:20:39 +0000
@@ -71,6 +71,7 @@
71 this.notify_handlers = new HashTable<MediaPlayer, ulong> (direct_hash, direct_equal);71 this.notify_handlers = new HashTable<MediaPlayer, ulong> (direct_hash, direct_equal);
7272
73 this.greeter_players = (flags & DisplayFlags.GREETER_PLAYERS) != 0;73 this.greeter_players = (flags & DisplayFlags.GREETER_PLAYERS) != 0;
74
74 }75 }
7576
76 ~SoundMenu () {77 ~SoundMenu () {
@@ -185,6 +186,28 @@
185 this.notify_handlers.remove (player);186 this.notify_handlers.remove (player);
186 }187 }
187188
189 public void update_volume_slider (VolumeControl.ActiveOutput active_output) {
190 int index = find_action (this.volume_section, "indicator.volume");
191 if (index != -1) {
192 string label = "Volume";
193 switch (active_output) {
194 case VolumeControl.ActiveOutput.SPEAKERS:
195 label = "Volume";
196 break;
197 case VolumeControl.ActiveOutput.HEADPHONES:
198 label = "Volume (Headphones)";
199 break;
200 case VolumeControl.ActiveOutput.BLUETOOTH_HEADPHONES:
201 label = "Volume (Bluetooth)";
202 break;
203 }
204 this.volume_section.remove (index);
205 this.volume_section.insert_item (index, this.create_slider_menu_item (_(label), "indicator.volume(0)", 0.0, 1.0, 0.01,
206 "audio-volume-low-zero-panel",
207 "audio-volume-high-panel"));
208 }
209 }
210
188 public Menu root;211 public Menu root;
189 public Menu menu;212 public Menu menu;
190 Menu volume_section;213 Menu volume_section;
191214
=== modified file 'src/volume-control-pulse.vala'
--- src/volume-control-pulse.vala 2015-08-12 18:16:40 +0000
+++ src/volume-control-pulse.vala 2015-10-05 12:20:39 +0000
@@ -87,6 +87,7 @@
87 private bool _send_next_local_volume = false;87 private bool _send_next_local_volume = false;
88 private double _account_service_volume = 0.0;88 private double _account_service_volume = 0.0;
89 private bool _active_port_headphone = false;89 private bool _active_port_headphone = false;
90 private VolumeControl.ActiveOutput _active_output = VolumeControl.ActiveOutput.SPEAKERS;
9091
91 /** true when connected to the pulse server */92 /** true when connected to the pulse server */
92 public override bool ready { get; private set; }93 public override bool ready { get; private set; }
@@ -135,6 +136,52 @@
135 stop_high_volume_approved_timer();136 stop_high_volume_approved_timer();
136 }137 }
137138
139 private VolumeControl.ActiveOutput calculate_active_output (SinkInfo? sink) {
140
141 VolumeControl.ActiveOutput ret_output = VolumeControl.ActiveOutput.SPEAKERS;
142 /* Check if the current active port is headset/headphone */
143 /* There is not easy way to check if the port is a headset/headphone besides
144 * checking for the port name. On touch (with the pulseaudio droid element)
145 * the headset/headphone port is called 'output-headset' and 'output-headphone'.
146 * On the desktop this is usually called 'analog-output-headphones' */
147 if (sink.active_port != null) {
148 // look if it's a headset/headphones
149 if (sink.active_port.name.contains("headset") ||
150 sink.active_port.name.contains("headphone")) {
151 _active_port_headphone = true;
152 // check if it's a bluetooth device
153 var device_bus = sink.proplist.gets ("device.bus");
154 if (device_bus != null && device_bus == "bluetooth") {
155 ret_output = VolumeControl.ActiveOutput.BLUETOOTH_HEADPHONES;
156 } else if (device_bus != null && device_bus == "usb") {
157 ret_output = VolumeControl.ActiveOutput.USB_HEADPHONES;
158 } else if (device_bus != null && device_bus == "hdmi") {
159 ret_output = VolumeControl.ActiveOutput.HDMI_HEADPHONES;
160 } else {
161 ret_output = VolumeControl.ActiveOutput.HEADPHONES;
162 }
163 } else {
164 // speaker
165 _active_port_headphone = false;
166 var device_bus = sink.proplist.gets ("device.bus");
167 if (device_bus != null && device_bus == "bluetooth") {
168 ret_output = VolumeControl.ActiveOutput.BLUETOOTH_SPEAKER;
169 } else if (device_bus != null && device_bus == "usb") {
170 ret_output = VolumeControl.ActiveOutput.USB_SPEAKER;
171 } else if (device_bus != null && device_bus == "hdmi") {
172 ret_output = VolumeControl.ActiveOutput.HDMI_SPEAKER;
173 } else {
174 ret_output = VolumeControl.ActiveOutput.SPEAKERS;
175 }
176 }
177 } else {
178 _active_port_headphone = false;
179 ret_output = VolumeControl.ActiveOutput.SPEAKERS;
180 }
181
182 return ret_output;
183 }
184
138 /* PulseAudio logic*/185 /* PulseAudio logic*/
139 private void context_events_cb (Context c, Context.SubscriptionEventType t, uint32 index)186 private void context_events_cb (Context c, Context.SubscriptionEventType t, uint32 index)
140 {187 {
@@ -201,18 +248,20 @@
201 this.notify_property ("is-playing");248 this.notify_property ("is-playing");
202 }249 }
203250
204 /* Check if the current active port is headset/headphone */251 // store the current status of the active output
205 /* There is not easy way to check if the port is a headset/headphone besides252 VolumeControl.ActiveOutput active_output_before = active_output;
206 * checking for the port name. On touch (with the pulseaudio droid element)253
207 * the headset/headphone port is called 'output-headset' and 'output-headphone'.254 // calculate the output
208 * On the desktop this is usually called 'analog-output-headphones' */255 _active_output = calculate_active_output (i);
209 if (i.active_port != null &&256
210 (i.active_port.name == "output-wired_headset" ||257 // check if the output has changed, if so... emit a signal
211 i.active_port.name == "output-wired_headphone" ||258 VolumeControl.ActiveOutput active_output_now = active_output;
212 i.active_port.name == "analog-output-headphones")) {259 if (active_output_now != active_output_before) {
213 _active_port_headphone = true;260 this.active_output_changed (active_output_now);
214 } else {261 if (active_output_now == VolumeControl.ActiveOutput.SPEAKERS) {
215 _active_port_headphone = false;262 _high_volume_approved = false;
263 }
264 update_high_volume();
216 }265 }
217266
218 if (_pulse_use_stream_restore == false &&267 if (_pulse_use_stream_restore == false &&
@@ -535,6 +584,14 @@
535 }584 }
536 }585 }
537586
587 public override VolumeControl.ActiveOutput active_output
588 {
589 get
590 {
591 return _active_output;
592 }
593 }
594
538 /* Volume operations */595 /* Volume operations */
539 private static PulseAudio.Volume double_to_volume (double vol)596 private static PulseAudio.Volume double_to_volume (double vol)
540 {597 {
541598
=== modified file 'src/volume-control.vala'
--- src/volume-control.vala 2015-08-12 14:00:56 +0000
+++ src/volume-control.vala 2015-10-05 12:20:39 +0000
@@ -28,6 +28,17 @@
28 VOLUME_STREAM_CHANGE28 VOLUME_STREAM_CHANGE
29 }29 }
3030
31 public enum ActiveOutput {
32 SPEAKERS,
33 HEADPHONES,
34 BLUETOOTH_HEADPHONES,
35 BLUETOOTH_SPEAKER,
36 USB_SPEAKER,
37 USB_HEADPHONES,
38 HDMI_SPEAKER,
39 HDMI_HEADPHONES
40 }
41
31 public class Volume : Object {42 public class Volume : Object {
32 public double volume;43 public double volume;
33 public VolumeReasons reason;44 public VolumeReasons reason;
@@ -39,6 +50,7 @@
39 public virtual bool high_volume { get { return false; } protected set { } }50 public virtual bool high_volume { get { return false; } protected set { } }
40 public virtual bool mute { get { return false; } }51 public virtual bool mute { get { return false; } }
41 public virtual bool is_playing { get { return false; } }52 public virtual bool is_playing { get { return false; } }
53 public virtual VolumeControl.ActiveOutput active_output { get { return VolumeControl.ActiveOutput.SPEAKERS; } }
42 private Volume _volume;54 private Volume _volume;
43 public virtual Volume volume { get { return _volume; } set { } }55 public virtual Volume volume { get { return _volume; } set { } }
44 public virtual double mic_volume { get { return 0.0; } set { } }56 public virtual double mic_volume { get { return 0.0; } set { } }
@@ -56,4 +68,6 @@
56 v.reason = reason;68 v.reason = reason;
57 this.volume = v;69 this.volume = v;
58 }70 }
71
72 public signal void active_output_changed (VolumeControl.ActiveOutput active_output);
59}73}
6074
=== modified file 'tests/notifications-test.cc'
--- tests/notifications-test.cc 2015-08-11 22:19:36 +0000
+++ tests/notifications-test.cc 2015-10-05 12:20:39 +0000
@@ -345,7 +345,7 @@
345 auto notev = notifications->getNotifications();345 auto notev = notifications->getNotifications();
346 ASSERT_EQ(1, notev.size());346 ASSERT_EQ(1, notev.size());
347 EXPECT_EQ("Volume", notev[0].summary);347 EXPECT_EQ("Volume", notev[0].summary);
348 EXPECT_EQ("", notev[0].body);348 EXPECT_EQ("Speakers", notev[0].body);
349 EXPECT_GVARIANT_EQ("@s 'false'", notev[0].hints["x-canonical-value-bar-tint"]);349 EXPECT_GVARIANT_EQ("@s 'false'", notev[0].hints["x-canonical-value-bar-tint"]);
350350
351 /* Set high volume with volume change */351 /* Set high volume with volume change */

Subscribers

People subscribed via source and target branches