baskerville / xdo

Small X utility to perform elementary actions on windows
BSD 2-Clause "Simplified" License
303 stars 18 forks source link

xdo SOMETIMES not doing what it's supposed to #15

Closed toshokan closed 7 years ago

toshokan commented 7 years ago

I recently noticed that xdo does not always do what it is told. I initially noticed this with the above and below actions, and then tried testing with the show and hide actions.

Sometimes the exact same command (ex xdo hide $id) has to be run many times (sometimes up to 10 times) before it takes effect. The return code is always the same, so it is hard to tell what causes this.

msteen commented 7 years ago

I noticed this problem with xdo as well. A few things I noticed when debugging this myself is that when I add a few more calls to xcb_flush(dpy), it will work more often. If I use xdo lower -a name it will lower the windows named name consistently (I have yet to see it fail), while xdo lower window_id will fail most of the time. If I use nanosleep for 10ms before xcb_disconnect(dpy) in finish it works consistently all the time. So I assume it has to do with either how XCB or the X server are working internally and xdo closing the connection to early. The manual says this about xcb_flush:

Forces any buffered output to be written to the server. Blocks until the write is complete.

So you would assume that the actions have been written safely to the X server after xcb_flush has been called. I am not experienced with XCB or the X server, so I unfortunately I have no idea how to properly fix this.

baskerville commented 7 years ago

I would seem that wmutils/core@dd268ecacc773aa6f767f8d3e6653b2a71f25c4e might be the answer.

msteen commented 7 years ago

Hah! Good timing, I was just about to say that as well, I am looking into it this very moment. I noticed it by looking at your examples, seeing wattr point to wmutils and indeed seeing them using xcb_aux_sync.

msteen commented 7 years ago

By using xcb_aux_sync my tests now work consistently all the time, so it seems indeed to be the proper fix.