X11-extras 0.3 → 0.4
raw patch · 2 files changed
+189/−4 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Graphics.X11.Xlib.Extras: ExposeEvent :: !EventType -> !CULong -> !Bool -> Display -> !Window -> !CInt -> !CInt -> !CInt -> !CInt -> !CInt -> Event
+ Graphics.X11.Xlib.Extras: FontSet :: (Ptr FontSet) -> FontSet
+ Graphics.X11.Xlib.Extras: PropertyEvent :: !EventType -> !CULong -> !Bool -> Display -> !Window -> !Atom -> !Time -> !CInt -> Event
+ Graphics.X11.Xlib.Extras: SelectionRequest :: !EventType -> !CULong -> !Bool -> Display -> !Window -> !Window -> !Atom -> !Atom -> !Atom -> !Time -> Event
+ Graphics.X11.Xlib.Extras: createFontSet :: Display -> String -> IO ([String], String, FontSet)
+ Graphics.X11.Xlib.Extras: ev_atom :: Event -> !Atom
+ Graphics.X11.Xlib.Extras: ev_owner :: Event -> !Window
+ Graphics.X11.Xlib.Extras: ev_property :: Event -> !Atom
+ Graphics.X11.Xlib.Extras: ev_propstate :: Event -> !CInt
+ Graphics.X11.Xlib.Extras: ev_requestor :: Event -> !Window
+ Graphics.X11.Xlib.Extras: ev_selection :: Event -> !Atom
+ Graphics.X11.Xlib.Extras: ev_target :: Event -> !Atom
+ Graphics.X11.Xlib.Extras: freeFontSet :: Display -> FontSet -> IO ()
+ Graphics.X11.Xlib.Extras: freeStringList :: Ptr CString -> IO ()
+ Graphics.X11.Xlib.Extras: instance Eq FontSet
+ Graphics.X11.Xlib.Extras: instance Ord FontSet
+ Graphics.X11.Xlib.Extras: instance Show FontSet
+ Graphics.X11.Xlib.Extras: newtype FontSet
+ Graphics.X11.Xlib.Extras: setSelectionNotify :: XEventPtr -> Window -> Atom -> Atom -> Atom -> Time -> IO ()
+ Graphics.X11.Xlib.Extras: wcDrawImageString :: Display -> Drawable -> FontSet -> GC -> Position -> Position -> String -> IO ()
+ Graphics.X11.Xlib.Extras: wcDrawString :: Display -> Drawable -> FontSet -> GC -> Position -> Position -> String -> IO ()
+ Graphics.X11.Xlib.Extras: wcTextEscapement :: FontSet -> String -> Int32
+ Graphics.X11.Xlib.Extras: wcTextExtents :: FontSet -> String -> (Rectangle, Rectangle)
+ Graphics.X11.Xlib.Extras: xCreateFontSet :: Display -> CString -> Ptr (Ptr CString) -> Ptr CInt -> Ptr CString -> IO (Ptr FontSet)
+ Graphics.X11.Xlib.Extras: xwcDrawImageString :: Display -> Drawable -> FontSet -> GC -> Position -> Position -> CWString -> CInt -> IO ()
+ Graphics.X11.Xlib.Extras: xwcDrawString :: Display -> Drawable -> FontSet -> GC -> Position -> Position -> CWString -> CInt -> IO ()
+ Graphics.X11.Xlib.Extras: xwcTextEscapement :: FontSet -> CWString -> CInt -> IO Int32
+ Graphics.X11.Xlib.Extras: xwcTextExtents :: FontSet -> CWString -> CInt -> Ptr Rectangle -> Ptr Rectangle -> IO CInt
Files
- Graphics/X11/Xlib/Extras.hsc +188/−3
- X11-extras.cabal +1/−1
Graphics/X11/Xlib/Extras.hsc view
@@ -170,6 +170,40 @@ , ev_focus :: !Bool , ev_state :: !Modifier }+ | SelectionRequest+ { ev_event_type :: !EventType+ , ev_serial :: !CULong+ , ev_send_event :: !Bool+ , ev_event_display :: Display+ , ev_owner :: !Window+ , ev_requestor :: !Window+ , ev_selection :: !Atom+ , ev_target :: !Atom+ , ev_property :: !Atom+ , ev_time :: !Time+ }+ | PropertyEvent+ { ev_event_type :: !EventType+ , ev_serial :: !CULong+ , ev_send_event :: !Bool+ , ev_event_display :: Display+ , ev_window :: !Window+ , ev_atom :: !Atom+ , ev_time :: !Time+ , ev_propstate :: !CInt+ }+ | ExposeEvent+ { ev_event_type :: !EventType+ , ev_serial :: !CULong+ , ev_send_event :: !Bool+ , ev_event_display :: Display+ , ev_window :: !Window+ , ev_x :: !CInt+ , ev_y :: !CInt+ , ev_width :: !CInt+ , ev_height :: !CInt+ , ev_count :: !CInt+ } deriving ( Show, Typeable ) @@ -479,6 +513,71 @@ , ev_state = fromIntegral state } + -------------------------+ -- SelectionRequestEvent:+ -------------------------+ | type_ == selectionRequest -> do+ owner <- #{peek XSelectionRequestEvent, owner } p+ requestor <- #{peek XSelectionRequestEvent, requestor } p+ selection <- #{peek XSelectionRequestEvent, selection } p+ target <- #{peek XSelectionRequestEvent, target } p+ property <- #{peek XSelectionRequestEvent, property } p+ time <- #{peek XSelectionRequestEvent, time } p+ return $ SelectionRequest+ { ev_event_type = type_+ , ev_serial = serial+ , ev_send_event = send_event+ , ev_event_display = display+ , ev_owner = owner+ , ev_requestor = requestor+ , ev_selection = selection+ , ev_target = target+ , ev_property = property+ , ev_time = time+ }++ -------------------------+ -- PropertyEvent+ -------------------------+ | type_ == propertyNotify -> do+ window <- #{peek XPropertyEvent, window } p+ atom <- #{peek XPropertyEvent, atom } p+ time <- #{peek XPropertyEvent, time } p+ state <- #{peek XPropertyEvent, state } p+ return $ PropertyEvent+ { ev_event_type = type_+ , ev_serial = serial+ , ev_send_event = send_event+ , ev_event_display = display+ , ev_window = window+ , ev_atom = atom+ , ev_time = time+ , ev_propstate = state+ }++ -------------------------+ -- ExposeEvent+ -------------------------+ | type_ == expose -> do+ window <- #{peek XExposeEvent, window } p+ x <- #{peek XExposeEvent, x } p+ y <- #{peek XExposeEvent, y } p+ width <- #{peek XExposeEvent, width } p+ height <- #{peek XExposeEvent, height } p+ count <- #{peek XExposeEvent, count } p+ return $ ExposeEvent+ { ev_event_type = type_+ , ev_serial = serial+ , ev_send_event = send_event+ , ev_event_display = display+ , ev_window = window+ , ev_x = x+ , ev_y = y+ , ev_width = width+ , ev_height = height+ , ev_count = count+ }+ -- We don't handle this event specifically, so return the generic -- AnyEvent. | otherwise -> do@@ -629,9 +728,6 @@ f ungrabServer dpy -foreign import ccall unsafe "XlibExtras.h XFetchName"- xFetchName :: Display -> Window -> Ptr CString -> IO Status- data TextProperty = TextProperty { tp_value :: CString, tp_encoding :: Atom,@@ -681,6 +777,72 @@ foreign import ccall unsafe "XlibExtras.h XwcFreeStringList" wcFreeStringList :: Ptr CWString -> IO () +newtype FontSet = FontSet (Ptr FontSet)+ deriving (Eq, Ord, Show)++foreign import ccall unsafe "XlibExtras.h XCreateFontSet"+ xCreateFontSet :: Display -> CString -> Ptr (Ptr CString) -> Ptr CInt -> Ptr CString -> IO (Ptr FontSet)++createFontSet :: Display -> String -> IO ([String], String, FontSet)+createFontSet d fn =+ withCString fn $ \fontp ->+ alloca $ \listp ->+ alloca $ \countp ->+ alloca $ \defp -> do+ fs <- throwIfNull "createFontSet" $+ xCreateFontSet d fontp listp countp defp+ count <- peek countp+ list <- peek listp+ missing <- flip mapM [0..fromIntegral count - 1] $ \i ->+ peekElemOff list i >>= peekCString+ def <- peek defp >>= peekCString+ freeStringList list+ return (missing, def, FontSet fs)++foreign import ccall unsafe "XlibExtras.h XFreeStringList"+ freeStringList :: Ptr CString -> IO ()++foreign import ccall unsafe "XlibExtras.h XFreeFontSet"+ freeFontSet :: Display -> FontSet -> IO ()++foreign import ccall unsafe "XlibExtras.h XwcTextExtents"+ xwcTextExtents :: FontSet -> CWString -> CInt -> Ptr Rectangle -> Ptr Rectangle -> IO CInt++wcTextExtents :: FontSet -> String -> (Rectangle, Rectangle)+wcTextExtents fs text = unsafePerformIO $+ withCWStringLen text $ \(textp, len) ->+ alloca $ \inkp ->+ alloca $ \logicalp -> do+ xwcTextExtents fs textp (fromIntegral len) inkp logicalp+ (,) `fmap` peek inkp `ap` peek logicalp++foreign import ccall unsafe "XlibExtras.h XwcDrawString"+ xwcDrawString :: Display -> Drawable -> FontSet -> GC -> Position -> Position -> CWString -> CInt -> IO ()++wcDrawString :: Display -> Drawable -> FontSet -> GC -> Position -> Position -> String -> IO ()+wcDrawString d w fs gc x y =+ flip withCWStringLen $ \(s, len) ->+ xwcDrawString d w fs gc x y s (fromIntegral len)++foreign import ccall unsafe "XlibExtras.h XwcDrawImageString"+ xwcDrawImageString :: Display -> Drawable -> FontSet -> GC -> Position -> Position -> CWString -> CInt -> IO ()++wcDrawImageString :: Display -> Drawable -> FontSet -> GC -> Position -> Position -> String -> IO ()+wcDrawImageString d w fs gc x y =+ flip withCWStringLen $ \(s, len) ->+ xwcDrawImageString d w fs gc x y s (fromIntegral len)++foreign import ccall unsafe "XlibExtras.h XwcTextEscapement"+ xwcTextEscapement :: FontSet -> CWString -> CInt -> IO Int32++wcTextEscapement :: FontSet -> String -> Int32+wcTextEscapement font_set string = unsafePerformIO $+ withCWStringLen string $ \ (c_string, len) ->+ xwcTextEscapement font_set c_string (fromIntegral len)++foreign import ccall unsafe "XlibExtras.h XFetchName"+ xFetchName :: Display -> Window -> Ptr CString -> IO Status+ fetchName :: Display -> Window -> IO (Maybe String) fetchName d w = alloca $ \p -> do xFetchName d w p@@ -749,6 +911,29 @@ setEventType :: XEventPtr -> EventType -> IO () setEventType = #{poke XEvent,type}++{-+typedef struct {+ int type; /* SelectionNotify */+ unsigned long serial; /* # of last request processed by server */+ Bool send_event; /* true if this came from a SendEvent request */+ Display *display; /* Display the event was read from */+ Window requestor;+ Atom selection;+ Atom target;+ Atom property; /* atom or None */+ Time time;+} XSelectionEvent;+-}++setSelectionNotify :: XEventPtr -> Window -> Atom -> Atom -> Atom -> Time -> IO ()+setSelectionNotify p requestor selection target property time = do+ setEventType p selectionNotify+ #{poke XSelectionEvent, requestor} p requestor+ #{poke XSelectionEvent, selection} p selection+ #{poke XSelectionEvent, target} p target+ #{poke XSelectionEvent, property} p property+ #{poke XSelectionEvent, time} p time -- hacky way to set up an XClientMessageEvent -- Should have a Storable instance for XEvent/Event?
X11-extras.cabal view
@@ -1,5 +1,5 @@ name: X11-extras-version: 0.3+version: 0.4 license: BSD3 license-file: LICENSE author: Spencer Janssen