canonical / etrace

Utility for tracing execution of apps
GNU General Public License v3.0
57 stars 12 forks source link

Look into using xdo instead of xdotool #58

Open anonymouse64 opened 3 years ago

anonymouse64 commented 3 years ago

xdotool is unmaintained and doesn't work with XWayland on Wayland as per @bboozzoo

Suggestion was to investigate xdo instead: https://github.com/baskerville/xdo

anonymouse64 commented 3 years ago

FWIW this sort of loop seems to work most reliably:

xdo id -m -N "Antstream Arcade" # wait for the a client with the window opts to appear
# loop waiting for the id to no longer be inspectable, trying to close the window repeatedly
while xdo id -N "Antstream Arcade" > /dev/null; do 
    xdo close -N "Antstream Arcade"
done

We need to do this because there isn't really a command which blocks until the window is painted/mapped in xdo as it stands, at which point we then would grab a time measurement and close the window. xdo kill -m ... just kills the client immediately before anything is drawn or painted which skews the measurement to be smaller than it should be in reality, while xdo close ... simply submits a "close request" or some sort of thing which can be sent successfully so xdo returns exit code 0 but the application can be in a state where that close request does nothing and is effectively ignored. So we need to keep sending the close request until the window stops appearing in which case we know it showed up and was closed.

@bboozzoo mentioned there may be a better way if we patched xdo to have a call to xcb_get_geometry() that we could use (or maybe we could just do the call directly from etrace via cgo) but needs some investigation

anonymouse64 commented 3 years ago

The option mapping between xdotool (where etrace currently derives it's own options names from) and xdo is essentially as follows I think:

xdotool xdo
--classname -N
--name -a
--class ???

--class vs --classname in xdotool is a bit of a mystery to me still so it's unclear if -N is sufficient or not for both cases