2014-08-05 14:25:30 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 14:07:06 +00:00
|
|
|
/* exported EdgeDragAction */
|
2014-08-05 14:25:30 +00:00
|
|
|
|
2019-02-09 03:21:36 +00:00
|
|
|
const { Clutter, GObject, Meta, St } = imports.gi;
|
2014-08-05 14:25:30 +00:00
|
|
|
|
2014-11-27 19:46:50 +00:00
|
|
|
const Main = imports.ui.main;
|
|
|
|
|
2017-07-18 17:47:27 +00:00
|
|
|
var EDGE_THRESHOLD = 20;
|
|
|
|
var DRAG_DISTANCE = 80;
|
2014-08-05 14:25:30 +00:00
|
|
|
|
2017-10-31 01:23:39 +00:00
|
|
|
var EdgeDragAction = GObject.registerClass({
|
2017-02-14 17:24:50 +00:00
|
|
|
Signals: { 'activated': {} },
|
2017-10-31 01:23:39 +00:00
|
|
|
}, class EdgeDragAction extends Clutter.GestureAction {
|
2017-10-31 00:03:21 +00:00
|
|
|
_init(side, allowedModes) {
|
2017-10-31 01:23:39 +00:00
|
|
|
super._init();
|
2014-08-05 14:25:30 +00:00
|
|
|
this._side = side;
|
2014-11-27 19:46:50 +00:00
|
|
|
this._allowedModes = allowedModes;
|
2014-08-05 14:25:30 +00:00
|
|
|
this.set_n_touch_points(1);
|
|
|
|
|
2019-01-28 00:42:00 +00:00
|
|
|
global.display.connect('grab-op-begin', () => this.cancel());
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2014-08-05 14:25:30 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getMonitorRect(x, y) {
|
2014-08-05 14:25:30 +00:00
|
|
|
let rect = new Meta.Rectangle({ x: x - 1, y: y - 1, width: 1, height: 1 });
|
2018-01-03 07:55:38 +00:00
|
|
|
let monitorIndex = global.display.get_monitor_index_for_rect(rect);
|
2014-08-05 14:25:30 +00:00
|
|
|
|
2018-01-03 07:55:38 +00:00
|
|
|
return global.display.get_monitor_geometry(monitorIndex);
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2014-08-05 14:25:30 +00:00
|
|
|
|
2019-01-31 14:08:10 +00:00
|
|
|
vfunc_gesture_prepare(_actor) {
|
2014-08-05 14:25:30 +00:00
|
|
|
if (this.get_n_current_points() == 0)
|
|
|
|
return false;
|
|
|
|
|
2014-12-11 14:35:40 +00:00
|
|
|
if (!(this._allowedModes & Main.actionMode))
|
2014-11-27 19:46:50 +00:00
|
|
|
return false;
|
|
|
|
|
2014-08-05 14:25:30 +00:00
|
|
|
let [x, y] = this.get_press_coords(0);
|
|
|
|
let monitorRect = this._getMonitorRect(x, y);
|
|
|
|
|
2019-08-19 19:38:51 +00:00
|
|
|
return (this._side == St.Side.LEFT && x < monitorRect.x + EDGE_THRESHOLD) ||
|
2014-08-05 14:25:30 +00:00
|
|
|
(this._side == St.Side.RIGHT && x > monitorRect.x + monitorRect.width - EDGE_THRESHOLD) ||
|
|
|
|
(this._side == St.Side.TOP && y < monitorRect.y + EDGE_THRESHOLD) ||
|
2019-08-19 19:38:51 +00:00
|
|
|
(this._side == St.Side.BOTTOM && y > monitorRect.y + monitorRect.height - EDGE_THRESHOLD);
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2014-08-05 14:25:30 +00:00
|
|
|
|
2019-01-31 14:08:10 +00:00
|
|
|
vfunc_gesture_progress(_actor) {
|
2014-08-05 14:25:30 +00:00
|
|
|
let [startX, startY] = this.get_press_coords(0);
|
|
|
|
let [x, y] = this.get_motion_coords(0);
|
2019-08-19 17:55:49 +00:00
|
|
|
let offsetX = Math.abs(x - startX);
|
|
|
|
let offsetY = Math.abs(y - startY);
|
2014-08-05 14:25:30 +00:00
|
|
|
|
|
|
|
if (offsetX < EDGE_THRESHOLD && offsetY < EDGE_THRESHOLD)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if ((offsetX > offsetY &&
|
|
|
|
(this._side == St.Side.TOP || this._side == St.Side.BOTTOM)) ||
|
|
|
|
(offsetY > offsetX &&
|
|
|
|
(this._side == St.Side.LEFT || this._side == St.Side.RIGHT))) {
|
|
|
|
this.cancel();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2014-08-05 14:25:30 +00:00
|
|
|
|
2019-01-31 14:08:10 +00:00
|
|
|
vfunc_gesture_end(_actor) {
|
2014-08-05 14:25:30 +00:00
|
|
|
let [startX, startY] = this.get_press_coords(0);
|
|
|
|
let [x, y] = this.get_motion_coords(0);
|
|
|
|
let monitorRect = this._getMonitorRect(startX, startY);
|
|
|
|
|
|
|
|
if ((this._side == St.Side.TOP && y > monitorRect.y + DRAG_DISTANCE) ||
|
|
|
|
(this._side == St.Side.BOTTOM && y < monitorRect.y + monitorRect.height - DRAG_DISTANCE) ||
|
|
|
|
(this._side == St.Side.LEFT && x > monitorRect.x + DRAG_DISTANCE) ||
|
|
|
|
(this._side == St.Side.RIGHT && x < monitorRect.x + monitorRect.width - DRAG_DISTANCE))
|
|
|
|
this.emit('activated');
|
|
|
|
}
|
|
|
|
});
|