style(taffybar): align combined labels and keep clock centered

This commit is contained in:
2026-02-20 02:43:15 -08:00
committed by Kat Huang
parent 384d2dfd6a
commit 2db7f07982
2 changed files with 37 additions and 9 deletions

View File

@@ -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;
}

View File

@@ -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
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 =