7

Is there any simple way to align window of Node-Webkit application? As far as I can see in documentation there is such metod as Window.moveTo(), as well as property "position", which nevertheless could have only 3 values: "center", "mouse" and null. So in order to align the app by the right side of monitor I need to move window manually from code on start, or are there any other way?

Harsh
  • 1,072
  • 1
  • 10
  • 16
SLoN1ck
  • 221
  • 3
  • 6
  • Its dead simple. My bad was to place question and didn't think enough to workaround the issue. You can use Window.X and position: center in order to get half of screen. To align window to the right, you just need to hide window in options file, then on startup move window to the right and show it. – SLoN1ck Mar 16 '14 at 16:21

1 Answers1

12
  1. Use javascript window.screen.availHeight and window.screen.availWidth (which excludes window decorations n toolbar)
    or

    window.screen.height and window.screen.width (which includes window decorations n toolbar) to get the screen resolution.

  2. In node-webkit package.json set

    "window": { "show": false } this will hide the node-webkit window initially.

  3. var appWidth = 400; // width of your application

  4. Use window.moveTo(window.screen.availWidth - appWidth, 40);

  5. Use window.show(); to show the window

this allows to place window anywhere on screen

Harsh
  • 1,072
  • 1
  • 10
  • 16
  • It's actually window.window.screen.height/width. The first object is the nw.js wrapper of the DOM window, which contains the screen object. – Alf Apr 12 '15 at 11:54
  • @Alf i have not checked this in the latest version of node-webkit (nw.js) but this code worked for me in older versions – Harsh Apr 18 '15 at 10:42
  • I just double checked (nw.js 0.12): require('nw.gui').Window.get().screen is undefined. require('nw.gui').Window.get().window.screen works. – Alf Apr 20 '15 at 09:06