From 176ddf1cc2d3860d209c7638001721c8efca3f0f Mon Sep 17 00:00:00 2001 From: Rafostar <40623528+Rafostar@users.noreply.github.com> Date: Thu, 3 Sep 2020 10:40:58 +0200 Subject: [PATCH] Bind keyboard up/down arrow keys to volume --- clapper_src/app.js | 47 +++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/clapper_src/app.js b/clapper_src/app.js index 2a0fef1b..2fc04714 100644 --- a/clapper_src/app.js +++ b/clapper_src/app.js @@ -151,12 +151,23 @@ var App = GObject.registerClass({ if(!res) return; //let keyName = Gdk.keyval_name(key); + let bool = false; switch(key) { case Gdk.KEY_space: case Gdk.KEY_Return: this.player.toggle_play(); break; + case Gdk.KEY_Right: + bool = true; + case Gdk.KEY_Left: + //this._handleScaleIncrement('position', 'Scale', bool); + break; + case Gdk.KEY_Up: + bool = true; + case Gdk.KEY_Down: + this._handleScaleIncrement('volume', 'Button', bool); + break; case Gdk.KEY_F11: this.window.toggleFullscreen(); break; @@ -164,6 +175,10 @@ var App = GObject.registerClass({ if(this.window.isFullscreen) this.window.unfullscreen(); break; + case Gdk.KEY_q: + case Gdk.KEY_Q: + this.quit(); + break; default: break; } @@ -225,27 +240,33 @@ var App = GObject.registerClass({ item = 'Scale'; case Gdk.ScrollDirection.UP: case Gdk.ScrollDirection.DOWN: - let value = this.interface.controls[`${type}${item}`].get_value(); - let maxValue = this.interface.controls[`${type}Adjustment`].get_upper(); - let increment = this.interface.controls[`${type}Adjustment`].get_page_increment(); - value += ( + let isUp = ( direction === Gdk.ScrollDirection.UP || direction === Gdk.ScrollDirection.RIGHT - ) - ? increment - : -increment; - value = (value < 0) - ? 0 - : (value > maxValue) - ? maxValue - : value; - this.interface.controls[`${type}${item}`].set_value(value); + ); + this._handleScaleIncrement(type, item, isUp); break; default: break; } } + _handleScaleIncrement(type, item, isUp) + { + let value = this.interface.controls[`${type}${item}`].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}${item}`].set_value(value); + } + _onPlayerEnterNotifyEvent(self, event) { this.isCursorInPlayer = true;