mirror of
https://github.com/Rafostar/clapper.git
synced 2025-08-30 16:02:00 +02:00
Fix volume button icon behaviour
This commit is contained in:
37
clapper_src/controls.js
vendored
37
clapper_src/controls.js
vendored
@@ -29,7 +29,16 @@ class ClapperControls extends Gtk.HBox
|
||||
this.positionAdjustment = this.positionScale.get_adjustment();
|
||||
|
||||
this.volumeButton = new Gtk.ScaleButton({
|
||||
icons: ['audio-volume-muted-symbolic'],
|
||||
icons: [
|
||||
'audio-volume-muted-symbolic',
|
||||
'audio-volume-overamplified-symbolic',
|
||||
'audio-volume-low-symbolic',
|
||||
'audio-volume-medium-symbolic',
|
||||
'audio-volume-high-symbolic',
|
||||
'audio-volume-overamplified-symbolic',
|
||||
'audio-volume-overamplified-symbolic',
|
||||
'audio-volume-overamplified-symbolic',
|
||||
],
|
||||
size: Gtk.IconSize.SMALL_TOOLBAR
|
||||
});
|
||||
this.volumeButtonImage = this.volumeButton.get_child();
|
||||
@@ -55,14 +64,10 @@ class ClapperControls extends Gtk.HBox
|
||||
|
||||
_prepareVolumeButton()
|
||||
{
|
||||
this.volumeAdjustment.set_upper(2);
|
||||
this.volumeAdjustment.set_upper(2.001);
|
||||
this.volumeAdjustment.set_step_increment(0.05);
|
||||
this.volumeAdjustment.set_page_increment(0.05);
|
||||
|
||||
this.volumeButton.connect(
|
||||
'value-changed', this._onVolumeValueChanged.bind(this)
|
||||
);
|
||||
|
||||
let popup = this.volumeButton.get_popup();
|
||||
let box = popup.get_child();
|
||||
let boxChildren = box.get_children();
|
||||
@@ -72,29 +77,11 @@ class ClapperControls extends Gtk.HBox
|
||||
box.remove(child);
|
||||
else if(child.constructor === Gtk.Scale) {
|
||||
child.height_request = 200;
|
||||
child.round_digits = 2;
|
||||
child.add_mark(0, Gtk.PositionType.LEFT, '0%');
|
||||
child.add_mark(1, Gtk.PositionType.LEFT, '100%');
|
||||
child.add_mark(2, Gtk.PositionType.LEFT, '200%');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_onVolumeValueChanged(widget, value)
|
||||
{
|
||||
if(value <= 0)
|
||||
return;
|
||||
|
||||
let iconName = (value <= 0.33)
|
||||
? 'audio-volume-low-symbolic'
|
||||
: (value <= 0.66)
|
||||
? 'audio-volume-medium-symbolic'
|
||||
: (value <= 1)
|
||||
? 'audio-volume-high-symbolic'
|
||||
: 'audio-volume-overamplified-symbolic';
|
||||
|
||||
if(this.volumeButtonImage.icon_name === iconName)
|
||||
return;
|
||||
|
||||
this.volumeButtonImage.icon_name = iconName;
|
||||
}
|
||||
});
|
||||
|
@@ -8,6 +8,7 @@ class ClapperInterface extends Gtk.Grid
|
||||
{
|
||||
super._init();
|
||||
|
||||
this.lastVolumeValue = null;
|
||||
this.lastPositionValue = 0;
|
||||
|
||||
this.controls = new Controls();
|
||||
@@ -19,12 +20,6 @@ class ClapperInterface extends Gtk.Grid
|
||||
this._player = player;
|
||||
this._player.widget.expand = true;
|
||||
|
||||
this.attach(this._player.widget, 0, 0, 1, 1);
|
||||
this._connectControlsToPlayer();
|
||||
}
|
||||
|
||||
_connectControlsToPlayer()
|
||||
{
|
||||
this._player.connect('state-changed', this._onPlayerStateChanged.bind(this));
|
||||
this._player.connect('volume-changed', this._onPlayerVolumeChanged.bind(this));
|
||||
this._player.connect('duration-changed', this._onPlayerDurationChanged.bind(this));
|
||||
@@ -39,6 +34,8 @@ class ClapperInterface extends Gtk.Grid
|
||||
this.controls.volumeButton.connect(
|
||||
'value-changed', this._onControlsVolumeChanged.bind(this)
|
||||
);
|
||||
|
||||
this.attach(this._player.widget, 0, 0, 1, 1);
|
||||
}
|
||||
|
||||
_onPlayerStateChanged(player, state)
|
||||
@@ -85,14 +82,14 @@ class ClapperInterface extends Gtk.Grid
|
||||
this.controls.positionScale.set_value(positionSeconds);
|
||||
}
|
||||
|
||||
_onPlayerVolumeChanged(player)
|
||||
_onPlayerVolumeChanged()
|
||||
{
|
||||
let volume = player.get_volume();
|
||||
let volume = Number(this._player.get_volume().toFixed(2));
|
||||
|
||||
if(this.controls.volumeButton.value === volume)
|
||||
if(volume === this.lastVolumeValue)
|
||||
return;
|
||||
|
||||
this.controls.volumeButton.value = volume;
|
||||
this.controls.volumeButton.set_value(volume);
|
||||
}
|
||||
|
||||
_onControlsTogglePlayClicked()
|
||||
@@ -113,9 +110,10 @@ class ClapperInterface extends Gtk.Grid
|
||||
|
||||
_onControlsVolumeChanged(widget, value)
|
||||
{
|
||||
if(this._player.get_volume() === value)
|
||||
if(value === this.lastVolumeValue)
|
||||
return;
|
||||
|
||||
this.lastVolumeValue = value;
|
||||
this._player.set_volume(value);
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user