GithubHelp home page GithubHelp logo

Comments (5)

gseregni avatar gseregni commented on May 25, 2024

Same here..

from electron-window-state.

MathieuDebit avatar MathieuDebit commented on May 25, 2024

The algorithm that checks if the window can be displayed within display bounds is in the validateState() method:

const displayBounds = screen.getDisplayMatching(state).bounds;
const sameBounds = deepEqual(state.displayBounds, displayBounds, {strict: true});
if (!sameBounds) {
if (displayBounds.width < state.displayBounds.width) {
if (state.x > displayBounds.width) {
state.x = 0;
}
if (state.width > displayBounds.width) {
state.width = displayBounds.width;
}
}
if (displayBounds.height < state.displayBounds.height) {
if (state.y > displayBounds.height) {
state.y = 0;
}
if (state.height > displayBounds.height) {
state.height = displayBounds.height;
}
}
}
}
}

Here is an explanation of what this is doing:

  • Retrieve the display that most closely intersects the saved bounds, and get its bounds
  • if the retrieved bounds is not deeply equal to the saved bounds:
    • if the retrieved screen size is smaller than the saved screen size:
      • if the saved window position values are bigger than the retrieved screen size:
        • set the window position values to 0
      • if the saved window size is bigger than the retrieved screen size:
        • set the window size to the retrieved screen size

This logic has drawbacks because it only takes into accounts positive values. Therefore it only works with this exact dual screen setup (with the window previously positioned in the second screen which is bigger than the primary one):

capture

from electron-window-state.

MathieuDebit avatar MathieuDebit commented on May 25, 2024

Mac OSX is handling the window positioning differently than Windows. This difference can be simply tested by manually setting the main window position in a basic electron-quick-start example.

With these options:

mainWindow = new BrowserWindow({
    'x': -100,
    'y': 0,
    'width': 800,
    'height': 600,
  });

the window in Windows will be 100px off the main screen and partly in the second screen, while on Mac OSX the window will be fully on the main screen. You can't position a window between two screens in OSX.
We can understand that Windows has an extended desktop while Mac OSX has separate ones.

Actually electron-boilerplate checks if the window is within a display bounds. See electron-boilerplate:src/helpers/window.js.

Microsoft VSCode seems to have an interesting implementation too. See vscode:src/vs/code/electron-main/window.ts

from electron-window-state.

MathieuDebit avatar MathieuDebit commented on May 25, 2024

PR #45 proposes to fix this issue. Check it out 🤙

from electron-window-state.

mawie81 avatar mawie81 commented on May 25, 2024

With the merge of #45 this issue is hopefully fixed 👍
Thx @MathieuDebit

from electron-window-state.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.