startDrag for windows

I want to be able to move a window around without having a title bar. Is this possible with lime or openfl? If I naively have a listener on mouse move update the position it doesn’t work right because of course the positions I get from mouse move are relative to the window.

class Main extends Sprite
    var mouseDown:Bool = false;

    public function new()

        stage.window.onMouseDown.add(function(_, _, mouseButton) {
            if (mouseButton == MouseButton.LEFT) mouseDown = true;

        stage.window.onMouseUp.add(function(_, _, mouseButton) {
            if (mouseButton == MouseButton.LEFT)  mouseDown = false;

        stage.window.onMouseMove.add(function(_x:Float, _y:Float) {
            if (mouseDown) {
                stage.window.move( + _x), + _y));
                // stage.window.move(,;

Hi, never player with that yet but can’t you just store mouse x and y and use the difference ?

Store lastMouseX and lastMouseY on mouseDown then on mouseMove xMove = mouseX-lastMouseX, same for y and store lastMouseX/Y again.

onMouseMoveRelative already gives you the difference between the last time (I believe). But the problem is nothing to my knowledge gives you the coordinates with respect to the window manager, yet window.move() is based on those same absolute coordinates.

It was a dumb mistake, I was using the sprite’s x instead of the window’s. This works:

    stage.addEventListener(MouseEvent.MOUSE_DOWN, function(event:MouseEvent) {
        startClickX = event.localX;
        startClickY = event.localY;
        trace('startClick: $startClickX,$startClickY');

    stage.addEventListener(MouseEvent.MOUSE_MOVE, function(event:MouseEvent) {
        if (event.buttonDown) {
            stage.window.move(stage.window.x + - startClickX), stage.window.y + - startClickY));
1 Like