diff options
author | Sibi Prabakaran <sibi@psibi.in> | 2020-05-10 19:43:56 +0530 |
---|---|---|
committer | Sibi Prabakaran <sibi@psibi.in> | 2020-05-10 19:43:56 +0530 |
commit | 3e9e1cb9d300e13109206496d825351c4f41cc1c (patch) | |
tree | d40f6c9f185ea4b01b6652e4178a5f28e450c8fa /src/Xmobar/App | |
parent | 6f3b730415147041ff34558fe7292a76dc87b1f0 (diff) | |
download | xmobar-3e9e1cb9d300e13109206496d825351c4f41cc1c.tar.gz xmobar-3e9e1cb9d300e13109206496d825351c4f41cc1c.tar.bz2 |
Fix crashes/busy looping happening via index
Right now, with the `StdinReader` plugin enabled - you can crash/cause
busy looping of xmobar if the following html file is opened:
```
<html>
<head>
<title>hello <fn=1>string</fn> </title>
</head>
</html>
```
More details about this bug is here:
https://github.com/jaor/xmobar/issues/442#issuecomment-625706001
This MR also fixes another bug which produces a crash in xmobar if you
pass non integer items between fn:
<fn=crash>
Diffstat (limited to 'src/Xmobar/App')
-rw-r--r-- | src/Xmobar/App/EventLoop.hs | 6 | ||||
-rw-r--r-- | src/Xmobar/App/Main.hs | 3 |
2 files changed, 6 insertions, 3 deletions
diff --git a/src/Xmobar/App/EventLoop.hs b/src/Xmobar/App/EventLoop.hs index f6ab932..cad95a5 100644 --- a/src/Xmobar/App/EventLoop.hs +++ b/src/Xmobar/App/EventLoop.hs @@ -40,6 +40,7 @@ import Control.Exception (bracket_, handle, SomeException(..)) import Data.Bits import Data.Map hiding (foldr, map, filter) import Data.Maybe (fromJust, isJust) +import qualified Data.List.NonEmpty as NE import Xmobar.System.Signal import Xmobar.Config.Types @@ -52,6 +53,7 @@ import Xmobar.X11.Text import Xmobar.X11.Draw import Xmobar.X11.Bitmap as Bitmap import Xmobar.X11.Types +import Xmobar.System.Utils (safeIndex) #ifndef THREADED_RUNTIME import Xmobar.X11.Events(nextEvent') @@ -208,7 +210,7 @@ eventLoop tv xc@(XConf d r w fs vos is cfg) as signal = do eventLoop tv xc as signal reposWindow rcfg = do - r' <- repositionWin d w (head fs) rcfg + r' <- repositionWin d w (NE.head fs) rcfg eventLoop tv (XConf d r' w fs vos is rcfg) as signal updateConfigPosition ocfg = @@ -262,7 +264,7 @@ updateActions conf (Rectangle _ _ wid _) ~[left,center,right] = do strLn :: [(Widget, String, Int, Maybe [Action])] -> IO [(Maybe [Action], Position, Position)] strLn = liftIO . mapM getCoords iconW i = maybe 0 Bitmap.width (lookup i $ iconS conf) - getCoords (Text s,_,i,a) = textWidth d (fs!!i) s >>= \tw -> return (a, 0, fi tw) + getCoords (Text s,_,i,a) = textWidth d (safeIndex fs i) s >>= \tw -> return (a, 0, fi tw) getCoords (Icon s,_,_,a) = return (a, 0, fi $ iconW s) partCoord off xs = map (\(a, x, x') -> (fromJust a, x, x')) $ filter (\(a, _,_) -> isJust a) $ diff --git a/src/Xmobar/App/Main.hs b/src/Xmobar/App/Main.hs index e0b0329..f173e12 100644 --- a/src/Xmobar/App/Main.hs +++ b/src/Xmobar/App/Main.hs @@ -29,6 +29,7 @@ import System.Environment (getArgs) import System.FilePath import System.FilePath.Posix (takeBaseName, takeDirectory) import Text.Parsec.Error (ParseError) +import Data.List.NonEmpty (NonEmpty(..)) import Graphics.X11.Xlib @@ -63,7 +64,7 @@ xmobar conf = withDeferSignals $ do let ic = Map.empty to = textOffset conf ts = textOffsets conf ++ replicate (length fl) (-1) - startLoop (XConf d r w (fs:fl) (to:ts) ic conf) sig refLock vars + startLoop (XConf d r w (fs :| fl) (to:ts) ic conf) sig refLock vars configFromArgs :: Config -> IO Config configFromArgs cfg = getArgs >>= getOpts >>= doOpts cfg . fst |