Code Monkey home page Code Monkey logo

electron-window-position's Introduction

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

electron-window-position's People

Contributors

kimbtech avatar

Watchers

 avatar

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.