Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Emit event when window moves

This thread is locked; no one can reply to it. rss feed Print
Emit event when window moves
urskogshumla
Member #16,942
January 2019
avatar

Hi!

I could only find an event for when the window is resized, not when it is moved around the screen so I thought, why not emit an event for it since there is a hook (at least for the XDisplay on linux) already in use for the resize event.

I simply duplicated the event creation code for the resize event, changed the condition and added a new event to the enum. Code style wise, I pledge guilty. It aint beautiful. But it's the most logical way I can see to handle this.

Would you do different? Poll and check this at user level every frame instead?

My diff: https://pastebin.com/UHZvbXXN

EDIT: There is also no way to tell which display that the event is relevant for. Since we can create a number of windows (around 20 per allegro application on my machine) there should be some way to identify which display that generated the event. Or, if multiple displays is not a feature we support fully, maybe that should be more clear OR even restricted by the API or something? Just some thoughts, for myself I'll just patch in some integer identifier system or similar.

EDIT 2: Found the al_get_x_window_id(dpy) function, that might be sufficient.

EDIT 3: And I guess I can just compare the two ALLEGRO_DISPLAY pointers (event.display.source and my stored pointer from display creation)? Because they should point to the same memory right?

Hugs,
Ivan

Elias
Member #358
May 2000

Sounds useful to me!

And yes, the "source" field of the event will be the display it came from for all display events.

The only small concern I have is wether we should create those events in response to al_set_window_position or not - we do have some code there to prevent resize events when the user calls al_resize_display. I don't know why. But resizing is a bit more complex because of al_acknowledge_resize.

Just for consistency we might want to do the same for move events, but not really sure. Myself I can't see a possible use case for detecting when a window moves in a game so hard to know what would make sense with events for al_set_window_position.

--
"Either help out or stop whining" - Evert

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

dthompson
Member #5,749
April 2005
avatar

Hey, I know at least one other person with a use case for this.

{"name":"611909","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/0\/80a90af231375e976c9cbca32646e734.jpg","w":1920,"h":1083,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/0\/80a90af231375e976c9cbca32646e734"}611909

______________________________________________________
Website. It was freakdesign.bafsoft.net.
This isn't a game!

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

playing with anime pr0n does not count ;D

To be more helpful, the patch looks good. I could probably do something similar on Windows.

EDIT
This may not be so easy on Windows. WM_ENTERSIZEMOVE triggers a modal loop in DefWindowProc that doesn't exit until WM_EXITSIZEMOVE is called. This means you could move the window around the screen, and you wouldn't get a move message until you let go of the mouse if I understand correctly.

EDIT2
WM_MOVING might work.

Go to: