* Enno Gottox Boland <[EMAIL PROTECTED]> [Dec 28 2007 21:23] wrote: > Very nice idea. But there are some things I want to note: > > ... && argv[i+1]) > very bad idea to test for argv[i+1]. Use "i+1 < argc" instead yeah, thats right
> while (seconds_idle(d) < wait) > usleep(500000); > > Polling is unneeded here. What do you think about this: > > while (seconds_idle(d) < wait) > sleep(wait - seconds_idle(d)); > > (maybe you can store seconds_idle(d) in a var to avoid unneeded Xserver > polling) This is also a good idea, thank you for that > Hmm... I dislike this for-loop. It's unneeded, isn't it :) Why do you dislike the for-loop? > Nevertheless a very good idea, I like it. I attached an patched version of sinac. greetz didi -- No documentation is better than bad documentation
/*****************************************************************************
*
* xidletime
*
* derived from xautolock supplied by
* Authors: Michel Eyckmans (MCE) & Stefan De Troch (SDT)
*
* --------------------------------------------------------------------------
*
* Copyright 1990,1992-1999,2001-2002 by Stefan De Troch and Michel Eyckmans.
* Copyright 2005 by Stefan Siegl <[EMAIL PROTECTED]>
* Copyright 2007 by Christian Dietrich <[EMAIL PROTECTED]>
*
* Versions 2.0 and above of xautolock are available under version 2 of the
* GNU GPL.
*
*****************************************************************************/
#include <X11/Xos.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/Xresource.h>
#include <X11/extensions/scrnsaver.h>
#include <stdio.h>
#define VERSION "0.1.1"
static XScreenSaverInfo* xss_info = 0;
int
seconds_idle(Display *d)
{
if (! xss_info )
xss_info = XScreenSaverAllocInfo();
XScreenSaverQueryInfo(d, DefaultRootWindow(d), xss_info);
return xss_info->idle / 1000;
}
int
main (int argc, char* argv[])
{
Display* d;
Time idleTime;
if (!(d = XOpenDisplay (0))) {
fprintf (stderr, "Couldn't connect to %s\n", XDisplayName (0));
return 1;
}
(void) XSync (d, 0);
if (argc == 1)
fprintf(stdout, "%ld\n", seconds_idle(d));
int i;
for (i = 1; i < argc; i++) {
if ((strcmp(argv[i], "-w") == 0) && (i+1 < argc)) {
int wait = atoi(argv[++i]), idle;
while ((idle = seconds_idle(d)) < wait)
usleep(wait - idle);
}
else if (strcmp(argv[i], "-p") == 0)
fprintf(stdout, "%ld\n", seconds_idle(d));
else {
fprintf(stderr, "sinac - " VERSION ": %s [-w <seconds>] [-p]\n",
argv[0]);
return 1;
}
}
return 0;
}
pgpYy5YVK0Wpb.pgp
Description: PGP signature
