Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Aug 31, 2020. It is now read-only.

kimbtech/electron-window-position

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

12 Commits
12 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Electron-Window-Position

Easy and intuitive window positioning for electron browser windows.

When opening an Electron BrowserWindow one have to define an position or use the default, which centers the window over all screens.
On some systems the default centering won't open the window on your current screen, e.g. the window could open on a monitor which is switched off.

This package detects on which screen the users mouse is and centers the window on that screen. Or opens it in the top left corner of that screen.

Installation

npm install electron-window-position --save

Usage

const electron = require('electron');
const WindowPosition = require( 'electron-window-position' );

// Open window on electron.app.ready
new WindowPosition( function ( pos ){
  mainWindow = new electron.BrowserWindow({
      x: pos.x, 
      y: pos.y,
      width: 300,
      height: 300,
      show: true,
      resizable: false
  });
});
const electron = require('electron');
const WindowPosition = require( 'electron-window-position' );

// Get position for centered window
var position = new WindowPosition();
try{
  var pos = position.getActiveScreenCenter(300,300);
  
  mainWindow = new electron.BrowserWindow({
      x: pos.x, 
      y: pos.y,
      width: 300,
      height: 300,
      show: true,
      resizable: false
  });
} catch (e) {
	// electron.app not ready
}

See also JSDoc at GitHub Pages

About

Easy and intuitive window positioning for electron browser windows โ€” ๐Ÿ–ฅ๐Ÿ•น

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.