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
|
|
|
|
|
2021-11-24 00:21:18 -05:00
|
|
|
import Control.Monad
|
2021-11-23 18:28:38 -05:00
|
|
|
|
2021-06-23 00:09:59 -04:00
|
|
|
import Data.Either
|
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-11-21 22:47:43 -05:00
|
|
|
import DBus.Client
|
2021-11-27 01:02:22 -05:00
|
|
|
import DBus.Internal
|
2021-06-21 23:41:57 -04:00
|
|
|
|
2021-06-23 00:09:59 -04:00
|
|
|
import System.Directory
|
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
|
2021-11-07 13:35:08 -05:00
|
|
|
import System.Process
|
|
|
|
( readProcessWithExitCode
|
|
|
|
)
|
2021-06-23 00:09:59 -04:00
|
|
|
|
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
|
|
|
|
2021-11-07 13:35:08 -05:00
|
|
|
import XMonad (getXMonadDir)
|
2021-11-27 17:33:02 -05:00
|
|
|
import XMonad.Hooks.DynamicLog (wrap)
|
2021-11-07 13:35:08 -05:00
|
|
|
import XMonad.Internal.Command.Power (hasBattery)
|
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
|
2021-11-20 19:35:24 -05:00
|
|
|
import XMonad.Internal.DBus.Screensaver (ssSignalDep)
|
2021-11-08 00:27:39 -05:00
|
|
|
import XMonad.Internal.Dependency
|
2021-11-23 18:28:38 -05:00
|
|
|
import XMonad.Internal.Shell
|
2021-11-07 13:35:08 -05:00
|
|
|
import qualified XMonad.Internal.Theme as T
|
2021-06-19 00:54:01 -04:00
|
|
|
import Xmobar
|
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
|
2021-11-21 22:47:43 -05:00
|
|
|
sysClient <- getDBusClient True
|
|
|
|
sesClient <- getDBusClient False
|
2021-11-22 23:26:59 -05:00
|
|
|
cs <- getAllCommands =<< rightPlugins sysClient sesClient
|
2021-06-23 23:08:50 -04:00
|
|
|
d <- getXMonadDir
|
2021-11-09 00:59:17 -05:00
|
|
|
-- this is needed to see any printed messages
|
|
|
|
hFlush stdout
|
2021-11-21 22:47:43 -05:00
|
|
|
mapM_ (maybe skip disconnect) [sysClient, sesClient]
|
2021-06-23 23:08:50 -04:00
|
|
|
xmobar $ config cs d
|
2020-03-15 13:12:01 -04:00
|
|
|
|
2021-06-23 23:08:50 -04:00
|
|
|
config :: BarRegions -> String -> Config
|
|
|
|
config br confDir = defaultConfig
|
2021-11-27 17:33:02 -05:00
|
|
|
-- TODO head makes me feel icky
|
|
|
|
{ font = head allFontStrings
|
|
|
|
, additionalFonts = drop 1 allFontStrings
|
|
|
|
, textOffset = head allFontOffsets
|
|
|
|
, textOffsets = drop 1 allFontOffsets
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- | 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
|
|
|
|
}
|
|
|
|
|
2021-06-23 20:19:55 -04:00
|
|
|
ethernetCmd :: String -> CmdSpec
|
|
|
|
ethernetCmd iface = CmdSpec
|
|
|
|
{ csAlias = iface
|
|
|
|
, csRunnable = Run
|
2021-11-27 17:33:02 -05:00
|
|
|
$ Device (iface, fontifyText IconMedium "\xf0e8", colors)
|
2021-06-23 20:19:55 -04:00
|
|
|
}
|
|
|
|
|
2021-06-23 20:47:41 -04:00
|
|
|
batteryCmd :: CmdSpec
|
|
|
|
batteryCmd = CmdSpec
|
|
|
|
{ csAlias = "battery"
|
|
|
|
, csRunnable = Run
|
|
|
|
$ Battery
|
|
|
|
[ "--template", "<acstatus><left>"
|
|
|
|
, "--Low", "10"
|
|
|
|
, "--High", "80"
|
|
|
|
, "--low", "red"
|
|
|
|
, "--normal", T.fgColor
|
|
|
|
, "--high", T.fgColor
|
|
|
|
, "--"
|
2021-06-30 23:04:00 -04:00
|
|
|
, "-a", notify
|
2021-06-23 20:47:41 -04:00
|
|
|
, "-P"
|
2021-11-27 17:33:02 -05:00
|
|
|
, "-o" , fontify "\xf0e7"
|
|
|
|
, "-O" , fontify "\xf1e6"
|
|
|
|
, "-i" , fontify "\xf1e6"
|
2021-06-23 20:47:41 -04:00
|
|
|
] 50
|
|
|
|
}
|
2021-06-30 23:04:00 -04:00
|
|
|
where
|
2021-11-27 17:33:02 -05:00
|
|
|
fontify = fontifyText IconSmall
|
|
|
|
-- TODO format this with standardized notification library from xmonad.internal
|
2021-06-30 23:04:00 -04:00
|
|
|
notify = fmtCmd "notify-send"
|
|
|
|
[ "-u"
|
|
|
|
, "critical"
|
|
|
|
, "-i"
|
|
|
|
, "'dialog-information-symbolic'"
|
|
|
|
, "'low battery'"
|
|
|
|
]
|
2021-06-23 20:47:41 -04:00
|
|
|
|
2021-06-23 00:38:23 -04:00
|
|
|
vpnCmd :: CmdSpec
|
|
|
|
vpnCmd = CmdSpec
|
|
|
|
{ csAlias = vpnAlias
|
2021-11-27 17:33:02 -05:00
|
|
|
, csRunnable = Run $ VPN (fontifyText IconMedium "\xf023", colors)
|
2021-06-23 00:38:23 -04:00
|
|
|
}
|
|
|
|
|
2021-06-23 23:08:50 -04:00
|
|
|
btCmd :: CmdSpec
|
|
|
|
btCmd = CmdSpec
|
|
|
|
{ csAlias = btAlias
|
|
|
|
, csRunnable = Run
|
2021-11-27 17:33:02 -05:00
|
|
|
$ Bluetooth (fontify "\xf5b0", fontify "\xf5ae") colors
|
2021-06-23 23:08:50 -04:00
|
|
|
}
|
2021-11-27 17:33:02 -05:00
|
|
|
where
|
|
|
|
fontify = fontifyText IconLarge
|
2021-06-23 00:38:23 -04:00
|
|
|
|
2021-06-23 23:08:50 -04:00
|
|
|
alsaCmd :: CmdSpec
|
|
|
|
alsaCmd = CmdSpec
|
|
|
|
{ csAlias = "alsa:default:Master"
|
|
|
|
, csRunnable = Run
|
|
|
|
$ Alsa "default" "Master"
|
|
|
|
[ "-t", "<status><volume>%"
|
|
|
|
, "--"
|
2021-11-27 17:33:02 -05:00
|
|
|
, "-O", fontifyText IconSmall "\xf028"
|
|
|
|
, "-o", fontifyText IconSmall "\xf026 "
|
2021-06-23 23:08:50 -04:00
|
|
|
, "-c", T.fgColor
|
|
|
|
, "-C", T.fgColor
|
|
|
|
]
|
|
|
|
}
|
2021-06-23 00:09:59 -04:00
|
|
|
|
2021-06-23 23:08:50 -04:00
|
|
|
blCmd :: CmdSpec
|
|
|
|
blCmd = CmdSpec
|
2021-11-21 00:42:40 -05:00
|
|
|
{ csAlias = blAlias
|
2021-11-27 17:33:02 -05:00
|
|
|
, csRunnable = Run $ IntelBacklight $ fontifyText IconSmall "\xf185"
|
2021-06-23 23:08:50 -04:00
|
|
|
}
|
2021-06-23 00:09:59 -04:00
|
|
|
|
2021-11-05 21:15:37 -04:00
|
|
|
ckCmd :: CmdSpec
|
|
|
|
ckCmd = CmdSpec
|
|
|
|
{ csAlias = ckAlias
|
2021-11-27 17:33:02 -05:00
|
|
|
, csRunnable = Run $ ClevoKeyboard $ fontifyText IconSmall "\xf40b"
|
2021-11-05 21:15:37 -04:00
|
|
|
}
|
|
|
|
|
2021-06-23 23:08:50 -04:00
|
|
|
ssCmd :: CmdSpec
|
|
|
|
ssCmd = CmdSpec
|
|
|
|
{ csAlias = ssAlias
|
|
|
|
, csRunnable = Run
|
2021-11-27 17:33:02 -05:00
|
|
|
$ Screensaver (fontifyText IconSmall "\xf254", colors)
|
2021-06-23 23:08:50 -04:00
|
|
|
}
|
2021-06-23 00:09:59 -04:00
|
|
|
|
2021-06-23 23:08:50 -04:00
|
|
|
lockCmd :: CmdSpec
|
|
|
|
lockCmd = CmdSpec
|
|
|
|
{ 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
|
|
|
|
numIcon = fontify "\xf8a5"
|
|
|
|
capIcon = fontify "\xf657"
|
|
|
|
fontify = fontifyText IconXLarge
|
|
|
|
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
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- | command runtime checks and setup
|
2021-11-23 18:28:38 -05:00
|
|
|
--
|
2021-06-23 23:08:50 -04:00
|
|
|
-- some commands depend on the presence of interfaces that can only be
|
|
|
|
-- determined at runtime; define these checks here
|
2021-11-23 18:28:38 -05:00
|
|
|
--
|
2021-06-23 23:08:50 -04:00
|
|
|
-- in the case of network interfaces, assume that the system uses systemd in
|
|
|
|
-- which case ethernet interfaces always start with "en" and wireless
|
|
|
|
-- interfaces always start with "wl"
|
2021-11-23 18:28:38 -05:00
|
|
|
|
2021-11-27 17:33:02 -05:00
|
|
|
type BarFeature = Feature CmdSpec
|
|
|
|
|
2021-06-23 23:08:50 -04:00
|
|
|
isWireless :: String -> Bool
|
|
|
|
isWireless ('w':'l':_) = True
|
|
|
|
isWireless _ = False
|
|
|
|
|
|
|
|
isEthernet :: String -> Bool
|
|
|
|
isEthernet ('e':'n':_) = True
|
|
|
|
isEthernet _ = False
|
|
|
|
|
|
|
|
listInterfaces :: IO [String]
|
|
|
|
listInterfaces = fromRight [] <$> tryIOError (listDirectory sysfsNet)
|
2021-06-23 00:09:59 -04:00
|
|
|
|
2021-06-23 23:08:50 -04:00
|
|
|
sysfsNet :: FilePath
|
|
|
|
sysfsNet = "/sys/class/net"
|
|
|
|
|
2021-11-21 22:47:43 -05:00
|
|
|
readInterface :: (String -> Bool) -> IO (Either [String] String)
|
2021-11-09 00:59:17 -05:00
|
|
|
readInterface f = do
|
|
|
|
ns <- filter f <$> listInterfaces
|
|
|
|
case ns of
|
2021-11-21 22:47:43 -05:00
|
|
|
[] -> return $ Left ["no interfaces found"]
|
2021-11-09 00:59:17 -05:00
|
|
|
(x:xs) -> do
|
|
|
|
unless (null xs) $
|
|
|
|
putStrLn $ "WARNING: extra interfaces found, using " ++ x
|
2021-11-21 22:47:43 -05:00
|
|
|
return $ Right x
|
2021-11-09 00:59:17 -05:00
|
|
|
|
2021-11-19 00:35:54 -05:00
|
|
|
vpnPresent :: IO (Maybe String)
|
2021-11-09 00:59:17 -05:00
|
|
|
vpnPresent = do
|
|
|
|
res <- tryIOError $ readProcessWithExitCode "nmcli" args ""
|
|
|
|
-- TODO provide some error messages
|
|
|
|
return $ case res of
|
2021-11-19 00:35:54 -05:00
|
|
|
(Right (ExitSuccess, out, _)) -> if "vpn" `elem` lines out then Nothing else Just "vpn not found"
|
|
|
|
_ -> Just "puke"
|
2021-11-09 00:59:17 -05:00
|
|
|
where
|
|
|
|
args = ["-c", "no", "-t", "-f", "TYPE", "c", "show"]
|
|
|
|
|
2021-11-21 22:47:43 -05:00
|
|
|
rightPlugins :: Maybe Client -> Maybe Client -> IO [MaybeAction CmdSpec]
|
|
|
|
rightPlugins sysClient sesClient = mapM evalFeature
|
2021-11-09 00:59:17 -05:00
|
|
|
[ getWireless
|
2021-11-22 23:02:23 -05:00
|
|
|
, getEthernet sysClient
|
2021-11-21 23:07:33 -05:00
|
|
|
, getVPN sysClient
|
2021-11-21 22:47:43 -05:00
|
|
|
, getBt sysClient
|
|
|
|
, getAlsa
|
|
|
|
, getBattery
|
|
|
|
, getBl sesClient
|
|
|
|
, getCk sesClient
|
|
|
|
, getSs sesClient
|
|
|
|
, ConstFeature lockCmd
|
|
|
|
, ConstFeature dateCmd
|
2021-11-09 00:59:17 -05:00
|
|
|
]
|
|
|
|
|
2021-11-21 22:47:43 -05:00
|
|
|
getWireless :: BarFeature
|
|
|
|
getWireless = Feature
|
2021-11-22 23:28:54 -05:00
|
|
|
{ ftrDepTree = GenTree (Double wirelessCmd $ readInterface isWireless) []
|
2021-11-21 22:47:43 -05:00
|
|
|
, ftrName = "wireless status indicator"
|
|
|
|
, ftrWarning = Default
|
|
|
|
}
|
|
|
|
|
2021-11-22 23:02:23 -05:00
|
|
|
getEthernet :: Maybe Client -> BarFeature
|
|
|
|
getEthernet client = Feature
|
2021-11-25 00:12:00 -05:00
|
|
|
{ ftrDepTree = DBusTree action client [devDep] []
|
2021-11-21 22:47:43 -05:00
|
|
|
, ftrName = "ethernet status indicator"
|
|
|
|
, ftrWarning = Default
|
|
|
|
}
|
2021-11-22 23:02:23 -05:00
|
|
|
where
|
2021-11-23 18:28:38 -05:00
|
|
|
action = Double (\i _ -> ethernetCmd i) (readInterface isEthernet)
|
2021-06-23 23:08:50 -04:00
|
|
|
|
2021-11-11 23:25:11 -05:00
|
|
|
getBattery :: BarFeature
|
|
|
|
getBattery = Feature
|
2021-11-22 23:28:54 -05:00
|
|
|
{ ftrDepTree = GenTree (Single batteryCmd) [IOTest hasBattery]
|
2021-11-20 19:35:24 -05:00
|
|
|
, ftrName = "battery level indicator"
|
|
|
|
, ftrWarning = Default
|
2021-11-11 23:25:11 -05:00
|
|
|
}
|
2021-06-23 23:08:50 -04:00
|
|
|
|
2021-11-21 23:07:33 -05:00
|
|
|
getVPN :: Maybe Client -> BarFeature
|
|
|
|
getVPN client = Feature
|
2021-11-24 00:43:58 -05:00
|
|
|
{ ftrDepTree = DBusTree (Single (const vpnCmd)) client [vpnDep] [dp]
|
2021-11-20 19:35:24 -05:00
|
|
|
, ftrName = "VPN status indicator"
|
|
|
|
, ftrWarning = Default
|
2021-11-11 23:25:11 -05:00
|
|
|
}
|
2021-11-21 23:55:19 -05:00
|
|
|
where
|
|
|
|
dp = IOTest vpnPresent
|
2021-11-11 23:25:11 -05:00
|
|
|
|
2021-11-21 22:47:43 -05:00
|
|
|
getBt :: Maybe Client -> BarFeature
|
|
|
|
getBt client = Feature
|
2021-11-23 18:28:38 -05:00
|
|
|
{ ftrDepTree = DBusTree (Single (const btCmd)) client [btDep] []
|
2021-11-20 19:35:24 -05:00
|
|
|
, ftrName = "bluetooth status indicator"
|
|
|
|
, ftrWarning = Default
|
2021-11-11 23:25:11 -05:00
|
|
|
}
|
2021-06-23 23:08:50 -04:00
|
|
|
|
2021-11-11 23:25:11 -05:00
|
|
|
getAlsa :: BarFeature
|
|
|
|
getAlsa = Feature
|
2021-11-22 23:28:54 -05:00
|
|
|
{ ftrDepTree = GenTree (Single alsaCmd) [Executable "alsactl"]
|
2021-11-20 19:35:24 -05:00
|
|
|
, ftrName = "volume level indicator"
|
|
|
|
, ftrWarning = Default
|
2021-11-11 23:25:11 -05:00
|
|
|
}
|
2021-06-23 23:08:50 -04:00
|
|
|
|
2021-11-21 22:47:43 -05:00
|
|
|
getBl :: Maybe Client -> BarFeature
|
|
|
|
getBl client = Feature
|
2021-11-22 23:28:54 -05:00
|
|
|
{ ftrDepTree = DBusTree (Single (const blCmd)) client [intelBacklightSignalDep] []
|
2021-11-20 19:35:24 -05:00
|
|
|
, ftrName = "Intel backlight indicator"
|
|
|
|
, ftrWarning = Default
|
2021-11-11 23:25:11 -05:00
|
|
|
}
|
2021-06-23 23:08:50 -04:00
|
|
|
|
2021-11-21 22:47:43 -05:00
|
|
|
getCk :: Maybe Client -> BarFeature
|
|
|
|
getCk client = Feature
|
2021-11-22 23:28:54 -05:00
|
|
|
{ ftrDepTree = DBusTree (Single (const ckCmd)) client [clevoKeyboardSignalDep] []
|
2021-11-21 17:54:00 -05:00
|
|
|
, ftrName = "Clevo keyboard indicator"
|
|
|
|
, ftrWarning = Default
|
|
|
|
}
|
|
|
|
|
2021-11-21 22:47:43 -05:00
|
|
|
getSs :: Maybe Client -> BarFeature
|
|
|
|
getSs client = Feature
|
2021-11-22 23:28:54 -05:00
|
|
|
{ ftrDepTree = DBusTree (Single (const ssCmd)) client [ssSignalDep] []
|
2021-11-20 19:35:24 -05:00
|
|
|
, ftrName = "screensaver indicator"
|
|
|
|
, ftrWarning = Default
|
2021-11-11 23:25:11 -05:00
|
|
|
}
|
2021-06-23 23:08:50 -04:00
|
|
|
|
2021-11-21 10:26:28 -05:00
|
|
|
getAllCommands :: [MaybeAction CmdSpec] -> IO BarRegions
|
2021-11-09 00:59:17 -05:00
|
|
|
getAllCommands right = do
|
2021-06-23 23:08:50 -04:00
|
|
|
let left =
|
|
|
|
[ CmdSpec
|
|
|
|
{ csAlias = "UnsafeStdinReader"
|
|
|
|
, csRunnable = Run UnsafeStdinReader
|
2021-06-23 00:09:59 -04:00
|
|
|
}
|
2021-06-21 23:41:57 -04:00
|
|
|
]
|
2021-06-23 00:09:59 -04:00
|
|
|
return $ BarRegions
|
|
|
|
{ brLeft = left
|
|
|
|
, brCenter = []
|
2021-11-22 23:26:59 -05:00
|
|
|
, brRight = catMaybes right
|
2021-06-23 00:09:59 -04:00
|
|
|
}
|
2021-06-21 23:41:57 -04:00
|
|
|
|
2021-06-23 23:08:50 -04:00
|
|
|
--------------------------------------------------------------------------------
|
2021-11-27 17:33:02 -05:00
|
|
|
-- | fonts
|
2021-06-23 23:08:50 -04:00
|
|
|
|
2021-11-27 17:33:02 -05:00
|
|
|
data Font = Text
|
|
|
|
| IconSmall
|
|
|
|
| IconMedium
|
|
|
|
| IconLarge
|
|
|
|
| IconXLarge
|
|
|
|
deriving (Eq, Enum, Bounded, Show)
|
2021-06-23 23:08:50 -04:00
|
|
|
|
2021-11-27 17:33:02 -05:00
|
|
|
-- font data ~ (offset, fontification string)
|
|
|
|
fontData :: Font -> (Int, String)
|
|
|
|
fontData Text = (16, barFont)
|
|
|
|
fontData IconSmall = (16, nerdFont 13)
|
|
|
|
fontData IconMedium = (17, nerdFont 15)
|
|
|
|
fontData IconLarge = (17, nerdFont 18)
|
|
|
|
fontData IconXLarge = (18, nerdFont 20)
|
2021-06-23 23:08:50 -04:00
|
|
|
|
2021-11-27 17:33:02 -05:00
|
|
|
fontString :: Font -> String
|
|
|
|
fontString = snd . fontData
|
2021-06-23 23:08:50 -04:00
|
|
|
|
2021-11-27 17:33:02 -05:00
|
|
|
fontOffset :: Font -> Int
|
|
|
|
fontOffset = fst . fontData
|
2021-06-23 23:08:50 -04:00
|
|
|
|
2021-11-27 17:33:02 -05:00
|
|
|
allFonts :: [Font]
|
|
|
|
allFonts = enumFrom minBound
|
2021-06-21 23:41:57 -04:00
|
|
|
|
2021-11-27 17:33:02 -05:00
|
|
|
allFontOffsets :: [Int]
|
|
|
|
allFontOffsets = fontOffset <$> allFonts
|
|
|
|
|
|
|
|
allFontStrings :: [String]
|
|
|
|
allFontStrings = fontString <$> allFonts
|
2020-03-15 13:12:01 -04:00
|
|
|
|
2020-03-16 13:50:08 -04:00
|
|
|
barFont :: String
|
|
|
|
barFont = T.fmtFontXFT T.font
|
|
|
|
{ T.family = "DejaVu Sans Mono"
|
|
|
|
, T.size = Just 11
|
|
|
|
, T.weight = Just T.Bold
|
|
|
|
}
|
|
|
|
|
2021-11-05 21:15:37 -04:00
|
|
|
nerdFont :: Int -> String
|
|
|
|
nerdFont size = T.fmtFontXFT T.font
|
2021-06-30 22:47:49 -04:00
|
|
|
{ T.family = "Symbols Nerd Font"
|
2020-03-16 13:50:08 -04:00
|
|
|
, T.size = Nothing
|
2021-11-05 21:15:37 -04:00
|
|
|
, T.pixelsize = Just size
|
2020-03-16 13:50:08 -04:00
|
|
|
}
|
|
|
|
|
2021-11-27 17:33:02 -05:00
|
|
|
fontifyText :: Font -> String -> String
|
|
|
|
fontifyText fnt txt = concat ["<fn=", show $ fromEnum fnt, ">", txt, "</fn>"]
|
2021-11-05 21:15:37 -04:00
|
|
|
|
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
|
2021-11-26 23:35:03 -05:00
|
|
|
|