2019-01-31 09:07:06 -05:00
|
|
|
/* exported PointerA11yTimeout */
|
2019-03-20 12:46:12 -04:00
|
|
|
const { Clutter, GLib, GObject, Meta, St } = imports.gi;
|
|
|
|
const Main = imports.ui.main;
|
|
|
|
const Cairo = imports.cairo;
|
|
|
|
|
2019-08-21 10:47:38 -04:00
|
|
|
var PieTimer = GObject.registerClass({
|
|
|
|
Properties: {
|
|
|
|
'angle': GObject.ParamSpec.double(
|
|
|
|
'angle', 'angle', 'angle',
|
|
|
|
GObject.ParamFlags.READWRITE,
|
|
|
|
0, 2 * Math.PI, 0)
|
|
|
|
}
|
|
|
|
}, class PieTimer extends St.DrawingArea {
|
2019-03-20 12:46:12 -04:00
|
|
|
_init() {
|
2019-08-21 10:47:38 -04:00
|
|
|
this._angle = 0;
|
2019-07-25 20:25:32 -04:00
|
|
|
super._init({
|
|
|
|
style_class: 'pie-timer',
|
|
|
|
visible: false,
|
|
|
|
can_focus: false,
|
|
|
|
reactive: false
|
|
|
|
});
|
2019-08-21 10:47:38 -04:00
|
|
|
}
|
2019-07-25 20:28:40 -04:00
|
|
|
|
2019-08-21 10:47:38 -04:00
|
|
|
get angle() {
|
|
|
|
return this._angle;
|
|
|
|
}
|
|
|
|
|
|
|
|
set angle(angle) {
|
|
|
|
if (this._angle == angle)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._angle = angle;
|
|
|
|
this.notify('angle');
|
|
|
|
this.queue_repaint();
|
2019-03-20 12:46:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
vfunc_repaint() {
|
|
|
|
let node = this.get_theme_node();
|
|
|
|
let backgroundColor = node.get_color('-pie-background-color');
|
|
|
|
let borderColor = node.get_color('-pie-border-color');
|
|
|
|
let borderWidth = node.get_length('-pie-border-width');
|
|
|
|
let [width, height] = this.get_surface_size();
|
|
|
|
let radius = Math.min(width / 2, height / 2);
|
|
|
|
|
|
|
|
let startAngle = 3 * Math.PI / 2;
|
2019-08-21 10:47:38 -04:00
|
|
|
let endAngle = startAngle + this._angle;
|
2019-03-20 12:46:12 -04:00
|
|
|
|
|
|
|
let cr = this.get_context();
|
|
|
|
cr.setLineCap(Cairo.LineCap.ROUND);
|
|
|
|
cr.setLineJoin(Cairo.LineJoin.ROUND);
|
|
|
|
cr.translate(width / 2, height / 2);
|
|
|
|
|
2019-08-22 04:05:40 -04:00
|
|
|
if (this._angle < 2 * Math.PI)
|
|
|
|
cr.moveTo(0, 0);
|
|
|
|
|
2019-03-20 12:46:12 -04:00
|
|
|
cr.arc(0, 0, radius - borderWidth, startAngle, endAngle);
|
2019-08-22 04:05:40 -04:00
|
|
|
|
|
|
|
if (this._angle < 2 * Math.PI)
|
|
|
|
cr.lineTo(0, 0);
|
|
|
|
|
2019-03-20 12:46:12 -04:00
|
|
|
cr.closePath();
|
|
|
|
|
|
|
|
cr.setLineWidth(0);
|
|
|
|
Clutter.cairo_set_source_color(cr, backgroundColor);
|
|
|
|
cr.fillPreserve();
|
|
|
|
|
|
|
|
cr.setLineWidth(borderWidth);
|
|
|
|
Clutter.cairo_set_source_color(cr, borderColor);
|
|
|
|
cr.stroke();
|
|
|
|
|
|
|
|
cr.$dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
start(x, y, duration) {
|
2018-07-20 15:46:19 -04:00
|
|
|
this.remove_all_transitions();
|
2019-03-20 12:46:12 -04:00
|
|
|
|
2019-08-22 04:02:42 -04:00
|
|
|
this.opacity = 0;
|
2019-03-20 12:46:12 -04:00
|
|
|
this.x = x - this.width / 2;
|
|
|
|
this.y = y - this.height / 2;
|
2019-08-21 10:47:38 -04:00
|
|
|
this._angle = 0;
|
|
|
|
|
2019-03-20 12:46:12 -04:00
|
|
|
this.show();
|
|
|
|
Main.uiGroup.set_child_above_sibling(this, null);
|
|
|
|
|
2019-08-22 04:02:42 -04:00
|
|
|
this.ease({
|
|
|
|
opacity: 255,
|
|
|
|
duration: duration / 4,
|
|
|
|
mode: Clutter.AnimationMode.EASE_IN_QUAD
|
|
|
|
});
|
|
|
|
|
2019-08-21 10:47:38 -04:00
|
|
|
this.ease_property('angle', 2 * Math.PI, {
|
2018-07-20 15:46:19 -04:00
|
|
|
duration,
|
2019-08-21 10:47:38 -04:00
|
|
|
mode: Clutter.AnimationMode.LINEAR,
|
2018-07-20 15:46:19 -04:00
|
|
|
onComplete: () => this.stop()
|
|
|
|
});
|
2019-03-20 12:46:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
2018-07-20 15:46:19 -04:00
|
|
|
this.remove_all_transitions();
|
2019-03-20 12:46:12 -04:00
|
|
|
this.hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var PointerA11yTimeout = class PointerA11yTimeout {
|
|
|
|
constructor() {
|
|
|
|
let manager = Clutter.DeviceManager.get_default();
|
|
|
|
let pieTimer = new PieTimer();
|
|
|
|
|
|
|
|
Main.uiGroup.add_actor(pieTimer);
|
|
|
|
|
|
|
|
manager.connect('ptr-a11y-timeout-started', (manager, device, type, timeout) => {
|
2019-02-01 08:41:55 -05:00
|
|
|
let [x, y] = global.get_pointer();
|
2019-03-20 12:46:12 -04:00
|
|
|
pieTimer.start(x, y, timeout);
|
|
|
|
if (type == Clutter.PointerA11yTimeoutType.GESTURE)
|
2019-01-29 14:36:54 -05:00
|
|
|
global.display.set_cursor(Meta.Cursor.CROSSHAIR);
|
2019-03-20 12:46:12 -04:00
|
|
|
});
|
|
|
|
|
2019-08-22 04:10:23 -04:00
|
|
|
manager.connect('ptr-a11y-timeout-stopped', (manager, device, type, clicked) => {
|
|
|
|
if (!clicked)
|
|
|
|
pieTimer.stop();
|
|
|
|
|
2019-03-20 12:46:12 -04:00
|
|
|
if (type == Clutter.PointerA11yTimeoutType.GESTURE)
|
2019-01-29 14:36:54 -05:00
|
|
|
global.display.set_cursor(Meta.Cursor.DEFAULT);
|
2019-03-20 12:46:12 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|