xlib: keep track of modifiers and generate events on focus

This is required to prevent stuck keys if modifiers are pressed while
unfocusing.  This should theoretically be ensured by the responsible
window manager, but many do not handle this.
xlib: ensure motion ID and flags are set properly
Update Makefile to link test app as a library
Update test