Add long press gesture to toggle play/pause #93

Press and hold on touchscreen while in fullscreen to toggle between play and pause
This commit is contained in:
Rafał Dzięgiel
2021-07-16 18:31:26 +02:00
parent c6b252f261
commit 5378facb46

View File

@@ -32,6 +32,7 @@ class ClapperWidget extends Gtk.Grid
this.isDragAllowed = false;
this.isSwipePerformed = false;
this.isReleaseKeyEnabled = false;
this.isLongPressed = false;
this.isCursorInPlayer = false;
this.isPopoverOpen = false;
@@ -83,6 +84,11 @@ class ClapperWidget extends Gtk.Grid
const clickGestureTop = this._getClickGesture();
this.revealerTop.add_controller(clickGestureTop);
const longPressGesture = this._getLongPressGesture();
playerWidget.add_controller(longPressGesture);
const longPressGestureTop = this._getLongPressGesture();
this.revealerTop.add_controller(longPressGestureTop);
const dragGesture = this._getDragGesture();
playerWidget.add_controller(dragGesture);
const dragGestureTop = this._getDragGesture();
@@ -672,14 +678,26 @@ class ClapperWidget extends Gtk.Grid
_getClickGesture()
{
const clickGesture = new Gtk.GestureClick();
clickGesture.set_button(0);
const clickGesture = new Gtk.GestureClick({
button: 0,
});
clickGesture.connect('pressed', this._onPressed.bind(this));
clickGesture.connect('released', this._onReleased.bind(this));
return clickGesture;
}
_getLongPressGesture()
{
const longPressGesture = new Gtk.GestureLongPress({
touch_only: true,
delay_factor: 0.9,
});
longPressGesture.connect('pressed', this._onLongPressed.bind(this));
return longPressGesture;
}
_getDragGesture()
{
const dragGesture = new Gtk.GestureDrag();
@@ -751,6 +769,7 @@ class ClapperWidget extends Gtk.Grid
const isDouble = (nPress % 2 == 0);
this.isDragAllowed = !isDouble;
this.isSwipePerformed = false;
this.isLongPressed = false;
switch(button) {
case Gdk.BUTTON_PRIMARY:
@@ -767,8 +786,11 @@ class ClapperWidget extends Gtk.Grid
_onReleased(gesture, nPress, x, y)
{
/* Reveal if touch was not a swipe or was already revealed */
if(!this.isSwipePerformed || this.revealerBottom.child_revealed) {
/* Reveal if touch was not a swipe/long press or was already revealed */
if(
(!this.isSwipePerformed && !this.isLongPressed)
|| this.revealerBottom.child_revealed
) {
const { source } = gesture.get_device();
switch(source) {
@@ -782,6 +804,15 @@ class ClapperWidget extends Gtk.Grid
}
}
_onLongPressed(gesture, x, y)
{
if(!this.isDragAllowed || !this.isFullscreenMode)
return;
this.isLongPressed = true;
this.player.toggle_play();
}
_onKeyReleased(controller, keyval, keycode, state)
{
/* Ignore releases that did not trigger keypress