Enable scroll on volume button

This commit is contained in:
Rafostar
2020-09-14 16:10:09 +02:00
parent 71659491c0
commit 234c49221e
3 changed files with 51 additions and 46 deletions

View File

@@ -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;

View File

@@ -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;
}
}
});

View File

@@ -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)
);