mirror of
https://github.com/Rafostar/clapper.git
synced 2025-08-30 07:42:23 +02:00
Swipe when fullscreen to seek or adjust volume
This commit is contained in:
@@ -44,6 +44,13 @@ class ClapperPlayer extends PlayerBase
|
|||||||
dragGesture.connect('drag-update', this._onWidgetDragUpdate.bind(this));
|
dragGesture.connect('drag-update', this._onWidgetDragUpdate.bind(this));
|
||||||
this.widget.add_controller(dragGesture);
|
this.widget.add_controller(dragGesture);
|
||||||
|
|
||||||
|
const swipeGesture = new Gtk.GestureSwipe({
|
||||||
|
touch_only: true,
|
||||||
|
});
|
||||||
|
swipeGesture.connect('swipe', this._onWidgetSwipe.bind(this));
|
||||||
|
swipeGesture.connect('update', this._onWidgetSwipeUpdate.bind(this));
|
||||||
|
this.widget.add_controller(swipeGesture);
|
||||||
|
|
||||||
const keyController = new Gtk.EventControllerKey();
|
const keyController = new Gtk.EventControllerKey();
|
||||||
keyController.connect('key-pressed', this._onWidgetKeyPressed.bind(this));
|
keyController.connect('key-pressed', this._onWidgetKeyPressed.bind(this));
|
||||||
keyController.connect('key-released', this._onWidgetKeyReleased.bind(this));
|
keyController.connect('key-released', this._onWidgetKeyReleased.bind(this));
|
||||||
@@ -259,10 +266,12 @@ class ClapperPlayer extends PlayerBase
|
|||||||
controls.positionScale.set_value(positionSeconds);
|
controls.positionScale.set_value(positionSeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
adjust_volume(isIncrease)
|
adjust_volume(isIncrease, offset)
|
||||||
{
|
{
|
||||||
|
offset = offset || 0.05;
|
||||||
|
|
||||||
const { controls } = this.widget.get_ancestor(Gtk.Grid);
|
const { controls } = this.widget.get_ancestor(Gtk.Grid);
|
||||||
const value = (isIncrease) ? 0.05 : -0.05;
|
const value = (isIncrease) ? offset : -offset;
|
||||||
const volume = controls.volumeScale.get_value() + value;
|
const volume = controls.volumeScale.get_value() + value;
|
||||||
|
|
||||||
controls.volumeScale.set_value(volume);
|
controls.volumeScale.set_value(volume);
|
||||||
@@ -292,6 +301,21 @@ class ClapperPlayer extends PlayerBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getIsSwipeOk(velocity, otherVelocity)
|
||||||
|
{
|
||||||
|
if(!velocity)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const absVel = Math.abs(velocity);
|
||||||
|
|
||||||
|
if(absVel < 20 || Math.abs(otherVelocity) * 1.5 >= absVel)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const clapperWidget = this.widget.get_ancestor(Gtk.Grid);
|
||||||
|
|
||||||
|
return clapperWidget.fullscreenMode;
|
||||||
|
}
|
||||||
|
|
||||||
_setHideCursorTimeout()
|
_setHideCursorTimeout()
|
||||||
{
|
{
|
||||||
this._clearTimeout('hideCursor');
|
this._clearTimeout('hideCursor');
|
||||||
@@ -723,6 +747,27 @@ class ClapperPlayer extends PlayerBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_onWidgetSwipe(gesture, velocityX, velocityY)
|
||||||
|
{
|
||||||
|
if(!this.getIsSwipeOk(velocityX, velocityY))
|
||||||
|
return;
|
||||||
|
|
||||||
|
this._onScroll(gesture, -velocityX, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
_onWidgetSwipeUpdate(gesture, sequence)
|
||||||
|
{
|
||||||
|
const [isCalc, velocityX, velocityY] = gesture.get_velocity();
|
||||||
|
if(!isCalc) return;
|
||||||
|
|
||||||
|
if(!this.getIsSwipeOk(velocityY, velocityX))
|
||||||
|
return;
|
||||||
|
|
||||||
|
const isIncrease = velocityY < 0;
|
||||||
|
|
||||||
|
this.adjust_volume(isIncrease, 0.01);
|
||||||
|
}
|
||||||
|
|
||||||
_onScroll(controller, dx, dy)
|
_onScroll(controller, dx, dy)
|
||||||
{
|
{
|
||||||
const isHorizontal = (Math.abs(dx) >= Math.abs(dy));
|
const isHorizontal = (Math.abs(dx) >= Math.abs(dy));
|
||||||
|
Reference in New Issue
Block a user