mirror of
https://github.com/Rafostar/clapper.git
synced 2025-08-30 07:42:23 +02:00
Drag application from video (MPV like window dragging)
This commit is contained in:
@@ -22,6 +22,7 @@ var App = GObject.registerClass({
|
|||||||
this.window = null;
|
this.window = null;
|
||||||
this.interface = null;
|
this.interface = null;
|
||||||
this.player = null;
|
this.player = null;
|
||||||
|
this.dragStartReady = false;
|
||||||
|
|
||||||
this.connect('startup', () => this._buildUI());
|
this.connect('startup', () => this._buildUI());
|
||||||
this.connect('activate', () => this._openWindow());
|
this.connect('activate', () => this._openWindow());
|
||||||
@@ -54,6 +55,27 @@ var App = GObject.registerClass({
|
|||||||
this.window.show_all();
|
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()
|
_onWindowRealize()
|
||||||
{
|
{
|
||||||
this.player = new Player();
|
this.player = new Player();
|
||||||
@@ -72,6 +94,9 @@ var App = GObject.registerClass({
|
|||||||
this.player.widget.connect(
|
this.player.widget.connect(
|
||||||
'scroll-event', this._onPlayerScrollEvent.bind(this)
|
'scroll-event', this._onPlayerScrollEvent.bind(this)
|
||||||
);
|
);
|
||||||
|
this.player.widget.connect(
|
||||||
|
'motion-notify-event', this._onPlayerMotionNotifyEvent.bind(this)
|
||||||
|
);
|
||||||
|
|
||||||
this.player.widget.show_all();
|
this.player.widget.show_all();
|
||||||
this.emit('ready', true);
|
this.emit('ready', true);
|
||||||
@@ -118,8 +143,7 @@ var App = GObject.registerClass({
|
|||||||
|
|
||||||
switch(button) {
|
switch(button) {
|
||||||
case Gdk.BUTTON_PRIMARY:
|
case Gdk.BUTTON_PRIMARY:
|
||||||
if(event.get_event_type() === Gdk.EventType.DOUBLE_BUTTON_PRESS)
|
this._handlePrimaryButtonPress(event, button);
|
||||||
this.window.toggleFullscreen();
|
|
||||||
break;
|
break;
|
||||||
case Gdk.BUTTON_SECONDARY:
|
case Gdk.BUTTON_SECONDARY:
|
||||||
if(event.get_event_type() !== Gdk.EventType.DOUBLE_BUTTON_PRESS)
|
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)
|
_onPlayerWarning(self, error)
|
||||||
{
|
{
|
||||||
log(error.message);
|
log(error.message);
|
||||||
|
Reference in New Issue
Block a user