2014-08-05 10:25:30 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
2023-07-10 05:53:00 -04:00
|
|
|
import Clutter from 'gi://Clutter';
|
|
|
|
import GObject from 'gi://GObject';
|
2023-08-08 14:07:03 -04:00
|
|
|
import Mtk from 'gi://Mtk';
|
2023-07-10 05:53:00 -04:00
|
|
|
import St from 'gi://St';
|
2014-08-05 10:25:30 -04:00
|
|
|
|
2023-07-10 05:53:00 -04:00
|
|
|
import * as Main from './main.js';
|
2014-11-27 14:46:50 -05:00
|
|
|
|
2023-07-10 05:53:00 -04:00
|
|
|
const EDGE_THRESHOLD = 20;
|
|
|
|
const DRAG_DISTANCE = 80;
|
2014-08-05 10:25:30 -04:00
|
|
|
|
2023-07-10 05:53:00 -04:00
|
|
|
export const EdgeDragAction = GObject.registerClass({
|
2021-02-11 08:15:25 -05:00
|
|
|
Signals: {
|
|
|
|
'activated': {},
|
2023-08-06 18:40:20 -04:00
|
|
|
'progress': {param_types: [GObject.TYPE_DOUBLE]},
|
2021-02-11 08:15:25 -05:00
|
|
|
},
|
2017-10-30 21:23:39 -04:00
|
|
|
}, class EdgeDragAction extends Clutter.GestureAction {
|
2017-10-30 20:03:21 -04:00
|
|
|
_init(side, allowedModes) {
|
2017-10-30 21:23:39 -04:00
|
|
|
super._init();
|
2014-08-05 10:25:30 -04:00
|
|
|
this._side = side;
|
2014-11-27 14:46:50 -05:00
|
|
|
this._allowedModes = allowedModes;
|
2014-08-05 10:25:30 -04:00
|
|
|
this.set_n_touch_points(1);
|
2022-05-25 14:54:39 -04:00
|
|
|
this.set_threshold_trigger_edge(Clutter.GestureTriggerEdge.AFTER);
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2014-08-05 10:25:30 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_getMonitorRect(x, y) {
|
2023-08-08 14:07:03 -04:00
|
|
|
const rect = new Mtk.Rectangle({x: x - 1, y: y - 1, width: 1, height: 1});
|
2018-01-03 02:55:38 -05:00
|
|
|
let monitorIndex = global.display.get_monitor_index_for_rect(rect);
|
2014-08-05 10:25:30 -04:00
|
|
|
|
2018-01-03 02:55:38 -05:00
|
|
|
return global.display.get_monitor_geometry(monitorIndex);
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2014-08-05 10:25:30 -04:00
|
|
|
|
2019-01-31 09:08:10 -05:00
|
|
|
vfunc_gesture_prepare(_actor) {
|
2023-08-06 20:51:19 -04:00
|
|
|
if (this.get_n_current_points() === 0)
|
2014-08-05 10:25:30 -04:00
|
|
|
return false;
|
|
|
|
|
2014-12-11 09:35:40 -05:00
|
|
|
if (!(this._allowedModes & Main.actionMode))
|
2014-11-27 14:46:50 -05:00
|
|
|
return false;
|
|
|
|
|
2014-08-05 10:25:30 -04:00
|
|
|
let [x, y] = this.get_press_coords(0);
|
|
|
|
let monitorRect = this._getMonitorRect(x, y);
|
|
|
|
|
2023-08-06 20:51:19 -04:00
|
|
|
return (this._side === St.Side.LEFT && x < monitorRect.x + EDGE_THRESHOLD) ||
|
|
|
|
(this._side === St.Side.RIGHT && x > monitorRect.x + monitorRect.width - EDGE_THRESHOLD) ||
|
|
|
|
(this._side === St.Side.TOP && y < monitorRect.y + EDGE_THRESHOLD) ||
|
|
|
|
(this._side === St.Side.BOTTOM && y > monitorRect.y + monitorRect.height - EDGE_THRESHOLD);
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2014-08-05 10:25:30 -04:00
|
|
|
|
2019-01-31 09:08:10 -05:00
|
|
|
vfunc_gesture_progress(_actor) {
|
2014-08-05 10:25:30 -04:00
|
|
|
let [startX, startY] = this.get_press_coords(0);
|
|
|
|
let [x, y] = this.get_motion_coords(0);
|
2019-08-19 13:55:49 -04:00
|
|
|
let offsetX = Math.abs(x - startX);
|
|
|
|
let offsetY = Math.abs(y - startY);
|
2014-08-05 10:25:30 -04:00
|
|
|
|
|
|
|
if (offsetX < EDGE_THRESHOLD && offsetY < EDGE_THRESHOLD)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if ((offsetX > offsetY &&
|
2023-08-06 20:51:19 -04:00
|
|
|
(this._side === St.Side.TOP || this._side === St.Side.BOTTOM)) ||
|
2014-08-05 10:25:30 -04:00
|
|
|
(offsetY > offsetX &&
|
2023-08-06 20:51:19 -04:00
|
|
|
(this._side === St.Side.LEFT || this._side === St.Side.RIGHT))) {
|
2014-08-05 10:25:30 -04:00
|
|
|
this.cancel();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-02-11 08:15:25 -05:00
|
|
|
if (this._side === St.Side.TOP ||
|
|
|
|
this._side === St.Side.BOTTOM)
|
|
|
|
this.emit('progress', offsetY);
|
|
|
|
else
|
|
|
|
this.emit('progress', offsetX);
|
|
|
|
|
2014-08-05 10:25:30 -04:00
|
|
|
return true;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2014-08-05 10:25:30 -04:00
|
|
|
|
2019-01-31 09:08:10 -05:00
|
|
|
vfunc_gesture_end(_actor) {
|
2014-08-05 10:25:30 -04:00
|
|
|
let [startX, startY] = this.get_press_coords(0);
|
|
|
|
let [x, y] = this.get_motion_coords(0);
|
|
|
|
let monitorRect = this._getMonitorRect(startX, startY);
|
|
|
|
|
2023-08-06 20:51:19 -04:00
|
|
|
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))
|
2014-08-05 10:25:30 -04:00
|
|
|
this.emit('activated');
|
2021-02-14 04:26:38 -05:00
|
|
|
else
|
|
|
|
this.cancel();
|
2014-08-05 10:25:30 -04:00
|
|
|
}
|
|
|
|
});
|