summaryrefslogtreecommitdiffstats
path: root/XMonad/Stockholm/XUtils.hs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2015-11-09 17:44:50 +0100
committertv <tv@krebsco.de>2015-11-09 17:50:32 +0100
commit2dbefe42fc5cfe9093465bf3e22ba8f82feeef6e (patch)
tree1f82e4c70445e04d18837de6ec5e4a564d776fde /XMonad/Stockholm/XUtils.hs
initial import from stockholm's xmonad-tv
Diffstat (limited to 'XMonad/Stockholm/XUtils.hs')
-rw-r--r--XMonad/Stockholm/XUtils.hs47
1 files changed, 47 insertions, 0 deletions
diff --git a/XMonad/Stockholm/XUtils.hs b/XMonad/Stockholm/XUtils.hs
new file mode 100644
index 0000000..5b477b8
--- /dev/null
+++ b/XMonad/Stockholm/XUtils.hs
@@ -0,0 +1,47 @@
+module XMonad.Stockholm.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