xmobar 0.48 → 0.48.1
raw patch · 4 files changed
+20/−62 lines, 4 files
Files
- changelog.md +5/−0
- doc/plugins.org +2/−3
- src/Xmobar/Plugins/Kbd.hs +12/−58
- xmobar.cabal +1/−1
changelog.md view
@@ -1,3 +1,8 @@+## Version 0.48.1 (May, 2024)++- Removing for now mouse support for `Kbd`, which can be recovered by+ interested users using regular actions (see issue #703 for further details).+ ## Version 0.48 (April, 2024) - The `Kbd` monitor is now clickable (thanks, Enrico Maria)
doc/plugins.org view
@@ -658,9 +658,8 @@ ** Keyboard and screen monitors *** =Kbd Opts= - - Registers to XKB/X11-Events, output the currently active keyboard- layout, and maps left and right clicks to switching to next and- previous layouts respectively. Supports replacement of layout names.+ - Registers to XKB/X11-Events and output the currently active keyboard+ layout. Supports replacement of layout names. - Aliases to =kbd=
src/Xmobar/Plugins/Kbd.hs view
@@ -14,11 +14,9 @@ module Xmobar.Plugins.Kbd(Kbd(..)) where -import Data.Bifunctor (bimap)-import Data.List (find, tails, isPrefixOf)+import Data.List (isPrefixOf) import Data.Maybe (fromMaybe)-import Data.Char (toLower, isLetter)-import Data.Function ((&))+import Data.Char (toLower) import Control.Monad (forever) import Control.Applicative ((<|>)) import Graphics.X11.Xlib@@ -28,13 +26,6 @@ import Xmobar.X11.Events (nextEvent') import Xmobar.System.Kbd --- some strong typing-newtype Lay = Lay String deriving (Eq)-newtype Sym = Sym String-instance Show Sym where show (Sym s) = s-type KbdOpts' = [(Lay, Sym)]-typed :: [(String, String)] -> [(Lay, Sym)]-typed = map (bimap Lay Sym) -- 'Bad' prefixes of layouts noLaySymbols :: [String]@@ -58,22 +49,15 @@ (pref, "") -> [pref] -- replaces input string if on search list (exact match) with corresponding--- element on replacement list, and returns it paired with the following item+-- element on replacement list. ----- if not found, return string unchanged, paired with empty string-searchReplaceLayout :: KbdOpts' -> String -> (Lay, Lay, Sym)-searchReplaceLayout opts curr- = maybe (Lay "", Lay "", Sym curr)- pickSymWithAdjLays- (find currLayout (tails $ cycle opts))- where- pickSymWithAdjLays ((l1, _):(_, s):(l2, _):_) = (l1, l2, s)- pickSymWithAdjLays _ = error "This should never happen"- currLayout = (Lay curr ==) . (!! 1) . map fst+-- if not found, return string unchanged+searchReplaceLayout :: KbdOpts -> String -> String+searchReplaceLayout opts s = fromMaybe s $ lookup s opts --- returns the active layout and the following one-getCurAndNextKbdLays :: Display -> KbdOpts' -> IO (Lay, Lay, Sym)-getCurAndNextKbdLays dpy opts = do+-- returns the active layout+getKbdLay :: Display -> KbdOpts -> IO String+getKbdLay dpy opts = do lay <- splitLayout <$> getLayoutStr dpy grps <- map (map toLower . take 2) <$> getGrpNames dpy curLay <- getKbdLayout dpy@@ -89,37 +73,6 @@ newtype Kbd = Kbd [(String, String)] deriving (Read, Show) -attachClickAction :: (Lay, Lay, Sym) -> Sym-attachClickAction (Lay prv, Lay nxt, txt) = txt & linkTo nxt `onKey` "1"- & linkTo prv `onKey` "3"- where- splitLayParensPhon :: String -> (String, String, String)- splitLayParensPhon = (\(a, (b, c)) -> (a, b, c))- . second (second (drop 1) . break (== ')') . drop 1)- . break (== '(')- parseLayPhon :: String -> (Maybe String, Maybe String)- parseLayPhon s = let (l, p, i) = splitLayParensPhon s- l' = if all isLetter l- then Just ("-layout " ++ l)- else Nothing- p' = if (p, i) == ("phonetic", "")- then Just "-variant phonetic"- else Nothing- in (l', p')- linkTo :: String -> String -> Sym -> Sym- linkTo linked button currLay = Sym $ case parseLayPhon linked of- (Nothing, _) -> "??"- (Just linkedLay, phon) -> wrapIn setxkbmap button currLay- where- setxkbmap = unwords ["setxkbmap", linkedLay, fromMaybe "" phon]- wrapIn :: String -> String -> Sym -> String- wrapIn action buttons (Sym sym) = openingTag ++ sym ++ closingTag- where- openingTag = "<action=`" ++ action ++ "` button=" ++ buttons ++ ">"- closingTag = "</action>"- onKey = ($)- second = fmap- instance Exec Kbd where alias (Kbd _) = "kbd" start (Kbd opts) cb = do@@ -127,7 +80,7 @@ dpy <- openDisplay "" -- initial set of layout- cb . show . attachClickAction =<< getCurAndNextKbdLays dpy (typed opts)+ cb =<< getKbdLay dpy opts -- enable listing for -- group changes@@ -138,6 +91,7 @@ allocaXEvent $ \e -> forever $ do nextEvent' dpy e _ <- getEvent e- cb . show . attachClickAction =<< getCurAndNextKbdLays dpy (typed opts)+ cb =<< getKbdLay dpy opts closeDisplay dpy+ return ()
xmobar.cabal view
@@ -1,5 +1,5 @@ name: xmobar-version: 0.48+version: 0.48.1 homepage: https://codeberg.org/xmobar/xmobar synopsis: A Minimalistic Text Based Status Bar description: Xmobar is a minimalistic text based status bar.