mabox-colorizer/bin/colorizer

258 lines
9.2 KiB
Bash
Executable File

#!/bin/bash
CNF_DIR="$HOME/.config/colorizer"
mkdir -p "$CNF_DIR"
CNF_FILE="$CNF_DIR/colorizer.conf"
if [ ! -f $CNF_FILE ]; then
cat <<EOF > ${CNF_FILE}
# Autogenerate color themes on wallpaper change? yes or no
wall2themes=yes
# conky preffered bg color dark, light or none (none = not generate/change colorscheme)
wall2themes_conky=dark
# Menu prefferred bg color dark, light or none (not generate/change colorscheme)
wall2themes_menu=light
# Accent color dark, light or none
wall2themes_accent=dark
# PyRadio preferred bg color dark, light or none (not generate/change colorscheme)
wall2themes_pyradio=dark
# User wallpaper dir
user_wallpapers_dir=~/wallpapers
EOF
# Copy new nitrogen wrapper
cp -a /usr/share/mabox/common/wrappers/nitrogen ~/.local/bin/
fi
source "$CNF_FILE"
WALLPALDIR="$HOME/.config/colormenu/palettes/wallp"
mkdir -p "$WALLPALDIR"
read WALLPATH<<< $(grep file "$HOME"/.config/nitrogen/bg-saved.cfg | cut -d'=' -f2)
WALLPAPER=${WALLPATH##*/}
if [ ! -f "$WALLPALDIR/$WALLPAPER.clr" ]; then
convert ${WALLPATH} -resize 25% -colors 16 -unique-colors txt:- |grep -v '^#'| awk '{print substr($3,1,7)}' |pastel sort-by brightness |pastel format hex > "$WALLPALDIR/$WALLPAPER.clr"
fi
mapfile -t w < "$WALLPALDIR/$WALLPAPER.clr"
if [[ "${#w[@]}" -lt 8 ]]; then
w+=("#2e3440" "#4c566a" "#5e81ac" "#bf616b" "#b48ead" "#a3be8c" "#ebcb8b" "#d8dee9" "#eceff4")
fi
#Accent colors
plasma=("#e93a9a" "#e93d58" "#e9643a" "#e8cb2d" "#3dd425" "#00d3b8" "#3daee9" "#b875dc" "#926ee4" "#686b6f")
ubuntu=("#E95420" "#18b0b0" "#3584e4" "#0e8420" "#c748ba" "#77216f" "#c7162b" "#f4a100")
mint+=("#6cabcd" "#5b73c4" "#aa876a" "#9d9d9d" "#db9d61" "#c76199" "#8c6ec9" "#c15b58" "#c8ac69" "#5aaa9a")
case "$LANG" in
pl*)
OBTHEME="Motyw Openbox"
MENUPANELS="Menu i Panele"
TERMINALTHEME="Motyw terminala"
WALLCOLORS="Kolory z tapety"
ACCENTINFO="<i>ustaw kolor akcentu</i>"
ACCENT_COLORS="Popularne kolory akcentu"
EDIT_PALETTE="Edytuj paletę kolorów"
RANDWALL="Ustaw losową tapetę"
RANDOM_SYSWALLPAPER="Tapeta systemowa"
RANDOM_USERWALLPAPER="Tapeta użytkownika"
SETTINGS_AND_HELP="Pomoc i Ustawienia"
SETTINGS="Ustawienia"
COLORIZER_SETTINGS="Ustawienia Colorizera"
AUTOGEN_THEMES="Autogenerowanie motywów?"
EDITCONF="Edytuj plik konfiguracyjny"
RESET="Resetuj ustawienia"
YES="Tak"
NO="Nie"
LIGHTBG="<b>light</b> - jasne tło"
DARKBG="<b>dark</b> - ciemne tło"
OTHERTOOLS="Inne narzędzia"
WALLPAPERS="Tapety"
HELP="Pomoc"
;;
*)
OBTHEME="Openbox Theme"
MENUPANELS="Menus/Panels"
TERMINALTHEME="Terminal color scheme"
WALLCOLORS="Wallpaper Colors"
ACCENTINFO="<i>click to set accent color</i>"
ACCENT_COLORS="Popular accent colors"
EDIT_PALETTE="Edit color palette"
RANDWALL="Set random wallpaper"
RANDOM_SYSWALLPAPER="System Wallpaper"
RANDOM_USERWALLPAPER="User Wallpaper"
SETTINGS_AND_HELP="Settings and Help"
SETTINGS="Settings"
COLORIZER_SETTINGS="Colorizer Settings"
AUTOGEN_THEMES="Autogenerate themes?"
EDITCONF="Edit config file"
RESET="Reset to defaults"
YES="Yes"
NO="No"
LIGHTBG="with <b>light</b> background"
DARKBG="with <b>dark</b> background"
OTHERTOOLS="Other tools"
WALLPAPERS="Wallpaper"
HELP="About and Help"
;;
esac
out+=("^sep(Mabox Colorizer)")
out+=("$OBTHEME,^pipe(colorizer-ob)")
out+=("$MENUPANELS,^pipe(colorizer-menus)")
#out+=("TINT2,^pipe(colorizer-tint2)")
out+=("Conky,^pipe(colorizer-conky)")
#out+=("Systray HW monitor,^pipe(colorizer-phwmon)")
out+=("$TERMINALTHEME,^term(theme.sh -i2;/bin/bash)")
out+=("^sep()")
out+=("PyRadio,^pipe(colorizer-pyradio)")
#out+=("GTKTHEME,^pipe(colorizer-gtktheme)")
out+=("^sep($WALLCOLORS)")
out+=("^sep($ACCENTINFO)")
for i in "${w[@]}"
do
out+=("<tt><small>$i</small> <span bgcolor='$i'> </span></tt>,w2theme accent '${i}';colorizer -s")
done
out+=("^sep()")
out+=("$ACCENT_COLORS,^checkout(acccolors)")
out2+=("^tag(acccolors)")
out2+=("^sep(Ubuntu)")
for i in ${ubuntu[@]};do out2+=("<tt><small>$i</small> <span bgcolor='$i'> </span></tt>,w2theme accent '${i}';colorizer -s");done
out2+=("^sep(Mint)")
for i in ${mint[@]};do out2+=("<tt><small>$i</small> <span bgcolor='$i'> </span></tt>,w2theme accent '${i}';colorizer -s");done
out2+=("^sep(Plasma)")
for i in ${plasma[@]};do out2+=("<tt><small>$i</small> <span bgcolor='$i'> </span></tt>,w2theme accent '${i}';colorizer -s");done
out+=("$EDIT_PALETTE,geany $WALLPALDIR/$WALLPAPER.clr")
out+=("^sep($RANDWALL)")
out+=("$RANDOM_SYSWALLPAPER,nitrogen --random /usr/share/backgrounds --set-scaled --save;colorizer -s")
[ -d "${user_wallpapers_dir}" ] && out+=("$RANDOM_USERWALLPAPER,nitrogen --random ${user_wallpapers_dir} --set-scaled --save;colorizer -s")
### FUTURE: SAVE AND RESTORE
#out+=("^sep()")
#out+=("Pin current colors to wallpaper")
###
out+=("^sep($SETTINGS_AND_HELP)")
out+=("$SETTINGS,^checkout(settings)")
out2+=("^tag(settings)")
out2+=("^sep($COLORIZER_SETTINGS)")
out2+=("$AUTOGEN_THEMES [ <b>${wall2themes}</b> ],^checkout(autogen)")
out3+=("^tag(autogen")
out3+=("^sep(GENERATE THEMES ON WALLPAPER CHANGE?)")
out3+=("$YES,mb-setvar wall2themes=yes $CNF_FILE;colorizer -s")
out3+=("$NO,mb-setvar wall2themes=no $CNF_FILE;colorizer -s")
out2+=("^sep()")
out2+=("$MENUPANELS [ <b>${wall2themes_menu}</b> ],^checkout(mp)")
out3+=("^tag(mp)")
out3+=("^sep(Generate menu/panels theme?)")
out3+=("$NO,mb-setvar wall2themes_menu=none $CNF_FILE;colorizer -s")
out3+=("^sep()")
out3+=("$LIGHTBG,mb-setvar wall2themes_menu=light $CNF_FILE;colorizer -s")
out3+=("$DARKBG,mb-setvar wall2themes_menu=dark $CNF_FILE;colorizer -s")
out2+=("Conky [ <b>${wall2themes_conky}</b> ],^checkout(conky)")
out3+=("^tag(conky)")
out3+=("^sep(Generate Conky theme?)")
out3+=("$NO,mb-setvar wall2themes_conky=none $CNF_FILE;colorizer -s")
out3+=("^sep()")
out3+=("$LIGHTBG,mb-setvar wall2themes_conky=light $CNF_FILE;colorizer -s")
out3+=("$DARKBG,mb-setvar wall2themes_conky=dark $CNF_FILE;colorizer -s")
out2+=("PyRadio [ <b>${wall2themes_pyradio}</b> ],^checkout(pyradio)")
out3+=("^tag(pyradio)")
out3+=("^sep(Generate PyRadio theme?)")
out3+=("$NO,mb-setvar wall2themes_pyradio=none $CNF_FILE;colorizer -s")
out3+=("^sep()")
out3+=("$LIGHTBG,mb-setvar wall2themes_pyradio=light $CNF_FILE;colorizer -s")
out3+=("$DARKBG,mb-setvar wall2themes_pyradio=dark $CNF_FILE;colorizer -s")
out2+=("^sep()")
out2+=("$EDITCONF,xdg-open $CNF_FILE")
out2+=("$RESET,rm $CNF_FILE;colorizer -s")
LNG=${LANG:0:2}
if [[ -f "/usr/share/mabox-colorizer/help/$LNG.html" ]];then
out+=("$HELP,yhtml /usr/share/mabox-colorizer/help/$LNG.html 'Mabox Help - Colorizer'")
else
out+=("$HELP,yhtml /usr/share/mabox-colorizer/help/en.html 'Mabox Help - Colorizer'")
fi
out+=("^sep($OTHERTOOLS)")
out+=("Tint2 Menu,^pipe(jgtint2-pipe)")
#out+=("$WALLPAPERS,^pipe(jgwallpaperchanger)")
out+=("Color Menu,colormenu")
#out+=("PREFERENCES")
### RUN
if [[ "$1" == "-s" ]]; then
. /usr/share/mb-jgtools/pipemenu-standalone.cfg
. $HOME/.config/mabox/mabox.conf
#out+=("^sep()")
#out+=(" ⮜ $LEFTPANEL,mb-jgtools places")
if [[ $panels_heightpos == "top" ]]; then
MENU_VALIGN="top"
MENU_MARGIN_Y=${panels_topmargin:-0}
elif [[ $panels_heightpos == "bottom" ]]; then
MENU_VALIGN="bottom"
MENU_MARGIN_Y=${panels_topmargin:-0}
else
MENU_VALIGN="center"
fi
MENU_PADDING_TOP=${jgtools_padding:-0}
MENU_HALIGN="left"
jgmenu_icon_size=0
menu_margin_x=${submenu_spacing:-0}
[ $(pidof picom) ] && MENU_RADIUS=$jgtools_radius
[ -z $jgmenu_use_borders ] && menu_border=0
JGWIDTH=$((jgtools_padding + 278 + jgtools_padding))
MENU_PADDING_TOP=$((jgtools_padding + 158))
#TEMP POSITION:
MENU_VALIGN="top"
MENU_MARGIN_Y="60"
THUMBDIR="$HOME/.config/mabox/wallthumbs"
mkdir -p ${THUMBDIR}
THUMB="${THUMBDIR}/${WALLPAPER}.png"
if [[ ! -f "$THUMB" ]]
then
convert ${WALLPATH} -resize 270x150^ -gravity center -extent 270x150 ${THUMB}
fi
# colors
n=0
m=0
X=$((jgtools_padding + 12))
Y=$((jgtools_padding + 104))
for i in "${w[@]}"
do
if [[ "$n" -lt "10" ]];then
dots+=("@rect,,$((X + 25*n)),$((Y)),22,22,1,left,top,#FFFFFF 60,${i} 100,")
else
dots+=("@rect,,$((X + 25*m)),$((Y+24)),22,22,1,left,top,#FFFFFF 80,${i} 100,")
((m=m+1))
fi
((n=n+1))
done
mkconfigfile
#THUMB="$(DISPLAY=:0 scrot -t 220x100 -o $HOME/.config/mabox/colorizer.png -e 'echo $m')"
cat <<EOF > ${MENU_ITEMS}
@icon,,$((jgtools_padding + 4)),$((jgtools_padding + 4)),270,150,4,left,top,,,${THUMB}
@rect,,$((jgtools_padding + 4)),$((jgtools_padding + 100)),270,54,0,left,top,#222222 20,#222222 70,
@text,,$((jgtools_padding + 168)),$((jgtools_padding + 124)),120,30,0,left,top,#FFFFFF ,${WINCLR}, <b>Colorizer</b>
$(printf '%s\n' "${dots[@]}")
#@icon,,$((jgtools_padding + 4)),$((jgtools_padding + 34)),270,120,4,left,top,,,/usr/share/mabox-colorizer/img/colorizer.png
$(printf '%s\n' "${out[@]}")
$(printf '%s\n' "${out2[@]}")
$(printf '%s\n' "${out3[@]}")
EOF
jgmenu --config-file=${CONFIG_FILE} --csv-file=${MENU_ITEMS} 2>/dev/null
exit 0
fi
printf '%s\n' "${out[@]}"
printf '%s\n' "${out2[@]}"
printf '%s\n' "${out3[@]}"