xmonad/X11

rawGetWindowProperty should perhaps return an array instead of a list

Opened this issue · 3 comments

for very large properties such as "_NET_WM_ICON" lists can be slow enough that it makes certain things unfeasible.

A compatible solution could be to provide a more generic

peekWindowProperty  Storable a  (Int  Ptr a  IO b)  Int  Display  Atom  Window  IO (Maybe b)
peekWindowProperty peekFunction bits d atom w =
    -- Implementation like current implementation of `rawGetWindowProperty`,
    -- but with `peekArray` replaced by `peekFunction`.

rawGetWindowProperty  Storable a  Int  Display  Atom  Window  IO (Maybe [a])
rawGetWindowProperty = peekWindowProperty peekArray

This could then be used with Data.StorableVector.peek or a function based on Data.Vector.Storable.unsafeFromForeignPtr0. The same interface would also allow to use Foreign.C.String.peekCStringLen to obtain a String directly.

A probably more natural solution would be to directly return the pointer to the data and the data’s length as in

getWindowPropertyPtr  Storable a  Int  Display  Atom  Window  IO (Maybe (ForeignPtr a, Int))

with xFree registered as finalizer for the returned pointer.

@mgkurtz yeah i think I prefer the second option you preferred here.