packages feed

taffybar 0.1.0 → 0.1.1

raw patch · 6 files changed

+145/−99 lines, 6 filesdep +filepathdep +xdg-basedir

Dependencies added: filepath, xdg-basedir

Files

src/System/Taffybar.hs view
@@ -1,94 +1,128 @@--- | This is a system status bar meant for use with window manager--- like XMonad.  It is similar to xmobar, but with more visual flare--- and a different widget set.  Contributed widgets are more than--- welcome.  The bar is drawn using gtk and cairo.  It is actually the--- simplest possible thing that could plausibly work: you give--- Taffybar a list of GTK widgets and it will render them in a--- horizontal bar for you (taking care of ugly details like reserving--- strut space so that window managers don't put windows over it).------ This is the real main module.  The default bar should be--- customized to taste in the config file--- (~/.config/taffybar/taffybar.hs).  Typically, this means adding--- widgets to the default config.  A default configuration file is--- included in the distribution, but the essentials are covered here.------ The config file is just a Haskell source file that is compiled at--- startup (if it has changed) to produce a custom executable with the--- desired set of widgets.  You will want to import this module along--- with the modules of any widgets you want to add to the bar.  Note,--- you can define any widgets that you want in your config file or--- other libraries.  Taffybar only cares that you give it some GTK--- widgets to display.------ Below is a fairly typical example:------ > import System.Taffybar--- > import System.Taffybar.Systray--- > import System.Taffybar.XMonadLog--- > import System.Taffybar.SimpleClock--- > import System.Taffybar.Widgets.PollingGraph--- > import System.Information.CPU--- >--- > cpuCallback = do--- >   (_, systemLoad, totalLoad) <- cpuLoad--- >   return [ totalLoad, systemLoad ]--- >--- > main = do--- >   let cpuCfg = defaultGraphConfig { graphDataColors = [ (0, 1, 0, 1), (1, 0, 1, 0.5)]--- >                                   , graphLabel = Just "cpu"--- >                                   }--- >       clock = textClockNew Nothing "<span fgcolor='orange'>%a %b %_d %H:%M</span>" 1--- >       log = xmonadLogNew--- >       tray = systrayNew--- >       cpu = pollingGraphNew cpuCfg 0.5 cpuCallback--- >   defaultTaffybar defaultTaffybarConfig { startWidgets = [ log ]--- >                                         , endWidgets = [ tray, clock, cpu ]--- >                                         }------ This configuration creates a bar with four widgets.  On the left is--- the XMonad log.  The rightmost widget is the system tray, with a--- clock and then a CPU graph.  The clock is formatted using standard--- strftime-style format strings (see the clock module).  Note that--- the clock is colored using Pango markup (again, see the clock--- module).------ The CPU widget plots two graphs on the same widget: total CPU use--- in green and then system CPU use in a kind of semi-transparent--- purple on top of the green.------ It is important to note that the widget lists are *not* [Widget].--- They are actually [IO Widget] since the bar needs to construct them--- after performing some GTK initialization.------ The XMonadLog widget differs from its counterpart in xmobar: it--- listens for updates over DBus instead of reading from stdin.  This--- makes it easy to restart Taffybar independently of XMonad.  XMonad--- does not come with a DBus logger, so here is an example of how to--- make it work.  Note: this requires the dbus-core (>0.9) package,--- which is installed as a dependency of Taffybar.------ > import XMonad.Hooks.DynamicLog--- > import DBus.Client.Simple--- > import System.Taffybar.XMonadLog ( dbusLog )--- >--- > main = do--- >   client <- connectSession--- >   let pp = defaultPP--- >   xmonad defaultConfig { logHook = dbusLog client pp }------ The complexity is handled in the System.Tafftbar.XMonadLog module.+-- | The main module of Taffybar module System.Taffybar (+  -- * Detail+  --+  -- | This is a system status bar meant for use with window manager+  -- like XMonad.  It is similar to xmobar, but with more visual flare+  -- and a different widget set.  Contributed widgets are more than+  -- welcome.  The bar is drawn using gtk and cairo.  It is actually+  -- the simplest possible thing that could plausibly work: you give+  -- Taffybar a list of GTK widgets and it will render them in a+  -- horizontal bar for you (taking care of ugly details like+  -- reserving strut space so that window managers don't put windows+  -- over it).+  --+  -- This is the real main module.  The default bar should be+  -- customized to taste in the config file+  -- (~/.config/taffybar/taffybar.hs).  Typically, this means adding+  -- widgets to the default config.  A default configuration file is+  -- included in the distribution, but the essentials are covered+  -- here.++  -- * Config File+  --+  -- | The config file is just a Haskell source file that is compiled+  -- at startup (if it has changed) to produce a custom executable+  -- with the desired set of widgets.  You will want to import this+  -- module along with the modules of any widgets you want to add to+  -- the bar.  Note, you can define any widgets that you want in your+  -- config file or other libraries.  Taffybar only cares that you+  -- give it some GTK widgets to display.+  --+  -- Below is a fairly typical example:+  --+  -- > import System.Taffybar+  -- > import System.Taffybar.Systray+  -- > import System.Taffybar.XMonadLog+  -- > import System.Taffybar.SimpleClock+  -- > import System.Taffybar.Widgets.PollingGraph+  -- > import System.Information.CPU+  -- >+  -- > cpuCallback = do+  -- >   (_, systemLoad, totalLoad) <- cpuLoad+  -- >   return [ totalLoad, systemLoad ]+  -- >+  -- > main = do+  -- >   let cpuCfg = defaultGraphConfig { graphDataColors = [ (0, 1, 0, 1), (1, 0, 1, 0.5)]+  -- >                                   , graphLabel = Just "cpu"+  -- >                                   }+  -- >       clock = textClockNew Nothing "<span fgcolor='orange'>%a %b %_d %H:%M</span>" 1+  -- >       log = xmonadLogNew+  -- >       tray = systrayNew+  -- >       cpu = pollingGraphNew cpuCfg 0.5 cpuCallback+  -- >   defaultTaffybar defaultTaffybarConfig { startWidgets = [ log ]+  -- >                                         , endWidgets = [ tray, clock, cpu ]+  -- >                                         }+  --+  -- This configuration creates a bar with four widgets.  On the left is+  -- the XMonad log.  The rightmost widget is the system tray, with a+  -- clock and then a CPU graph.  The clock is formatted using standard+  -- strftime-style format strings (see the clock module).  Note that+  -- the clock is colored using Pango markup (again, see the clock+  -- module).+  --+  -- The CPU widget plots two graphs on the same widget: total CPU use+  -- in green and then system CPU use in a kind of semi-transparent+  -- purple on top of the green.+  --+  -- It is important to note that the widget lists are *not* [Widget].+  -- They are actually [IO Widget] since the bar needs to construct them+  -- after performing some GTK initialization.++  -- * XMonad Integration (via DBus)+  --+  -- | The XMonadLog widget differs from its counterpart in xmobar: it+  -- listens for updates over DBus instead of reading from stdin.+  -- This makes it easy to restart Taffybar independently of XMonad.+  -- XMonad does not come with a DBus logger, so here is an example of+  -- how to make it work.  Note: this requires the dbus-core (>0.9)+  -- package, which is installed as a dependency of Taffybar.+  --+  -- > import XMonad.Hooks.DynamicLog+  -- > import DBus.Client.Simple+  -- > import System.Taffybar.XMonadLog ( dbusLog )+  -- >+  -- > main = do+  -- >   client <- connectSession+  -- >   let pp = defaultPP+  -- >   xmonad defaultConfig { logHook = dbusLog client pp }+  --+  -- The complexity is handled in the System.Tafftbar.XMonadLog module.++  -- ** A note about DBus:+  -- |+  -- * If you start xmonad using a graphical login manager like gdm or+  --   kdm, DBus should be started automatically for you.+  --+  -- * If you start xmonad with a different graphical login manager that+  --   does not start DBus for you automatically, put the line @eval+  --   \`dbus-launch --auto-syntax\`@ into your ~\/.xsession *before*+  --   xmonad and taffybar are started.  This command sets some+  --   environment variables that the two must agree on.+  --+  -- * If you start xmonad via @startx@ or a similar command, add the+  --   above command to ~\/.xinitrc++  -- * Colors+  --+  -- | While taffybar is based on GTK+, it ignores your GTK+ theme.+  -- The default theme that it uses is in+  -- @~\/.cabal\/share\/taffybar-\<version\>\/taffybar.rc@.  You can+  -- customize this theme by copying it to+  -- @~\/.config\/taffybar\/taffybar.rc@.  For an idea of the customizations you can make,+  -- see <https://live.gnome.org/GnomeArt/Tutorials/GtkThemes>.   TaffybarConfig(..),   defaultTaffybar,   defaultTaffybarConfig   ) where  import qualified Config.Dyre as Dyre-+import System.Environment.XDG.BaseDir ( getUserConfigFile )+import System.FilePath ( (</>) ) import Graphics.UI.Gtk import Text.Printf +import Paths_taffybar ( getDataDir ) import System.Taffybar.StrutProperties  data TaffybarConfig =@@ -134,9 +168,23 @@     Nothing -> taffybarMain cfg     Just err -> error ("Error: " ++ err) +getDefaultConfigFile :: String -> IO FilePath+getDefaultConfigFile name = do+  dataDir <- getDataDir+  return (dataDir </> name)+ taffybarMain :: TaffybarConfig -> IO () taffybarMain cfg = do+  -- Override the default GTK theme path settings.  This causes the+  -- bar (by design) to ignore the real GTK theme and just use the+  -- provided minimal theme to set the background and text colors.+  -- Users can override this default.+  defaultGtkConfig <- getDefaultConfigFile "taffybar.rc"+  userGtkConfig <- getUserConfigFile "taffybar" "taffybar.rc"+  rcSetDefaultFiles [ defaultGtkConfig, userGtkConfig ]+   _ <- initGUI+   Just disp <- displayGetDefault   nscreens <- displayGetNScreens disp   screen <- case screenNumber cfg < nscreens of@@ -153,7 +201,6 @@   windowSetScreen window screen   windowSetDefaultSize window w (barHeight cfg)   windowMove window x y-  widgetModifyBg window StateNormal (Color 0 0 0)   _ <- onRealize window $ setStrutProperties window (0, 0, barHeight cfg, 0,                              0, 0,                              0, 0,
src/System/Taffybar/Systray.hs view
@@ -8,14 +8,12 @@ systrayNew :: IO Widget systrayNew = do   box <- hBoxNew False 5-  widgetModifyBg box StateNormal (Color 0 0 0)    trayManager <- trayManagerNew   Just screen <- screenGetDefault   _ <- trayManagerManageScreen trayManager screen    _ <- on trayManager trayIconAdded $ \w -> do-    widgetModifyBg w StateNormal (Color 0 0 0)     widgetShowAll w     boxPackStart box w PackNatural 0 
src/System/Taffybar/Widgets/Graph.hs view
@@ -94,11 +94,6 @@       fw = fromIntegral w       fh = fromIntegral h -  -- Clear the background to match the bar-  setSourceRGB 0 0 0-  rectangle 0 0 fw fh-  fill-   -- Draw the requested background   setSourceRGB backR backG backB   rectangle fpad fpad (fw - 2 * fpad) (fh - 2 * fpad)
src/System/Taffybar/Widgets/VerticalBar.hs view
@@ -57,10 +57,6 @@ renderFrame cfg width height = do   let fwidth = fromIntegral width       fheight = fromIntegral height-  -- Make a full black background for the whole widget-  setSourceRGB 0 0 0-  rectangle 0 0 fwidth fheight-  fill    -- Now draw the user's requested background, respecting padding   let (bgR, bgG, bgB) = barBackgroundColor cfg@@ -119,8 +115,6 @@                                  , barCanvas = drawArea                                  , barConfig = cfg                                  }--  widgetModifyBg drawArea StateNormal (Color 0 0 0)    widgetSetSizeRequest drawArea (barWidth cfg) (-1)   _ <- on drawArea exposeEvent $ tryEvent $ liftIO (drawBar mv drawArea)
taffybar.cabal view
@@ -1,5 +1,5 @@ name: taffybar-version: 0.1.0+version: 0.1.1 synopsis: A desktop bar similar to xmobar, but with more GUI license: BSD3 license-file: LICENSE@@ -9,6 +9,7 @@ build-type: Simple cabal-version: >=1.10 homepage: http://github.com/travitch/taffybar+data-files: taffybar.rc extra-source-files: README.md,                     taffybar.hs.example @@ -22,7 +23,8 @@   build-depends: base > 3 && < 5, time, old-locale, containers, text, HTTP,                  parsec >= 3.1, mtl >= 2, network, web-encodings, cairo,                  dbus-core >= 0.9.1 && < 1.0, gtk >= 0.12, dyre >= 0.8.6,-                 HStringTemplate, gtk-traymanager, xmonad-contrib, xmonad+                 HStringTemplate, gtk-traymanager, xmonad-contrib, xmonad,+                 xdg-basedir, filepath   hs-source-dirs: src   pkgconfig-depends: gtk+-2.0   exposed-modules: System.Taffybar,@@ -41,7 +43,8 @@                    System.Information.Battery,                    System.Information.Memory,                    System.Information.CPU-  other-modules: System.Taffybar.StrutProperties+  other-modules: System.Taffybar.StrutProperties,+                 Paths_taffybar    c-sources: src/gdk_property_change_wrapper.c @@ -51,7 +54,8 @@  executable taffybar   default-language: Haskell2010-  build-depends: base > 3 && < 5, dyre >= 0.8.6, gtk >= 0.12+  build-depends: base > 3 && < 5, dyre >= 0.8.6, gtk >= 0.12,+                 xdg-basedir, filepath   hs-source-dirs: src   main-is: Main.hs   pkgconfig-depends: gtk+-2.0
+ taffybar.rc view
@@ -0,0 +1,8 @@+style "default" {+  bg[NORMAL] = "#000000"+  fg[NORMAL] = "#FFFFFF"+  text[NORMAL] = "#FFFFFF"+}++class "GtkWidget" style "default"+