mabox-colorizer/bin/jgctl

309 lines
9.1 KiB
Plaintext
Raw Normal View History

2022-05-15 03:25:01 +02:00
#!/bin/bash
# jgctl - menu config actions
# jgctl variable value config_file
. $HOME/.config/mabox/mabox.conf
case "$jgmenu_theme" in
obtheme)
OBTHEME=$(awk '/<theme>/ {while (getline n) {if (match(n, /<name>/))
{l=n; exit}}} END {split(l, a, "[<>]"); print a[3]}' "$HOME/.config/openbox/rc.xml");
THEMERC="$HOME/.config/mabox/jgobthemes/${OBTHEME}.colorrc";;
*)
THEMERC="$HOME/.config/mabox/jgobthemes/${jgmenu_theme}.colorrc";;
esac
2022-08-15 01:42:52 +02:00
# Backup original theme file
if [ ! -f "${THEMERC}.bak" ]; then
cp ${THEMERC} ${THEMERC}.bak
fi
2022-12-19 22:22:23 +01:00
theme () {
mb-setvar jgmenu_theme=${1}
}
2022-05-15 03:25:01 +02:00
reset () {
rm ${THEMERC}
mv ${THEMERC}.bak ${THEMERC}
}
2022-12-19 22:22:23 +01:00
resetMBcolors() {
mb-setvar jgmenu_theme=MBcolors
reset
case "$1" in
2022-12-20 09:46:47 +01:00
show)
colorizer-menus -s
;;
2022-12-19 22:22:23 +01:00
*):;;
esac
}
2022-05-15 03:25:01 +02:00
color_menu_bg () {
read MBG MBGA<<< "$(grep 'color_menu_bg ' ${THEMERC} | cut -d'=' -f2)"
case "${#1}" in
7) #color
sd "color_menu_bg .*$" "color_menu_bg = $1 $MBGA" ${THEMERC}
;;
*)
sd "color_menu_bg .*$" "color_menu_bg = $MBG $1" ${THEMERC}
;;
esac
}
color_menu_bg_to () {
read MBGT MBGTA<<< "$(grep 'color_menu_bg_to ' ${THEMERC} | cut -d'=' -f2)"
case "${#1}" in
7) #color
sd "color_menu_bg_to.*$" "color_menu_bg_to = $1 $MBGTA" ${THEMERC}
;;
*)
sd "color_menu_bg_to.*$" "color_menu_bg_to = $MBGT $1" ${THEMERC}
;;
esac
}
color_menu_border () {
read MBORDER MBORDERA<<< "$(grep 'color_menu_border' ${THEMERC} | cut -d'=' -f2)"
case "${#1}" in
7) #color
sd "color_menu_border.*$" "color_menu_border = $1 $MBORDERA" ${THEMERC}
;;
*)
sd "color_menu_border.*$" "color_menu_border = $MBORDER $1" ${THEMERC}
;;
esac
}
menu_gradient_pos () {
sd "menu_gradient_pos.*$" "menu_gradient_pos = $1" ${THEMERC}
}
2022-09-19 20:59:26 +02:00
gradient () {
read MBG MBGA<<< "$(grep 'color_menu_bg ' ${THEMERC} | cut -d'=' -f2)"
read MBGT MBGTA<<< "$(grep 'color_menu_bg_to ' ${THEMERC} | cut -d'=' -f2)"
sd "color_menu_bg .*$" "color_menu_bg = $1 $MBGA" ${THEMERC}
sd "color_menu_bg_to.*$" "color_menu_bg_to = $2 $MBGTA" ${THEMERC}
2023-05-09 14:14:23 +02:00
# Item
2022-09-19 20:59:26 +02:00
ITEM_FG=$(pastel textcolor ${2}|pastel format hex)
2023-05-09 14:14:23 +02:00
if [[ "${ITEM_FG}" == *"ffffff"* ]];then
ITEM_FGCOLOR="#c0c0c0"
else
ITEM_FGCOLOR="#222222"
fi
2022-09-19 20:59:26 +02:00
read NFG NFGA<<< "$(grep 'color_norm_fg' ${THEMERC} | cut -d'=' -f2)"
2023-05-09 14:14:23 +02:00
sd "color_norm_fg.*$" "color_norm_fg = $ITEM_FGCOLOR $NFGA" ${THEMERC}
read NBG NBGA<<< "$(grep 'color_norm_bg' ${THEMERC} | cut -d'=' -f2)"
sd "color_norm_bg.*$" "color_norm_bg = $2 $NBGA" ${THEMERC}
# Title (Separator with text)
2022-09-19 20:59:26 +02:00
read TBG TBGA<<< "$(grep 'color_title_bg' ${THEMERC} | cut -d'=' -f2)"
2023-05-09 14:14:23 +02:00
sd "color_title_bg.*$" "color_title_bg = $2 $TBGA" ${THEMERC}
2022-09-19 20:59:26 +02:00
# calculate readable FG color
2023-05-09 14:14:23 +02:00
TITLE_FG=$(pastel textcolor ${2}|pastel format hex)
2022-09-19 20:59:26 +02:00
read TFG TFGA<<< "$(grep 'color_title_fg' ${THEMERC} | cut -d'=' -f2)"
2023-05-09 14:14:23 +02:00
###TITLE_FGCOLOR=$(pastel complement ${2}|pastel format hex)
2022-09-19 20:59:26 +02:00
if [[ "${TITLE_FG}" == *"ffffff"* ]];then
2023-05-09 14:14:23 +02:00
TITLE_FGCOLOR=$(pastel mix -f 0.7 '#ffffff' "${2}"|pastel format hex)
2022-09-19 20:59:26 +02:00
else
2023-05-09 14:14:23 +02:00
TITLE_FGCOLOR=$(pastel mix -f 0.7 '#000000' "${2}"|pastel format hex)
2022-09-19 20:59:26 +02:00
fi
sd "color_title_fg.*$" "color_title_fg = ${TITLE_FGCOLOR} $TFGA" ${THEMERC}
2023-05-09 14:14:23 +02:00
###sd "color_title_fg.*$" "color_title_fg = ${1} $TFGA" ${THEMERC}
2022-09-19 20:59:26 +02:00
read TBORDER TBORDERA<<< "$(grep 'color_title_border' ${THEMERC} | cut -d'=' -f2)"
TITLE_BORDER=$(pastel darken 0.05 ${1}|pastel format hex)
sd "color_title_border.*$" "color_title_border = $TITLE_BORDER $TBORDERA" ${THEMERC}
2023-05-09 14:14:23 +02:00
# Selected (Active) item
2022-09-19 20:59:26 +02:00
read SBG SBGA<<< "$(grep 'color_sel_bg' ${THEMERC} | cut -d'=' -f2)"
alpha=${SBGA:-100}
sd "color_sel_bg.*$" "color_sel_bg = $2 $alpha" ${THEMERC}
ACTIVE_FG=$(pastel textcolor ${2}|pastel format hex)
read SFG SFGA<<< "$(grep 'color_sel_fg' ${THEMERC} | cut -d'=' -f2)"
sd "color_sel_fg.*$" "color_sel_fg = $ACTIVE_FG $SFGA" ${THEMERC}
2023-05-09 14:14:23 +02:00
read SBORDER SBORDERA<<< "$(grep 'color_sel_border' ${THEMERC} | cut -d'=' -f2)"
alpha=${SBORDERA:-100}
sd "color_sel_border.*$" "color_sel_border = $1 $alpha" ${THEMERC}
# Separator line
2022-09-19 20:59:26 +02:00
read SFG SFGA<<< "$(grep 'color_sep_fg' ${THEMERC} | cut -d'=' -f2)"
SEP_FG=$(pastel mix -f 0.5 "${1}" "${2}"|pastel format hex)
sd "color_sep_fg.*$" "color_sep_fg = $SEP_FG $SFGA" ${THEMERC}
# Menu border
read MBORDER MBORDERA<<< "$(grep 'color_menu_border' ${THEMERC} | cut -d'=' -f2)"
sd "color_menu_border.*$" "color_menu_border = $1 $MBORDERA" ${THEMERC}
}
2022-05-15 03:25:01 +02:00
sep_halign () {
sd "sep_halign.*$" "sep_halign = $1" ${THEMERC}
}
color_sep_fg () {
read SFG SFGA<<< "$(grep 'color_sep_fg' ${THEMERC} | cut -d'=' -f2)"
case "${#1}" in
7) #color
sd "color_sep_fg.*$" "color_sep_fg = $1 $SFGA" ${THEMERC}
;;
*)
sd "color_sep_fg.*$" "color_sep_fg = $SFG $1" ${THEMERC}
;;
esac
}
color_title_bg () {
read TBG TBGA<<< "$(grep 'color_title_bg' ${THEMERC} | cut -d'=' -f2)"
2022-08-20 20:51:56 +02:00
#notify-send.sh "${1}" "${#1}"
2022-05-15 03:25:01 +02:00
case "${#1}" in
7) #color
sd "color_title_bg.*$" "color_title_bg = $1 $TBGA" ${THEMERC}
;;
*)
sd "color_title_bg.*$" "color_title_bg = $TBG $1" ${THEMERC}
;;
esac
}
color_title_fg () {
read TFG TFGA<<< "$(grep 'color_title_fg' ${THEMERC} | cut -d'=' -f2)"
case "${#1}" in
7) #color
sd "color_title_fg.*$" "color_title_fg = $1 $TFGA" ${THEMERC}
;;
*)
sd "color_title_fg.*$" "color_title_fg = $TFG $1" ${THEMERC}
;;
esac
}
color_title_border () {
read TBORDER TBORDERA<<< "$(grep 'color_title_border' ${THEMERC} | cut -d'=' -f2)"
case "${#1}" in
7) #color
sd "color_title_border.*$" "color_title_border = $1 $TBORDERA" ${THEMERC}
;;
*)
sd "color_title_border.*$" "color_title_border = $TBORDER $1" ${THEMERC}
;;
esac
}
item_border () {
sd "item_border.*$" "item_border = $1" ${THEMERC}
}
item_radius () {
sd "item_radius.*$" "item_radius = $1" ${THEMERC}
}
color_norm_bg () {
read NBG NBGA<<< "$(grep 'color_norm_bg' ${THEMERC} | cut -d'=' -f2)"
case "${#1}" in
7) #color
sd "color_norm_bg.*$" "color_norm_bg = $1 $NBGA" ${THEMERC}
;;
*)
sd "color_norm_bg.*$" "color_norm_bg = $NBG $1" ${THEMERC}
;;
esac
}
color_norm_fg () {
read NFG NFGA<<< "$(grep 'color_norm_fg' ${THEMERC} | cut -d'=' -f2)"
case "${#1}" in
7) #color
sd "color_norm_fg.*$" "color_norm_fg = $1 $NFGA" ${THEMERC}
;;
*)
sd "color_norm_fg.*$" "color_norm_fg = $NFG $1" ${THEMERC}
;;
esac
}
color_sel_bg () {
read SBG SBGA<<< "$(grep 'color_sel_bg' ${THEMERC} | cut -d'=' -f2)"
2022-09-19 20:59:26 +02:00
alpha=${SBGA:-100}
2022-05-15 03:25:01 +02:00
case "${#1}" in
7) #color
2022-08-15 01:42:52 +02:00
sd "color_sel_bg.*$" "color_sel_bg = $1 $alpha" ${THEMERC}
2022-05-15 03:25:01 +02:00
;;
*)
sd "color_sel_bg.*$" "color_sel_bg = $SBG $1" ${THEMERC}
;;
esac
}
color_sel_fg () {
read SFG SFGA<<< "$(grep 'color_sel_fg' ${THEMERC} | cut -d'=' -f2)"
case "${#1}" in
7) #color
sd "color_sel_fg.*$" "color_sel_fg = $1 $SFGA" ${THEMERC}
;;
*)
sd "color_sel_fg.*$" "color_sel_fg = $SFG $1" ${THEMERC}
;;
esac
}
color_sel_border () {
read SBORDER SBORDERA<<< "$(grep 'color_sel_border' ${THEMERC} | cut -d'=' -f2)"
case "${#1}" in
7) #color
sd "color_sel_border.*$" "color_sel_border = $1 $SBORDERA" ${THEMERC}
;;
*)
sd "color_sel_border.*$" "color_sel_border = $SBORDER $1" ${THEMERC}
;;
esac
2023-05-09 14:14:23 +02:00
read IBOR<<< "$(grep 'item_border' ${THEMERC} | cut -d'=' -f2)"
[[ ${IBOR} == "0" ]] && item_border 1
}
tweak () {
case "$1" in
solid)
menu_gradient_pos none
tweak opacity 100
opacity color_norm_bg 0
opacity color_sep_fg 30
item_radius 0
item_border 0
;;
gradient)
menu_gradient_pos right
opacity color_norm_bg 10
opacity color_sep_fg 0
item_radius 3
item_border 0
;;
opacity)
opacity color_menu_bg "$2"
opacity color_menu_bg_to "$2"
;;
padding)
case "$2" in
tight)
mb-setvar jgtools_padding=0
;;
normal)
mb-setvar jgtools_padding=8
;;
wide)
mb-setvar jgtools_padding=20
;;
esac
;;
*):;;
esac
}
opacity () {
# jgctl opacity element value
read FUNC B COLOR OPACITY REST<<< "$(grep ${1} ${THEMERC})"
#echo "$FUNC $B $COLOR $OPACITY $REST"
sd "$1.*= $COLOR.*$" "$FUNC = $COLOR $2 $REST" ${THEMERC}
2022-05-15 03:25:01 +02:00
}
case "$1" in
2022-12-19 22:22:23 +01:00
theme) theme "$2";;
2022-05-15 03:25:01 +02:00
reset) reset ;;
2022-12-19 22:22:23 +01:00
resetMBcolors) resetMBcolors "$2";;
2022-05-15 03:25:01 +02:00
color_menu_bg) color_menu_bg "$2";;
color_menu_bg_to) color_menu_bg_to "$2";;
color_menu_border) color_menu_border "$2";;
menu_gradient_pos) menu_gradient_pos "$2";;
2022-09-19 20:59:26 +02:00
gradient) gradient "$2" "$3";;
2022-05-15 03:25:01 +02:00
sep_halign) sep_halign "$2";;
color_sep_fg) color_sep_fg "$2";;
color_title_bg) color_title_bg "$2";;
color_title_fg) color_title_fg "$2";;
color_title_border) color_title_border "$2";;
item_border) item_border "$2";;
item_radius) item_radius "$2";;
color_norm_bg) color_norm_bg "$2";;
color_norm_fg) color_norm_fg "$2";;
color_sel_bg) color_sel_bg "$2";;
color_sel_fg) color_sel_fg "$2";;
color_sel_border) color_sel_border "$2";;
2023-05-09 14:14:23 +02:00
tweak) tweak "$2" "$3";;
opacity) opacity "$2" "$3";;
2022-05-15 03:25:01 +02:00
*) : ;;
esac