Bug fix #144: Workaround for insane window type changes

Dynamically detect window type as a workaround to insane applications.
Thanks to Feltzer for reporting. (#144)