From cb96e9596dbf68ea6e7229873cf9f89718e0dae8 Mon Sep 17 00:00:00 2001 From: bordun Date: Mon, 27 Jul 2020 12:50:12 +0200 Subject: [PATCH] window: store full geometry for launcher & cient, make this default for all platforms --- CHANGELOG.md | 7 ++++- src/server/electron-window.js | 59 +++++++++++++++++++++-------------- src/server/index.js | 4 +-- 3 files changed, 44 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8f66dc6..d90b4997 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Changelog -## v1.0.0 +## 1.0.1 + +- UI + - windows' dimensions and position are now saved upon closing and restored at startup + +## 1.0.0 *This list is not exhaustive* diff --git a/src/server/electron-window.js b/src/server/electron-window.js index 7e2c56f6..e499dc18 100644 --- a/src/server/electron-window.js +++ b/src/server/electron-window.js @@ -7,23 +7,9 @@ var path = require('path'), module.exports = function(options={}) { - var window, - currentScreen = screen.getDisplayNearestPoint(screen.getCursorScreenPoint()) - - if (process.platform === 'win32' && settings.read('last-used-screen')) { - // on windows, retreive last used screen - var lastScreen = screen.getAllDisplays().find(x=>x.id === settings.read('last-used-screen')) - if (lastScreen) currentScreen = lastScreen - else settings.write('last-used-screen', null) - } - - var screenSize = currentScreen.size, - width = options.width || screenSize.width, - height = options.height || screenSize.height + var window window = new BrowserWindow({ - width: width, - height: height, title: options.title || settings.infos.appName, icon: path.resolve(__dirname + '/../assets/logo.png'), backgroundColor: options.color || theme.backgroundColor, @@ -37,11 +23,27 @@ module.exports = function(options={}) { show: false, }) - var bounds = currentScreen.bounds, + + // default geometry + var currentScreen = screen.getDisplayNearestPoint(screen.getCursorScreenPoint()), + screenSize = currentScreen.size, + width = options.width || screenSize.width, + height = options.height || screenSize.height, + bounds = currentScreen.bounds, x = Math.ceil(bounds.x + ((bounds.width - width) / 2)), y = Math.ceil(bounds.y + ((bounds.height - height) / 2)) - window.setBounds({x: x, y: y}) + window.setBounds({x, y, width, height}) + + // retreive last geometry + if (settings.read('geometry')) { + var geometry = settings.read('geometry')[options.id], + mScreen = screen.getDisplayMatching(geometry) + if (intersectionArea(geometry, mScreen.bounds) > 20000) { + // don't load geometry if the window is not visible enough + window.setBounds(geometry) + } + } window.once('ready-to-show', ()=>{ window.show() @@ -122,12 +124,12 @@ module.exports = function(options={}) { }) } - if (process.platform === 'win32') { - // on windows, store last used screen when closing - window.on('close', function() { - settings.write('last-used-screen', screen.getDisplayMatching(window.getBounds()).id) - }) - } + window.on('close', function() { + // save geometry + var geometry = settings.read('geometry') || {} + geometry[options.id] = window.getBounds() + settings.write('geometry', geometry) + }) if (options.shortcuts) { @@ -148,3 +150,14 @@ module.exports = function(options={}) { return window } + + +function intersectionArea(a, b) { + // intersectionArea between two rectangles + + var width = Math.min(a.x + a.width, b.x + b.width) - Math.max(a.x, b.x), + height = Math.min(a.y + a.height, b.y + b.height) - Math.max(a.y, b.y) + + return width * height + +} diff --git a/src/server/index.js b/src/server/index.js index fe9543fe..c4663dde 100644 --- a/src/server/index.js +++ b/src/server/index.js @@ -80,7 +80,7 @@ function openClient() { var address = settings.appAddresses()[0] var launch = ()=>{ - var win = require('./electron-window')({address:address, shortcuts:true, fullscreen: settings.read('fullscreen')}) + var win = require('./electron-window')({address:address, shortcuts:true, fullscreen: settings.read('fullscreen'), id: 'client'}) win.on('error', ()=>{ console.log('ERR') }) @@ -122,7 +122,7 @@ if (settings.cli) { global.midilist = require('./midi').list global.serverProcess = null global.clientWindows = [] - launcher = require('./electron-window')({address:address, shortcuts:dev, width:680, height:(40 + 200 + 20 + 24 * Object.keys(settings.options).filter(x=>settings.options[x].launcher !== false).length / 2), node:true, color:'#151a24'}) + launcher = require('./electron-window')({address:address, shortcuts:dev, width:680, height:(40 + 200 + 20 + 24 * Object.keys(settings.options).filter(x=>settings.options[x].launcher !== false).length / 2), node:true, color:'#151a24', id: 'launcher'}) launcher.on('close', ()=>{ process.stdout.write = stdoutWrite process.stderr.write = stderrWrite