diff --git a/src/QBar/BlockOutput.hs b/src/QBar/BlockOutput.hs index 8230f62757c7ab69b2da399380a127d92f5301ec..b3756738fac568abd98f32474bbe568eb3bba58a 100644 --- a/src/QBar/BlockOutput.hs +++ b/src/QBar/BlockOutput.hs @@ -133,23 +133,30 @@ toImportance' (tMax, tCritical, tError, tWarning, tNormal, tMinimal) val valueOtherwise tNormal' Nothing v = 1 - logarithmicMatch v tNormal' +invalidateBlock :: BlockOutput -> BlockOutput +invalidateBlock block@BlockOutput{ _fullText, _shortText } = block { + _fullText = normalText . rawText $ _fullText, + _shortText = normalText . rawText <$> _shortText, + _invalid = True +} -removePango :: BlockText -> T.Text -removePango (BlockText b) = foldr ((<>) . removePangoFromSegment) "" b + +rawText :: BlockText -> T.Text +rawText (BlockText b) = foldMap rawTextFromSegment b where - removePangoFromSegment :: BlockTextSegment -> T.Text - removePangoFromSegment BlockTextSegment { active=_active, importance=_importance, text } = text - removePangoFromSegment (PangoTextSegment text) = + rawTextFromSegment :: BlockTextSegment -> T.Text + rawTextFromSegment BlockTextSegment{text} = text + rawTextFromSegment (PangoTextSegment text) = case parsePango text of Left _ -> text Right parsed -> removeFormatting parsed printedLength :: BlockText -> Int64 -printedLength (BlockText b) = foldr ((+) . printedLength') 0 b +printedLength (BlockText b) = sum . map segmentLength $ b where - printedLength' :: BlockTextSegment -> Int64 - printedLength' BlockTextSegment { text, active=_, importance=_ } = T.length text - printedLength' (PangoTextSegment _) = 0 + segmentLength :: BlockTextSegment -> Int64 + segmentLength BlockTextSegment { text } = T.length text + segmentLength (PangoTextSegment pango) = either (const $ T.length pango) (T.length . removeFormatting) $ parsePango pango mkText :: Bool -> Importance -> T.Text -> BlockText mkText active importance text = BlockText [BlockTextSegment { text = pangoFriendly text, active, importance }] diff --git a/src/QBar/Core.hs b/src/QBar/Core.hs index acb96548c799e54da377130de9b2daaac09eb766..0957f82573a8e02159e372114220034adda66e1d 100644 --- a/src/QBar/Core.hs +++ b/src/QBar/Core.hs @@ -187,7 +187,7 @@ sharedInterval seconds = do updateClickHandler Nothing _ = return () updateClickHandler (Just (block, _)) _ = do -- Give user feedback that the block is updating - let outdatedBlock = block & invalid.~True + let outdatedBlock = invalidateBlock block -- The invalidated block output has no event handler liftIO $ void $ atomically $ send output . Just $ (outdatedBlock, Nothing) -- Notify bar about changed block state to display the feedback diff --git a/src/QBar/Theme.hs b/src/QBar/Theme.hs index 7490ed2b27e89652034091d5be5b172be2bcdddb..ff6f294c3d77fa41bf9496505c359d7b3dfd4f36 100644 --- a/src/QBar/Theme.hs +++ b/src/QBar/Theme.hs @@ -71,7 +71,7 @@ rainbowTheme time blocks = reverse $ evalState (mapM rainbowBlock $ reverse bloc where rainbowBlock :: BlockOutput -> State Integer BlockOutput rainbowBlock block = do - let text = removePango $ block ^. fullText + let text = rawText $ block ^. fullText let chars = T.unpack . T.reverse $ text coloredChars <- mapM rainbowChar chars let rainbowText = T.concat . reverse $ coloredChars