xmonad-config/lib/XMonad/Internal/Theme.hs

206 lines
5.4 KiB
Haskell
Raw Normal View History

{-# LANGUAGE OverloadedStrings #-}
2020-04-01 22:06:00 -04:00
--------------------------------------------------------------------------------
-- | Theme for XMonad and Xmobar
2020-04-01 20:17:47 -04:00
module XMonad.Internal.Theme
( baseColor
, bgColor
, fgColor
, bordersColor
, warningColor
, errorColor
, selectedFgColor
, selectedBgColor
, selectedBordersColor
, backdropBaseColor
, backdropFgColor
, backdropTextColor
, blend'
, darken'
, Slant(..)
, Weight(..)
2022-07-02 17:09:21 -04:00
, FontData(..)
, FontBuilder
, buildFont
, fallbackFont
, defFontFamily
2022-07-02 17:09:21 -04:00
, defFontData
2020-04-01 20:17:47 -04:00
, tabbedTheme
, promptTheme
) where
import Data.Colour
import Data.Colour.SRGB
import qualified RIO.Text as T
2020-03-16 13:50:08 -04:00
import qualified XMonad.Layout.Decoration as D
import qualified XMonad.Prompt as P
2020-03-16 13:50:08 -04:00
2020-04-01 22:06:00 -04:00
--------------------------------------------------------------------------------
-- | Colors - vocabulary roughly based on GTK themes
2020-03-16 13:50:08 -04:00
baseColor :: T.Text
2020-03-16 13:50:08 -04:00
baseColor = "#f7f7f7"
bgColor :: T.Text
2020-03-16 13:50:08 -04:00
bgColor = "#d6d6d6"
fgColor :: T.Text
2020-03-16 14:48:38 -04:00
fgColor = "#2c2c2c"
2020-03-16 13:50:08 -04:00
bordersColor :: T.Text
2020-03-22 17:59:49 -04:00
bordersColor = darken' 0.3 bgColor
2020-03-16 13:50:08 -04:00
warningColor :: T.Text
2020-03-16 13:50:08 -04:00
warningColor = "#ffca28"
errorColor :: T.Text
2020-03-16 13:50:08 -04:00
errorColor = "#e53935"
selectedFgColor :: T.Text
2020-03-16 13:50:08 -04:00
selectedFgColor = "#ffffff"
selectedBgColor :: T.Text
2021-11-05 16:54:53 -04:00
selectedBgColor = "#4a79c7"
2020-03-16 13:50:08 -04:00
selectedBordersColor :: T.Text
2021-11-05 16:54:53 -04:00
selectedBordersColor = "#4a79c7"
2020-03-22 17:59:49 -04:00
backdropBaseColor :: T.Text
2020-03-16 13:50:08 -04:00
backdropBaseColor = baseColor
backdropTextColor :: T.Text
2020-03-16 13:50:08 -04:00
backdropTextColor = blend' 0.95 fgColor backdropBaseColor
backdropFgColor :: T.Text
2020-03-16 13:50:08 -04:00
backdropFgColor = blend' 0.75 fgColor bgColor
2020-04-01 22:06:00 -04:00
--------------------------------------------------------------------------------
-- | Color functions
2020-03-16 13:50:08 -04:00
blend' :: Float -> T.Text -> T.Text -> T.Text
blend' wt c0 c1 = sRGB24showT $ blend wt (sRGB24readT c0) (sRGB24readT c1)
darken' :: Float -> T.Text -> T.Text
darken' wt = sRGB24showT . darken wt . sRGB24readT
sRGB24readT :: (RealFrac a, Floating a) => T.Text -> Colour a
sRGB24readT = sRGB24read . T.unpack
2020-03-16 13:50:08 -04:00
sRGB24showT :: (RealFrac a, Floating a) => Colour a -> T.Text
sRGB24showT = T.pack . sRGB24show
2020-03-16 13:50:08 -04:00
2020-04-01 22:06:00 -04:00
--------------------------------------------------------------------------------
-- | Fonts
2020-03-16 13:50:08 -04:00
2020-03-22 17:59:49 -04:00
data Slant = Roman
| Italic
| Oblique
deriving (Eq, Show)
data Weight = Light
| Medium
| Demibold
| Bold
| Black
deriving (Eq, Show)
2022-07-02 17:09:21 -04:00
data FontData = FontData
{ weight :: Maybe Weight
2020-03-22 17:59:49 -04:00
, slant :: Maybe Slant
, size :: Maybe Int
, pixelsize :: Maybe Int
, antialias :: Maybe Bool
}
2020-03-16 13:50:08 -04:00
type FontBuilder = FontData -> T.Text
2022-07-02 17:09:21 -04:00
buildFont :: Maybe T.Text -> FontData -> T.Text
2022-07-02 17:09:21 -04:00
buildFont Nothing _ = "fixed"
buildFont (Just fam) FontData { weight = w
, slant = l
, size = s
, pixelsize = p
, antialias = a
}
= T.intercalate ":" $ ["xft", fam] ++ elems
2020-03-16 13:50:08 -04:00
where
elems = [ T.concat [k, "=", v] | (k, Just v) <- [ ("weight", showLower w)
, ("slant", showLower l)
, ("size", showLower s)
, ("pixelsize", showLower p)
, ("antialias", showLower a)
]
2020-04-01 21:03:00 -04:00
]
showLower :: Show a => Maybe a -> Maybe T.Text
showLower = fmap (T.toLower . T.pack . show)
2020-03-16 13:50:08 -04:00
2022-07-03 18:23:32 -04:00
fallbackFont :: FontBuilder
fallbackFont = buildFont Nothing
2022-07-02 17:09:21 -04:00
--------------------------------------------------------------------------------
-- | Default font and data
defFontData :: FontData
defFontData = FontData
{ size = Just 10
2020-03-16 13:50:08 -04:00
, antialias = Just True
, weight = Nothing
, slant = Nothing
, pixelsize = Nothing
}
defFontFamily :: T.Text
defFontFamily = "DejaVu Sans"
2022-07-03 18:23:32 -04:00
-- defFontDep :: IODependency FontBuilder
-- defFontDep = fontDependency "DejaVu Sans"
-- defFontTree :: IOTree FontBuilder
-- defFontTree = fontTree "DejaVu Sans"
2022-07-02 17:09:21 -04:00
2020-04-01 22:06:00 -04:00
--------------------------------------------------------------------------------
-- | Complete themes
2020-03-16 13:50:08 -04:00
2022-07-02 17:09:21 -04:00
tabbedTheme :: FontBuilder -> D.Theme
tabbedTheme fb = D.def
{ D.fontName = T.unpack $ fb $ defFontData { weight = Just Bold }
2020-03-16 13:50:08 -04:00
, D.activeTextColor = T.unpack fgColor
, D.activeColor = T.unpack bgColor
, D.activeBorderColor = T.unpack bgColor
2020-03-16 13:50:08 -04:00
, D.inactiveTextColor = T.unpack backdropTextColor
, D.inactiveColor = T.unpack backdropFgColor
, D.inactiveBorderColor = T.unpack backdropFgColor
2020-03-16 13:50:08 -04:00
, D.urgentTextColor = T.unpack $ darken' 0.5 errorColor
, D.urgentColor = T.unpack errorColor
, D.urgentBorderColor = T.unpack errorColor
2020-03-16 13:50:08 -04:00
-- this is in a newer version
-- , D.activeBorderWidth = 0
-- , D.inactiveBorderWidth = 0
-- , D.urgentBorderWidth = 0
, D.decoHeight = 20
, D.windowTitleAddons = []
, D.windowTitleIcons = []
2022-07-02 17:09:21 -04:00
}
2020-03-16 13:50:08 -04:00
2022-07-02 17:09:21 -04:00
promptTheme :: FontBuilder -> P.XPConfig
promptTheme fb = P.def
{ P.font = T.unpack $ fb $ defFontData { size = Just 12 }
, P.bgColor = T.unpack bgColor
, P.fgColor = T.unpack fgColor
, P.fgHLight = T.unpack selectedFgColor
, P.bgHLight = T.unpack selectedBgColor
, P.borderColor = T.unpack bordersColor
2020-03-16 13:50:08 -04:00
, P.promptBorderWidth = 1
2020-04-01 22:49:36 -04:00
, P.height = 35
2020-03-16 13:50:08 -04:00
, P.position = P.CenteredAt 0.5 0.5
, P.historySize = 0
2020-03-16 13:50:08 -04:00
}