From 3e96a13f002c364ec98ec06594112c5e3a2e1ea7 Mon Sep 17 00:00:00 2001 From: Rafostar <40623528+Rafostar@users.noreply.github.com> Date: Tue, 13 Oct 2020 20:32:59 +0200 Subject: [PATCH] Restore window dragging by drag on player --- clapper_src/app.js | 47 ++++++++++++++++++++----------------------- clapper_src/player.js | 2 ++ 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/clapper_src/app.js b/clapper_src/app.js index 730335e1..820e3437 100644 --- a/clapper_src/app.js +++ b/clapper_src/app.js @@ -38,7 +38,6 @@ var App = GObject.registerClass({ this.window = null; this.interface = null; this.player = null; - this.dragStartReady = false; this.posX = 0; this.posY = 0; @@ -189,6 +188,9 @@ var App = GObject.registerClass({ this.player.motionController.connect( 'motion', this._onPlayerMotion.bind(this) ); + this.player.dragGesture.connect( + 'drag-update', this._onPlayerDragUpdate.bind(this) + ); /* Widget signals that are disconnected after first run */ this._playerRealizeSignal = this.player.widget.connect( @@ -317,8 +319,6 @@ var App = GObject.registerClass({ let [res, button] = event.get_button(); if(!res) return; - this.dragStartReady = false; - switch(button) { case Gdk.BUTTON_PRIMARY: this._handlePrimaryButtonPress(event, button); @@ -337,14 +337,6 @@ var App = GObject.registerClass({ 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; @@ -392,24 +384,29 @@ var App = GObject.registerClass({ else if(this.hideControlsTimeout) { this.clearTimeout('hideControls'); } + } - if(!this.dragStartReady || this.window.isFullscreen) - return; + _onPlayerDragUpdate(gesture, offsetX, offsetY) + { + let { gtk_double_click_distance } = this.player.widget.get_settings(); - let startDrag = this.player.widget.drag_check_threshold( - this.dragStartX, this.dragStartY, posX, posY - ); - if(!startDrag) return; + if ( + Math.abs(offsetX) > gtk_double_click_distance + || Math.abs(offsetY) > gtk_double_click_distance + ) { + let [isActive, startX, startY] = gesture.get_start_point(); + if(!isActive) return; - this.dragStartReady = false; - let timestamp = event.get_time(); + this.activeWindow.get_surface().begin_move( + gesture.get_device(), + gesture.get_current_button(), + startX, + startY, + gesture.get_current_event_time() + ); - this.window.begin_move_drag( - Gdk.BUTTON_PRIMARY, - this.dragStartX, - this.dragStartY, - timestamp - ); + gesture.reset(); + } } _onWindowCloseRequest() diff --git a/clapper_src/player.js b/clapper_src/player.js index f297cdf6..151afa37 100644 --- a/clapper_src/player.js +++ b/clapper_src/player.js @@ -82,9 +82,11 @@ class ClapperPlayer extends GstPlayer.Player this.keyController = new Gtk.EventControllerKey(); this.motionController = new Gtk.EventControllerMotion(); + this.dragGesture = new Gtk.GestureDrag(); this.widget.add_controller(this.keyController); this.widget.add_controller(this.motionController); + this.widget.add_controller(this.dragGesture); this.connect('state-changed', this._onStateChanged.bind(this)); this.connect('uri-loaded', this._onUriLoaded.bind(this));