mabox-colorizer/bin/w2theme

416 lines
12 KiB
Plaintext
Raw Normal View History

#!/bin/bash
#
# colorizer - set of tools for Mabox (auto)theming
# Copyright (C) 2022-2023 Daniel Napora <napcok@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# w2theme - generate themes from wallpaper colors
2023-01-25 21:17:32 +01:00
WALLPALDIR="$HOME/.cache/colorizer/palettes"
mkdir -p "$WALLPALDIR"
read WALLPATH<<< $(grep file "$HOME"/.config/nitrogen/bg-saved.cfg | cut -d'=' -f2)
2023-01-25 21:17:32 +01:00
NAME=${WALLPATH////_}
if [[ "${NAME}" =~ ^_home_.* ]]; then
n=${#HOME}
((n++))
NAME=${NAME:${n}}
fi
if [ ! -f "$WALLPALDIR/$NAME.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/$NAME.clr"
fi
2023-01-25 21:17:32 +01:00
mapfile -t w < "$WALLPALDIR/$NAME.clr"
2022-08-15 01:42:52 +02:00
if [[ "${#w[@]}" -lt 8 ]]; then
w+=("#2e3440" "#4c566a" "#5e81ac" "#bf616b" "#b48ead" "#a3be8c" "#ebcb8b" "#d8dee9" "#eceff4")
fi
2023-07-25 00:21:05 +02:00
accents=("#e93d57" "#c7162b" "#e9633a" "#e95620" "#f4a300" "#e8cc2d" "#3cd425" "#0e8420" "#00d3b7" "#18b0b0" "#3dade9" "#686b6f" "#3584e4" "#916ee4" "#b875dc" "#77216e" "#c748ba" "#e93a9a")
menu_theme () {
2022-12-30 08:38:43 +01:00
jgctl theme MBcolors
case "$1" in
dark) #dark bg
2022-09-19 20:59:26 +02:00
jgctl color_menu_bg "${w[2]}"
2022-08-15 01:42:52 +02:00
jgctl color_menu_bg_to "${w[1]}"
2022-09-19 20:59:26 +02:00
jgctl color_menu_border "${w[3]}"
jgctl color_norm_fg "${w[-2]}"
2022-09-19 20:59:26 +02:00
jgctl color_title_bg "${w[1]}"
jgctl color_title_fg "${w[-3]}"
jgctl color_title_border "${w[0]}"
jgctl color_sel_bg "${w[4]}"
jgctl color_sel_fg "${w[-1]}"
jgctl color_sel_border "${w[3]}"
jgctl color_sep_fg "${w[3]}"
2022-08-15 01:42:52 +02:00
#sleep 1
;;
*) #light bg
jgctl color_menu_bg "${w[-1]}"
2022-08-15 01:42:52 +02:00
jgctl color_menu_bg_to "${w[-2]}"
2022-09-19 20:59:26 +02:00
jgctl color_menu_border "${w[-3]}"
jgctl color_norm_fg "${w[1]}"
jgctl color_title_bg "${w[-3]}"
jgctl color_title_fg "${w[1]}"
jgctl color_title_border "${w[-4]}"
jgctl color_sel_bg "${w[-5]}"
jgctl color_sel_fg "${w[0]}"
jgctl color_sel_border "${w[-4]}"
jgctl color_sep_fg "${w[-5]}"
2022-08-15 01:42:52 +02:00
#sleep 1
;;
esac
2022-12-23 11:10:27 +01:00
case "$2" in
show)
colorizer-menus -s
;;
*):;;
esac
}
conky_colors() {
2022-09-19 20:59:26 +02:00
source ~/.config/colorizer/colorizer.conf
case "$1" in
dark) #dark bg
conkyctl win_bgcolor_all "${w[0]}"
conkyctl default_color_all "${w[-1]}"
conkyctl color0_all "${w[-3]}"
conkyctl color1_all "${w[-4]}"
2023-07-25 00:21:05 +02:00
#conkyctl color2_all "${w[-5]}"
;;
*) #light bg
conkyctl win_bgcolor_all "${w[-1]}"
conkyctl default_color_all "${w[0]}"
conkyctl color0_all "${w[2]}"
2022-08-15 01:42:52 +02:00
conkyctl color1_all "${w[4]}"
2023-07-25 00:21:05 +02:00
#conkyctl color2_all "${w[6]}"
;;
esac
2023-07-25 00:21:05 +02:00
#bars/graphs color
#random
conkyctl color2_all "${accents[ $RANDOM % ${#accents[@]} ]}"
}
2022-10-27 01:10:17 +02:00
conky_colorsone () {
source ~/.config/colorizer/colorizer.conf
case "$1" in
dark) #dark bg
conkyctl win_bgcolor "${w[0]}" "${2}"
conkyctl default_color "${w[-1]}" "${2}"
conkyctl color0 "${w[-3]}" "${2}"
conkyctl color1 "${w[-4]}" "${2}"
conkyctl color2 "${w[-5]}" "${2}"
;;
*) #light bg
conkyctl win_bgcolor "${w[-1]}" "${2}"
conkyctl default_color "${w[0]}" "${2}"
conkyctl color0 "${w[2]}" "${2}"
conkyctl color1 "${w[4]}" "${2}"
conkyctl color2 "${w[6]}" "${2}"
;;
esac
}
pyradio_theme() {
case "$1" in
dark) #dark bg
prtctl stations "${w[-3]}" "${w[0]}"
prtctl active_station "${w[-1]}"
prtctl status_bar "${w[0]}" "${w[-3]}"
prtctl normal_cursor "${w[1]}" "${w[-4]}"
prtctl active_cursor "${w[2]}" "${w[-3]}"
prtctl edit_cursor "${w[2]}" "${w[-3]}"
prtctl extra_func "${w[6]}"
prtctl pyradio_url "${w[2]}"
prtctl messages_border "${w[2]}"
;;
*) # light bg
prtctl stations "${w[4]}" "${w[-1]}"
prtctl active_station "${w[0]}"
prtctl status_bar "${w[0]}" "${w[-3]}"
prtctl normal_cursor "${w[4]}" "${w[-3]}"
prtctl active_cursor "${w[2]}" "${w[-3]}"
prtctl edit_cursor "${w[2]}" "${w[-3]}"
prtctl extra_func "${w[6]}"
prtctl pyradio_url "${w[2]}"
prtctl messages_border "${w[4]}"
;;
esac
}
2023-05-09 14:14:23 +02:00
cava () {
case "$1" in
light) #light bottom
cavactl gradientcolors "${w[-3]}" "${w[3]}"
cavactl foregroundcolor "${w[-3]}"
cavactl reload_colors
;;
*) #dark bottom
cavactl gradientcolors "${w[3]}" "${w[-3]}"
cavactl foregroundcolor "${w[3]}"
cavactl reload_colors
;;
esac
}
2022-08-15 01:42:52 +02:00
accent () {
2022-12-08 17:48:55 +01:00
#obtctl clractivebg ${1}
#colorTo=$(pastel darken 0.2 "${1}"|pastel format hex)
#obtctl clractivebgto ${colorTo}
2022-08-15 01:42:52 +02:00
# JGMENU based menus, sidepanels and tools
2022-09-19 20:59:26 +02:00
#jgctl color_title_bg ${1}
2022-08-15 01:42:52 +02:00
#TITLE_FG=$(pastel textcolor ${colorTo}|pastel format hex)
2022-09-19 20:59:26 +02:00
#TITLE_FG=$(pastel textcolor ${1}|pastel format hex)
2022-08-20 20:51:56 +02:00
#notify-send.sh "title_fg $TITLE_FG" "${w[1]} ${w[-1]}"
2022-09-19 20:59:26 +02:00
#if [[ "${TITLE_FG}" == *"ffffff"* ]];then
#FG=${w[-2]}
#BBG=${w[1]}
#else
#FG=${w[2]}
#BBG=${w[1]}
#fi
2022-08-15 01:42:52 +02:00
SEL_FG=$(pastel textcolor ${1}|pastel format hex)
2022-09-19 20:59:26 +02:00
#jgctl color_title_fg ${FG}
2022-08-20 20:51:56 +02:00
#jgctl color_title_border ${BBG}
2022-08-15 01:42:52 +02:00
jgctl color_sel_bg ${1}
2022-09-19 20:59:26 +02:00
jgctl color_sel_bg 100
2022-08-15 01:42:52 +02:00
jgctl color_sel_fg ${SEL_FG}
}
2022-09-19 20:59:26 +02:00
gradient () {
source ~/.config/colorizer/colorizer.conf
#notify-send.sh "zmiennne" "${1} ${2}"
if [ "$gradient_obtheme" = "yes" ]; then
obtctl activegradient "${1}" "${2}"
fi
if [ "$gradient_menu" = "yes" ]; then
jgctl gradient "${1}" "${2}"
fi
if [ "$gradient_conkies" = "yes" ]; then
conkygradient "${1}" "${2}"
fi
}
conkygradient () {
CONKYDIR="$HOME"/.config/conky
for i in "$CONKYDIR"/*_mbcolor*; do
if [[ "$i" = *"sysinfo_graph"* ]];then
conkyctl win_bgcolor ${1} ${i}
FG_COLOR=$(pastel textcolor ${1}|pastel format hex)
if [[ "${FG_COLOR}" == *"ffffff"* ]]; then
conkyctl default_color ${w[-1]} ${i}
conkyctl color0 ${w[-2]} ${i}
conkyctl color1 ${w[-3]} ${i}
else
conkyctl default_color ${w[0]} ${i}
conkyctl color0 ${w[1]} ${i}
conkyctl color1 ${w[2]} ${i}
fi
conkyctl color2 ${2} ${i}
elif [[ "$i" = *"sysinfo_mb"* ]];then
conkyctl win_bgcolor ${2} ${i}
FG_COLOR=$(pastel textcolor ${2}|pastel format hex)
if [[ "${FG_COLOR}" == *"ffffff"* ]]; then
conkyctl default_color ${w[-1]} ${i}
conkyctl color0 ${w[-2]} ${i}
conkyctl color1 ${w[-3]} ${i}
else
conkyctl default_color ${w[0]} ${i}
conkyctl color0 ${w[1]} ${i}
conkyctl color1 ${w[2]} ${i}
fi
conkyctl color2 ${1} ${i}
elif [[ "$i" == *"logo"* ]];then
:
else
ran="$((RANDOM % 8))"
rand=$((ran + 1))
BG=$(pastel mix -f 0.${rand} ${1} ${2}|pastel format hex)
conkyctl win_bgcolor ${BG} ${i}
FG_COLOR=$(pastel textcolor ${BG}|pastel format hex)
if [[ "${FG_COLOR}" == *"ffffff"* ]]; then
conkyctl default_color ${w[-1]} ${i}
conkyctl color0 ${w[-2]} ${i}
conkyctl color1 ${w[-3]} ${i}
else
conkyctl default_color ${w[0]} ${i}
conkyctl color0 ${w[1]} ${i}
conkyctl color1 ${w[2]} ${i}
fi
fi
done
}
2022-12-23 11:10:27 +01:00
obtheme () {
case "$1" in
dark)
obtctl clractivebg ${w[2]}
TITLE_FG=$(pastel textcolor ${w[2]}|pastel format hex)
if [[ "$TITLE_FG" == *"ffffff"* ]];then
obtctl activetextcolor "#E5E5E5"
#obtctl activetextcolor ${w[-1]}
#obtctl activebuttonscolors ${w[-1]}
2022-12-23 11:10:27 +01:00
else
obtctl activetextcolor "#222222"
#obtctl activetextcolor ${w[0]}
#obtctl activebuttonscolors ${w[0]}
2022-12-23 11:10:27 +01:00
fi
obtctl clractivebgto ${w[4]}
obtctl clrnormalbg ${w[0]}
obtctl clrnormalbgto "$(pastel darken 0.1 "${w[0]}"|pastel format hex)"
;;
light)
obtctl clractivebg ${w[-2]}
TITLE_FG=$(pastel textcolor ${w[-2]}|pastel format hex)
if [[ "$TITLE_FG" == *"ffffff"* ]];then
obtctl activetextcolor "#E5E5E5"
#obtctl activetextcolor ${w[-1]}
#obtctl activebuttonscolors ${w[-1]}
2022-12-23 11:10:27 +01:00
else
obtctl activetextcolor "#222222"
#obtctl activetextcolor ${w[0]}
#obtctl activebuttonscolors ${w[0]}
2022-12-23 11:10:27 +01:00
fi
obtctl clractivebgto ${w[-4]}
obtctl clrnormalbg ${w[1]}
obtctl clrnormalbgto "$(pastel darken 0.1 "${w[1]}"|pastel format hex)"
;;
esac
}
2022-08-15 01:42:52 +02:00
colorize () {
source ~/.config/colorizer/colorizer.conf
# CONKY
case "$wall2themes_conky" in
dark) conky_colors dark;;
2022-08-16 16:50:11 +02:00
light) conky_colors light;;
2022-08-15 01:42:52 +02:00
*) : ;;
esac
2022-08-20 20:51:56 +02:00
# ACCENT_COLOR
case "$wall2themes_accent" in
dark)
obtctl theme MBcolors
accent ${w[1]}
;;
light)
obtctl theme MBcolors
accent ${w[-1]}
;;
*) : ;;
esac
2022-08-15 01:42:52 +02:00
# MENUS
case "$wall2themes_menu" in
dark) menu_theme dark;;
light) menu_theme light;;
*) : ;;
esac
2022-12-08 17:48:55 +01:00
# Openbox (TUTAJ WARUNEK)
2022-12-23 13:48:01 +01:00
case "$wall2themes_ob" in
dark) obtheme dark;;
light) obtheme light;;
*) : ;;
esac
2022-08-20 20:51:56 +02:00
# PYRADIO THEME
case "$wall2themes_pyradio" in
dark) pyradio_theme dark;;
light) pyradio_theme light;;
*) : ;;
esac
}
reverse () {
source ~/.config/colorizer/colorizer.conf
# CONKY
case "$wall2themes_conky" in
2022-09-19 20:59:26 +02:00
dark) conky_colors light
;;
light) conky_colors dark
;;
2022-08-20 20:51:56 +02:00
*) : ;;
esac
2022-08-15 01:42:52 +02:00
# ACCENT_COLOR
case "$wall2themes_accent" in
dark)
obtctl theme MBcolors
2022-08-20 20:51:56 +02:00
accent ${w[-1]}
2022-08-15 01:42:52 +02:00
;;
light)
obtctl theme MBcolors
2022-08-20 20:51:56 +02:00
accent ${w[1]}
2022-08-15 01:42:52 +02:00
;;
*) : ;;
esac
2022-08-20 20:51:56 +02:00
# MENUS
case "$wall2themes_menu" in
dark) menu_theme light;;
light) menu_theme dark;;
*) : ;;
esac
2022-12-08 17:48:55 +01:00
# Openbox (TUTAJ WARUNEK)
2022-12-23 13:48:01 +01:00
case "$wall2themes_ob" in
dark) obtheme light;;
light) obtheme dark;;
*) : ;;
esac
2022-08-15 01:42:52 +02:00
# PYRADIO THEME
case "$wall2themes_pyradio" in
2022-08-20 20:51:56 +02:00
dark) pyradio_theme light;;
light) pyradio_theme dark;;
2022-08-15 01:42:52 +02:00
*) : ;;
esac
}
genthumb () {
#$1 - filename with full path
NAME=${1////_}
if [[ "${NAME}" =~ ^_home_.* ]]; then
n=${#HOME}
((n++))
NAME=${NAME:${n}}
fi
# GENERATE THUMBNAIL
THUMBDIR="$HOME/.cache/colorizer/thumbs"
mkdir -p ${THUMBDIR}
THUMB="${THUMBDIR}/${NAME}.png"
if [[ ! -f "$THUMB" ]]; then
convert ${1} -resize 270x150^ -gravity center -extent 270x150 ${THUMB}
fi
}
2022-08-15 01:42:52 +02:00
pin () {
#get wallpaper path and filename without ext
# mkdir for colorscheme
mkdir -p ~/.config/colorizer/pinned/$WALLNAME
# if dir exist then action is update so remove old content
rm -rf ~/.config/colorizer/pinned/$WALLNAME
# get menu themename jgmenu_theme= ( it is always MBcolors ????)
. ~/.config/mabox/mabox.conf
}
case "$1" in
ob) obtheme "$2";;
2022-12-23 11:10:27 +01:00
menu) menu_theme "$2" "$3";;
conky) conky_colors "$2";;
2022-10-27 01:10:17 +02:00
conkyone) conky_colorsone "$2" "$3";;
pyradio) pyradio_theme "$2";;
2023-05-09 14:14:23 +02:00
cava) cava "$2";;
2022-08-15 01:42:52 +02:00
accent) accent "$2";;
2022-09-19 20:59:26 +02:00
gradient) gradient "$2" "$3";;
2022-08-15 01:42:52 +02:00
colorize) colorize;;
2022-08-20 20:51:56 +02:00
reverse) reverse;;
genthumb)genthumb "$2";;
2022-08-15 01:42:52 +02:00
pin) pin;;
*) ;;
esac