aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2014-02-25 15:50:44 -0600
committerTed Gould <ted@gould.cx>2014-02-25 15:50:44 -0600
commitc003018253a7f1574c5f370bf2e1c2148e1df328 (patch)
tree938cf52caa3dccd85e7b48e0161473b316674f41 /src
parent0b93aa745830a32185f4383ba3813fbbd307bdf2 (diff)
parent69231381cb7656b551d860c441b8d9750f9f5bc2 (diff)
downloadayatana-indicator-sound-c003018253a7f1574c5f370bf2e1c2148e1df328.tar.gz
ayatana-indicator-sound-c003018253a7f1574c5f370bf2e1c2148e1df328.tar.bz2
ayatana-indicator-sound-c003018253a7f1574c5f370bf2e1c2148e1df328.zip
Merge trunk and export
Diffstat (limited to 'src')
-rw-r--r--src/accounts-service-user.vala6
-rw-r--r--src/service.vala55
2 files changed, 53 insertions, 8 deletions
diff --git a/src/accounts-service-user.vala b/src/accounts-service-user.vala
index 03aeb25..f021764 100644
--- a/src/accounts-service-user.vala
+++ b/src/accounts-service-user.vala
@@ -27,10 +27,13 @@ public class AccountsServiceUser : Object {
public MediaPlayer? player {
set {
this._player = value;
+ debug("New player: %s", this._player != null ? this._player.name : "Cleared");
/* No proxy, no settings to set */
- if (this.proxy == null)
+ if (this.proxy == null) {
+ debug("Nothing written to Accounts Service, waiting on proxy");
return;
+ }
/* Always reset the timer */
if (this.timer != 0) {
@@ -68,6 +71,7 @@ public class AccountsServiceUser : Object {
}
this.timer = GLib.Timeout.add_seconds(5 * 60, () => {
+ debug("Writing timestamp");
this.proxy.timestamp = GLib.get_monotonic_time();
return true;
});
diff --git a/src/service.vala b/src/service.vala
index 7b88e1b..be0164d 100644
--- a/src/service.vala
+++ b/src/service.vala
@@ -17,9 +17,10 @@
* Lars Uebernickel <lars.uebernickel@canonical.com>
*/
-public class IndicatorSound.Service {
+public class IndicatorSound.Service: Object {
public Service (MediaPlayerList playerlist) {
this.settings = new Settings ("com.canonical.indicator.sound");
+ this.sharedsettings = new Settings ("com.ubuntu.sound");
this.volume_control = new VolumeControl ();
@@ -58,6 +59,8 @@ public class IndicatorSound.Service {
this.notification.set_hint_string ("x-canonical-private-synchronous", "indicator-sound");
}
}
+
+ sharedsettings.bind ("allow-amplified-volume", this, "allow-amplified-volume", SettingsBindFlags.GET);
}
public int run () {
@@ -75,6 +78,25 @@ public class IndicatorSound.Service {
return 0;
}
+ public bool allow_amplified_volume {
+ get {
+ return this.max_volume > 1.0;
+ }
+
+ set {
+ if (value) {
+ /* from pulse/volume.h: #define PA_VOLUME_UI_MAX (pa_sw_volume_from_dB(+11.0)) */
+ this.max_volume = (double)PulseAudio.Volume.sw_from_dB(11.0) / PulseAudio.Volume.NORM;
+ }
+ else {
+ this.max_volume = 1.0;
+ }
+
+ /* Normalize volume, because the volume action's state is [0.0, 1.0], see create_volume_action() */
+ this.actions.change_action_state ("volume", this.volume_control.get_volume () / this.max_volume);
+ }
+ }
+
const ActionEntry[] action_entries = {
{ "root", null, null, "@a{sv} {}", null },
{ "scroll", activate_scroll_action, "i", null, null },
@@ -86,6 +108,7 @@ public class IndicatorSound.Service {
SimpleActionGroup actions;
HashTable<string, SoundMenu> menus;
Settings settings;
+ Settings sharedsettings;
VolumeControl volume_control;
MediaPlayerList players;
uint player_action_update_id;
@@ -93,13 +116,18 @@ public class IndicatorSound.Service {
bool syncing_preferred_players = false;
AccountsServiceUser? accounts_service = null;
+ /* Maximum volume as a scaling factor between the volume action's state and the value in
+ * this.volume_control. See create_volume_action().
+ */
+ double max_volume = 1.0;
+
const double volume_step_percentage = 0.06;
void activate_scroll_action (SimpleAction action, Variant? param) {
int delta = param.get_int32(); /* positive for up, negative for down */
double v = this.volume_control.get_volume () + volume_step_percentage * delta;
- this.volume_control.set_volume (v.clamp (0.0, 1.0));
+ this.volume_control.set_volume (v.clamp (0.0, this.max_volume));
if (this.notification != null) {
string icon;
@@ -206,22 +234,35 @@ public class IndicatorSound.Service {
void volume_changed (double volume) {
var volume_action = this.actions.lookup_action ("volume") as SimpleAction;
- volume_action.set_state (new Variant.double (volume));
+
+ /* Normalize volume, because the volume action's state is [0.0, 1.0], see create_volume_action() */
+ volume_action.set_state (new Variant.double (volume / this.max_volume));
this.update_root_icon ();
}
Action create_volume_action () {
- var volume_action = new SimpleAction.stateful ("volume", VariantType.INT32, new Variant.double (this.volume_control.get_volume ()));
+ /* The action's state is between be in [0.0, 1.0] instead of [0.0,
+ * max_volume], so that we don't need to update the slider menu item
+ * every time allow-amplified-volume is changed. Convert between the
+ * two here, so that we always pass the full range into
+ * volume_control.set_volume().
+ */
+
+ double volume = this.volume_control.get_volume () / this.max_volume;
+
+ var volume_action = new SimpleAction.stateful ("volume", VariantType.INT32, new Variant.double (volume));
volume_action.change_state.connect ( (action, val) => {
- volume_control.set_volume (val.get_double ());
+ double v = val.get_double () * this.max_volume;
+ volume_control.set_volume (v.clamp (0.0, this.max_volume));
});
/* activating this action changes the volume by the amount given in the parameter */
volume_action.activate.connect ( (action, param) => {
- double v = volume_control.get_volume () + volume_step_percentage * param.get_int32 ();
- volume_control.set_volume (v.clamp (0.0, 1.0));
+ int delta = param.get_int32 ();
+ double v = volume_control.get_volume () + volume_step_percentage * delta;
+ volume_control.set_volume (v.clamp (0.0, this.max_volume));
});
this.volume_control.volume_changed.connect (volume_changed);