diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Xmobar.hs | 40 | ||||
-rw-r--r-- | src/lib/Xmobar/Parsers.hs | 13 | ||||
-rw-r--r-- | src/lib/Xmobar/Plugins/BufferedPipeReader.hs | 2 | ||||
-rw-r--r-- | src/lib/Xmobar/Plugins/CommandReader.hs | 2 | ||||
-rw-r--r-- | src/lib/Xmobar/Plugins/DateZone.hs | 1 | ||||
-rw-r--r-- | src/lib/Xmobar/Plugins/Kbd.hs | 96 | ||||
-rw-r--r-- | src/lib/Xmobar/Plugins/Locks.hs | 4 | ||||
-rw-r--r-- | src/lib/Xmobar/Plugins/Mail.hs | 2 | ||||
-rw-r--r-- | src/lib/Xmobar/Plugins/PipeReader.hs | 2 | ||||
-rw-r--r-- | src/lib/Xmobar/System/Kbd.hsc (renamed from src/lib/Xmobar/Plugins/Kbd.hsc) | 89 |
10 files changed, 150 insertions, 101 deletions
diff --git a/src/lib/Xmobar.hs b/src/lib/Xmobar.hs index 3ab779d..ecc664a 100644 --- a/src/lib/Xmobar.hs +++ b/src/lib/Xmobar.hs @@ -15,7 +15,27 @@ -- ----------------------------------------------------------------------------- -module Xmobar (xmobar, Runnable (..), module Xmobar.Config) where +module Xmobar (xmobar + , Runnable (..) + , module Xmobar.Config + , module Xmobar.Plugins.BufferedPipeReader + , module Xmobar.Plugins.CommandReader + , module Xmobar.Plugins.Date +#ifdef DATEZONE + , module Xmobar.Plugins.DateZone +#endif + , module Xmobar.Plugins.EWMH + , module Xmobar.Plugins.Kbd + , module Xmobar.Plugins.Locks +#ifdef INOTIFY + , module Xmobar.Plugins.Mail + , module Xmobar.Plugins.MBox +#endif + , module Xmobar.Plugins.Monitors + , module Xmobar.Plugins.PipeReader + , module Xmobar.Plugins.StdinReader + , module Xmobar.Plugins.XMonadLog + ) where import Data.Foldable (for_) import qualified Data.Map as Map @@ -32,6 +52,24 @@ import Xmobar.X11.Types import Xmobar.X11.EventLoop (startLoop, startCommand) import Xmobar.X11.XUtil import Xmobar.X11.Window +import Xmobar.Plugins.BufferedPipeReader +import Xmobar.Plugins.CommandReader +import Xmobar.Plugins.Date +#ifdef DATEZONE +import Xmobar.Plugins.DateZone +#endif +import Xmobar.Plugins.EWMH +import Xmobar.Plugins.Kbd +import Xmobar.Plugins.Locks +#ifdef INOTIFY +import Xmobar.Plugins.Mail +import Xmobar.Plugins.MBox +#endif +import Xmobar.Plugins.Monitors +import Xmobar.Plugins.PipeReader +import Xmobar.Plugins.StdinReader +import Xmobar.Plugins.XMonadLog + splitTemplate :: Config -> [String] splitTemplate conf = diff --git a/src/lib/Xmobar/Parsers.hs b/src/lib/Xmobar/Parsers.hs index b7e4dbd..d8bd409 100644 --- a/src/lib/Xmobar/Parsers.hs +++ b/src/lib/Xmobar/Parsers.hs @@ -50,13 +50,12 @@ allParsers :: ColorString -> FontIndex -> Maybe [Action] -> Parser [(Widget, ColorString, FontIndex, Maybe [Action])] -allParsers c f a = - textParser c f a - <|> try (iconParser c f a) - <|> try (rawParser c f a) - <|> try (actionParser c f a) - <|> try (fontParser c a) - <|> colorParser f a +allParsers c f a = textParser c f a + <|> try (iconParser c f a) + <|> try (rawParser c f a) + <|> try (actionParser c f a) + <|> try (fontParser c a) + <|> colorParser f a -- | Gets the string and combines the needed parsers stringParser :: String -> FontIndex -> Maybe [Action] diff --git a/src/lib/Xmobar/Plugins/BufferedPipeReader.hs b/src/lib/Xmobar/Plugins/BufferedPipeReader.hs index 9bb421e..0b55cf7 100644 --- a/src/lib/Xmobar/Plugins/BufferedPipeReader.hs +++ b/src/lib/Xmobar/Plugins/BufferedPipeReader.hs @@ -12,7 +12,7 @@ -- ----------------------------------------------------------------------------- -module Xmobar.Plugins.BufferedPipeReader where +module Xmobar.Plugins.BufferedPipeReader(BufferedPipeReader(..)) where import Control.Monad(forM_, when, void) import Control.Concurrent diff --git a/src/lib/Xmobar/Plugins/CommandReader.hs b/src/lib/Xmobar/Plugins/CommandReader.hs index 87cf5a4..4c71c96 100644 --- a/src/lib/Xmobar/Plugins/CommandReader.hs +++ b/src/lib/Xmobar/Plugins/CommandReader.hs @@ -13,7 +13,7 @@ -- ----------------------------------------------------------------------------- -module Xmobar.Plugins.CommandReader where +module Xmobar.Plugins.CommandReader(CommandReader(..)) where import System.IO import Xmobar.Commands diff --git a/src/lib/Xmobar/Plugins/DateZone.hs b/src/lib/Xmobar/Plugins/DateZone.hs index d3d4341..5dad871 100644 --- a/src/lib/Xmobar/Plugins/DateZone.hs +++ b/src/lib/Xmobar/Plugins/DateZone.hs @@ -23,7 +23,6 @@ module Xmobar.Plugins.DateZone (DateZone(..)) where import Xmobar.Commands -import Xmobar.Commands(tenthSeconds) #ifdef DATEZONE import Control.Concurrent.STM diff --git a/src/lib/Xmobar/Plugins/Kbd.hs b/src/lib/Xmobar/Plugins/Kbd.hs new file mode 100644 index 0000000..76914cc --- /dev/null +++ b/src/lib/Xmobar/Plugins/Kbd.hs @@ -0,0 +1,96 @@ +----------------------------------------------------------------------------- +-- | +-- Module : Plugins.Kbd +-- Copyright : (c) Martin Perner +-- License : BSD-style (see LICENSE) +-- +-- Maintainer : Martin Perner <martin@perner.cc> +-- Stability : unstable +-- Portability : unportable +-- +-- A keyboard layout indicator for Xmobar +-- +----------------------------------------------------------------------------- + +module Xmobar.Plugins.Kbd(Kbd(..)) where + +import Data.List (isPrefixOf, findIndex) +import Data.Maybe (fromJust) +import Control.Monad (forever) +import Graphics.X11.Xlib +import Graphics.X11.Xlib.Extras + +import Xmobar.Commands +import Xmobar.Utils (nextEvent') +import Xmobar.System.Kbd + + +-- 'Bad' prefixes of layouts +noLaySymbols :: [String] +noLaySymbols = ["group", "inet", "ctr", "pc", "ctrl"] + + +-- splits the layout string into the actual layouts +splitLayout :: String -> [String] +splitLayout s = splitLayout' noLaySymbols $ split s '+' + +splitLayout' :: [String] -> [String] -> [String] +-- end of recursion, remove empty strings +splitLayout' [] s = map (takeWhile (\x -> x /= ':')) $ filter (\x -> length x > 0) s +-- remove current string if it has a 'bad' prefix +splitLayout' bad s = splitLayout' (tail bad) [x | x <- s, not $ isPrefixOf (head bad) x] + +-- split String at each Char +split :: String -> Char -> [String] +split [] _ = [""] +split (c:cs) delim + | c == delim = "" : rest + | otherwise = (c : head rest) : tail rest + where + rest = split cs delim + +-- replaces input string if on search list (exact match) with corresponding +-- element on replacement list. +-- +-- if not found, return string unchanged +searchReplaceLayout :: KbdOpts -> String -> String +searchReplaceLayout opts s = let c = findIndex (\x -> fst x == s) opts in + case c of + Nothing -> s + x -> let i = (fromJust x) in + snd $ opts!!i + +-- returns the active layout +getKbdLay :: Display -> KbdOpts -> IO String +getKbdLay dpy opts = do + lay <- getLayoutStr dpy + curLay <- getKbdLayout dpy + return $ searchReplaceLayout opts $ (splitLayout lay)!!(curLay) + + + +data Kbd = Kbd [(String, String)] + deriving (Read, Show) + +instance Exec Kbd where + alias (Kbd _) = "kbd" + start (Kbd opts) cb = do + + dpy <- openDisplay "" + + -- initial set of layout + cb =<< getKbdLay dpy opts + + -- enable listing for + -- group changes + _ <- xkbSelectEventDetails dpy xkbUseCoreKbd xkbStateNotify xkbAllStateComponentsMask xkbGroupStateMask + -- layout/geometry changes + _ <- xkbSelectEvents dpy xkbUseCoreKbd xkbNewKeyboardNotifyMask xkbNewKeyboardNotifyMask + + allocaXEvent $ \e -> forever $ do + nextEvent' dpy e + _ <- getEvent e + cb =<< getKbdLay dpy opts + + closeDisplay dpy + return () diff --git a/src/lib/Xmobar/Plugins/Locks.hs b/src/lib/Xmobar/Plugins/Locks.hs index c086464..1f73f1f 100644 --- a/src/lib/Xmobar/Plugins/Locks.hs +++ b/src/lib/Xmobar/Plugins/Locks.hs @@ -12,7 +12,7 @@ -- ----------------------------------------------------------------------------- -module Xmobar.Plugins.Locks where +module Xmobar.Plugins.Locks(Locks(..)) where import Graphics.X11 import Data.List @@ -20,7 +20,7 @@ import Data.Bits import Control.Monad import Graphics.X11.Xlib.Extras import Xmobar.Commands -import Xmobar.Plugins.Kbd +import Xmobar.System.Kbd import Xmobar.Utils (nextEvent') data Locks = Locks diff --git a/src/lib/Xmobar/Plugins/Mail.hs b/src/lib/Xmobar/Plugins/Mail.hs index 8c0321f..aa28b98 100644 --- a/src/lib/Xmobar/Plugins/Mail.hs +++ b/src/lib/Xmobar/Plugins/Mail.hs @@ -13,7 +13,7 @@ -- ----------------------------------------------------------------------------- -module Xmobar.Plugins.Mail where +module Xmobar.Plugins.Mail(Mail(..)) where import Xmobar.Commands #ifdef INOTIFY diff --git a/src/lib/Xmobar/Plugins/PipeReader.hs b/src/lib/Xmobar/Plugins/PipeReader.hs index ac59356..d04f747 100644 --- a/src/lib/Xmobar/Plugins/PipeReader.hs +++ b/src/lib/Xmobar/Plugins/PipeReader.hs @@ -12,7 +12,7 @@ -- ----------------------------------------------------------------------------- -module Xmobar.Plugins.PipeReader where +module Xmobar.Plugins.PipeReader(PipeReader(..)) where import System.IO import Xmobar.Commands(Exec(..)) diff --git a/src/lib/Xmobar/Plugins/Kbd.hsc b/src/lib/Xmobar/System/Kbd.hsc index 5439785..b9e1d57 100644 --- a/src/lib/Xmobar/Plugins/Kbd.hsc +++ b/src/lib/Xmobar/System/Kbd.hsc @@ -13,18 +13,13 @@ -- ----------------------------------------------------------------------------- -module Xmobar.Plugins.Kbd where +module Xmobar.System.Kbd where -import Graphics.X11.Xlib -import Graphics.X11.Xlib.Extras import Foreign import Foreign.C.Types import Foreign.C.String -import Control.Monad (forever) -import Xmobar.Commands -import Xmobar.Utils (nextEvent') -import Data.List (isPrefixOf, findIndex) -import Data.Maybe (fromJust) + +import Graphics.X11.Xlib #include <X11/XKBlib.h> #include <X11/extensions/XKB.h> @@ -97,10 +92,6 @@ getKbdLayout d = alloca $ \stRecPtr -> do st <- peek stRecPtr return $ fromIntegral (group st) --- --- --- - data XkbKeyNameRec = XkbKeyNameRec { name :: Ptr CChar -- array } @@ -307,7 +298,6 @@ xkbGroupNamesMask = #const XkbGroupNamesMask type KbdOpts = [(String, String)] --- gets the layout string getLayoutStr :: Display -> IO String getLayoutStr dpy = do kbdDescPtr <- xkbAllocKeyboard @@ -329,76 +319,3 @@ getLayoutStr' st dpy kbdDescPtr = else -- Behaviour on error do return "Error while requesting layout!" - - --- 'Bad' prefixes of layouts -noLaySymbols :: [String] -noLaySymbols = ["group", "inet", "ctr", "pc", "ctrl"] - - --- splits the layout string into the actual layouts -splitLayout :: String -> [String] -splitLayout s = splitLayout' noLaySymbols $ split s '+' - -splitLayout' :: [String] -> [String] -> [String] --- end of recursion, remove empty strings -splitLayout' [] s = map (takeWhile (\x -> x /= ':')) $ filter (\x -> length x > 0) s --- remove current string if it has a 'bad' prefix -splitLayout' bad s = splitLayout' (tail bad) [x | x <- s, not $ isPrefixOf (head bad) x] - --- split String at each Char -split :: String -> Char -> [String] -split [] _ = [""] -split (c:cs) delim - | c == delim = "" : rest - | otherwise = (c : head rest) : tail rest - where - rest = split cs delim - --- replaces input string if on search list (exact match) with corresponding --- element on replacement list. --- --- if not found, return string unchanged -searchReplaceLayout :: KbdOpts -> String -> String -searchReplaceLayout opts s = let c = findIndex (\x -> fst x == s) opts in - case c of - Nothing -> s - x -> let i = (fromJust x) in - snd $ opts!!i - --- returns the active layout -getKbdLay :: Display -> KbdOpts -> IO String -getKbdLay dpy opts = do - lay <- getLayoutStr dpy - curLay <- getKbdLayout dpy - return $ searchReplaceLayout opts $ (splitLayout lay)!!(curLay) - - - -data Kbd = Kbd [(String, String)] - deriving (Read, Show) - -instance Exec Kbd where - alias (Kbd _) = "kbd" - start (Kbd opts) cb = do - - dpy <- openDisplay "" - - -- initial set of layout - cb =<< getKbdLay dpy opts - - -- enable listing for - -- group changes - _ <- xkbSelectEventDetails dpy xkbUseCoreKbd xkbStateNotify xkbAllStateComponentsMask xkbGroupStateMask - -- layout/geometry changes - _ <- xkbSelectEvents dpy xkbUseCoreKbd xkbNewKeyboardNotifyMask xkbNewKeyboardNotifyMask - - allocaXEvent $ \e -> forever $ do - nextEvent' dpy e - _ <- getEvent e - cb =<< getKbdLay dpy opts - - closeDisplay dpy - return () - --- vim:ft=haskell:ts=4:shiftwidth=4:softtabstop=4:expandtab:foldlevel=20: |