nwjs / nw.js

Call all Node.js modules directly from DOM/WebWorker and enable a new way of writing applications with all Web technologies.
https://nwjs.io
MIT License
40.38k stars 3.88k forks source link

New fullscreen windows do not respect the primary screen under Linux #7937

Open chewi opened 2 years ago

chewi commented 2 years ago

Issue Type

Current/Missing Behavior

When I start CrossCode (using the latest NW.js, not the bundled one) in fullscreen under Linux, it does not respect the "primary" screen. Instead, it starts on the top left screen, essentially at 0, 0. This happens under both Xfce/X11 and KDE/Wayland.

If I exit fullscreen, drag the window across to the correct screen, and make it fullscreen again, then it stays on the correct screen, but this does not persist to the next invocation.

Expected/Proposed Behavior

Both of these environments have the concept of a primary screen so it should respect this like other applications do. I have checked the Chromium source and found even that has the concept of a primary screen.

I don't think this is a bug with CrossCode itself, but I do not know of another NW.js example I could try for comparison. I'd be happy to do so if pointed at one though.

I wonder whether NW.js even needs to check for the primary screen. This code in nw_content.cc seems to anchor new windows at 0, 0 almost unconditionally. What if it simply didn't do that?

  int x = 0, y = 0;
  if (manifest->GetInteger(switches::kmX, &x))
    ret.window_spec.bounds.set_x(x);
  if (manifest->GetInteger(switches::kmY, &y))
    ret.window_spec.bounds.set_y(y);

Additional Info

ayushmanchhabra commented 2 years ago

After going through this comment again, this may be related to #7884. I'll try to come up with a repro.

chewi commented 2 years ago

I don't think it's the same issue. I tried 0.60.0, but it didn't help. However, I did play around with CrossCode's package.json a bit more. Here's what it normally looks like.

{
  "name": "CrossCode",
  "version" : "1.0.0",
  "main": "assets/node-webkit.html",
  "chromium-args" : "--ignore-gpu-blacklist --ignore-gpu-blocklist --disable-direct-composition --disable-background-networking --in-process-gpu --password-store=basic",
  "window" : {
        "toolbar" : false,
        "icon" : "favicon.png",
        "width" : 1136,
        "height": 640,
        "fullscreen" : false
  }
}

If I remove width and height then it works. fullscreen makes no difference as the game starts fullscreen by default anyway. I guess it uses its own logic for that.

The problem is that removing width and height prevents the game's "double size" option from working properly. It doesn't double the size of the window so you only see the top-left quarter of the game. You can resize the window manually, but it doesn't remember that the next time.

In short, setting width and height should not break which screen the game starts on. This is probably an NW.js bug. I don't think it's the game's own fullscreen logic messing it up because the above workaround respects the primary screen, even when the game isn't fullscreen.