summaryrefslogtreecommitdiffstats
path: root/tv/2configs/xserver/xmonad/Util/XUtils.hs
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2015-10-27 18:12:29 +0100
committermakefu <github@syntax-fehler.de>2015-10-27 18:12:29 +0100
commita85114c59c5102b839584f72454bca2c8abbb887 (patch)
tree18fc24394171f4afae3dee0e68e3781df75723ea /tv/2configs/xserver/xmonad/Util/XUtils.hs
parentfe4f5b98b91f6bacb036d57b5322fb4e09c22f14 (diff)
parent20ad77468131b7c69c5b3a26ea149ae7fdc0173b (diff)
Merge branch 'master' of pnp:stockholm
Diffstat (limited to 'tv/2configs/xserver/xmonad/Util/XUtils.hs')
-rw-r--r--tv/2configs/xserver/xmonad/Util/XUtils.hs47
1 files changed, 47 insertions, 0 deletions
diff --git a/tv/2configs/xserver/xmonad/Util/XUtils.hs b/tv/2configs/xserver/xmonad/Util/XUtils.hs
new file mode 100644
index 000000000..de1d8247c
--- /dev/null
+++ b/tv/2configs/xserver/xmonad/Util/XUtils.hs
@@ -0,0 +1,47 @@
+module Util.XUtils
+ ( shapeWindow
+ , withGC
+ , withPixmap
+ , withPixmapAndGC
+ ) where
+
+import Control.Exception ( bracket )
+import Foreign.C.Types ( CInt )
+import Graphics.X11.Xlib
+import Graphics.X11.Xlib.Extras
+import Graphics.X11.Xshape
+
+
+shapeWindow :: Display -> Window -> (Pixmap -> GC -> IO ()) -> IO ()
+shapeWindow d w f = do
+ wa <- getWindowAttributes d w
+
+ let width = fromIntegral $ wa_width wa
+ height = fromIntegral $ wa_height wa
+
+ withPixmapAndGC d w width height 1 $ \ p g -> do
+
+ setForeground d g 0
+ fillRectangle d p g 0 0 width height
+
+ setForeground d g 1
+
+ f p g
+
+ xshapeCombineMask d w shapeBounding 0 0 p shapeSet
+
+
+withGC :: Display -> Drawable -> (GC -> IO ()) -> IO ()
+withGC d p =
+ bracket (createGC d p) (freeGC d)
+
+
+withPixmap :: Display -> Drawable -> Dimension -> Dimension -> CInt -> (Pixmap -> IO ()) -> IO ()
+withPixmap d p w h depth =
+ bracket (createPixmap d p w h depth) (freePixmap d)
+
+
+withPixmapAndGC :: Display -> Drawable -> Dimension -> Dimension -> CInt -> (Pixmap -> GC -> IO ()) -> IO ()
+withPixmapAndGC d w width height depth f =
+ withPixmap d w width height depth $ \ p ->
+ withGC d p $ \ g -> f p g