Skip to content
Snippets Groups Projects
Commit d5f18388 authored by Jens Nolte's avatar Jens Nolte
Browse files

Fix render indicator by moving it to the end of the pipeline

parent eb0294f5
No related branches found
No related tags found
No related merge requests found
......@@ -12,7 +12,7 @@ import QBar.Pango
import QBar.Theme
import QBar.Util
import Control.Monad (forever, when, unless, forM_)
import Control.Monad (when, unless, forM_)
import Control.Concurrent.Async (async, link)
import Control.Concurrent.Event as Event
import Control.Concurrent.MVar (MVar, newMVar, modifyMVar, modifyMVar_)
......@@ -29,9 +29,8 @@ import Pipes.Concurrent (Input, spawn, latest, toOutput, fromInput)
import qualified Pipes.Prelude as PP
import System.IO (stdin, stdout, stderr, hFlush)
renderIndicator :: CachedBlock
-- Using 'cachedBlock' is a hack to actually get the block to update on every bar update (by doing this it will not get a cache later in the pipeline).
renderIndicator = forever $ each $ map (mkBlockState . mkBlockOutput . normalText) ["/", "-", "\\", "|"]
renderIndicators :: [Text]
renderIndicators = ["*"] <> cycle ["/", "-", "\\", "|"]
data PangoBlock = PangoBlock {
pangoBlockFullText :: PangoText,
......@@ -75,18 +74,27 @@ swayBarInput MainOptions{verbose} = swayBarInput'
swayBarOutput :: MainOptions -> Consumer [ThemedBlockOutput] IO ()
swayBarOutput options = do
swayBarOutput options@MainOptions{indicator} = do
-- Print header
liftIO $ do
putStrLn "{\"version\":1,\"click_events\":true}"
putStrLn "["
swayBarOutput'
if indicator
then swayBarOutputWithIndicator' renderIndicators
else swayBarOutput'
where
swayBarOutput' :: Consumer [ThemedBlockOutput] IO ()
swayBarOutput' = do
await >>= (liftIO . outputLine options)
blockOutputs <- await
liftIO $ outputLine options blockOutputs
swayBarOutput'
swayBarOutputWithIndicator' :: [Text] -> Consumer [ThemedBlockOutput] IO ()
swayBarOutputWithIndicator' [] = throw $ userError "List should be infinite"
swayBarOutputWithIndicator' (ind : inds) = do
blockOutputs <- await
liftIO $ outputLine options (blockOutputs <> [whiteThemedBlockOutput ind])
swayBarOutputWithIndicator' inds
outputLine :: MainOptions -> [ThemedBlockOutput] -> IO ()
outputLine MainOptions{verbose} themedBlocks = do
let encodedOutput = encodeOutput themedBlocks
......@@ -110,14 +118,8 @@ swayBarOutput options = do
}
runBarServer :: BarIO () -> MainOptions -> IO ()
runBarServer defaultBarConfig options = runBarHost barServer (swayBarInput options) loadBlocks
runBarServer defaultBarConfig options = runBarHost barServer (swayBarInput options) defaultBarConfig
where
loadBlocks :: BarIO ()
loadBlocks = do
-- Load blocks
when (indicator options) $ addBlock renderIndicator
defaultBarConfig
barServer :: Consumer [BlockOutput] IO ()
barServer = do
-- Event to render the bar (fired when block output or theme is changed)
......
......@@ -69,7 +69,6 @@ findTheme themeName = maybe invalidThemeName Right $ HM.lookup themeName themes
where
invalidThemeName = Left $ "Invalid theme: " <> themeName
mkTheme :: SimplifiedTheme -> Theme
mkTheme theming' = StaticTheme $ map themeBlock
where
......@@ -89,9 +88,22 @@ mkTheme theming' = StaticTheme $ map themeBlock
themeSegment :: SimplifiedTheme -> BlockTextSegment -> ThemedBlockTextSegment
themeSegment theming BlockTextSegment {active, importance, segmentText} = mkThemedSegment (theming active importance) segmentText
mkThemedBlockOutput :: (Color, Maybe Color) -> Text -> ThemedBlockOutput
mkThemedBlockOutput color text = ThemedBlockOutput {
_fullText = mkThemedText color text,
_shortText = Nothing,
_blockName = Nothing
}
mkThemedText :: (Color, Maybe Color) -> Text -> ThemedBlockText
mkThemedText color text = ThemedBlockText [mkThemedSegment color text]
mkThemedSegment :: (Color, Maybe Color) -> Text -> ThemedBlockTextSegment
mkThemedSegment (color, backgroundColor) text = ThemedBlockTextSegment{themedSegmentText=text, color, backgroundColor}
whiteThemedBlockOutput :: Text -> ThemedBlockOutput
whiteThemedBlockOutput = mkThemedBlockOutput (ColorRGB (RGB 1 1 1), Nothing)
invalidColor :: Color
invalidColor = ColorRGBA (RGB (0x96 / 255) (0x98 / 255) (0x96 / 255)) (0x77 / 255)
......@@ -151,4 +163,3 @@ rainbowTheme = AnimatedTheme rainbowThemePipe
let hue' = position * 3
color = hsv hue' 0.8 1.0
in ColorRGB color
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment