mabox-colorizer/bin/jgctl
2024-02-22 14:24:51 +01:00

467 lines
13 KiB
Bash
Executable File

#!/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
# Backup original theme file
if [ ! -f "${THEMERC}.bak" ]; then
cp ${THEMERC} ${THEMERC}.bak
fi
theme () {
mb-setvar jgmenu_theme=${1}
}
reset () {
rm ${THEMERC}
mv ${THEMERC}.bak ${THEMERC}
}
resetMBcolors() {
mb-setvar jgmenu_theme=MBcolors
mb-setvar item_height_factor=200
reset
case "$1" in
show)
colorizer-menus -s
;;
*):;;
esac
}
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}
}
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}
# Item
ITEM_FG=$(pastel textcolor ${2}|pastel format hex)
if [[ "${ITEM_FG}" == *"ffffff"* ]];then
ITEM_FGCOLOR="#c0c0c0"
else
ITEM_FGCOLOR="#222222"
fi
read NFG NFGA<<< "$(grep 'color_norm_fg' ${THEMERC} | cut -d'=' -f2)"
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)
read TBG TBGA<<< "$(grep 'color_title_bg' ${THEMERC} | cut -d'=' -f2)"
sd "color_title_bg.*$" "color_title_bg = $2 $TBGA" ${THEMERC}
# calculate readable FG color
TITLE_FG=$(pastel textcolor ${2}|pastel format hex)
read TFG TFGA<<< "$(grep 'color_title_fg' ${THEMERC} | cut -d'=' -f2)"
###TITLE_FGCOLOR=$(pastel complement ${2}|pastel format hex)
if [[ "${TITLE_FG}" == *"ffffff"* ]];then
TITLE_FGCOLOR=$(pastel mix -f 0.7 '#ffffff' "${2}"|pastel format hex)
else
TITLE_FGCOLOR=$(pastel mix -f 0.7 '#000000' "${2}"|pastel format hex)
fi
sd "color_title_fg.*$" "color_title_fg = ${TITLE_FGCOLOR} $TFGA" ${THEMERC}
###sd "color_title_fg.*$" "color_title_fg = ${1} $TFGA" ${THEMERC}
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}
# Selected (Active) item
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}
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
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}
}
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)"
#notify-send.sh "${1}" "${#1}"
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)"
alpha=${SBGA:-100}
case "${#1}" in
7) #color
sd "color_sel_bg.*$" "color_sel_bg = $1 $alpha" ${THEMERC}
;;
*)
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
#read IBOR<<< "$(grep 'item_border' ${THEMERC} | cut -d'=' -f2)"
#[[ ${IBOR} == "0" ]] && item_border 1
}
accent () {
color_sel_bg "${1}"
color_sel_fg "${2}"
color_sel_border "${2}"
}
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"
;;
sizing)
case "$2" in
tight)
mb-setvar jgtools_padding=4
mb-setvar jgtools_border=0
mb-setvar submenu_spacing=2
mb-setvar arrow_string=
;;
normal)
mb-setvar jgtools_padding=8
mb-setvar jgtools_border=3
mb-setvar submenu_spacing=3
mb-setvar arrow_string=
;;
wide)
mb-setvar jgtools_padding=20
mb-setvar jgtools_border=6
mb-setvar submenu_spacing=6
mb-setvar arrow_string=
;;
esac
;;
*):;;
esac
[[ "$3" == "menu" ]] && colorizer-menus -s 2>/dev/null
}
t_search_field () {
[[ $search_field == "false" ]] && mb-setvar search_field=true || mb-setvar search_field=false
mb-jgtools main ipc
}
t_apps_in_submenu () {
[[ $apps_in_submenu == "true" ]] && mb-setvar apps_in_submenu=false || mb-setvar apps_in_submenu=true
mb-jgtools main ipc
}
t_icons () {
[[ $jgmenu_use_icons == "true" ]] && mb-setvar jgmenu_use_icons=false || mb-setvar jgmenu_use_icons=true
mb-jgtools main ipc
}
border () {
[[ "$jgtools_padding" -lt "${1}" ]] && mb-setvar jgtools_padding=${1}
mb-setvar jgtools_border=${1}
colorizer-menus -s
}
padding () {
[[ "$jgtools_border" -gt "${1}" ]] && mb-setvar jgtools_border=${1}
mb-setvar jgtools_padding=${1}
colorizer-menus -s
}
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}
}
savescheme () {
case "$LANG" in
pl*)SAVE_AS="Nowy motyw Menu"
DESC="Zapisz obecnie ustawione kolory Menu jako nowy motyw..."
LABEL="Nazwa:"
NAME="nazwa";;
*) SAVE_AS="New Menu colorscheme"
DESC="Save current Menu colors as colorscheme..."
LABEL="Name:"
NAME="colorscheme-name";;
esac
# ask for scheme name
schemename=$(yad --center --width=300 --borders=20 --window-icon=mbcc --title "$SAVE_AS" --text="$DESC" --entry --entry-label="$LABEL" --entry-text="$NAME") || exit 1
echo "${1}${schemename}" >> "$HOME/.config/colorizer/menus/userschemes.csv"
}
applyscheme () {
theme MBcolors
line=$(awk 'NR == n' n=$1 "$HOME/.config/colorizer/menus/userschemes.csv")
#notify-send.sh "$1" "${line}"
case "$1" in
sys) SCHEMEFILE="/usr/share/mabox-colorizer/colorschemes/menus.csv";;
usr) SCHEMEFILE="$HOME/.config/colorizer/menus/userschemes.csv";;
esac
while IFS="|" read -r mbg mbgt mborder tbg tfg tborder normbg nfg sbg sfg sborder sepfg grad scheme_name
do
mb-setvar jgmenu_theme=MBcolors
color_menu_bg "${mbg}"
color_menu_bg_to "${mbgt}"
color_menu_border "${mborder}"
color_title_bg "${tbg}"
color_title_fg "${tfg}"
color_title_border "${tborder}"
color_norm_bg "${normbg}"
color_norm_fg "${nfg}"
color_sel_bg "${sbg}"
color_sel_fg "${sfg}"
color_sel_border "${sborder}"
color_sep_fg "${sepfg}"
menu_gradient_pos "${grad}"
item_border 0
color_title_bg 100
color_menu_bg 100
color_menu_bg_to 100
color_norm_bg 0
#notify-send.sh "${scheme_name}" "${mbg}"
done < <(awk 'NR == n' n=$2 "$SCHEMEFILE")
}
delscheme() {
sed -i ${1}d "$HOME/.config/colorizer/menus/userschemes.csv"
}
mono () {
lighten=(0.92 0.8 0.65 0.45 0.28)
darken=(0.9 0.74 0.54 0.38 0.18)
if [ "${1}" == pick ];then
color=$(gpick -pso 2>/dev/null)
else
color="${1}"
fi
if [ "${#color}" == 7 ];then
for i in "${lighten[@]}"
do
pal+=("$(pastel mix -f $i "#ffffff" "$color"|pastel format hex)")
done
pal+=("$color")
for i in "${darken[@]}"
do
pal+=("$(pastel mix -f $i "$color" "#000000"|pastel format hex)")
done
else
exit 0
fi
# colorize menu
if [ "$2" == "dark" ];then
#notify-send.sh "$1" "gen_menu"
color_menu_bg "${pal[8]}"
color_menu_bg_to "${pal[7]}"
color_menu_border "${pal[10]}"
color_title_bg "${pal[9]}"
color_title_border "${pal[9]}"
color_title_fg "${pal[2]}"
color_norm_fg "${pal[3]}"
color_sel_bg "${pal[6]}"
color_sel_fg "${pal[1]}"
color_sep_fg "${pal[6]}"
else #light
color_menu_bg "${pal[2]}"
color_menu_bg_to "${pal[3]}"
color_menu_border "${pal[1]}"
color_title_bg "${pal[3]}"
color_title_border "${pal[4]}"
color_title_fg "${pal[10]}"
color_norm_fg "${pal[8]}"
color_sel_bg "${pal[4]}"
color_sel_fg "${pal[10]}"
color_sep_fg "${pal[3]}"
fi
colorizer-menus -s 2>/dev/null
}
case "$1" in
theme) theme "$2";;
reset) reset ;;
resetMBcolors) resetMBcolors "$2";;
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";;
gradient) gradient "$2" "$3";;
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";;
accent) accent "$2" "$3";;
tweak) tweak "$2" "$3" "$4";;
opacity) opacity "$2" "$3";;
t_search_field)t_search_field;;
t_apps_in_submenu) t_apps_in_submenu;;
t_icons)t_icons;;
border)border "$2";;
padding)padding "$2";;
mono) mono "$2" "$3";;
savescheme) savescheme "$2";;
applyscheme) applyscheme "$2" "$3";;
delscheme) delscheme "$2";;
*) : ;;
esac