summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorjgrocho <codeberg@jon.grocho.net>2022-11-30 06:07:50 +0000
committerjao <mail@jao.io>2022-11-30 06:07:50 +0000
commit94f9c2c282b24c68403b8456279b09f5f05d37fc (patch)
treeb011492a032f2ca6e851631291fdd532c988334e
parent2a30cb05d0ff98d36bd34eb21de993b23334d4b1 (diff)
downloadxmobar-94f9c2c282b24c68403b8456279b09f5f05d37fc.tar.gz
xmobar-94f9c2c282b24c68403b8456279b09f5f05d37fc.tar.bz2
Adds DPI configuration (#660)
Adds a new DPI configuration, especially useful for HiDPI displays. This changes the scaling factor for fonts as displayed by Pango. It defaults to 96.0 which corresponds to an average screen and is the default in [Cairo](https://hackage.haskell.org/package/pango-0.13.5.0/docs/Graphics-Rendering-Pango-Cairo.html#v:cairoFontMapGetDefault). It's also possible to supply a zero or negative value to use the default scaling factor, but I felt setting the default to 96.0 makes it more explicit. It also adds a matching command line option. I haven't tested it too thoroughly, but in my limited use it appears to be working as intended. One thing this does not do is scale XBM and XPM bitmap files which I'm unsure how to do or if that should even be our concern (instead leaving it up to the user to supply appropriate bitmaps). Co-authored-by: Jonathan Grochowski <jon@grocho.net> Reviewed-on: https://codeberg.org/xmobar/xmobar/pulls/660 Co-authored-by: jgrocho <codeberg@jon.grocho.net> Co-committed-by: jgrocho <codeberg@jon.grocho.net>
-rw-r--r--doc/quick-start.org6
-rw-r--r--src/Xmobar/App/Config.hs1
-rw-r--r--src/Xmobar/App/Opts.hs4
-rw-r--r--src/Xmobar/Config/Parse.hs5
-rw-r--r--src/Xmobar/Config/Types.hs1
-rw-r--r--src/Xmobar/Draw/Cairo.hs1
6 files changed, 16 insertions, 2 deletions
diff --git a/doc/quick-start.org b/doc/quick-start.org
index 53c4803..b013446 100644
--- a/doc/quick-start.org
+++ b/doc/quick-start.org
@@ -48,6 +48,7 @@ configuration language, see [[../etc/xmobar.config][etc/xmobar.config]], and you
-x screen --screen=screen On which X screen number to start
-p position --position=position Specify position of xmobar. Same syntax as in config file
-T [format] --text[=format] Write output to stdout
+ -D dpi --dpi=dpi The DPI scaling factor. Default 96.0
Mail bug reports and suggestions to <mail@jao.io>
#+end_example
@@ -77,6 +78,11 @@ configuration language, see [[../etc/xmobar.config][etc/xmobar.config]], and you
additionalFonts = [iconFont, altIconFont]
#+end_src
+ - =dpi= The DPI scaling factor, as a decimal, to use. If 0, negative, or not
+ given, the default of 96 will be used, which corresponds to an average
+ screen. A 10pt font will therefore scale to 10pt * (1/72 pt/inch) * (96
+ pixel/inch) = 13.3 pixel. This is especially useful for HiDPI displays.
+
The global font is used by default when none of the others is specified
using the ~<fn=n>...</fn>~ markup, with ~n~ a 1-based index in the
~additionalFonts~ array. So, for instance
diff --git a/src/Xmobar/App/Config.hs b/src/Xmobar/App/Config.hs
index a284973..5c2f362 100644
--- a/src/Xmobar/App/Config.hs
+++ b/src/Xmobar/App/Config.hs
@@ -67,6 +67,7 @@ defaultConfig =
, signal = SignalChan Nothing
, textOutput = False
, textOutputFormat = Plain
+ , dpi = 96.0
}
-- | Return the path to the xmobar data directory. This directory is
diff --git a/src/Xmobar/App/Opts.hs b/src/Xmobar/App/Opts.hs
index 3a6b4e7..bc01435 100644
--- a/src/Xmobar/App/Opts.hs
+++ b/src/Xmobar/App/Opts.hs
@@ -52,6 +52,7 @@ data Opts = Help
| Position String
| WmClass String
| WmName String
+ | Dpi String
deriving (Show, Eq)
options :: [OptDescr Opts]
@@ -95,6 +96,8 @@ options =
"On which X screen number to start"
, Option "p" ["position"] (ReqArg Position "position")
"Specify position of xmobar. Same syntax as in config file"
+ , Option "D" ["dpi"] (ReqArg Dpi "dpi")
+ "The DPI scaling factor. Default 96.0"
]
getOpts :: [String] -> IO ([Opts], [String])
@@ -161,6 +164,7 @@ doOpts conf (o:oo) =
Right x -> doOpts' (conf {commands = commands conf ++ x})
Left e -> putStr (e ++ usage) >> exitWith (ExitFailure 1)
Position s -> readPosition s
+ Dpi d -> doOpts' (conf {dpi = read d})
where readCom c str =
case readStr str of
[x] -> Right x
diff --git a/src/Xmobar/Config/Parse.hs b/src/Xmobar/Config/Parse.hs
index 23de4db..0b41267 100644
--- a/src/Xmobar/Config/Parse.hs
+++ b/src/Xmobar/Config/Parse.hs
@@ -72,7 +72,7 @@ parseConfig defaultConfig =
<|?> pAllDesktops <|?> pOverrideRedirect <|?> pPickBroadest
<|?> pLowerOnStart <|?> pPersistent <|?> pIconRoot
<|?> pCommands <|?> pSepChar <|?> pAlignSep <|?> pTemplate
- <|?> pVerbose <|?> pSignal
+ <|?> pVerbose <|?> pSignal <|?> pDpi
fields = [ "font", "additionalFonts", "bgColor", "fgColor"
, "wmClass", "wmName", "sepChar"
@@ -81,7 +81,7 @@ parseConfig defaultConfig =
, "allDesktops", "overrideRedirect", "pickBroadest"
, "hideOnStart", "lowerOnStart", "persistent", "iconRoot"
, "alpha", "commands", "verbose", "signal", "textOutput"
- , "textOutputFormat"
+ , "textOutputFormat", "dpi"
]
pTextOutput = readField textOutput "textOutput"
@@ -112,6 +112,7 @@ parseConfig defaultConfig =
pIconRoot = readField iconRoot "iconRoot"
pAlpha = readField alpha "alpha"
pVerbose = readField verbose "verbose"
+ pDpi = readField dpi "dpi"
pSignal = field signal "signal" $
fail "signal is meant for use with Xmobar as a library.\n It is not meant for use in the configuration file."
diff --git a/src/Xmobar/Config/Types.hs b/src/Xmobar/Config/Types.hs
index ea7b958..785b55b 100644
--- a/src/Xmobar/Config/Types.hs
+++ b/src/Xmobar/Config/Types.hs
@@ -85,6 +85,7 @@ data Config =
, template :: String -- ^ The output template
, verbose :: Bool -- ^ Emit additional debug messages
, signal :: SignalChan -- ^ Channel to send signals to xmobar
+ , dpi :: Double -- ^ DPI scaling factor for fonts
} deriving (Read, Show)
-- | The position datatype
diff --git a/src/Xmobar/Draw/Cairo.hs b/src/Xmobar/Draw/Cairo.hs
index d9f7ced..dfcfd14 100644
--- a/src/Xmobar/Draw/Cairo.hs
+++ b/src/Xmobar/Draw/Cairo.hs
@@ -172,6 +172,7 @@ drawSegments dctx surf = do
conf = T.dcConfig dctx
sWidth = foldl (\a (_,_,w) -> a + w) 0
ctx <- Pango.cairoCreateContext Nothing
+ Pango.cairoContextSetResolution ctx $ C.dpi conf
llyts <- mapM (withRenderinfo ctx dctx) left
rlyts <- mapM (withRenderinfo ctx dctx) right
clyts <- mapM (withRenderinfo ctx dctx) center