mirror of
https://codeberg.org/leana8959/.files.git
synced 2025-12-06 14:49:14 +00:00
vanadium/xmobar: make dpi aware
This commit is contained in:
parent
96508e6638
commit
d638f445e3
1 changed files with 43 additions and 1 deletions
|
|
@ -2,6 +2,48 @@ import Xmobar
|
|||
|
||||
import Data.Function ((&))
|
||||
import Data.List (intercalate)
|
||||
import Data.Map qualified as M
|
||||
import System.Process
|
||||
|
||||
parseXRDB :: String -> M.Map String String
|
||||
parseXRDB = M.fromList . parseXRDBLines . lines
|
||||
|
||||
parseXRDBLines :: [String] -> [(String, String)]
|
||||
parseXRDBLines = map parseXRDBLine
|
||||
|
||||
parseXRDBLine :: String -> (String, String)
|
||||
parseXRDBLine s = case break (== ':') s of
|
||||
(k, ':' : v) -> (k, dropWhile (== '\t') v)
|
||||
_ -> error $ "Failed to parse " <> s
|
||||
|
||||
-- | Hack to adapt the bar height, fontsize, etc, with the chosen dpi in XRDB
|
||||
withDynamicDPI :: Config -> IO Config
|
||||
withDynamicDPI cfg = do
|
||||
xrdbConfig <- parseXRDB <$> readCreateProcess (shell "xrdb -query") mempty
|
||||
case xrdbConfig M.!? "Xft.dpi" of
|
||||
Nothing -> pure cfg
|
||||
Just dpiStr ->
|
||||
let
|
||||
dpi = read dpiStr
|
||||
|
||||
-- In case of low DPI:
|
||||
-- * reduce height
|
||||
-- * increase font size
|
||||
isLowDPI = dpi < 120
|
||||
|
||||
updatePosition (BottomH x) = BottomH $ if isLowDPI then 15 else x
|
||||
updatePosition x = x
|
||||
|
||||
updateFontSize x = k <> " " <> v'
|
||||
where
|
||||
(k, ' ' : v) = break (== ' ') x
|
||||
v' = if isLowDPI then "9" else v
|
||||
in
|
||||
pure $ cfg
|
||||
{ dpi = dpi
|
||||
, position = updatePosition (position cfg)
|
||||
, font = updateFontSize (font cfg)
|
||||
}
|
||||
|
||||
config :: Config
|
||||
config =
|
||||
|
|
@ -99,4 +141,4 @@ minute :: Int -> Int
|
|||
minute = (* 60) . second
|
||||
|
||||
main :: IO ()
|
||||
main = xmobar config
|
||||
main = withDynamicDPI config >>= xmobar
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue