rtfm / Xterm
Xterm (and other terminal emulators) can often be controlled, (moved around, (de)iconified, retitled, etc) by the application running in them, by way of emitting certain arcane escape sequences.
In this section you will find a (partially) htmlised version of the control sequence documentation that comes with xterm, and, when I get around to adding them, bits and pieces of code which actually let you use said sequences. (Reading back responses from those sequences that trigger them is tricky - you have to get your termios magic exactly right...)
WEIRDNESS: It does not seem to matter which of the stdin, stdout or stderr filehandles you use for this, as long as the filehandle in question is connected to your terminal emulator. This means you can do bizarre things like writing to stdin from within the application itself to control the terminal emulator - this is arguably bizarre, and it is probably preferable to open /dev/tty from within your program and use that instead.
IMPLEMENTATION: Not all emulators implement all (or even many) of these sequences. In particular, sequences ending in the ST string (\x1b\x5c) are often unrecognised: stock rxvt (as of 2.6.4) doesn't recognise at least some of these, and stock gnome-terminal (in fact, anything relying on libzvt as of 184.108.40.206) actually just hangs if fed an ST terminated sequence. The latest debian libzvt2 (220.127.116.11-9) has been patched to fix this, and the patch has been provisionally accepted by the gnome team. (The patch also covers the dtterm sequences mentioned below).
Additionally, libzvt doesn't implement dtterm escape sequence handling at all. Again, the latest debian version (18.104.22.168-9) has been patched to implement almost all of these (except CSI 11 t (coming soon) and CSI 9 Ps t (can't be arsed :))
It's been a long time since the last update: Anyhow, there's now a shell script that can generate (and read responses to) various escape sequences. There are some bashisms in the functions, so you probably do need bash to run it - I haven't tested it in any other shells in any case.