2020-04-01 20:17:47 -04:00
|
|
|
module Main (main) where
|
|
|
|
|
2020-04-01 22:35:53 -04:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- | Xmobar binary
|
|
|
|
--
|
|
|
|
-- Features:
|
|
|
|
-- * Uses the 'UnsafeStdinReader' to receive the current workspace/layout config
|
|
|
|
-- from xmonad
|
|
|
|
-- * FontAwesome and Symbol fonts for icons
|
|
|
|
-- * Some custom plugins (imported below)
|
|
|
|
-- * Theme integration with xmonad (shared module imported below)
|
|
|
|
-- * A custom Locks plugin from my own forked repo
|
|
|
|
|
2022-07-09 17:44:14 -04:00
|
|
|
import Data.Internal.DBus
|
|
|
|
import Data.Internal.Dependency
|
2020-04-01 20:17:47 -04:00
|
|
|
import Data.List
|
2021-06-23 00:09:59 -04:00
|
|
|
import Data.Maybe
|
2020-04-01 20:17:47 -04:00
|
|
|
|
2021-06-23 00:38:23 -04:00
|
|
|
import System.Exit
|
2021-06-23 23:08:50 -04:00
|
|
|
import System.IO
|
2021-06-23 00:09:59 -04:00
|
|
|
import System.IO.Error
|
|
|
|
|
2020-03-25 18:55:52 -04:00
|
|
|
import Xmobar.Plugins.Bluetooth
|
2021-11-05 21:15:37 -04:00
|
|
|
import Xmobar.Plugins.ClevoKeyboard
|
2020-05-28 23:17:17 -04:00
|
|
|
import Xmobar.Plugins.Device
|
2020-03-25 18:55:52 -04:00
|
|
|
import Xmobar.Plugins.IntelBacklight
|
|
|
|
import Xmobar.Plugins.Screensaver
|
|
|
|
import Xmobar.Plugins.VPN
|
2020-03-15 15:10:25 -04:00
|
|
|
|
2022-07-02 18:22:26 -04:00
|
|
|
import System.Posix.Signals
|
2022-07-09 17:48:07 -04:00
|
|
|
import XMonad.Core hiding (config)
|
|
|
|
import XMonad.Hooks.DynamicLog hiding (xmobar)
|
2022-07-09 01:02:37 -04:00
|
|
|
import XMonad.Internal.Command.Desktop
|
|
|
|
import XMonad.Internal.Command.Power
|
2021-11-21 17:54:00 -05:00
|
|
|
import XMonad.Internal.DBus.Brightness.ClevoKeyboard
|
2021-11-09 00:59:17 -05:00
|
|
|
import XMonad.Internal.DBus.Brightness.IntelBacklight
|
2022-07-04 00:36:41 -04:00
|
|
|
import XMonad.Internal.DBus.Control
|
2021-11-20 19:35:24 -05:00
|
|
|
import XMonad.Internal.DBus.Screensaver (ssSignalDep)
|
2022-07-09 17:48:07 -04:00
|
|
|
import XMonad.Internal.Process hiding (CmdSpec)
|
2021-11-07 13:35:08 -05:00
|
|
|
import qualified XMonad.Internal.Theme as T
|
2022-07-04 00:36:41 -04:00
|
|
|
import Xmobar hiding
|
|
|
|
( iconOffset
|
|
|
|
)
|
2021-11-27 17:33:02 -05:00
|
|
|
import Xmobar.Plugins.Common
|
2020-03-15 13:12:01 -04:00
|
|
|
|
2021-06-23 23:08:50 -04:00
|
|
|
main :: IO ()
|
|
|
|
main = do
|
2022-07-04 00:36:41 -04:00
|
|
|
db <- connectDBus
|
2022-07-04 12:30:13 -04:00
|
|
|
c <- withCache $ evalConfig db
|
2022-07-04 00:36:41 -04:00
|
|
|
disconnectDBus db
|
2022-07-02 18:22:26 -04:00
|
|
|
-- this is needed to prevent waitForProcess error when forking in plugins (eg
|
|
|
|
-- alsacmd)
|
|
|
|
_ <- installHandler sigCHLD Default Nothing
|
2021-11-09 00:59:17 -05:00
|
|
|
-- this is needed to see any printed messages
|
|
|
|
hFlush stdout
|
2022-07-04 00:36:41 -04:00
|
|
|
xmobar c
|
|
|
|
|
2022-07-04 12:30:13 -04:00
|
|
|
evalConfig :: DBusState -> FIO Config
|
2022-07-04 00:36:41 -04:00
|
|
|
evalConfig db = do
|
2022-07-04 12:30:13 -04:00
|
|
|
cs <- getAllCommands <$> rightPlugins db
|
2022-07-04 00:36:41 -04:00
|
|
|
bf <- getTextFont
|
|
|
|
(ifs, ios) <- getIconFonts
|
2022-07-04 12:30:13 -04:00
|
|
|
d <- io $ cfgDir <$> getDirectories
|
2022-07-04 00:36:41 -04:00
|
|
|
return $ config bf ifs ios cs d
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- | toplevel configuration
|
|
|
|
|
|
|
|
-- | The text font family
|
|
|
|
textFont :: Always T.FontBuilder
|
2022-07-09 01:02:37 -04:00
|
|
|
textFont = fontAlways "XMobar Text Font" "DejaVu Sans Mono" defFontPkgs
|
2022-07-04 00:36:41 -04:00
|
|
|
|
|
|
|
-- | Offset of the text in the bar
|
|
|
|
textFontOffset :: Int
|
|
|
|
textFontOffset = 16
|
|
|
|
|
|
|
|
-- | Attributes for the bar font (size, weight, etc)
|
|
|
|
textFontData :: T.FontData
|
|
|
|
textFontData = T.defFontData { T.weight = Just T.Bold, T.size = Just 11 }
|
|
|
|
|
|
|
|
-- | The icon font family
|
|
|
|
iconFont :: Sometimes T.FontBuilder
|
2022-07-06 18:54:10 -04:00
|
|
|
iconFont = fontSometimes "XMobar Icon Font" "Symbols Nerd Font"
|
2022-07-09 14:59:42 -04:00
|
|
|
[Package Official "ttf-nerd-fonts-symbols"]
|
2022-07-04 00:36:41 -04:00
|
|
|
|
|
|
|
-- | Offsets for the icons in the bar (relative to the text offset)
|
|
|
|
iconOffset :: BarFont -> Int
|
|
|
|
iconOffset IconSmall = 0
|
|
|
|
iconOffset IconMedium = 1
|
|
|
|
iconOffset IconLarge = 1
|
|
|
|
iconOffset IconXLarge = 2
|
|
|
|
|
|
|
|
-- | Sizes (in pixels) for the icon fonts
|
|
|
|
iconSize :: BarFont -> Int
|
|
|
|
iconSize IconSmall = 13
|
|
|
|
iconSize IconMedium = 15
|
|
|
|
iconSize IconLarge = 18
|
|
|
|
iconSize IconXLarge = 20
|
|
|
|
|
|
|
|
-- | Attributes for icon fonts
|
|
|
|
iconFontData :: Int -> T.FontData
|
|
|
|
iconFontData s = T.defFontData { T.pixelsize = Just s, T.size = Nothing }
|
|
|
|
|
|
|
|
-- | Global configuration
|
|
|
|
-- Note that the 'font' and 'textOffset' are assumed to pertain to one (and
|
|
|
|
-- only one) text font, and all other fonts are icon fonts. If this assumption
|
|
|
|
-- changes the code will need to change significantly
|
|
|
|
config :: String -> [String] -> [Int] -> BarRegions -> FilePath -> Config
|
|
|
|
config bf ifs ios br confDir = defaultConfig
|
|
|
|
{ font = bf
|
|
|
|
, additionalFonts = ifs
|
|
|
|
, textOffset = textFontOffset
|
|
|
|
, textOffsets = ios
|
2021-06-23 23:08:50 -04:00
|
|
|
, bgColor = T.bgColor
|
|
|
|
, fgColor = T.fgColor
|
|
|
|
, position = BottomSize C 100 24
|
|
|
|
, border = NoBorder
|
|
|
|
, borderColor = T.bordersColor
|
2021-06-21 23:41:57 -04:00
|
|
|
|
2021-06-23 23:08:50 -04:00
|
|
|
, sepChar = pSep
|
|
|
|
, alignSep = [lSep, rSep]
|
|
|
|
, template = fmtRegions br
|
2020-04-01 22:35:53 -04:00
|
|
|
|
2021-06-23 23:08:50 -04:00
|
|
|
, lowerOnStart = False
|
|
|
|
, hideOnStart = False
|
|
|
|
, allDesktops = True
|
|
|
|
, overrideRedirect = True
|
|
|
|
, pickBroadest = False
|
|
|
|
, persistent = True
|
|
|
|
-- store the icons with the xmonad/xmobar stack project
|
|
|
|
, iconRoot = confDir ++ "/icons"
|
|
|
|
|
|
|
|
, commands = csRunnable <$> concatRegions br
|
|
|
|
}
|
|
|
|
|
2022-07-04 00:36:41 -04:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- | plugin features
|
|
|
|
--
|
|
|
|
-- some commands depend on the presence of interfaces that can only be
|
|
|
|
-- determined at runtime; define these checks here
|
|
|
|
|
2022-07-04 12:30:13 -04:00
|
|
|
getAllCommands :: [Maybe CmdSpec] -> BarRegions
|
|
|
|
getAllCommands right = BarRegions
|
|
|
|
{ brLeft = [ CmdSpec
|
|
|
|
{ csAlias = "UnsafeStdinReader"
|
|
|
|
, csRunnable = Run UnsafeStdinReader
|
|
|
|
}
|
|
|
|
]
|
|
|
|
, brCenter = []
|
|
|
|
, brRight = catMaybes right
|
|
|
|
}
|
|
|
|
|
|
|
|
rightPlugins :: DBusState -> FIO [Maybe CmdSpec]
|
2022-07-04 00:36:41 -04:00
|
|
|
rightPlugins DBusState { dbSesClient = ses, dbSysClient = sys }
|
|
|
|
= mapM evalFeature
|
|
|
|
[ Left getWireless
|
|
|
|
, Left $ getEthernet sys
|
|
|
|
, Left $ getVPN sys
|
|
|
|
, Left $ getBt sys
|
|
|
|
, Left getAlsa
|
|
|
|
, Left getBattery
|
|
|
|
, Left $ getBl ses
|
|
|
|
, Left $ getCk ses
|
|
|
|
, Left $ getSs ses
|
|
|
|
, Right getLock
|
|
|
|
, always' "date indicator" dateCmd
|
|
|
|
]
|
|
|
|
where
|
|
|
|
always' n = Right . Always n . Always_ . FallbackAlone
|
|
|
|
|
|
|
|
type BarFeature = Sometimes CmdSpec
|
|
|
|
|
2022-07-07 01:05:17 -04:00
|
|
|
-- TODO what if I don't have a wireless card?
|
2022-07-04 00:36:41 -04:00
|
|
|
getWireless :: BarFeature
|
2022-07-08 20:01:35 -04:00
|
|
|
getWireless = Sometimes "wireless status indicator" xpfWireless
|
|
|
|
[Subfeature (IORoot wirelessCmd $ Only readWireless) "sysfs path"]
|
2022-07-04 00:36:41 -04:00
|
|
|
|
2022-07-09 17:08:10 -04:00
|
|
|
getEthernet :: Maybe SysClient -> BarFeature
|
2022-07-08 20:01:35 -04:00
|
|
|
getEthernet cl = iconDBus "ethernet status indicator" (const True) root tree
|
2022-07-04 00:36:41 -04:00
|
|
|
where
|
|
|
|
root useIcon tree' = DBusRoot (const . ethernetCmd useIcon) tree' cl
|
2022-07-07 19:20:21 -04:00
|
|
|
tree = And1 (Only readEthernet) (Only_ devDep)
|
2022-07-04 00:36:41 -04:00
|
|
|
|
|
|
|
getBattery :: BarFeature
|
2022-07-08 20:01:35 -04:00
|
|
|
getBattery = iconIO_ "battery level indicator" xpfBattery root tree
|
2022-07-04 00:36:41 -04:00
|
|
|
where
|
|
|
|
root useIcon = IORoot_ (batteryCmd useIcon)
|
2022-07-09 01:02:37 -04:00
|
|
|
tree = Only_ $ IOTest_ "Test if battery is present" []
|
|
|
|
$ fmap (Msg Error) <$> hasBattery
|
2022-07-04 00:36:41 -04:00
|
|
|
|
2022-07-09 17:08:10 -04:00
|
|
|
getVPN :: Maybe SysClient -> BarFeature
|
2022-07-08 20:01:35 -04:00
|
|
|
getVPN cl = iconDBus_ "VPN status indicator" xpfVPN root $ toAnd_ vpnDep test
|
2022-07-04 00:36:41 -04:00
|
|
|
where
|
|
|
|
root useIcon tree = DBusRoot_ (const $ vpnCmd useIcon) tree cl
|
2022-07-09 01:02:37 -04:00
|
|
|
test = DBusIO $ IOTest_ "Use nmcli to test if VPN is present"
|
|
|
|
networkManagerPkgs vpnPresent
|
2022-07-04 00:36:41 -04:00
|
|
|
|
2022-07-09 17:08:10 -04:00
|
|
|
getBt :: Maybe SysClient -> BarFeature
|
2022-07-08 20:01:35 -04:00
|
|
|
getBt = xmobarDBus "bluetooth status indicator" xpfBluetooth btDep btCmd
|
2022-07-04 00:36:41 -04:00
|
|
|
|
|
|
|
getAlsa :: BarFeature
|
2022-07-08 20:01:35 -04:00
|
|
|
getAlsa = iconIO_ "volume level indicator" (const True) root
|
2022-07-09 14:59:42 -04:00
|
|
|
$ Only_ $ sysExe [Package Official "alsa-utils"] "alsactl"
|
2022-07-04 00:36:41 -04:00
|
|
|
where
|
|
|
|
root useIcon = IORoot_ (alsaCmd useIcon)
|
|
|
|
|
2022-07-09 17:08:10 -04:00
|
|
|
getBl :: Maybe SesClient -> BarFeature
|
2022-07-08 20:01:35 -04:00
|
|
|
getBl = xmobarDBus "Intel backlight indicator" xpfIntelBacklight
|
|
|
|
intelBacklightSignalDep blCmd
|
2022-07-04 00:36:41 -04:00
|
|
|
|
2022-07-09 17:08:10 -04:00
|
|
|
getCk :: Maybe SesClient -> BarFeature
|
2022-07-08 20:01:35 -04:00
|
|
|
getCk = xmobarDBus "Clevo keyboard indicator" xpfClevoBacklight
|
|
|
|
clevoKeyboardSignalDep ckCmd
|
2022-07-04 00:36:41 -04:00
|
|
|
|
2022-07-09 17:08:10 -04:00
|
|
|
getSs :: Maybe SesClient -> BarFeature
|
2022-07-08 20:01:35 -04:00
|
|
|
getSs = xmobarDBus "screensaver indicator" (const True) ssSignalDep ssCmd
|
2022-07-04 00:36:41 -04:00
|
|
|
|
|
|
|
getLock :: Always CmdSpec
|
2022-07-06 18:54:10 -04:00
|
|
|
getLock = always1 "lock indicator" "icon indicator" root $ lockCmd fontifyAlt
|
2022-07-04 00:36:41 -04:00
|
|
|
where
|
2022-07-06 18:54:10 -04:00
|
|
|
root = IORoot_ (lockCmd fontifyIcon) $ Only_ iconDependency
|
2022-07-04 00:36:41 -04:00
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- | bar feature constructors
|
|
|
|
|
2022-07-09 17:08:10 -04:00
|
|
|
xmobarDBus :: SafeClient c => String -> XPQuery -> DBusDependency_ c
|
|
|
|
-> (Fontifier -> CmdSpec) -> Maybe c -> BarFeature
|
2022-07-08 20:01:35 -04:00
|
|
|
xmobarDBus n q dep cmd cl = iconDBus_ n q root (Only_ dep)
|
2022-07-04 00:36:41 -04:00
|
|
|
where
|
|
|
|
root useIcon tree = DBusRoot_ (const $ cmd useIcon) tree cl
|
|
|
|
|
2022-07-08 20:01:35 -04:00
|
|
|
iconIO_ :: String -> XPQuery -> (Fontifier -> IOTree_ -> Root CmdSpec)
|
|
|
|
-> IOTree_ -> BarFeature
|
2022-07-04 00:36:41 -04:00
|
|
|
iconIO_ = iconSometimes' And_ Only_
|
|
|
|
|
2022-07-09 17:08:10 -04:00
|
|
|
iconDBus :: SafeClient c => String -> XPQuery
|
|
|
|
-> (Fontifier -> DBusTree c p -> Root CmdSpec) -> DBusTree c p -> BarFeature
|
2022-07-04 00:36:41 -04:00
|
|
|
iconDBus = iconSometimes' And1 $ Only_ . DBusIO
|
|
|
|
|
2022-07-09 17:08:10 -04:00
|
|
|
iconDBus_ :: SafeClient c => String -> XPQuery
|
|
|
|
-> (Fontifier -> DBusTree_ c -> Root CmdSpec) -> DBusTree_ c -> BarFeature
|
2022-07-04 00:36:41 -04:00
|
|
|
iconDBus_ = iconSometimes' And_ $ Only_ . DBusIO
|
|
|
|
|
2022-07-08 20:01:35 -04:00
|
|
|
iconSometimes' :: (t -> t_ -> t) -> (IODependency_ -> t_) -> String -> XPQuery
|
2022-07-06 18:54:10 -04:00
|
|
|
-> (Fontifier -> t -> Root CmdSpec) -> t -> BarFeature
|
2022-07-08 20:01:35 -04:00
|
|
|
iconSometimes' c d n q r t = Sometimes n q
|
2022-07-08 19:02:49 -04:00
|
|
|
[ Subfeature icon "icon indicator"
|
|
|
|
, Subfeature text "text indicator"
|
2022-07-04 00:36:41 -04:00
|
|
|
]
|
|
|
|
where
|
2022-07-06 18:54:10 -04:00
|
|
|
icon = r fontifyIcon $ c t $ d iconDependency
|
|
|
|
text = r fontifyAlt t
|
2022-07-04 00:36:41 -04:00
|
|
|
|
2021-06-23 23:08:50 -04:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- | command specifications
|
2020-04-01 22:35:53 -04:00
|
|
|
|
2021-06-21 23:41:57 -04:00
|
|
|
data BarRegions = BarRegions
|
|
|
|
{ brLeft :: [CmdSpec]
|
|
|
|
, brCenter :: [CmdSpec]
|
|
|
|
, brRight :: [CmdSpec]
|
|
|
|
} deriving Show
|
|
|
|
|
|
|
|
data CmdSpec = CmdSpec
|
|
|
|
{ csAlias :: String
|
|
|
|
, csRunnable :: Runnable
|
|
|
|
} deriving Show
|
|
|
|
|
|
|
|
concatRegions :: BarRegions -> [CmdSpec]
|
|
|
|
concatRegions (BarRegions l c r) = l ++ c ++ r
|
|
|
|
|
2021-06-23 00:09:59 -04:00
|
|
|
wirelessCmd :: String -> CmdSpec
|
2021-06-23 20:19:55 -04:00
|
|
|
wirelessCmd iface = CmdSpec
|
|
|
|
{ csAlias = iface ++ "wi"
|
2021-06-23 00:09:59 -04:00
|
|
|
, csRunnable = Run
|
2021-06-23 20:19:55 -04:00
|
|
|
$ Wireless iface
|
2021-06-23 00:09:59 -04:00
|
|
|
[ "-t", "<qualityipat><essid>"
|
|
|
|
, "--"
|
|
|
|
, "--quality-icon-pattern", "<icon=wifi_%%.xpm/>"
|
|
|
|
] 5
|
|
|
|
}
|
|
|
|
|
2022-07-06 18:54:10 -04:00
|
|
|
ethernetCmd :: Fontifier -> String -> CmdSpec
|
|
|
|
ethernetCmd fontify iface = CmdSpec
|
2021-06-23 20:19:55 -04:00
|
|
|
{ csAlias = iface
|
|
|
|
, csRunnable = Run
|
2022-07-06 18:54:10 -04:00
|
|
|
$ Device (iface, fontify IconMedium "\xf0e8" "ETH", colors)
|
2021-06-23 20:19:55 -04:00
|
|
|
}
|
|
|
|
|
2022-07-06 18:54:10 -04:00
|
|
|
batteryCmd :: Fontifier -> CmdSpec
|
|
|
|
batteryCmd fontify = CmdSpec
|
2021-06-23 20:47:41 -04:00
|
|
|
{ csAlias = "battery"
|
|
|
|
, csRunnable = Run
|
|
|
|
$ Battery
|
|
|
|
[ "--template", "<acstatus><left>"
|
|
|
|
, "--Low", "10"
|
|
|
|
, "--High", "80"
|
|
|
|
, "--low", "red"
|
|
|
|
, "--normal", T.fgColor
|
|
|
|
, "--high", T.fgColor
|
|
|
|
, "--"
|
|
|
|
, "-P"
|
2022-07-06 18:54:10 -04:00
|
|
|
, "-o" , fontify' "\xf0e7" "BAT"
|
|
|
|
, "-O" , fontify' "\xf1e6" "AC"
|
|
|
|
, "-i" , fontify' "\xf1e6" "AC"
|
2021-06-23 20:47:41 -04:00
|
|
|
] 50
|
|
|
|
}
|
2021-06-30 23:04:00 -04:00
|
|
|
where
|
2022-07-06 18:54:10 -04:00
|
|
|
fontify' = fontify IconSmall
|
2021-06-23 20:47:41 -04:00
|
|
|
|
2022-07-06 18:54:10 -04:00
|
|
|
vpnCmd :: Fontifier -> CmdSpec
|
|
|
|
vpnCmd fontify = CmdSpec
|
2021-06-23 00:38:23 -04:00
|
|
|
{ csAlias = vpnAlias
|
2022-07-06 18:54:10 -04:00
|
|
|
, csRunnable = Run $ VPN (fontify IconMedium "\xf023" "VPN", colors)
|
2021-06-23 00:38:23 -04:00
|
|
|
}
|
|
|
|
|
2022-07-06 18:54:10 -04:00
|
|
|
btCmd :: Fontifier -> CmdSpec
|
|
|
|
btCmd fontify = CmdSpec
|
2021-06-23 23:08:50 -04:00
|
|
|
{ csAlias = btAlias
|
|
|
|
, csRunnable = Run
|
2022-07-06 18:54:10 -04:00
|
|
|
$ Bluetooth (fontify' "\xf5b0" "+", fontify' "\xf5ae" "-") colors
|
2021-06-23 23:08:50 -04:00
|
|
|
}
|
2021-11-27 17:33:02 -05:00
|
|
|
where
|
2022-07-06 19:10:28 -04:00
|
|
|
fontify' i = fontify IconLarge i . ("BT" ++)
|
2021-06-23 00:38:23 -04:00
|
|
|
|
2022-07-06 18:54:10 -04:00
|
|
|
alsaCmd :: Fontifier -> CmdSpec
|
|
|
|
alsaCmd fontify = CmdSpec
|
2021-06-23 23:08:50 -04:00
|
|
|
{ csAlias = "alsa:default:Master"
|
|
|
|
, csRunnable = Run
|
|
|
|
$ Alsa "default" "Master"
|
|
|
|
[ "-t", "<status><volume>%"
|
|
|
|
, "--"
|
2022-07-06 18:54:10 -04:00
|
|
|
, "-O", fontify' "\xf028" "+"
|
|
|
|
, "-o", fontify' "\xf026" "-" ++ " "
|
2021-06-23 23:08:50 -04:00
|
|
|
, "-c", T.fgColor
|
|
|
|
, "-C", T.fgColor
|
|
|
|
]
|
|
|
|
}
|
2022-07-04 00:36:41 -04:00
|
|
|
where
|
2022-07-06 19:10:28 -04:00
|
|
|
fontify' i = fontify IconSmall i . ("VOL" ++)
|
2021-06-23 00:09:59 -04:00
|
|
|
|
2022-07-06 18:54:10 -04:00
|
|
|
blCmd :: Fontifier -> CmdSpec
|
|
|
|
blCmd fontify = CmdSpec
|
2021-11-21 00:42:40 -05:00
|
|
|
{ csAlias = blAlias
|
2022-07-06 18:54:10 -04:00
|
|
|
, csRunnable = Run $ IntelBacklight $ fontify IconSmall "\xf185" "BL: "
|
2021-06-23 23:08:50 -04:00
|
|
|
}
|
2021-06-23 00:09:59 -04:00
|
|
|
|
2022-07-06 18:54:10 -04:00
|
|
|
ckCmd :: Fontifier -> CmdSpec
|
|
|
|
ckCmd fontify = CmdSpec
|
2021-11-05 21:15:37 -04:00
|
|
|
{ csAlias = ckAlias
|
2022-07-06 18:54:10 -04:00
|
|
|
, csRunnable = Run $ ClevoKeyboard $ fontify IconSmall "\xf40b" "KB: "
|
2021-11-05 21:15:37 -04:00
|
|
|
}
|
|
|
|
|
2022-07-06 18:54:10 -04:00
|
|
|
ssCmd :: Fontifier -> CmdSpec
|
|
|
|
ssCmd fontify = CmdSpec
|
2021-06-23 23:08:50 -04:00
|
|
|
{ csAlias = ssAlias
|
2022-07-06 18:54:10 -04:00
|
|
|
, csRunnable = Run $ Screensaver (fontify IconSmall "\xf254" "SS", colors)
|
2021-06-23 23:08:50 -04:00
|
|
|
}
|
2021-06-23 00:09:59 -04:00
|
|
|
|
2022-07-06 18:54:10 -04:00
|
|
|
lockCmd :: Fontifier -> CmdSpec
|
|
|
|
lockCmd fontify = CmdSpec
|
2021-06-23 23:08:50 -04:00
|
|
|
{ csAlias = "locks"
|
|
|
|
, csRunnable = Run
|
|
|
|
$ Locks
|
2021-11-27 17:33:02 -05:00
|
|
|
[ "-N", numIcon
|
|
|
|
, "-n", disabledColor numIcon
|
|
|
|
, "-C", capIcon
|
|
|
|
, "-c", disabledColor capIcon
|
2021-06-23 23:08:50 -04:00
|
|
|
, "-s", ""
|
|
|
|
, "-S", ""
|
2021-06-30 22:47:49 -04:00
|
|
|
, "-d", " "
|
2021-06-23 23:08:50 -04:00
|
|
|
]
|
|
|
|
}
|
2021-11-27 17:33:02 -05:00
|
|
|
where
|
2022-07-06 18:54:10 -04:00
|
|
|
numIcon = fontify' "\xf8a5" "N"
|
|
|
|
capIcon = fontify' "\xf657" "C"
|
|
|
|
fontify' = fontify IconXLarge
|
2021-11-27 17:33:02 -05:00
|
|
|
disabledColor = xmobarFGColor T.backdropFgColor
|
2021-06-23 00:09:59 -04:00
|
|
|
|
2021-06-23 23:08:50 -04:00
|
|
|
dateCmd :: CmdSpec
|
|
|
|
dateCmd = CmdSpec
|
|
|
|
{ csAlias = "date"
|
|
|
|
, csRunnable = Run $ Date "%Y-%m-%d %H:%M:%S " "date" 10
|
|
|
|
}
|
2021-06-23 00:09:59 -04:00
|
|
|
|
2021-06-23 23:08:50 -04:00
|
|
|
--------------------------------------------------------------------------------
|
2022-07-04 00:36:41 -04:00
|
|
|
-- | low-level testing functions
|
2021-11-09 00:59:17 -05:00
|
|
|
|
2022-07-07 01:05:17 -04:00
|
|
|
vpnPresent :: IO (Maybe Msg)
|
2022-07-02 18:22:26 -04:00
|
|
|
vpnPresent =
|
|
|
|
go <$> tryIOError (readCreateProcessWithExitCode' (proc' "nmcli" args) "")
|
2021-11-09 00:59:17 -05:00
|
|
|
where
|
|
|
|
args = ["-c", "no", "-t", "-f", "TYPE", "c", "show"]
|
2022-07-02 17:09:21 -04:00
|
|
|
go (Right (ExitSuccess, out, _)) = if "vpn" `elem` lines out then Nothing
|
2022-07-07 01:05:17 -04:00
|
|
|
else Just $ Msg Error "vpn not found"
|
|
|
|
go (Right (ExitFailure c, _, err)) = Just $ Msg Error
|
|
|
|
$ "vpn search exited with code "
|
2022-07-02 17:09:21 -04:00
|
|
|
++ show c ++ ": " ++ err
|
2022-07-07 01:05:17 -04:00
|
|
|
go (Left e) = Just $ Msg Error $ show e
|
2021-11-09 00:59:17 -05:00
|
|
|
|
2022-07-04 00:36:41 -04:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- | text font
|
|
|
|
--
|
|
|
|
-- ASSUME there is only one text font for this entire configuration. This
|
|
|
|
-- will correspond to the first font/offset parameters in the config record.
|
2021-11-21 22:47:43 -05:00
|
|
|
|
2022-07-04 12:30:13 -04:00
|
|
|
getTextFont :: FIO String
|
2022-07-04 00:36:41 -04:00
|
|
|
getTextFont = do
|
|
|
|
fb <- evalAlways textFont
|
|
|
|
return $ fb textFontData
|
2021-06-23 23:08:50 -04:00
|
|
|
|
2022-07-04 00:36:41 -04:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- | icon fonts
|
2021-06-23 23:08:50 -04:00
|
|
|
|
2022-07-04 12:30:13 -04:00
|
|
|
getIconFonts :: FIO ([String], [Int])
|
2022-07-04 00:36:41 -04:00
|
|
|
getIconFonts = do
|
|
|
|
fb <- evalSometimes iconFont
|
|
|
|
return $ maybe ([], []) apply fb
|
2021-11-21 23:55:19 -05:00
|
|
|
where
|
2022-07-04 00:36:41 -04:00
|
|
|
apply fb = unzip $ (\i -> (iconString fb i, iconOffset i + textFontOffset))
|
|
|
|
<$> iconFonts
|
2021-06-23 23:08:50 -04:00
|
|
|
|
2022-07-04 00:36:41 -04:00
|
|
|
data BarFont = IconSmall
|
2021-11-27 17:33:02 -05:00
|
|
|
| IconMedium
|
|
|
|
| IconLarge
|
|
|
|
| IconXLarge
|
|
|
|
deriving (Eq, Enum, Bounded, Show)
|
2021-06-23 23:08:50 -04:00
|
|
|
|
2022-07-04 00:36:41 -04:00
|
|
|
iconFonts :: [BarFont]
|
|
|
|
iconFonts = enumFrom minBound
|
2022-07-02 17:09:21 -04:00
|
|
|
|
2022-07-04 00:36:41 -04:00
|
|
|
iconString :: T.FontBuilder -> BarFont -> String
|
|
|
|
iconString fb i = fb $ iconFontData $ iconSize i
|
|
|
|
|
|
|
|
iconDependency :: IODependency_
|
|
|
|
iconDependency = IOSometimes_ iconFont
|
2022-07-02 17:09:21 -04:00
|
|
|
|
|
|
|
fontifyText :: BarFont -> String -> String
|
2022-07-04 00:36:41 -04:00
|
|
|
fontifyText fnt txt = concat ["<fn=", show $ 1 + fromEnum fnt, ">", txt, "</fn>"]
|
2021-11-05 21:15:37 -04:00
|
|
|
|
2022-07-06 18:54:10 -04:00
|
|
|
type Fontifier = BarFont -> String -> String -> String
|
|
|
|
|
|
|
|
fontifyAlt :: Fontifier
|
|
|
|
fontifyAlt _ _ alt = alt
|
|
|
|
|
|
|
|
fontifyIcon :: Fontifier
|
|
|
|
fontifyIcon f i _ = fontifyText f i
|
|
|
|
|
2021-11-27 17:33:02 -05:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- | various formatting things
|
|
|
|
|
|
|
|
colors :: Colors
|
|
|
|
colors = Colors { colorsOn = T.fgColor, colorsOff = T.backdropFgColor }
|
|
|
|
|
|
|
|
sep :: String
|
|
|
|
sep = xmobarFGColor T.backdropFgColor " : "
|
|
|
|
|
|
|
|
lSep :: Char
|
|
|
|
lSep = '}'
|
|
|
|
|
|
|
|
rSep :: Char
|
|
|
|
rSep = '{'
|
2020-03-22 17:17:57 -04:00
|
|
|
|
2021-11-27 17:33:02 -05:00
|
|
|
pSep :: String
|
|
|
|
pSep = "%"
|
|
|
|
|
|
|
|
fmtSpecs :: [CmdSpec] -> String
|
|
|
|
fmtSpecs = intercalate sep . fmap go
|
|
|
|
where
|
|
|
|
go CmdSpec { csAlias = a } = wrap pSep pSep a
|
|
|
|
|
|
|
|
fmtRegions :: BarRegions -> String
|
|
|
|
fmtRegions BarRegions { brLeft = l, brCenter = c, brRight = r } =
|
|
|
|
fmtSpecs l ++ [lSep] ++ fmtSpecs c ++ [rSep] ++ fmtSpecs r
|