简体   繁体   English

X11:如何使窗口一个接一个地移动?

[英]X11: how to make a window move after another?

I have two top-level windows, win1 and win2. 我有两个顶级窗口,即win1和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. 我想使win1移动时使win2跟在win1之后,以便win2相对于win1的位置(我称之为relpos )保持恒定。 IOW, sticky windows! 哎呀,窗户很粘!

My idea was to move win2 in the ConfigureNotify of win1. 我的想法是在win1的ConfigureNotify中移动win2。 To do that I need to know the relpos . 为此,我需要了解相关relpos

I can get (and store) relpos in win2's ConfigureNotify when win2 is moved. 当移动win2时,我可以在win2的ConfigureNotify中获得(并存储)relpos。

The problem is that win2 gets ConfigureNotify both when moved by the user and when moved programmatically. 问题在于,在用户移动和以编程方式移动时,win2都会获取ConfigureNotify。 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. 注意:我不能只设置“ moving_programmatically”标志,移动窗口,然后检查ConfigureNotify上的标志,因为X是异步的(其最大的缺点之一-许多人将此功能视为功能),并且不能保证何时以及有多少ConfigureNotify我得到的事件。 Try doing this and move win1 too fast and see how win2 lags behind. 尝试这样做,将win1移得太快,看看win2如何落后。

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. 麻烦的原因是,您无法获得“单击win1标题”和“在win1上释放鼠标按钮”事件-窗口管理器会在应用程序看到它们之前将其吞下。 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. 对于这些事件,解决方案很简单:当用户单击win1的标题栏时获取相对偏移,而在win1移动时仅使用此偏移。

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). 其他应用程序(例如LibreOffice)通过允许将这样的窗口拖到主窗口中来解决此问题(主窗口增大,子窗口变成侧面的调色板)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM