c++x11window-managersmotif

XWindow not listening to its own attributes/ window manager


Problem: I have a java window controlled by XWindows in a Window Manager C++ file on a Linux system. There is a bug somewhere, if you open the HCI roughly between 7-35 times consecutively (and quickly) typically at least one time the window is opened at its default location (0,0) rather than the location I set (430, 300). After a failure if I close the HCI and reopen it, it is opened at the correct location, just as it would before the bug. The attributes are initially set with XMoveResizeWindow.

I have added a loop to check the location of the HCI (via XTranslateAttributes and XGetWindowAttributes), and compare the X and Y to the set location, and to reset the attributes if they don't match.

However when I print the attributes it shows (430, 300) even when the window has actually opened at (0,0).

Specific Question: Is this a bug with XWindows? does it make sense for the attributes to read one thing, but for it not to match the actual location(i.e. maybe these attributes are suggestions, not demands)? is there a different method that may return a more accurate location of the HCI?

Update: I have tried changing the loop to just move the location 15 times in a row via XMoveWindow. It seems to have fixed it (not done testing yet). But surely there must be a better way than through brute force.


Solution

  • You need to wait to ensure the window is actually realized before trying to alter its position, etc. Try adding an event handler that masks for SubstructureRedirectMask and call XMoveResizeWindow in the event handler when the event type is XMapRequestEvent.