xscreensaver will lauch your program based on the configuration file /usr/lib/X11/app-defaults/XScreenSaver. Most screensavers have a command line option to switch between full screen and window. When user input occurs, xscreensaver will shut down your program. So, you don't need to do any weird things, just concentrate on the graphics.