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.35k stars 3.88k forks source link

[Feature request] Add ability to drag frameless window like soon to be deprecated webkit-app-region #6462

Open Yonezpt opened 6 years ago

Yonezpt commented 6 years ago

Following up on the recent deprecation news of webkit-app-region linked in #6201 I would like request for NWJS to implement its own method of dragging a frameless window (or frame window even) with the same behavior as the soon to be deprecated webkit-app-region, but without the bug reported in the linked issue.

The lack of this feature will make frameless windows completely useless if they are not used in fullscreen mode only (kiosk mode), seeing that current window move javascript based solutions are broken, which means that there will be absolutely no way to drag windows across different screens, use Windows' snap edge functionality and any other behaviors tied to moving a window via the dedicate taskbar.

razor-4eg commented 6 years ago

And in addition to that ability to draw window control buttons on top HTML, like Electron did.

sadikyalcin commented 5 years ago

Bump. What can we do @rogerwang with this mate? I know it's a chromium issue which they are looking of removing as well, it will be a nice to have. It works fine with macos at the moment but need to force a re-paint on windows for it to work.

shaynem commented 5 years ago

+1 just came across this as needing to update to the latest nwjs version due to some linux bug.

leegrey commented 2 years ago

I know this was posted in 2018, and for all I know there's a more official way to do this by now, but you can make a draggable frameless window by doing something like this:

var nwWin = nw.Window.get();

var isDragging = false;
var dragOrigin = {x:0, y:0};

document.onmousedown = (e) => {
    isDragging = true;
    dragOrigin.x = e.x;
    dragOrigin.y = e.y;
}

document.mouseleave = (_) => isDragging = false;
document.onmouseup = (_) => isDragging = false;

document.onmousemove = (e) => {
    if (isDragging) {
        nwWin.moveTo(e.screenX - dragOrigin.x, e.screenY - dragOrigin.y);
    }
}

This is for a widget style application so the entire window is draggable, but you can just set the onmousedown to be your "drag bar" element instead, to limit the area.