mirror of
https://github.com/Rafostar/clapper.git
synced 2025-08-30 16:02:00 +02:00
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:
@@ -32,6 +32,7 @@ class ClapperWidget extends Gtk.Grid
|
|||||||
this.isDragAllowed = false;
|
this.isDragAllowed = false;
|
||||||
this.isSwipePerformed = false;
|
this.isSwipePerformed = false;
|
||||||
this.isReleaseKeyEnabled = false;
|
this.isReleaseKeyEnabled = false;
|
||||||
|
this.isLongPressed = false;
|
||||||
|
|
||||||
this.isCursorInPlayer = false;
|
this.isCursorInPlayer = false;
|
||||||
this.isPopoverOpen = false;
|
this.isPopoverOpen = false;
|
||||||
@@ -83,6 +84,11 @@ class ClapperWidget extends Gtk.Grid
|
|||||||
const clickGestureTop = this._getClickGesture();
|
const clickGestureTop = this._getClickGesture();
|
||||||
this.revealerTop.add_controller(clickGestureTop);
|
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();
|
const dragGesture = this._getDragGesture();
|
||||||
playerWidget.add_controller(dragGesture);
|
playerWidget.add_controller(dragGesture);
|
||||||
const dragGestureTop = this._getDragGesture();
|
const dragGestureTop = this._getDragGesture();
|
||||||
@@ -672,14 +678,26 @@ class ClapperWidget extends Gtk.Grid
|
|||||||
|
|
||||||
_getClickGesture()
|
_getClickGesture()
|
||||||
{
|
{
|
||||||
const clickGesture = new Gtk.GestureClick();
|
const clickGesture = new Gtk.GestureClick({
|
||||||
clickGesture.set_button(0);
|
button: 0,
|
||||||
|
});
|
||||||
clickGesture.connect('pressed', this._onPressed.bind(this));
|
clickGesture.connect('pressed', this._onPressed.bind(this));
|
||||||
clickGesture.connect('released', this._onReleased.bind(this));
|
clickGesture.connect('released', this._onReleased.bind(this));
|
||||||
|
|
||||||
return clickGesture;
|
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()
|
_getDragGesture()
|
||||||
{
|
{
|
||||||
const dragGesture = new Gtk.GestureDrag();
|
const dragGesture = new Gtk.GestureDrag();
|
||||||
@@ -751,6 +769,7 @@ class ClapperWidget extends Gtk.Grid
|
|||||||
const isDouble = (nPress % 2 == 0);
|
const isDouble = (nPress % 2 == 0);
|
||||||
this.isDragAllowed = !isDouble;
|
this.isDragAllowed = !isDouble;
|
||||||
this.isSwipePerformed = false;
|
this.isSwipePerformed = false;
|
||||||
|
this.isLongPressed = false;
|
||||||
|
|
||||||
switch(button) {
|
switch(button) {
|
||||||
case Gdk.BUTTON_PRIMARY:
|
case Gdk.BUTTON_PRIMARY:
|
||||||
@@ -767,8 +786,11 @@ class ClapperWidget extends Gtk.Grid
|
|||||||
|
|
||||||
_onReleased(gesture, nPress, x, y)
|
_onReleased(gesture, nPress, x, y)
|
||||||
{
|
{
|
||||||
/* Reveal if touch was not a swipe or was already revealed */
|
/* Reveal if touch was not a swipe/long press or was already revealed */
|
||||||
if(!this.isSwipePerformed || this.revealerBottom.child_revealed) {
|
if(
|
||||||
|
(!this.isSwipePerformed && !this.isLongPressed)
|
||||||
|
|| this.revealerBottom.child_revealed
|
||||||
|
) {
|
||||||
const { source } = gesture.get_device();
|
const { source } = gesture.get_device();
|
||||||
|
|
||||||
switch(source) {
|
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)
|
_onKeyReleased(controller, keyval, keycode, state)
|
||||||
{
|
{
|
||||||
/* Ignore releases that did not trigger keypress
|
/* Ignore releases that did not trigger keypress
|
||||||
|
Reference in New Issue
Block a user