From 647ad3f1ec481d763aa00f971d488d7fd377683b Mon Sep 17 00:00:00 2001 From: Rafostar <40623528+Rafostar@users.noreply.github.com> Date: Tue, 1 Sep 2020 19:48:25 +0200 Subject: [PATCH] Drag application from video (MPV like window dragging) --- clapper_src/app.js | 52 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/clapper_src/app.js b/clapper_src/app.js index bb52830d..99b7945d 100644 --- a/clapper_src/app.js +++ b/clapper_src/app.js @@ -22,6 +22,7 @@ var App = GObject.registerClass({ this.window = null; this.interface = null; this.player = null; + this.dragStartReady = false; this.connect('startup', () => this._buildUI()); this.connect('activate', () => this._openWindow()); @@ -54,6 +55,27 @@ var App = GObject.registerClass({ this.window.show_all(); } + _handlePrimaryButtonPress(event, button) + { + let eventType = event.get_event_type(); + + switch(eventType) { + case Gdk.EventType.BUTTON_PRESS: + let [res, x, y] = event.get_root_coords(); + if(!res) + break; + this.dragStartX = x; + this.dragStartY = y; + this.dragStartReady = true; + break; + case Gdk.EventType.DOUBLE_BUTTON_PRESS: + this.window.toggleFullscreen(); + break; + default: + break; + } + } + _onWindowRealize() { this.player = new Player(); @@ -72,6 +94,9 @@ var App = GObject.registerClass({ this.player.widget.connect( 'scroll-event', this._onPlayerScrollEvent.bind(this) ); + this.player.widget.connect( + 'motion-notify-event', this._onPlayerMotionNotifyEvent.bind(this) + ); this.player.widget.show_all(); this.emit('ready', true); @@ -118,8 +143,7 @@ var App = GObject.registerClass({ switch(button) { case Gdk.BUTTON_PRIMARY: - if(event.get_event_type() === Gdk.EventType.DOUBLE_BUTTON_PRESS) - this.window.toggleFullscreen(); + this._handlePrimaryButtonPress(event, button); break; case Gdk.BUTTON_SECONDARY: if(event.get_event_type() !== Gdk.EventType.DOUBLE_BUTTON_PRESS) @@ -166,6 +190,30 @@ var App = GObject.registerClass({ } } + _onPlayerMotionNotifyEvent(self, event) + { + if(!this.dragStartReady) + 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 + ); + if(!startDrag) return; + + this.dragStartReady = false; + let timestamp = event.get_time(); + + this.window.begin_move_drag( + Gdk.BUTTON_PRIMARY, + this.dragStartX, + this.dragStartY, + timestamp + ); + } + _onPlayerWarning(self, error) { log(error.message);