Window moves itself to account for frame on linux MATE desktop?


I’ve been working on having my app remember it’s window position and restore that position when it runs next time. I’ve finally got it all sorted but discovered something strange about window positioning on linux. When I set the bounds of the window, my window “move” event listener is triggered twice; for example:

1487632152309 window_moved { x: 568, y: 341, width: 568, height: 360 }
1487632152321 window_moved { x: 571, y: 367, width: 568, height: 360 }

The first time the bounds of the window are what I set it to, but then some milliseconds later the window moves itself to slightly different position. The difference is roughly what I guess the size of the window frame is. It seems like Electron is assuming I was trying to set the position in relation to the top, left corner of the window content (which I didn’t, I set the window bounds, which surely includes the frame?) and it’s making an adjustment for me.

Has anyone else experienced this, either on linux or other systems?

I worked around it by using a boolean flag to track whether changes are caused by the user or programmatically. If the latter, then I compensate for the auto adjust by setting the bounds, then reading the bounds to see if they equal what I set them to, if not equal then I calculate the difference between the desired position and the actual position, setting the position to the desired minus the difference to get what I actually wanted.


After a bit more debugging, it seems all of the window functions for position, size and bounds do refer to the window content, not the frame.

However, when you set the position or bounds something is moving the window so that the position you give ends up being the corner of the frame, not the content. Is this an inconsistency bug in Electron?


This automatic overriding of your window position also forces the entire window to be on one physical screen. If I place the window over a boundary of two monitors, close the app, then run the app again it tried to restore itself to that position but Electron won’t let it, even though in linux both monitors are configured as one overall screen.

I can understand the need to help prevent users from losing their window off screen, but I think Electron’s window management is a bit over zealous and prevents legitimate positions on a multi-display setup.