diff options
author | Marcin Mikołajczyk <marcinmikolajcz@gmail.com> | 2014-02-18 21:21:39 +0100 |
---|---|---|
committer | Marcin Mikołajczyk <marcinmikolajcz@gmail.com> | 2014-02-18 21:21:39 +0100 |
commit | fc240b66c24b8d257299c9ccc8e51f30129e774c (patch) | |
tree | 83e2b21c07a3ac6a716c42a20e247437f35822eb /src/Actions.hs | |
parent | 0a9528f92cddd6b145be7e75142af2b1b2905877 (diff) | |
download | xmobar-fc240b66c24b8d257299c9ccc8e51f30129e774c.tar.gz xmobar-fc240b66c24b8d257299c9ccc8e51f30129e774c.tar.bz2 |
Add support for multiple actions per item, activated depending on mouse button clicked
Diffstat (limited to 'src/Actions.hs')
-rw-r--r-- | src/Actions.hs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/Actions.hs b/src/Actions.hs index 42b9545..2befe77 100644 --- a/src/Actions.hs +++ b/src/Actions.hs @@ -14,14 +14,21 @@ module Actions (Action(..), runAction, stripActions) where import System.Process (system) import Control.Monad (void) -import Text.Regex (subRegex, mkRegex) +import Text.Regex (Regex, subRegex, mkRegex, matchRegex) +import Graphics.X11.Types (Button) -data Action = Spawn String +data Action = Spawn Button String deriving (Eq) runAction :: Action -> IO () -runAction (Spawn s) = void $ system (s ++ "&") +runAction (Spawn _ s) = void $ system (s ++ "&") stripActions :: String -> String -stripActions s = subRegex actionRegex s "[action=\1]\2[action]" - where actionRegex = mkRegex "<action=([^>])*>(.+)</action>" +stripActions s = case matchRegex actionRegex s of + Nothing -> s + Just _ -> stripActions strippedOneLevel + where + strippedOneLevel = subRegex actionRegex s $ "[\\1=\\2]\\3[\\4]" + +actionRegex :: Regex +actionRegex = mkRegex "<(action|button.)=([^>]*)>(.+)</(action|button.)>" |