From 70ec6311c01a00b2851693362d7269cc42adb4dd Mon Sep 17 00:00:00 2001 From: Rafostar <40623528+Rafostar@users.noreply.github.com> Date: Wed, 2 Sep 2020 18:31:22 +0200 Subject: [PATCH] Add seeking on slider drop and make it default behaviour Seeking during slider drag is very CPU and HDD intensive task. We are requesting the player to keep seeking in VERY short amounts of time. This can be performed more effectively by doing a single seek after slider drop. Since this is a different behaviour then usually in media players, I am making this optional (enabled by default). --- clapper_src/controls.js | 28 ++++++++++++++++++++++++++-- clapper_src/interface.js | 28 +++++++++++++++++++++++++--- 2 files changed, 51 insertions(+), 5 deletions(-) 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;