Comments (9)
@kwshi This is already supported, through the more advanced bar configuration interface (BarConfigGetter on Context). I don't think that having multiple taffybar processes is a good approach anyway.
Basically the way you use it is by writing a taffybar io action that returns a List of BarConfigs. This interface is admittedly complex and perhaps somewhat difficult to use but it allows a lot of flexibility.
from taffybar.
On further inspection, if this were to be implemented, it would have to be slightly more complicated than simply passing a CLI argument to taffybar
-- the bar executable itself needs to also know where to find its own source to recompile. So one would have to customize the default dyreTaffybar
arguments, something like this:
import qualified Config.Dyre as Dyre
import System.Taffybar
dyreTaffybar :: TaffybarConfig -> IO ()
dyreTaffybarAlt = Dyre.wrapMain $ taffybarDyreParams { Dyre.projectName = "taffybar-alt" }
Another caveat to this is that Dyre seems to be designed with only single instances in mind-- this approach would require the two configurations to be located in different folders as well: one under $XDG_CONFIG_HOME/taffybar/taffybar.hs
, the other at $XDG_CONFIG_HOME/taffybar-alt/taffybar-alt.hs
. This isn't totally a dealbreaker, but it's not very ergonomic and also makes it harder to reuse helper code across the two configurations.
from taffybar.
Why not just use an environment variable to decide which configuration to use?
from taffybar.
Also @purefn 's suggestion would also work for something like what you want.
from taffybar.
However, taffybar hardcodes launching from
$XDG_CONFIG_HOME/taffybar/taffybar.hs
,
This is only true if you aren't use the project approach.
from taffybar.
Aha! I think I've figured out how to do it with the BarConfigGetter
interface. Here's a rough sketch of how I did it:
-- bar unique ID (needed for passing into StrutConfig) -> monitor index -> configuration record
type BarDefinition = Data.Unique.Unique -> GHC.Int.Int32 -> BarConfig
bar1 :: BarDefinition
bar1 barId monitor =
-- see <https://hackage.haskell.org/package/taffybar-3.3.0/docs/System-Taffybar-Context.html#t:BarConfig>
defaultBarConfig
{ -- see <https://hackage.haskell.org/package/taffybar-3.3.0/docs/src/System.Taffybar.SimpleConfig.html#toStrutConfig>
strutConfig = defaultStrutConfig { strutMonitor = Just monitor },
startWidgets = [ {- stuff -} ],
endWidgets = [ {- other stuff -} ],
{- other overrides -}
}
bar2 :: BarDefinition
bar2 = _ {- another definition -}
-- for displaying on all monitors, see <https://hackage.haskell.org/package/taffybar-3.3.0/docs/src/System.Taffybar.SimpleConfig.html#useAllMonitors>
getMonitors :: IO [GHC.Int.Int32]
getMonitors = do
screen <- GI.Gdk.screenGetDefault
monitorCount <-
maybe (pure 0)
(GI.Gdk.screenGetDisplay >=> GI.Gdk.displayGetNMonitors) screen
pure [0 .. monitorCount - 1]
withIds :: BarDefinition -> [GHC.Int.Int32] -> IO [BarConfig
withIds defn = mapM (withId f)
where
withId f monitor = f <$> Data.Unique.newUnique <*> pure monitor
getBars :: IO [BarConfig]
getBars = do
monitors <- getMonitors
top <- withIds topBar monitors
bottom <- withIds bottomBar monitors
pure $ top <> bottom
main :: IO ()
main =
dyreTaffybar $
defaultTaffybarConfig
{ getBarConfigsParam = lift getBars }
By the way, I noticed that the existing SimpleConfig
makes use of MVars to generate multiple bar instances, but I can't tell/understand why that's necessary/how that achieves anything really different from a List.map
(which is why I've defined my example above using only list fmaps). My code above seems to work as expected for me; am I missing out on something/doing something wrong by not doing this with MVars?
Edit: on second thought, maybe it has something to do with hotplug/unplugging monitors, and updating bar instances on-the-fly? I'm not sure.
from taffybar.
on second thought, maybe it has something to do with hotplug/unplugging monitors, and updating bar instances on-the-fly? I'm not sure.
Yes exactly. This was perhaps a misguided attempt to allow you to avoid recreating bars by giving them a unique Id. This bar config getter is really only called on initialization and when the monitor configuration changes. For what you want to do it shouldn't matter too much.
from taffybar.
on second thought, maybe it has something to do with hotplug/unplugging monitors, and updating bar instances on-the-fly? I'm not sure.
Yes exactly. This was perhaps a misguided attempt to allow you to avoid recreating bars by giving them a unique Id. This bar config getter is really only called on initialization and when the monitor configuration changes. For what you want to do it shouldn't matter too much.
from taffybar.
Wonderful, thanks so much! I'll close this now.
from taffybar.
Related Issues (20)
- Chrome MPRIS Icon is not set properly
- Fix up README
- ConfigFile -> MissingH dependency HOT 2
- taffybar-3.3.0 failed to build in Stackage Nightly HOT 9
- Image command buttons HOT 1
- Taffybar fails to build with haskell-gi-0.26 HOT 1
- Handling X11 error with error handler HOT 5
- Window titles missing HOT 1
- Make Crypto Widgets Fail Gracefully when Unable to Connect
- Taffybar crashes when using Discord HOT 9
- Somehow document how to make cabal new-repl work with nix shell HOT 2
- Taffybar barHeight problem HOT 2
- Set a maximum exponential backoff for crypto widgets
- mmap 4096 bytes at (nil): Cannot allocate memory HOT 37
- Windows widget `truncatedGet*Label` functions don't account for character entity encoding HOT 3
- Fully working taffybar with nix flakes example HOT 3
- Avoid calling Refresh on org.freedesktop.UPower.Device HOT 5
- Crypto Widgets aren't working. Possible issue with coin gecko
- mtl 2.3 HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from taffybar.