Remove taffybar widget debug profiles

This commit is contained in:
2026-05-04 22:17:09 -07:00
parent 211aa60b73
commit 52aa541aee
3 changed files with 40 additions and 139 deletions

View File

@@ -8,28 +8,6 @@ run:
restart: restart:
@scripts/taffybar-restart @scripts/taffybar-restart
# Restart with one of the bisect widget profiles:
# minimal, workspaces, workspaces-windows, or full.
restart-widget-profile profile:
@TAFFYBAR_WIDGET_PROFILE='{{profile}}' scripts/taffybar-restart
# Restart a widget profile with draw and workspace update logging enabled.
# Inspect /tmp/taffybar.log after switching workspaces.
restart-redraw-debug profile="full":
@TAFFYBAR_WIDGET_PROFILE='{{profile}}' TAFFYBAR_DRAW_DEBUG=1 TAFFYBAR_WORKSPACE_DEBUG=1 scripts/taffybar-restart
# Minimal widget profile with all taffybar CSS disabled.
restart-redraw-minimal:
@TAFFYBAR_WIDGET_PROFILE='minimal' TAFFYBAR_DRAW_DEBUG=1 TAFFYBAR_WORKSPACE_DEBUG=1 TAFFYBAR_DISABLE_VENDOR_CSS=1 TAFFYBAR_DISABLE_USER_CSS=1 scripts/taffybar-restart
# Workspace-only profile with all taffybar CSS disabled.
restart-redraw-workspaces-empty-css:
@TAFFYBAR_WIDGET_PROFILE='workspaces' TAFFYBAR_DRAW_DEBUG=1 TAFFYBAR_WORKSPACE_DEBUG=1 TAFFYBAR_DISABLE_VENDOR_CSS=1 TAFFYBAR_DISABLE_USER_CSS=1 scripts/taffybar-restart
# Workspace-only profile with the normal configured CSS.
restart-redraw-workspaces-user-css:
@TAFFYBAR_WIDGET_PROFILE='workspaces' TAFFYBAR_DRAW_DEBUG=1 TAFFYBAR_WORKSPACE_DEBUG=1 scripts/taffybar-restart
# Restart with no vendor CSS (taffybar's built-in stylesheet) loaded. # Restart with no vendor CSS (taffybar's built-in stylesheet) loaded.
restart-no-vendor-css: restart-no-vendor-css:
@TAFFYBAR_DISABLE_VENDOR_CSS=1 scripts/taffybar-restart @TAFFYBAR_DISABLE_VENDOR_CSS=1 scripts/taffybar-restart

View File

@@ -37,7 +37,6 @@ executable taffybar
, time , time
, taffybar>=3.2.0 , taffybar>=3.2.0
, transformers , transformers
, unix
, xdg-basedir , xdg-basedir
default-language: Haskell2010 default-language: Haskell2010

View File

@@ -11,7 +11,6 @@ import Control.Monad.Trans.Reader (asks)
import Data.Char (toLower) import Data.Char (toLower)
import Data.Foldable (for_) import Data.Foldable (for_)
import Data.GI.Base (castTo) import Data.GI.Base (castTo)
import Data.IORef (newIORef, readIORef, writeIORef)
import Data.Int (Int32) import Data.Int (Int32)
import Data.List (nub) import Data.List (nub)
import qualified Data.Map as M import qualified Data.Map as M
@@ -26,9 +25,7 @@ import Network.HostName (getHostName)
import qualified StatusNotifier.Tray as SNITray import qualified StatusNotifier.Tray as SNITray
import System.Environment (lookupEnv) import System.Environment (lookupEnv)
import System.Environment.XDG.BaseDir (getUserConfigFile) import System.Environment.XDG.BaseDir (getUserConfigFile)
import System.IO (hFlush, stdout)
import System.Log.Logger (Priority (WARNING), rootLoggerName, setLevel, updateGlobalLogger) import System.Log.Logger (Priority (WARNING), rootLoggerName, setLevel, updateGlobalLogger)
import System.Posix.Process (getProcessID)
import System.Taffybar (startTaffybar) import System.Taffybar (startTaffybar)
import System.Taffybar.Context import System.Taffybar.Context
( Backend (BackendWayland, BackendX11), ( Backend (BackendWayland, BackendX11),
@@ -84,40 +81,6 @@ import System.Taffybar.WindowIcon (pixBufFromColor)
import Text.Printf (printf) import Text.Printf (printf)
import Text.Read (readMaybe) import Text.Read (readMaybe)
envFlag :: String -> IO Bool
envFlag name = do
value <- lookupEnv name
pure $
case fmap (map toLower) value of
Just "1" -> True
Just "true" -> True
Just "yes" -> True
Just "on" -> True
_ -> False
envTextDefault :: String -> Text -> IO Text
envTextDefault name fallback =
maybe fallback T.pack <$> lookupEnv name
attachDrawProbe :: Text -> Gtk.Widget -> TaffyIO Gtk.Widget
attachDrawProbe name widget = do
enabled <- liftIO $ envFlag "TAFFYBAR_DRAW_DEBUG"
when enabled $ liftIO $ do
counter <- newIORef (0 :: Int)
pid <- getProcessID
_ <- Gtk.onWidgetDraw widget $ \_ -> do
count <- (+ 1) <$> readIORef counter
writeIORef counter count
printf "taffybar-draw pid=%s widget=%s count=%d\n" (show pid) (T.unpack name) count
hFlush stdout
pure False
pure ()
pure widget
withDrawProbe :: Text -> TaffyIO Gtk.Widget -> TaffyIO Gtk.Widget
withDrawProbe name builder =
builder >>= attachDrawProbe name
-- | Wrap the widget in a "TaffyBox" (via 'buildContentsBox') and add a CSS class. -- | Wrap the widget in a "TaffyBox" (via 'buildContentsBox') and add a CSS class.
decorateWithClassAndBox :: (MonadIO m) => Text -> Gtk.Widget -> m Gtk.Widget decorateWithClassAndBox :: (MonadIO m) => Text -> Gtk.Widget -> m Gtk.Widget
decorateWithClassAndBox klass widget = do decorateWithClassAndBox klass widget = do
@@ -355,19 +318,14 @@ windowsWidget =
) )
workspacesWidget :: TaffyIO Gtk.Widget workspacesWidget :: TaffyIO Gtk.Widget
workspacesWidget = do workspacesWidget =
iconProfile <- liftIO $ envTextDefault "TAFFYBAR_WORKSPACE_ICON_PROFILE" "custom" Workspaces.workspacesNew cfg
Workspaces.workspacesNew (cfg iconProfile)
where where
iconGetter "default" = Workspaces.defaultGetWindowIconPixbuf cfg =
iconGetter "fallback" = workspaceFallbackIcon
iconGetter "none" = \_ _ -> return Nothing
iconGetter _ = workspaceWindowIconGetter
cfg iconProfile =
Workspaces.defaultWorkspacesConfig Workspaces.defaultWorkspacesConfig
{ Workspaces.widgetGap = 0, { Workspaces.widgetGap = 0,
Workspaces.minIcons = 1, Workspaces.minIcons = 1,
Workspaces.getWindowIconPixbuf = iconGetter iconProfile, Workspaces.getWindowIconPixbuf = workspaceWindowIconGetter,
Workspaces.labelSetter = workspaceLabelSetter, Workspaces.labelSetter = workspaceLabelSetter,
Workspaces.showWorkspaceFn = Workspaces.showWorkspaceFn =
\workspace -> \workspace ->
@@ -713,99 +671,66 @@ sniTrayWidget = do
-- ** Layout -- ** Layout
probeWidgets :: [(Text, TaffyIO Gtk.Widget)] -> [TaffyIO Gtk.Widget] startWidgetsForBackend :: Backend -> [TaffyIO Gtk.Widget]
probeWidgets = startWidgetsForBackend backend =
map (uncurry withDrawProbe)
startWidgetsForBackend :: Text -> Backend -> [TaffyIO Gtk.Widget]
startWidgetsForBackend "minimal" _ =
[]
startWidgetsForBackend "workspaces" _ =
probeWidgets [("workspaces", workspacesWidget)]
startWidgetsForBackend "workspaces-windows" _ =
probeWidgets [("workspaces", workspacesWidget), ("windows", windowsWidget)]
startWidgetsForBackend _ backend =
case backend of case backend of
BackendX11 -> BackendX11 -> [omniMenuWidget, workspacesWidget, layoutWidget, windowsWidget]
probeWidgets
[ ("omni-menu", omniMenuWidget),
("workspaces", workspacesWidget),
("layout", layoutWidget),
("windows", windowsWidget)
]
-- These Wayland widgets are Hyprland-specific. -- These Wayland widgets are Hyprland-specific.
BackendWayland -> BackendWayland -> [omniMenuWidget, workspacesWidget, windowsWidget]
probeWidgets
[ ("omni-menu", omniMenuWidget),
("workspaces", workspacesWidget),
("windows", windowsWidget)
]
centerWidgetsForProfile :: Text -> [TaffyIO Gtk.Widget] endWidgetsForHost :: String -> [TaffyIO Gtk.Widget]
centerWidgetsForProfile "workspaces" = [] endWidgetsForHost hostName =
centerWidgetsForProfile _ = probeWidgets [("clock", clockWidget)]
endWidgetsForHost :: Text -> String -> [TaffyIO Gtk.Widget]
endWidgetsForHost "minimal" _ =
[]
endWidgetsForHost "workspaces" _ =
[]
endWidgetsForHost "workspaces-windows" _ =
[]
endWidgetsForHost _ hostName =
-- NOTE: end widgets are packed with Gtk.boxPackEnd, so the list order is -- NOTE: end widgets are packed with Gtk.boxPackEnd, so the list order is
-- right-to-left on screen. Make the tray appear at the far right by placing -- right-to-left on screen. Make the tray appear at the far right by placing
-- it first in the list. (On laptops: the battery/wifi stack is far right, -- it first in the list. (On laptops: the battery/wifi stack is far right,
-- tray immediately left of it.) -- tray immediately left of it.)
let baseEndWidgets = let baseEndWidgets =
probeWidgets [ sniTrayWidget,
[ ("sni-tray", sniTrayWidget), audioWidget,
("audio", audioWidget), anthropicUsageWidget,
("anthropic-usage", anthropicUsageWidget), openAIUsageWidget,
("openai-usage", openAIUsageWidget), cpuWidget,
("cpu", cpuWidget), ramSwapWidget,
("ram-swap", ramSwapWidget), diskUsageWidget,
("disk-usage", diskUsageWidget), networkWidget,
("network", networkWidget), sunLockWidget,
("sun-lock", sunLockWidget), mprisWidget
("mpris", mprisWidget)
] ]
laptopEndWidgets = laptopEndWidgets =
probeWidgets [ batteryNetworkWidget,
[ ("battery-network", batteryNetworkWidget), sniTrayWidget,
("sni-tray", sniTrayWidget), asusDiskUsageWidget,
("asus-disk-usage", asusDiskUsageWidget), audioBacklightWidget,
("audio-backlight", audioBacklightWidget), anthropicUsageWidget,
("anthropic-usage", anthropicUsageWidget), openAIUsageWidget,
("openai-usage", openAIUsageWidget), cpuWidget,
("cpu", cpuWidget), ramSwapWidget,
("ram-swap", ramSwapWidget), sunLockWidget,
("sun-lock", sunLockWidget), mprisWidget
("mpris", mprisWidget)
] ]
in if hostName `elem` laptopHosts in if hostName `elem` laptopHosts
then laptopEndWidgets then laptopEndWidgets
else baseEndWidgets else baseEndWidgets
mkSimpleTaffyConfig :: String -> Text -> Backend -> [FilePath] -> SimpleTaffyConfig mkSimpleTaffyConfig :: String -> Backend -> [FilePath] -> SimpleTaffyConfig
mkSimpleTaffyConfig hostName widgetProfile backend cssFiles = mkSimpleTaffyConfig hostName backend cssFiles =
defaultSimpleTaffyConfig defaultSimpleTaffyConfig
{ startWidgets = startWidgetsForBackend widgetProfile backend, { startWidgets = startWidgetsForBackend backend,
centerWidgets = centerWidgetsForProfile widgetProfile, centerWidgets = [clockWidget],
endWidgets = endWidgetsForHost widgetProfile hostName, endWidgets = endWidgetsForHost hostName,
barLevels = Nothing, barLevels = Nothing,
barPosition = Top, barPosition = Top,
widgetSpacing = 0, widgetSpacing = 0,
barPadding = barPadding =
if hostName `elem` smallBarHosts if hostName `elem` smallBarHosts
then 0 then 1
else else
if hostName `elem` compactBarHosts if hostName `elem` compactBarHosts
then 2 then 2
else 4, else 4,
barHeight = barHeight =
if hostName `elem` smallBarHosts if hostName `elem` smallBarHosts
then ScreenRatio $ 1 / 64 then ScreenRatio $ 1 / 48
else else
if hostName `elem` compactBarHosts if hostName `elem` compactBarHosts
then ScreenRatio $ 1 / 40 then ScreenRatio $ 1 / 40
@@ -821,10 +746,9 @@ main = do
hostName <- getHostName hostName <- getHostName
backend <- detectBackend backend <- detectBackend
widgetProfile <- envTextDefault "TAFFYBAR_WIDGET_PROFILE" "full"
cssFiles <- mapM (getUserConfigFile "taffybar") (cssFilesForHost hostName) cssFiles <- mapM (getUserConfigFile "taffybar") (cssFilesForHost hostName)
let simpleTaffyConfig = mkSimpleTaffyConfig hostName widgetProfile backend cssFiles let simpleTaffyConfig = mkSimpleTaffyConfig hostName backend cssFiles
startTaffybar $ startTaffybar $
withLogServer $ withLogServer $
withLogLevels $ withLogLevels $