-
Notifications
You must be signed in to change notification settings - Fork 477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Center tourWindow & dialog on primary display #144
Changes from 5 commits
13083c1
08c14a2
8843ee5
76d52e9
a01067b
0f5ecb1
c32a860
c626021
ec86afa
9ddf8af
4b4633d
3d158c0
430e812
2c71827
ca237a4
bd99db7
63acc29
ad2c3eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ const omit = require('lodash').omit; | |
|
||
// Electron Libs | ||
const { app, BrowserWindow, ipcMain } = require('electron'); | ||
const electron = require('electron'); | ||
|
||
// Prevent Linux GPU Bug | ||
// https://github.com/electron/electron/issues/4322 | ||
|
@@ -27,10 +28,18 @@ let mainWindow = null; | |
let previewWindow = null; | ||
|
||
function createTourWindow() { | ||
// Easier to work with when centering tour | ||
// window on primary display. | ||
const width = 700; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, why do we need to declare There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I use the So if you ever have to change the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I see it now, sorry 😛 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
And please don't! 😄 |
||
const height = 600; | ||
// Get Primary Display (screen / monitor) | ||
const primaryDisplay = electron.screen.getPrimaryDisplay(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then const primaryDisplay = screen.getPrimaryDisplay(); |
||
// Creating a New Window | ||
tourWindow = new BrowserWindow({ | ||
width: 700, | ||
height: 600, | ||
x: primaryDisplay.bounds.x / 2 - width / 2 + primaryDisplay.bounds.x, | ||
y: primaryDisplay.bounds.y / 2 + height / 2 + primaryDisplay.bounds.y, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, can you explain what line 39 and line 40 do? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On my monitor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is your I'm using only my laptop and got this:
What would happen if you use only 1 monitor? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are correct, my primary display is on the right. x: primaryDisplay.bounds.x / 2 - width / 2 + primaryDisplay.bounds.x,
y: primaryDisplay.bounds.y / 2 + height / 2 + primaryDisplay.bounds.y,
If I only use: x: primaryDisplay.bounds.x,
y: primaryDisplay.bounds.y, For me this is 1920, 1080, but for you 0, 0. It will show on correct screen but not in center 😞 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. const primaryDisplay = electron.screen.getPrimaryDisplay();
let x = undefined
let y = undefined
if (primaryDisplay.bounds.x === 0 && primaryDisplay.bounds.y === 0) {
x = primaryDisplay.bounds.width / 2 - width / 2
y = primaryDisplay.bounds.height / 2 - height / 2
} else {
x = primaryDisplay.bounds.x / 2 - width / 2 + primaryDisplay.bounds.x
y = primaryDisplay.bounds.y / 2 + height / 2 + primaryDisplay.bounds.y
} If PrimaryDisplay is Monitor 1 we can assume it start at 0, 0, right? If PrimaryDisplay is Monitor 2 or higher: Tests (The tour window is in center) One Monitor: If you have some weird monitor configure, such as if right top corner monitor 1 is linked to bottom left corner monitor 2 than tour window wont be 100% in center, but somewhere close to it 😛 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if we use this in all cases? x = primaryDisplay.bounds.width / 2 - width / 2
y = primaryDisplay.bounds.height / 2 - height / 2 Because what we want is for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the sake of this example I use the same resolution for all monitors. if I use x = primaryDisplay.bounds.width / 2 - width / 2
y = primaryDisplay.bounds.height / 2 - height / 2 x and y will always be the same because the resolution is the same on all monitors. This means the tour window will always show on monitor 1 regardless whether it is the primary display or not. If one monitor would be a different resolution and it was the primary display, it would still show on monitor 1 but not in center. Let's assume monitor 5 is the primary display (worst case scenario). x = primaryDisplay.bounds.x / 2 - width / 2 + primaryDisplay.bounds.x
y = primaryDisplay.bounds.y / 2 + height / 2 + primaryDisplay.bounds.y
I believe this should work. x = primaryDisplay.bounds.width / 2 - width / 2 + primaryDisplay.bounds.x
y = primaryDisplay.bounds.height / 2 - height / 2 + primaryDisplay.bounds.y
I dont have more monitors to test this theory on 😛 I need someone smart to tell me whether I am wrong or not 🙂 |
||
width, | ||
height, | ||
show: false, | ||
frame: false, | ||
resizable: false, | ||
|
@@ -248,8 +257,13 @@ function migrateData() { | |
}, | ||
}); | ||
// Omit old keys | ||
return omit(migratedConfigs, ['info', 'appSettings', 'printOptions', 'test']); | ||
} | ||
return omit(migratedConfigs, [ | ||
'info', | ||
'appSettings', | ||
'printOptions', | ||
'test', | ||
]); | ||
}, | ||
}; | ||
// Get the current Config | ||
const configs = appConfig.getAll(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can just add
screen
to the above line like soThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the API Documentation for screen you posted in the issue.
Note: In the renderer / DevTools, window.screen is a reserved DOM property, so writing let {screen} = require('electron') will not work.
I could try and see what happens 😛 ??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, nice catch! 👍