2017-08-24 02:51:02 -05:00
|
|
|
'use strict';
|
2017-04-20 13:54:11 -05:00
|
|
|
|
|
|
|
const electron = require('electron');
|
|
|
|
|
2017-04-26 11:46:15 -05:00
|
|
|
|
2017-04-20 13:54:11 -05:00
|
|
|
/**
|
|
|
|
* Returns true if given rectangle is contained within the workArea of at
|
|
|
|
* least one of the screens.
|
2017-08-24 02:51:02 -05:00
|
|
|
* @param {Object} rect - ex:- {x: Number, y: Number, width: Number, height: Number}
|
|
|
|
* @return {Boolean} true if condition in desc is met.
|
2017-04-20 13:54:11 -05:00
|
|
|
*/
|
|
|
|
function isInDisplayBounds(rect) {
|
|
|
|
if (!rect) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
let displays = electron.screen.getAllDisplays();
|
|
|
|
|
|
|
|
for(let i = 0, len = displays.length; i < len; i++) {
|
|
|
|
let workArea = displays[i].workArea;
|
|
|
|
if (rect.x >= workArea.x && rect.y >= workArea.y &&
|
|
|
|
((rect.x + rect.width) <= (workArea.x + workArea.width)) &&
|
|
|
|
((rect.y + rect.height) <= (workArea.y + workArea.height))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = isInDisplayBounds;
|