-
Notifications
You must be signed in to change notification settings - Fork 0
/
GtkHelpers.hs
42 lines (33 loc) · 1.38 KB
/
GtkHelpers.hs
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
{-# LANGUAGE ForeignFunctionInterface, EmptyDataDecls #-}
module GtkHelpers (
drawWindowInputShapeCombineRegion,
drawWindowSetOverrideRedirect,
withCairoRegion
) where
import Control.Exception
import Foreign.Ptr
import Foreign.ForeignPtr
import Foreign.C.Types
import Graphics.UI.Gtk
import System.Glib.GObject
data CairoRegion
foreign import ccall unsafe
cairo_region_create :: IO (Ptr CairoRegion)
foreign import ccall unsafe
cairo_region_destroy :: Ptr CairoRegion -> IO ()
foreign import ccall unsafe
gdk_window_input_shape_combine_region :: Ptr GObject -> Ptr CairoRegion -> CInt -> CInt -> IO ()
foreign import ccall unsafe
gdk_window_set_override_redirect :: Ptr GObject -> CInt -> IO ()
drawWindowInputShapeCombineRegion :: DrawWindowClass self => self -> Ptr CairoRegion -> Int -> Int -> IO ()
drawWindowInputShapeCombineRegion self region offX offY =
withForeignPtr (unGObject (toGObject self)) $ \ptrSelf ->
gdk_window_input_shape_combine_region ptrSelf region cOffX cOffY
where
cOffX = fromIntegral offX
cOffY = fromIntegral offY
withCairoRegion = bracket cairo_region_create cairo_region_destroy
drawWindowSetOverrideRedirect :: DrawWindowClass self => self -> Bool -> IO ()
drawWindowSetOverrideRedirect self bool =
withForeignPtr (unGObject (toGObject self)) $ \ptrSelf ->
gdk_window_set_override_redirect ptrSelf (fromIntegral $ fromEnum bool)