Skip to content
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

Support partially visible window state #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 19 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ module.exports = function (options) {
file: 'window-state.json',
path: app.getPath('userData'),
maximize: true,
fullScreen: true
fullScreen: true,
allowPartiallyVisibleWindow: false,
minVisiblePart: 100
}, options);
const fullStoreFileName = path.join(config.path, config.file);

Expand Down Expand Up @@ -45,6 +47,15 @@ module.exports = function (options) {
};
}

function isPartiallyVisibleWindow(bounds) {
return (
bounds.x + config.minVisiblePart < state.x + state.width &&
bounds.x + bounds.width - config.minVisiblePart > state.x &&
bounds.y + config.minVisiblePart < state.y + state.height &&
bounds.y + bounds.height - config.minVisiblePart > state.y
);
}

function windowWithinBounds(bounds) {
return (
state.x >= bounds.x &&
Expand All @@ -56,7 +67,13 @@ module.exports = function (options) {

function ensureWindowVisibleOnSomeDisplay() {
const visible = screen.getAllDisplays().some(display => {
return windowWithinBounds(display.bounds);
return (
windowWithinBounds(display.bounds) ||
(
config.allowPartiallyVisibleWindow &&
isPartiallyVisibleWindow(display.bounds)
)
);
});

if (!visible) {
Expand Down