/* Copyright 2018-2019 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ var red = 0xFF; var yellow = 0xFFFF; var GXxor = 0x6; // src XOR dst var GXclear = 0x0; var ExposureMask = (1 << 15); function windows_monitorborder() { this._ObjectID = 'monitor-info'; var info = require('monitor-info'); var gm = require('_GenericMarshal'); var user32 = gm.CreateNativeProxy('user32.dll'); info.monitors = []; user32.CreateMethod('GetDC'); user32.CreateMethod('ReleaseDC'); user32.CreateMethod('FillRect'); user32.CreateMethod('InvalidateRect'); var gdi32 = gm.CreateNativeProxy('gdi32.dll'); gdi32.CreateMethod('CreateSolidBrush'); var redBrush = gdi32.CreateSolidBrush(red); var yellowBrush = gdi32.CreateSolidBrush(yellow); require('events').EventEmitter.call(this); this.on('~', function () { this.Stop(); }); this.Stop = function Stop() { info.redInterval = null; var drawRect = gm.CreateVariable(16); var drawRectBuffer = drawRect.toBuffer(); for (var i in info.monitors) { // Top drawRectBuffer.writeInt32LE(info.monitors[i].left, 0); drawRectBuffer.writeInt32LE(info.monitors[i].top, 4); drawRectBuffer.writeInt32LE(info.monitors[i].left + (info.monitors[i].right - info.monitors[i].left), 8); drawRectBuffer.writeInt32LE(info.monitors[i].bottom - info.monitors[i].top, 12); user32.InvalidateRect(0, drawRect, 0); } } this.Start = function Start() { info.getInfo().then(function (mon) { var drawRect = gm.CreateVariable(16); info.monitors = mon; info.dc = user32.GetDC(0); info.state = 0; info.redInterval = setInterval(function () { info.state = (info.state + 1) % 8; var drawRectBuffer = drawRect.toBuffer(); for(var i in info.monitors) { drawRectBuffer.writeInt32LE(info.monitors[i].left, 0); drawRectBuffer.writeInt32LE(info.monitors[i].top, 4); drawRectBuffer.writeInt32LE(info.monitors[i].left + (info.monitors[i].right - info.monitors[i].left)/2, 8); drawRectBuffer.writeInt32LE(5, 12); user32.FillRect(info.dc, drawRect, (info.state == 0 || info.state == 4) ? yellowBrush : redBrush); drawRectBuffer.writeInt32LE(info.monitors[i].left + (info.monitors[i].right - info.monitors[i].left) / 2, 0); drawRectBuffer.writeInt32LE(info.monitors[i].top, 4); drawRectBuffer.writeInt32LE(info.monitors[i].right, 8); drawRectBuffer.writeInt32LE(5, 12); user32.FillRect(info.dc, drawRect, (info.state == 1 || info.state == 5) ? yellowBrush : redBrush); drawRectBuffer.writeInt32LE(info.monitors[i].right - 5, 0); drawRectBuffer.writeInt32LE(info.monitors[i].top, 4); drawRectBuffer.writeInt32LE(info.monitors[i].right, 8); drawRectBuffer.writeInt32LE(info.monitors[i].top + (info.monitors[i].bottom - info.monitors[i].top)/2, 12); user32.FillRect(info.dc, drawRect, (info.state == 2 || info.state == 6) ? yellowBrush : redBrush); drawRectBuffer.writeInt32LE(info.monitors[i].right - 5, 0); drawRectBuffer.writeInt32LE(info.monitors[i].top + (info.monitors[i].bottom - info.monitors[i].top) / 2, 4); drawRectBuffer.writeInt32LE(info.monitors[i].right, 8); drawRectBuffer.writeInt32LE(info.monitors[i].bottom, 12); user32.FillRect(info.dc, drawRect, (info.state == 3 || info.state == 7) ? yellowBrush : redBrush); drawRectBuffer.writeInt32LE(info.monitors[i].left + (info.monitors[i].right - info.monitors[i].left) / 2, 0); drawRectBuffer.writeInt32LE(info.monitors[i].bottom - 5, 4); drawRectBuffer.writeInt32LE(info.monitors[i].right, 8); drawRectBuffer.writeInt32LE(info.monitors[i].bottom, 12); user32.FillRect(info.dc, drawRect, (info.state == 4 || info.state == 0) ? yellowBrush : redBrush); drawRectBuffer.writeInt32LE(info.monitors[i].left, 0); drawRectBuffer.writeInt32LE(info.monitors[i].bottom - 5, 4); drawRectBuffer.writeInt32LE(info.monitors[i].left + (info.monitors[i].right - info.monitors[i].left) / 2, 8); drawRectBuffer.writeInt32LE(info.monitors[i].bottom, 12); user32.FillRect(info.dc, drawRect, (info.state == 5 || info.state == 1) ? yellowBrush : redBrush); drawRectBuffer.writeInt32LE(info.monitors[i].left, 0); drawRectBuffer.writeInt32LE(info.monitors[i].top + (info.monitors[i].bottom - info.monitors[i].top) / 2, 4); drawRectBuffer.writeInt32LE(info.monitors[i].left + 5, 8); drawRectBuffer.writeInt32LE(info.monitors[i].bottom, 12); user32.FillRect(info.dc, drawRect, (info.state == 6 || info.state == 2) ? yellowBrush : redBrush); drawRectBuffer.writeInt32LE(info.monitors[i].left, 0); drawRectBuffer.writeInt32LE(info.monitors[i].top, 4); drawRectBuffer.writeInt32LE(info.monitors[i].left + 5, 8); drawRectBuffer.writeInt32LE(info.monitors[i].top + (info.monitors[i].bottom - info.monitors[i].top) / 2, 12); user32.FillRect(info.dc, drawRect, (info.state == 7 || info.state == 3) ? yellowBrush : redBrush); } }, 450); }); } } function linux_monitorborder() { var self = this; this.displays = []; this._ObjectID = 'monitor-info'; this._info = require('monitor-info'); this._isUnity = this._info.isUnity(); console.log('isUnity = ' + this._isUnity); require('events').EventEmitter.call(this); this.on('~', function () { this.Stop(); }); this.Stop = function Stop() { this._timeout = null; if(!this._isUnity) { for(var i=0; i < this.displays.length; ++i) { if(this.displays[i].GC1 && this.displays[i].rootWindow) { self._info._X11.XSetFunction(self.displays[i].display, self.displays[i].GC1, GXclear); self._info._X11.XDrawLine(self.displays[i].display, self.displays[i].rootWindow, self.displays[i].GC1, 0, 0, self.displays[i].right, 0); self._info._X11.XDrawLine(self.displays[i].display, self.displays[i].rootWindow, self.displays[i].GC1, self.displays[i].right, 0, self.displays[i].right, self.displays[i].bottom); self._info._X11.XDrawLine(self.displays[i].display, self.displays[i].rootWindow, self.displays[i].GC1, 0, self.displays[i].bottom, self.displays[i].right, self.displays[i].bottom); self._info._X11.XDrawLine(self.displays[i].display, self.displays[i].rootWindow, self.displays[i].GC1, 0, 0, 0, self.displays[i].bottom); this._info._X11.XFlush(this.displays[i].display); } } } } this.Start = function Start() { this._info.getInfo().then(function (mon) { self.displays = mon; console.log(mon.length + ' displays'); for(var i = 0; i