Detect full-screen width & height in node webkit

1.3k views Asked by At

I'm able to get the node webkit app to load full screen with this in my html's javascript:

"use strict";

const gui = require('nw.gui');
var win = gui.Window.get();
win.enterFullscreen();

So after reading https://github.com/nwjs/nw.js/wiki/Screen , I tried this:

"use strict";

const gui = require('nw.gui');
var win = gui.Window.get();
var screen = gui.Screen.Init();

var onDisplayBoundsChanged = function(screen) {
  alert("hey");
}

gui.Screen.on('displayBoundsChanged', onDisplayBoundsChanged);

// win.enterFullscreen();
win.maximize();

window.client = new GameClient(screen);

I never see the alert. Ideally I want to delay

window.client = new GameClient(screen);

until after the application fullscreens and has a new, full screen bounds I can use.

How do I detect full-screen and get the width & height?

1

There are 1 answers

0
quantumpotato On

I misunderstood what gui.Screen.Init() was returning.

Change var screen to

var screen = gui.Screen.Init().screens[0];

then

    generateCanvas(screen) {
    var canvas = document.getElementById('canvas');
    Thing.prototype.scale = 1;

    // let bounds = screen.bounds;
    let sw = screen.bounds.width;
    let sh = screen.bounds.height;