2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2010-05-11 15:00:07 -04:00
|
|
|
|
2011-08-16 08:26:49 -04:00
|
|
|
const Gio = imports.gi.Gio;
|
2010-05-11 15:00:07 -04:00
|
|
|
const Main = imports.ui.main;
|
|
|
|
|
2018-09-05 20:55:20 -04:00
|
|
|
const { loadInterfaceXML } = imports.misc.fileUtils;
|
|
|
|
|
2010-05-11 15:00:07 -04:00
|
|
|
const MAG_SERVICE_PATH = '/org/gnome/Magnifier';
|
|
|
|
const ZOOM_SERVICE_PATH = '/org/gnome/Magnifier/ZoomRegion';
|
|
|
|
|
|
|
|
// Subset of gnome-mag's Magnifier dbus interface -- to be expanded. See:
|
|
|
|
// http://git.gnome.org/browse/gnome-mag/tree/xml/...Magnifier.xml
|
2018-09-05 20:55:20 -04:00
|
|
|
const MagnifierIface = loadInterfaceXML('org.gnome.Magnifier');
|
2010-05-11 15:00:07 -04:00
|
|
|
|
|
|
|
// Subset of gnome-mag's ZoomRegion dbus interface -- to be expanded. See:
|
|
|
|
// http://git.gnome.org/browse/gnome-mag/tree/xml/...ZoomRegion.xml
|
2018-09-05 20:55:20 -04:00
|
|
|
const ZoomRegionIface = loadInterfaceXML('org.gnome.Magnifier.ZoomRegion');
|
2010-05-11 15:00:07 -04:00
|
|
|
|
|
|
|
// For making unique ZoomRegion DBus proxy object paths of the form:
|
2010-05-13 15:46:04 -04:00
|
|
|
// '/org/gnome/Magnifier/ZoomRegion/zoomer0',
|
|
|
|
// '/org/gnome/Magnifier/ZoomRegion/zoomer1', etc.
|
2010-05-11 15:00:07 -04:00
|
|
|
let _zoomRegionInstanceCount = 0;
|
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var ShellMagnifier = class ShellMagnifier {
|
|
|
|
constructor() {
|
2010-05-11 15:00:07 -04:00
|
|
|
this._zoomers = {};
|
2011-08-16 08:26:49 -04:00
|
|
|
|
|
|
|
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(MagnifierIface, this);
|
|
|
|
this._dbusImpl.export(Gio.DBus.session, MAG_SERVICE_PATH);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-11 15:00:07 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setActive:
|
|
|
|
* @activate: Boolean to activate or de-activate the magnifier.
|
|
|
|
*/
|
2017-10-30 20:03:21 -04:00
|
|
|
setActive(activate) {
|
2010-05-11 15:00:07 -04:00
|
|
|
Main.magnifier.setActive(activate);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-11 15:00:07 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* isActive:
|
|
|
|
* @return Whether the magnifier is active (boolean).
|
|
|
|
*/
|
2017-10-30 20:03:21 -04:00
|
|
|
isActive() {
|
2010-05-11 15:00:07 -04:00
|
|
|
return Main.magnifier.isActive();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-11 15:00:07 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* showCursor:
|
|
|
|
* Show the system mouse pointer.
|
|
|
|
*/
|
2017-10-30 20:03:21 -04:00
|
|
|
showCursor() {
|
2010-05-11 15:00:07 -04:00
|
|
|
Main.magnifier.showSystemCursor();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-11 15:00:07 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* hideCursor:
|
|
|
|
* Hide the system mouse pointer.
|
|
|
|
*/
|
2017-10-30 20:03:21 -04:00
|
|
|
hideCursor() {
|
2010-05-11 15:00:07 -04:00
|
|
|
Main.magnifier.hideSystemCursor();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-11 15:00:07 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* createZoomRegion:
|
|
|
|
* Create a new ZoomRegion and return its object path.
|
|
|
|
* @xMagFactor: 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.
|
|
|
|
* @yMagFactor: The power to set the vertical magnification of the
|
|
|
|
* ZoomRegion.
|
|
|
|
* @roi Array of integers defining the region of the
|
|
|
|
* screen/desktop to magnify. The array has the form
|
2010-08-06 13:07:49 -04:00
|
|
|
* [left, top, right, bottom].
|
|
|
|
* @viewPort Array of integers, [left, top, right, bottom] that defines
|
2010-05-11 15:00:07 -04:00
|
|
|
* the position of the ZoomRegion on screen.
|
2010-10-30 16:31:30 -04:00
|
|
|
*
|
|
|
|
* FIXME: The arguments here are redundant, since the width and height of
|
|
|
|
* the ROI are determined by the viewport and magnification factors.
|
|
|
|
* We ignore the passed in width and height.
|
|
|
|
*
|
2010-05-11 15:00:07 -04:00
|
|
|
* @return The newly created ZoomRegion.
|
|
|
|
*/
|
2017-10-30 20:03:21 -04:00
|
|
|
createZoomRegion(xMagFactor, yMagFactor, roi, viewPort) {
|
2010-08-06 13:07:49 -04:00
|
|
|
let ROI = { x: roi[0], y: roi[1], width: roi[2] - roi[0], height: roi[3] - roi[1] };
|
|
|
|
let viewBox = { x: viewPort[0], y: viewPort[1], width: viewPort[2] - viewPort[0], height: viewPort[3] - viewPort[1] };
|
2010-05-11 15:00:07 -04:00
|
|
|
let realZoomRegion = Main.magnifier.createZoomRegion(xMagFactor, yMagFactor, ROI, viewBox);
|
2010-05-13 15:46:04 -04:00
|
|
|
let objectPath = ZOOM_SERVICE_PATH + '/zoomer' + _zoomRegionInstanceCount;
|
2010-05-11 15:00:07 -04:00
|
|
|
_zoomRegionInstanceCount++;
|
|
|
|
|
|
|
|
let zoomRegionProxy = new ShellMagnifierZoomRegion(objectPath, realZoomRegion);
|
|
|
|
let proxyAndZoomRegion = {};
|
|
|
|
proxyAndZoomRegion.proxy = zoomRegionProxy;
|
|
|
|
proxyAndZoomRegion.zoomRegion = realZoomRegion;
|
|
|
|
this._zoomers[objectPath] = proxyAndZoomRegion;
|
|
|
|
return objectPath;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-11 15:00:07 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* addZoomRegion:
|
|
|
|
* Append the given ZoomRegion to the magnifier's list of ZoomRegions.
|
|
|
|
* @zoomerObjectPath: The object path for the zoom region proxy.
|
|
|
|
*/
|
2017-10-30 20:03:21 -04:00
|
|
|
addZoomRegion(zoomerObjectPath) {
|
2010-05-11 15:00:07 -04:00
|
|
|
let proxyAndZoomRegion = this._zoomers[zoomerObjectPath];
|
|
|
|
if (proxyAndZoomRegion && proxyAndZoomRegion.zoomRegion) {
|
|
|
|
Main.magnifier.addZoomRegion(proxyAndZoomRegion.zoomRegion);
|
|
|
|
return true;
|
2019-01-29 16:02:57 -05:00
|
|
|
} else {
|
2010-05-11 15:00:07 -04:00
|
|
|
return false;
|
2019-01-29 16:02:57 -05:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-11 15:00:07 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* getZoomRegions:
|
|
|
|
* Return a list of ZoomRegion object paths for this Magnifier.
|
|
|
|
* @return: The Magnifier's zoom region list as an array of DBus object
|
|
|
|
* paths.
|
|
|
|
*/
|
2017-10-30 20:03:21 -04:00
|
|
|
getZoomRegions() {
|
2010-05-11 15:00:07 -04:00
|
|
|
// There may be more ZoomRegions in the magnifier itself than have
|
|
|
|
// been added through dbus. Make sure all of them are associated with
|
|
|
|
// an object path and proxy.
|
|
|
|
let zoomRegions = Main.magnifier.getZoomRegions();
|
|
|
|
let objectPaths = [];
|
|
|
|
let thoseZoomers = this._zoomers;
|
2017-10-30 20:38:18 -04:00
|
|
|
zoomRegions.forEach ((aZoomRegion, index, array) => {
|
2010-05-11 15:00:07 -04:00
|
|
|
let found = false;
|
|
|
|
for (let objectPath in thoseZoomers) {
|
|
|
|
let proxyAndZoomRegion = thoseZoomers[objectPath];
|
|
|
|
if (proxyAndZoomRegion.zoomRegion === aZoomRegion) {
|
|
|
|
objectPaths.push(objectPath);
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) {
|
|
|
|
// Got a ZoomRegion with no DBus proxy, make one.
|
2010-05-13 15:46:04 -04:00
|
|
|
let newPath = ZOOM_SERVICE_PATH + '/zoomer' + _zoomRegionInstanceCount;
|
2010-05-11 15:00:07 -04:00
|
|
|
_zoomRegionInstanceCount++;
|
|
|
|
let zoomRegionProxy = new ShellMagnifierZoomRegion(newPath, aZoomRegion);
|
|
|
|
let proxyAndZoomer = {};
|
|
|
|
proxyAndZoomer.proxy = zoomRegionProxy;
|
|
|
|
proxyAndZoomer.zoomRegion = aZoomRegion;
|
|
|
|
thoseZoomers[newPath] = proxyAndZoomer;
|
|
|
|
objectPaths.push(newPath);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return objectPaths;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-11 15:00:07 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* clearAllZoomRegions:
|
|
|
|
* Remove all the zoom regions from this Magnfier's ZoomRegion list.
|
|
|
|
*/
|
2017-10-30 20:03:21 -04:00
|
|
|
clearAllZoomRegions() {
|
2010-05-11 15:00:07 -04:00
|
|
|
Main.magnifier.clearAllZoomRegions();
|
|
|
|
for (let objectPath in this._zoomers) {
|
|
|
|
let proxyAndZoomer = this._zoomers[objectPath];
|
2011-08-16 08:26:49 -04:00
|
|
|
proxyAndZoomer.proxy.destroy();
|
2010-05-11 15:00:07 -04:00
|
|
|
proxyAndZoomer.proxy = null;
|
|
|
|
proxyAndZoomer.zoomRegion = null;
|
|
|
|
delete this._zoomers[objectPath];
|
|
|
|
}
|
|
|
|
this._zoomers = {};
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-11 15:00:07 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* fullScreenCapable:
|
|
|
|
* Consult if the Magnifier can magnify in full-screen mode.
|
|
|
|
* @return Always return true.
|
|
|
|
*/
|
2017-10-30 20:03:21 -04:00
|
|
|
fullScreenCapable() {
|
2010-05-11 15:00:07 -04:00
|
|
|
return true;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-11 15:00:07 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setCrosswireSize:
|
|
|
|
* Set the crosswire size of all ZoomRegions.
|
|
|
|
* @size: The thickness of each line in the cross wire.
|
|
|
|
*/
|
2017-10-30 20:03:21 -04:00
|
|
|
setCrosswireSize(size) {
|
2010-05-11 15:00:07 -04:00
|
|
|
Main.magnifier.setCrosshairsThickness(size);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-11 15:00:07 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* getCrosswireSize:
|
|
|
|
* Get the crosswire size of all ZoomRegions.
|
|
|
|
* @return: The thickness of each line in the cross wire.
|
|
|
|
*/
|
2017-10-30 20:03:21 -04:00
|
|
|
getCrosswireSize() {
|
2010-05-11 15:00:07 -04:00
|
|
|
return Main.magnifier.getCrosshairsThickness();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-11 15:00:07 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setCrosswireLength:
|
|
|
|
* Set the crosswire length of all zoom-regions..
|
|
|
|
* @size: The length of each line in the cross wire.
|
|
|
|
*/
|
2017-10-30 20:03:21 -04:00
|
|
|
setCrosswireLength(length) {
|
2010-05-11 15:00:07 -04:00
|
|
|
Main.magnifier.setCrosshairsLength(length);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-11 15:00:07 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setCrosswireSize:
|
|
|
|
* Set the crosswire size of all zoom-regions.
|
|
|
|
* @size: The thickness of each line in the cross wire.
|
|
|
|
*/
|
2017-10-30 20:03:21 -04:00
|
|
|
getCrosswireLength() {
|
2010-05-11 15:00:07 -04:00
|
|
|
return Main.magnifier.getCrosshairsLength();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-11 15:00:07 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setCrosswireClip:
|
|
|
|
* Set if the crosswire will be clipped by the cursor image..
|
|
|
|
* @clip: Flag to indicate whether to clip the crosswire.
|
|
|
|
*/
|
2017-10-30 20:03:21 -04:00
|
|
|
setCrosswireClip(clip) {
|
2010-05-11 15:00:07 -04:00
|
|
|
Main.magnifier.setCrosshairsClip(clip);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-11 15:00:07 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* getCrosswireClip:
|
|
|
|
* Get the crosswire clip value.
|
|
|
|
* @return: Whether the crosswire is clipped by the cursor image.
|
|
|
|
*/
|
2017-10-30 20:03:21 -04:00
|
|
|
getCrosswireClip() {
|
2010-05-11 15:00:07 -04:00
|
|
|
return Main.magnifier.getCrosshairsClip();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-11 15:00:07 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setCrosswireColor:
|
|
|
|
* Set the crosswire color of all ZoomRegions.
|
|
|
|
* @color: Unsigned int of the form rrggbbaa.
|
|
|
|
*/
|
2017-10-30 20:03:21 -04:00
|
|
|
setCrosswireColor(color) {
|
2010-06-24 18:43:55 -04:00
|
|
|
Main.magnifier.setCrosshairsColor('#%08x'.format(color));
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-11 15:00:07 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* getCrosswireClip:
|
|
|
|
* Get the crosswire color of all ZoomRegions.
|
|
|
|
* @return: The crosswire color as an unsigned int in the form rrggbbaa.
|
|
|
|
*/
|
2017-10-30 20:03:21 -04:00
|
|
|
getCrosswireColor() {
|
2010-05-11 15:00:07 -04:00
|
|
|
let colorString = Main.magnifier.getCrosshairsColor();
|
|
|
|
// Drop the leading '#'.
|
|
|
|
return parseInt(colorString.slice(1), 16);
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2010-05-11 15:00:07 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ShellMagnifierZoomRegion:
|
|
|
|
* Object that implements the DBus ZoomRegion interface.
|
|
|
|
* @zoomerObjectPath: String that is the path to a DBus ZoomRegion.
|
|
|
|
* @zoomRegion: The actual zoom region associated with the object path.
|
|
|
|
*/
|
2017-10-30 21:19:44 -04:00
|
|
|
var ShellMagnifierZoomRegion = class ShellMagnifierZoomRegion {
|
|
|
|
constructor(zoomerObjectPath, zoomRegion) {
|
2010-05-11 15:00:07 -04:00
|
|
|
this._zoomRegion = zoomRegion;
|
2011-08-16 08:26:49 -04:00
|
|
|
|
|
|
|
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(ZoomRegionIface, this);
|
|
|
|
this._dbusImpl.export(Gio.DBus.session, zoomerObjectPath);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-11 15:00:07 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setMagFactor:
|
|
|
|
* @xMagFactor: The power to set the horizontal magnification factor to
|
|
|
|
* of the magnified view. A value of 1.0 means no
|
|
|
|
* magnification. A value of 2.0 doubles the size.
|
|
|
|
* @yMagFactor: The power to set the vertical magnification factor to
|
|
|
|
* of the magnified view.
|
|
|
|
*/
|
2017-10-30 20:03:21 -04:00
|
|
|
setMagFactor(xMagFactor, yMagFactor) {
|
2010-05-11 15:00:07 -04:00
|
|
|
this._zoomRegion.setMagFactor(xMagFactor, yMagFactor);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-11 15:00:07 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* getMagFactor:
|
|
|
|
* @return 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.
|
|
|
|
*/
|
2017-10-30 20:03:21 -04:00
|
|
|
getMagFactor() {
|
2010-05-11 15:00:07 -04:00
|
|
|
return this._zoomRegion.getMagFactor();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-11 15:00:07 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setRoi:
|
|
|
|
* Sets the "region of interest" that the ZoomRegion is magnifying.
|
2010-08-06 13:07:49 -04:00
|
|
|
* @roi Array, [left, top, right, bottom], defining the region of the
|
|
|
|
* screen to magnify. The values are in screen (unmagnified)
|
|
|
|
* coordinate space.
|
2010-05-11 15:00:07 -04:00
|
|
|
*/
|
2017-10-30 20:03:21 -04:00
|
|
|
setRoi(roi) {
|
2010-08-06 13:07:49 -04:00
|
|
|
let roiObject = { x: roi[0], y: roi[1], width: roi[2] - roi[0], height: roi[3] - roi[1] };
|
2010-05-11 15:00:07 -04:00
|
|
|
this._zoomRegion.setROI(roiObject);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-11 15:00:07 -04: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.
|
2010-08-06 13:07:49 -04:00
|
|
|
* @return an array, [left, top, right, bottom], representing the bounding
|
2010-05-11 15:00:07 -04:00
|
|
|
* rectangle of what is shown in the magnified view.
|
|
|
|
*/
|
2017-10-30 20:03:21 -04:00
|
|
|
getRoi() {
|
2010-08-06 13:07:49 -04:00
|
|
|
let roi = this._zoomRegion.getROI();
|
|
|
|
roi[2] += roi[0];
|
|
|
|
roi[3] += roi[1];
|
|
|
|
return roi;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-11 15:00:07 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the "region of interest" by centering the given screen coordinate
|
|
|
|
* within the zoom region.
|
|
|
|
* @x The x-coord of the point to place at the center of the zoom region.
|
|
|
|
* @y The y-coord.
|
|
|
|
* @return Whether the shift was successful (for GS-mag, this is always
|
|
|
|
* true).
|
|
|
|
*/
|
2017-10-30 20:03:21 -04:00
|
|
|
shiftContentsTo(x, y) {
|
2010-05-11 15:00:07 -04:00
|
|
|
this._zoomRegion.scrollContentsTo(x, y);
|
|
|
|
return true;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-11 15:00:07 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* moveResize
|
|
|
|
* Sets the position and size of the ZoomRegion on screen.
|
2010-08-06 13:07:49 -04:00
|
|
|
* @viewPort Array, [left, top, right, bottom], defining the position and
|
|
|
|
* size on screen to place the zoom region.
|
2010-05-11 15:00:07 -04:00
|
|
|
*/
|
2017-10-30 20:03:21 -04:00
|
|
|
moveResize(viewPort) {
|
2010-08-06 13:07:49 -04:00
|
|
|
let viewRect = { x: viewPort[0], y: viewPort[1], width: viewPort[2] - viewPort[0], height: viewPort[3] - viewPort[1] };
|
2010-05-11 15:00:07 -04:00
|
|
|
this._zoomRegion.setViewPort(viewRect);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-08-16 08:26:49 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
destroy() {
|
2011-08-16 08:26:49 -04:00
|
|
|
this._dbusImpl.unexport();
|
2010-05-11 15:00:07 -04:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|