taffybar-4.0.1: A desktop bar similar to xmobar, but with more GUI

Copyright | (c) Ivan A. Malison
License | BSD3-style (see LICENSE)
Maintainer | Ivan A. Malison
Stability | unstable
Portability | unportable
Safe Haskell | Safe-Inferred
Language | Haskell2010

System.Taffybar.Information.Battery

Description

This module provides functions for querying battery information using the UPower dbus, as well as a BroadcastChan system for allowing multiple readers to receive `BatteryState` updates without duplicating requests.

Synopsis

- data BatteryInfo = BatteryInfo {
  - batteryNativePath :: String
  - batteryVendor :: String
  - batteryModel :: String
  - batterySerial :: String
  - batteryUpdateTime :: Word64
  - batteryType :: BatteryType
  - batteryPowerSupply :: Bool
  - batteryHasHistory :: Bool
  - batteryHasStatistics :: Bool
  - batteryOnline :: Bool
  - batteryEnergy :: Double
  - batteryEnergyEmpty :: Double
  - batteryEnergyFull :: Double
  - batteryEnergyFullDesign :: Double
  - batteryEnergyRate :: Double
  - batteryVoltage :: Double
  - batteryLuminosity :: Double
  - batteryTimeToEmpty :: Int64
  - batteryTimeToFull :: Int64
  - batteryPercentage :: Double
  - batteryTemperature :: Double
  - batteryIsPresent :: Bool
  - batteryState :: BatteryState
  - batteryIsRechargeable :: Bool
  - batteryCapacity :: Double
  - batteryTechnology :: BatteryTechnology
  - batteryWarningLevel :: Word32
  - batteryBatteryLevel :: Word32
  - batteryIconName :: String
  }
- data BatteryState
  - = BatteryStateUnknown
  - | BatteryStateCharging
  - | BatteryStateDischarging
  - | BatteryStateEmpty
  - | BatteryStateFullyCharged
  - | BatteryStatePendingCharge
  - | BatteryStatePendingDischarge
- data BatteryTechnology
  - = BatteryTechnologyUnknown
  - | BatteryTechnologyLithiumIon
  - | BatteryTechnologyLithiumPolymer
  - | BatteryTechnologyLithiumIronPhosphate
  - | BatteryTechnologyLeadAcid
  - | BatteryTechnologyNickelCadmium
  - | BatteryTechnologyNickelMetalHydride
- data BatteryType
  - = BatteryTypeUnknown
  - | BatteryTypeLinePower
  - | BatteryTypeBatteryType
  - | BatteryTypeUps
  - | BatteryTypeMonitor
  - | BatteryTypeMouse
  - | BatteryTypeKeyboard
  - | BatteryTypePda
  - | BatteryTypePhone
- newtype DisplayBatteryChanVar = DisplayBatteryChanVar (BroadcastChan In BatteryInfo, MVar BatteryInfo)
- refreshBatteriesOnPropChange :: TaffyIO ()
- batteryLogPath :: String
- dummyMethodError :: MethodError
- batteryLog :: MonadIO m => Priority -> String -> m ()
- batteryLogF :: (MonadIO m, Show t) => Priority -> String -> t -> m ()
- batteryPrefix :: String
- isBattery :: ObjectPath -> Bool
- readDict :: IsVariant a => Map Text Variant -> Text -> a -> a
- readDictIntegral :: Map Text Variant -> Text -> Int32 -> Int
- getBatteryInfo :: ObjectPath -> TaffyIO (Either MethodError BatteryInfo)
- infoMapToBatteryInfo :: Map Text Variant -> BatteryInfo
- getBatteryPaths :: TaffyIO (Either MethodError [ObjectPath])
- getDisplayBatteryInfo :: TaffyIO BatteryInfo
- getDisplayBatteryChanVar :: TaffyIO DisplayBatteryChanVar
- defaultMonitorDisplayBatteryProperties :: [String]
- setupDisplayBatteryChanVar :: [String] -> TaffyIO DisplayBatteryChanVar
- monitorDisplayBattery :: [String] -> TaffyIO (BroadcastChan In BatteryInfo, MVar BatteryInfo)
- getDisplayBatteryChan :: TaffyIO (BroadcastChan In BatteryInfo)
- updateBatteryInfo :: BroadcastChan In BatteryInfo -> MVar BatteryInfo -> ObjectPath -> TaffyIO ()
- registerForAnyUPowerPropertiesChanged :: (Signal -> String -> Map String Variant -> [String] -> IO ()) -> ReaderT Context IO SignalHandler
- registerForUPowerPropertyChanges :: [String] -> (Signal -> String -> Map String Variant -> [String] -> IO ()) -> ReaderT Context IO SignalHandler
- refreshAllBatteries :: TaffyIO ()

# Documentation

data BatteryInfo Source #

Constructors

BatteryInfo |

Fields

- batteryNativePath :: String
- batteryVendor :: String
- batteryModel :: String
- batterySerial :: String
- batteryUpdateTime :: Word64
- batteryType :: BatteryType
- batteryPowerSupply :: Bool
- batteryHasHistory :: Bool
- batteryHasStatistics :: Bool
- batteryOnline :: Bool
- batteryEnergy :: Double
- batteryEnergyEmpty :: Double
- batteryEnergyFull :: Double
- batteryEnergyFullDesign :: Double
- batteryEnergyRate :: Double
- batteryVoltage :: Double
- batteryLuminosity :: Double
- batteryTimeToEmpty :: Int64
- batteryTimeToFull :: Int64
- batteryPercentage :: Double
- batteryTemperature :: Double
- batteryIsPresent :: Bool
- batteryState :: BatteryState
- batteryIsRechargeable :: Bool
- batteryCapacity :: Double
- batteryTechnology :: BatteryTechnology
- batteryWarningLevel :: Word32
- batteryBatteryLevel :: Word32
- batteryIconName :: String

#### Instances

Instances details

Show BatteryInfo Source # |
Instance details Defined in System.Taffybar.DBus.Client.UPowerDevice Methods showsPrec :: Int -> BatteryInfo -> ShowS Source # show :: BatteryInfo -> String Source # showList :: [BatteryInfo] -> ShowS Source #
Eq BatteryInfo Source # |
Instance details Defined in System.Taffybar.DBus.Client.UPowerDevice Methods (==) :: BatteryInfo -> BatteryInfo -> Bool Source # (/=) :: BatteryInfo -> BatteryInfo -> Bool Source #

data BatteryState Source #

Constructors

BatteryStateUnknown |
BatteryStateCharging |
BatteryStateDischarging |
BatteryStateEmpty |
BatteryStateFullyCharged |
BatteryStatePendingCharge |
BatteryStatePendingDischarge |

#### Instances

Instances details

Enum BatteryState Source # |

Instance details

Defined in System.Taffybar.DBus.Client.Params

Methods

succ :: BatteryState -> BatteryState Source #

pred :: BatteryState -> BatteryState Source #

toEnum :: Int -> BatteryState Source #

fromEnum :: BatteryState -> Int Source #

enumFrom :: BatteryState -> [BatteryState] Source #

enumFromThen :: BatteryState -> BatteryState -> [BatteryState] Source #

enumFromTo :: BatteryState -> BatteryState -> [BatteryState] Source #

enumFromThenTo :: BatteryState -> BatteryState -> BatteryState -> [BatteryState] Source #

Show BatteryState Source # |
Instance details Defined in System.Taffybar.DBus.Client.Params Methods showsPrec :: Int -> BatteryState -> ShowS Source # show :: BatteryState -> String Source # showList :: [BatteryState] -> ShowS Source #
Eq BatteryState Source # |
Instance details Defined in System.Taffybar.DBus.Client.Params Methods (==) :: BatteryState -> BatteryState -> Bool Source # (/=) :: BatteryState -> BatteryState -> Bool Source #
Ord BatteryState Source # |

Instance details

Defined in System.Taffybar.DBus.Client.Params

Methods

compare :: BatteryState -> BatteryState -> Ordering Source #

(<) :: BatteryState -> BatteryState -> Bool Source #

(<=) :: BatteryState -> BatteryState -> Bool Source #

(>) :: BatteryState -> BatteryState -> Bool Source #

(>=) :: BatteryState -> BatteryState -> Bool Source #

max :: BatteryState -> BatteryState -> BatteryState Source #

min :: BatteryState -> BatteryState -> BatteryState Source #

data BatteryTechnology Source #

Constructors

BatteryTechnologyUnknown |
BatteryTechnologyLithiumIon |
BatteryTechnologyLithiumPolymer |
BatteryTechnologyLithiumIronPhosphate |
BatteryTechnologyLeadAcid |
BatteryTechnologyNickelCadmium |
BatteryTechnologyNickelMetalHydride |

#### Instances

Instances details

Enum BatteryTechnology Source # |

Instance details

Defined in System.Taffybar.DBus.Client.Params

Methods

succ :: BatteryTechnology -> BatteryTechnology Source #

pred :: BatteryTechnology -> BatteryTechnology Source #

toEnum :: Int -> BatteryTechnology Source #

fromEnum :: BatteryTechnology -> Int Source #

enumFrom :: BatteryTechnology -> [BatteryTechnology] Source #

enumFromThen :: BatteryTechnology -> BatteryTechnology -> [BatteryTechnology] Source #

enumFromTo :: BatteryTechnology -> BatteryTechnology -> [BatteryTechnology] Source #

enumFromThenTo :: BatteryTechnology -> BatteryTechnology -> BatteryTechnology -> [BatteryTechnology] Source #

Show BatteryTechnology Source # |
Instance details Defined in System.Taffybar.DBus.Client.Params Methods showsPrec :: Int -> BatteryTechnology -> ShowS Source # show :: BatteryTechnology -> String Source # showList :: [BatteryTechnology] -> ShowS Source #
Eq BatteryTechnology Source # |
Instance details Defined in System.Taffybar.DBus.Client.Params Methods (==) :: BatteryTechnology -> BatteryTechnology -> Bool Source # (/=) :: BatteryTechnology -> BatteryTechnology -> Bool Source #
Ord BatteryTechnology Source # |

Instance details

Defined in System.Taffybar.DBus.Client.Params

Methods

compare :: BatteryTechnology -> BatteryTechnology -> Ordering Source #

(<) :: BatteryTechnology -> BatteryTechnology -> Bool Source #

(<=) :: BatteryTechnology -> BatteryTechnology -> Bool Source #

(>) :: BatteryTechnology -> BatteryTechnology -> Bool Source #

(>=) :: BatteryTechnology -> BatteryTechnology -> Bool Source #

max :: BatteryTechnology -> BatteryTechnology -> BatteryTechnology Source #

min :: BatteryTechnology -> BatteryTechnology -> BatteryTechnology Source #

data BatteryType Source #

Constructors

BatteryTypeUnknown |
BatteryTypeLinePower |
BatteryTypeBatteryType |
BatteryTypeUps |
BatteryTypeMonitor |
BatteryTypeMouse |
BatteryTypeKeyboard |
BatteryTypePda |
BatteryTypePhone |

#### Instances

Instances details

Enum BatteryType Source # |

Instance details

Defined in System.Taffybar.DBus.Client.Params

Methods

succ :: BatteryType -> BatteryType Source #

pred :: BatteryType -> BatteryType Source #

toEnum :: Int -> BatteryType Source #

fromEnum :: BatteryType -> Int Source #

enumFrom :: BatteryType -> [BatteryType] Source #

enumFromThen :: BatteryType -> BatteryType -> [BatteryType] Source #

enumFromTo :: BatteryType -> BatteryType -> [BatteryType] Source #

enumFromThenTo :: BatteryType -> BatteryType -> BatteryType -> [BatteryType] Source #

Show BatteryType Source # |
Instance details Defined in System.Taffybar.DBus.Client.Params Methods showsPrec :: Int -> BatteryType -> ShowS Source # show :: BatteryType -> String Source # showList :: [BatteryType] -> ShowS Source #
Eq BatteryType Source # |
Instance details Defined in System.Taffybar.DBus.Client.Params Methods (==) :: BatteryType -> BatteryType -> Bool Source # (/=) :: BatteryType -> BatteryType -> Bool Source #
Ord BatteryType Source # |

Instance details

Defined in System.Taffybar.DBus.Client.Params

Methods

compare :: BatteryType -> BatteryType -> Ordering Source #

(<) :: BatteryType -> BatteryType -> Bool Source #

(<=) :: BatteryType -> BatteryType -> Bool Source #

(>) :: BatteryType -> BatteryType -> Bool Source #

(>=) :: BatteryType -> BatteryType -> Bool Source #

max :: BatteryType -> BatteryType -> BatteryType Source #

min :: BatteryType -> BatteryType -> BatteryType Source #

newtype DisplayBatteryChanVar Source #

Constructors

DisplayBatteryChanVar (BroadcastChan In BatteryInfo, MVar BatteryInfo) |

refreshBatteriesOnPropChange :: TaffyIO () Source #

Call "refreshAllBatteries" whenever the BatteryInfo for the DisplayDevice is updated. This handles cases where there is a race between the signal that something is updated and the update actually being visible. See https://github.com/taffybar/taffybar/issues/330 for more details.

batteryLogPath :: String Source #

dummyMethodError :: MethodError Source #

batteryLog :: MonadIO m => Priority -> String -> m () Source #

batteryLogF :: (MonadIO m, Show t) => Priority -> String -> t -> m () Source #

batteryPrefix :: String Source #

The prefix of name of battery devices path. UPower generates the object path as "battery" + "_" + basename of the sysfs object.

isBattery :: ObjectPath -> Bool Source #

Determine if a power source is a battery.

readDict :: IsVariant a => Map Text Variant -> Text -> a -> a Source #

A helper to read the variant contents of a dict with a default value.

readDictIntegral :: Map Text Variant -> Text -> Int32 -> Int Source #

Read the variant contents of a dict which is of an unknown integral type.

getBatteryInfo :: ObjectPath -> TaffyIO (Either MethodError BatteryInfo) Source #

Query the UPower daemon about information on a specific battery. If some fields are not actually present, they may have bogus values here. Don't bet anything critical on it.

infoMapToBatteryInfo :: Map Text Variant -> BatteryInfo Source #

getBatteryPaths :: TaffyIO (Either MethodError [ObjectPath]) Source #

getDisplayBatteryInfo :: TaffyIO BatteryInfo Source #

getDisplayBatteryChanVar :: TaffyIO DisplayBatteryChanVar Source #

defaultMonitorDisplayBatteryProperties :: [String] Source #

setupDisplayBatteryChanVar :: [String] -> TaffyIO DisplayBatteryChanVar Source #

Start the monitoring of the display battery, and setup the associated channel and mvar for the current state.

monitorDisplayBattery :: [String] -> TaffyIO (BroadcastChan In BatteryInfo, MVar BatteryInfo) Source #

Monitor the DisplayDevice for changes, writing a new BatteryInfo object to returned MVar and Chan objects

getDisplayBatteryChan :: TaffyIO (BroadcastChan In BatteryInfo) Source #

updateBatteryInfo :: BroadcastChan In BatteryInfo -> MVar BatteryInfo -> ObjectPath -> TaffyIO () Source #

registerForAnyUPowerPropertiesChanged :: (Signal -> String -> Map String Variant -> [String] -> IO ()) -> ReaderT Context IO SignalHandler Source #

registerForUPowerPropertyChanges :: [String] -> (Signal -> String -> Map String Variant -> [String] -> IO ()) -> ReaderT Context IO SignalHandler Source #

refreshAllBatteries :: TaffyIO () Source #

Request a refresh of all UPower batteries. This is only needed if UPower's refresh mechanism is not working properly.