Open popup at mouse cursor

I have a template with a button in it that is used to launch a popup.

  1. I would like to open the popup at the mouse cursor, but am struggling to get the mouse coordinates relative to the parent window.

  2. The other thing I might want to do instead of using the mouse coordinates, is to use the coordinates of the button itself, relative to the client, so that I can display the popup slightly to the left/right of the template object itself to still keep it visible. In this case, how would I get the coordinates of the button component, relative to the client?

I’m sure I should know how to do this…

Cheers

Edit: I’ve gotten a little further.

def setRelativeLocation(event, window, compRelX, compRelY):
	windowX = window.getX()
	windowY = window.getY()
	
	screenRelX, screenRelY = system.gui.convertPointToScreen(compRelX, compRelY, event)

	window.setLocation(screenRelX, screenRelY)

#Called on button mouseReleased event
win = system.nav.openWindowInstance('Popups/ppuSAW_Valve', {'DeviceName': event.source.parent.DeviceName})
setRelativeLocation(event, win, event.x, event.y)

This opens the popup almost in the correct location if the client window is in the top left of the screen. Correct x (although it may be off by a few pixels due to the width of the client window border) but the y is wrong as the coordinates are relative to the main window and not the whole client window which includes the main window and a docked header window. How can I get the coordinates relative to the whole client window as a whole? I don’t want to have to hardcode this, or look for open windows and get their heights, etc. as I would also like to accommodate for other events that may change the client size such as:

  • staging mode header
  • updates available header
  • other docked windows that may be opened and closed for alerts similar to the updates available header

If the client window is windowed (not fullscreen) and the client is moved around the screen, the popup opens in completely the wrong positions as it opens the popup relative to if the client window was in the top left of the monitor.
How do I get the component’s coordinates relative to the actual client window?