From e39f66aac6805d832e8a5bc765ba9b385a20cd16 Mon Sep 17 00:00:00 2001 From: jao Date: Thu, 15 Sep 2022 15:34:00 +0100 Subject: new flag: with_xrender --- doc/compiling.org | 7 +++++-- src/Xmobar/X11/CairoDraw.hs | 18 ++++++++++++++++-- src/Xmobar/X11/Loop.hs | 7 ------- xmobar.cabal | 14 ++++++++++---- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/doc/compiling.org b/doc/compiling.org index b967292..6c707e5 100644 --- a/doc/compiling.org +++ b/doc/compiling.org @@ -57,8 +57,8 @@ them to =stack= directly: - =with_threaded= Uses GHC's threaded runtime. Use this option if xmobar enters a high-CPU regime right after starting. - - =with_cairo= Antialiased fonts via Cairo/Pango. Requires the [[http://hackage.haskell.org/package/X11-xft/][X11-xft]] - package. To use XFT fonts you can use their fontconfig name, e.g + - =with_cairo= Antialiased fonts via Cairo/Pango. For fonts, you can use + their fontconfig name, e.g #+begin_src haskell font = "Iosevka Medium 10" @@ -77,6 +77,9 @@ them to =stack= directly: font = "xft:DejaVu Sans Mono-10" #+end_src + - =with_xrender= Enables the main bar background alpha parameter. Requires + the [[http://hackage.haskell.org/package/X11-xft/][X11-xft]] package. + - =with_mpd= Enables support for the [[http://mpd.wikia.com/][MPD]] daemon. Requires the [[http://hackage.haskell.org/package/libmpd/][libmpd]] package. diff --git a/src/Xmobar/X11/CairoDraw.hs b/src/Xmobar/X11/CairoDraw.hs index e93e5ae..df6f1e4 100644 --- a/src/Xmobar/X11/CairoDraw.hs +++ b/src/Xmobar/X11/CairoDraw.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} ------------------------------------------------------------------------------ -- | -- Module: Xmobar.X11.CairoDraw @@ -43,7 +44,9 @@ import Xmobar.Config.Types import Xmobar.Text.Pango (fixXft) import Xmobar.X11.Types import qualified Xmobar.X11.Bitmap as B +#ifdef XRENDER import Xmobar.X11.XRender (drawBackground) +#endif import Xmobar.X11.CairoSurface type Renderinfo = (Segment, Surface -> Double -> Double -> IO (), Double) @@ -78,7 +81,9 @@ drawInPixmap gc p s = do conf = config xconf dc = DC (drawXBitmap xconf gc p) (lookupXBitmap xconf) conf dw dh s render = drawSegments dc +#ifdef XRENDER liftIO $ drawBackground disp p (bgColor conf) (alpha conf) (Rectangle 0 0 w h) +#endif liftIO $ withXlibSurface disp p vis (fromIntegral w) (fromIntegral h) render lookupXBitmap :: XConf -> String -> Maybe B.Bitmap @@ -193,7 +198,7 @@ drawSegment dctx surface maxoff (off, acts, boxs) (segment, render, lwidth) = do setSourceColor :: (SRGB.Colour Double, Double) -> C.Render () setSourceColor (colour, alph) = - C.setSourceRGBA r g b alph + if alph < 1 then C.setSourceRGBA r g b alph else C.setSourceRGB r g b where rgb = SRGB.toSRGB colour r = SRGB.channelRed rgb g = SRGB.channelGreen rgb @@ -235,6 +240,13 @@ drawBoxes dctx surf [bi] = drawBoxes' dctx surf bi drawBoxes _ _ [] = return () +#ifndef XRENDER +drawCairoBackground :: DrawContext -> Surface -> IO () +drawCairoBackground dctx surf = do + let (c, _) = readColourName (bgColor (dcConfig dctx)) + C.renderWith surf $ setSourceColor (c, 1.0) >> C.paint +#endif + drawSegments :: DrawContext -> Surface -> IO Actions drawSegments dctx surf = do let [left, center, right] = take 3 $ dcSegments dctx @@ -245,6 +257,9 @@ drawSegments dctx surf = do llyts <- mapM (withRenderinfo ctx dctx) left rlyts <- mapM (withRenderinfo ctx dctx) right clyts <- mapM (withRenderinfo ctx dctx) center +#ifndef XRENDER + drawCairoBackground dctx surf +#endif (lend, as, bx) <- foldM (drawSegment dctx surf dw) (0, [], []) llyts let rw = layoutsWidth rlyts rstart = max (lend + 1) (dw - rw - 1) @@ -253,7 +268,6 @@ drawSegments dctx surf = do cstart = lend + 1 + max 0 (dw - rw - lend - cw) / 2.0 (_, as', bx') <- foldM (drawSegment dctx surf cmax) (cstart, as, bx) clyts (_, as'', bx'') <- foldM (drawSegment dctx surf dw) (rstart, as', bx') rlyts - -- putStrLn $ show (reverse bx'') drawBoxes dctx surf (reverse bx'') when (borderWidth conf > 0) (drawBorder conf dw dh surf) return as'' diff --git a/src/Xmobar/X11/Loop.hs b/src/Xmobar/X11/Loop.hs index ea1c309..aeaf38a 100644 --- a/src/Xmobar/X11/Loop.hs +++ b/src/Xmobar/X11/Loop.hs @@ -58,10 +58,6 @@ import Xmobar.Run.Loop (loop) import Xmobar.X11.Events(nextEvent') #endif -#ifdef CAIRO -import Graphics.X11.Xft -#endif - runX :: XConf -> X a -> IO a runX xc f = runReaderT f xc @@ -72,9 +68,6 @@ x11Loop conf = do d <- openDisplay "" fs <- initFont d (font conf) fl <- mapM (initFont d) (additionalFonts conf) -#ifdef CAIRO - xftInitFtLibrary -#endif (r,w) <- createWin d fs conf loop conf (startLoop (XConf d r w (fs :| fl) Map.empty conf)) diff --git a/xmobar.cabal b/xmobar.cabal index a2958ad..3bf1dd6 100644 --- a/xmobar.cabal +++ b/xmobar.cabal @@ -32,6 +32,9 @@ source-repository head location: git://codeberg.org/xmobar/xmobar.git branch: master +flag with_xrender + description: Use XRender for alpha background pseudo-transparency. + flag with_cairo description: Use Cairo and Pango to render anti-aliased text. @@ -224,14 +227,17 @@ library if flag(with_rtsopts) cpp-options: -DRTSOPTS + if flag(with_xrender) + build-depends: X11-xft >= 0.2 + other-modules: Xmobar.X11.XRender + cpp-options: -DXRENDER + if flag(with_cairo) build-depends: cairo >= 0.13, pango >= 0.13, - colour >= 2.3.6, - X11-xft >= 0.2 + colour >= 2.3.6 other-modules: Xmobar.X11.CairoSurface, - Xmobar.X11.CairoDraw, - Xmobar.X11.XRender + Xmobar.X11.CairoDraw cpp-options: -DCAIRO else other-modules: Xmobar.X11.XlibDraw -- cgit v1.2.3