ENH add dependency tests for acpi
This commit is contained in:
parent
7981533664
commit
4d79caffe2
|
@ -18,7 +18,8 @@ import Data.Connection
|
||||||
|
|
||||||
import Text.Read (readMaybe)
|
import Text.Read (readMaybe)
|
||||||
|
|
||||||
import System.IO.Streams.Internal as S (read)
|
import System.Directory (doesPathExist)
|
||||||
|
import System.IO.Streams as S (read)
|
||||||
import System.IO.Streams.UnixSocket
|
import System.IO.Streams.UnixSocket
|
||||||
|
|
||||||
import XMonad.Core
|
import XMonad.Core
|
||||||
|
@ -76,6 +77,18 @@ isDischarging = do
|
||||||
Left _ -> return Nothing
|
Left _ -> return Nothing
|
||||||
Right s -> return $ Just (s == "Discharging")
|
Right s -> return $ Just (s == "Discharging")
|
||||||
|
|
||||||
|
listenACPI :: IO ()
|
||||||
|
listenACPI = do
|
||||||
|
Connection { source = s } <- connect acpiPath
|
||||||
|
forever $ readStream s
|
||||||
|
where
|
||||||
|
readStream s = do
|
||||||
|
out <- S.read s
|
||||||
|
mapM_ sendACPIEvent $ parseLine =<< out
|
||||||
|
|
||||||
|
acpiPath :: FilePath
|
||||||
|
acpiPath = "/var/run/acpid.socket"
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- | Exported API
|
-- | Exported API
|
||||||
|
|
||||||
|
@ -83,13 +96,9 @@ isDischarging = do
|
||||||
-- and send ClientMessage events when it receives them
|
-- and send ClientMessage events when it receives them
|
||||||
runPowermon :: IO ()
|
runPowermon :: IO ()
|
||||||
runPowermon = do
|
runPowermon = do
|
||||||
-- TODO barf when the socket doesn't exist
|
e <- doesPathExist acpiPath
|
||||||
Connection { source = s } <- connect "/var/run/acpid.socket"
|
if e then listenACPI else
|
||||||
forever $ readStream s
|
print ("WARNING: ACPI socket not found; disabling ACPI event management" :: String)
|
||||||
where
|
|
||||||
readStream s = do
|
|
||||||
out <- S.read s
|
|
||||||
mapM_ sendACPIEvent $ parseLine =<< out
|
|
||||||
|
|
||||||
-- | Handle ClientMessage event containing and ACPI event (to be used in
|
-- | Handle ClientMessage event containing and ACPI event (to be used in
|
||||||
-- Xmonad's event hook)
|
-- Xmonad's event hook)
|
||||||
|
@ -101,6 +110,7 @@ handleACPI tag = do
|
||||||
Sleep -> runSuspendPrompt
|
Sleep -> runSuspendPrompt
|
||||||
LidClose -> do
|
LidClose -> do
|
||||||
status <- io isDischarging
|
status <- io isDischarging
|
||||||
forM_ status $ \s -> do
|
-- only run suspend if battery exists and is discharging
|
||||||
|
forM_ status $ flip when runSuspend
|
||||||
io runScreenLock >>= whenInstalled
|
io runScreenLock >>= whenInstalled
|
||||||
when s runSuspend
|
|
||||||
|
|
Loading…
Reference in New Issue