Draggable borderless game window and center position in the .js manifest help

Hello everyone!

I am a 8-bit pixel artist and I am making a game within NES screen resolution of 256x240. So to keep it looking good while upscaled, I am building the game at 3x (768x720).

I am trying to get rid of the game application window title bar and frame and to set specific X values for the window size to keep the pixel art aspect ratio intact (256x240, 512x480, 768x720)

I managed to edit the package.json to remove it by adding "frame: false", and "position: "center", but after doing some research I found out that also makes the window "undraggable" and the position kept behaving the same as before when the window was resized.
I researched for some solution for drag the window and i found out this on docs.nwjs.io:

"Frameless apps do not have a title bar for the user to click and drag the window. You can use CSS to designate DOM elements as draggable regions.

.drag-enable {
-webkit-app-region: drag;
}

.drag-disable {
-webkit-app-region: no-drag;
}

I did many amateurish attemps editing the Index.html but I have no coding knowledge to make it work right.

about the position of the window on screen, this is what i did and how the window look like:

package.png


256 x 240

256.png


512 x 480

512.png


768 x 720 (default build, that's why it looks centered)

768.png


My questions then are, if possible, can somebody help me with the draggable code to make it work, or some workaround and also help me understand why the window isn't centered and how can I make that happen?

EDIT: forgot to mention I've tried SRD game upgrade plugin, but it crashed the game completely due being outdated. So, not much of an option 🙁

Thanks in advance! 😀
Hello everyone!

I am a 8-bit pixel artist and I am making a game within NES screen resolution of 256x240. So to keep it looking good while upscaled, I am building the game at 3x (768x720).

I am trying to get rid of the game application window title bar and frame and to set specific X values for the window size to keep the pixel art aspect ratio intact (256x240, 512x480, 768x720)

I managed to edit the package.json to remove it by adding "frame: false", and "position: "center", but after doing some research I found out that also makes the window "undraggable" and the position kept behaving the same as before when the window was resized.
I researched for some solution for drag the window and i found out this on docs.nwjs.io:

"Frameless apps do not have a title bar for the user to click and drag the window. You can use CSS to designate DOM elements as draggable regions.

.drag-enable {
-webkit-app-region: drag;
}

.drag-disable {
-webkit-app-region: no-drag;
}

I did many amateurish attemps editing the Index.html but I have no coding knowledge to make it work right.

about the position of the window on screen, this is what i did and how the window look like:

View attachment 292388

256 x 240

View attachment 292389

512 x 480

View attachment 292390

768 x 720 (default build, that's why it looks centered)

View attachment 292391

My questions then are, if possible, can somebody help me with the draggable code to make it work, or some workaround and also help me understand why the window isn't centered and how can I make that happen?

EDIT: forgot to mention I've tried SRD game upgrade plugin, but it crashed the game completely due being outdated. So, not much of an option 🙁

Thanks in advance! 😀
Open up your index.html with Notepad or VSCode and type this below the </body> and above the </html>:

Code:
<div style="left:0px;width:100%;height:5%;position:absolute;-webkit-app-region:drag;">
</div>

That should make it so that 100% of the width of your screen and only the upper 5% of the height of the screen is click-draggable. Do be careful with this because if you have movement, menu items, or other interactive things in that area - you will not be able to click there.

Is there a reason why you are not using F3/F4 to use full screen and fill?
Open up your index.html with Notepad or VSCode and type this below the </body> and above the </html>:

Code:
<div style="left:0px;width:100%;height:5%;position:absolute;-webkit-app-region:drag;">
</div>

That should make it so that 100% of the width of your screen and only the upper 5% of the height of the screen is click-draggable. Do be careful with this because if you have movement, menu items, or other interactive things in that area - you will not be able to click there.

Is there a reason why you are not using F3/F4 to use full screen and fill?

Oh thank you very much! I tested it and it works perfectly! \o/ thanks for the quick response and solution 😀

funny thing, Bing Copilot gave me a similar line of code when I was researching and I didn't knew the right line to paste, so I tried inside <head></head> and <body></body> lol.

Just one question about the fullscreen, when mouse hover the midsection the cusrsor is changed to default, I guess bc it's reading as the draggable section?

here some screenshots of how it's behaving in fullscreen mode:

2024-01-20 12-33-16.mkv_snapshot_00.03.491.jpg


When I'm out that vertical section the cursor is back to normal:

2024-01-20 12-33-16.mkv_snapshot_00.03.910.jpg


about the full screen, I am using this option as well, I just don't want to force only FS mode. Also trying to achieve something close to an emulator experience. The F3 stretch don't resize the window content when the window size is changed, so I end up with scrollbar on the right and the bottom.
Oh thank you very much! I tested it and it works perfectly! \o/ thanks for the quick response and solution 😀

funny thing, Bing Copilot gave me a similar line of code when I was researching and I didn't knew the right line to paste, so I tried inside <head></head> and <body></body> lol.

Just one question about the fullscreen, when mouse hover the midsection the cusrsor is changed to default, I guess bc it's reading as the draggable section?

here some screenshots of how it's behaving in fullscreen mode:

View attachment 292415

When I'm out that vertical section the cursor is back to normal:

View attachment 292416

about the full screen, I am using this option as well, I just don't want to force only FS mode. Also trying to achieve something close to an emulator experience. The F3 stretch don't resize the window content when the window size is changed, so I end up with scrollbar on the right and the bottom.
If you need it to resize with F3, you will have to set "resizable" to true in package.json. I am sure there is a way to make it resizable only when full screen with the Graphics command but I haven't looked into it.

The cursor change may be because it is interacting when certain elements on in your game or inside the window. If it was the dragable area, that area should have been limited to only the top bar where the title frame should have been unless some of the values were changed or some other element is there.

You might be able to set it to something else permanently when your game is loaded, which does mean that it won't change to other things until you make the change.

In your main.js inside onload() and below the Scene_Boot, type in
JavaScript:
document.body.style.cursor = "pointer"

That will change it to the pointer cursor only. You can check out other cursors available.

Style Cursors
If you need it to resize with F3, you will have to set "resizable" to true in package.json. I am sure there is a way to make it resizable only when full screen with the Graphics command but I haven't looked into it.

The cursor change may be because it is interacting when certain elements on in your game or inside the window. If it was the dragable area, that area should have been limited to only the top bar where the title frame should have been unless some of the values were changed or some other element is there.

You might be able to set it to something else permanently when your game is loaded, which does mean that it won't change to other things until you make the change.

In your main.js inside onload() and below the Scene_Boot, type in
JavaScript:
document.body.style.cursor = "pointer"

That will change it to the pointer cursor only. You can check out other cursors available.

Style Cursors

Thank you for the help!

I'm using a custom cursor plugin, so the pointer option,won't work, BUT if there is a way to disable the line of code you sent when in fullscreen mode, that would do the trick.

I am trying to make it, but again I don't know how to make the proper syntax:

HTML:
<div style="left:0px;width:100%;height:5%;position:absolute;-webkit-app-region:drag;"></div>
<div style="left:0px;width:0%;height:0%;position:absolute;onwebkitfullscreenchange=" if (document.webkitFullscreenElement) {this.style.webkitAppRegion = 'no-drag';}"></div>

oh btw I activate the resizable option on the manifest. No reason to limit that option haha

sorry for the trouble, but you think its possible to make an exception on your code line when app is fullscreen?

EDIT: I forgot to mention that there is no cursor change in windowed mode when i hover on that horizontal section, only when i hover on the draggable section of your code, which is totally fine.
I said vertical on the previous post, but the behavior is exactly the same of the 5% height, 100% width top draggable region you created but on the middle of the screen. And when I hover the mouse on the top of the screen there is no cursor change.

some screenshots:

windowed - draggable area show normal cursor pointer, all good

2024-01-20 13-56-46.mkv_snapshot_00.05.987.jpg


outside draggable area, the custom game cursor is displayed, all good. I moved it closer to this red collider just so u can compare with the fullscren position

2024-01-20 13-58-40.mkv_snapshot_00.03.238.jpg



Fullscreen - the pointer isn't shown in the top draggabble area anymore

2024-01-20 13-57-49.mkv_snapshot_00.09.856.jpg


instead all across this horizintal narrow section it is shown the standard windows cursor, which looks like to be the draggable area displaced to the middle of the screen

2024-01-20 13-58-40.mkv_snapshot_00.16.667.jpg



This just happens in full screen mode
Are you asking about when it is full screen? The window should not be draggable in fullscreen mode.
It could be that the canvas is stretched as well. Maybe in the height of the div, put something like 24px instead of a percentage. Also, are you still using that other div underneath? It may be overwriting stuff as well.

For the stretching, you might be able to try this as a separate plugin to overwrite what is in the corescript (I haven't tested it since i am not by a computer at the moment):

Edit: try this instead:
JavaScript:
Graphics._onKeyDown = function(event) {
    if (!event.ctrlKey && !event.altKey) {
        switch (event.keyCode) {
        case 113:   // F2
            event.preventDefault();
            this._switchFPSMeter();
            break;
        case 114:   // F3
            event.preventDefault();
            // Here is the edit to the corescript - only allows stretching in full screen mode
            if (!this._isFullScreen()) this._switchStretchMode();
            break;
        case 115:   // F4
            event.preventDefault();
            this._switchFullScreen();
            break;
        }
    }
};
Are you asking about when it is full screen? The window should not be draggable in fullscreen mode.

For the stretching, you might be able to try this as a separate plugin to overwrite what is in the corescript (I haven't tested it since i am not by a computer st the moment):
JavaScript:
Graphics._switchStretchMode = function() {
    if (this._isFullScreen()) {
        this._stretchEnabled = !this._stretchEnabled;
        this._updateAllElements();
    } else this._stretchEnabled = false;
};

Awesome, I will test the stretch code as soon as I have the chance, thank you very much!

and yes, in fullscreen mode even tho its not possible to move the screen around (which is supposed) it looks like the draggable area is still present changing the cursor when hover. In my previous post I added some screenshots of the cursor behavior in detail.

Thank you for the help!

I'm using a custom cursor plugin, so the pointer option,won't work, BUT if there is a way to disable the line of code you sent when in fullscreen mode, that would do the trick.

I am trying to make it, but again I don't know how to make the proper syntax:

HTML:
<div style="left:0px;width:100%;height:5%;position:absolute;-webkit-app-region:drag;"></div>
<div style="left:0px;width:0%;height:0%;position:absolute;onwebkitfullscreenchange=" if (document.webkitFullscreenElement) {this.style.webkitAppRegion = 'no-drag';}"></div>

oh btw I activate the resizable option on the manifest. No reason to limit that option haha

sorry for the trouble, but you think its possible to make an exception on your code line when app is fullscreen?

EDIT: I forgot to mention that there is no cursor change in windowed mode when i hover on that horizontal section, only when i hover on the draggable section of your code, which is totally fine.
I said vertical on the previous post, but the behavior is exactly the same of the 5% height, 100% width top draggable region you created but on the middle of the screen. And when I hover the mouse on the top of the screen there is no cursor change.

some screenshots:

windowed - draggable area show normal cursor pointer, all good

View attachment 292420

outside draggable area, the custom game cursor is displayed, all good. I moved it closer to this red collider just so u can compare with the fullscren position

View attachment 292421


Fullscreen - the pointer isn't shown in the top draggabble area anymore

View attachment 292422

instead all across this horizintal narrow section it is shown the standard windows cursor, which looks like to be the draggable area displaced to the middle of the screen

View attachment 292423


This just happens in full screen mode


that's why I asked for a line to disable the draggable region when full screen mode, so that don't interfere with the cursor. in any way. 🙂 If it's not much trouble ofc. Thank you so much for the help and patience!
Awesome, I will test the stretch code as soon as I have the chance, thank you very much!

and yes, in fullscreen mode even tho its not possible to move the screen around (which is supposed) it looks like the draggable area is still present changing the cursor when hover. In my previous post I added some screenshots of the cursor behavior in detail.




that's why I asked for a line to disable the draggable region when full screen mode, so that don't interfere with the cursor. in any way. 🙂 If it's not much trouble ofc. Thank you so much for the help and patience!
I think I understand now - the cursor is being affected, not whether it is draggable or not. Unfortunately, my cursor stays the same whether I drag or not and doesn't change whether it is full screen or not so I'll have to look into it.
I think I understand now - the cursor is being affected, not whether it is draggable or not. Unfortunately, my cursor stays the same whether I drag or not and doesn't change whether it is full screen or not so I'll have to look into it.
Exactly, I said it looks like it's the draggable area being moved from top to the middle of the screen because there are no other elements whatsoever that interact with the mouse cursor. In fact the cursor only began to change to default after I added your code line inside index.html to create the draggable region on top, and it only changes to default when I hover the region on windowed mode, like "showing" that this region is different from the game canvas.

however when I switch to full screen, the behavior is the same but instead of having the cursor change on the top of the screen like when in windowed mode, it it happening in the mid section of the screen. I think that, since it's unecessary to drag the window when in fullscreen, if there was a way to disable the div draggable region when in full screen mode, it would also not affect the cursor as a positive collateral effect. Thant would solve the issue 100%! hopefully its possible somehow.

EDIT: SOLVED

I changed the position attribute to "relative" in the code line @bass2yang sent, like this:

HTML:
<div style="left:0px;width:100%;height:5%;position:relative;-webkit-app-region:drag;">
</div>

No more cursor change on fullscreen mode, and the draggable area still works on windowed mode 😀

Thank you very much @bass2yang !! i'll definitely mention you in the credits of my game 😀
Exactly, I said it looks like it's the draggable area being moved from top to the middle of the screen because there are no other elements whatsoever that interact with the mouse cursor. In fact the cursor only began to change to default after I added your code line inside index.html to create the draggable region on top, and it only changes to default when I hover the region on windowed mode, like "showing" that this region is different from the game canvas.

however when I switch to full screen, the behavior is the same but instead of having the cursor change on the top of the screen like when in windowed mode, it it happening in the mid section of the screen. I think that, since it's unecessary to drag the window when in fullscreen, if there was a way to disable the div draggable region when in full screen mode, it would also not affect the cursor as a positive collateral effect. Thant would solve the issue 100%! hopefully its possible somehow.

EDIT: SOLVED

I changed the position attribute to "top" in the code line @bass2yang sent, like this:

HTML:
<div style="left:0px;width:100%;height:5%;position:top;-webkit-app-region:drag;">
</div>

No more cursor change on fullscreen mode, and the draggable area still works on windowed mode 😀

Thank you very much @bass2yang !! i'll definitely mention you in the credits of my game 😀
Awesome! I was looking at different things you could do in the toggle f3 and f4 keys, but if this works, keep it.

You should be able to use other attributes such as left, right, etc. as well if needed.
It worked better than I expected thanks to you! I’ll play with this to see if I can learn more and modify for the other borders as well 🙂

I tested the script for the stretch and it worked too

Again, thank you very much!

Original thread: https://forums.rpgmakerweb.com/threads/draggable-borderless-game-window-and-center-position-in-the-js-manifest-help.164949/