The xeyes program is a simple demo of how to follow the mouse cursor. This is from the modular X.org X11 project.