Permalink
Browse files

Made DPMS timeout configureable

  • Loading branch information...
1 parent f5a3c44 commit cd4fdd6f3e74bdf269bee3e63e6942570a4ee120 @skinner33 committed Jan 6, 2012
Showing with 18 additions and 7 deletions.
  1. +5 −3 src/Hlockx.hs
  2. +13 −4 src/Main.hs
View
8 src/Hlockx.hs
@@ -8,15 +8,17 @@ import XUtils
import Control.Monad (unless)
+import Foreign.C.Types (CUInt)
+
import Graphics.X11.Types
import Graphics.X11.Xlib
import Graphics.X11.Xlib.Extras
import System.Environment
-hlockx :: Bool -> IO ()
-hlockx slock = do
+hlockx :: Bool -> CUInt -> IO ()
+hlockx slock timeout = do
progName <- getProgName
pw <- getPasswordHash
@@ -33,7 +35,7 @@ hlockx slock = do
-- check if DPMS was enabled before enabling it
(standby, suspend, off, wasEnabled) <- getCurrentDPMSStatus dpy
_ <- dPMSEnable dpy
- _ <- dPMSSetTimeouts dpy 0 0 2
+ _ <- dPMSSetTimeouts dpy 0 0 timeout
if slock then
eventLoop dpy pw processInputSLock
View
17 src/Main.hs
@@ -8,19 +8,24 @@ import Hlockx
import Paths_hlockx (version)
import Data.Version (showVersion)
+import Foreign.C.Types (CUInt)
+
import System.Environment
import System.Exit
import System.IO
import System.Console.GetOpt
-data Options = Options { optSLock :: Bool }
+data Options = Options { optSLock :: Bool
+ , optTimeout :: CUInt }
startOptions :: Options
#ifdef DEF_SLOCK
-startOptions = Options { optSLock = True }
+startOptions = Options { optSLock = True
#else
-startOptions = Options { optSLock = False }
+startOptions = Options { optSLock = False
#endif
+ , optTimeout = 2
+ }
options :: [ OptDescr (Options -> IO Options) ]
options =
@@ -38,6 +43,10 @@ options =
hPutStrLn stderr (usageInfo prg options)
exitWith ExitSuccess))
"Show help"
+ , Option "t" ["timeout"]
+ (ReqArg
+ (\arg opt -> return opt { optTimeout = read arg }) "Seconds")
+ "Set DPMS timeout (default: 2s)"
, Option "s" ["slock"]
(NoArg
(\opt -> return opt { optSLock = True }))
@@ -62,4 +71,4 @@ main = do
-- Parse options, getting a list of option actions
let (actions, _, _) = getOpt RequireOrder options args
opts <- foldl (>>=) (return startOptions) actions
- hlockx (optSLock opts)
+ hlockx (optSLock opts) (optTimeout opts)

0 comments on commit cd4fdd6

Please sign in to comment.