diff options
-rw-r--r-- | README.md | 4 | ||||
-rwxr-xr-x | cbits/a.out | bin | 0 -> 5884 bytes | |||
-rw-r--r-- | cbits/getidletime_posix.c | 32 | ||||
-rw-r--r-- | src/Utility/IdleUser/X11.hs | 12 | ||||
-rw-r--r-- | srem.cabal | 9 |
5 files changed, 57 insertions, 0 deletions
@@ -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 Binary files differnew file mode 100755 index 0000000..0fef3f8 --- /dev/null +++ b/cbits/a.out 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 <stdio.h> +#include <X11/extensions/scrnsaver.h> + +/* 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 @@ -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 |