aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2015-08-11 15:10:56 -0500
committerCharles Kerr <charles.kerr@canonical.com>2015-08-11 15:10:56 -0500
commitf52fe2483aae720b92878272f052b8fc6605dcd9 (patch)
tree482b18696c6f7bfb99582cfcc32c16ca47be17e5
parent8e7aa6d1ba5f62c4525c7d20e674ce8ef579040b (diff)
downloadayatana-indicator-sound-f52fe2483aae720b92878272f052b8fc6605dcd9.tar.gz
ayatana-indicator-sound-f52fe2483aae720b92878272f052b8fc6605dcd9.tar.bz2
ayatana-indicator-sound-f52fe2483aae720b92878272f052b8fc6605dcd9.zip
clamp the volume whenever the 'high volume' confirmation notification is open.
-rw-r--r--src/service.vala34
-rw-r--r--src/volume-control-pulse.vala23
-rw-r--r--src/volume-control.vala1
3 files changed, 47 insertions, 11 deletions
diff --git a/src/service.vala b/src/service.vala
index 994de30..c8382a5 100644
--- a/src/service.vala
+++ b/src/service.vala
@@ -139,6 +139,8 @@ public class IndicatorSound.Service: Object {
clear_acts_player();
+ stop_clamp_volume_timeout();
+
if (this.player_action_update_id > 0) {
Source.remove (this.player_action_update_id);
this.player_action_update_id = 0;
@@ -416,7 +418,9 @@ public class IndicatorSound.Service: Object {
}
private void update_volume_action_state() {
- volume_action.set_state(create_volume_action_state());
+ var state = create_volume_action_state();
+ message("updating volume_action state to %s", state.print(true));
+ volume_action.set_state(state);
}
private SimpleAction volume_action;
@@ -445,6 +449,11 @@ public class IndicatorSound.Service: Object {
if (reason == VolumeControl.VolumeReasons.USER_KEYPRESS ||
reason == VolumeControl.VolumeReasons.DEVICE_OUTPUT_CHANGE)
this.update_notification ();
+
+ /* if the volume changes while the "high volume"
+ * warning dialog is up, clamp to high-volume */
+ if (this.warn_notification.id != 0)
+ this.clamp_volume_soon();
});
this.volume_control.bind_property ("ready", volume_action, "enabled", BindingFlags.SYNC_CREATE);
@@ -598,4 +607,27 @@ public class IndicatorSound.Service: Object {
this.update_preferred_players ();
}
+
+ /** VOLUME CLAMPING **/
+
+ private uint _clamp_volume_timeout = 0;
+
+ private void stop_clamp_volume_timeout() {
+ if (_clamp_volume_timeout != 0) {
+ Source.remove(_clamp_volume_timeout);
+ _clamp_volume_timeout = 0;
+ }
+ }
+
+ private void clamp_volume_soon() {
+ const uint interval_msec = 200; /* arbitrary, but works */
+ if (_clamp_volume_timeout == 0)
+ _clamp_volume_timeout = Timeout.add(interval_msec, clamp_volume_idle);
+ }
+
+ private bool clamp_volume_idle() {
+ _clamp_volume_timeout = 0;
+ volume_control.clamp_to_high_volume();
+ return false; // Source.REMOVE;
+ }
}
diff --git a/src/volume-control-pulse.vala b/src/volume-control-pulse.vala
index 7f0edcb..edbfd23 100644
--- a/src/volume-control-pulse.vala
+++ b/src/volume-control-pulse.vala
@@ -616,16 +616,6 @@ public class VolumeControlPulse : VolumeControl
return _volume;
}
set {
-
- if ((value.reason == VolumeReasons.USER_KEYPRESS)
- && !_high_volume_approved
- && calculate_high_volume_from_volume(value.volume))
- {
- var clamped = value.volume.clamp(0, _warning_volume_norms);
- message("User is trying to raise volume past warning... clamping from %f down to %f", value.volume, clamped);
- value.volume = clamped;
- }
-
var volume_changed = (value.volume != _volume.volume);
debug("Setting volume to %f for profile %d because %d", value.volume, _active_sink_input, value.reason);
@@ -722,6 +712,19 @@ public class VolumeControlPulse : VolumeControl
&& (stream == "multimedia");
}
+ public override void clamp_to_high_volume() {
+ if (_high_volume) {
+ message("_volume.volume(%f) _warning_volume_norms(%f)", _volume.volume, _warning_volume_norms);
+ if (_volume.volume > _warning_volume_norms) {
+ var vol = new VolumeControl.Volume();
+ vol.volume = _volume.volume.clamp(0, _warning_volume_norms);
+ vol.reason = _volume.reason;
+ message("Clamping from %f down to %f", _volume.volume, vol.volume);
+ volume = vol;
+ }
+ }
+ }
+
/** HIGH VOLUME APPROVED PROPERTY **/
private bool _high_volume_approved = false;
diff --git a/src/volume-control.vala b/src/volume-control.vala
index 36d7083..a30a373 100644
--- a/src/volume-control.vala
+++ b/src/volume-control.vala
@@ -46,6 +46,7 @@ public abstract class VolumeControl : Object
public virtual bool high_volume_approved { get { return false; } protected set { } }
public virtual void approve_high_volume() { }
+ public virtual void clamp_to_high_volume() { }
public abstract void set_mute (bool mute);