1 patch for repository http://code.haskell.org/X11: Sun Apr 24 17:08:44 CEST 2011 athas@sigkill.dk * Add support for X resource functions. New patches: [Add support for X resource functions. athas@sigkill.dk**20110424150844 Ignore-this: 42fdaf3f6ba4bcd85c18243fc404b820 ] { hunk ./Graphics/X11/Xlib.hs 32 Display, Screen, Visual, GC, SetWindowAttributes, Point(..), Rectangle(..), Arc(..), Segment(..), Color(..), Pixel, Position, Dimension, Angle, ScreenNumber, Buffer, + RMDatabase(..), RMValue(..), -- * X11 library functions module Graphics.X11.Xlib.Event, hunk ./Graphics/X11/Xlib/Misc.hsc 18 module Graphics.X11.Xlib.Misc( - rmInitialize, autoRepeatOff, autoRepeatOn, bell, hunk ./Graphics/X11/Xlib/Misc.hsc 161 -- * Window properties setTextProperty, + -- * Resource manager + rmInitialize, + rmGetFileDatabase, + rmPutFileDatabase, + rmGetStringDatabase, + rmLocaleOfDatabase, + rmDestroyDatabase, + rmSetDatabase, + rmGetDatabase, + rmCombineFileDatabase, + rmCombineDatabase, + rmMergeDatabases, + rmGetResource, + rmPutResource, + rmPutStringResource, + rmPutLineResource, + getDefault, + rmValue, + ) where import Graphics.X11.Types hunk ./Graphics/X11/Xlib/Misc.hsc 1222 -- %code Status err = XSetStandardProperties(arg1,arg2,arg3,arg4,arg5,arg6,arg6_size,&arg7) -- %fail { Success != err }{ BadStatus(err,XSetStandardProperties) } +---------------------------------------------------------------- +-- Resource manager +---------------------------------------------------------------- + +-- | interface to the X11 library function @XrmInitialize()@. +foreign import ccall unsafe "HsXlib.h XrmInitialize" + rmInitialize :: IO () + +-- | interface to the X11 library function @XrmGetFileDatabase()@. +rmGetFileDatabase :: String -> IO (Maybe RMDatabase) +rmGetFileDatabase file = withCString file $ \ c_file -> do + RMDatabase db <- xrmGetFileDatabase c_file + if db == nullPtr + then return Nothing + else return $ Just $ RMDatabase db +foreign import ccall unsafe "HsXlib.h XrmGetFileDatabase" + xrmGetFileDatabase :: CString -> IO RMDatabase + +-- | interface to the X11 library function @XrmPutFileDatabase()@. +rmPutFileDatabase :: RMDatabase -> String -> IO () +rmPutFileDatabase db file = withCString file $ \ c_file -> + xrmPutFileDatabase db c_file +foreign import ccall unsafe "HsXlib.h XrmPutFileDatabase" + xrmPutFileDatabase :: RMDatabase -> CString -> IO () + +-- | interface to the X11 library function @XrmGetStringDatabase()@. +rmGetStringDatabase :: String -> IO RMDatabase +rmGetStringDatabase s = withCString s $ \ c_s -> + xrmGetStringDatabase c_s +foreign import ccall unsafe "HsXlib.h XrmGetStringDatabase" + xrmGetStringDatabase :: CString -> IO RMDatabase + +-- | interface to the X11 library function @XrmLocaleOfDatabase()@. +rmLocaleOfDatabase :: RMDatabase -> IO String +rmLocaleOfDatabase db = peekCString =<< xrmLocaleOfDatabase db +foreign import ccall unsafe "HsXlib.h XrmLocaleOfDatabase" + xrmLocaleOfDatabase :: RMDatabase -> IO CString + +-- | interface to the X11 library function @XrmDestroyDatabase()@. +foreign import ccall unsafe "HsXlib.h XrmDestroyDatabase" + rmDestroyDatabase :: RMDatabase -> IO () + +-- | interface to the X11 library function @XrmSetDatabase()@. +foreign import ccall unsafe "HsXlib.h XrmSetDatabase" + rmSetDatabase :: Display -> RMDatabase -> IO () + +-- | interface to the X11 library function @XrmGetDatabase()@. +rmGetDatabase :: Display -> IO (Maybe RMDatabase) +rmGetDatabase dpy = do RMDatabase db <- xrmGetDatabase dpy + if db == nullPtr + then return Nothing + else return $ Just $ RMDatabase db +foreign import ccall unsafe "HsXlib.h XrmGetDatabase" + xrmGetDatabase :: Display -> IO RMDatabase + +-- | interface to the X11 library function @XrmCombineFileDatabase()@. +rmCombineFileDatabase :: String -> RMDatabase -> Bool -> IO () +rmCombineFileDatabase file db override = withCString file $ \ c_file -> + throwIfZero "rmCombineFileDatabase" $ + xrmCombineFileDatabase c_file db override +foreign import ccall unsafe "HsXlib.h XrmCombineFileDatabase" + xrmCombineFileDatabase :: CString -> RMDatabase -> Bool -> IO Status + +-- | interface to the X11 library function @XrmCombineDatabase()@. +foreign import ccall unsafe "HsXlib.h XrmCombineDatabase" + rmCombineDatabase :: RMDatabase -> RMDatabase -> Bool -> IO () + +-- | interface to the X11 library function @XrmMergeDatabases()@. +foreign import ccall unsafe "HsXlib.h XrmMergeDatabases" + rmMergeDatabases :: RMDatabase -> RMDatabase -> IO () + +-- | interface to the X11 library function @XrmGetResource()@. +rmGetResource :: RMDatabase -> String -> String -> IO (Maybe (String, RMValue)) +rmGetResource db name clss = withCString name $ \c_name -> + withCString clss $ \c_clss -> + alloca $ \type_ret -> + alloca $ \val_ret -> do + b <- xrmGetResource db c_name c_clss type_ret val_ret + if b + then do s <- peekCString =<< peek type_ret + v <- peek val_ret + return $ Just (s, v) + else return Nothing +foreign import ccall unsafe "HsXlib.h XrmGetResource" + xrmGetResource :: RMDatabase -> CString -> CString + -> Ptr CString -> Ptr RMValue -> IO Bool + +-- | interface to the X11 library function @XrmPutResource()@. +rmPutResource :: RMDatabase -> String -> String -> RMValue -> IO () +rmPutResource db name clss val = withCString name $ \c_name -> + withCString clss $ \c_clss -> + alloca $ \c_val -> do + poke c_val val + xrmPutResource db c_name c_clss c_val +foreign import ccall unsafe "HsXlib.h XrmPutResource" + xrmPutResource :: RMDatabase -> CString -> CString + -> Ptr RMValue -> IO () + +-- | interface to the X11 library function @XrmPutStringResource()@. +rmPutStringResource :: RMDatabase -> String -> String -> IO () +rmPutStringResource db spec val = withCString spec $ \c_spec -> + withCString val $ \c_val -> + xrmPutStringResource db c_spec c_val +foreign import ccall unsafe "HsXlib.h XrmPutStringResource" + xrmPutStringResource :: RMDatabase -> CString -> CString -> IO () + + +-- | interface to the X11 library function @XrmPutStringResource()@. +rmPutLineResource :: RMDatabase -> String -> IO () +rmPutLineResource db line = withCString line $ \c_line -> + xrmPutLineResource db c_line +foreign import ccall unsafe "HsXlib.h XrmPutLineResource" + xrmPutLineResource :: RMDatabase -> CString -> IO () + +-- | interface to the X11 library function @XGetDefault()@. +getDefault :: Display -> String -> String -> IO (Maybe String) +getDefault dpy prog opt = withCString prog $ \ c_prog -> + withCString opt $ \ c_opt -> do + s <- xGetDefault dpy c_prog c_opt + if s == nullPtr + then return Nothing + else Just `fmap` peekCString s +foreign import ccall unsafe "HsXlib.h XGetDefault" + xGetDefault :: Display -> CString -> CString -> IO CString + +-- | Extract string from RMValue structure. Make sure the RMValue +-- actually points at a null-terminated string. +rmValue :: RMValue -> IO String +rmValue val = peekCString $ intPtrToPtr $ rmvalue_addr val + ---------------------------------------------------------------- -- Canned handling of output parameters ---------------------------------------------------------------- hunk ./Graphics/X11/Xlib/Types.hsc 19 -- #hide module Graphics.X11.Xlib.Types( Display(..), Screen(..), Visual, GC, GCValues, SetWindowAttributes, - Image(..), Point(..), Rectangle(..), Arc(..), Segment(..), Color(..), - Pixel, Position, Dimension, Angle, ScreenNumber, Buffer + Image(..), RMDatabase(..), Point(..), Rectangle(..), Arc(..), + Segment(..), Color(..), RMValue(..), Pixel, Position, Dimension, + Angle, ScreenNumber, Buffer ) where -- import Control.Monad( zipWithM_ ) hunk ./Graphics/X11/Xlib/Types.hsc 98 deriving (Eq, Ord, Show) #endif +-- | pointer to an X11 @XrmDatabase@ structure +newtype RMDatabase = RMDatabase (Ptr RMDatabase) +#if __GLASGOW_HASKELL__ + deriving (Eq, Ord, Show, Typeable, Data) +#else + deriving (Eq, Ord, Show) +#endif + type Pixel = #{type unsigned long} type Position = #{type int} type Dimension = #{type unsigned int} hunk ./Graphics/X11/Xlib/Types.hsc 308 #{poke XColor,blue} p blue #{poke XColor,flags} p flags +-- | counterpart of an X11 @XrmValue@ structure +data RMValue = RMValue { + rmvalue_size :: CInt, + rmvalue_addr :: IntPtr + } + deriving (Eq, Show) + +instance Storable RMValue where + sizeOf _ = #{size XrmValue} + alignment _ = alignment (undefined::CInt) + peek p = do size <- #{peek XrmValue,size} p + addr <- #{peek XrmValue,addr} p + return (RMValue size addr) + ---------------------------------------------------------------- -- End ---------------------------------------------------------------- hunk ./include/HsXlib.h 20 #include #include #include +#include /* Xutil.h overrides some functions with macros. * In recent versions of X this can be turned off with } Context: [Bump version Spencer Janssen **20091216003141 Ignore-this: fb8347bf233e6937a3384e383b85a542 ] [I'm taking maintainership of X11. Spencer Janssen **20091216002449 Ignore-this: 9711bb52e44243b366f1c624fec026dd Thanks to Don Stewart for his maintenance work the past two years. ] [Remove weird character in comment. May fix building with hsc2hs on 6.12 Spencer Janssen **20091125002712 Ignore-this: ef1b32d6bb9ed22cb09a63b35a64d231 ] [De-orphan the Read Rectangle instance Adam Vogt **20091115212115 Ignore-this: 2ac94627adef450b7aec291a50878f43 ] [Escape path / from haddock Adam Vogt **20091115212213 Ignore-this: 2ccd8b59a6c75beb609abf3e7b4ca722 ] [ExportScreenDataConstructor arsenm2@rpi.edu**20091107202100 Ignore-this: 4b8c1886a9f0acfcfb13fa7f421d0c13 ] [Move build-type from wrong stanza Don Stewart **20091005014719] [Add XGetModifierMapping binding Spencer Janssen **20091103214200 Ignore-this: c22c6efc472d3a2d9bdd6c81b7d84f4d ] [KeyCode should be a byte, not a Unicode Char Spencer Janssen **20091103211642 Ignore-this: e53bc8b64fd12247ce907c710e293b67 ] [Add minimum cabal version Don Stewart **20091005014343] [Refactor cabal file. And enable support for syb generics. Don Stewart **20091005013359] [We can relax the versioning constraint on base. Don Stewart **20091004231553] [Bump configure.ac to 1.4.6 Don Stewart **20091004225102] [haskell-x11: export Cursor in Xlib.hs Andres Salomon **20090915162318 Ignore-this: 77e1afa7994d1d0a3396dac2f7b37d27 Whoops, I forgot to export the cursors along w/ the rest of Xlib. ] [Some extra fields, bump the version. Don Stewart **20090915161044] [haskell-x11: add and export the list of cursors Andres Salomon **20090915155708 Ignore-this: 995cede8cdd8830a2c0bb6c63b8229b9 Pulled in from X11/cursorfont.h, export things like xC_X_cursor and xC_left_ptr for things like createFontCursor to use. ] [TAG 1.4.5 Spencer Janssen **20081203050348 Ignore-this: d8112e4ff25ec56fe5ac2cdc9fa1ead ] [Bump version to 1.4.5 Spencer Janssen **20081203050251 Ignore-this: 665f8093d82bef9e6b13bf1e4db74e1d ] [Bump configure.ac to 1.4.4 as well Spencer Janssen **20081203050154 Ignore-this: ef3fabf26fc7dbfdb6dfaa92073e3c9e ] [Fix memory leak in getWMHints Spencer Janssen **20081125221512 Ignore-this: dacc19acbb60e13d945509cde0551bc8 ] [more precise X11 deps Don Stewart **20081011211930] [TAG 1.4.3 Spencer Janssen **20080921082528] Patch bundle hash: c80ffd4dd51946645b731ba34b2c947b164e999c