ENH generalize desktop and power

This commit is contained in:
Nathan Dwarshuis 2022-12-31 19:16:44 -05:00
parent 315f3a8f24
commit 4b06ee125b
2 changed files with 12 additions and 11 deletions

View File

@ -46,9 +46,9 @@ import RIO
import RIO.FilePath
import qualified RIO.Process as P
import qualified RIO.Text as T
import System.Environment
import System.Posix.User
import UnliftIO.Directory
import UnliftIO.Environment
import XMonad.Actions.Volume
import XMonad.Core hiding (spawn)
import XMonad.Internal.DBus.Common
@ -334,7 +334,7 @@ runRecompile = do
--------------------------------------------------------------------------------
-- Screen capture commands
getCaptureDir :: IO FilePath
getCaptureDir :: MonadIO m => m FilePath
getCaptureDir = do
e <- lookupEnv "XDG_DATA_HOME"
parent <- case e of

View File

@ -26,15 +26,13 @@ module XMonad.Internal.Command.Power
)
where
import Data.Either
import Data.Internal.Dependency
import qualified Data.Map as M
import Graphics.X11.Types
import RIO
import RIO.FilePath
import qualified RIO.Map as M
import qualified RIO.Process as P
import qualified RIO.Text as T
import System.IO.Error
import UnliftIO.Directory
import XMonad.Core hiding (spawn)
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
-- the nvidia card is up, so block suspend if nvidia card is running
-- and warn user
isUsingNvidia :: IO Bool
isUsingNvidia :: MonadUnliftIO m => m Bool
isUsingNvidia = doesDirectoryExist "/sys/module/nvidia"
hasBattery :: IO (Maybe T.Text)
hasBattery :: MonadUnliftIO m => m (Maybe T.Text)
hasBattery = do
ps <- fromRight [] <$> tryIOError (listDirectory syspath)
ts <- mapM readType ps
return $ if "Battery\n" `elem` ts then Nothing else Just "battery not found"
ps <- fromRight [] <$> tryIO (listDirectory syspath)
ts <- catMaybes <$> mapM readType ps
return $
if any (T.isPrefixOf "Battery") ts
then Nothing
else Just "battery not found"
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"
runOptimusPrompt' :: XT.FontBuilder -> X ()