packages feed

wild-bind-indicator 0.1.0.1 → 0.2.0.0

raw patch · 3 files changed

+63/−15 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ WildBind.Indicator: adaptIndicator :: (i -> i') -> (i' -> Maybe i) -> Indicator s i -> Indicator s i'
+ WildBind.Indicator: toggleBinding :: (NumPadPosition i, Ord i, Enum i, Bounded i) => Indicator s i -> NumPadLocked -> Binding' bs fs i
- WildBind.Indicator: bindingHook :: (Ord i, Enum i, Bounded i) => Indicator s1 i -> FrontEnd s2 i -> [(i, ActionDescription)] -> IO ()
+ WildBind.Indicator: bindingHook :: Ord i => Indicator s1 i -> FrontEnd s2 i -> [(i, ActionDescription)] -> IO ()
- WildBind.Indicator: wildBindWithIndicator :: (Ord i, Enum i, Bounded i) => Indicator s i -> Binding s i -> FrontEnd s i -> IO ()
+ WildBind.Indicator: wildBindWithIndicator :: Ord i => Indicator s i -> Binding s i -> FrontEnd s i -> IO ()
- WildBind.Indicator: withNumPadIndicator :: NumPadPosition i => (Indicator s i -> IO ()) -> IO ()
+ WildBind.Indicator: withNumPadIndicator :: (NumPadPosition i, Enum i, Bounded i) => (Indicator s i -> IO ()) -> IO ()

Files

ChangeLog.md view
@@ -1,5 +1,11 @@ # Revision history for wild-bind-indicator +## 0.2.0.0  -- 2018-01-01++* Modify constraints of `withNumPadIndicator`, `wildBindWithIndicator`, `bindingHook` functions.+* Add `adaptIndicator`, `toggleBinding` functions.++ ## 0.1.0.1  -- 2016-09-22  * First version. Released on an unsuspecting world.
src/WildBind/Indicator.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE OverloadedStrings #-} -- | -- Module: WildBind.Indicator -- Description: Graphical indicator for WildBind@@ -21,6 +22,10 @@          setPresence,          togglePresence,          quit,+         -- ** Conversion+         adaptIndicator,+         -- ** Binding+         toggleBinding,          -- * Generalization of number pad types          NumPadPosition(..)        ) where@@ -56,7 +61,8 @@ import System.IO (stderr, hPutStrLn)  import WildBind ( ActionDescription, Option(optBindingHook),-                  FrontEnd(frontDefaultDescription), Binding,+                  FrontEnd(frontDefaultDescription), Binding, Binding',+                  binding, Action(Action),                   wildBind', defOption                 ) import WildBind.Input.NumPad (NumPadUnlocked(..), NumPadLocked(..))@@ -79,9 +85,13 @@     setPresence :: Bool -> IO (),     -- ^ Set the presence of the indicator. -    quit :: IO ()+    quit :: IO (),     -- ^ Destroy the indicator. This usually means quitting the entire     -- application.++    allButtons :: [i]+    -- ^ list of all buttons on which the indicator displays+    -- descriptions.   }  -- | Toggle the presence of the indicator.@@ -91,11 +101,11 @@ -- | Convert actions in the input 'Indicator' so that those actions -- can be executed from a non-GTK-main thread. transportIndicator :: Indicator s i -> Indicator s i-transportIndicator ind = Indicator { updateDescription = \i d -> postGUIAsync $ updateDescription ind i d,-                                     getPresence = postGUISync $ getPresence ind,-                                     setPresence = \visible -> postGUIAsync $ setPresence ind visible,-                                     quit = postGUISync $ quit ind-                                   }+transportIndicator ind = ind { updateDescription = \i d -> postGUIAsync $ updateDescription ind i d,+                               getPresence = postGUISync $ getPresence ind,+                               setPresence = \visible -> postGUIAsync $ setPresence ind visible,+                               quit = postGUISync $ quit ind+                             }   -- | Something that can be mapped to number pad's key positions.@@ -153,7 +163,7 @@ --  -- The executable must be compiled by ghc with __@-threaded@ option enabled.__ -- Otherwise, it aborts.-withNumPadIndicator :: NumPadPosition i => (Indicator s i -> IO ()) -> IO ()+withNumPadIndicator :: (NumPadPosition i, Enum i, Bounded i) => (Indicator s i -> IO ()) -> IO () withNumPadIndicator action = if rtsSupportsBoundThreads then impl else error_impl where   error_impl = throwIO $ userError "You need to build with -threaded option when you use WildBind.Indicator.withNumPadIndicator function."   impl = do@@ -172,7 +182,8 @@           { updateDescription = \i d -> updater i d,             getPresence = G.get win widgetVisible,             setPresence = \visible -> if visible then widgetShowAll win else widgetHide win,-            quit = mainQuit+            quit = mainQuit,+            allButtons = enumFromTo minBound maxBound           }     liftIO $ void $ G.on win deleteEvent $ do       liftIO $ widgetHide win@@ -194,13 +205,13 @@  -- | Run 'WildBind.wildBind' with the given 'Indicator'. 'ActionDescription's -- are shown by the 'Indicator'.-wildBindWithIndicator :: (Ord i, Enum i, Bounded i) => Indicator s i -> Binding s i -> FrontEnd s i -> IO ()-wildBindWithIndicator ind binding front = wildBind' (defOption { optBindingHook = bindingHook ind front }) binding front+wildBindWithIndicator :: Ord i => Indicator s i -> Binding s i -> FrontEnd s i -> IO ()+wildBindWithIndicator ind b front = wildBind' (defOption { optBindingHook = bindingHook ind front }) b front  -- | Create an action appropriate for 'optBindingHook' in 'Option' -- from 'Indicator' and 'FrontEnd'.-bindingHook :: (Ord i, Enum i, Bounded i) => Indicator s1 i -> FrontEnd s2 i -> [(i, ActionDescription)] -> IO ()-bindingHook ind front bind_list = forM_ (enumFromTo minBound maxBound) $ \input -> do+bindingHook :: Ord i => Indicator s1 i -> FrontEnd s2 i -> [(i, ActionDescription)] -> IO ()+bindingHook ind front bind_list = forM_ (allButtons ind) $ \input -> do   let desc = M.findWithDefault (frontDefaultDescription front input) input (M.fromList bind_list)   updateDescription ind input desc                        @@ -291,3 +302,34 @@     checkMenuItemSetActive toggler =<< getPresence ind     void $ G.on toggler checkMenuItemToggled (togglePresence ind)     return toggler++-- | Map input type of 'Indicator', so that it can adapt to the new+-- input type @i'@.+--+-- If the contra-mapper function returns 'Nothing', those input+-- symbols are ignored by the 'Indicator'.+--+-- @since 0.2.0.0+adaptIndicator :: (i -> i') -- ^ mapper function+               -> (i' -> Maybe i) -- ^ contra-mapper function+               -> Indicator s i -- ^ original+               -> Indicator s i' -- ^ adapted indicator+adaptIndicator mapper cmapper ind =+  ind { updateDescription = newDesc,+        allButtons = map mapper $ allButtons ind+      }+  where+    newDesc input = case cmapper input of+      Nothing -> const $ return ()+      Just orig_input -> updateDescription ind orig_input++-- | A binding that toggles presence of the 'Indicator'.+--+-- @since 0.2.0.0+toggleBinding :: (NumPadPosition i, Ord i, Enum i, Bounded i)+              => Indicator s i+              -> NumPadLocked -- ^ the button to bind the 'togglePresence' action+              -> Binding' bs fs i+toggleBinding ind button = binding $ map (\input -> (input, Action "Toggle description" $ togglePresence ind)) help_likes+  where+    help_likes = filter ((== button) . toNumPad) $ enumFromTo minBound maxBound
wild-bind-indicator.cabal view
@@ -1,5 +1,5 @@ name:                   wild-bind-indicator-version:                0.1.0.1+version:                0.2.0.0 author:                 Toshio Ito <debug.ito@gmail.com> maintainer:             Toshio Ito <debug.ito@gmail.com> license:                BSD3@@ -19,7 +19,7 @@   default-language:     Haskell2010   hs-source-dirs:       src   ghc-options:          -Wall -fno-warn-unused-imports-  default-extensions:   OverloadedStrings+  other-extensions:     OverloadedStrings   exposed-modules:      WildBind.Indicator   other-modules:        Paths_wild_bind_indicator   build-depends:        base >=4.6 && <5.0,