aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2015-04-05 13:42:04 +0900
committerSean Whitton <spwhitton@spwhitton.name>2015-04-05 13:42:04 +0900
commit87e15e8f3d6b687bc256712b5f5cbcd2bb3bcd75 (patch)
treedc545991d626576750e815b9cc7a84a198541102
parent330a4f9562f9e71ebf680451b8ed78790b103f30 (diff)
downloadsrem-idleuser.tar.gz
start trying to detect idle user under X11idleuser
Can't make it build yet
-rw-r--r--README.md4
-rwxr-xr-xcbits/a.outbin0 -> 5884 bytes
-rw-r--r--cbits/getidletime_posix.c32
-rw-r--r--src/Utility/IdleUser/X11.hs12
-rw-r--r--srem.cabal9
5 files changed, 57 insertions, 0 deletions
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
--- /dev/null
+++ b/cbits/a.out
Binary files 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 <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
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