Quick way to get screen cordinates for a window

Andy Maskell's icon

Is there a quick way to get the screen coordinates for a window that is open in Max runtime?

I have an interface window open in my standalone application (it contains a bpatcher that displays various interface patchers) that is NOT the top-level patcher. I currently open it in a fixed location on the left hand screen of three, so it has a negative x coordinate.

If the window is moved, is there a way that I can find out where it has been moved to by reading the window size parameters somehow?

Andy Maskell's icon

I can see that I can get window position and size info from @11olsen's [11globalForegroundWindow] but then in this case I would need to know that the window in question has become the forground window!

Any ideas how I could detect that?

11OLSEN's icon

Hello Andy, window questions are my thing ;-) You should only use 11gFW if there's no other option left, like knowing which other app is in the foreground. One idea is to use a 'notitle' window and make it dragable with jsui. This way you can get a bang when the drag ends and check the new position.
Another option is to build a little window observer in js which is basically the same as constantly banging a 'window getsize' message to [thispatcher] with a [qmetro]. So I don't like it. Last but not least I can only offer you again to test another external beta that closes a lot of gaps of Max's patcher window management.

Andy Maskell's icon

Thanks @11Olsen. I came up with this in the end:

The initial window position is set by RstCtl. When the window is active and in its dragable state, the qmetro keeps tabs on where the window is. When the window is switched into its non-dragable state or is in the background, the metro is turned off and the last location retained for when it is reactivated.

Andy Maskell's icon

I presumed that there must be a way to do this with [thispatcher] but I completely missed the bit at the bottom of the reference page discussing the (window getsize) message!