           makeNewGObject (GObject, objectUnrefFromMainloop) (return obj1) >>= \obj1' ->
           callback (unsafeCastGObject obj2')
 
+eventListenerNewAsync :: EventClass event => (event -> IO ()) -> IO EventListener
+eventListenerNewAsync = eventListenerNew
+
+eventListenerNewSync :: EventClass event => (event -> IO ()) -> IO EventListener
+eventListenerNewSync = eventListenerNew
+
+foreign import ccall unsafe "g_closure_unref"
+  g_closure_unref :: Ptr GClosure -> IO ()
+
+eventListenerRelease :: EventListener -> IO ()
+eventListenerRelease (EventListener gclosurePtr sptr) = do
+  g_closure_unref gclosurePtr
+  freeStablePtr sptr
+
+

  toEventListener a = a

foreign import ccall unsafe "gtk2hs_closure_new"
  gtk2hs_closure_new :: StablePtr a -> IO (Ptr EventListener)

eventListenerNew :: EventClass event => (event -> IO ()) -> IO EventListener
eventListenerNew callback = do -- EventListener . castRef <$> syncCallback1 AlwaysRetain True (callback . unsafeCastGObject . GObject)
  sptr <- newStablePtr action
  gclosurePtr <- gtk2hs_closure_new sptr
  return $ EventListener gclosurePtr
  where action :: Ptr GObject -> Ptr GObject -> IO ()
        action obj1 obj2 =
          failOnGError $

{-# LANGUAGE CPP #-}
{-# CFILES events.c #-}
module Graphics.UI.Gtk.WebKit.DOM.EventTargetClosures
       (EventName(..), SaferEventListener(..), EventListener(..), unEventListener, EventListenerClass(..),
       eventListenerNew, eventListenerNewAsync, eventListenerNewSync, eventListenerRelease) where
import Control.Monad.Reader (ReaderT)
import System.Glib.FFI (newStablePtr, freeStablePtr, StablePtr, Ptr(..), toBool, CInt(..), CChar,
        withForeignPtr, fromBool)
import System.Glib.UTFString
import Control.Applicative
