Bind volume scale with player volume prop

Now that player API itself is operating on a cubic scale (no value conversion required), the volume slider can be bind to the volume property. Thanks to that, player volume scale will correctly reflect Clapper volume set via external applications e.g. gnome-settings.
This commit is contained in:
Rafał Dzięgiel
2021-02-24 11:09:42 +01:00
parent 775ec8a780
commit 199a8f1931
2 changed files with 20 additions and 44 deletions

41
src/controls.js vendored
View File

@@ -24,7 +24,6 @@ class ClapperControls extends Gtk.Box
can_focus: false,
});
this.currentVolume = 0;
this.currentPosition = 0;
this.currentDuration = 0;
this.isPositionDragging = false;
@@ -409,26 +408,6 @@ class ClapperControls extends Gtk.Box
this.volumeButton.popoverBox.append(this.volumeScale);
}
_updateVolumeButtonIcon(volume)
{
const icon = (volume <= 0)
? 'muted'
: (volume <= 0.3)
? 'low'
: (volume <= 0.7)
? 'medium'
: (volume <= 1)
? 'high'
: 'overamplified';
const iconName = `audio-volume-${icon}-symbolic`;
if(this.volumeButton.icon_name === iconName)
return;
this.volumeButton.set_icon_name(iconName);
debug(`set volume icon: ${icon}`);
}
_setChapterVisible(isVisible)
{
const type = (isVisible) ? 'Show' : 'Hide';
@@ -567,9 +546,6 @@ class ClapperControls extends Gtk.Box
_onVolumeScaleValueChanged(scale)
{
const volume = scale.get_value();
const { player } = this.get_ancestor(Gtk.Grid);
player.set_volume(volume);
/* FIXME: All of below should be placed in 'volume-changed'
* event once we move to message bus API */
@@ -585,7 +561,22 @@ class ClapperControls extends Gtk.Box
scale.remove_css_class(cssClass);
}
this._updateVolumeButtonIcon(volume);
const icon = (volume <= 0)
? 'muted'
: (volume <= 0.3)
? 'low'
: (volume <= 0.7)
? 'medium'
: (volume <= 1)
? 'high'
: 'overamplified';
const iconName = `audio-volume-${icon}-symbolic`;
if(this.volumeButton.icon_name === iconName)
return;
this.volumeButton.icon_name = iconName;
debug(`set volume icon: ${icon}`);
}
_onPositionScaleDragging(scale)