const assert = require('assert'), fs = require('fs'), path = require('path'), vm = require('vm'); const api = vm.createContext({}); vm.runInContext(fs.readFileSync(path.join(__dirname, '../quickshell/overview/OverviewLogic.js'), 'utf8'), api); const dims = g => g.rows + 'x' + g.columns; // Balanced rows of at most five. assert.equal(dims(api.grid(9)), '2x5'); assert.equal(dims(api.grid(10)), '2x5'); assert.equal(dims(api.grid(6)), '2x3'); assert.equal(dims(api.grid(4)), '1x4'); assert.equal(dims(api.grid(0)), '1x1'); assert.equal(dims(api.grid(11)), '3x4'); // A short last row is centred. const g9 = api.grid(9); assert.equal(JSON.stringify(api.cell(0, g9)), '{"row":0,"column":0}'); assert.equal(JSON.stringify(api.cell(5, g9)), '{"row":1,"column":0.5}'); assert.equal(JSON.stringify(api.cell(8, g9)), '{"row":1,"column":3.5}'); // Left/right wrap through every slot. assert.equal(api.step(0, 'left', g9), 8); assert.equal(api.step(8, 'right', g9), 0); assert.equal(api.step(4, 'right', g9), 5); // Up/down go to the nearest slot in the other row and wrap. assert.equal(api.step(0, 'down', g9), 5); assert.equal(api.step(4, 'down', g9), 8); assert.equal(api.step(5, 'up', g9), 0); assert.equal(api.step(8, 'up', g9), 3); assert.equal(api.step(6, 'down', g9), 1); assert.equal(api.step(2, 'up', g9), 6); // One row: up/down stay; an unknown slot starts at the first. assert.equal(api.step(2, 'down', api.grid(4)), 2); assert.equal(api.step(-1, 'right', g9), 0); // Windows are scaled into the thumbnail relative to their monitor. const mon = {x: 1920, y: 0, width: 1920, height: 1080}; assert.equal(JSON.stringify(api.project({x: 1920, y: 0, width: 960, height: 1080}, mon, 192, 108)), '{"x":0,"y":0,"width":96,"height":108}'); // Off-monitor parts are clipped; windows elsewhere are dropped. assert.equal(JSON.stringify(api.project({x: 3600, y: 540, width: 600, height: 1080}, mon, 192, 108)), '{"x":168,"y":54,"width":24,"height":54}'); assert.equal(api.project({x: 0, y: 0, width: 800, height: 600}, mon, 192, 108), null); assert.equal(api.project({x: 1920, y: 0, width: 0, height: 10}, mon, 192, 108), null); assert.equal(api.project({x: 0, y: 0, width: 10, height: 10}, null, 192, 108), null); // A portrait monitor in a landscape thumbnail is centred. const portrait = {x: 0, y: 0, width: 1080, height: 1920}; assert.equal(JSON.stringify(api.project({x: 0, y: 0, width: 1080, height: 1920}, portrait, 192, 108)), '{"x":65.625,"y":0,"width":60.75,"height":108}'); console.log('overview logic: ok');