Overview
This article provides code examples of how to detect the monitor a window is located in.
Solution 1
The code below gets the bounds of the current window then checks which monitor matches the top-left corner coordinates of the window.
function isInMonitor(winBounds, monitorData) {
return winBounds.left >= monitorData.monitorRect.left
&& winBounds.left <=monitorData.monitorRect.right
&& winBounds.top >= monitorData.monitorRect.top
&& winBounds.top <= monitorData.monitorRect.bottom;
}
fin.desktop.Window.getCurrent().getBounds(winBounds => {
fin.desktop.System.getMonitorInfo(data=>{
if (isInMonitor(winBounds, data.primaryMonitor)) {
console.log("window is in primary monitor, monitor name: " + data.primaryMonitor.name);
}
else {
data.nonPrimaryMonitors.forEach(monitorData => {
if (isInMonitor(winBounds, monitorData)) {
console.log("window is in non-primary monitor, monitor name: " + monitorData.name);
}
});
}
})
});
Comments
0 comments
Please sign in to leave a comment.