I'd like to be able to execute a command when switching to specific applications. In particular, I'd like to able to change the xmodmap when switching to the Terminal and then change it again when switching away (e.g. to firefox).
I figure that it may be possible to detect when an application comes to the foreground, and then run xmodmap?
How would I do this (esp. on Ubuntu 19.04, X11)?
Some things I've discovered:
There is a visibilityNotify event which the X server can produce. Not sure how to utilise this and whether it does what I want?
"xdotool search --class Terminal behave %@ focus getwindowpid" notifies on focus change, which is great. However, getactivewindow causes a segmentation fault, so I cannot actually get the window id for use with xwininfo or similar. Any ideas along those lines?