haskell-gi-base 0.24.2 → 0.24.3
raw patch · 10 files changed
+306/−245 lines, 10 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.GI.Base: [On] :: (GObject obj, SignalInfo info) => SignalProxy obj info -> HaskellCallbackType info -> AttrOp obj tag
+ Data.GI.Base.Attributes: [On] :: (GObject obj, SignalInfo info) => SignalProxy obj info -> HaskellCallbackType info -> AttrOp obj tag
+ Data.GI.Base.GParamSpec: AnotherGParamFlag :: Int -> GParamFlag
+ Data.GI.Base.GParamSpec: GParamConstruct :: GParamFlag
+ Data.GI.Base.GParamSpec: GParamConstructOnly :: GParamFlag
+ Data.GI.Base.GParamSpec: GParamExplicitNotify :: GParamFlag
+ Data.GI.Base.GParamSpec: GParamReadable :: GParamFlag
+ Data.GI.Base.GParamSpec: GParamWritable :: GParamFlag
+ Data.GI.Base.GParamSpec: data GParamFlag
+ Data.GI.Base.ShortPrelude: [On] :: (GObject obj, SignalInfo info) => SignalProxy obj info -> HaskellCallbackType info -> AttrOp obj tag
Files
- ChangeLog.md +4/−0
- Data/GI/Base/Attributes.hs +9/−0
- Data/GI/Base/GError.hsc +2/−2
- Data/GI/Base/GObject.hsc +22/−12
- Data/GI/Base/GParamSpec.hsc +1/−0
- Data/GI/Base/ManagedPtr.hs +6/−3
- Data/GI/Base/Signals.hs +226/−0
- Data/GI/Base/Signals.hs-boot +34/−0
- Data/GI/Base/Signals.hsc +0/−226
- haskell-gi-base.cabal +2/−2
ChangeLog.md view
@@ -1,3 +1,7 @@+### 0.24.3+++ Require hsc2hs version 0.68.6 or higher+ ### 0.24.2 + Provide type init functions for GParamSpec types.
Data/GI/Base/Attributes.hs view
@@ -146,11 +146,15 @@ AttrLabelProxy(..) ) where +import Control.Monad (void) import Control.Monad.IO.Class (MonadIO, liftIO) +import Data.GI.Base.BasicTypes (GObject) import Data.GI.Base.GValue (GValueConstruct) import Data.GI.Base.Overloading (HasAttributeList, ResolveAttribute) +import {-# SOURCE #-} Data.GI.Base.Signals (SignalInfo(..), SignalProxy, on)+ import Data.Proxy (Proxy(..)) import GHC.TypeLits@@ -434,6 +438,9 @@ (AttrTransferTypeConstraint info) b, AttrSetTypeConstraint info (AttrTransferType info)) => AttrLabelProxy (attr :: Symbol) -> b -> AttrOp obj tag+ -- | Connect the given signal to a signal handler.+ On :: (GObject obj, SignalInfo info) =>+ SignalProxy obj info -> HaskellCallbackType info -> AttrOp obj tag -- | Set a number of properties for some object. set :: forall o m. MonadIO m => o -> [AttrOp o 'AttrSet] -> m ()@@ -457,6 +464,8 @@ app ((_attr :: AttrLabelProxy label) :&= x) = attrTransfer @(ResolveAttribute label o) (Proxy @o) x >>= attrSet @(ResolveAttribute label o) obj++ app (On signal callback) = void $ on obj signal callback -- | Constraints on a @obj@\/@attr@ pair so `get` is possible, -- producing a value of type @result@.
Data/GI/Base/GError.hsc view
@@ -108,7 +108,7 @@ instance GBoxed GError -- | A GQuark.-type GQuark = #type GQuark+type GQuark = #{type GQuark} -- | A code used to identify the "namespace" of the error. Within each error -- domain all the error codes are defined in an enumeration. Each gtk\/gnome@@ -122,7 +122,7 @@ -- enumeration type for each error domain. Of course which enumeration to use -- depends on the error domain, but if you use 'catchGErrorJustDomain' or -- 'handleGErrorJustDomain', this is worked out for you automatically.-type GErrorCode = #type gint+type GErrorCode = #{type gint} -- | A human readable error message. type GErrorMessage = Text
Data/GI/Base/GObject.hsc view
@@ -37,18 +37,19 @@ , gobjectInstallCStringProperty ) where +import Data.Maybe (catMaybes)+import Control.Monad (void) import Control.Monad.IO.Class (MonadIO, liftIO) import Data.Proxy (Proxy(..)) import Data.Coerce (coerce) import Foreign.C (CUInt(..), CString, newCString)-#if !MIN_VERSION_base(4,13,0)-import Foreign.Ptr (FunPtr)+import Foreign.Ptr (Ptr, FunPtr, nullPtr, castPtr, plusPtr) import Foreign.StablePtr (newStablePtr, deRefStablePtr, castStablePtrToPtr, castPtrToStablePtr)-#endif-import Foreign+import Foreign.Storable (Storable(peek, poke, pokeByteOff, sizeOf))+import Foreign (mallocBytes, copyBytes, free) #if !MIN_VERSION_base(4,11,0) import Data.Monoid ((<>))@@ -76,6 +77,7 @@ import Data.GI.Base.ManagedPtr (withManagedPtr, touchManagedPtr, wrapObject, newObject) import Data.GI.Base.Overloading (ResolveAttribute)+import Data.GI.Base.Signals (on) import Data.GI.Base.Utils (dbgLog) #include <glib-object.h>@@ -91,20 +93,28 @@ -> [AttrOp o 'AttrConstruct] -> m o constructGObject constructor attrs = liftIO $ do- props <- mapM construct attrs- doConstructGObject constructor props+ props <- catMaybes <$> mapM construct attrs+ obj <- doConstructGObject constructor props+ mapM_ (setSignal obj) attrs+ return obj where construct :: AttrOp o 'AttrConstruct ->- IO (GValueConstruct o)+ IO (Maybe (GValueConstruct o)) construct ((_attr :: AttrLabelProxy label) := x) =- attrConstruct @(ResolveAttribute label o) x+ Just <$> attrConstruct @(ResolveAttribute label o) x construct ((_attr :: AttrLabelProxy label) :=> x) =- x >>= attrConstruct @(ResolveAttribute label o)+ Just <$> (x >>= attrConstruct @(ResolveAttribute label o)) - construct ((_attr :: AttrLabelProxy label) :&= x) =- attrTransfer @(ResolveAttribute label o) (Proxy @o) x >>=- attrConstruct @(ResolveAttribute label o)+ construct ((_attr :: AttrLabelProxy label) :&= x) = Just <$>+ (attrTransfer @(ResolveAttribute label o) (Proxy @o) x >>=+ attrConstruct @(ResolveAttribute label o))++ construct (On _ _) = return Nothing++ setSignal :: GObject o => o -> AttrOp o 'AttrConstruct -> IO ()+ setSignal obj (On signal callback) = void $ on obj signal callback+ setSignal _ _ = return () -- | Construct the given `GObject`, given a set of actions -- constructing desired `GValue`s to set at construction time.
Data/GI/Base/GParamSpec.hsc view
@@ -20,6 +20,7 @@ , gParamSpecCString , CIntPropertyInfo(..) , gParamSpecCInt+ , GParamFlag(..) -- * Get\/Set , PropGetSetter(..)
Data/GI/Base/ManagedPtr.hs view
@@ -98,9 +98,12 @@ ownedFinalizer finalizer ptr allocCallStack callStackRef = do cs <- readIORef callStackRef -- cs will be @Just cs@ whenever the pointer has been disowned.- when (isNothing cs) $ do- maybe (return ()) (printAllocDebug ptr) allocCallStack- finalizer+ when (isNothing cs) $ case allocCallStack of+ Just acs -> do+ printAllocDebug ptr acs+ finalizer+ dbgLog (T.pack "Released successfully.\n")+ Nothing -> finalizer -- | Print some debug diagnostics for an allocation. printAllocDebug :: Ptr a -> CallStack -> IO ()
+ Data/GI/Base/Signals.hs view
@@ -0,0 +1,226 @@+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE ConstraintKinds #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE PolyKinds #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE GADTs #-}+{-# LANGUAGE EmptyDataDecls #-}+{-# LANGUAGE UndecidableInstances #-}+{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE TypeApplications #-}+{-# LANGUAGE AllowAmbiguousTypes #-}++-- | Routines for connecting `GObject`s to signals. There are two+-- basic variants, 'on' and 'after', which correspond to+-- <https://developer.gnome.org/gobject/stable/gobject-Signals.html#g-signal-connect g_signal_connect> and <https://developer.gnome.org/gobject/stable/gobject-Signals.html#g-signal-connect-after g_signal_connect_after>, respectively.+--+-- Basic usage is+--+-- @ 'on' widget #signalName $ do ... @+--+-- or+--+-- @ 'after' widget #signalName $ do ... @+--+-- Note that in the Haskell bindings we represent the signal name in+-- camelCase, so a signal like <https://webkitgtk.org/reference/webkit2gtk/stable/WebKitUserContentManager.html#WebKitUserContentManager-script-message-received script-message-received> in the original API becomes <https://hackage.haskell.org/package/gi-webkit2-4.0.24/docs/GI-WebKit2-Objects-UserContentManager.html#g:16 scriptMessageReceived> in the bindings.+--+-- There are two variants of note. If you want to provide a detail+-- when connecting the signal you can use ':::', as follows:+--+-- @ 'on' widget (#scriptMessageReceived ':::' "handlerName") $ do ... @+--+-- On the other hand, if you want to connect to the "<https://hackage.haskell.org/package/gi-gobject-2.0.21/docs/GI-GObject-Objects-Object.html#g:30 notify>" signal for a property of a widget, it is recommended to use instead 'PropertyNotify', as follows:+--+-- @ 'on' widget ('PropertyNotify' #propertyName) $ do ... @+--+-- which has the advantage that it will be checked at compile time+-- that the widget does indeed have the property "@propertyName@".+module Data.GI.Base.Signals+ ( on+ , after+ , SignalProxy(..)+ , SignalConnectMode(..)+ , connectSignalFunPtr+ , disconnectSignalHandler+ , SignalHandlerId+ , SignalInfo(..)+ , GObjectNotifySignalInfo+ , SignalCodeGenError+ ) where++import Control.Monad.IO.Class (MonadIO, liftIO)+import Data.Proxy (Proxy(..))+#if !MIN_VERSION_base(4,11,0)+import Data.Monoid ((<>))+#endif++import Foreign+import Foreign.C+#if !MIN_VERSION_base(4,13,0)+import Foreign.Ptr (nullPtr)+#endif++import GHC.TypeLits++import qualified Data.Text as T+import Data.Text (Text)++import Data.GI.Base.Attributes (AttrLabelProxy(..), AttrInfo(AttrLabel))+import Data.GI.Base.BasicConversions (withTextCString)+import Data.GI.Base.BasicTypes+import Data.GI.Base.GParamSpec (newGParamSpecFromPtr)+import Data.GI.Base.ManagedPtr (withManagedPtr)+import Data.GI.Base.Overloading (ResolveSignal, ResolveAttribute)++import GHC.OverloadedLabels (IsLabel(..))++-- | Type of a `GObject` signal handler id.+type SignalHandlerId = CULong++-- | Support for overloaded signal connectors.+data SignalProxy (object :: *) (info :: *) where+ -- | A basic signal name connector.+ SignalProxy :: SignalProxy o info+ -- | A signal connector annotated with a detail.+ (:::) :: forall o info. SignalProxy o info -> Text -> SignalProxy o info+ -- | A signal connector for the @notify@ signal on the given property.+ PropertyNotify :: (info ~ ResolveAttribute propName o,+ AttrInfo info,+ pl ~ AttrLabel info, KnownSymbol pl) =>+ AttrLabelProxy propName ->+ SignalProxy o GObjectNotifySignalInfo++-- | Support for overloaded labels.+instance (info ~ ResolveSignal slot object) =>+ IsLabel slot (SignalProxy object info) where+#if MIN_VERSION_base(4,10,0)+ fromLabel = SignalProxy+#else+ fromLabel _ = SignalProxy+#endif++-- | Information about an overloaded signal.+class SignalInfo (info :: *) where+ -- | The type for the signal handler.+ type HaskellCallbackType info :: *+ -- | Connect a Haskell function to a signal of the given+ -- `GObject`, specifying whether the handler will be called before+ -- or after the default handler.+ connectSignal :: GObject o =>+ o ->+ HaskellCallbackType info ->+ SignalConnectMode ->+ Maybe Text ->+ IO SignalHandlerId++-- | Whether to connect a handler to a signal with `connectSignal` so+-- that it runs before/after the default handler for the given signal.+data SignalConnectMode = SignalConnectBefore -- ^ Run before the default handler.+ | SignalConnectAfter -- ^ Run after the default handler.++-- | Connect a signal to a signal handler.+on :: forall object info m.+ (GObject object, MonadIO m, SignalInfo info) =>+ object -> SignalProxy object info+ -> HaskellCallbackType info -> m SignalHandlerId+on o p c =+ liftIO $ connectSignal @info o c SignalConnectBefore (proxyDetail p)++-- | Connect a signal to a handler, running the handler after the default one.+after :: forall object info m.+ (GObject object, MonadIO m, SignalInfo info) =>+ object -> SignalProxy object info+ -> HaskellCallbackType info -> m SignalHandlerId+after o p c =+ liftIO $ connectSignal @info o c SignalConnectAfter (proxyDetail p)++-- | Given a signal proxy, determine the corresponding detail.+proxyDetail :: forall object info. SignalProxy object info -> Maybe Text+proxyDetail p = case p of+ SignalProxy -> Nothing+ (_ ::: detail) -> Just detail+ PropertyNotify (AttrLabelProxy :: AttrLabelProxy propName) ->+ Just . T.pack $ symbolVal (Proxy @(AttrLabel (ResolveAttribute propName object)))++-- Connecting GObjects to signals+foreign import ccall g_signal_connect_data ::+ Ptr a -> -- instance+ CString -> -- detailed_signal+ FunPtr b -> -- c_handler+ Ptr () -> -- data+ FunPtr c -> -- destroy_data+ CUInt -> -- connect_flags+ IO SignalHandlerId++-- Releasing the `FunPtr` for the signal handler.+foreign import ccall "& haskell_gi_release_signal_closure"+ ptr_to_release_closure :: FunPtr (Ptr () -> Ptr () -> IO ())++-- | Connect a signal to a handler, given as a `FunPtr`.+connectSignalFunPtr :: GObject o =>+ o -> Text -> FunPtr a -> SignalConnectMode ->+ Maybe Text -> IO SignalHandlerId+connectSignalFunPtr object signal fn mode maybeDetail = do+ let flags = case mode of+ SignalConnectAfter -> 1+ SignalConnectBefore -> 0+ signalSpec = case maybeDetail of+ Nothing -> signal+ Just detail -> signal <> "::" <> detail+ withTextCString signalSpec $ \csignal ->+ withManagedPtr object $ \objPtr ->+ g_signal_connect_data objPtr csignal fn nullPtr ptr_to_release_closure flags++foreign import ccall g_signal_handler_disconnect :: Ptr o -> SignalHandlerId -> IO ()++-- | Disconnect a previously connected signal.+disconnectSignalHandler :: GObject o => o -> SignalHandlerId -> IO ()+disconnectSignalHandler obj handlerId =+ withManagedPtr obj $ \objPtr ->+ g_signal_handler_disconnect objPtr handlerId++-- | Connection information for a "notify" signal indicating that a+-- specific property changed (see `PropertyNotify` for the relevant+-- constructor).+data GObjectNotifySignalInfo+instance SignalInfo GObjectNotifySignalInfo where+ type HaskellCallbackType GObjectNotifySignalInfo = GObjectNotifyCallback+ connectSignal = connectGObjectNotify++-- | Type for a `GObject` "notify" callback.+type GObjectNotifyCallback = GParamSpec -> IO ()++gobjectNotifyCallbackWrapper ::+ GObjectNotifyCallback -> Ptr () -> Ptr GParamSpec -> Ptr () -> IO ()+gobjectNotifyCallbackWrapper _cb _ pspec _ = do+ pspec' <- newGParamSpecFromPtr pspec+ _cb pspec'++type GObjectNotifyCallbackC = Ptr () -> Ptr GParamSpec -> Ptr () -> IO ()++foreign import ccall "wrapper"+ mkGObjectNotifyCallback :: GObjectNotifyCallbackC -> IO (FunPtr GObjectNotifyCallbackC)++-- | Connect the given notify callback for a GObject.+connectGObjectNotify :: GObject o =>+ o -> GObjectNotifyCallback ->+ SignalConnectMode ->+ Maybe Text ->+ IO SignalHandlerId+connectGObjectNotify obj cb mode detail = do+ cb' <- mkGObjectNotifyCallback (gobjectNotifyCallbackWrapper cb)+ connectSignalFunPtr obj "notify" cb' mode detail++-- | Generate an informative type error whenever one tries to use a+-- signal for which code generation has failed.+type family SignalCodeGenError (signalName :: Symbol) :: * where+ SignalCodeGenError signalName = TypeError+ ('Text "The signal ‘"+ ':<>: 'Text signalName+ ':<>: 'Text "’ is not supported, because haskell-gi failed to generate appropriate bindings."+ ':$$: 'Text "Please file an issue at https://github.com/haskell-gi/haskell-gi/issues.")
+ Data/GI/Base/Signals.hs-boot view
@@ -0,0 +1,34 @@+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE AllowAmbiguousTypes #-}+{-# LANGUAGE GADTs #-}+{-# LANGUAGE RoleAnnotations #-}++module Data.GI.Base.Signals (SignalInfo(..), SignalProxy, on) where++import Data.GI.Base.BasicTypes (GObject)+import Control.Monad.IO.Class (MonadIO)+import Foreign.C (CULong)+import Data.Text (Text)++data SignalConnectMode = SignalConnectBefore+ | SignalConnectAfter++class SignalInfo info where+ type HaskellCallbackType info+ connectSignal :: GObject o =>+ o ->+ HaskellCallbackType info ->+ SignalConnectMode ->+ Maybe Text ->+ IO SignalHandlerId++type role SignalProxy nominal nominal+data SignalProxy object info where++type SignalHandlerId = CULong++on :: forall object info m.+ (GObject object, MonadIO m, SignalInfo info) =>+ object -> SignalProxy object info+ -> HaskellCallbackType info -> m SignalHandlerId
− Data/GI/Base/Signals.hsc
@@ -1,226 +0,0 @@-{-# LANGUAGE OverloadedStrings #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE ConstraintKinds #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE PolyKinds #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE GADTs #-}-{-# LANGUAGE EmptyDataDecls #-}-{-# LANGUAGE UndecidableInstances #-}-{-# LANGUAGE TypeOperators #-}-{-# LANGUAGE TypeApplications #-}-{-# LANGUAGE AllowAmbiguousTypes #-}---- | Routines for connecting `GObject`s to signals. There are two--- basic variants, 'on' and 'after', which correspond to--- <https://developer.gnome.org/gobject/stable/gobject-Signals.html#g-signal-connect g_signal_connect> and <https://developer.gnome.org/gobject/stable/gobject-Signals.html#g-signal-connect-after g_signal_connect_after>, respectively.------ Basic usage is------ @ 'on' widget #signalName $ do ... @------ or------ @ 'after' widget #signalName $ do ... @------ Note that in the Haskell bindings we represent the signal name in--- camelCase, so a signal like <https://webkitgtk.org/reference/webkit2gtk/stable/WebKitUserContentManager.html#WebKitUserContentManager-script-message-received script-message-received> in the original API becomes <https://hackage.haskell.org/package/gi-webkit2-4.0.24/docs/GI-WebKit2-Objects-UserContentManager.html#g:16 scriptMessageReceived> in the bindings.------ There are two variants of note. If you want to provide a detail--- when connecting the signal you can use ':::', as follows:------ @ 'on' widget (#scriptMessageReceived ':::' "handlerName") $ do ... @------ On the other hand, if you want to connect to the "<https://hackage.haskell.org/package/gi-gobject-2.0.21/docs/GI-GObject-Objects-Object.html#g:30 notify>" signal for a property of a widget, it is recommended to use instead 'PropertyNotify', as follows:------ @ 'on' widget ('PropertyNotify' #propertyName) $ do ... @------ which has the advantage that it will be checked at compile time--- that the widget does indeed have the property "@propertyName@".-module Data.GI.Base.Signals- ( on- , after- , SignalProxy(..)- , SignalConnectMode(..)- , connectSignalFunPtr- , disconnectSignalHandler- , SignalHandlerId- , SignalInfo(..)- , GObjectNotifySignalInfo- , SignalCodeGenError- ) where--import Control.Monad.IO.Class (MonadIO, liftIO)-import Data.Proxy (Proxy(..))-#if !MIN_VERSION_base(4,11,0)-import Data.Monoid ((<>))-#endif--import Foreign-import Foreign.C-#if !MIN_VERSION_base(4,13,0)-import Foreign.Ptr (nullPtr)-#endif--import GHC.TypeLits--import qualified Data.Text as T-import Data.Text (Text)--import Data.GI.Base.Attributes (AttrLabelProxy(..), AttrInfo(AttrLabel))-import Data.GI.Base.BasicConversions (withTextCString)-import Data.GI.Base.BasicTypes-import Data.GI.Base.GParamSpec (newGParamSpecFromPtr)-import Data.GI.Base.ManagedPtr (withManagedPtr)-import Data.GI.Base.Overloading (ResolveSignal, ResolveAttribute)--import GHC.OverloadedLabels (IsLabel(..))---- | Type of a `GObject` signal handler id.-type SignalHandlerId = CULong---- | Support for overloaded signal connectors.-data SignalProxy (object :: *) (info :: *) where- -- | A basic signal name connector.- SignalProxy :: SignalProxy o info- -- | A signal connector annotated with a detail.- (:::) :: forall o info. SignalProxy o info -> Text -> SignalProxy o info- -- | A signal connector for the @notify@ signal on the given property.- PropertyNotify :: (info ~ ResolveAttribute propName o,- AttrInfo info,- pl ~ AttrLabel info, KnownSymbol pl) =>- AttrLabelProxy propName ->- SignalProxy o GObjectNotifySignalInfo---- | Support for overloaded labels.-instance (info ~ ResolveSignal slot object) =>- IsLabel slot (SignalProxy object info) where-#if MIN_VERSION_base(4,10,0)- fromLabel = SignalProxy-#else- fromLabel _ = SignalProxy-#endif---- | Information about an overloaded signal.-class SignalInfo (info :: *) where- -- | The type for the signal handler.- type HaskellCallbackType info :: *- -- | Connect a Haskell function to a signal of the given- -- `GObject`, specifying whether the handler will be called before- -- or after the default handler.- connectSignal :: GObject o =>- o ->- HaskellCallbackType info ->- SignalConnectMode ->- Maybe Text ->- IO SignalHandlerId---- | Whether to connect a handler to a signal with `connectSignal` so--- that it runs before/after the default handler for the given signal.-data SignalConnectMode = SignalConnectBefore -- ^ Run before the default handler.- | SignalConnectAfter -- ^ Run after the default handler.---- | Connect a signal to a signal handler.-on :: forall object info m.- (GObject object, MonadIO m, SignalInfo info) =>- object -> SignalProxy object info- -> HaskellCallbackType info -> m SignalHandlerId-on o p c =- liftIO $ connectSignal @info o c SignalConnectBefore (proxyDetail p)---- | Connect a signal to a handler, running the handler after the default one.-after :: forall object info m.- (GObject object, MonadIO m, SignalInfo info) =>- object -> SignalProxy object info- -> HaskellCallbackType info -> m SignalHandlerId-after o p c =- liftIO $ connectSignal @info o c SignalConnectAfter (proxyDetail p)---- | Given a signal proxy, determine the corresponding detail.-proxyDetail :: forall object info. SignalProxy object info -> Maybe Text-proxyDetail p = case p of- SignalProxy -> Nothing- (_ ::: detail) -> Just detail- PropertyNotify (AttrLabelProxy :: AttrLabelProxy propName) ->- Just . T.pack $ symbolVal (Proxy @(AttrLabel (ResolveAttribute propName object)))---- Connecting GObjects to signals-foreign import ccall g_signal_connect_data ::- Ptr a -> -- instance- CString -> -- detailed_signal- FunPtr b -> -- c_handler- Ptr () -> -- data- FunPtr c -> -- destroy_data- CUInt -> -- connect_flags- IO SignalHandlerId---- Releasing the `FunPtr` for the signal handler.-foreign import ccall "& haskell_gi_release_signal_closure"- ptr_to_release_closure :: FunPtr (Ptr () -> Ptr () -> IO ())---- | Connect a signal to a handler, given as a `FunPtr`.-connectSignalFunPtr :: GObject o =>- o -> Text -> FunPtr a -> SignalConnectMode ->- Maybe Text -> IO SignalHandlerId-connectSignalFunPtr object signal fn mode maybeDetail = do- let flags = case mode of- SignalConnectAfter -> 1- SignalConnectBefore -> 0- signalSpec = case maybeDetail of- Nothing -> signal- Just detail -> signal <> "::" <> detail- withTextCString signalSpec $ \csignal ->- withManagedPtr object $ \objPtr ->- g_signal_connect_data objPtr csignal fn nullPtr ptr_to_release_closure flags--foreign import ccall g_signal_handler_disconnect :: Ptr o -> SignalHandlerId -> IO ()---- | Disconnect a previously connected signal.-disconnectSignalHandler :: GObject o => o -> SignalHandlerId -> IO ()-disconnectSignalHandler obj handlerId =- withManagedPtr obj $ \objPtr ->- g_signal_handler_disconnect objPtr handlerId---- | Connection information for a "notify" signal indicating that a--- specific property changed (see `PropertyNotify` for the relevant--- constructor).-data GObjectNotifySignalInfo-instance SignalInfo GObjectNotifySignalInfo where- type HaskellCallbackType GObjectNotifySignalInfo = GObjectNotifyCallback- connectSignal = connectGObjectNotify---- | Type for a `GObject` "notify" callback.-type GObjectNotifyCallback = GParamSpec -> IO ()--gobjectNotifyCallbackWrapper ::- GObjectNotifyCallback -> Ptr () -> Ptr GParamSpec -> Ptr () -> IO ()-gobjectNotifyCallbackWrapper _cb _ pspec _ = do- pspec' <- newGParamSpecFromPtr pspec- _cb pspec'--type GObjectNotifyCallbackC = Ptr () -> Ptr GParamSpec -> Ptr () -> IO ()--foreign import ccall "wrapper"- mkGObjectNotifyCallback :: GObjectNotifyCallbackC -> IO (FunPtr GObjectNotifyCallbackC)---- | Connect the given notify callback for a GObject.-connectGObjectNotify :: GObject o =>- o -> GObjectNotifyCallback ->- SignalConnectMode ->- Maybe Text ->- IO SignalHandlerId-connectGObjectNotify obj cb mode detail = do- cb' <- mkGObjectNotifyCallback (gobjectNotifyCallbackWrapper cb)- connectSignalFunPtr obj "notify" cb' mode detail---- | Generate an informative type error whenever one tries to use a--- signal for which code generation has failed.-type family SignalCodeGenError (signalName :: Symbol) :: * where- SignalCodeGenError signalName = TypeError- ('Text "The signal ‘"- ':<>: 'Text signalName- ':<>: 'Text "’ is not supported, because haskell-gi failed to generate appropriate bindings."- ':$$: 'Text "Please file an issue at https://github.com/haskell-gi/haskell-gi/issues.")
haskell-gi-base.cabal view
@@ -1,5 +1,5 @@ name: haskell-gi-base-version: 0.24.2+version: 0.24.3 synopsis: Foundation for libraries generated by haskell-gi description: Foundation for libraries generated by haskell-gi homepage: https://github.com/haskell-gi/haskell-gi@@ -53,7 +53,7 @@ ghc-options: -Wall -Wno-redundant-constraints -fwarn-incomplete-patterns - build-tool-depends: hsc2hs:hsc2hs >= 0.68.5+ build-tool-depends: hsc2hs:hsc2hs >= 0.68.6 cc-options: -fPIC default-language: Haskell2010 default-extensions: CPP, ForeignFunctionInterface, DoAndIfThenElse, MonoLocalBinds