Xorg timeout and wakeup events

There is a lot of code in the video drivers and it is not trivial for
me to find the screen saver mechanism.

What I mean is there is a timeout period after which the screen turns
blank. I have a touch-screen and touching it restores the display as
it should. What I want to do is to add a keypad (that generates /dev/
input/event1) events as a second source of wake-up events. Must be
trivial. Could anyone please enlighten me how this mechanism works?
Also how to change the idle time? Didn't find anything in the /sys
filesystem. Probably didn't look hard enough.