getWindowPos() not updating continuously

I want to make an application that displays objects relative to the screen and not the program window. This way they have an absolute position and your window is kind of your view to it. Aka, if you move your window the particles don’t move with it.

To achieve this I use getWindowPos() as anchor point. But I noticed it is only updated after the window is moved, while the app itself keeps updating.

I use the following code to capture when the window moves:
getWindow()->getSignalMove().connect( std::bind( &SoundParticlesApp::windowMove, this ) );
Even if I poll getWindowPos() in draw(), it is only updated when the window stops moving.

I made a short video showing the result. The app creates a log every time windowMove is triggered.
Notice how the app keeps updating while I drag it, but the getWindowPos is only updated when it stops moving (this causes the jumps).

So:

  • is it possible to trigger an update of the window position?
  • if not, is there another way to track your position relative to the entire screen?

Cheers!

You might find these links useful:

https://developer.apple.com/reference/appkit/nswindowdidmovenotification

1 Like