aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/service.vala39
-rw-r--r--src/sound-menu.vala11
-rw-r--r--src/volume-control-pulse.vala20
-rw-r--r--src/volume-control.vala7
4 files changed, 64 insertions, 13 deletions
diff --git a/src/service.vala b/src/service.vala
index 985d434..0a7e108 100644
--- a/src/service.vala
+++ b/src/service.vala
@@ -40,7 +40,11 @@ public class IndicatorSound.Service: Object {
warn_notification.set_hint ("x-canonical-non-shaped-icon", "true");
warn_notification.set_hint ("x-canonical-snap-decisions", "true");
warn_notification.set_hint ("x-canonical-private-affirmative-tint", "true");
- warn_notification.closed.connect((n) => { n.clear_actions(); waiting_user_approve_warn=false; });
+ warn_notification.closed.connect((n) => {
+ n.clear_actions();
+ waiting_user_approve_warn=false;
+ increment_volume_sync_action();
+ });
BusWatcher.watch_namespace (GLib.BusType.SESSION,
"org.freedesktop.Notifications",
() => { debug("Notifications name appeared"); },
@@ -77,6 +81,7 @@ public class IndicatorSound.Service: Object {
this.actions.add_action (this.create_volume_action ());
this.actions.add_action (this.create_mic_volume_action ());
this.actions.add_action (this.create_high_volume_action ());
+ this.actions.add_action (this.create_volume_sync_action ());
this.menus = new HashTable<string, SoundMenu> (str_hash, str_equal);
this.menus.insert ("desktop_greeter", new SoundMenu (null, SoundMenu.DisplayFlags.SHOW_MUTE | SoundMenu.DisplayFlags.HIDE_PLAYERS | SoundMenu.DisplayFlags.GREETER_PLAYERS));
@@ -606,9 +611,11 @@ public class IndicatorSound.Service: Object {
notify_server_caps_checked = true;
var loud = volume_control.high_volume;
+ bool ignore_warning_this_time = this.volume_control.ignore_high_volume;
var warn = loud
&& this.notify_server_supports_actions
- && !this.volume_control.high_volume_approved;
+ && !this.volume_control.high_volume_approved
+ && !ignore_warning_this_time;
if (waiting_user_approve_warn && volume_control.below_warning_volume) {
volume_control.set_warning_volume();
close_notification(warn_notification);
@@ -624,16 +631,19 @@ public class IndicatorSound.Service: Object {
warn_notification.add_action ("ok", _("OK"), (n, a) => {
stop_clamp_to_high_timeout();
volume_control.approve_high_volume ();
- if (_pre_warn_volume != null) {
- var tmp = _pre_warn_volume;
- _pre_warn_volume = null;
- volume_control.volume = tmp;
- }
+ // restore the volume the user introduced
+ VolumeControl.Volume vol = new VolumeControl.Volume();
+ vol.volume = volume_control.get_pre_clamped_volume();
+ vol.reason = VolumeControl.VolumeReasons.USER_KEYPRESS;
+ _pre_warn_volume = null;
+ volume_control.volume = vol;
+
waiting_user_approve_warn = false;
});
warn_notification.add_action ("cancel", _("Cancel"), (n, a) => {
_pre_warn_volume = null;
waiting_user_approve_warn = false;
+ increment_volume_sync_action();
});
waiting_user_approve_warn = true;
show_notification(warn_notification);
@@ -641,8 +651,7 @@ public class IndicatorSound.Service: Object {
if (!waiting_user_approve_warn) {
close_notification(warn_notification);
- if (notify_server_supports_sync && !block_info_notifications) {
-
+ if (notify_server_supports_sync && !block_info_notifications && !ignore_warning_this_time) {
/* Determine Label */
string volume_label = get_notification_label ();
@@ -818,6 +827,18 @@ public class IndicatorSound.Service: Object {
return high_volume_action;
}
+ SimpleAction volume_sync_action;
+ uint64 volume_sync_number_ = 0;
+ Action create_volume_sync_action () {
+ volume_sync_action = new SimpleAction.stateful("volume-sync", VariantType.UINT64, new Variant.uint64 (volume_sync_number_));
+
+ return volume_sync_action;
+ }
+
+ void increment_volume_sync_action () {
+ volume_sync_action.set_state(new Variant.uint64 (++volume_sync_number_));
+ }
+
uint export_actions = 0;
Variant action_state_for_player (MediaPlayer player, bool show_track = true) {
diff --git a/src/sound-menu.vala b/src/sound-menu.vala
index 3d682e4..bdb8df2 100644
--- a/src/sound-menu.vala
+++ b/src/sound-menu.vala
@@ -46,7 +46,7 @@ public class SoundMenu: Object
volume_section.append_item (this.create_slider_menu_item (_("Volume"), "indicator.volume(0)", 0.0, 1.0, 0.01,
"audio-volume-low-zero-panel",
- "audio-volume-high-panel"));
+ "audio-volume-high-panel", true));
this.menu = new Menu ();
this.menu.append_section (null, volume_section);
@@ -101,7 +101,7 @@ public class SoundMenu: Object
if (value && !this.mic_volume_shown) {
var slider = this.create_slider_menu_item (_("Microphone Volume"), "indicator.mic-volume", 0.0, 1.0, 0.01,
"audio-input-microphone-low-zero-panel",
- "audio-input-microphone-high-panel");
+ "audio-input-microphone-high-panel", false);
volume_section.append_item (slider);
this.mic_volume_shown = true;
}
@@ -227,7 +227,7 @@ public class SoundMenu: Object
this.volume_section.remove (index);
this.volume_section.insert_item (index, this.create_slider_menu_item (_(label), "indicator.volume(0)", 0.0, 1.0, 0.01,
"audio-volume-low-zero-panel",
- "audio-volume-high-panel"));
+ "audio-volume-high-panel", true));
}
}
@@ -386,7 +386,7 @@ public class SoundMenu: Object
}
}
- MenuItem create_slider_menu_item (string label, string action, double min, double max, double step, string min_icon_name, string max_icon_name) {
+ MenuItem create_slider_menu_item (string label, string action, double min, double max, double step, string min_icon_name, string max_icon_name, bool sync_action) {
var min_icon = new ThemedIcon.with_default_fallbacks (min_icon_name);
var max_icon = new ThemedIcon.with_default_fallbacks (max_icon_name);
@@ -397,6 +397,9 @@ public class SoundMenu: Object
slider.set_attribute ("min-value", "d", min);
slider.set_attribute ("max-value", "d", max);
slider.set_attribute ("step", "d", step);
+ if (sync_action) {
+ slider.set_attribute ("x-canonical-sync-action", "s", "indicator.volume-sync");
+ }
return slider;
}
diff --git a/src/volume-control-pulse.vala b/src/volume-control-pulse.vala
index 66b6ba4..4bd3076 100644
--- a/src/volume-control-pulse.vala
+++ b/src/volume-control-pulse.vala
@@ -42,6 +42,7 @@ public class VolumeControlPulse : VolumeControl
private PulseAudio.Context context;
private bool _mute = true;
private bool _is_playing = false;
+ private bool _ignore_warning_this_time = false;
private VolumeControl.Volume _volume = new VolumeControl.Volume();
private double _mic_volume = 0.0;
private Settings _settings = new Settings ("com.canonical.indicator.sound");
@@ -344,6 +345,10 @@ public class VolumeControlPulse : VolumeControl
var vol = new VolumeControl.Volume();
vol.volume = volume_to_double (lvolume);
vol.reason = VolumeControl.VolumeReasons.PULSE_CHANGE;
+ // Ignore changes from PULSE to avoid issues with
+ // some apps that change the volume in the sink
+ // We only take into account volume changes from the user
+ this._ignore_warning_this_time = true;
this.volume = vol;
}
}
@@ -388,6 +393,10 @@ public class VolumeControlPulse : VolumeControl
var vol = new VolumeControl.Volume();
vol.volume = volume_to_double (volume);
vol.reason = VolumeControl.VolumeReasons.VOLUME_STREAM_CHANGE;
+ // Ignore changes from PULSE to avoid issues with
+ // some apps that change the volume in the sink
+ // We only take into account volume changes from the user
+ this._ignore_warning_this_time = true;
this.volume = vol;
} catch (GLib.Error e) {
warning ("unable to get volume for active role %s (%s)", sink_input_objp, e.message);
@@ -741,6 +750,17 @@ public class VolumeControlPulse : VolumeControl
private bool _warning_volume_enabled;
private double _warning_volume_norms; /* 1.0 == PA_VOLUME_NORM */
private bool _high_volume = false;
+ public override bool ignore_high_volume {
+ get {
+ if (_ignore_warning_this_time) {
+ warning("Ignore");
+ _ignore_warning_this_time = false;
+ return true;
+ }
+ return false;
+ }
+ set { }
+ }
public override bool high_volume {
get { return this._high_volume; }
private set { this._high_volume = value; }
diff --git a/src/volume-control.vala b/src/volume-control.vala
index 30dcfcf..90fc325 100644
--- a/src/volume-control.vala
+++ b/src/volume-control.vala
@@ -49,11 +49,13 @@ public abstract class VolumeControl : Object
public virtual bool ready { get { return false; } set { } }
public virtual bool active_mic { get { return false; } set { } }
public virtual bool high_volume { get { return false; } protected set { } }
+ public virtual bool ignore_high_volume { get { return false; } protected set { } }
public virtual bool below_warning_volume { get { return false; } protected set { } }
public virtual bool mute { get { return false; } }
public virtual bool is_playing { get { return false; } }
public virtual VolumeControl.ActiveOutput active_output { get { return VolumeControl.ActiveOutput.SPEAKERS; } }
private Volume _volume;
+ private double _pre_clamp_volume;
public virtual Volume volume { get { return _volume; } set { } }
public virtual double mic_volume { get { return 0.0; } set { } }
public virtual double max_volume { get { return 1.0; } protected set { } }
@@ -70,6 +72,11 @@ public abstract class VolumeControl : Object
v.volume = unclamped.clamp (0.0, this.max_volume);
v.reason = reason;
this.volume = v;
+ _pre_clamp_volume = unclamped;
+ }
+
+ public double get_pre_clamped_volume () {
+ return _pre_clamp_volume;
}
public signal void active_output_changed (VolumeControl.ActiveOutput active_output);