summaryrefslogtreecommitdiffhomepage
path: root/src/Xmobar/X11/Draw.hs
blob: 4f14d22c60a42f1a7356373221463a48bf801e63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
{-# LANGUAGE CPP #-}

------------------------------------------------------------------------------
-- |
-- Module: Xmobar.X11.Draw
-- Copyright: (c) 2018, 2020, 2022 Jose Antonio Ortega Ruiz
-- License: BSD3-style (see LICENSE)
--
-- Maintainer: jao@gnu.org
-- Stability: unstable
-- Portability: portable
-- Created: Sat Nov 24, 2018 18:49
--
--
-- Drawing the xmobar contents
--
------------------------------------------------------------------------------


module Xmobar.X11.Draw (drawInWin) where

import Control.Monad.IO.Class
import Control.Monad.Reader

import Graphics.X11.Xlib hiding (Segment)

import Xmobar.Run.Parsers (Segment)
import Xmobar.X11.Types

#ifdef CAIRO
import Xmobar.X11.CairoDraw
#else
import Xmobar.X11.XlibDraw
#endif

-- | Draws in and updates the window
drawInWin :: [[Segment]] -> X [ActionPos]
drawInWin segments = do
  xconf <- ask
  let d = display xconf
      w = window xconf
      (Rectangle _ _ wid ht) = rect xconf
      depth = defaultDepthOfScreen (defaultScreenOfDisplay d)
  p <- liftIO $ createPixmap d w wid ht depth
  gc <- liftIO $ createGC d w
  liftIO $ setGraphicsExposures d gc False

#ifdef CAIRO
  res <- drawInPixmap gc p segments
#else
  res <- updateActions (rect xconf) segments
  drawInPixmap gc p wid ht segments
#endif
  -- copy the pixmap with the new string to the window
  liftIO $ copyArea d p w gc 0 0 wid ht 0 0
  -- free up everything (we do not want to leak memory!)
  liftIO $ freeGC d gc
  liftIO $ freePixmap d p
  -- resync (discard events, we don't read/process events from this display conn)
  liftIO $ sync d True
  return res