Permalink
Browse files

Add x11-misc/idletime

  • Loading branch information...
1 parent 10aa339 commit 7719d2b6b12f7d352afc8d6c32444e2154cb1094 @Godin committed Aug 6, 2012
Showing with 63 additions and 0 deletions.
  1. +30 −0 x11-misc/idletime/files/idletime.c
  2. +33 −0 x11-misc/idletime/idletime-0.ebuild
View
30 x11-misc/idletime/files/idletime.c
@@ -0,0 +1,30 @@
+// http://stackoverflow.com/questions/222606/detecting-keyboard-mouse-activity-in-linux
+// Compilation: gcc -o idletime -L/usr/X11R6/lib/ -lX11 -lXext -lXss idletime.c
+
+#include <time.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/extensions/scrnsaver.h>
+
+int GetIdleTime () {
+ time_t idle_time;
+ static XScreenSaverInfo *mit_info;
+ Display *display;
+ int screen;
+ mit_info = XScreenSaverAllocInfo();
+ if ((display=XOpenDisplay(NULL)) == NULL) {
+ return(-1);
+ }
+ screen = DefaultScreen(display);
+ XScreenSaverQueryInfo(display, RootWindow(display,screen), mit_info);
+ idle_time = (mit_info->idle) / 1000;
+ XFree(mit_info);
+ XCloseDisplay(display);
+ return idle_time;
+}
+
+int main() {
+ printf("%d\n", GetIdleTime());
+}
View
33 x11-misc/idletime/idletime-0.ebuild
@@ -0,0 +1,33 @@
+EAPI=4
+inherit eutils toolchain-funcs
+
+DESCRIPTION=""
+HOMEPAGE=""
+SRC_URI=""
+
+LICENSE=""
+SLOT="0"
+KEYWORDS="~amd64 ~x86"
+IUSE=""
+
+DEPEND="
+ x11-libs/libX11
+ x11-libs/libXScrnSaver
+ "
+RDEPEND="${DEPEND}"
+
+S=${WORKDIR}
+
+src_prepare() {
+ cp "${FILESDIR}/idletime.c" "${WORKDIR}"
+}
+
+src_compile() {
+ local my_compile="$(tc-getCC) ${CFLAGS} ${LDFLAGS} -o ${PN}{,.c} -lX11 -lXext -lXss"
+ echo ${my_compile}
+ eval ${my_compile} || die
+}
+
+src_install() {
+ dobin ${PN}
+}

0 comments on commit 7719d2b

Please sign in to comment.