From d3e4f3bb0ff4f09458d04b3e794c0822547aec6e Mon Sep 17 00:00:00 2001 From: Rafostar <40623528+Rafostar@users.noreply.github.com> Date: Mon, 12 Oct 2020 16:25:54 +0200 Subject: [PATCH] Add player motion and key controllers --- clapper_src/app.js | 60 +++++++++++++++++++++------------------- clapper_src/player.js | 8 +++++- clapper_src/revealers.js | 7 +++++ clapper_src/window.js | 4 --- css/styles.css | 2 +- 5 files changed, 46 insertions(+), 35 deletions(-) diff --git a/clapper_src/app.js b/clapper_src/app.js index 86d27304..730335e1 100644 --- a/clapper_src/app.js +++ b/clapper_src/app.js @@ -39,6 +39,9 @@ var App = GObject.registerClass({ this.interface = null; this.player = null; this.dragStartReady = false; + + this.posX = 0; + this.posY = 0; } vfunc_startup() @@ -46,18 +49,15 @@ var App = GObject.registerClass({ super.vfunc_startup(); this.window = new Window(this, APP_NAME); - this.window.connect('close-request', this._onWindowCloseRequest.bind(this)); - this.window.connect('unmap', () => this.quit()); - this.windowRealizeSignal = this.window.connect( 'realize', this._onWindowRealize.bind(this) ); - this.window.keyController.connect( - 'key-pressed', this._onWindowKeyPressEvent.bind(this) - ); this.window.connect( 'fullscreen-changed', this._onWindowFullscreenChanged.bind(this) ); + this.window.connect( + 'close-request', this._onWindowCloseRequest.bind(this) + ); this.interface = new Interface(); @@ -104,8 +104,8 @@ var App = GObject.registerClass({ this.hideCursorTimeout = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 1, () => { this.hideCursorTimeout = null; - if(this.isCursorInPlayer) - this.playerWindow.set_cursor(this.blankCursor); + if(this.player.motionController.is_pointer) + this.player.widget.set_cursor(this.blankCursor); return GLib.SOURCE_REMOVE; }); @@ -182,10 +182,14 @@ var App = GObject.registerClass({ this.player.connectWidget( 'leave-notify-event', this._onPlayerLeaveNotifyEvent.bind(this) ); - this.player.connectWidget( - 'motion-notify-event', this._onPlayerMotionNotifyEvent.bind(this) - ); */ + this.player.keyController.connect( + 'key-pressed', this._onPlayerKeyPress.bind(this) + ); + this.player.motionController.connect( + 'motion', this._onPlayerMotion.bind(this) + ); + /* Widget signals that are disconnected after first run */ this._playerRealizeSignal = this.player.widget.connect( 'realize', this._onPlayerRealize.bind(this) @@ -208,7 +212,7 @@ var App = GObject.registerClass({ this.interface.setFullscreenMode(isFullscreen); } - _onWindowKeyPressEvent(self, keyval, keycode, state) + _onPlayerKeyPress(self, keyval, keycode, state) { let bool = false; @@ -237,7 +241,7 @@ var App = GObject.registerClass({ break; case Gdk.KEY_q: case Gdk.KEY_Q: - this.window.destroy(); + this._onWindowCloseRequest(); break; default: break; @@ -257,17 +261,9 @@ var App = GObject.registerClass({ this.player.widget.disconnect(this._playerRealizeSignal); this.player.renderer.expose(); - let display = this.player.widget.get_display(); -/* - this.defaultCursor = Gdk.Cursor.new_from_name( - display, 'default' - ); - this.blankCursor = Gdk.Cursor.new_for_display( - display, Gdk.CursorType.BLANK_CURSOR - ); + this.defaultCursor = Gdk.Cursor.new_from_name('default', null); + this.blankCursor = Gdk.Cursor.new_from_name('none', null); - this.playerWindow = this.player.widget.get_window(); -*/ this.setHideCursorTimeout(); } @@ -374,9 +370,16 @@ var App = GObject.registerClass({ this.clearTimeout('hideControls'); } - _onPlayerMotionNotifyEvent(self, event) + _onPlayerMotion(self, posX, posY) { - this.playerWindow.set_cursor(this.defaultCursor); + /* GTK4 sometimes generates motions with same coords */ + if(this.posX === posX && this.posY === posY) + return; + + this.posX = posX; + this.posY = posY; + + this.player.widget.set_cursor(this.defaultCursor); this.setHideCursorTimeout(); if(this.window.isFullscreen) { @@ -393,11 +396,8 @@ var App = GObject.registerClass({ if(!this.dragStartReady || this.window.isFullscreen) return; - let [res, x, y] = event.get_root_coords(); - if(!res) return; - let startDrag = this.player.widget.drag_check_threshold( - this.dragStartX, this.dragStartY, x, y + this.dragStartX, this.dragStartY, posX, posY ); if(!startDrag) return; @@ -417,5 +417,7 @@ var App = GObject.registerClass({ this.window.destroy(); this.player.widget.emit('destroy'); this.interface.emit('destroy'); + + this.quit(); } }); diff --git a/clapper_src/player.js b/clapper_src/player.js index d0f4259d..f297cdf6 100644 --- a/clapper_src/player.js +++ b/clapper_src/player.js @@ -1,4 +1,4 @@ -const { Gio, GLib, GObject, Gst, GstPlayer } = imports.gi; +const { Gio, GLib, GObject, Gst, GstPlayer, Gtk } = imports.gi; const ByteArray = imports.byteArray; const Debug = imports.clapper_src.debug; @@ -80,6 +80,12 @@ class ClapperPlayer extends GstPlayer.Player this._trackId = 0; this.playlist_ext = opts.playlist_ext || 'claps'; + this.keyController = new Gtk.EventControllerKey(); + this.motionController = new Gtk.EventControllerMotion(); + + this.widget.add_controller(this.keyController); + this.widget.add_controller(this.motionController); + this.connect('state-changed', this._onStateChanged.bind(this)); this.connect('uri-loaded', this._onUriLoaded.bind(this)); this.connect('end-of-stream', this._onStreamEnded.bind(this)); diff --git a/clapper_src/revealers.js b/clapper_src/revealers.js index f148b4ef..7eb95e38 100644 --- a/clapper_src/revealers.js +++ b/clapper_src/revealers.js @@ -10,6 +10,13 @@ class ClapperCustomRevealer extends Gtk.Revealer { _init(opts) { + opts = opts || {}; + + let defaults = { + visible: false, + }; + Object.assign(opts, defaults); + super._init(opts); this.revealerName = ''; diff --git a/clapper_src/window.js b/clapper_src/window.js index 0b8b011b..5ca1d546 100644 --- a/clapper_src/window.js +++ b/clapper_src/window.js @@ -17,10 +17,6 @@ var Window = GObject.registerClass({ destroy_with_parent: true, }); this.isFullscreen = false; - - this.keyController = new Gtk.EventControllerKey(); - this.add_controller(this.keyController); - this.mapSignal = this.connect('map', this._onMap.bind(this)); } diff --git a/css/styles.css b/css/styles.css index 04b845c0..8fe8f4ad 100644 --- a/css/styles.css +++ b/css/styles.css @@ -39,7 +39,7 @@ scale marks { background: black; } .reavealertop { - min-height: 100px; + min-height: 90px; box-shadow: inset 0px 200px 10px -124px rgba(0,0,0,0.3); font-family: 'Cantarell', 'Noto Sans', sans-serif; font-size: 30px;