xmonad / X11

A Haskell binding to the X11 graphics library.
http://hackage.haskell.org/package/X11
Other
103 stars 49 forks source link

Add `getWindowPropertyPtr` returning `IO (Maybe (ForeignPtr a, Int))` #104

Open mgkurtz opened 4 months ago

mgkurtz commented 4 months ago

This is a draft for the concept discussed in #52. Actually, I did not even test it (beyond building). Quite likely, I have cheated when setting the type of xFreePtr to FinalizerPtr a = FunPtr (Ptr a → IO ()) instead of FunPtr (Ptr a → IO Int). I do not know, what would be a clean solution here.

As I am not very experienced with regards to Haskell building and testing, I would appreciate any help.

geekosaur commented 4 months ago

I've been thinking about this, and I'm not sure it's a good idea to expose internals like that; it's usually better to pull C values into Haskell and immediately free the C side instead. The main exception would be when you want to make a ByteString from it, in which case you want https://downloads.haskell.org/ghc/9.2.5/docs/html/libraries/bytestring-0.11.3.1/Data-ByteString-Unsafe.html#v:unsafePackCStringFinalizer.