diff --git a/dotfiles/config/taffybar/taffybar.css b/dotfiles/config/taffybar/taffybar.css index fe92d7b6..9a3357a8 100644 --- a/dotfiles/config/taffybar/taffybar.css +++ b/dotfiles/config/taffybar/taffybar.css @@ -30,6 +30,12 @@ padding-right: 11px; } +/* Keep icon+label "combined" widgets left-aligned, including multiline labels. */ +.icon-label > .label { + -GtkLabel-xalign: 0; + -GtkLabel-justify: left; +} + /* Compact two-line RAM/SWAP widget: reduce icon padding a bit. */ .ram-swap .icon-label > .icon { /* Different glyphs have different visual widths; fix the icon column width @@ -301,6 +307,12 @@ letter-spacing: 0.2px; } +/* Clock stays centered even though combined widgets are left-aligned. */ +.clock label { + -GtkLabel-xalign: 0.5; + -GtkLabel-justify: center; +} + .wakeup-debug label { font-size: 10px; } diff --git a/dotfiles/config/taffybar/taffybar.hs b/dotfiles/config/taffybar/taffybar.hs index 294c7057..a111cede 100644 --- a/dotfiles/config/taffybar/taffybar.hs +++ b/dotfiles/config/taffybar/taffybar.hs @@ -9,6 +9,7 @@ import Control.Monad (when) import Control.Monad.IO.Class (MonadIO, liftIO) import Control.Monad.Trans.Reader (asks) import Data.Char (toLower) +import Data.GI.Base (castTo) import Data.IORef (IORef, modifyIORef', newIORef, readIORef) import Data.Int (Int32) import Data.List (nub, sortOn, stripPrefix) @@ -75,6 +76,21 @@ decorateWithClassAndBoxM :: (MonadIO m) => Text -> m Gtk.Widget -> m Gtk.Widget decorateWithClassAndBoxM klass builder = builder >>= decorateWithClassAndBox klass +setLabelAlignmentRecursively :: Float -> Gtk.Justification -> Gtk.Widget -> IO () +setLabelAlignmentRecursively xalign justify widget = do + maybeLabel <- castTo Gtk.Label widget + case maybeLabel of + Just label -> do + Gtk.labelSetXalign label xalign + Gtk.labelSetJustify label justify + Nothing -> pure () + + maybeContainer <- castTo Gtk.Container widget + case maybeContainer of + Just container -> + Gtk.containerGetChildren container >>= mapM_ (setLabelAlignmentRecursively xalign justify) + Nothing -> pure () + -- ** X11 Workspaces x11FullWorkspaceNames :: X11Property [(WorkspaceId, String)] @@ -265,15 +281,15 @@ workspacesWidget = Workspaces.workspacesNew cfg } clockWidget :: TaffyIO Gtk.Widget -clockWidget = - decorateWithClassAndBoxM - "clock" - ( textClockNewWith - defaultClockConfig - { clockUpdateStrategy = RoundedTargetInterval 60 0.0, - clockFormatString = "%a %b %_d\n%I:%M %p" - } - ) +clockWidget = do + clock <- + textClockNewWith + defaultClockConfig + { clockUpdateStrategy = RoundedTargetInterval 60 0.0, + clockFormatString = "%a %b %_d\n%I:%M %p" + } + liftIO $ setLabelAlignmentRecursively 0.5 Gtk.JustificationCenter clock + decorateWithClassAndBox "clock" clock singleLineMprisLabel :: Text -> Text singleLineMprisLabel =