-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A programming language for simple GUIs -- -- Sindre is a language inspired by Awk, meant for creating very simple -- graphical user interfaces. @package sindre @version 0.2 -- | Interface to the Xft library based on the X11-xft binding by -- Clemens Fruhwirth. This library builds upon the X11 binding to Xlib -- (Graphics.X11) and cannot be used with any other. A tiny part -- of Xrender is also exposed, as no Haskell interface exists as of this -- writing. -- -- The spirit of this binding is to hide away the fact that the -- underlying implementation is accessed via the FFI, and create a -- Haskell-like interface that does not expose many artifacts of the C -- implementation. To that end, the only numeric types exposed are -- high-level (no CInts), and facilities for integrating resource -- cleanup with the Haskell garbage collector have been defined (see -- XftMgr). -- -- Another priority has been robustness. Many naively written FFI -- bindings to not properly check the return values of the C functions -- they call. In particular, null pointers are often assumed to never -- exist, and oftentimes impossible to check by the user as the -- underlying pointer is not visible across the module boundary. In this -- binding, any Xft function that can return null has been translated -- into a Haskell function that returns a Maybe value. -- -- Two kinds of allocator functions are provided: some that use the -- nomenclature new and some that uses open (for -- example newColorName versus openColorName). The former -- require that you explicitly call the corresponding deallocator -- (freeColor in this case), while the latter takes an -- XftMgr as an additional argument, and automatically calls the -- deallocator when the value is garbage-collected. It is an error to -- call a deallocator on an automatically managed value. module Graphics.X11.Xft -- | A central staging point for Xft object creation. All Xft object -- creation functions take as argument an XftMgr value that keeps -- track of lifetime information. You are required to manually free the -- XftMgr via freeXftMgr when you are done with it. data XftMgr -- | Create an XftMgr whose objects will be used on the given screen -- and display. As Xlib is not re-entrant, a synchronisation mechanism -- must be used, so the XftMgr includes actions for obtaining and -- releasing atomic access to the display via two IO actions. -- These will be executed before and after objects allocated via the -- manager are released. It is recommended to use an -- Control.Concurrent.MVar to implement a mutex for -- synchronising the access, but if you are absolutely certain that there -- will not be any concurrent attempts to access the display, the actions -- can merely be return (). newXftMgr :: Display -> Screen -> IO () -> IO () -> IO XftMgr -- | Free the manager and reclaim any objects associated with it. After an -- XftMgr has been freed, it is invalid to use any objects created -- through it. The lock must currently be held by the thread calling -- freeXftMgr, and it will be repeatedly released and reacquired -- throughout deallocating any remaining objects in the manager. When the -- command returns, the lock will once again be held. freeXftMgr :: XftMgr -> IO () -- | An Xft colour. data Color -- | The core X11 colour contained in an Xft colour. pixel :: Color -> Pixel -- | Create a new Xft colour based on a name. The name may be either a -- human-readable colour such as red, white or -- darkslategray (all core X colour names are supported) or a -- hexidecimal name such as #A9E2AF. Names are not case-sensitive. -- Returns Nothing if the given name is not recognised as a -- colour. newColorName :: Display -> Visual -> Colormap -> String -> IO (Maybe Color) -- | As newColorName, but instead of a name, an XRender color value -- is used. newColorValue :: Display -> Visual -> Colormap -> RenderColor -> IO (Maybe Color) -- | Free a colour that has been allocated with newColorName or -- newColorValue. freeColor :: Display -> Visual -> Colormap -> Color -> IO () -- | As newColorName, but automatically freed through the given Xft -- manager when no longer accessible. openColorName :: XftMgr -> Visual -> Colormap -> String -> IO (Maybe Color) -- | As newColorValue, but automatically freed through the given Xft -- manager when no longer accessible. openColorValue :: XftMgr -> Visual -> Colormap -> RenderColor -> IO (Maybe Color) -- | An Xft drawable. data Draw -- | The display for the Xft drawable. display :: Draw -> Display -- | The colormap for the Xft drawable. colormap :: Draw -> Colormap -- | The visual for the Xft drawable. visual :: Draw -> Visual -- | The X11 drawable underlying the Xft drawable. drawable :: Draw -> Drawable -- | Change the X11 drawable underlying the Xft drawable. changeDraw :: Draw -> Drawable -> IO () -- | Create a new Xft drawable on the given display, using the provided -- Drawable to draw on. Will return Nothing if the call to -- XftDrawCreate fails, which it will usually only do if memory -- cannot be allocated. The Draw has to be manually freed with -- freeDraw once you are done with it. newDraw :: Display -> Drawable -> Visual -> Colormap -> IO (Maybe Draw) -- | Behaves as newDraw, except that it uses a Pixmap of -- color depth 1 instead of a Drawable. newDrawBitmap :: Display -> Pixmap -> IO (Maybe Draw) -- | Behaves as newDraw, except that it uses a Pixmap of the -- given depth instead of a Drawable. newDrawAlpha :: Integral a => Display -> Pixmap -> a -> IO (Maybe Draw) -- | Free a Draw created with newDraw. Do not free -- Draws created with openDraw, these are automatically -- managed. freeDraw :: Draw -> IO () -- | As newDraw, but automatically freed when no longer used. openDraw :: XftMgr -> Drawable -> Visual -> Colormap -> IO (Maybe Draw) -- | As newDrawBitmap, but automatically freed when no longer used. openDrawBitmap :: XftMgr -> Drawable -> IO (Maybe Draw) -- | As newDrawBitmap, but automatically freed when no longer used. openDrawAlpha :: Integral a => XftMgr -> Drawable -> a -> IO (Maybe Draw) -- | An Xft font. data Font -- | The ascent (vertical distance upwards from the baseline) of a -- character in the font. ascent :: Integral a => Font -> a -- | The descent (vertical distance downwards from the baseline) of a -- character in the font. descent :: Integral a => Font -> a -- | The ascent plus descent of a character in the font. height :: Integral a => Font -> a -- | The greatest horizontal width of a character in the font. maxAdvanceWidth :: Integral a => Font -> a -- | newFontName dpy scr s, where s is a Fontconfig -- pattern string, finds the best match for s and returns a font -- that can be used to draw on the given screen. This function very -- rarely returns Nothing, and seems to return some default font -- even if you feed it utter garbage (or an empty string). newFontName :: Display -> Screen -> String -> IO (Maybe Font) -- | As newFontName, except that the name should be an X Logical -- Font Description (the usual fourteen elements produced by -- xfontsel). newFontXlfd :: Display -> Screen -> String -> IO (Maybe Font) -- | Close the given Xft font. freeFont :: Display -> Font -> IO () -- | As newFontName, but automatically freed when no longer used. openFontName :: XftMgr -> String -> IO (Maybe Font) -- | As newFontXfld, but automatically freed when no longer used. openFontXlfd :: XftMgr -> String -> IO (Maybe Font) -- | Lock the file underlying the Xft font. I am not certain when you would -- need this. The return value is supposed to be an FT_TYPE from -- Freetype, but that binding has not been written yet. lockFace :: Font -> IO () -- | Unlock a face locked by lockFontFace. unlockFace :: Font -> IO () -- | Note that the 'glyphWidth'/'glyphHeight' fields are the number of -- pixels you should advance after drawing a string of this size. textExtents :: Display -> Font -> String -> IO GlyphInfo -- | Shortcut for calling textExtents and picking out the -- glyphWidth field of the GlyphInfo. textWidth :: Integral a => Display -> Font -> String -> IO a -- | Shortcut for calling textExtents and picking out the -- glyphHeight field of the GlyphInfo. textHeight :: Integral a => Display -> Font -> String -> IO a -- | Draw a string on the given drawable in the specified colour and font. -- Drawing begins at the baseline of the string. drawString :: (Integral x, Integral y) => Draw -> Color -> Font -> x -> y -> String -> IO () -- | Draw a sequence of glyphs on the given drawable in the specified -- colour and font. Drawing begins at the baseline of the string. drawGlyphs :: (Integral x, Integral y, Integral c) => Draw -> Color -> Font -> x -> y -> [c] -> IO () -- | drawRect d c x y w h draws a solid rectangle on d -- with colour c, with its upper left corner at (x,y), -- width w and height h. drawRect :: (Integral x, Integral y, Integral w, Integral h) => Draw -> Color -> x -> y -> w -> h -> IO () -- | The XRenderColor from the XRender library. Note that the -- colour channels are only interpreted as 16-bit numbers when actually -- used. data RenderColor RenderColor :: Int -> Int -> Int -> Int -> RenderColor red :: RenderColor -> Int green :: RenderColor -> Int blue :: RenderColor -> Int alpha :: RenderColor -> Int -- | The size of some glyph(s). Note that there's a difference between the -- logical size, which may include some blank pixels, and the actual -- bitmap. data GlyphInfo GlyphInfo :: Int -> Int -> Int -> Int -> Int -> Int -> GlyphInfo glyphImageWidth :: GlyphInfo -> Int glyphImageHeight :: GlyphInfo -> Int glyphImageX :: GlyphInfo -> Int glyphImageY :: GlyphInfo -> Int glyphWidth :: GlyphInfo -> Int glyphHeight :: GlyphInfo -> Int instance Storable GlyphInfo instance Storable RenderColor -- | Various utility bits and pieces. module Sindre.Util -- | Short-hand for liftIO io :: MonadIO m => IO a -> m a -- | Short-hand for fromIntegral fi :: (Integral a, Num b) => a -> b -- | Short-hand for 'liftIO . hPutStrLn stderr' err :: MonadIO m => String -> m () -- | Short-hand for 'map toUpper' upcase :: String -> String -- | Short-hand for 'map toLower' downcase :: String -> String -- | Conversion scheme as in -- http:en.wikipedia.orgwikiHSV_color_space hsv2rgb :: Fractional a => (Integer, a, a) -> (a, a, a) -- | Prepend and append first argument to second argument. wrap :: String -> String -> String -- | Put double quotes around the given string. quote :: String -> String -- | Bound a value by minimum and maximum values. clamp :: Ord a => a -> a -> a -> a -- | The mapAccumLM function behaves like a combination of -- mapM and foldlM; it applies a monadic function to each -- element of a list, passing an accumulating parameter from left to -- right, and returning a final value of this accumulator together with -- the new list. mapAccumLM :: Monad m => (acc -> x -> m (acc, y)) -> acc -> [x] -> m (acc, [y]) -- | Like when, but with two branches. A lifted if. ifM :: Monad m => m Bool -> m a -> m a -> m a module Sindre.KeyVal -- | Parse a key-value string wrapper constructed via the permutation -- parser combinators from Text.Parsec.Perm and the parsers -- value and values. parseKV :: PermParser Parser a -> Text -> Either String a -- | value k is a parser for the single-valued key k. value :: Text -> Parser Text -- | values k is a parser for the list-valued key k. At -- least a single value is required. values :: Text -> Parser [Text] -- | The expression f <$?> (x,p) creates a fresh permutation -- parser consisting of parser p. The the final result of the -- permutation parser is the function f applied to the return -- value of p. The parser p is optional - if it can not -- be applied, the default value x will be used instead. (<$?>) :: (a -> b) -> (a, p a) -> PermParser p b -- | The expression perm <||> p adds parser p to -- the permutation parser perm. The parser p is not -- allowed to accept empty input - use the optional combinator -- (<|?>) instead. Returns a new permutation parser that -- includes p. (<||>) :: PermParser p (a -> b) -> p a -> PermParser p b -- | The expression f <$$> p creates a fresh permutation -- parser consisting of parser p. The the final result of the -- permutation parser is the function f applied to the return -- value of p. The parser p is not allowed to accept -- empty input - use the optional combinator (<$?>) instead. -- -- If the function f takes more than one parameter, the type -- variable b is instantiated to a functional type which -- combines nicely with the adds parser p to the -- (<||>) combinator. This results in stylized code where a -- permutation parser starts with a combining function f -- followed by the parsers. The function f gets its parameters -- in the order in which the parsers are specified, but actual input can -- be in any order. (<$$>) :: (a -> b) -> p a -> PermParser p b -- | The expression perm <||> (x,p) adds parser p -- to the permutation parser perm. The parser p is -- optional - if it can not be applied, the default value x will -- be used instead. Returns a new permutation parser that includes the -- optional parser p. (<|?>) :: PermParser p (a -> b) -> (a, p a) -> PermParser p b -- | General definitions for the Sindre programming language. The -- documentation for this module does not include a description of the -- language semantics. module Sindre.Sindre -- | A rectangle represented as its upper-left corner, width and height. -- You should never create rectangles with negative dimensions, and the -- functions in this module make no guarantee to their behaviour if you -- do. data Rectangle Rectangle :: Integer -> Integer -> Integer -> Integer -> Rectangle rectX :: Rectangle -> Integer rectY :: Rectangle -> Integer rectWidth :: Rectangle -> Integer rectHeight :: Rectangle -> Integer -- | A size constraint in one dimension. data DimNeed -- | At minimum this many pixels. Min :: Integer -> DimNeed -- | At most this many pixels. Max :: Integer -> DimNeed -- | As many or as few pixels as necessary. Unlimited :: DimNeed -- | Exactly this many pixels. Exact :: Integer -> DimNeed -- | Size constraints in both dimensions. type SpaceNeed = (DimNeed, DimNeed) -- | The amount of space actually used by a widget. type SpaceUse = [Rectangle] -- | Externally-imposed optional minimum and maximum values for width and -- height. type Constraints = ((Maybe Integer, Maybe Integer), (Maybe Integer, Maybe Integer)) -- | Instruction on how to align a smaller interval within a larger -- interval. data Align -- | Align towards negative infinity. AlignNeg :: Align -- | Align towards positive infinity. AlignPos :: Align -- | Align towards the center of the interval. AlignCenter :: Align -- | constrainNeed need constraints reduces the space requirement -- given by need in order to fulfill constraints. constrainNeed :: SpaceNeed -> Constraints -> SpaceNeed -- | fitRect rect need yields a rectangle as large as possible, -- but no larger than rect, that tries to fulfill the -- constraints need. fitRect :: Rectangle -> SpaceNeed -> Rectangle -- | splitHoriz rect dims splits rect horizontally into a -- number of non-overlapping equal-width rectangles stacked on top of -- each other. dims is a list of height requirements that the -- function will attempt to fulfill as best it is able. The union of the -- list of returned rectangles will always be equal to rect. No -- rectangle will ever have negative dimensions. splitHoriz :: Rectangle -> [DimNeed] -> [Rectangle] -- | As splitHoriz, but splits vertically instead of horizontally, -- so the rectangles will be next to each other. splitVert :: Rectangle -> [DimNeed] -> [Rectangle] -- | Flip the x and y coordinates and width and height of a rectangle, in a -- sense rotating it ninety degrees. Note that rectTranspose . -- rectTranspose = id. rectTranspose :: Rectangle -> Rectangle -- | align a lower x upper, where lower<=upper, aligns -- a subinterval of length x in the interval lower to -- upper, returning the coordinate at which the aligned -- subinterval starts. For example, -- --
--   >>> align AlignCenter 2 4 10
--   4
--   
--   >>> align AlignNeg 2 4 10
--   2
--   
--   >>> align AlignPos 2 4 10
--   6
--   
align :: Integral a => Align -> a -> a -> a -> a -- | adjustRect (walign, halign) bigrect smallrect returns a -- rectangle with the same dimensions as smallrect aligned -- within bigrect in both dimensions. adjustRect :: (Align, Align) -> Rectangle -> Rectangle -> Rectangle -- | A keyboard modifier key. The precise meaning (and location) of these -- is somewhat platform-dependent. Note that the Shift modifier -- should not be passed along if the associated key is a -- CharKey, as Shift will already have been handled. data KeyModifier Control :: KeyModifier Meta :: KeyModifier Super :: KeyModifier Hyper :: KeyModifier Shift :: KeyModifier -- | Either a key corresponding to a visible character, or a control key -- not associated with any character. data Key -- | Unicode character associated with the key. CharKey :: Char -> Key -- | Name of the control key, using X11 key names (for example -- BackSpace or Return). CtrlKey :: String -> Key -- | A combination of a set of modifier keys and a primary key, -- representing a complete piece of keyboard input. type Chord = (Set KeyModifier, Key) -- | Wrap a value with source position information. data P a P :: SourcePos -> a -> P a sourcePos :: P a -> SourcePos unP :: P a -> a -- | x at y gives a value containing x, but with -- the same source position as y. at :: a -> P b -> P a -- | A position in a source file, consisting of a file name, one-indexed -- line number, and one-indexed column number. type SourcePos = (String, Int, Int) -- | A default position when no other is available. nowhere :: SourcePos -- | Prettyprint a source position in a human-readable form. -- --
--   >>> position ("foobar.sindre", 5, 15)
--   "foobar.sindre:5:15: "
--   
position :: SourcePos -> String -- | The type of names (such as variables and classes) in the syntax tree. type Identifier = String -- | The syntax of Sindre statements. data Stmt Print :: [P Expr] -> Stmt Exit :: (Maybe (P Expr)) -> Stmt Return :: (Maybe (P Expr)) -> Stmt Next :: Stmt If :: (P Expr) -> [P Stmt] -> [P Stmt] -> Stmt While :: (P Expr) -> [P Stmt] -> Stmt For :: (P Expr) -> (P Expr) -> (P Expr) -> [P Stmt] -> Stmt Do :: [P Stmt] -> (P Expr) -> Stmt Break :: Stmt Continue :: Stmt Expr :: (P Expr) -> Stmt Focus :: (P Expr) -> Stmt -- | The syntax of Sindre expressions. data Expr Literal :: Value -> Expr Var :: Identifier -> Expr FieldOf :: Identifier -> (P Expr) -> Expr Lookup :: (P Expr) -> (P Expr) -> Expr Not :: (P Expr) -> Expr LessThan :: (P Expr) -> (P Expr) -> Expr LessEql :: (P Expr) -> (P Expr) -> Expr Equal :: (P Expr) -> (P Expr) -> Expr Assign :: (P Expr) -> (P Expr) -> Expr PostInc :: (P Expr) -> Expr PostDec :: (P Expr) -> Expr Concat :: (P Expr) -> (P Expr) -> Expr Plus :: (P Expr) -> (P Expr) -> Expr Minus :: (P Expr) -> (P Expr) -> Expr Times :: (P Expr) -> (P Expr) -> Expr Divided :: (P Expr) -> (P Expr) -> Expr Modulo :: (P Expr) -> (P Expr) -> Expr RaisedTo :: (P Expr) -> (P Expr) -> Expr Funcall :: Identifier -> [P Expr] -> Expr Methcall :: (P Expr) -> Identifier -> [P Expr] -> Expr Cond :: (P Expr) -> (P Expr) -> (P Expr) -> Expr -- | Low-level reference to an object. type ObjectNum = Int -- | High-level reference to an object, containing its class and name (if -- any) as well. For non-widgets, the object name is the same as the -- object class. type ObjectRef = (ObjectNum, Identifier, Maybe Identifier) -- | High-level reference to a widget. type WidgetRef = ObjectRef -- | Dynamically typed run-time value in the Sindre language. data Value StringV :: Text -> Value Number :: Double -> Value Reference :: ObjectRef -> Value Dict :: (Map Value Value) -> Value -- | string s returns a Sindre string. string :: String -> Value -- | true v returns True if v is interpreted as a -- true value in Sindre, False otherwise. true :: Value -> Bool -- | Canonical false value, see true. -- -- Canonical true value, see true. truth, falsity :: Value -- | Something that happened in the world. data Event KeyPress :: Chord -> Event NamedEvent :: Identifier -> [Value] -> EventSource -> Event -- | The name of the event. eventName :: Event -> Identifier -- | The payload of the event. eventValue :: Event -> [Value] -- | Where it's from. eventSource :: Event -> EventSource -- | The origin of an event. This is used when determining where to handle -- it. data EventSource -- | FieldSrc obj f designates that the source of the event is the -- property f of obj FieldSrc :: ObjectRef -> Identifier -> EventSource -- | The source is the given object. ObjectSrc :: ObjectRef -> EventSource -- | The source is something within the bowels of the active backend, -- probably from the external world. BackendSrc :: EventSource -- | Description of sets of sources, values of this type can be used to -- pattern-match EventSources. data SourcePat -- | For NamedSource k fk, the source must be the object named -- k. If fk is Just fk', the source must also -- be the field named fk'. NamedSource :: Identifier -> (Maybe Identifier) -> SourcePat -- | For GenericSource cn k fk, the source must be of class -- cn. If fk is Just fk', the source must also -- be the field named fk'. The variable named k should -- be bound to the actual object if this pattern matches. GenericSource :: Identifier -> Identifier -> (Maybe Identifier) -> SourcePat -- | A description of an event used to indicate how to handle different -- events. data Pattern -- | Match if the event is a chord. ChordPattern :: Chord -> Pattern -- | Match if either pattern matches. OrPattern :: Pattern -> Pattern -> Pattern -- | SourcedPattern src ev vars matches if src matches -- the event source (see SourcePat) an ev matches the -- event name. vars should be bound to the values in the payload -- of the event. SourcedPattern :: SourcePat -> Identifier -> [Identifier] -> Pattern patternSource :: Pattern -> SourcePat patternEvent :: Pattern -> Identifier patternVars :: Pattern -> [Identifier] -- | Reaction to an event. data Action -- | Execute these statements. StmtAction :: [P Stmt] -> Action -- | A function consists of lexically bound parameters and a body. data Function Function :: [Identifier] -> [P Stmt] -> Function -- | A Sindre GUI is a recursive tree, with each node representing a single -- widget and consisting of the following fields. data GUI GUI :: Maybe Identifier -> P Identifier -> WidgetArgs -> [(Maybe (P Expr), GUI)] -> GUI -- | Name of the widget, if any. widgetName :: GUI -> Maybe Identifier -- | Class of the widget. widgetClass :: GUI -> P Identifier -- | The arguments passed to the widget. widgetArgs :: GUI -> WidgetArgs -- | Children of the widget, if any. widgetChildren :: GUI -> [(Maybe (P Expr), GUI)] -- | A complete Sindre program. Note that this is intentionally defined -- such that some invalid programs, like those with duplicate definitions -- can be represented - the compiler (see Sindre.Compiler) should -- detect and handle such errors. data Program Program :: (Maybe (P Expr), GUI) -> [P (Pattern, Action)] -> [P (Identifier, P Expr)] -> [P (Identifier, (SindreOption, Maybe Value))] -> [P (Identifier, Function)] -> [P Stmt] -> Program programGUI :: Program -> (Maybe (P Expr), GUI) programActions :: Program -> [P (Pattern, Action)] programGlobals :: Program -> [P (Identifier, P Expr)] programOptions :: Program -> [P (Identifier, (SindreOption, Maybe Value))] programFunctions :: Program -> [P (Identifier, Function)] -- | The contents of the BEGIN block. programBegin :: Program -> [P Stmt] -- | A command line argument. type SindreOption = OptDescr (Arguments -> Arguments) -- | The arguments passed to the Sindre program from the command line. type Arguments = Map String String instance Show Rectangle instance Eq Rectangle instance Eq DimNeed instance Show DimNeed instance Ord DimNeed instance Show Align instance Eq Align instance Eq KeyModifier instance Ord KeyModifier instance Show KeyModifier instance Show Key instance Eq Key instance Ord Key instance Eq Value instance Ord Value instance Show a => Show (P a) instance Eq a => Eq (P a) instance Ord a => Ord (P a) instance Functor P instance Show Expr instance Eq Expr instance Ord Expr instance Show Stmt instance Eq Stmt instance Show EventSource instance Show Event instance Eq SourcePat instance Ord SourcePat instance Show SourcePat instance Eq Pattern instance Ord Pattern instance Show Pattern instance Show Function instance Eq Function instance Show Action instance Show GUI instance Show Value instance Monoid Rectangle -- | Parser for the Sindre programming language. The documentation for this -- module does not include a description of the language syntax. module Sindre.Parser -- | parseSindre prog filename string extends the Program -- prog with the declarations in the given Sindre source code. -- In case of mutually-exclusive definitions (such as the BEGIN -- block, or identically named functions), the new definitions in -- string take precedence. parseSindre :: Program -> SourceName -> String -> Either ParseError Program -- | Try to parse an integer according to the Sindre syntax, ignoring -- trailing whitespace. parseInteger :: String -> Maybe Double -- | Definitions for the Sindre runtime environment. module Sindre.Runtime -- | The main monad in which a Sindre program executes. More specialised -- monads, such as Execution are used for specific purposes, but -- they all run on top of the Sindre monad. data Sindre m a -- | execSindre e m executes the action m in environment -- e, returning the exit code of m. execSindre :: MonadBackend m => SindreEnv m -> Sindre m a -> m ExitCode -- | Immediately return from execSindre, returning the given exit -- code. quitSindre :: MonadBackend m => ExitCode -> Sindre m () -- | MonadSindre im m is the class of monads m that run -- on top of Sindre with backend im, and can thus access -- Sindre functionality. class (MonadBackend im, Monad (m im)) => MonadSindre im m sindre :: MonadSindre im m => Sindre im a -> m im a back :: MonadSindre im m => im a -> m im a broadcast :: MonadBackend im => Event -> ObjectM o im () changed :: MonadBackend im => Identifier -> Value -> Value -> ObjectM o im () redraw :: (MonadBackend im, Widget im s) => ObjectM s im () fullRedraw :: MonadSindre im m => m im () setRootPosition :: MonadBackend m => Value -> Sindre m () -- | A monad that can be used as the layer beneath Sindre. class (Monad m, Functor m, Applicative m, Mold (RootPosition m)) => MonadBackend m where { type family BackEvent m :: *; type family RootPosition m :: *; } redrawRoot :: MonadBackend m => Sindre m () redrawRegion :: MonadBackend m => [Rectangle] -> Sindre m () getBackEvent :: MonadBackend m => Sindre m (Maybe Event) waitForBackEvent :: MonadBackend m => Sindre m Event printVal :: MonadBackend m => String -> m () class MonadBackend m => Object m s callMethodI :: Object m s => Identifier -> [Value] -> ObjectM s m Value fieldSetI :: Object m s => Identifier -> Value -> ObjectM s m Value fieldGetI :: Object m s => Identifier -> ObjectM s m Value recvEventI :: Object m s => Event -> ObjectM s m () data ObjectM o m a fieldSet :: MonadSindre im m => ObjectRef -> Identifier -> Value -> m im Value fieldGet :: MonadSindre im m => ObjectRef -> Identifier -> m im Value callMethod :: MonadSindre im m => ObjectRef -> Identifier -> [Value] -> m im Value class Object m s => Widget m s composeI :: Widget m s => ObjectM s m SpaceNeed drawI :: Widget m s => Rectangle -> ObjectM s m SpaceUse draw :: MonadSindre im m => WidgetRef -> Maybe Rectangle -> m im SpaceUse compose :: MonadSindre im m => WidgetRef -> m im SpaceNeed recvEvent :: MonadSindre im m => WidgetRef -> Event -> m im () data DataSlot m WidgetSlot :: s -> WidgetState -> DataSlot m ObjectSlot :: s -> DataSlot m data WidgetState WidgetState :: Constraints -> Rectangle -> WidgetState constraints :: WidgetState -> Constraints dimensions :: WidgetState -> Rectangle data SindreEnv m SindreEnv :: Array ObjectNum (DataSlot m) -> Seq Event -> IntMap Value -> Frame -> WidgetRef -> (Maybe (RootPosition m), WidgetRef) -> Arguments -> Redraw -> SindreEnv m objects :: SindreEnv m -> Array ObjectNum (DataSlot m) evtQueue :: SindreEnv m -> Seq Event globals :: SindreEnv m -> IntMap Value execFrame :: SindreEnv m -> Frame kbdFocus :: SindreEnv m -> WidgetRef rootWidget :: SindreEnv m -> (Maybe (RootPosition m), WidgetRef) arguments :: SindreEnv m -> Arguments needsRedraw :: SindreEnv m -> Redraw newEnv :: WidgetRef -> Arguments -> SindreEnv m globalVal :: MonadBackend m => Key -> Sindre m Value setGlobal :: MonadBackend m => Key -> Value -> Sindre m () data Execution m a execute :: MonadBackend m => Execution m Value -> Sindre m Value execute_ :: MonadBackend m => Execution m a -> Sindre m () returnHere :: MonadBackend m => Execution m Value -> Execution m Value doReturn :: MonadBackend m => Value -> Execution m () nextHere :: MonadBackend m => Execution m () -> Execution m () doNext :: MonadBackend m => Execution m () breakHere :: MonadBackend m => Execution m () -> Execution m () doBreak :: MonadBackend m => Execution m () contHere :: MonadBackend m => Execution m () -> Execution m () doCont :: MonadBackend m => Execution m () setScope :: MonadBackend m => [Value] -> Execution m a -> Execution m a enterScope :: MonadBackend m => [Value] -> Execution m a -> Execution m a lexicalVal :: MonadBackend m => Key -> Execution m Value setLexical :: MonadBackend m => Key -> Value -> Execution m () eventLoop :: MonadBackend m => EventHandler m -> Sindre m () type EventHandler m = Event -> Execution m () class Mold a mold :: Mold a => Value -> Maybe a unmold :: Mold a => a -> Value instance Functor (Sindre m) instance Monad (Sindre m) instance Applicative (Sindre m) instance MonadCont (Sindre m) instance MonadState (SindreEnv m) (Sindre m) instance MonadReader (QuitFun m) (Sindre m) instance Functor (ObjectM o m) instance Monad (ObjectM o m) instance Applicative (ObjectM o m) instance MonadState o (ObjectM o m) instance MonadReader ObjectRef (ObjectM o m) instance Functor (Execution m) instance Monad (Execution m) instance Applicative (Execution m) instance MonadReader (ExecutionEnv m) (Execution m) instance MonadCont (Execution m) instance Mold (Align, Align) instance Mold () instance Mold Bool instance Mold Int instance Mold Integer instance Mold Double instance Mold Text instance Mold String instance Mold Value instance MonadBackend im => MonadSindre im Execution instance (MonadIO m, MonadBackend m) => MonadIO (ObjectM o m) instance MonadBackend im => MonadSindre im (ObjectM o) instance MonadBackend im => MonadSindre im Sindre instance Monoid (Sindre m ()) instance MonadIO m => MonadIO (Sindre m) instance MonadTrans Sindre -- | Transforming a Sindre program into a callable function. module Sindre.Compiler -- | Given a Sindre program and its environment, compile the program and -- return a pair of command-line options accepted by the program, and a -- startup function. The program can be executed by calling the startup -- function with the command-like arguments and an initial value for the -- root widget. If compilation fails, an IO exception is raised. compileSindre :: MonadBackend m => Program -> ClassMap m -> ObjectMap m -> FuncMap m -> GlobMap m -> ([SindreOption], Arguments -> m ExitCode) -- | Mapping from class names to constructors. type ClassMap m = Map Identifier (Constructor m) -- | Mapping from object names to object constructor functions. type ObjectMap m = Map Identifier (ObjectRef -> m (NewObject m)) -- | Mapping from function names to built-in functions. These must first be -- executed in the Compiler monad as they may have specific -- requirements of the environment. type FuncMap m = Map Identifier (Compiler m ([Value] -> Sindre m Value)) -- | Mapping from names of global variables to computations that yield -- their initial values. type GlobMap m = Map Identifier (m Value) -- | Container wrapping a newly created widget. data NewWidget m NewWidget :: s -> NewWidget m -- | Container wrapping a newly created object. data NewObject m NewObject :: s -> NewObject m -- | Function that, given an initial value, the name of itself if any, and -- a list of children, yields a computation that constructs a new widget. type Constructor m = WidgetRef -> [(Maybe Value, ObjectRef)] -> ConstructorM m (NewWidget m) -- | The monad in which widget construction takes place. You can only -- execute this by defining a Constructor that is then used in a -- Sindre program (see also ClassMap). An example usage could be: -- --
--   myWidget :: Constructor MyBackEnd
--   myWidget w k cs : do
--     -- ConstructorM is an instance of Alternative, so we can provide
--     -- defaults or fallbacks for missing parameters.
--     arg - 'param' \"myParam\" <| return 12
--     rest of construction
--   
data ConstructorM m a -- | Class of types that a given backend can convert to from Values. -- In effect, a monadic version of Mold. class MonadBackend m => Param m a moldM :: Param m a => Value -> m (Maybe a) -- | As paramM, but moldM is always used for conversion. paramM :: (Param m a, MonadBackend m) => Identifier -> ConstructorM m a -- | k paramAs f yields the value of the widget parameter -- k, using f to convert it to the proper Haskell type. -- If f returns Nothing, badValue k is -- called. If k does not exist, noParam k is -- called. paramAs :: MonadBackend m => Identifier -> (Value -> Maybe a) -> ConstructorM m a -- | As param, but mold is always used for conversion. param :: (Mold a, MonadBackend m) => Identifier -> ConstructorM m a -- | noParam k signals that parameter k is missing. noParam :: String -> ConstructorM m a -- | badValue k v signals that parameter k is present -- with value v, but that v is an invalid value. badValue :: String -> Value -> ConstructorM m a -- | Monad inside which compilation takes place. type Compiler m a = RWS (CompilerEnv m) (Initialisation m) (CompilerState m) a -- | Given a variable name, return a computation that will yield the value -- of the variable when executed. value :: MonadBackend m => Identifier -> Compiler m (Execution m Value) -- | Given a variable name, return a computation that can be used to set -- the value of the variable when executed. setValue :: MonadBackend m => Identifier -> Compiler m (Value -> Execution m ()) instance Show ParamError instance MonadState (Map Identifier Value) (ConstructorM m) instance MonadError ParamError (ConstructorM m) instance Monad (ConstructorM m) instance Functor (ConstructorM m) instance Applicative (ConstructorM m) instance (MonadIO m, MonadBackend m) => MonadIO (ConstructorM m) instance MonadBackend im => MonadSindre im ConstructorM instance MonadBackend m => Alternative (ConstructorM m) instance Error ParamError -- | Parser and definition of the dzen2-inspired formatting language used -- by Sindre. A format string is a sequence of commands changing drawing -- option parameters, and things to draw. module Sindre.Formatting -- | A formatting command is either a change to the drawing state, or a -- string to be printed at the current location. data Format -- | Draw text in the given colour. Fg :: String -> Format -- | Draw text in the default colour. DefFg :: Format -- | Draw the background in the given colour. Bg :: String -> Format -- | Draw the background in the default colour. DefBg :: Format -- | Draw the given string. Text :: Text -> Format -- | A list of formatting commands, interpreted left-to-right. type FormatString = [Format] -- | The human-readable part of a format string, with formatting directives -- stripped. textContents :: FormatString -> Text -- | The first background colour preceding any default background colour or -- text entry specified in the format string, if any. startBg :: FormatString -> Maybe String -- | Parse a format string, returning either an error message or the result -- of the parse. parseFormatString :: Text -> Either String FormatString -- | Prettyprint a FormatString to a string that, when parsed by -- parseFormatString, results in the original FormatString unparseFormatString :: FormatString -> Text instance Show Format instance Eq Format instance Ord Format instance Mold FormatString -- | Library routines and helper functions for the Sindre programming -- language. module Sindre.Lib -- | A set of pure functions that can work with any Sindre backend. -- Includes the functions length, abs, substr, -- index, match, sub, gsub, -- tolower, and toupper. stdFunctions :: MonadBackend im => FuncMap im -- | A set of impure functions that only work in IO backends. Includes the -- system function. ioFunctions :: (MonadIO im, MonadBackend im) => FuncMap im -- | Global variables that require an IO backend. Includes the -- ENVIRON global. ioGlobals :: MonadIO im => Map Identifier (im Value) -- | A class making it easy to adapt Haskell functions as Sindre functions -- that take and return Values. class (MonadBackend im, MonadSindre im m) => LiftFunction im m a function :: LiftFunction im m a => a -> [Value] -> m im Value -- | Convenience class for writing Chord values. class KeyLike a chord :: KeyLike a => [KeyModifier] -> a -> Chord instance KeyLike String instance KeyLike Char instance (Mold a, LiftFunction im m b, MonadSindre im m) => LiftFunction im m (a -> b) instance (Mold a, MonadSindre im m) => LiftFunction im m (m im a) -- | Portable Sindre gadgets and helper functions that can be used by any -- backend. module Sindre.Widgets -- | A widget that arranges its children in a horizontal row. mkHorizontally :: MonadBackend m => Constructor m -- | A widget that arranges its children in a vertical column. mkVertically :: MonadBackend m => Constructor m -- | changeFields fs m applies m to the state of the -- object, replacing the state with the return value of m. -- Value-changed events are sent for each pair of field-name and accessor -- function passed in fs. changeFields :: MonadBackend im => [(Identifier, a -> Value)] -> (a -> ObjectM a im a) -> ObjectM a im () instance MonadBackend m => Widget m Oriented instance MonadBackend m => Object m Oriented -- | X11 backend for Sindre. For internationalised keyboard input to work, -- make sure the locale is correctly set. module Sindre.X11 -- | Sindre backend using Xlib. data SindreX11M a -- | The read-only configuration of the X11 backend, created during backend -- initialisation. data SindreX11Conf -- | Execute Sindre in the X11 backend, grabbing control of the entire -- display and staying on top. sindreX11override :: String -> SindreX11M ExitCode -> IO ExitCode -- | Execute Sindre in the X11 backend as a dock/statusbar. sindreX11dock :: String -> SindreX11M ExitCode -> IO ExitCode -- | Execute Sindre in the X11 backend as an ordinary client visible to the -- window manager. sindreX11 :: String -> SindreX11M ExitCode -> IO ExitCode -- | Performs a lookup in the X resources database for a given property. -- The class used is Sindre.class.property -- and the name is progname.name.property, -- where progname is the value of getProgName. xopt :: Param SindreX11M a => Maybe String -> String -> String -> ConstructorM SindreX11M a -- | Options regarding visual appearance of widgets (colors and fonts). data VisualOpts VisualOpts :: Color -> Color -> Color -> Color -> Font -> VisualOpts foreground :: VisualOpts -> Color background :: VisualOpts -> Color focusForeground :: VisualOpts -> Color focusBackground :: VisualOpts -> Color font :: VisualOpts -> Font -- | Read visual options from either widget parameters or the X resources -- database using xopt, or a combination. The following graphical -- components are read: -- -- visualOpts :: WidgetRef -> ConstructorM SindreX11M VisualOpts allocColor :: MonadIO m => XftMgr -> String -> m Color -- | Helper function that makes it easier it write consistent widgets in -- the X11 backend. The widget is automatically filled with its -- (nonfocus) background color. You are supposed to use this in the -- drawI method of a Widget instance definition. An -- example: -- --
--   drawI = drawing myWidgetWin myWidgetVisual $ r fg bg ffg fbg -> do
--     fg drawString 0 5 "foreground"
--     bg drawString 0 15 "background"
--     ffg drawString 0 25 "focus foreground"
--     fbg drawString 0 35 "focus background"
--   
drawing :: (a -> VisualOpts) -> (Rectangle -> Drawer -> Drawer -> ObjectM a SindreX11M [Rectangle]) -> Rectangle -> ObjectM a SindreX11M SpaceUse -- | Variant of drawing that assumes the entire rectangle is used. drawing' :: (a -> VisualOpts) -> (Rectangle -> Drawer -> Drawer -> ObjectM a SindreX11M ()) -> Rectangle -> ObjectM a SindreX11M SpaceUse data Drawer Drawer :: (forall f. CoreDrawer f) -> (forall f. CoreDrawer f) -> Font -> Color -> Color -> Drawer fg :: Drawer -> forall f. CoreDrawer f bg :: Drawer -> forall f. CoreDrawer f drawerFont :: Drawer -> Font drawerFgColor :: Drawer -> Color drawerBgColor :: Drawer -> Color setFgColor :: Drawer -> Color -> IO Drawer setBgColor :: Drawer -> Color -> IO Drawer textExtents :: Font -> String -> SindreX11M (Int, Int) drawText :: (Integral x, Integral y, Integral z) => Color -> Font -> x -> y -> z -> String -> SindreX11M () -- | A simple dial using an arc segment to indicate the value compared to -- the max value. Accepts max and value parameters -- (both integers, default values 12 and 0), and a single field: -- value. n and p are used to -- increase and decrease the value. mkDial :: Constructor SindreX11M -- | Label displaying the text contained in the field label, which -- is also accepted as a widget parameter (defaults to the empty string). mkLabel :: Constructor SindreX11M -- | A blank widget, showing only background color, that can use as much or -- as little room as necessary. Useful for constraining the layout of -- other widgets. mkBlank :: Constructor SindreX11M -- | Single-line text field, whose single field value (also a -- parameter, defaults to the empty string) is the contents of the -- editing buffer. mkTextField :: Constructor SindreX11M -- | An input stream object wrapping the given Handle. Input is -- purely event-driven and line-oriented: the event lines is -- sent (roughly) for each sequence of lines that can be read without -- blocking, with the payload being a single string value containing the -- lines read since the last time the event was sent. When end of file is -- reached, the eof event (no payload) is sent. mkInStream :: Handle -> ObjectRef -> SindreX11M (NewObject SindreX11M) -- | Horizontal dmenu-style list containing a list of elements, one of -- which is the "selected" element. If the parameter i is given -- a true value, element matching will be case-insensitive. The following -- methods are supported: -- -- -- -- The field selected is the selected element. mkHList :: Constructor SindreX11M -- | As mkHList, except the list is vertical. The parameter -- lines (default value 10) is the number of lines shown. mkVList :: Constructor SindreX11M instance Functor SindreX11M instance Monad SindreX11M instance MonadIO SindreX11M instance MonadReader SindreX11Conf SindreX11M instance MonadState Surface SindreX11M instance Applicative SindreX11M instance Show ListElem instance Eq ListElem instance Ord ListElem instance Widget SindreX11M List instance Object SindreX11M List instance Widget SindreX11M TextField instance Object SindreX11M TextField instance Widget SindreX11M Blank instance Object SindreX11M Blank instance Widget SindreX11M Label instance Object SindreX11M Label instance Widget SindreX11M Dial instance Object SindreX11M Dial instance Param SindreX11M Font instance Param SindreX11M Color instance (MonadIO m, MonadBackend m) => Object m InStream instance MonadBackend SindreX11M -- | Sindre, a programming language for writing simple GUIs module Sindre.Main -- | The main Sindre entry point. sindreMain :: Program -> ClassMap SindreX11M -> ObjectMap SindreX11M -> FuncMap SindreX11M -> GlobMap SindreX11M -> [String] -> IO () emptyProgram :: Program classMap :: ClassMap SindreX11M objectMap :: ObjectMap SindreX11M funcMap :: FuncMap SindreX11M globMap :: GlobMap SindreX11M