deviantfero / wpgtk

:flower_playing_cards: a colorscheme, wallpaper and template manager for *nix
http://deviantfero.github.io/wpgtk/
GNU General Public License v2.0
2.04k stars 49 forks source link

Can't get template for rofi .rasi to work #137

Closed goteksc closed 5 years ago

goteksc commented 5 years ago

I'm trying to create a template for a global.rasi file that holds the color values that I'll then import into other rofi themes. But wpgtk won't apply the colors in any .rasi template I try.

Though the template for the old rofi config format that comes with wpgtk, in addition to dunst and i3wm works for me.

globals.rasi

* {
  tp-color00: #000114cc;
  color00:    #010114;
  color01:    #d3487c;
  color02:    #72397e;
  color03:    #9a3b7a;
  color04:    #473888;
  color05:    #eb5584;
  color06:    #5a3c8e;
  color07:    #b0a6b5;
  color08:    #030344;
  color09:    #ef4599;
  color10:    #993cac;
  color11:    #d33c9f;
  color12:    #543cb7;
  color13:    #ed569c;
  color14:    #6e3ec1;
  color15:    #e6dfe7;

  font01: "DejaVuSansMono Nerd Font Mono 11";
}

globals.rasi.base

* {{
  tp-color00: #{color0.strip}{rofi-tp};
  color00:    {color0};
  color01:    {color1};
  color02:    {color2};
  color03:    {color3};
  color04:    {color4};
  color05:    {color5};
  color06:    {color6};
  color07:    {color7};
  color08:    {color8};
  color09:    {color9};
  color10:    {color10};
  color11:    {color11};
  color12:    {color12};
  color13:    {color13};
  color14:    {color14};
  color15:    {color15};

  font01: "{font-mono} {rofi-font-size}";
}}
goteksc commented 5 years ago

I solved this with the following script:

#!/bin/bash
# colors.css file found in either ~/.config/wpg/formats/ for wpgtk users
# or ~/.cache/wal/ for pywal users
colors_src="$HOME/.config/wpg/formats/colors.css"
rasi_file="$HOME/.config/rofi/globals.rasi"
resources="tp-color0 color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 color10 color11 color12 color13 color14 color15"

for r in $resources; do
    if [[ "$r" == "tp-color0" ]]; then
      color_tp=$(xrdb -query | awk -v reso=$r '/Rofi\*transparency/{print $2}')
      color_var="$(awk '/--color0/{print $2}' $colors_src | tr -d '[=;=]')$color_tp;"
      sed -i --follow-symlinks "/$r:/c\\$r: $color_var" "$rasi_file"
    elif [[ "$r" != "tp-color0" ]]; then
      color_var=$(awk -v reso=$r '$1~reso{print $2}' $colors_src)
      sed -i --follow-symlinks "/^$r:/c\\$r: $color_var" "$rasi_file"
    fi
done
# regex in awk is to account for font names with spaces e.g: match the second column and any after
fnt=$(xrdb -query | awk '/Rofi\*font1/{ s = ""; for (i = 2; i <= NF; i++) s = s $i " "; print s }')
fntsz=$(xrdb -query | awk '/Rofi\*fontsz1/{print $2}')
sed -i --follow-symlinks "/font01:/c\font01: \"$fnt$fntsz\"\;" "$rasi_file"

Relevant lines from .Xresources

Rofi*font1: DejaVuSansMono Nerd Font Mono
Rofi*fontsz1: 12
! Transparency chart for dummies like me.
! 100% 95% 90% 85% 80% 75% 70% 65% 60% 55% 50% 45% 40% 35% 30% 25% 20% 15% 5% 10% 0%
! FF   F2  E6  D9  CC  BF  B3  A6  99  8C  80  73  66  59  4D  40  33  26  1A 0D  00
Rofi*transparency: D9

Writing to a globals.rasi file:

* {
tp-color0: #1f1b20D9;
color0: #1f1b20;
color1: #bf4b32;
color2: #5696A7;
color3: #33A4D8;
color4: #2985B3;
color5: #60B5D5;
color6: #5DC7E8;
color7: #c8e1e8;
color8: #39313b;
color9: #ff5731;
color10: #5fcce9;
color11: #30dbff;
color12: #26b1f7;
color13: #68f4ff;
color14: #63ffff;
color15: #ecffff;
font01: "DejaVuSansMono Nerd Font Mono 12";
}

Which is then imported in the first line of the actual theme I use: @import "globals.rasi"