问题描述:

I have two top-level windows, win1 and win2.

I want to make win2 follow win1 when win1 is moved so that the position of win2 relative to win1 (I'll call that relpos) stays constant. IOW, sticky windows!

My idea was to move win2 in the ConfigureNotify of win1. To do that I need to know the relpos.

I can get (and store) relpos in win2's ConfigureNotify when win2 is moved.

The problem is that win2 gets ConfigureNotify both when moved by the user and when moved programmatically. Is there a way to distinguish between the two cases?

If there isn't, the whole approach is a fail, and so the next question is: is there another way?

Thanks.

NOTE: I can't just set a "moving_programmatically" flag, move the window and then check the flag on ConfigureNotify because X is asynchronous (one of its biggest warts - many consider this a feature) and there's no guarantee when and how many ConfigureNotify events I get. Try doing this and move win1 too fast and see how win2 lags behind.

网友答案:

I think you'll have to write a window manager for this. The reason for your trouble is that you can't get the "click on win1 title" and "released mouse button over win1" events - the window manager swallows them before your app can see them. With these events, the solution is simple: Get the relative offset when the user clicks on the title bar of win1 and just use this offset while win1 is moved.

Other applications (like LibreOffice) solve this by allowing to drag such windows into the main window (main window grows and child window becomes a palette at the side).

相关阅读:
Top