From 234c49221e5566a988639a4b935daf7285c613ad Mon Sep 17 00:00:00 2001 From: Rafostar <40623528+Rafostar@users.noreply.github.com> Date: Mon, 14 Sep 2020 16:10:09 +0200 Subject: [PATCH] Enable scroll on volume button --- clapper_src/app.js | 47 ++-------------------------------------- clapper_src/controls.js | 46 ++++++++++++++++++++++++++++++++++++++- clapper_src/interface.js | 4 ++++ 3 files changed, 51 insertions(+), 46 deletions(-) diff --git a/clapper_src/app.js b/clapper_src/app.js index 709751aa..4ef618c2 100644 --- a/clapper_src/app.js +++ b/clapper_src/app.js @@ -149,9 +149,6 @@ var App = GObject.registerClass({ this.player.connectWidget( 'button-press-event', this._onPlayerButtonPressEvent.bind(this) ); - this.player.connectWidget( - 'scroll-event', this._onPlayerScrollEvent.bind(this) - ); this.player.connectWidget( 'enter-notify-event', this._onPlayerEnterNotifyEvent.bind(this) ); @@ -212,12 +209,12 @@ var App = GObject.registerClass({ bool = true; case Gdk.KEY_Left: // disabled due to missing "seek on drop" support - //this._handleScaleIncrement('position', bool); + //this.interface.controls.handleScaleIncrement('position', bool); break; case Gdk.KEY_Up: bool = true; case Gdk.KEY_Down: - this._handleScaleIncrement('volume', bool); + this.interface.controls.handleScaleIncrement('volume', bool); break; case Gdk.KEY_F11: this.window.toggleFullscreen(); @@ -340,46 +337,6 @@ var App = GObject.registerClass({ } } - _onPlayerScrollEvent(self, event) - { - let [res, direction] = event.get_scroll_direction(); - if(!res) return; - - let type = 'volume'; - - switch(direction) { - case Gdk.ScrollDirection.RIGHT: - case Gdk.ScrollDirection.LEFT: - type = 'position'; - case Gdk.ScrollDirection.UP: - case Gdk.ScrollDirection.DOWN: - let isUp = ( - direction === Gdk.ScrollDirection.UP - || direction === Gdk.ScrollDirection.RIGHT - ); - this._handleScaleIncrement(type, isUp); - break; - default: - break; - } - } - - _handleScaleIncrement(type, isUp) - { - let value = this.interface.controls[`${type}Scale`].get_value(); - let maxValue = this.interface.controls[`${type}Adjustment`].get_upper(); - let increment = this.interface.controls[`${type}Adjustment`].get_page_increment(); - - value += (isUp) ? increment : -increment; - value = (value < 0) - ? 0 - : (value > maxValue) - ? maxValue - : value; - - this.interface.controls[`${type}Scale`].set_value(value); - } - _onPlayerEnterNotifyEvent(self, event) { this.isCursorInPlayer = true; diff --git a/clapper_src/controls.js b/clapper_src/controls.js index d8186282..9f33251f 100644 --- a/clapper_src/controls.js +++ b/clapper_src/controls.js @@ -1,4 +1,4 @@ -const { GObject, Gtk } = imports.gi; +const { GObject, Gdk, Gtk } = imports.gi; const Buttons = imports.clapper_src.buttons; const Debug = imports.clapper_src.debug; @@ -187,6 +187,22 @@ var Controls = GObject.registerClass({ this.volumeScale.add_mark(2, Gtk.PositionType.LEFT, '200%'); } + handleScaleIncrement(type, isUp) + { + let value = this[`${type}Scale`].get_value(); + let maxValue = this[`${type}Adjustment`].get_upper(); + let increment = this[`${type}Adjustment`].get_page_increment(); + + value += (isUp) ? increment : -increment; + value = (value < 0) + ? 0 + : (value > maxValue) + ? maxValue + : value; + + this[`${type}Scale`].set_value(value); + } + _addTogglePlayButton() { this.togglePlayButton = this.addButton( @@ -239,6 +255,10 @@ var Controls = GObject.registerClass({ this.volumeButton = this.addPopoverButton( 'audio-volume-muted-symbolic' ); + this.volumeButton.add_events(Gdk.EventMask.SCROLL_MASK); + this.volumeButton.connect( + 'scroll-event', (self, event) => this._onScrollEvent(event) + ); this.volumeScale = new Gtk.Scale({ orientation: Gtk.Orientation.VERTICAL, inverted: true, @@ -330,4 +350,28 @@ var Controls = GObject.registerClass({ for(let name of hiddenButtons) this[`${name}Button`].hide(); } + + _onScrollEvent(event) + { + let [res, direction] = event.get_scroll_direction(); + if(!res) return; + + let type = 'volume'; + + switch(direction) { + case Gdk.ScrollDirection.RIGHT: + case Gdk.ScrollDirection.LEFT: + type = 'position'; + case Gdk.ScrollDirection.UP: + case Gdk.ScrollDirection.DOWN: + let isUp = ( + direction === Gdk.ScrollDirection.UP + || direction === Gdk.ScrollDirection.RIGHT + ); + this.handleScaleIncrement(type, isUp); + break; + default: + break; + } + } }); diff --git a/clapper_src/interface.js b/clapper_src/interface.js index 91b5a157..2e17a183 100644 --- a/clapper_src/interface.js +++ b/clapper_src/interface.js @@ -52,6 +52,10 @@ class ClapperInterface extends Gtk.Grid this._player.connect('duration-changed', this._onPlayerDurationChanged.bind(this)); this._player.connect('position-updated', this._onPlayerPositionUpdated.bind(this)); + this._player.connectWidget( + 'scroll-event', (self, event) => this.controls._onScrollEvent(event) + ); + this.controls.togglePlayButton.connect( 'clicked', this._onControlsTogglePlayClicked.bind(this) );