geommer / yabar

A modern and lightweight status bar for X window managers.
MIT License
681 stars 49 forks source link

Use colors from Xresources #173

Open lrargerich opened 6 years ago

lrargerich commented 6 years ago

Hi,

Simple question: Is there a way to take the colors from Xresources? This would make theming yabar an easy task.

Thanks!

vinnyA3 commented 6 years ago

Currently, I don't believe there is a native way to interact with Xresources. As a workaround, you can always write a script that replaces some fields in your yabar config with colors from Xresources. I'm doing something similiar with dynamic pywal colors.

lrargerich commented 6 years ago

If you can share what you are doing it will probably help me.

vinnyA3 commented 6 years ago

Sure thing. Here is a piece of my script:

#!/bin/bash

ya=/usr/bin/yabar
ya_conf_dir=$HOME/.dotfiles/config/yabar

# If we don't have a yabar config file in tmp, create both
# yabar.confg and yabar-sp.config
if [ ! -f /tmp/yabar.conf ];
then
    # source pywal color scheme
    source $HOME/.cache/wal/colors.sh

    colors=( $(echo $background $color12 | sed -e 's/#//g') )

    # create tmp ya config
    cp $ya_conf_dir/yabar.conf /tmp/yabar.conf

    # create tmp ya-sp config
    awk '/ya_workspace:/ && c == 0 {
        c = 1;
        system("cat ~/.dotfiles/config/yabar/ya_song_block");
    }; {print} ' $ya_conf_dir/yabar.conf > /tmp/yabar-sp.conf

    # insert 'ya_song' into loaded blocks (yabar-sp.conf)
    sed -ie "/\"ya_workspace\"/a \"ya_song\"," /tmp/yabar-sp.conf

    # replace all occurrences of primary/secondary color keys
    # with sourced pywal colors
    sed -ie "s/PRICOLOR/${colors[0]}/g;s/SECCOLOR/${colors[1]}/g" /tmp/yabar* 
fi

In my script, I'm creating a yabar-sp file because I'm utilizing yabar's internal song block. I noticed that if the media player (in my case spotify) isn't running, then the internal block eats at the cpu since it's trying to display song information. Hope this helps. You can check out the rest of the script(s) in my dotfiles repo.

lrargerich commented 6 years ago

Thanks! I ended up using your ideas and creating a script that automatically changes the wallpaper, runs pywal and re-starts yabar with the new colors. I also created a small icon in yabar to execute this so I can just click in the little icon and change the whole theme, yabar, i3, wallpaper, terms, etc...

Curious question why did you choose color 12 from pywal as your foreground? If that is the foreground...

vinnyA3 commented 6 years ago

Glad it helped! That's a really good idea. I'm going to do the same thing.

Curious question why did you choose color 12 from pywal as your foreground? If that is the foreground...

I'm not sure haha 😄 . I think I was testing something at time time and never changed it back to $foreground. I guess it makes no difference here ( except for making sense of it ).

lausek commented 6 years ago

@lrargerich @vinnyA3 Sorry, if I misunderstand the topic here but isn't XrmGetFileDatabase what we are looking for?