Browse files

Added license (BSD), changed sleep time to a 1/10 of a second, clarif…

…ied some

points in the README, added an example usage to the README.
  • Loading branch information...
1 parent c4ace10 commit 0d72ce0c5a54d7e4263a35ee32b75c72593635bd Jared Candelaria committed Oct 22, 2011
Showing with 32 additions and 5 deletions.
  1. +10 −3 README
  2. +22 −2 idler.c
View
13 README
@@ -1,12 +1,19 @@
This program will patiently wait until you've stopped moving before executing another program.
-Its command line options include:
+Its command line options are:
-h Prints out how to use the program
-t timeout Tell the program how long to wait before considering you idle (in seconds)
-The code is pretty readable. I used OpenBSD's sudo(8)'s idea for checking for a valid file. I'm sure
-there are thousands of programs like these but I wanted something small to act like a screen saver launcher.
+The default timeout is 10 minutes. You MUST provide a program to run. A typical invocation would
+look like: -t 300 slock
+
+To build, link against X11 and Xss (XScreenSaver) with -lX11 -lXss.
+
+The code is pretty readable. I used OpenBSD's sudo(8)'s idea for checking for a valid program. I'm sure
+there are thousands of programs like this but I wanted something small to act like a screen saver launcher.
I also wanted to write it in Haskell but such is life.
You can have this program run a script that will set your irssi status, then lock the screen, then unset your
status if you want. Or do anything that relies on idle times, which makes sense.
+
+If you want it to stop running, you must manually kill it.
View
24 idler.c
@@ -1,3 +1,19 @@
+/*
+ * Copyright (c) 2011, Jared Candelaria (jcande @ github)
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
@@ -36,6 +52,7 @@ xmalloc(size_t s)
return p;
}
+/* XXX Doesn't check if it's executable. */
int
proper_file(const char *file)
{
@@ -44,7 +61,7 @@ proper_file(const char *file)
if (stat(file, &f))
return 0;
- return (S_ISREG(f.st_mode)); /* && (f.st_mode & 0000111)); */
+ return (S_ISREG(f.st_mode));
}
/* Taken from OpenBSD's sudo(8). */
@@ -93,6 +110,8 @@ launch(char *file, char **command)
err(1, NULL);
case 0:
execvp(file, command);
+ /* We shouldn't ever reach here. */
+ err(1, NULL);
default:
wait(NULL);
}
@@ -149,7 +168,8 @@ main(int argc, char **argv)
saved_timeout = info->idle;
launch(argv[0], argv);
} else
- usleep(1000);
+ /* Sleep for .1 second. Maybe use sleep(3) instead? */
+ usleep(100000);
/* Make sure we only run once per idle period. */
if (info->idle < saved_timeout)

0 comments on commit 0d72ce0

Please sign in to comment.