diff --git a/clapper_src/controls.js b/clapper_src/controls.js index 99dfc86a..55d982fc 100644 --- a/clapper_src/controls.js +++ b/clapper_src/controls.js @@ -1,7 +1,12 @@ const { GObject, Gtk } = imports.gi; -var Controls = GObject.registerClass( -class ClapperControls extends Gtk.HBox +var Controls = GObject.registerClass({ + Signals: { + 'position-seeking-changed': { + param_types: [GObject.TYPE_BOOLEAN] + }, + } +}, class ClapperControls extends Gtk.HBox { _init() { @@ -27,6 +32,13 @@ class ClapperControls extends Gtk.HBox value_pos: Gtk.PositionType.LEFT, draw_value: false }); + this.positionScale.connect( + 'button-press-event', this._onPositionScaleButtonPressEvent.bind(this) + ); + this.positionScale.connect( + 'button-release-event', this._onPositionScaleButtonReleaseEvent.bind(this) + ); + this.positionAdjustment = this.positionScale.get_adjustment(); this.pack_start(this.positionScale, true, true, 0); @@ -108,4 +120,16 @@ class ClapperControls extends Gtk.HBox } } } + + _onPositionScaleButtonPressEvent() + { + this.isPositionSeeking = true; + this.emit('position-seeking-changed', this.isPositionSeeking); + } + + _onPositionScaleButtonReleaseEvent() + { + this.isPositionSeeking = false; + this.emit('position-seeking-changed', this.isPositionSeeking); + } }); diff --git a/clapper_src/interface.js b/clapper_src/interface.js index 991a8d98..b1e14219 100644 --- a/clapper_src/interface.js +++ b/clapper_src/interface.js @@ -4,10 +4,15 @@ const { Controls } = imports.clapper_src.controls; var Interface = GObject.registerClass( class ClapperInterface extends Gtk.Grid { - _init() + _init(opts) { super._init(); + let defaults = { + seekOnDrop: true + }; + Object.assign(this, defaults, opts); + this.lastVolumeValue = null; this.lastPositionValue = 0; @@ -34,6 +39,9 @@ class ClapperInterface extends Gtk.Grid this.controls.volumeButton.connect( 'value-changed', this._onControlsVolumeChanged.bind(this) ); + this.controls.connect( + 'position-seeking-changed', this._onPositionSeekingChanged.bind(this) + ); this.attach(this._player.widget, 0, 0, 1, 1); } @@ -72,6 +80,9 @@ class ClapperInterface extends Gtk.Grid _onPlayerPositionUpdated(player, position) { + if(this.controls.isPositionSeeking) + return; + let positionSeconds = position / 1000000000; let positionFloor = Math.floor(positionSeconds); @@ -92,14 +103,25 @@ class ClapperInterface extends Gtk.Grid this.controls.volumeButton.set_value(volume); } + _onPositionSeekingChanged(self, isPositionSeeking) + { + if(isPositionSeeking || !this.seekOnDrop) + return; + + this._onControlsPositionChanged(this.controls.positionScale); + } + _onControlsTogglePlayClicked() { this._player.toggle_play(); } - _onControlsPositionChanged(range) + _onControlsPositionChanged(positionScale) { - let position = Math.floor(range.get_value()); + if(this.seekOnDrop && this.controls.isPositionSeeking) + return; + + let position = Math.floor(positionScale.get_value()); if(position === this.lastPositionValue) return;