ENH generalize desktop and power
This commit is contained in:
parent
315f3a8f24
commit
4b06ee125b
|
@ -46,9 +46,9 @@ import RIO
|
||||||
import RIO.FilePath
|
import RIO.FilePath
|
||||||
import qualified RIO.Process as P
|
import qualified RIO.Process as P
|
||||||
import qualified RIO.Text as T
|
import qualified RIO.Text as T
|
||||||
import System.Environment
|
|
||||||
import System.Posix.User
|
import System.Posix.User
|
||||||
import UnliftIO.Directory
|
import UnliftIO.Directory
|
||||||
|
import UnliftIO.Environment
|
||||||
import XMonad.Actions.Volume
|
import XMonad.Actions.Volume
|
||||||
import XMonad.Core hiding (spawn)
|
import XMonad.Core hiding (spawn)
|
||||||
import XMonad.Internal.DBus.Common
|
import XMonad.Internal.DBus.Common
|
||||||
|
@ -334,7 +334,7 @@ runRecompile = do
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- Screen capture commands
|
-- Screen capture commands
|
||||||
|
|
||||||
getCaptureDir :: IO FilePath
|
getCaptureDir :: MonadIO m => m FilePath
|
||||||
getCaptureDir = do
|
getCaptureDir = do
|
||||||
e <- lookupEnv "XDG_DATA_HOME"
|
e <- lookupEnv "XDG_DATA_HOME"
|
||||||
parent <- case e of
|
parent <- case e of
|
||||||
|
|
|
@ -26,15 +26,13 @@ module XMonad.Internal.Command.Power
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
import Data.Either
|
|
||||||
import Data.Internal.Dependency
|
import Data.Internal.Dependency
|
||||||
import qualified Data.Map as M
|
|
||||||
import Graphics.X11.Types
|
import Graphics.X11.Types
|
||||||
import RIO
|
import RIO
|
||||||
import RIO.FilePath
|
import RIO.FilePath
|
||||||
|
import qualified RIO.Map as M
|
||||||
import qualified RIO.Process as P
|
import qualified RIO.Process as P
|
||||||
import qualified RIO.Text as T
|
import qualified RIO.Text as T
|
||||||
import System.IO.Error
|
|
||||||
import UnliftIO.Directory
|
import UnliftIO.Directory
|
||||||
import XMonad.Core hiding (spawn)
|
import XMonad.Core hiding (spawn)
|
||||||
import XMonad.Internal.Shell
|
import XMonad.Internal.Shell
|
||||||
|
@ -129,16 +127,19 @@ runQuitPrompt = sometimesPrompt "quit prompt" quitPrompt
|
||||||
-- TODO for some reason the screen never wakes up after suspend when
|
-- TODO for some reason the screen never wakes up after suspend when
|
||||||
-- the nvidia card is up, so block suspend if nvidia card is running
|
-- the nvidia card is up, so block suspend if nvidia card is running
|
||||||
-- and warn user
|
-- and warn user
|
||||||
isUsingNvidia :: IO Bool
|
isUsingNvidia :: MonadUnliftIO m => m Bool
|
||||||
isUsingNvidia = doesDirectoryExist "/sys/module/nvidia"
|
isUsingNvidia = doesDirectoryExist "/sys/module/nvidia"
|
||||||
|
|
||||||
hasBattery :: IO (Maybe T.Text)
|
hasBattery :: MonadUnliftIO m => m (Maybe T.Text)
|
||||||
hasBattery = do
|
hasBattery = do
|
||||||
ps <- fromRight [] <$> tryIOError (listDirectory syspath)
|
ps <- fromRight [] <$> tryIO (listDirectory syspath)
|
||||||
ts <- mapM readType ps
|
ts <- catMaybes <$> mapM readType ps
|
||||||
return $ if "Battery\n" `elem` ts then Nothing else Just "battery not found"
|
return $
|
||||||
|
if any (T.isPrefixOf "Battery") ts
|
||||||
|
then Nothing
|
||||||
|
else Just "battery not found"
|
||||||
where
|
where
|
||||||
readType p = fromRight [] <$> tryIOError (readFile $ syspath </> p </> "type")
|
readType p = either (const Nothing) Just <$> tryIO (readFileUtf8 $ syspath </> p </> "type")
|
||||||
syspath = "/sys/class/power_supply"
|
syspath = "/sys/class/power_supply"
|
||||||
|
|
||||||
runOptimusPrompt' :: XT.FontBuilder -> X ()
|
runOptimusPrompt' :: XT.FontBuilder -> X ()
|
||||||
|
|
Loading…
Reference in New Issue