X11 icon indicating copy to clipboard operation
X11 copied to clipboard

rawGetWindowProperty should perhaps return an array instead of a list

Open colonelpanic8 opened this issue 7 years ago • 3 comments

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

colonelpanic8 avatar May 12 '17 22:05 colonelpanic8

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.

mgkurtz avatar Apr 27 '24 19:04 mgkurtz

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 avatar Apr 28 '24 15:04 mgkurtz

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

colonelpanic8 avatar Apr 28 '24 22:04 colonelpanic8