mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-12 20:18:41 -09:00
Open new window offset from last focused window (Credit: albinekb) (#581)
* Open new window offset from last focused window * Make sure a newly opened window is seen to now have focus * Instead of setting focus time, simply emit the event first * Add comment explaining why we emit the focus event * Don't fire the event, as that can make it fire twice
This commit is contained in:
parent
749d1f4681
commit
518b0cd9a5
1 changed files with 10 additions and 4 deletions
14
app/index.js
14
app/index.js
|
|
@ -60,9 +60,9 @@ app.on('ready', () => {
|
|||
// Open the new window roughly the height of the header away from the
|
||||
// previous window. This also ensures in multi monitor setups that the
|
||||
// new terminal is on the correct screen.
|
||||
if (BrowserWindow.getFocusedWindow() !== null) {
|
||||
const currentWindow = BrowserWindow.getFocusedWindow();
|
||||
const points = currentWindow.getPosition();
|
||||
const focusedWindow = BrowserWindow.getFocusedWindow() || app.getLastFocusedWindow();
|
||||
if (focusedWindow) {
|
||||
const points = focusedWindow.getPosition();
|
||||
const currentScreen = screen.getDisplayNearestPoint({ x: points[0], y: points[1] });
|
||||
|
||||
const biggestX = ((points[0] + 100 + width) - currentScreen.bounds.x);
|
||||
|
|
@ -280,9 +280,15 @@ app.on('ready', () => {
|
|||
// Keep track of focus time of every window, to figure out
|
||||
// which one of the existing window is the last focused.
|
||||
// Works nicely even if a window is closed and removed.
|
||||
win.on('focus', () => {
|
||||
const updateFocusTime = () => {
|
||||
win.focusTime = process.uptime();
|
||||
};
|
||||
win.on('focus', () => {
|
||||
updateFocusTime();
|
||||
});
|
||||
// Ensure focusTime is set on window open. The focus event doesn't
|
||||
// fire from the dock (see bug #583)
|
||||
updateFocusTime();
|
||||
|
||||
// the window can be closed by the browser process itself
|
||||
win.on('close', () => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue