/*Detect idle time and blank screen (sivann@sofltab.ece.ntua.gr sioan@mykonos.esd.ece.ntua.gr)*/ # include # include # include # include # include # include # include # define TTYPATH "/dev" main (argc,argv) int argc; char *argv[]; { char device[20]; struct stat stats,stats_mouse,stats_kbd; time_t access_time,idle_time; time_t current_time; time_t kbd_access,kbd_idle; char tty[20]; int i,ip,fd; if (argc!=3) { fprintf(stderr,"Screen saver, Spiros Ioannou 1995\n"); fprintf(stderr,"Usage: %s [tty] [delay]\n",argv[0]); exit(2); } if((fd = open("/dev/fb", O_RDWR)) == -1) { fprintf(stderr, "Cant open device\n"); exit(1); } strcpy(tty,argv[1]); for (;;) { current_time = time ((time_t *)0); sprintf (device, "%s/%s", TTYPATH, tty); if (lstat (device, &stats) == -1 || (stats.st_mode & S_IFMT) == S_IFLNK) access_time=time(NULL); else access_time = stats.st_atime; idle_time=current_time - access_time; if (lstat ("/dev/kbd", &stats_kbd) == -1 || (stats_kbd.st_mode & S_IFMT) == S_IFLNK) kbd_access=time(NULL); else kbd_access = stats_kbd.st_atime; kbd_idle=current_time - kbd_access; if(idle_time>atol(argv[2])) i=0; else i=1; if (ip!=i)ioctl(fd, FBIOSVIDEO, &i); ip=i; /* printf("Idle Terminal :%d sec\n",idle_time ); printf("Idle Keyboard or Mouse devices:%d sec\n",kbd_idle); */ sleep(1); } }