From 684fee419fb6ee35efd28c196b0c520d800fffa9 Mon Sep 17 00:00:00 2001 From: jao Date: Fri, 16 Sep 2022 05:15:09 +0100 Subject: cairo: outer boxes fixes --- src/Xmobar/X11/Boxes.hs | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/Xmobar/X11/Boxes.hs (limited to 'src/Xmobar/X11/Boxes.hs') diff --git a/src/Xmobar/X11/Boxes.hs b/src/Xmobar/X11/Boxes.hs new file mode 100644 index 0000000..c0eeeed --- /dev/null +++ b/src/Xmobar/X11/Boxes.hs @@ -0,0 +1,52 @@ +------------------------------------------------------------------------------ +-- | +-- Module: Xmobar.X11.Boxes +-- Copyright: (c) 2022 Jose Antonio Ortega Ruiz +-- License: BSD3-style (see LICENSE) +-- +-- Maintainer: jao@gnu.org +-- Stability: unstable +-- Portability: unportable +--Start date: Fri Sep 16, 2022 04:01 +-- +-- Borders and boxes +-- +------------------------------------------------------------------------------ + +module Xmobar.X11.Boxes (boxLines, borderRect) where + +import Xmobar.Run.Parsers +import Xmobar.Config.Types + +boxLines :: Box -> Double -> Double -> Double -> [(Double, Double, Double, Double)] +boxLines (Box bd offset lw _ margins) ht x0 x1 = + case bd of + BBTop -> [rtop]; BBBottom -> [rbot]; BBVBoth -> [rtop, rbot] + BBLeft -> [rleft]; BBRight -> [rright]; BBHBoth -> [rleft, rright] + BBFull -> [rtop, rbot, rleft, rright] + where (BoxMargins top right bot left) = margins + (BoxOffset align m) = offset + ma = fromIntegral m + (p0, p1) = case align of L -> (0, -ma); C -> (ma, -ma); R -> (ma, 0) + lc = fromIntegral lw / 2 + [mt, mr, mb, ml] = map fromIntegral [top, right, bot, left] + xmin = x0 - ml - lc + xmax = x1 + mr + lc + ymin = mt + lc + ymax = ht - mb - lc + rtop = (xmin + p0, ymin, xmax + p1, ymin) + rbot = (xmin + p0, ymax, xmax + p1, ymax) + rleft = (xmin, ymin + p0, xmin, ymax + p1) + rright = (xmax, ymin + p0, xmax, ymax + p1) + +borderRect :: Border -> Double -> Double -> (Double, Double, Double, Double) +borderRect bdr w h = + case bdr of + TopB -> (0, 0, w - 1, 0) + BottomB -> (0, h - 1, w - 1, 0) + FullB -> (0, 0, w - 1, h - 1) + TopBM m -> (0, fi m, w - 1, 0) + BottomBM m -> (0, h - fi m, w - 1, 0) + FullBM m -> (fi m, fi m, w - 2 * fi m, h - 2 * fi m) + NoBorder -> (-1, -1, -1, -1) + where fi = fromIntegral -- cgit v1.2.3