2011-09-28 13:16:26 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2022-07-04 22:30:44 +00:00
|
|
|
/* exported Magnifier */
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2023-06-08 04:52:46 +00:00
|
|
|
const Atspi = imports.gi.Atspi;
|
|
|
|
const Clutter = imports.gi.Clutter;
|
|
|
|
const GDesktopEnums = imports.gi.GDesktopEnums;
|
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const GLib = imports.gi.GLib;
|
|
|
|
const GObject = imports.gi.GObject;
|
|
|
|
const Meta = imports.gi.Meta;
|
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
const St = imports.gi.St;
|
2022-07-04 22:30:44 +00:00
|
|
|
const Signals = imports.misc.signals;
|
2010-07-21 08:44:59 +00:00
|
|
|
|
2014-02-13 16:24:46 +00:00
|
|
|
const Background = imports.ui.background;
|
2013-09-04 17:53:36 +00:00
|
|
|
const FocusCaretTracker = imports.ui.focusCaretTracker;
|
2010-05-11 19:00:07 +00:00
|
|
|
const Main = imports.ui.main;
|
2010-10-30 20:31:30 +00:00
|
|
|
const Params = imports.misc.params;
|
2012-08-30 19:19:32 +00:00
|
|
|
const PointerWatcher = imports.ui.pointerWatcher;
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2017-07-18 17:47:27 +00:00
|
|
|
var CROSSHAIRS_CLIP_SIZE = [100, 100];
|
|
|
|
var NO_CHANGE = 0.0;
|
2010-06-19 13:43:39 +00:00
|
|
|
|
2017-07-18 17:47:27 +00:00
|
|
|
var POINTER_REST_TIME = 1000; // milliseconds
|
2015-07-24 16:47:34 +00:00
|
|
|
|
2010-06-19 13:43:39 +00:00
|
|
|
// Settings
|
2011-02-17 15:05:22 +00:00
|
|
|
const MAGNIFIER_SCHEMA = 'org.gnome.desktop.a11y.magnifier';
|
2010-06-19 13:43:39 +00:00
|
|
|
const SCREEN_POSITION_KEY = 'screen-position';
|
|
|
|
const MAG_FACTOR_KEY = 'mag-factor';
|
2012-04-04 15:10:31 +00:00
|
|
|
const INVERT_LIGHTNESS_KEY = 'invert-lightness';
|
2012-06-01 12:36:47 +00:00
|
|
|
const COLOR_SATURATION_KEY = 'color-saturation';
|
2012-03-12 19:52:41 +00:00
|
|
|
const BRIGHT_RED_KEY = 'brightness-red';
|
|
|
|
const BRIGHT_GREEN_KEY = 'brightness-green';
|
|
|
|
const BRIGHT_BLUE_KEY = 'brightness-blue';
|
|
|
|
const CONTRAST_RED_KEY = 'contrast-red';
|
|
|
|
const CONTRAST_GREEN_KEY = 'contrast-green';
|
|
|
|
const CONTRAST_BLUE_KEY = 'contrast-blue';
|
2010-06-19 13:43:39 +00:00
|
|
|
const LENS_MODE_KEY = 'lens-mode';
|
|
|
|
const CLAMP_MODE_KEY = 'scroll-at-edges';
|
|
|
|
const MOUSE_TRACKING_KEY = 'mouse-tracking';
|
2013-09-04 17:53:36 +00:00
|
|
|
const FOCUS_TRACKING_KEY = 'focus-tracking';
|
|
|
|
const CARET_TRACKING_KEY = 'caret-tracking';
|
2010-06-19 13:43:39 +00:00
|
|
|
const SHOW_CROSS_HAIRS_KEY = 'show-cross-hairs';
|
|
|
|
const CROSS_HAIRS_THICKNESS_KEY = 'cross-hairs-thickness';
|
|
|
|
const CROSS_HAIRS_COLOR_KEY = 'cross-hairs-color';
|
|
|
|
const CROSS_HAIRS_OPACITY_KEY = 'cross-hairs-opacity';
|
|
|
|
const CROSS_HAIRS_LENGTH_KEY = 'cross-hairs-length';
|
|
|
|
const CROSS_HAIRS_CLIP_KEY = 'cross-hairs-clip';
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2019-01-29 13:46:33 +00:00
|
|
|
var MouseSpriteContent = GObject.registerClass({
|
2019-01-29 01:27:05 +00:00
|
|
|
Implements: [Clutter.Content],
|
2019-01-29 13:46:33 +00:00
|
|
|
}, class MouseSpriteContent extends GObject.Object {
|
|
|
|
_init() {
|
|
|
|
super._init();
|
|
|
|
this._texture = null;
|
|
|
|
}
|
|
|
|
|
2019-01-31 21:07:38 +00:00
|
|
|
vfunc_get_preferred_size() {
|
2019-01-29 13:46:33 +00:00
|
|
|
if (!this._texture)
|
2019-03-11 20:36:55 +00:00
|
|
|
return [false, 0, 0];
|
2019-01-29 13:46:33 +00:00
|
|
|
|
2019-03-11 20:36:55 +00:00
|
|
|
return [true, this._texture.get_width(), this._texture.get_height()];
|
2019-01-29 13:46:33 +00:00
|
|
|
}
|
|
|
|
|
2019-12-06 19:10:58 +00:00
|
|
|
vfunc_paint_content(actor, node, _paintContext) {
|
2019-01-29 13:46:33 +00:00
|
|
|
if (!this._texture)
|
|
|
|
return;
|
|
|
|
|
2019-03-11 20:39:29 +00:00
|
|
|
let color = Clutter.Color.get_static(Clutter.StaticColor.WHITE);
|
2019-03-11 21:30:39 +00:00
|
|
|
let [minFilter, magFilter] = actor.get_content_scaling_filters();
|
2019-01-29 13:46:33 +00:00
|
|
|
let textureNode = new Clutter.TextureNode(this._texture,
|
2019-03-11 21:30:39 +00:00
|
|
|
color, minFilter, magFilter);
|
2019-01-29 13:46:33 +00:00
|
|
|
textureNode.set_name('MouseSpriteContent');
|
|
|
|
node.add_child(textureNode);
|
|
|
|
|
|
|
|
textureNode.add_rectangle(actor.get_content_box());
|
|
|
|
}
|
|
|
|
|
|
|
|
get texture() {
|
|
|
|
return this._texture;
|
|
|
|
}
|
|
|
|
|
|
|
|
set texture(coglTexture) {
|
|
|
|
if (this._texture == coglTexture)
|
|
|
|
return;
|
|
|
|
|
2019-03-11 20:40:45 +00:00
|
|
|
let oldTexture = this._texture;
|
2019-01-29 13:46:33 +00:00
|
|
|
this._texture = coglTexture;
|
|
|
|
this.invalidate();
|
2019-03-11 20:40:45 +00:00
|
|
|
|
2019-03-11 21:09:08 +00:00
|
|
|
if (!oldTexture || !coglTexture ||
|
2019-03-11 20:40:45 +00:00
|
|
|
oldTexture.get_width() != coglTexture.get_width() ||
|
|
|
|
oldTexture.get_height() != coglTexture.get_height())
|
|
|
|
this.invalidate_size();
|
2019-01-29 13:46:33 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-07-04 22:30:44 +00:00
|
|
|
var Magnifier = class Magnifier extends Signals.EventEmitter {
|
2017-10-31 01:19:44 +00:00
|
|
|
constructor() {
|
2022-07-04 22:30:44 +00:00
|
|
|
super();
|
|
|
|
|
2010-05-11 19:00:07 +00:00
|
|
|
// Magnifier is a manager of ZoomRegions.
|
|
|
|
this._zoomRegions = [];
|
|
|
|
|
|
|
|
// Create small clutter tree for the magnified mouse.
|
2018-01-03 07:55:38 +00:00
|
|
|
let cursorTracker = Meta.CursorTracker.get_for_display(global.display);
|
2019-01-29 13:46:33 +00:00
|
|
|
this._cursorTracker = cursorTracker;
|
|
|
|
|
|
|
|
this._mouseSprite = new Clutter.Actor({ request_mode: Clutter.RequestMode.CONTENT_SIZE });
|
|
|
|
this._mouseSprite.content = new MouseSpriteContent();
|
|
|
|
|
2023-05-29 14:42:13 +00:00
|
|
|
this._cursorRoot = new Clutter.Actor();
|
|
|
|
this._cursorRoot.add_actor(this._mouseSprite);
|
|
|
|
|
2010-05-11 19:00:07 +00:00
|
|
|
// Create the first ZoomRegion and initialize it according to the
|
2010-06-19 13:43:39 +00:00
|
|
|
// magnification settings.
|
2010-10-30 21:01:41 +00:00
|
|
|
|
2019-02-01 13:41:55 +00:00
|
|
|
[this.xMouse, this.yMouse] = global.get_pointer();
|
2010-10-30 21:01:41 +00:00
|
|
|
|
2023-05-29 14:42:13 +00:00
|
|
|
let aZoomRegion = new ZoomRegion(this, this._cursorRoot);
|
2010-05-11 19:00:07 +00:00
|
|
|
this._zoomRegions.push(aZoomRegion);
|
2019-03-12 21:41:18 +00:00
|
|
|
this._settingsInit(aZoomRegion);
|
2010-10-30 21:01:41 +00:00
|
|
|
aZoomRegion.scrollContentsTo(this.xMouse, this.yMouse);
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2019-03-12 21:41:18 +00:00
|
|
|
St.Settings.get().connect('notify::magnifier-active', () => {
|
|
|
|
this.setActive(St.Settings.get().magnifier_active);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.setActive(St.Settings.get().magnifier_active);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* showSystemCursor:
|
|
|
|
* Show the system mouse pointer.
|
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
showSystemCursor() {
|
2019-10-07 13:02:17 +00:00
|
|
|
const seat = Clutter.get_default_backend().get_default_seat();
|
|
|
|
|
|
|
|
if (seat.is_unfocus_inhibited())
|
|
|
|
seat.uninhibit_unfocus();
|
2022-03-08 11:50:03 +00:00
|
|
|
|
|
|
|
if (this._cursorVisibilityChangedId) {
|
|
|
|
this._cursorTracker.disconnect(this._cursorVisibilityChangedId);
|
|
|
|
delete this._cursorVisibilityChangedId;
|
|
|
|
|
|
|
|
this._cursorTracker.set_pointer_visible(true);
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* hideSystemCursor:
|
|
|
|
* Hide the system mouse pointer.
|
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
hideSystemCursor() {
|
2019-10-07 13:02:17 +00:00
|
|
|
const seat = Clutter.get_default_backend().get_default_seat();
|
|
|
|
|
|
|
|
if (!seat.is_unfocus_inhibited())
|
|
|
|
seat.inhibit_unfocus();
|
2022-03-08 11:50:03 +00:00
|
|
|
|
|
|
|
if (!this._cursorVisibilityChangedId) {
|
|
|
|
this._cursorTracker.set_pointer_visible(false);
|
|
|
|
this._cursorVisibilityChangedId = this._cursorTracker.connect('visibility-changed', () => {
|
|
|
|
if (this._cursorTracker.get_pointer_visible())
|
|
|
|
this._cursorTracker.set_pointer_visible(false);
|
|
|
|
});
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setActive:
|
|
|
|
* Show/hide all the zoom regions.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {boolean} activate Boolean to activate or de-activate the magnifier.
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
setActive(activate) {
|
2014-02-13 14:11:07 +00:00
|
|
|
let isActive = this.isActive();
|
|
|
|
|
2019-02-04 11:30:53 +00:00
|
|
|
this._zoomRegions.forEach(zoomRegion => {
|
2010-05-11 19:00:07 +00:00
|
|
|
zoomRegion.setActive(activate);
|
|
|
|
});
|
|
|
|
|
2020-10-28 19:29:55 +00:00
|
|
|
if (isActive === activate)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (activate) {
|
|
|
|
this._updateMouseSprite();
|
2021-08-15 22:36:59 +00:00
|
|
|
this._cursorTracker.connectObject(
|
|
|
|
'cursor-changed', this._updateMouseSprite.bind(this), this);
|
2020-10-28 19:29:55 +00:00
|
|
|
Meta.disable_unredirect_for_display(global.display);
|
|
|
|
this.startTrackingMouse();
|
|
|
|
} else {
|
2021-08-15 22:36:59 +00:00
|
|
|
this._cursorTracker.disconnectObject(this);
|
2020-10-28 19:29:55 +00:00
|
|
|
this._mouseSprite.content.texture = null;
|
|
|
|
Meta.enable_unredirect_for_display(global.display);
|
|
|
|
this.stopTrackingMouse();
|
2014-01-28 20:04:59 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2021-06-28 12:19:15 +00:00
|
|
|
if (this._crossHairs)
|
|
|
|
this._crossHairs.setEnabled(activate);
|
|
|
|
|
2010-05-11 19:00:07 +00:00
|
|
|
// Make sure system mouse pointer is shown when all zoom regions are
|
|
|
|
// invisible.
|
|
|
|
if (!activate)
|
2019-10-07 13:00:19 +00:00
|
|
|
this.showSystemCursor();
|
2010-07-21 08:44:59 +00:00
|
|
|
|
|
|
|
// Notify interested parties of this change
|
|
|
|
this.emit('active-changed', activate);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* isActive:
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @returns {boolean} Whether the magnifier is active.
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
isActive() {
|
2010-05-11 19:00:07 +00:00
|
|
|
// Sufficient to check one ZoomRegion since Magnifier's active
|
|
|
|
// state applies to all of them.
|
|
|
|
if (this._zoomRegions.length == 0)
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return this._zoomRegions[0].isActive();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* startTrackingMouse:
|
|
|
|
* Turn on mouse tracking, if not already doing so.
|
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
startTrackingMouse() {
|
2018-05-10 10:13:49 +00:00
|
|
|
if (!this._pointerWatch) {
|
2021-11-08 04:00:47 +00:00
|
|
|
let interval = 1000 / 60;
|
2018-05-10 10:13:49 +00:00
|
|
|
this._pointerWatch = PointerWatcher.getPointerWatcher().addWatch(interval, this.scrollToMousePos.bind(this));
|
2022-03-08 11:55:00 +00:00
|
|
|
|
|
|
|
this.scrollToMousePos();
|
2018-05-10 10:13:49 +00:00
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* stopTrackingMouse:
|
|
|
|
* Turn off mouse tracking, if not already doing so.
|
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
stopTrackingMouse() {
|
2012-08-30 19:19:32 +00:00
|
|
|
if (this._pointerWatch)
|
|
|
|
this._pointerWatch.remove();
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2012-08-30 19:19:32 +00:00
|
|
|
this._pointerWatch = null;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* isTrackingMouse:
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @returns {boolean} whether the magnifier is currently tracking the mouse
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
isTrackingMouse() {
|
2010-05-11 19:00:07 +00:00
|
|
|
return !!this._mouseTrackingId;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* scrollToMousePos:
|
|
|
|
* Position all zoom regions' ROI relative to the current location of the
|
|
|
|
* system pointer.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {[xMouse: number, yMouse: number] | []} args
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2021-07-29 19:56:57 +00:00
|
|
|
scrollToMousePos(...args) {
|
|
|
|
const [xMouse, yMouse] = args.length ? args : global.get_pointer();
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2021-07-29 20:17:54 +00:00
|
|
|
if (xMouse === this.xMouse && yMouse === this.yMouse)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.xMouse = xMouse;
|
|
|
|
this.yMouse = yMouse;
|
|
|
|
|
|
|
|
let sysMouseOverAny = false;
|
|
|
|
this._zoomRegions.forEach(zoomRegion => {
|
|
|
|
if (zoomRegion.scrollToMousePos())
|
|
|
|
sysMouseOverAny = true;
|
|
|
|
});
|
|
|
|
if (sysMouseOverAny)
|
|
|
|
this.hideSystemCursor();
|
|
|
|
else
|
|
|
|
this.showSystemCursor();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* createZoomRegion:
|
|
|
|
* Create a ZoomRegion instance with the given properties.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {number} xMagFactor
|
2019-10-17 16:41:52 +00:00
|
|
|
* The power to set horizontal magnification of the ZoomRegion. A value
|
|
|
|
* of 1.0 means no magnification, a value of 2.0 doubles the size.
|
2023-07-30 12:56:59 +00:00
|
|
|
* @param {number} yMagFactor
|
2019-10-17 16:41:52 +00:00
|
|
|
* The power to set the vertical magnification of the ZoomRegion.
|
2023-07-30 12:56:59 +00:00
|
|
|
* @param {{x: number, y: number, width: number, height: number}} roi
|
2019-10-17 16:41:52 +00:00
|
|
|
* The reg Object that defines the region to magnify, given in
|
|
|
|
* unmagnified coordinates.
|
2023-07-30 12:56:59 +00:00
|
|
|
* @param {{x: number, y: number, width: number, height: number}} viewPort
|
2019-10-17 16:41:52 +00:00
|
|
|
* Object that defines the position of the ZoomRegion on screen.
|
|
|
|
* @returns {ZoomRegion} the newly created ZoomRegion.
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
createZoomRegion(xMagFactor, yMagFactor, roi, viewPort) {
|
2023-05-29 14:42:13 +00:00
|
|
|
let zoomRegion = new ZoomRegion(this, this._cursorRoot);
|
2010-05-11 19:00:07 +00:00
|
|
|
zoomRegion.setViewPort(viewPort);
|
2010-10-30 20:31:30 +00:00
|
|
|
|
|
|
|
// We ignore the redundant width/height on the ROI
|
2019-08-19 19:18:54 +00:00
|
|
|
let fixedROI = Object.create(roi);
|
2010-10-30 20:31:30 +00:00
|
|
|
fixedROI.width = viewPort.width / xMagFactor;
|
|
|
|
fixedROI.height = viewPort.height / yMagFactor;
|
|
|
|
zoomRegion.setROI(fixedROI);
|
|
|
|
|
2010-05-11 19:00:07 +00:00
|
|
|
zoomRegion.addCrosshairs(this._crossHairs);
|
|
|
|
return zoomRegion;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* addZoomRegion:
|
|
|
|
* Append the given ZoomRegion to the list of currently defined ZoomRegions
|
|
|
|
* for this Magnifier instance.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {ZoomRegion} zoomRegion The zoomRegion to add.
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
addZoomRegion(zoomRegion) {
|
2019-01-29 01:27:05 +00:00
|
|
|
if (zoomRegion) {
|
2010-05-11 19:00:07 +00:00
|
|
|
this._zoomRegions.push(zoomRegion);
|
|
|
|
if (!this.isTrackingMouse())
|
|
|
|
this.startTrackingMouse();
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* getZoomRegions:
|
|
|
|
* Return a list of ZoomRegion's for this Magnifier.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @returns {ZoomRegion[]} The Magnifier's zoom region list.
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
getZoomRegions() {
|
2010-05-11 19:00:07 +00:00
|
|
|
return this._zoomRegions;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* clearAllZoomRegions:
|
|
|
|
* Remove all the zoom regions from this Magnfier's ZoomRegion list.
|
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
clearAllZoomRegions() {
|
2010-10-30 20:31:30 +00:00
|
|
|
for (let i = 0; i < this._zoomRegions.length; i++)
|
2010-05-11 19:00:07 +00:00
|
|
|
this._zoomRegions[i].setActive(false);
|
|
|
|
|
|
|
|
this._zoomRegions.length = 0;
|
|
|
|
this.stopTrackingMouse();
|
|
|
|
this.showSystemCursor();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* addCrosshairs:
|
|
|
|
* Add and show a cross hair centered on the magnified mouse.
|
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
addCrosshairs() {
|
2010-05-11 19:00:07 +00:00
|
|
|
if (!this._crossHairs)
|
|
|
|
this._crossHairs = new Crosshairs();
|
|
|
|
|
2010-06-19 13:43:39 +00:00
|
|
|
let thickness = this._settings.get_int(CROSS_HAIRS_THICKNESS_KEY);
|
|
|
|
let color = this._settings.get_string(CROSS_HAIRS_COLOR_KEY);
|
2011-02-12 15:24:18 +00:00
|
|
|
let opacity = this._settings.get_double(CROSS_HAIRS_OPACITY_KEY);
|
2010-06-19 13:43:39 +00:00
|
|
|
let length = this._settings.get_int(CROSS_HAIRS_LENGTH_KEY);
|
|
|
|
let clip = this._settings.get_boolean(CROSS_HAIRS_CLIP_KEY);
|
|
|
|
|
2010-05-11 19:00:07 +00:00
|
|
|
this.setCrosshairsThickness(thickness);
|
|
|
|
this.setCrosshairsColor(color);
|
|
|
|
this.setCrosshairsOpacity(opacity);
|
|
|
|
this.setCrosshairsLength(length);
|
|
|
|
this.setCrosshairsClip(clip);
|
|
|
|
|
|
|
|
let theCrossHairs = this._crossHairs;
|
2019-08-19 17:55:49 +00:00
|
|
|
this._zoomRegions.forEach(zoomRegion => {
|
2010-05-11 19:00:07 +00:00
|
|
|
zoomRegion.addCrosshairs(theCrossHairs);
|
|
|
|
});
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setCrosshairsVisible:
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* Show or hide the cross hair
|
|
|
|
*
|
|
|
|
* @param {boolean} visible Flag that indicates show (true) or hide (false).
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
setCrosshairsVisible(visible) {
|
2010-05-11 19:00:07 +00:00
|
|
|
if (visible) {
|
|
|
|
if (!this._crossHairs)
|
2010-06-19 13:43:39 +00:00
|
|
|
this.addCrosshairs();
|
2010-05-11 19:00:07 +00:00
|
|
|
this._crossHairs.show();
|
2019-01-29 21:02:57 +00:00
|
|
|
} else {
|
2019-08-20 02:24:37 +00:00
|
|
|
// eslint-disable-next-line no-lonely-if
|
2010-05-11 19:00:07 +00:00
|
|
|
if (this._crossHairs)
|
|
|
|
this._crossHairs.hide();
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setCrosshairsColor:
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
2010-05-11 19:00:07 +00:00
|
|
|
* Set the color of the crosshairs for all ZoomRegions.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {string} color The color as a string, e.g. '#ff0000ff' or 'red'.
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
setCrosshairsColor(color) {
|
2010-05-11 19:00:07 +00:00
|
|
|
if (this._crossHairs) {
|
2019-01-31 14:08:00 +00:00
|
|
|
let [res_, clutterColor] = Clutter.Color.from_string(color);
|
2010-05-11 19:00:07 +00:00
|
|
|
this._crossHairs.setColor(clutterColor);
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* getCrosshairsColor:
|
|
|
|
* Get the color of the crosshairs.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
2019-10-17 16:41:52 +00:00
|
|
|
* @returns {string} The color as a string, e.g. '#0000ffff' or 'blue'.
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
getCrosshairsColor() {
|
2010-05-11 19:00:07 +00:00
|
|
|
if (this._crossHairs) {
|
|
|
|
let clutterColor = this._crossHairs.getColor();
|
|
|
|
return clutterColor.to_string();
|
2019-01-29 21:02:57 +00:00
|
|
|
} else {
|
2010-05-13 19:46:04 +00:00
|
|
|
return '#00000000';
|
2019-01-29 21:02:57 +00:00
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setCrosshairsThickness:
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
2010-05-11 19:00:07 +00:00
|
|
|
* Set the crosshairs thickness for all ZoomRegions.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {number} thickness The width of the vertical and
|
2019-10-17 16:41:52 +00:00
|
|
|
* horizontal lines of the crosshairs.
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
setCrosshairsThickness(thickness) {
|
2010-05-11 19:00:07 +00:00
|
|
|
if (this._crossHairs)
|
|
|
|
this._crossHairs.setThickness(thickness);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* getCrosshairsThickness:
|
|
|
|
* Get the crosshairs thickness.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
2019-10-17 16:41:52 +00:00
|
|
|
* @returns {number} The width of the vertical and horizontal
|
|
|
|
* lines of the crosshairs.
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
getCrosshairsThickness() {
|
2010-05-11 19:00:07 +00:00
|
|
|
if (this._crossHairs)
|
|
|
|
return this._crossHairs.getThickness();
|
|
|
|
else
|
|
|
|
return 0;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setCrosshairsOpacity:
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {number} opacity Value between 0.0 (transparent)
|
2019-10-17 16:41:52 +00:00
|
|
|
* and 1.0 (fully opaque).
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
setCrosshairsOpacity(opacity) {
|
2010-05-11 19:00:07 +00:00
|
|
|
if (this._crossHairs)
|
2011-02-12 15:24:18 +00:00
|
|
|
this._crossHairs.setOpacity(opacity * 255);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* getCrosshairsOpacity:
|
2019-10-17 16:41:52 +00:00
|
|
|
* @returns {number} Value between 0.0 (transparent) and 1.0 (fully opaque).
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
getCrosshairsOpacity() {
|
2010-05-11 19:00:07 +00:00
|
|
|
if (this._crossHairs)
|
2011-02-12 15:24:18 +00:00
|
|
|
return this._crossHairs.getOpacity() / 255.0;
|
2010-05-11 19:00:07 +00:00
|
|
|
else
|
2011-02-12 15:24:18 +00:00
|
|
|
return 0.0;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setCrosshairsLength:
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
2010-05-11 19:00:07 +00:00
|
|
|
* Set the crosshairs length for all ZoomRegions.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {number} length The length of the vertical and horizontal
|
2019-10-17 16:41:52 +00:00
|
|
|
* lines making up the crosshairs.
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
setCrosshairsLength(length) {
|
2020-02-06 09:31:17 +00:00
|
|
|
if (this._crossHairs) {
|
|
|
|
let scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor;
|
|
|
|
this._crossHairs.setLength(length / scaleFactor);
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* getCrosshairsLength:
|
|
|
|
* Get the crosshairs length.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
2019-10-17 16:41:52 +00:00
|
|
|
* @returns {number} The length of the vertical and horizontal
|
|
|
|
* lines making up the crosshairs.
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
getCrosshairsLength() {
|
2010-05-11 19:00:07 +00:00
|
|
|
if (this._crossHairs)
|
|
|
|
return this._crossHairs.getLength();
|
|
|
|
else
|
|
|
|
return 0;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setCrosshairsClip:
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
2010-05-11 19:00:07 +00:00
|
|
|
* Set whether the crosshairs are clipped at their intersection.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {boolean} clip Flag to indicate whether to clip the crosshairs.
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
setCrosshairsClip(clip) {
|
2019-08-20 02:10:46 +00:00
|
|
|
if (!this._crossHairs)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Setting no clipping on crosshairs means a zero sized clip rectangle.
|
|
|
|
this._crossHairs.setClip(clip ? CROSSHAIRS_CLIP_SIZE : [0, 0]);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* getCrosshairsClip:
|
|
|
|
* Get whether the crosshairs are clipped by the mouse image.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @returns {boolean} Whether the crosshairs are clipped.
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2019-01-29 19:36:54 +00:00
|
|
|
getCrosshairsClip() {
|
2010-05-11 19:00:07 +00:00
|
|
|
if (this._crossHairs) {
|
|
|
|
let [clipWidth, clipHeight] = this._crossHairs.getClip();
|
2019-08-19 19:38:51 +00:00
|
|
|
return clipWidth > 0 && clipHeight > 0;
|
2019-01-29 21:02:57 +00:00
|
|
|
} else {
|
2010-05-11 19:00:07 +00:00
|
|
|
return false;
|
2019-01-29 21:02:57 +00:00
|
|
|
}
|
2019-01-29 19:36:54 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2019-08-19 17:55:49 +00:00
|
|
|
// Private methods //
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updateMouseSprite() {
|
2019-01-29 13:46:33 +00:00
|
|
|
this._updateSpriteTexture();
|
2013-08-13 12:22:22 +00:00
|
|
|
let [xHot, yHot] = this._cursorTracker.get_hot();
|
2020-06-26 18:54:32 +00:00
|
|
|
this._mouseSprite.set({
|
|
|
|
translation_x: -xHot,
|
|
|
|
translation_y: -yHot,
|
|
|
|
});
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2019-01-29 13:46:33 +00:00
|
|
|
_updateSpriteTexture() {
|
|
|
|
let sprite = this._cursorTracker.get_sprite();
|
|
|
|
|
|
|
|
if (sprite) {
|
|
|
|
this._mouseSprite.content.texture = sprite;
|
|
|
|
this._mouseSprite.show();
|
|
|
|
} else {
|
|
|
|
this._mouseSprite.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_settingsInit(zoomRegion) {
|
2014-06-24 19:17:09 +00:00
|
|
|
this._settings = new Gio.Settings({ schema_id: MAGNIFIER_SCHEMA });
|
2010-06-19 13:43:39 +00:00
|
|
|
|
2019-01-30 00:18:24 +00:00
|
|
|
this._settings.connect(`changed::${SCREEN_POSITION_KEY}`,
|
2017-12-02 00:27:35 +00:00
|
|
|
this._updateScreenPosition.bind(this));
|
2019-01-30 00:18:24 +00:00
|
|
|
this._settings.connect(`changed::${MAG_FACTOR_KEY}`,
|
2017-12-02 00:27:35 +00:00
|
|
|
this._updateMagFactor.bind(this));
|
2019-01-30 00:18:24 +00:00
|
|
|
this._settings.connect(`changed::${LENS_MODE_KEY}`,
|
2017-12-02 00:27:35 +00:00
|
|
|
this._updateLensMode.bind(this));
|
2019-01-30 00:18:24 +00:00
|
|
|
this._settings.connect(`changed::${CLAMP_MODE_KEY}`,
|
2017-12-02 00:27:35 +00:00
|
|
|
this._updateClampMode.bind(this));
|
2019-01-30 00:18:24 +00:00
|
|
|
this._settings.connect(`changed::${MOUSE_TRACKING_KEY}`,
|
2017-12-02 00:27:35 +00:00
|
|
|
this._updateMouseTrackingMode.bind(this));
|
2019-01-30 00:18:24 +00:00
|
|
|
this._settings.connect(`changed::${FOCUS_TRACKING_KEY}`,
|
2017-12-02 00:27:35 +00:00
|
|
|
this._updateFocusTrackingMode.bind(this));
|
2019-01-30 00:18:24 +00:00
|
|
|
this._settings.connect(`changed::${CARET_TRACKING_KEY}`,
|
2017-12-02 00:27:35 +00:00
|
|
|
this._updateCaretTrackingMode.bind(this));
|
2010-06-19 13:43:39 +00:00
|
|
|
|
2019-01-30 00:18:24 +00:00
|
|
|
this._settings.connect(`changed::${INVERT_LIGHTNESS_KEY}`,
|
2017-12-02 00:27:35 +00:00
|
|
|
this._updateInvertLightness.bind(this));
|
2019-01-30 00:18:24 +00:00
|
|
|
this._settings.connect(`changed::${COLOR_SATURATION_KEY}`,
|
2017-12-02 00:27:35 +00:00
|
|
|
this._updateColorSaturation.bind(this));
|
2012-04-04 15:10:31 +00:00
|
|
|
|
2019-01-30 00:18:24 +00:00
|
|
|
this._settings.connect(`changed::${BRIGHT_RED_KEY}`,
|
2017-12-02 00:27:35 +00:00
|
|
|
this._updateBrightness.bind(this));
|
2019-01-30 00:18:24 +00:00
|
|
|
this._settings.connect(`changed::${BRIGHT_GREEN_KEY}`,
|
2017-12-02 00:27:35 +00:00
|
|
|
this._updateBrightness.bind(this));
|
2019-01-30 00:18:24 +00:00
|
|
|
this._settings.connect(`changed::${BRIGHT_BLUE_KEY}`,
|
2017-12-02 00:27:35 +00:00
|
|
|
this._updateBrightness.bind(this));
|
2012-03-12 19:52:41 +00:00
|
|
|
|
2019-01-30 00:18:24 +00:00
|
|
|
this._settings.connect(`changed::${CONTRAST_RED_KEY}`,
|
2017-12-02 00:27:35 +00:00
|
|
|
this._updateContrast.bind(this));
|
2019-01-30 00:18:24 +00:00
|
|
|
this._settings.connect(`changed::${CONTRAST_GREEN_KEY}`,
|
2017-12-02 00:27:35 +00:00
|
|
|
this._updateContrast.bind(this));
|
2019-01-30 00:18:24 +00:00
|
|
|
this._settings.connect(`changed::${CONTRAST_BLUE_KEY}`,
|
2017-12-02 00:27:35 +00:00
|
|
|
this._updateContrast.bind(this));
|
2012-03-12 19:52:41 +00:00
|
|
|
|
2019-01-30 00:18:24 +00:00
|
|
|
this._settings.connect(`changed::${SHOW_CROSS_HAIRS_KEY}`, () => {
|
2010-06-19 13:43:39 +00:00
|
|
|
this.setCrosshairsVisible(this._settings.get_boolean(SHOW_CROSS_HAIRS_KEY));
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2010-06-19 13:43:39 +00:00
|
|
|
|
2019-01-30 00:18:24 +00:00
|
|
|
this._settings.connect(`changed::${CROSS_HAIRS_THICKNESS_KEY}`, () => {
|
2010-06-19 13:43:39 +00:00
|
|
|
this.setCrosshairsThickness(this._settings.get_int(CROSS_HAIRS_THICKNESS_KEY));
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2010-06-19 13:43:39 +00:00
|
|
|
|
2019-01-30 00:18:24 +00:00
|
|
|
this._settings.connect(`changed::${CROSS_HAIRS_COLOR_KEY}`, () => {
|
2010-06-19 13:43:39 +00:00
|
|
|
this.setCrosshairsColor(this._settings.get_string(CROSS_HAIRS_COLOR_KEY));
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2010-06-19 13:43:39 +00:00
|
|
|
|
2019-01-30 00:18:24 +00:00
|
|
|
this._settings.connect(`changed::${CROSS_HAIRS_OPACITY_KEY}`, () => {
|
2011-02-12 15:24:18 +00:00
|
|
|
this.setCrosshairsOpacity(this._settings.get_double(CROSS_HAIRS_OPACITY_KEY));
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2010-06-19 13:43:39 +00:00
|
|
|
|
2019-01-30 00:18:24 +00:00
|
|
|
this._settings.connect(`changed::${CROSS_HAIRS_LENGTH_KEY}`, () => {
|
2010-06-19 13:43:39 +00:00
|
|
|
this.setCrosshairsLength(this._settings.get_int(CROSS_HAIRS_LENGTH_KEY));
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2010-06-19 13:43:39 +00:00
|
|
|
|
2019-01-30 00:18:24 +00:00
|
|
|
this._settings.connect(`changed::${CROSS_HAIRS_CLIP_KEY}`, () => {
|
2010-06-19 13:43:39 +00:00
|
|
|
this.setCrosshairsClip(this._settings.get_boolean(CROSS_HAIRS_CLIP_KEY));
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2015-03-20 19:41:01 +00:00
|
|
|
|
|
|
|
if (zoomRegion) {
|
|
|
|
// Mag factor is accurate to two decimal places.
|
|
|
|
let aPref = parseFloat(this._settings.get_double(MAG_FACTOR_KEY).toFixed(2));
|
|
|
|
if (aPref != 0.0)
|
|
|
|
zoomRegion.setMagFactor(aPref, aPref);
|
|
|
|
|
|
|
|
aPref = this._settings.get_enum(SCREEN_POSITION_KEY);
|
|
|
|
if (aPref)
|
|
|
|
zoomRegion.setScreenPosition(aPref);
|
|
|
|
|
|
|
|
zoomRegion.setLensMode(this._settings.get_boolean(LENS_MODE_KEY));
|
|
|
|
zoomRegion.setClampScrollingAtEdges(!this._settings.get_boolean(CLAMP_MODE_KEY));
|
|
|
|
|
|
|
|
aPref = this._settings.get_enum(MOUSE_TRACKING_KEY);
|
|
|
|
if (aPref)
|
|
|
|
zoomRegion.setMouseTrackingMode(aPref);
|
|
|
|
|
|
|
|
aPref = this._settings.get_enum(FOCUS_TRACKING_KEY);
|
|
|
|
if (aPref)
|
|
|
|
zoomRegion.setFocusTrackingMode(aPref);
|
|
|
|
|
|
|
|
aPref = this._settings.get_enum(CARET_TRACKING_KEY);
|
|
|
|
if (aPref)
|
|
|
|
zoomRegion.setCaretTrackingMode(aPref);
|
|
|
|
|
|
|
|
aPref = this._settings.get_boolean(INVERT_LIGHTNESS_KEY);
|
|
|
|
if (aPref)
|
|
|
|
zoomRegion.setInvertLightness(aPref);
|
|
|
|
|
|
|
|
aPref = this._settings.get_double(COLOR_SATURATION_KEY);
|
|
|
|
if (aPref)
|
|
|
|
zoomRegion.setColorSaturation(aPref);
|
|
|
|
|
|
|
|
let bc = {};
|
|
|
|
bc.r = this._settings.get_double(BRIGHT_RED_KEY);
|
|
|
|
bc.g = this._settings.get_double(BRIGHT_GREEN_KEY);
|
|
|
|
bc.b = this._settings.get_double(BRIGHT_BLUE_KEY);
|
|
|
|
zoomRegion.setBrightness(bc);
|
|
|
|
|
|
|
|
bc.r = this._settings.get_double(CONTRAST_RED_KEY);
|
|
|
|
bc.g = this._settings.get_double(CONTRAST_GREEN_KEY);
|
|
|
|
bc.b = this._settings.get_double(CONTRAST_BLUE_KEY);
|
|
|
|
zoomRegion.setContrast(bc);
|
|
|
|
}
|
|
|
|
|
|
|
|
let showCrosshairs = this._settings.get_boolean(SHOW_CROSS_HAIRS_KEY);
|
|
|
|
this.addCrosshairs();
|
|
|
|
this.setCrosshairsVisible(showCrosshairs);
|
2019-01-29 19:36:54 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updateScreenPosition() {
|
2010-05-11 19:00:07 +00:00
|
|
|
// Applies only to the first zoom region.
|
|
|
|
if (this._zoomRegions.length) {
|
2010-06-19 13:43:39 +00:00
|
|
|
let position = this._settings.get_enum(SCREEN_POSITION_KEY);
|
2010-05-11 19:00:07 +00:00
|
|
|
this._zoomRegions[0].setScreenPosition(position);
|
2011-10-19 20:47:04 +00:00
|
|
|
if (position != GDesktopEnums.MagnifierScreenPosition.FULL_SCREEN)
|
2010-05-11 19:00:07 +00:00
|
|
|
this._updateLensMode();
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updateMagFactor() {
|
2010-05-11 19:00:07 +00:00
|
|
|
// Applies only to the first zoom region.
|
|
|
|
if (this._zoomRegions.length) {
|
|
|
|
// Mag factor is accurate to two decimal places.
|
2010-06-19 13:43:39 +00:00
|
|
|
let magFactor = parseFloat(this._settings.get_double(MAG_FACTOR_KEY).toFixed(2));
|
2010-05-11 19:00:07 +00:00
|
|
|
this._zoomRegions[0].setMagFactor(magFactor, magFactor);
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updateLensMode() {
|
2010-05-11 19:00:07 +00:00
|
|
|
// Applies only to the first zoom region.
|
2019-08-20 00:51:42 +00:00
|
|
|
if (this._zoomRegions.length)
|
2010-06-19 13:43:39 +00:00
|
|
|
this._zoomRegions[0].setLensMode(this._settings.get_boolean(LENS_MODE_KEY));
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updateClampMode() {
|
2010-05-11 19:00:07 +00:00
|
|
|
// Applies only to the first zoom region.
|
|
|
|
if (this._zoomRegions.length) {
|
|
|
|
this._zoomRegions[0].setClampScrollingAtEdges(
|
2020-04-03 23:52:29 +00:00
|
|
|
!this._settings.get_boolean(CLAMP_MODE_KEY));
|
2010-05-11 19:00:07 +00:00
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updateMouseTrackingMode() {
|
2010-05-11 19:00:07 +00:00
|
|
|
// Applies only to the first zoom region.
|
|
|
|
if (this._zoomRegions.length) {
|
|
|
|
this._zoomRegions[0].setMouseTrackingMode(
|
2020-04-03 23:52:29 +00:00
|
|
|
this._settings.get_enum(MOUSE_TRACKING_KEY));
|
2010-05-11 19:00:07 +00:00
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-03-12 19:52:41 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updateFocusTrackingMode() {
|
2013-09-04 17:53:36 +00:00
|
|
|
// Applies only to the first zoom region.
|
|
|
|
if (this._zoomRegions.length) {
|
|
|
|
this._zoomRegions[0].setFocusTrackingMode(
|
2020-04-03 23:52:29 +00:00
|
|
|
this._settings.get_enum(FOCUS_TRACKING_KEY));
|
2013-09-04 17:53:36 +00:00
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-09-04 17:53:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updateCaretTrackingMode() {
|
2013-09-04 17:53:36 +00:00
|
|
|
// Applies only to the first zoom region.
|
|
|
|
if (this._zoomRegions.length) {
|
|
|
|
this._zoomRegions[0].setCaretTrackingMode(
|
2020-04-03 23:52:29 +00:00
|
|
|
this._settings.get_enum(CARET_TRACKING_KEY));
|
2013-09-04 17:53:36 +00:00
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-09-04 17:53:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updateInvertLightness() {
|
2012-04-04 15:10:31 +00:00
|
|
|
// Applies only to the first zoom region.
|
|
|
|
if (this._zoomRegions.length) {
|
|
|
|
this._zoomRegions[0].setInvertLightness(
|
2020-04-03 23:52:29 +00:00
|
|
|
this._settings.get_boolean(INVERT_LIGHTNESS_KEY));
|
2012-04-04 15:10:31 +00:00
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-04-04 15:10:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updateColorSaturation() {
|
2012-06-01 12:36:47 +00:00
|
|
|
// Applies only to the first zoom region.
|
|
|
|
if (this._zoomRegions.length) {
|
|
|
|
this._zoomRegions[0].setColorSaturation(
|
2020-04-03 23:52:29 +00:00
|
|
|
this._settings.get_double(COLOR_SATURATION_KEY));
|
2012-06-01 12:36:47 +00:00
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-06-01 12:36:47 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updateBrightness() {
|
2012-03-12 19:52:41 +00:00
|
|
|
// Applies only to the first zoom region.
|
|
|
|
if (this._zoomRegions.length) {
|
|
|
|
let brightness = {};
|
|
|
|
brightness.r = this._settings.get_double(BRIGHT_RED_KEY);
|
|
|
|
brightness.g = this._settings.get_double(BRIGHT_GREEN_KEY);
|
|
|
|
brightness.b = this._settings.get_double(BRIGHT_BLUE_KEY);
|
|
|
|
this._zoomRegions[0].setBrightness(brightness);
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-03-12 19:52:41 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updateContrast() {
|
2012-03-12 19:52:41 +00:00
|
|
|
// Applies only to the first zoom region.
|
|
|
|
if (this._zoomRegions.length) {
|
|
|
|
let contrast = {};
|
|
|
|
contrast.r = this._settings.get_double(CONTRAST_RED_KEY);
|
|
|
|
contrast.g = this._settings.get_double(CONTRAST_GREEN_KEY);
|
|
|
|
contrast.b = this._settings.get_double(CONTRAST_BLUE_KEY);
|
|
|
|
this._zoomRegions[0].setContrast(contrast);
|
|
|
|
}
|
2013-09-04 17:53:36 +00:00
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
};
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
var ZoomRegion = class ZoomRegion {
|
|
|
|
constructor(magnifier, mouseSourceActor) {
|
2010-05-11 19:00:07 +00:00
|
|
|
this._magnifier = magnifier;
|
2013-09-04 17:53:36 +00:00
|
|
|
this._focusCaretTracker = new FocusCaretTracker.FocusCaretTracker();
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2011-10-19 20:47:04 +00:00
|
|
|
this._mouseTrackingMode = GDesktopEnums.MagnifierMouseTrackingMode.NONE;
|
2013-09-04 17:53:36 +00:00
|
|
|
this._focusTrackingMode = GDesktopEnums.MagnifierFocusTrackingMode.NONE;
|
|
|
|
this._caretTrackingMode = GDesktopEnums.MagnifierCaretTrackingMode.NONE;
|
2010-10-30 20:31:30 +00:00
|
|
|
this._clampScrollingAtEdges = false;
|
|
|
|
this._lensMode = false;
|
2011-10-19 20:47:04 +00:00
|
|
|
this._screenPosition = GDesktopEnums.MagnifierScreenPosition.FULL_SCREEN;
|
2012-04-04 15:10:31 +00:00
|
|
|
this._invertLightness = false;
|
2012-06-01 12:36:47 +00:00
|
|
|
this._colorSaturation = 1.0;
|
2012-03-12 19:52:41 +00:00
|
|
|
this._brightness = { r: NO_CHANGE, g: NO_CHANGE, b: NO_CHANGE };
|
|
|
|
this._contrast = { r: NO_CHANGE, g: NO_CHANGE, b: NO_CHANGE };
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2010-10-30 20:31:30 +00:00
|
|
|
this._magView = null;
|
2012-01-26 04:34:45 +00:00
|
|
|
this._background = null;
|
2010-10-30 20:31:30 +00:00
|
|
|
this._uiGroupClone = null;
|
|
|
|
this._mouseSourceActor = mouseSourceActor;
|
|
|
|
this._mouseActor = null;
|
2010-05-11 19:00:07 +00:00
|
|
|
this._crossHairs = null;
|
2010-10-30 20:31:30 +00:00
|
|
|
this._crossHairsActor = null;
|
|
|
|
|
|
|
|
this._viewPortX = 0;
|
|
|
|
this._viewPortY = 0;
|
|
|
|
this._viewPortWidth = global.screen_width;
|
2012-01-26 04:34:45 +00:00
|
|
|
this._viewPortHeight = global.screen_height;
|
2010-10-30 20:31:30 +00:00
|
|
|
this._xCenter = this._viewPortWidth / 2;
|
|
|
|
this._yCenter = this._viewPortHeight / 2;
|
|
|
|
this._xMagFactor = 1;
|
|
|
|
this._yMagFactor = 1;
|
|
|
|
this._followingCursor = false;
|
2013-09-04 17:53:36 +00:00
|
|
|
this._xFocus = 0;
|
|
|
|
this._yFocus = 0;
|
|
|
|
this._xCaret = 0;
|
|
|
|
this._yCaret = 0;
|
2012-01-26 04:34:45 +00:00
|
|
|
|
2021-05-06 20:31:11 +00:00
|
|
|
this._pointerIdleMonitor = global.backend.get_core_idle_monitor();
|
2015-07-24 16:47:34 +00:00
|
|
|
this._scrollContentsTimerId = 0;
|
2019-03-27 21:57:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_connectSignals() {
|
|
|
|
if (this._signalConnections)
|
|
|
|
return;
|
2015-07-24 16:47:34 +00:00
|
|
|
|
2019-03-27 21:57:33 +00:00
|
|
|
this._signalConnections = [];
|
|
|
|
let id = Main.layoutManager.connect('monitors-changed',
|
|
|
|
this._monitorsChanged.bind(this));
|
|
|
|
this._signalConnections.push([Main.layoutManager, id]);
|
|
|
|
|
|
|
|
id = this._focusCaretTracker.connect('caret-moved', this._updateCaret.bind(this));
|
|
|
|
this._signalConnections.push([this._focusCaretTracker, id]);
|
|
|
|
|
|
|
|
id = this._focusCaretTracker.connect('focus-changed', this._updateFocus.bind(this));
|
|
|
|
this._signalConnections.push([this._focusCaretTracker, id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
_disconnectSignals() {
|
|
|
|
for (let [obj, id] of this._signalConnections)
|
|
|
|
obj.disconnect(id);
|
|
|
|
|
|
|
|
delete this._signalConnections;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-09-04 17:53:36 +00:00
|
|
|
|
2019-03-27 21:16:26 +00:00
|
|
|
_updateScreenPosition() {
|
2019-08-20 00:51:42 +00:00
|
|
|
if (this._screenPosition == GDesktopEnums.MagnifierScreenPosition.NONE) {
|
2019-03-27 21:16:26 +00:00
|
|
|
this._setViewPort({
|
|
|
|
x: this._viewPortX,
|
|
|
|
y: this._viewPortY,
|
|
|
|
width: this._viewPortWidth,
|
2019-08-20 21:43:54 +00:00
|
|
|
height: this._viewPortHeight,
|
2019-03-27 21:16:26 +00:00
|
|
|
});
|
2019-08-20 00:51:42 +00:00
|
|
|
} else {
|
2019-03-27 21:16:26 +00:00
|
|
|
this.setScreenPosition(this._screenPosition);
|
2019-08-20 00:51:42 +00:00
|
|
|
}
|
2019-03-27 21:16:26 +00:00
|
|
|
}
|
|
|
|
|
2022-05-23 21:01:23 +00:00
|
|
|
_convertExtentsToScreenSpace(accessible, extents) {
|
|
|
|
const toplevelWindowTypes = new Set([
|
|
|
|
Atspi.Role.FRAME,
|
|
|
|
Atspi.Role.DIALOG,
|
|
|
|
Atspi.Role.WINDOW,
|
|
|
|
]);
|
|
|
|
|
|
|
|
try {
|
|
|
|
let app = null;
|
|
|
|
let parentWindow = null;
|
|
|
|
let iter = accessible;
|
|
|
|
while (iter) {
|
|
|
|
if (iter.get_role() === Atspi.Role.APPLICATION) {
|
|
|
|
app = iter;
|
|
|
|
/* This is the last Accessible we are interested in */
|
|
|
|
break;
|
|
|
|
} else if (toplevelWindowTypes.has(iter.get_role())) {
|
|
|
|
parentWindow = iter;
|
|
|
|
}
|
|
|
|
iter = iter.get_parent();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We don't want to translate our own events to the focus window.
|
|
|
|
* They are also already scaled by clutter before being sent, so
|
|
|
|
* we don't need to do that here either. */
|
|
|
|
if (app && app.get_name() === 'gnome-shell')
|
|
|
|
return extents;
|
|
|
|
|
|
|
|
/* Only events from the focused widget of the focused window. Some
|
|
|
|
* widgets seem to claim to have focus when the window does not so
|
|
|
|
* check both. */
|
|
|
|
const windowActive = parentWindow &&
|
|
|
|
parentWindow.get_state_set().contains(Atspi.StateType.ACTIVE);
|
|
|
|
const accessibleFocused =
|
|
|
|
accessible.get_state_set().contains(Atspi.StateType.FOCUSED);
|
|
|
|
if (!windowActive || !accessibleFocused)
|
|
|
|
return null;
|
|
|
|
} catch (e) {
|
|
|
|
throw new Error(`Failed to validate parent window: ${e}`);
|
|
|
|
}
|
|
|
|
|
2022-05-31 16:18:45 +00:00
|
|
|
const { focusWindow } = global.display;
|
|
|
|
if (!focusWindow)
|
2022-05-23 21:01:23 +00:00
|
|
|
return null;
|
|
|
|
|
2022-05-31 16:18:45 +00:00
|
|
|
let windowRect = focusWindow.get_frame_rect();
|
|
|
|
if (!focusWindow.is_client_decorated())
|
|
|
|
windowRect = focusWindow.frame_rect_to_client_rect(windowRect);
|
|
|
|
|
2022-05-23 21:01:23 +00:00
|
|
|
const scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor;
|
|
|
|
const screenSpaceExtents = new Atspi.Rect({
|
2022-05-31 16:18:45 +00:00
|
|
|
x: windowRect.x + (scaleFactor * extents.x),
|
|
|
|
y: windowRect.y + (scaleFactor * extents.y),
|
2022-05-23 21:01:23 +00:00
|
|
|
width: scaleFactor * extents.width,
|
|
|
|
height: scaleFactor * extents.height,
|
|
|
|
});
|
|
|
|
|
|
|
|
return screenSpaceExtents;
|
|
|
|
}
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updateFocus(caller, event) {
|
2013-09-04 17:53:36 +00:00
|
|
|
let component = event.source.get_component_iface();
|
|
|
|
if (!component || event.detail1 != 1)
|
|
|
|
return;
|
2014-02-13 15:12:59 +00:00
|
|
|
let extents;
|
|
|
|
try {
|
2022-05-23 21:01:23 +00:00
|
|
|
extents = component.get_extents(Atspi.CoordType.WINDOW);
|
|
|
|
extents = this._convertExtentsToScreenSpace(event.source, extents);
|
|
|
|
if (!extents)
|
|
|
|
return;
|
2019-01-29 01:26:39 +00:00
|
|
|
} catch (e) {
|
2019-01-30 00:18:24 +00:00
|
|
|
log(`Failed to read extents of focused component: ${e.message}`);
|
2014-02-13 15:12:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-27 13:18:34 +00:00
|
|
|
const [xFocus, yFocus] = [
|
2022-05-23 21:01:23 +00:00
|
|
|
extents.x + (extents.width / 2),
|
|
|
|
extents.y + (extents.height / 2),
|
2020-03-27 13:18:34 +00:00
|
|
|
];
|
2020-02-06 09:56:44 +00:00
|
|
|
|
|
|
|
if (this._xFocus !== xFocus || this._yFocus !== yFocus) {
|
|
|
|
[this._xFocus, this._yFocus] = [xFocus, yFocus];
|
|
|
|
this._centerFromFocusPosition();
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-09-04 17:53:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updateCaret(caller, event) {
|
2013-09-04 17:53:36 +00:00
|
|
|
let text = event.source.get_text_iface();
|
|
|
|
if (!text)
|
|
|
|
return;
|
2014-02-13 15:12:59 +00:00
|
|
|
let extents;
|
|
|
|
try {
|
2022-05-23 21:01:23 +00:00
|
|
|
extents = text.get_character_extents(text.get_caret_offset(),
|
|
|
|
Atspi.CoordType.WINDOW);
|
|
|
|
extents = this._convertExtentsToScreenSpace(text, extents);
|
|
|
|
if (!extents)
|
|
|
|
return;
|
2019-01-29 01:26:39 +00:00
|
|
|
} catch (e) {
|
2019-01-30 00:18:24 +00:00
|
|
|
log(`Failed to read extents of text caret: ${e.message}`);
|
2014-02-13 15:12:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-23 21:01:23 +00:00
|
|
|
const [xCaret, yCaret] = [extents.x, extents.y];
|
2020-02-06 09:56:44 +00:00
|
|
|
|
2021-04-24 17:03:35 +00:00
|
|
|
// Ignore event(s) if the caret size is none (0x0). This happens a lot if
|
|
|
|
// the cursor offset can't be translated into a location. This is a work
|
|
|
|
// around.
|
|
|
|
if (extents.width === 0 && extents.height === 0)
|
|
|
|
return;
|
|
|
|
|
2020-02-06 09:56:44 +00:00
|
|
|
if (this._xCaret !== xCaret || this._yCaret !== yCaret) {
|
|
|
|
[this._xCaret, this._yCaret] = [xCaret, yCaret];
|
|
|
|
this._centerFromCaretPosition();
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setActive:
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {boolean} activate Boolean to show/hide the ZoomRegion.
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
setActive(activate) {
|
2013-09-13 09:56:54 +00:00
|
|
|
if (activate == this.isActive())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (activate) {
|
2010-10-30 20:31:30 +00:00
|
|
|
this._createActors();
|
|
|
|
if (this._isMouseOverRegion())
|
2010-05-11 19:00:07 +00:00
|
|
|
this._magnifier.hideSystemCursor();
|
2019-03-27 21:16:26 +00:00
|
|
|
this._updateScreenPosition();
|
2010-10-30 20:31:30 +00:00
|
|
|
this._updateMagViewGeometry();
|
|
|
|
this._updateCloneGeometry();
|
|
|
|
this._updateMousePosition();
|
2019-03-27 21:57:33 +00:00
|
|
|
this._connectSignals();
|
2013-09-13 09:56:54 +00:00
|
|
|
} else {
|
2021-06-25 09:09:06 +00:00
|
|
|
Main.uiGroup.set_opacity(255);
|
2019-03-27 21:57:33 +00:00
|
|
|
this._disconnectSignals();
|
2010-10-30 20:31:30 +00:00
|
|
|
this._destroyActors();
|
2010-05-11 19:00:07 +00:00
|
|
|
}
|
2014-02-13 15:25:24 +00:00
|
|
|
|
|
|
|
this._syncCaretTracking();
|
|
|
|
this._syncFocusTracking();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* isActive:
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @returns {boolean} Whether this ZoomRegion is active
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
isActive() {
|
2010-10-30 20:31:30 +00:00
|
|
|
return this._magView != null;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setMagFactor:
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {number} xMagFactor The power to set the horizontal
|
2019-10-17 16:41:52 +00:00
|
|
|
* magnification factor to of the magnified view. A value of 1.0
|
|
|
|
* means no magnification. A value of 2.0 doubles the size.
|
2023-07-30 12:56:59 +00:00
|
|
|
* @param {number} yMagFactor The power to set the vertical
|
2019-10-17 16:41:52 +00:00
|
|
|
* magnification factor to of the magnified view.
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
setMagFactor(xMagFactor, yMagFactor) {
|
2020-03-29 21:51:13 +00:00
|
|
|
this._changeROI({
|
|
|
|
xMagFactor,
|
|
|
|
yMagFactor,
|
|
|
|
redoCursorTracking: this._followingCursor,
|
|
|
|
animate: true,
|
|
|
|
});
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* getMagFactor:
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
2019-10-17 16:41:52 +00:00
|
|
|
* @returns {number[]} an array, [xMagFactor, yMagFactor], containing
|
|
|
|
* the horizontal and vertical magnification powers. A value of
|
|
|
|
* 1.0 means no magnification. A value of 2.0 means the contents
|
|
|
|
* are doubled in size, and so on.
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
getMagFactor() {
|
2010-10-30 20:31:30 +00:00
|
|
|
return [this._xMagFactor, this._yMagFactor];
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setMouseTrackingMode
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {GDesktopEnums.MagnifierMouseTrackingMode} mode the new mode
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
setMouseTrackingMode(mode) {
|
2011-10-19 20:47:04 +00:00
|
|
|
if (mode >= GDesktopEnums.MagnifierMouseTrackingMode.NONE &&
|
|
|
|
mode <= GDesktopEnums.MagnifierMouseTrackingMode.PUSH)
|
2010-05-11 19:00:07 +00:00
|
|
|
this._mouseTrackingMode = mode;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
2023-07-30 12:56:59 +00:00
|
|
|
* getMouseTrackingMode:
|
|
|
|
*
|
2019-10-17 16:41:52 +00:00
|
|
|
* @returns {GDesktopEnums.MagnifierMouseTrackingMode} the current mode
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
getMouseTrackingMode() {
|
2010-05-11 19:00:07 +00:00
|
|
|
return this._mouseTrackingMode;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2013-09-04 17:53:36 +00:00
|
|
|
/**
|
|
|
|
* setFocusTrackingMode
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {GDesktopEnums.MagnifierFocusTrackingMode} mode the new mode
|
2013-09-04 17:53:36 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
setFocusTrackingMode(mode) {
|
2013-09-04 17:53:36 +00:00
|
|
|
this._focusTrackingMode = mode;
|
2014-02-13 15:25:24 +00:00
|
|
|
this._syncFocusTracking();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-09-04 17:53:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setCaretTrackingMode
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {GDesktopEnums.MagnifierCaretTrackingMode} mode the new mode
|
2013-09-04 17:53:36 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
setCaretTrackingMode(mode) {
|
2013-09-04 17:53:36 +00:00
|
|
|
this._caretTrackingMode = mode;
|
2014-02-13 15:25:24 +00:00
|
|
|
this._syncCaretTracking();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2014-02-13 15:25:24 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_syncFocusTracking() {
|
2014-02-13 15:25:24 +00:00
|
|
|
let enabled = this._focusTrackingMode != GDesktopEnums.MagnifierFocusTrackingMode.NONE &&
|
|
|
|
this.isActive();
|
|
|
|
|
|
|
|
if (enabled)
|
|
|
|
this._focusCaretTracker.registerFocusListener();
|
2013-09-04 17:53:36 +00:00
|
|
|
else
|
2014-02-13 15:25:24 +00:00
|
|
|
this._focusCaretTracker.deregisterFocusListener();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2014-02-13 15:25:24 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_syncCaretTracking() {
|
2014-02-13 15:25:24 +00:00
|
|
|
let enabled = this._caretTrackingMode != GDesktopEnums.MagnifierCaretTrackingMode.NONE &&
|
|
|
|
this.isActive();
|
|
|
|
|
|
|
|
if (enabled)
|
2013-09-04 17:53:36 +00:00
|
|
|
this._focusCaretTracker.registerCaretListener();
|
2014-02-13 15:25:24 +00:00
|
|
|
else
|
|
|
|
this._focusCaretTracker.deregisterCaretListener();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-09-04 17:53:36 +00:00
|
|
|
|
2010-05-11 19:00:07 +00:00
|
|
|
/**
|
|
|
|
* setViewPort
|
|
|
|
* Sets the position and size of the ZoomRegion on screen.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {{x: number, y: number, width: number, height: number}} viewPort
|
2019-10-17 16:41:52 +00:00
|
|
|
* Object defining the position and size of the view port.
|
|
|
|
* The values are in stage coordinate space.
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
setViewPort(viewPort) {
|
2010-10-30 20:31:30 +00:00
|
|
|
this._setViewPort(viewPort);
|
2011-10-19 20:47:04 +00:00
|
|
|
this._screenPosition = GDesktopEnums.MagnifierScreenPosition.NONE;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setROI
|
|
|
|
* Sets the "region of interest" that the ZoomRegion is magnifying.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {{x: number, y: number, width: number, height: number}} roi
|
2019-10-17 16:41:52 +00:00
|
|
|
* Object that defines the region of the screen to magnify.
|
|
|
|
* The values are in screen (unmagnified) coordinate space.
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
setROI(roi) {
|
2010-10-30 20:31:30 +00:00
|
|
|
if (roi.width <= 0 || roi.height <= 0)
|
|
|
|
return;
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2010-10-30 20:31:30 +00:00
|
|
|
this._followingCursor = false;
|
2020-03-29 21:51:13 +00:00
|
|
|
this._changeROI({
|
|
|
|
xMagFactor: this._viewPortWidth / roi.width,
|
|
|
|
yMagFactor: this._viewPortHeight / roi.height,
|
|
|
|
xCenter: roi.x + roi.width / 2,
|
|
|
|
yCenter: roi.y + roi.height / 2,
|
|
|
|
});
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* getROI:
|
|
|
|
* Retrieves the "region of interest" -- the rectangular bounds of that part
|
|
|
|
* of the desktop that the magnified view is showing (x, y, width, height).
|
|
|
|
* The bounds are given in non-magnified coordinates.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
2019-10-17 16:41:52 +00:00
|
|
|
* @returns {number[]} an array, [x, y, width, height], representing
|
|
|
|
* the bounding rectangle of what is shown in the magnified view.
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
getROI() {
|
2010-10-30 20:31:30 +00:00
|
|
|
let roiWidth = this._viewPortWidth / this._xMagFactor;
|
|
|
|
let roiHeight = this._viewPortHeight / this._yMagFactor;
|
|
|
|
|
2020-03-27 13:18:34 +00:00
|
|
|
return [
|
|
|
|
this._xCenter - roiWidth / 2,
|
|
|
|
this._yCenter - roiHeight / 2,
|
|
|
|
roiWidth, roiHeight,
|
|
|
|
];
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setLensMode:
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* Turn lens mode on/off. In full screen mode, lens mode does nothing since
|
2010-05-11 19:00:07 +00:00
|
|
|
* a lens the size of the screen is pointless.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {boolean} lensMode Whether lensMode should be active
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
setLensMode(lensMode) {
|
2010-10-30 20:31:30 +00:00
|
|
|
this._lensMode = lensMode;
|
|
|
|
if (!this._lensMode)
|
2019-08-19 17:55:49 +00:00
|
|
|
this.setScreenPosition(this._screenPosition);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* isLensMode:
|
|
|
|
* Is lens mode on or off?
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @returns {boolean} The lens mode state.
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
isLensMode() {
|
2010-05-11 19:00:07 +00:00
|
|
|
return this._lensMode;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setClampScrollingAtEdges:
|
|
|
|
* Stop vs. allow scrolling of the magnified contents when it scroll beyond
|
|
|
|
* the edges of the screen.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {boolean} clamp Boolean to turn on/off clamping.
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
setClampScrollingAtEdges(clamp) {
|
2010-05-11 19:00:07 +00:00
|
|
|
this._clampScrollingAtEdges = clamp;
|
2010-10-30 20:31:30 +00:00
|
|
|
if (clamp)
|
|
|
|
this._changeROI();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setTopHalf:
|
|
|
|
* Magnifier view occupies the top half of the screen.
|
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
setTopHalf() {
|
2010-05-11 19:00:07 +00:00
|
|
|
let viewPort = {};
|
|
|
|
viewPort.x = 0;
|
|
|
|
viewPort.y = 0;
|
|
|
|
viewPort.width = global.screen_width;
|
2019-01-29 01:27:05 +00:00
|
|
|
viewPort.height = global.screen_height / 2;
|
2010-10-30 20:31:30 +00:00
|
|
|
this._setViewPort(viewPort);
|
2011-10-19 20:47:04 +00:00
|
|
|
this._screenPosition = GDesktopEnums.MagnifierScreenPosition.TOP_HALF;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setBottomHalf:
|
|
|
|
* Magnifier view occupies the bottom half of the screen.
|
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
setBottomHalf() {
|
2010-05-11 19:00:07 +00:00
|
|
|
let viewPort = {};
|
|
|
|
viewPort.x = 0;
|
2019-01-29 01:27:05 +00:00
|
|
|
viewPort.y = global.screen_height / 2;
|
2010-05-11 19:00:07 +00:00
|
|
|
viewPort.width = global.screen_width;
|
2019-01-29 01:27:05 +00:00
|
|
|
viewPort.height = global.screen_height / 2;
|
2010-10-30 20:31:30 +00:00
|
|
|
this._setViewPort(viewPort);
|
2011-10-19 20:47:04 +00:00
|
|
|
this._screenPosition = GDesktopEnums.MagnifierScreenPosition.BOTTOM_HALF;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setLeftHalf:
|
|
|
|
* Magnifier view occupies the left half of the screen.
|
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
setLeftHalf() {
|
2010-05-11 19:00:07 +00:00
|
|
|
let viewPort = {};
|
|
|
|
viewPort.x = 0;
|
|
|
|
viewPort.y = 0;
|
2019-01-29 01:27:05 +00:00
|
|
|
viewPort.width = global.screen_width / 2;
|
2010-05-11 19:00:07 +00:00
|
|
|
viewPort.height = global.screen_height;
|
2010-10-30 20:31:30 +00:00
|
|
|
this._setViewPort(viewPort);
|
2011-10-19 20:47:04 +00:00
|
|
|
this._screenPosition = GDesktopEnums.MagnifierScreenPosition.LEFT_HALF;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setRightHalf:
|
|
|
|
* Magnifier view occupies the right half of the screen.
|
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
setRightHalf() {
|
2010-05-11 19:00:07 +00:00
|
|
|
let viewPort = {};
|
2019-01-29 01:27:05 +00:00
|
|
|
viewPort.x = global.screen_width / 2;
|
2010-05-11 19:00:07 +00:00
|
|
|
viewPort.y = 0;
|
2019-01-29 01:27:05 +00:00
|
|
|
viewPort.width = global.screen_width / 2;
|
2010-05-11 19:00:07 +00:00
|
|
|
viewPort.height = global.screen_height;
|
2010-10-30 20:31:30 +00:00
|
|
|
this._setViewPort(viewPort);
|
2011-10-19 20:47:04 +00:00
|
|
|
this._screenPosition = GDesktopEnums.MagnifierScreenPosition.RIGHT_HALF;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setFullScreenMode:
|
|
|
|
* Set the ZoomRegion to full-screen mode.
|
|
|
|
* Note: disallows lens mode.
|
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
setFullScreenMode() {
|
2010-10-30 20:31:30 +00:00
|
|
|
let viewPort = {};
|
|
|
|
viewPort.x = 0;
|
|
|
|
viewPort.y = 0;
|
|
|
|
viewPort.width = global.screen_width;
|
|
|
|
viewPort.height = global.screen_height;
|
|
|
|
this.setViewPort(viewPort);
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2011-10-19 20:47:04 +00:00
|
|
|
this._screenPosition = GDesktopEnums.MagnifierScreenPosition.FULL_SCREEN;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setScreenPosition:
|
|
|
|
* Positions the zoom region to one of the enumerated positions on the
|
|
|
|
* screen.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {GDesktopEnums.MagnifierScreenPosition} inPosition the position
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
setScreenPosition(inPosition) {
|
2010-05-11 19:00:07 +00:00
|
|
|
switch (inPosition) {
|
2019-02-01 12:21:00 +00:00
|
|
|
case GDesktopEnums.MagnifierScreenPosition.FULL_SCREEN:
|
|
|
|
this.setFullScreenMode();
|
|
|
|
break;
|
|
|
|
case GDesktopEnums.MagnifierScreenPosition.TOP_HALF:
|
|
|
|
this.setTopHalf();
|
|
|
|
break;
|
|
|
|
case GDesktopEnums.MagnifierScreenPosition.BOTTOM_HALF:
|
|
|
|
this.setBottomHalf();
|
|
|
|
break;
|
|
|
|
case GDesktopEnums.MagnifierScreenPosition.LEFT_HALF:
|
|
|
|
this.setLeftHalf();
|
|
|
|
break;
|
|
|
|
case GDesktopEnums.MagnifierScreenPosition.RIGHT_HALF:
|
|
|
|
this.setRightHalf();
|
|
|
|
break;
|
2010-05-11 19:00:07 +00:00
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2010-10-30 20:31:30 +00:00
|
|
|
/**
|
|
|
|
* getScreenPosition:
|
|
|
|
* Tell the outside world what the current mode is -- magnifiying the
|
|
|
|
* top half, bottom half, etc.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @returns {GDesktopEnums.MagnifierScreenPosition}: the current position.
|
2010-10-30 20:31:30 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
getScreenPosition() {
|
2010-10-30 20:31:30 +00:00
|
|
|
return this._screenPosition;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-10-30 20:31:30 +00:00
|
|
|
|
2020-02-06 12:25:20 +00:00
|
|
|
_clearScrollContentsTimer() {
|
|
|
|
if (this._scrollContentsTimerId !== 0) {
|
|
|
|
GLib.source_remove(this._scrollContentsTimerId);
|
|
|
|
this._scrollContentsTimerId = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-30 20:31:30 +00:00
|
|
|
/**
|
|
|
|
* scrollToMousePos:
|
|
|
|
* Set the region of interest based on the position of the system pointer.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @returns {boolean}: Whether the system mouse pointer is over the
|
2019-10-17 16:41:52 +00:00
|
|
|
* magnified view.
|
2010-10-30 20:31:30 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
scrollToMousePos() {
|
2010-10-30 20:31:30 +00:00
|
|
|
this._followingCursor = true;
|
2011-10-19 20:47:04 +00:00
|
|
|
if (this._mouseTrackingMode != GDesktopEnums.MagnifierMouseTrackingMode.NONE)
|
2010-10-30 20:31:30 +00:00
|
|
|
this._changeROI({ redoCursorTracking: true });
|
|
|
|
else
|
|
|
|
this._updateMousePosition();
|
|
|
|
|
2020-02-06 12:25:20 +00:00
|
|
|
this._clearScrollContentsTimer();
|
|
|
|
this._scrollContentsTimerId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, POINTER_REST_TIME, () => {
|
|
|
|
this._followingCursor = false;
|
|
|
|
if (this._xDelayed !== null && this._yDelayed !== null) {
|
|
|
|
this._scrollContentsToDelayed(this._xDelayed, this._yDelayed);
|
|
|
|
this._xDelayed = null;
|
|
|
|
this._yDelayed = null;
|
|
|
|
}
|
|
|
|
|
2021-06-28 12:17:25 +00:00
|
|
|
this._scrollContentsTimerId = 0;
|
|
|
|
|
2020-02-06 12:25:20 +00:00
|
|
|
return GLib.SOURCE_REMOVE;
|
|
|
|
});
|
|
|
|
|
2010-10-30 20:31:30 +00:00
|
|
|
// Determine whether the system mouse pointer is over this zoom region.
|
|
|
|
return this._isMouseOverRegion();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-10-30 20:31:30 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_scrollContentsToDelayed(x, y) {
|
2020-02-06 12:25:20 +00:00
|
|
|
if (this._followingCursor) {
|
|
|
|
this._xDelayed = x;
|
|
|
|
this._yDelayed = y;
|
|
|
|
} else {
|
2015-07-24 16:47:34 +00:00
|
|
|
this.scrollContentsTo(x, y);
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2015-07-24 16:47:34 +00:00
|
|
|
|
2010-05-11 19:00:07 +00:00
|
|
|
/**
|
|
|
|
* scrollContentsTo:
|
|
|
|
* Shift the contents of the magnified view such it is centered on the given
|
2010-10-30 20:31:30 +00:00
|
|
|
* coordinate.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {number} x The x-coord of the point to center on.
|
|
|
|
* @param {number} y The y-coord of the point to center on.
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
scrollContentsTo(x, y) {
|
2020-02-06 09:52:24 +00:00
|
|
|
if (x < 0 || x > global.screen_width ||
|
|
|
|
y < 0 || y > global.screen_height)
|
|
|
|
return;
|
|
|
|
|
2015-07-24 16:47:34 +00:00
|
|
|
this._clearScrollContentsTimer();
|
|
|
|
|
2010-10-30 20:31:30 +00:00
|
|
|
this._followingCursor = false;
|
2020-03-29 21:51:13 +00:00
|
|
|
this._changeROI({
|
|
|
|
xCenter: x,
|
|
|
|
yCenter: y,
|
|
|
|
animate: true,
|
|
|
|
});
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* addCrosshairs:
|
|
|
|
* Add crosshairs centered on the magnified mouse.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {Crosshairs} crossHairs Crosshairs instance
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
addCrosshairs(crossHairs) {
|
2010-10-30 20:31:30 +00:00
|
|
|
this._crossHairs = crossHairs;
|
|
|
|
|
2010-05-11 19:00:07 +00:00
|
|
|
// If the crossHairs is not already within a larger container, add it
|
|
|
|
// to this zoom region. Otherwise, add a clone.
|
2019-08-20 00:51:42 +00:00
|
|
|
if (crossHairs && this.isActive())
|
2010-10-30 20:31:30 +00:00
|
|
|
this._crossHairsActor = crossHairs.addToZoomRegion(this, this._mouseActor);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2012-04-04 15:10:31 +00:00
|
|
|
/**
|
|
|
|
* setInvertLightness:
|
|
|
|
* Set whether to invert the lightness of the magnified view.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {boolean} flag whether brightness should be inverted
|
2012-04-04 15:10:31 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
setInvertLightness(flag) {
|
2012-04-04 15:10:31 +00:00
|
|
|
this._invertLightness = flag;
|
|
|
|
if (this._magShaderEffects)
|
|
|
|
this._magShaderEffects.setInvertLightness(this._invertLightness);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-04-04 15:10:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* getInvertLightness:
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
2012-04-04 15:10:31 +00:00
|
|
|
* Retrieve whether the lightness is inverted.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @returns {boolean} whether brightness should be inverted
|
2012-04-04 15:10:31 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
getInvertLightness() {
|
2012-04-04 15:10:31 +00:00
|
|
|
return this._invertLightness;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-04-04 15:10:31 +00:00
|
|
|
|
2012-06-01 12:36:47 +00:00
|
|
|
/**
|
|
|
|
* setColorSaturation:
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
2012-06-01 12:36:47 +00:00
|
|
|
* Set the color saturation of the magnified view.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {number} saturation A value from 0.0 to 1.0 that defines
|
2019-10-17 16:41:52 +00:00
|
|
|
* the color saturation, with 0.0 defining no color (grayscale),
|
|
|
|
* and 1.0 defining full color.
|
2012-06-01 12:36:47 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
setColorSaturation(saturation) {
|
2012-06-01 12:36:47 +00:00
|
|
|
this._colorSaturation = saturation;
|
|
|
|
if (this._magShaderEffects)
|
|
|
|
this._magShaderEffects.setColorSaturation(this._colorSaturation);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-06-01 12:36:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* getColorSaturation:
|
|
|
|
* Retrieve the color saturation of the magnified view.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @returns {number} the color saturation
|
2012-06-01 12:36:47 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
getColorSaturation() {
|
2012-06-01 12:36:47 +00:00
|
|
|
return this._colorSaturation;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-06-01 12:36:47 +00:00
|
|
|
|
2012-03-12 19:52:41 +00:00
|
|
|
/**
|
|
|
|
* setBrightness:
|
|
|
|
* Alter the brightness of the magnified view.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {object} brightness Object containing the contrast for the
|
2019-10-17 16:41:52 +00:00
|
|
|
* red, green, and blue channels. Values of 0.0 represent "standard"
|
|
|
|
* brightness (no change), whereas values less or greater than
|
|
|
|
* 0.0 indicate decreased or incresaed brightness, respectively.
|
|
|
|
*
|
|
|
|
* {number} brightness.r - the red component
|
|
|
|
* {number} brightness.g - the green component
|
|
|
|
* {number} brightness.b - the blue component
|
2012-03-12 19:52:41 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
setBrightness(brightness) {
|
2012-03-12 19:52:41 +00:00
|
|
|
this._brightness.r = brightness.r;
|
|
|
|
this._brightness.g = brightness.g;
|
|
|
|
this._brightness.b = brightness.b;
|
|
|
|
if (this._magShaderEffects)
|
|
|
|
this._magShaderEffects.setBrightness(this._brightness);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-03-12 19:52:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setContrast:
|
|
|
|
* Alter the contrast of the magnified view.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {object} contrast Object containing the contrast for the
|
2019-10-17 16:41:52 +00:00
|
|
|
* red, green, and blue channels. Values of 0.0 represent "standard"
|
|
|
|
* contrast (no change), whereas values less or greater than
|
|
|
|
* 0.0 indicate decreased or incresaed contrast, respectively.
|
|
|
|
*
|
|
|
|
* {number} contrast.r - the red component
|
|
|
|
* {number} contrast.g - the green component
|
|
|
|
* {number} contrast.b - the blue component
|
2012-03-12 19:52:41 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
setContrast(contrast) {
|
2012-03-12 19:52:41 +00:00
|
|
|
this._contrast.r = contrast.r;
|
|
|
|
this._contrast.g = contrast.g;
|
|
|
|
this._contrast.b = contrast.b;
|
|
|
|
if (this._magShaderEffects)
|
|
|
|
this._magShaderEffects.setContrast(this._contrast);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-03-12 19:52:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* getContrast:
|
2019-05-15 19:32:29 +00:00
|
|
|
* Retrieve the contrast of the magnified view.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @returns {{r: number, g: number, b: number}}: Object containing
|
2019-10-17 16:41:52 +00:00
|
|
|
* the contrast for the red, green, and blue channels.
|
2012-03-12 19:52:41 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
getContrast() {
|
2012-03-12 19:52:41 +00:00
|
|
|
let contrast = {};
|
|
|
|
contrast.r = this._contrast.r;
|
|
|
|
contrast.g = this._contrast.g;
|
|
|
|
contrast.b = this._contrast.b;
|
|
|
|
return contrast;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-03-12 19:52:41 +00:00
|
|
|
|
2019-08-19 17:55:49 +00:00
|
|
|
// Private methods //
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_createActors() {
|
2010-10-30 20:31:30 +00:00
|
|
|
// The root actor for the zoom region
|
2019-10-17 21:40:24 +00:00
|
|
|
this._magView = new St.Bin({ style_class: 'magnifier-zoom-region' });
|
2010-10-30 20:31:30 +00:00
|
|
|
global.stage.add_actor(this._magView);
|
|
|
|
|
2010-11-17 10:08:24 +00:00
|
|
|
// hide the magnified region from CLUTTER_PICK_ALL
|
2019-08-19 17:55:49 +00:00
|
|
|
Shell.util_set_hidden_from_pick(this._magView, true);
|
2010-11-17 10:08:24 +00:00
|
|
|
|
2012-08-31 00:35:17 +00:00
|
|
|
// Add a group to clip the contents of the magnified view.
|
|
|
|
let mainGroup = new Clutter.Actor({ clip_to_allocation: true });
|
2010-10-30 20:31:30 +00:00
|
|
|
this._magView.set_child(mainGroup);
|
|
|
|
|
|
|
|
// Add a background for when the magnified uiGroup is scrolled
|
|
|
|
// out of view (don't want to see desktop showing through).
|
2019-07-16 09:24:13 +00:00
|
|
|
this._background = new Background.SystemBackground();
|
2012-01-26 04:34:45 +00:00
|
|
|
mainGroup.add_actor(this._background);
|
2010-10-30 20:31:30 +00:00
|
|
|
|
|
|
|
// Clone the group that contains all of UI on the screen. This is the
|
|
|
|
// chrome, the windows, etc.
|
2020-03-29 21:51:13 +00:00
|
|
|
this._uiGroupClone = new Clutter.Clone({
|
|
|
|
source: Main.uiGroup,
|
|
|
|
clip_to_allocation: true,
|
|
|
|
});
|
2010-10-30 20:31:30 +00:00
|
|
|
mainGroup.add_actor(this._uiGroupClone);
|
|
|
|
|
|
|
|
// Add either the given mouseSourceActor to the ZoomRegion, or a clone of
|
|
|
|
// it.
|
|
|
|
if (this._mouseSourceActor.get_parent() != null)
|
|
|
|
this._mouseActor = new Clutter.Clone({ source: this._mouseSourceActor });
|
|
|
|
else
|
|
|
|
this._mouseActor = this._mouseSourceActor;
|
|
|
|
mainGroup.add_actor(this._mouseActor);
|
|
|
|
|
|
|
|
if (this._crossHairs)
|
|
|
|
this._crossHairsActor = this._crossHairs.addToZoomRegion(this, this._mouseActor);
|
|
|
|
else
|
|
|
|
this._crossHairsActor = null;
|
2012-03-12 19:52:41 +00:00
|
|
|
|
|
|
|
// Contrast and brightness effects.
|
2020-02-06 09:33:27 +00:00
|
|
|
this._magShaderEffects = new MagShaderEffects(mainGroup);
|
2012-06-01 12:36:47 +00:00
|
|
|
this._magShaderEffects.setColorSaturation(this._colorSaturation);
|
2012-04-04 15:10:31 +00:00
|
|
|
this._magShaderEffects.setInvertLightness(this._invertLightness);
|
2012-03-12 19:52:41 +00:00
|
|
|
this._magShaderEffects.setBrightness(this._brightness);
|
|
|
|
this._magShaderEffects.setContrast(this._contrast);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-10-30 20:31:30 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_destroyActors() {
|
2010-10-30 20:31:30 +00:00
|
|
|
if (this._mouseActor == this._mouseSourceActor)
|
2019-08-19 17:55:49 +00:00
|
|
|
this._mouseActor.get_parent().remove_actor(this._mouseActor);
|
2010-10-30 20:31:30 +00:00
|
|
|
if (this._crossHairs)
|
|
|
|
this._crossHairs.removeFromParent(this._crossHairsActor);
|
|
|
|
|
2012-03-12 19:52:41 +00:00
|
|
|
this._magShaderEffects.destroyEffects();
|
|
|
|
this._magShaderEffects = null;
|
2010-10-30 20:31:30 +00:00
|
|
|
this._magView.destroy();
|
|
|
|
this._magView = null;
|
2012-01-26 04:34:45 +00:00
|
|
|
this._background = null;
|
2010-10-30 20:31:30 +00:00
|
|
|
this._uiGroupClone = null;
|
|
|
|
this._mouseActor = null;
|
|
|
|
this._crossHairsActor = null;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-10-30 20:31:30 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_setViewPort(viewPort, fromROIUpdate) {
|
2010-10-30 20:31:30 +00:00
|
|
|
// Sets the position of the zoom region on the screen
|
|
|
|
|
|
|
|
let width = Math.round(Math.min(viewPort.width, global.screen_width));
|
|
|
|
let height = Math.round(Math.min(viewPort.height, global.screen_height));
|
|
|
|
let x = Math.max(viewPort.x, 0);
|
|
|
|
let y = Math.max(viewPort.y, 0);
|
|
|
|
|
|
|
|
x = Math.round(Math.min(x, global.screen_width - width));
|
|
|
|
y = Math.round(Math.min(y, global.screen_height - height));
|
|
|
|
|
|
|
|
this._viewPortX = x;
|
|
|
|
this._viewPortY = y;
|
|
|
|
this._viewPortWidth = width;
|
|
|
|
this._viewPortHeight = height;
|
|
|
|
|
|
|
|
this._updateMagViewGeometry();
|
|
|
|
|
|
|
|
if (!fromROIUpdate)
|
|
|
|
this._changeROI({ redoCursorTracking: this._followingCursor }); // will update mouse
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2010-10-30 20:31:30 +00:00
|
|
|
if (this.isActive() && this._isMouseOverRegion())
|
|
|
|
this._magnifier.hideSystemCursor();
|
2021-06-25 09:09:06 +00:00
|
|
|
|
|
|
|
const uiGroupIsOccluded = this.isActive() && this._isFullScreen();
|
|
|
|
Main.uiGroup.set_opacity(uiGroupIsOccluded ? 0 : 255);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-10-30 20:31:30 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_changeROI(params) {
|
2010-10-30 20:31:30 +00:00
|
|
|
// Updates the area we are viewing; the magnification factors
|
|
|
|
// and center can be set explicitly, or we can recompute
|
|
|
|
// the position based on the mouse cursor position
|
|
|
|
|
2020-03-29 21:51:13 +00:00
|
|
|
params = Params.parse(params, {
|
|
|
|
xMagFactor: this._xMagFactor,
|
|
|
|
yMagFactor: this._yMagFactor,
|
|
|
|
xCenter: this._xCenter,
|
|
|
|
yCenter: this._yCenter,
|
|
|
|
redoCursorTracking: false,
|
|
|
|
animate: false,
|
|
|
|
});
|
2010-10-30 20:31:30 +00:00
|
|
|
|
|
|
|
if (params.xMagFactor <= 0)
|
|
|
|
params.xMagFactor = this._xMagFactor;
|
|
|
|
if (params.yMagFactor <= 0)
|
|
|
|
params.yMagFactor = this._yMagFactor;
|
|
|
|
|
|
|
|
this._xMagFactor = params.xMagFactor;
|
|
|
|
this._yMagFactor = params.yMagFactor;
|
|
|
|
|
|
|
|
if (params.redoCursorTracking &&
|
2011-10-19 20:47:04 +00:00
|
|
|
this._mouseTrackingMode != GDesktopEnums.MagnifierMouseTrackingMode.NONE) {
|
2010-10-30 20:31:30 +00:00
|
|
|
// This depends on this.xMagFactor/yMagFactor already being updated
|
|
|
|
[params.xCenter, params.yCenter] = this._centerFromMousePosition();
|
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
if (this._clampScrollingAtEdges) {
|
2010-10-30 20:31:30 +00:00
|
|
|
let roiWidth = this._viewPortWidth / this._xMagFactor;
|
|
|
|
let roiHeight = this._viewPortHeight / this._yMagFactor;
|
|
|
|
|
|
|
|
params.xCenter = Math.min(params.xCenter, global.screen_width - roiWidth / 2);
|
|
|
|
params.xCenter = Math.max(params.xCenter, roiWidth / 2);
|
|
|
|
params.yCenter = Math.min(params.yCenter, global.screen_height - roiHeight / 2);
|
|
|
|
params.yCenter = Math.max(params.yCenter, roiHeight / 2);
|
2010-05-11 19:00:07 +00:00
|
|
|
}
|
2010-10-30 20:31:30 +00:00
|
|
|
|
|
|
|
this._xCenter = params.xCenter;
|
|
|
|
this._yCenter = params.yCenter;
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
// If in lens mode, move the magnified view such that it is centered
|
|
|
|
// over the actual mouse. However, in full screen mode, the "lens" is
|
|
|
|
// the size of the screen -- pointless to move such a large lens around.
|
2019-08-20 00:51:42 +00:00
|
|
|
if (this._lensMode && !this._isFullScreen()) {
|
2020-03-29 21:51:13 +00:00
|
|
|
this._setViewPort({
|
|
|
|
x: this._xCenter - this._viewPortWidth / 2,
|
|
|
|
y: this._yCenter - this._viewPortHeight / 2,
|
|
|
|
width: this._viewPortWidth,
|
|
|
|
height: this._viewPortHeight,
|
|
|
|
}, true);
|
2019-08-20 00:51:42 +00:00
|
|
|
}
|
2010-10-30 20:31:30 +00:00
|
|
|
|
2020-02-06 10:00:44 +00:00
|
|
|
this._updateCloneGeometry(params.animate);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-10-30 20:31:30 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_isMouseOverRegion() {
|
2010-10-30 20:31:30 +00:00
|
|
|
// Return whether the system mouse sprite is over this ZoomRegion. If the
|
|
|
|
// mouse's position is not given, then it is fetched.
|
|
|
|
let mouseIsOver = false;
|
|
|
|
if (this.isActive()) {
|
2010-10-30 21:01:41 +00:00
|
|
|
let xMouse = this._magnifier.xMouse;
|
|
|
|
let yMouse = this._magnifier.yMouse;
|
|
|
|
|
2019-08-19 19:38:51 +00:00
|
|
|
mouseIsOver =
|
2010-10-30 20:31:30 +00:00
|
|
|
xMouse >= this._viewPortX && xMouse < (this._viewPortX + this._viewPortWidth) &&
|
2019-08-19 19:38:51 +00:00
|
|
|
yMouse >= this._viewPortY && yMouse < (this._viewPortY + this._viewPortHeight);
|
2010-10-30 20:31:30 +00:00
|
|
|
}
|
|
|
|
return mouseIsOver;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-10-30 20:31:30 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_isFullScreen() {
|
2010-10-30 20:31:30 +00:00
|
|
|
// Does the magnified view occupy the whole screen? Note that this
|
|
|
|
// doesn't necessarily imply
|
2011-10-19 20:47:04 +00:00
|
|
|
// this._screenPosition = GDesktopEnums.MagnifierScreenPosition.FULL_SCREEN;
|
2010-10-30 20:31:30 +00:00
|
|
|
|
|
|
|
if (this._viewPortX != 0 || this._viewPortY != 0)
|
|
|
|
return false;
|
|
|
|
if (this._viewPortWidth != global.screen_width ||
|
|
|
|
this._viewPortHeight != global.screen_height)
|
|
|
|
return false;
|
|
|
|
return true;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_centerFromMousePosition() {
|
2010-10-30 20:31:30 +00:00
|
|
|
// Determines where the center should be given the current cursor
|
|
|
|
// position and mouse tracking mode
|
|
|
|
|
2010-10-30 21:01:41 +00:00
|
|
|
let xMouse = this._magnifier.xMouse;
|
|
|
|
let yMouse = this._magnifier.yMouse;
|
2010-10-30 20:31:30 +00:00
|
|
|
|
2019-08-20 00:51:42 +00:00
|
|
|
if (this._mouseTrackingMode == GDesktopEnums.MagnifierMouseTrackingMode.PROPORTIONAL)
|
2013-09-04 17:53:36 +00:00
|
|
|
return this._centerFromPointProportional(xMouse, yMouse);
|
2019-08-20 00:51:42 +00:00
|
|
|
else if (this._mouseTrackingMode == GDesktopEnums.MagnifierMouseTrackingMode.PUSH)
|
2013-09-04 17:53:36 +00:00
|
|
|
return this._centerFromPointPush(xMouse, yMouse);
|
2019-08-20 00:51:42 +00:00
|
|
|
else if (this._mouseTrackingMode == GDesktopEnums.MagnifierMouseTrackingMode.CENTERED)
|
2013-09-04 17:53:36 +00:00
|
|
|
return this._centerFromPointCentered(xMouse, yMouse);
|
2010-10-30 20:31:30 +00:00
|
|
|
|
|
|
|
return null; // Should never be hit
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_centerFromCaretPosition() {
|
2013-09-04 17:53:36 +00:00
|
|
|
let xCaret = this._xCaret;
|
|
|
|
let yCaret = this._yCaret;
|
|
|
|
|
|
|
|
if (this._caretTrackingMode == GDesktopEnums.MagnifierCaretTrackingMode.PROPORTIONAL)
|
|
|
|
[xCaret, yCaret] = this._centerFromPointProportional(xCaret, yCaret);
|
|
|
|
else if (this._caretTrackingMode == GDesktopEnums.MagnifierCaretTrackingMode.PUSH)
|
|
|
|
[xCaret, yCaret] = this._centerFromPointPush(xCaret, yCaret);
|
|
|
|
else if (this._caretTrackingMode == GDesktopEnums.MagnifierCaretTrackingMode.CENTERED)
|
|
|
|
[xCaret, yCaret] = this._centerFromPointCentered(xCaret, yCaret);
|
|
|
|
|
2015-07-24 16:47:34 +00:00
|
|
|
this._scrollContentsToDelayed(xCaret, yCaret);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-09-04 17:53:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_centerFromFocusPosition() {
|
2013-09-04 17:53:36 +00:00
|
|
|
let xFocus = this._xFocus;
|
|
|
|
let yFocus = this._yFocus;
|
|
|
|
|
|
|
|
if (this._focusTrackingMode == GDesktopEnums.MagnifierFocusTrackingMode.PROPORTIONAL)
|
|
|
|
[xFocus, yFocus] = this._centerFromPointProportional(xFocus, yFocus);
|
|
|
|
else if (this._focusTrackingMode == GDesktopEnums.MagnifierFocusTrackingMode.PUSH)
|
|
|
|
[xFocus, yFocus] = this._centerFromPointPush(xFocus, yFocus);
|
|
|
|
else if (this._focusTrackingMode == GDesktopEnums.MagnifierFocusTrackingMode.CENTERED)
|
|
|
|
[xFocus, yFocus] = this._centerFromPointCentered(xFocus, yFocus);
|
|
|
|
|
2015-07-24 16:47:34 +00:00
|
|
|
this._scrollContentsToDelayed(xFocus, yFocus);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-09-04 17:53:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_centerFromPointPush(xPoint, yPoint) {
|
2010-05-11 19:00:07 +00:00
|
|
|
let [xRoi, yRoi, widthRoi, heightRoi] = this.getROI();
|
2010-10-30 20:31:30 +00:00
|
|
|
let [cursorWidth, cursorHeight] = this._mouseSourceActor.get_size();
|
2010-05-11 19:00:07 +00:00
|
|
|
let xPos = xRoi + widthRoi / 2;
|
|
|
|
let yPos = yRoi + heightRoi / 2;
|
|
|
|
let xRoiRight = xRoi + widthRoi - cursorWidth;
|
|
|
|
let yRoiBottom = yRoi + heightRoi - cursorHeight;
|
|
|
|
|
2013-09-04 17:53:36 +00:00
|
|
|
if (xPoint < xRoi)
|
2019-08-19 19:38:51 +00:00
|
|
|
xPos -= xRoi - xPoint;
|
2013-09-04 17:53:36 +00:00
|
|
|
else if (xPoint > xRoiRight)
|
2019-08-19 19:38:51 +00:00
|
|
|
xPos += xPoint - xRoiRight;
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2013-09-04 17:53:36 +00:00
|
|
|
if (yPoint < yRoi)
|
2019-08-19 19:38:51 +00:00
|
|
|
yPos -= yRoi - yPoint;
|
2013-09-04 17:53:36 +00:00
|
|
|
else if (yPoint > yRoiBottom)
|
2019-08-19 19:38:51 +00:00
|
|
|
yPos += yPoint - yRoiBottom;
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2010-10-30 20:31:30 +00:00
|
|
|
return [xPos, yPos];
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_centerFromPointProportional(xPoint, yPoint) {
|
2019-01-31 14:08:00 +00:00
|
|
|
let [xRoi_, yRoi_, widthRoi, heightRoi] = this.getROI();
|
2010-05-11 19:00:07 +00:00
|
|
|
let halfScreenWidth = global.screen_width / 2;
|
|
|
|
let halfScreenHeight = global.screen_height / 2;
|
2010-11-14 22:21:43 +00:00
|
|
|
// We want to pad with a constant distance after zooming, so divide
|
|
|
|
// by the magnification factor.
|
|
|
|
let unscaledPadding = Math.min(this._viewPortWidth, this._viewPortHeight) / 5;
|
|
|
|
let xPadding = unscaledPadding / this._xMagFactor;
|
|
|
|
let yPadding = unscaledPadding / this._yMagFactor;
|
2013-09-04 17:53:36 +00:00
|
|
|
let xProportion = (xPoint - halfScreenWidth) / halfScreenWidth; // -1 ... 1
|
|
|
|
let yProportion = (yPoint - halfScreenHeight) / halfScreenHeight; // -1 ... 1
|
|
|
|
let xPos = xPoint - xProportion * (widthRoi / 2 - xPadding);
|
2019-01-29 01:27:05 +00:00
|
|
|
let yPos = yPoint - yProportion * (heightRoi / 2 - yPadding);
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2010-10-30 20:31:30 +00:00
|
|
|
return [xPos, yPos];
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_centerFromPointCentered(xPoint, yPoint) {
|
2013-09-04 17:53:36 +00:00
|
|
|
return [xPoint, yPoint];
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_screenToViewPort(screenX, screenY) {
|
2010-10-30 20:31:30 +00:00
|
|
|
// Converts coordinates relative to the (unmagnified) screen to coordinates
|
|
|
|
// relative to the origin of this._magView
|
2020-03-27 13:18:34 +00:00
|
|
|
return [
|
|
|
|
this._viewPortWidth / 2 + (screenX - this._xCenter) * this._xMagFactor,
|
|
|
|
this._viewPortHeight / 2 + (screenY - this._yCenter) * this._yMagFactor,
|
|
|
|
];
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-10-30 20:31:30 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updateMagViewGeometry() {
|
2010-10-30 20:31:30 +00:00
|
|
|
if (!this.isActive())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (this._isFullScreen())
|
|
|
|
this._magView.add_style_class_name('full-screen');
|
|
|
|
else
|
|
|
|
this._magView.remove_style_class_name('full-screen');
|
|
|
|
|
|
|
|
this._magView.set_size(this._viewPortWidth, this._viewPortHeight);
|
|
|
|
this._magView.set_position(this._viewPortX, this._viewPortY);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2020-02-06 10:00:44 +00:00
|
|
|
_updateCloneGeometry(animate = false) {
|
2010-10-30 20:31:30 +00:00
|
|
|
if (!this.isActive())
|
|
|
|
return;
|
|
|
|
|
|
|
|
let [x, y] = this._screenToViewPort(0, 0);
|
2020-02-06 10:00:44 +00:00
|
|
|
this._uiGroupClone.ease({
|
|
|
|
x: Math.round(x),
|
|
|
|
y: Math.round(y),
|
|
|
|
scale_x: this._xMagFactor,
|
|
|
|
scale_y: this._yMagFactor,
|
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
|
|
|
|
duration: animate ? 100 : 0,
|
|
|
|
});
|
2010-10-30 20:31:30 +00:00
|
|
|
|
2020-02-06 10:00:44 +00:00
|
|
|
let [mouseX, mouseY] = this._getMousePosition();
|
|
|
|
this._mouseActor.ease({
|
|
|
|
x: mouseX,
|
|
|
|
y: mouseY,
|
|
|
|
scale_x: this._xMagFactor,
|
|
|
|
scale_y: this._yMagFactor,
|
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
|
|
|
|
duration: animate ? 100 : 0,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (this._crossHairsActor) {
|
|
|
|
let [crossX, crossY] = this._getCrossHairsPosition();
|
|
|
|
this._crossHairsActor.ease({
|
|
|
|
x: crossX,
|
|
|
|
y: crossY,
|
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
|
|
|
|
duration: animate ? 100 : 0,
|
|
|
|
});
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-10-30 20:31:30 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updateMousePosition() {
|
2020-02-06 10:00:44 +00:00
|
|
|
let [xMagMouse, yMagMouse] = this._getMousePosition();
|
2010-10-30 20:31:30 +00:00
|
|
|
this._mouseActor.set_position(xMagMouse, yMagMouse);
|
|
|
|
|
|
|
|
if (this._crossHairsActor) {
|
2020-02-06 10:00:44 +00:00
|
|
|
let [crossX, crossY] = this._getCrossHairsPosition();
|
|
|
|
this._crossHairsActor.set_position(crossX, crossY);
|
2010-05-11 19:00:07 +00:00
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-01-26 04:34:45 +00:00
|
|
|
|
2020-02-06 10:00:44 +00:00
|
|
|
_getMousePosition() {
|
|
|
|
let [xMagMouse, yMagMouse] = this._screenToViewPort(
|
|
|
|
this._magnifier.xMouse, this._magnifier.yMouse);
|
|
|
|
return [Math.round(xMagMouse), Math.round(yMagMouse)];
|
|
|
|
}
|
|
|
|
|
|
|
|
_getCrossHairsPosition() {
|
|
|
|
let [xMagMouse, yMagMouse] = this._getMousePosition();
|
|
|
|
let [groupWidth, groupHeight] = this._crossHairsActor.get_size();
|
|
|
|
|
|
|
|
return [xMagMouse - groupWidth / 2, yMagMouse - groupHeight / 2];
|
|
|
|
}
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_monitorsChanged() {
|
2012-01-26 04:34:45 +00:00
|
|
|
this._background.set_size(global.screen_width, global.screen_height);
|
2019-03-27 21:16:26 +00:00
|
|
|
this._updateScreenPosition();
|
2010-05-11 19:00:07 +00:00
|
|
|
}
|
2023-07-30 12:56:59 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2019-07-16 09:24:13 +00:00
|
|
|
var Crosshairs = GObject.registerClass(
|
|
|
|
class Crosshairs extends Clutter.Actor {
|
|
|
|
_init() {
|
2010-05-11 19:00:07 +00:00
|
|
|
// Set the group containing the crosshairs to three times the desktop
|
|
|
|
// size in case the crosshairs need to appear to be infinite in
|
|
|
|
// length (i.e., extend beyond the edges of the view they appear in).
|
|
|
|
let groupWidth = global.screen_width * 3;
|
|
|
|
let groupHeight = global.screen_height * 3;
|
2010-06-19 13:43:39 +00:00
|
|
|
|
2019-07-16 09:24:13 +00:00
|
|
|
super._init({
|
2010-05-11 19:00:07 +00:00
|
|
|
clip_to_allocation: false,
|
|
|
|
width: groupWidth,
|
2019-08-20 21:43:54 +00:00
|
|
|
height: groupHeight,
|
2010-05-11 19:00:07 +00:00
|
|
|
});
|
2012-08-31 00:35:17 +00:00
|
|
|
this._horizLeftHair = new Clutter.Actor();
|
|
|
|
this._horizRightHair = new Clutter.Actor();
|
|
|
|
this._vertTopHair = new Clutter.Actor();
|
|
|
|
this._vertBottomHair = new Clutter.Actor();
|
2019-07-16 09:24:13 +00:00
|
|
|
this.add_actor(this._horizLeftHair);
|
|
|
|
this.add_actor(this._horizRightHair);
|
|
|
|
this.add_actor(this._vertTopHair);
|
|
|
|
this.add_actor(this._vertBottomHair);
|
2010-05-11 19:00:07 +00:00
|
|
|
this._clipSize = [0, 0];
|
|
|
|
this._clones = [];
|
|
|
|
this.reCenter();
|
2021-06-28 12:19:15 +00:00
|
|
|
this._monitorsChangedId = 0;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-01-26 04:34:45 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_monitorsChanged() {
|
2019-07-16 09:24:13 +00:00
|
|
|
this.set_size(global.screen_width * 3, global.screen_height * 3);
|
2012-01-26 04:34:45 +00:00
|
|
|
this.reCenter();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
2021-06-28 12:19:15 +00:00
|
|
|
setEnabled(enabled) {
|
|
|
|
if (enabled && this._monitorsChangedId === 0) {
|
|
|
|
this._monitorsChangedId = Main.layoutManager.connect(
|
|
|
|
'monitors-changed', this._monitorsChanged.bind(this));
|
|
|
|
} else if (!enabled && this._monitorsChangedId !== 0) {
|
|
|
|
Main.layoutManager.disconnect(this._monitorsChangedId);
|
|
|
|
this._monitorsChangedId = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-29 19:36:54 +00:00
|
|
|
/**
|
2010-05-11 19:00:07 +00:00
|
|
|
* addToZoomRegion
|
|
|
|
* Either add the crosshairs actor to the given ZoomRegion, or, if it is
|
|
|
|
* already part of some other ZoomRegion, create a clone of the crosshairs
|
|
|
|
* actor, and add the clone instead. Returns either the original or the
|
|
|
|
* clone.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {ZoomRegion} zoomRegion The container to add the crosshairs
|
2019-10-17 16:41:52 +00:00
|
|
|
* group to.
|
2023-07-30 12:56:59 +00:00
|
|
|
* @param {Clutter.Actor} magnifiedMouse The mouse actor for the
|
2019-10-17 16:41:52 +00:00
|
|
|
* zoom region -- used to position the crosshairs and properly
|
|
|
|
* layer them below the mouse.
|
|
|
|
* @returns {Clutter.Actor} The crosshairs actor, or its clone.
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
addToZoomRegion(zoomRegion, magnifiedMouse) {
|
2010-05-11 19:00:07 +00:00
|
|
|
let crosshairsActor = null;
|
|
|
|
if (zoomRegion && magnifiedMouse) {
|
|
|
|
let container = magnifiedMouse.get_parent();
|
|
|
|
if (container) {
|
2019-07-16 09:24:13 +00:00
|
|
|
crosshairsActor = this;
|
|
|
|
if (this.get_parent() != null) {
|
|
|
|
crosshairsActor = new Clutter.Clone({ source: this });
|
2010-05-11 19:00:07 +00:00
|
|
|
this._clones.push(crosshairsActor);
|
2019-07-16 09:24:13 +00:00
|
|
|
|
|
|
|
// Clones don't share visibility.
|
|
|
|
this.bind_property('visible', crosshairsActor, 'visible',
|
|
|
|
GObject.BindingFlags.SYNC_CREATE);
|
2010-05-11 19:00:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
container.add_actor(crosshairsActor);
|
2019-11-05 19:17:19 +00:00
|
|
|
container.set_child_above_sibling(magnifiedMouse, crosshairsActor);
|
2010-05-11 19:00:07 +00:00
|
|
|
let [xMouse, yMouse] = magnifiedMouse.get_position();
|
|
|
|
let [crosshairsWidth, crosshairsHeight] = crosshairsActor.get_size();
|
2019-01-29 01:27:05 +00:00
|
|
|
crosshairsActor.set_position(xMouse - crosshairsWidth / 2, yMouse - crosshairsHeight / 2);
|
2010-05-11 19:00:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return crosshairsActor;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* removeFromParent:
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
2010-10-30 20:31:30 +00:00
|
|
|
* Remove the crosshairs actor from its parent container, or destroy the
|
|
|
|
* child actor if it was just a clone of the crosshairs actor.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {Clutter.Actor} childActor the actor returned from
|
|
|
|
* addToZoomRegion
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
removeFromParent(childActor) {
|
2019-07-16 09:24:13 +00:00
|
|
|
if (childActor == this)
|
2010-10-30 20:31:30 +00:00
|
|
|
childActor.get_parent().remove_actor(childActor);
|
|
|
|
else
|
|
|
|
childActor.destroy();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setColor:
|
|
|
|
* Set the color of the crosshairs.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {Clutter.Color} clutterColor The color
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
setColor(clutterColor) {
|
2012-08-31 00:35:17 +00:00
|
|
|
this._horizLeftHair.background_color = clutterColor;
|
|
|
|
this._horizRightHair.background_color = clutterColor;
|
|
|
|
this._vertTopHair.background_color = clutterColor;
|
|
|
|
this._vertBottomHair.background_color = clutterColor;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* getColor:
|
|
|
|
* Get the color of the crosshairs.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
2019-10-17 16:41:52 +00:00
|
|
|
* @returns {ClutterColor} the crosshairs color
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
getColor() {
|
2012-08-31 00:38:21 +00:00
|
|
|
return this._horizLeftHair.get_color();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setThickness:
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
2010-05-11 19:00:07 +00:00
|
|
|
* Set the width of the vertical and horizontal lines of the crosshairs.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {number} thickness the new thickness value
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
setThickness(thickness) {
|
2010-05-11 19:00:07 +00:00
|
|
|
this._horizLeftHair.set_height(thickness);
|
|
|
|
this._horizRightHair.set_height(thickness);
|
|
|
|
this._vertTopHair.set_width(thickness);
|
|
|
|
this._vertBottomHair.set_width(thickness);
|
|
|
|
this.reCenter();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* getThickness:
|
|
|
|
* Get the width of the vertical and horizontal lines of the crosshairs.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
2019-10-17 16:41:52 +00:00
|
|
|
* @returns {number} The thickness of the crosshairs.
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
getThickness() {
|
2010-05-11 19:00:07 +00:00
|
|
|
return this._horizLeftHair.get_height();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setOpacity:
|
|
|
|
* Set how opaque the crosshairs are.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {number} opacity Value between 0 (fully transparent)
|
2019-10-17 16:41:52 +00:00
|
|
|
* and 255 (full opaque).
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
setOpacity(opacity) {
|
2010-05-11 19:00:07 +00:00
|
|
|
// set_opacity() throws an exception for values outside the range
|
|
|
|
// [0, 255].
|
|
|
|
if (opacity < 0)
|
|
|
|
opacity = 0;
|
|
|
|
else if (opacity > 255)
|
|
|
|
opacity = 255;
|
|
|
|
|
|
|
|
this._horizLeftHair.set_opacity(opacity);
|
|
|
|
this._horizRightHair.set_opacity(opacity);
|
|
|
|
this._vertTopHair.set_opacity(opacity);
|
|
|
|
this._vertBottomHair.set_opacity(opacity);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setLength:
|
|
|
|
* Set the length of the vertical and horizontal lines in the crosshairs.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {number} length The length of the crosshairs.
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
setLength(length) {
|
2010-05-11 19:00:07 +00:00
|
|
|
this._horizLeftHair.set_width(length);
|
|
|
|
this._horizRightHair.set_width(length);
|
|
|
|
this._vertTopHair.set_height(length);
|
|
|
|
this._vertBottomHair.set_height(length);
|
|
|
|
this.reCenter();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* getLength:
|
|
|
|
* Get the length of the vertical and horizontal lines in the crosshairs.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
2019-10-17 16:41:52 +00:00
|
|
|
* @returns {number} The length of the crosshairs.
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
getLength() {
|
2010-05-11 19:00:07 +00:00
|
|
|
return this._horizLeftHair.get_width();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setClip:
|
|
|
|
* Set the width and height of the rectangle that clips the crosshairs at
|
|
|
|
* their intersection
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {[number, number]} size Array of [width, height] defining the size
|
2019-10-17 16:41:52 +00:00
|
|
|
* of the clip rectangle.
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
setClip(size) {
|
2010-05-11 19:00:07 +00:00
|
|
|
if (size) {
|
|
|
|
// Take a chunk out of the crosshairs where it intersects the
|
|
|
|
// mouse.
|
|
|
|
this._clipSize = size;
|
|
|
|
this.reCenter();
|
2019-01-29 21:02:57 +00:00
|
|
|
} else {
|
2010-05-11 19:00:07 +00:00
|
|
|
// Restore the missing chunk.
|
|
|
|
this._clipSize = [0, 0];
|
|
|
|
this.reCenter();
|
|
|
|
}
|
2019-01-29 19:36:54 +00:00
|
|
|
}
|
2010-05-11 19:00:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* reCenter:
|
|
|
|
* Reposition the horizontal and vertical hairs such that they cross at
|
|
|
|
* the center of crosshairs group. If called with the dimensions of
|
|
|
|
* the clip rectangle, these are used to update the size of the clip.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {[number, number]} [clipSize] If present, the clip's [width, height].
|
2010-05-11 19:00:07 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
reCenter(clipSize) {
|
2019-07-16 09:24:13 +00:00
|
|
|
let [groupWidth, groupHeight] = this.get_size();
|
2010-05-11 19:00:07 +00:00
|
|
|
let leftLength = this._horizLeftHair.get_width();
|
|
|
|
let topLength = this._vertTopHair.get_height();
|
|
|
|
let thickness = this._horizLeftHair.get_height();
|
|
|
|
|
|
|
|
// Deal with clip rectangle.
|
|
|
|
if (clipSize)
|
|
|
|
this._clipSize = clipSize;
|
|
|
|
let clipWidth = this._clipSize[0];
|
|
|
|
let clipHeight = this._clipSize[1];
|
|
|
|
|
2020-02-06 09:38:50 +00:00
|
|
|
let left = groupWidth / 2 - clipWidth / 2 - leftLength - thickness / 2;
|
|
|
|
let right = groupWidth / 2 + clipWidth / 2 + thickness / 2;
|
|
|
|
let top = groupHeight / 2 - clipHeight / 2 - topLength - thickness / 2;
|
|
|
|
let bottom = groupHeight / 2 + clipHeight / 2 + thickness / 2;
|
2010-05-11 19:00:07 +00:00
|
|
|
this._horizLeftHair.set_position(left, (groupHeight - thickness) / 2);
|
|
|
|
this._horizRightHair.set_position(right, (groupHeight - thickness) / 2);
|
|
|
|
this._vertTopHair.set_position((groupWidth - thickness) / 2, top);
|
|
|
|
this._vertBottomHair.set_position((groupWidth - thickness) / 2, bottom);
|
|
|
|
}
|
2019-07-16 09:24:13 +00:00
|
|
|
});
|
2012-03-12 19:52:41 +00:00
|
|
|
|
2023-07-30 12:56:59 +00:00
|
|
|
class MagShaderEffects {
|
2017-10-31 01:19:44 +00:00
|
|
|
constructor(uiGroupClone) {
|
2012-04-04 15:10:31 +00:00
|
|
|
this._inverse = new Shell.InvertLightnessEffect();
|
2012-03-12 19:52:41 +00:00
|
|
|
this._brightnessContrast = new Clutter.BrightnessContrastEffect();
|
2012-07-24 16:59:47 +00:00
|
|
|
this._colorDesaturation = new Clutter.DesaturateEffect();
|
2012-04-04 15:10:31 +00:00
|
|
|
this._inverse.set_enabled(false);
|
2012-03-12 19:52:41 +00:00
|
|
|
this._brightnessContrast.set_enabled(false);
|
2021-11-08 04:19:32 +00:00
|
|
|
this._colorDesaturation.set_enabled(false);
|
2012-03-12 19:52:41 +00:00
|
|
|
|
|
|
|
this._magView = uiGroupClone;
|
2012-04-04 15:10:31 +00:00
|
|
|
this._magView.add_effect(this._inverse);
|
2012-03-12 19:52:41 +00:00
|
|
|
this._magView.add_effect(this._brightnessContrast);
|
2012-07-24 16:59:47 +00:00
|
|
|
this._magView.add_effect(this._colorDesaturation);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-03-12 19:52:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* destroyEffects:
|
|
|
|
* Remove contrast and brightness effects from the magnified view, and
|
|
|
|
* lose the reference to the actor they were applied to. Don't use this
|
|
|
|
* object after calling this.
|
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
destroyEffects() {
|
2012-03-12 19:52:41 +00:00
|
|
|
this._magView.clear_effects();
|
2012-07-24 16:59:47 +00:00
|
|
|
this._colorDesaturation = null;
|
2012-03-12 19:52:41 +00:00
|
|
|
this._brightnessContrast = null;
|
2012-04-04 15:10:31 +00:00
|
|
|
this._inverse = null;
|
2012-03-12 19:52:41 +00:00
|
|
|
this._magView = null;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-03-12 19:52:41 +00:00
|
|
|
|
2012-04-04 15:10:31 +00:00
|
|
|
/**
|
|
|
|
* setInvertLightness:
|
|
|
|
* Enable/disable invert lightness effect.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {boolean} invertFlag Enabled flag.
|
2012-04-04 15:10:31 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
setInvertLightness(invertFlag) {
|
2012-04-04 15:10:31 +00:00
|
|
|
this._inverse.set_enabled(invertFlag);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-04-04 15:10:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setColorSaturation(factor) {
|
2012-07-24 16:59:47 +00:00
|
|
|
this._colorDesaturation.set_factor(1.0 - factor);
|
2021-11-08 04:19:32 +00:00
|
|
|
this._colorDesaturation.set_enabled(factor !== 1.0);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-06-01 12:36:47 +00:00
|
|
|
|
2012-03-12 19:52:41 +00:00
|
|
|
/**
|
|
|
|
* setBrightness:
|
|
|
|
* Set the brightness of the magnified view.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {object} brightness Object containing the contrast for the
|
2019-10-17 16:41:52 +00:00
|
|
|
* red, green, and blue channels. Values of 0.0 represent "standard"
|
|
|
|
* brightness (no change), whereas values less or greater than
|
|
|
|
* 0.0 indicate decreased or incresaed brightness, respectively.
|
|
|
|
*
|
|
|
|
* {number} brightness.r - the red component
|
|
|
|
* {number} brightness.g - the green component
|
|
|
|
* {number} brightness.b - the blue component
|
2012-03-12 19:52:41 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
setBrightness(brightness) {
|
2012-03-12 19:52:41 +00:00
|
|
|
let bRed = brightness.r;
|
|
|
|
let bGreen = brightness.g;
|
|
|
|
let bBlue = brightness.b;
|
|
|
|
this._brightnessContrast.set_brightness_full(bRed, bGreen, bBlue);
|
|
|
|
|
|
|
|
// Enable the effect if the brightness OR contrast change are such that
|
|
|
|
// it modifies the brightness and/or contrast.
|
|
|
|
let [cRed, cGreen, cBlue] = this._brightnessContrast.get_contrast();
|
|
|
|
this._brightnessContrast.set_enabled(
|
2020-04-03 23:52:29 +00:00
|
|
|
bRed !== NO_CHANGE || bGreen !== NO_CHANGE || bBlue !== NO_CHANGE ||
|
|
|
|
cRed !== NO_CHANGE || cGreen !== NO_CHANGE || cBlue !== NO_CHANGE);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-03-12 19:52:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the contrast of the magnified view.
|
2023-07-30 12:56:59 +00:00
|
|
|
*
|
|
|
|
* @param {object} contrast Object containing the contrast for the
|
2019-10-17 16:41:52 +00:00
|
|
|
* red, green, and blue channels. Values of 0.0 represent "standard"
|
|
|
|
* contrast (no change), whereas values less or greater than
|
|
|
|
* 0.0 indicate decreased or incresaed contrast, respectively.
|
|
|
|
*
|
|
|
|
* {number} contrast.r - the red component
|
|
|
|
* {number} contrast.g - the green component
|
|
|
|
* {number} contrast.b - the blue component
|
2012-03-12 19:52:41 +00:00
|
|
|
*/
|
2017-10-31 00:03:21 +00:00
|
|
|
setContrast(contrast) {
|
2012-03-12 19:52:41 +00:00
|
|
|
let cRed = contrast.r;
|
|
|
|
let cGreen = contrast.g;
|
|
|
|
let cBlue = contrast.b;
|
|
|
|
|
|
|
|
this._brightnessContrast.set_contrast_full(cRed, cGreen, cBlue);
|
|
|
|
|
|
|
|
// Enable the effect if the contrast OR brightness change are such that
|
|
|
|
// it modifies the brightness and/or contrast.
|
|
|
|
// should be able to use Clutter.color_equal(), but that complains of
|
|
|
|
// a null first argument.
|
|
|
|
let [bRed, bGreen, bBlue] = this._brightnessContrast.get_brightness();
|
|
|
|
this._brightnessContrast.set_enabled(
|
2020-04-03 23:52:29 +00:00
|
|
|
cRed !== NO_CHANGE || cGreen !== NO_CHANGE || cBlue !== NO_CHANGE ||
|
|
|
|
bRed !== NO_CHANGE || bGreen !== NO_CHANGE || bBlue !== NO_CHANGE);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2023-07-30 12:56:59 +00:00
|
|
|
}
|