From a6dfeeca37e4583ab431cf01685815880329493d Mon Sep 17 00:00:00 2001 From: Rafostar <40623528+Rafostar@users.noreply.github.com> Date: Sun, 18 Jul 2021 15:05:00 +0200 Subject: [PATCH] Switch playlist items via double tap on screen side Double press left side of the touchscreen to play previous item, right side to play next one. #93 --- src/misc.js | 13 +++++++++++++ src/widget.js | 42 +++++++++++++++++++++++++++--------------- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/src/misc.js b/src/misc.js index 069f3082..46c4171e 100644 --- a/src/misc.js +++ b/src/misc.js @@ -219,6 +219,19 @@ function getUriProtocol(uri) return (arr.length > 1) ? arr[0] : null; } +function getIsTouch(gesture) +{ + const { source } = gesture.get_device(); + + switch(source) { + case Gdk.InputSource.PEN: + case Gdk.InputSource.TOUCHSCREEN: + return true; + default: + return false; + } +} + function encodeHTML(text) { return text.replace(/&/g, '&') diff --git a/src/widget.js b/src/widget.js index 876457ba..4c6fcc1c 100644 --- a/src/widget.js +++ b/src/widget.js @@ -676,6 +676,26 @@ class ClapperWidget extends Gtk.Grid }); } + _handleDoublePress(gesture, x, y) + { + if(!this.isFullscreenMode || !Misc.getIsTouch(gesture)) + return this.toggleFullscreen(); + + const fieldSize = this.layoutWidth / 6; + + if(x < fieldSize) { + debug('left side double press'); + this.player.playlistWidget.prevTrack(); + } + else if(x > this.layoutWidth - fieldSize) { + debug('right side double press'); + this.player.playlistWidget.nextTrack(); + } + else { + this.toggleFullscreen(); + } + } + _getClickGesture() { const clickGesture = new Gtk.GestureClick({ @@ -767,6 +787,7 @@ class ClapperWidget extends Gtk.Grid { const button = gesture.get_current_button(); const isDouble = (nPress % 2 == 0); + this.isDragAllowed = !isDouble; this.isSwipePerformed = false; this.isLongPressed = false; @@ -774,7 +795,7 @@ class ClapperWidget extends Gtk.Grid switch(button) { case Gdk.BUTTON_PRIMARY: if(isDouble) - this.toggleFullscreen(); + this._handleDoublePress(gesture, x, y); break; case Gdk.BUTTON_SECONDARY: this.player.toggle_play(); @@ -788,20 +809,11 @@ class ClapperWidget extends Gtk.Grid { /* 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) { - case Gdk.InputSource.PEN: - case Gdk.InputSource.TOUCHSCREEN: - this.revealControls(); - break; - default: - break; - } - } + ((!this.isSwipePerformed && !this.isLongPressed) + || this.revealerBottom.child_revealed) + && Misc.getIsTouch(gesture) + ) + this.revealControls(); } _onLongPressed(gesture, x, y)