Sorry, my last patch had a misplaced `#if' block at xterm.h, that I only noticed after trying to build emacs with gtk. I've attached an updated version here.