From 87e15e8f3d6b687bc256712b5f5cbcd2bb3bcd75 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sun, 5 Apr 2015 13:42:04 +0900 Subject: start trying to detect idle user under X11 Can't make it build yet --- README.md | 4 ++++ cbits/a.out | Bin 0 -> 5884 bytes cbits/getidletime_posix.c | 32 ++++++++++++++++++++++++++++++++ src/Utility/IdleUser/X11.hs | 12 ++++++++++++ srem.cabal | 9 +++++++++ 5 files changed, 57 insertions(+) create mode 100755 cbits/a.out create mode 100644 cbits/getidletime_posix.c create mode 100644 src/Utility/IdleUser/X11.hs diff --git a/README.md b/README.md index 5d70b6e..c983605 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,10 @@ TODO TODO +Debian packages required: libxss-dev + +Or maybe: nix-env -iA nixos.pkgs.xlibs.libXScrnSaver + ## Installation TODO diff --git a/cbits/a.out b/cbits/a.out new file mode 100755 index 0000000..0fef3f8 Binary files /dev/null and b/cbits/a.out differ diff --git a/cbits/getidletime_posix.c b/cbits/getidletime_posix.c new file mode 100644 index 0000000..95eb062 --- /dev/null +++ b/cbits/getidletime_posix.c @@ -0,0 +1,32 @@ +#include +#include + +/* Based on getIdleTime.c by falconindy on ArchLinux BBS thread ID + 121863. This function connects to the display in the DISPLAY + environment variable and returns the idle time. So the Haskell + code is responsible for determining and setting DISPLAY if + e.g. running from cron. */ + +int GetXIdleTime () +{ + Display *dpy = XOpenDisplay(NULL); + + if (!dpy) + { + return(-1); + } + + XScreenSaverInfo *info = XScreenSaverAllocInfo(); + XScreenSaverQueryInfo(dpy, DefaultRootWindow(dpy), info); + + return (info->idle); +} + +/* int main (void) +{ + int idletime; + + idletime = GetXIdleTime(); + printf("%u", idletime); + return 0; +} */ diff --git a/src/Utility/IdleUser/X11.hs b/src/Utility/IdleUser/X11.hs new file mode 100644 index 0000000..acdeb9e --- /dev/null +++ b/src/Utility/IdleUser/X11.hs @@ -0,0 +1,12 @@ +{-# LANGUAGE ForeignFunctionInterface #-} + +module Utility.IdleUser.X11 (userIdleTime) where + +import Foreign +import Foreign.C.Types + +foreign import ccall unsafe "GetXIdleTime" + getXIdleTime :: CUInt + +userIdleTime :: Int +userIdleTime = undefined diff --git a/srem.cabal b/srem.cabal index e4c3b89..88b98c8 100644 --- a/srem.cabal +++ b/srem.cabal @@ -10,6 +10,10 @@ category: Text build-type: Simple cabal-version: >=1.10 +extra-source-files: cbits +-- extra-include-dirs: /usr/include +-- extra-lib-dirs: /usr/lib/i386-linux-gnu + executable srem main-is: Main.hs build-depends: base @@ -26,3 +30,8 @@ executable srem , dbus hs-source-dirs: src default-language: Haskell2010 + + -- TODO conditional on building on GNU/Linux + c-sources: cbits/getIdleTime_posix.c + extra-libraries: Xss + includes: X11/extensions/scrnsaver.h -- cgit v1.2.3