mbxutils/bin/mbx-preferences

242 lines
8.4 KiB
Plaintext
Raw Normal View History

2021-10-24 13:08:30 +02:00
#!/bin/bash
# mbxutils: handy utilities for your X11 window manager.
# Copyright (C) 2021 Daniel Napora <napcok@gmail.com>
#
# mbx-preferences appsmenu|lpanel|rpanel|about - pipemenu
# mbx-preferences appsmenu|lpanel|rpanel|about st - standalone
2021-10-26 21:02:04 +02:00
ME=${0##*/}
2021-10-24 13:08:30 +02:00
CNF_DIR="$HOME/.config/mbxutils"
CNF_FILE="$CNF_DIR/mbx.conf"
source <(grep = $CNF_FILE)
fg(){
r=$(printf "%d" 0x${1:1:2}) g=$(printf "%d" 0x${1:3:2}) b=$(printf "%d" 0x${1:5:2})
rgb="$((r*299+g*587+b*114))"
[ "$rgb" -gt 138000 ] && fgcolor="#222222" color_title_fg="#111111" color_sel_fg="#111111" color_sep_fg="#222222 20"|| fgcolor="#EEEEEE" color_title_fg="#FFFFFF" color_sel_fg="#FFFFFF"
[ "$rgb" -gt 200000 ] && color_sel_bg="#222222 8" color_sel_border="#222222 16" color_title_bg="#222222 8"
}
fgc(){
r=$(printf "%d" 0x${1:1:2}) g=$(printf "%d" 0x${1:3:2}) b=$(printf "%d" 0x${1:5:2})
rgb="$((r*299+g*587+b*114))"
[ "$rgb" -gt 138000 ] && fgcolor="#222222"|| fgcolor="#EEEEEE"
}
[ "$menu_padding" == "0" ] && item_margin_x=0 item_margin_y=0 item_radius=0 item_padding_x=8
configure() {
if [ -f /usr/share/mbxutils/mbxutils.inc ];then
. /usr/share/mbxutils/mbxutils.inc
else
cat <<EOF > ${CONFIG_FILE}
position_mode = ${position_mode:-fixed}
csv_cmd = apps
stay_alive = 0
terminal_exec = ${terminal:-terminator}
terminal_args = -e
hover_delay = 80
columns = ${columns:-1}
# MENU
menu_halign = ${menu_halign:-left}
menu_valign = ${menu_valign:-center}
menu_margin_x = ${menu_margin_x:-4}
menu_margin_y = ${menu_margin_y:-4}
sub_spacing = ${sub_spacing:-2}
menu_width = ${menu_width:-20}
menu_border = 1
menu_height_min = ${menu_height_min:-0}
menu_height_max = ${menu_height_max:-0}
menu_padding_top = ${menu_padding_top:-5}
menu_padding_right = ${menu_padding:-5}
menu_padding_bottom = ${menu_padding:-5}
menu_padding_left = ${menu_padding:-5}
menu_radius = ${menu_radius:-1}
# ITEMS
item_height = $((font_size*item_height_factor/100))
item_halign = ${item_halign:-left}
item_padding_x = {item_padding_x:-2}
item_margin_x = ${item_margin_x:-3}
item_margin_y = ${item_margin_y:-3}
item_radius = ${item_radius:-2}
item_border = ${item_border:-1}
arrow_string = ${arrow_string:-▸}
hide_back_items = ${hide_back_items:-0}
# COLORS
color_sel_bg = ${color_sel_bg:-}
color_sel_fg = ${color_sel_fg:-}
color_sel_border = ${color_sel_border:-#eeeeee 40}
color_norm_fg = ${fgcolor:-}
color_title_fg = ${color_title_fg:-}
2021-10-25 23:14:07 +02:00
color_menu_bg = ${color_menu_bg:-#0F2437}
2021-10-24 13:08:30 +02:00
color_menu_border = #eeeeee 8
color_title_bg = ${color_title_bg:-"$fgcolor 12"}
color_title_border = ${color_title_border:-}
color_sep_fg = ${color_sep_fg:-}
icon_theme = ${icon_theme:-}
icon_size = ${icon_size:-0}
icon_norm_alpha = 70
icon_sel_alpha = 100
icon_text_spacing = $((icon_size/4))
font_size = ${font_size:-12}
font = ${font} ${font_size}px
sep_markup = weight="bold"
sep_halign = ${sep_halign:-center}
sep_height = ${sep_height:-3}
EOF
fi
}
fonts(){
PAR="mbx $1"
echo "^sep(Font)"
while read -r x
do
echo "<span size=\"x-large\" font_family=\"$x\">$x</span>,$ME setvar \"font=\'${x}\'\";$PAR fixed"
done < "$CNF_DIR"/inc/fonts.inc
}
setvar() {
search="$(echo $1|cut -d= -f1)="
if grep -Rq $search $CNF_FILE
then #found
sed -i s/^"$search".*$/"$1"/ $CNF_FILE
else #not found
echo $1 >> $CNF_FILE
fi
}
2021-10-25 23:14:07 +02:00
pickcolor() {
PAR="mbx ${2}"
color=$(colorpicker --short --one-shot --preview)
${ME} setvar color_menu_bg=${color}
${PAR}
}
2021-10-24 22:13:14 +02:00
main() {
2021-10-24 13:08:30 +02:00
# if $1 brak then standalone
PAR="mbx ${1:-preferences}"
case "$1" in
appsmenu)
out+=("^sep(Apps Menu)")
out+=("<tt>$(printf "%-15s %24s" "Show Apps in:" "[<b>$apps_in</b>]")</tt>,^checkout(appsin)")
out+=("^sep(<i>Custom commands in Apps Menu</i>)")
2022-02-01 21:20:11 +01:00
out+=("Favorites,xdg-open ~/.config/mbxutils/inc/menu_top.csv")
out+=("Commands below Apps,xdg-open ~/.config/mbxutils/inc/menu_bottom.csv")
2021-10-24 13:08:30 +02:00
;;
lpanel)
out+=("^sep(<i>Custom commands in Left Sidepanel</i>)")
2022-02-01 21:20:11 +01:00
out+=("Top,xdg-open ~/.config/mbxutils/inc/left_top.csv")
out+=("Bottom,xdg-open ~/.config/mbxutils/inc/left_bottom.csv")
2021-10-24 13:08:30 +02:00
;;
rpanel)
out+=("^sep(<i>Custom commands in Right Sidepanel</i>)")
2022-02-01 21:20:11 +01:00
out+=("Top,xdg-open ~/.config/mbxutils/inc/right_top.csv")
out+=("Bottom,xdg-open ~/.config/mbxutils/inc/right_bottom.csv")
2021-10-24 13:08:30 +02:00
;;
all)
out+=("^sep(<i>Custom commands ALL</i>)")
;;
esac
out+=("^sep(Global Settings)")
out+=("^sep(<i>Appearance</i>)")
out+=("<tt>$(printf "%-15s %24s" "Font:" "[<b>$font</b>]")</tt>,^pipe($ME fonts $1)")
out+=("<tt>$(printf "%-15s %24s" "Font size (px):" "[<b>$font_size</b>]")</tt>,^checkout(fontsize)")
out+=("<tt>$(printf "%-15s %24s" "Line height:" "[<b>$item_height_factor%</b>]")</tt>,^checkout(lineheight)")
2022-02-01 21:20:11 +01:00
out+=("<tt>$(printf "%-15s %24s" "Menu BGcolor:" "[<b>$color_menu_bg</b>]")</tt>,^checkout(bgcolor)")
2021-10-24 13:08:30 +02:00
out+=("<tt>$(printf "%-15s %24s" "Menu Padding:" "[<b>$menu_padding</b>]")</tt>,^checkout(menupadding)")
2021-10-24 22:13:14 +02:00
out+=("^sep()")
out+=("Reset to default,mbx reset ${1}")
2021-10-24 13:08:30 +02:00
out+=("^sep(<i>Other</i>)")
out+=("<tt>$(printf "%-15s %24s" "Terminal:" "[<b>$terminal</b>]")</tt>,^checkout(terminal),terminal")
#out+=("<tt>$(printf "%-15s %24s" "File Manager:" "[<b>$filemanager</b>]")</tt>,^checkout(filemanager)")
#out+=("<tt>$(printf "%-15s %20s" "Margin (px):" "[<b>$margin_xy</b>]")</tt>,^checkout(margin)")
out+=("^sep(<i>Config files</i>)")
out+=("Edit config file,xdg-open $CNF_FILE")
out+=("Open config dir,xdg-open $CNF_DIR")
out+=("^sep()")
2022-02-01 21:20:11 +01:00
out+=("About <b>mbxutils</b>,mbx")
2021-10-24 13:08:30 +02:00
#tags
out2+=("^tag(fontsize)")
out2+=("^sep(Font size)")
for i in 10 11 12 13 14 15 16 18 20; do out2+=("$(printf "<tt>%4s</tt>,%s" "$i" "$ME setvar font_size=${i};$PAR fixed")");done
out2+=("^tag(lineheight)")
for i in 120 140 160 180 200 240 280; do out2+=("$(printf "<tt>%4s%%</tt>,%s" "$i" "$ME setvar item_height_factor=${i};$PAR fixed")");done
out2+=("^tag(bgcolor)")
out2+=("^sep(Select BGcolor)")
2021-10-25 23:14:07 +02:00
if hash colorpicker 2>/dev/null; then
out2+=("Pick color from screen,${ME} pickcolor ${1}")
out2+=("^sep()")
fi
2021-10-24 13:08:30 +02:00
colors="$CNF_DIR/inc/colors.clr"
while read -r color; do
fgc $color
2021-10-25 23:14:07 +02:00
out2+=("<tt><span bgcolor='$color' fgcolor='$fgcolor'><sub> </sub>$color <sup> </sup></span></tt>,mbx setvar color_menu_bg='$color';$PAR fixed")
2021-10-24 13:08:30 +02:00
done < "$colors"
out2+=("^tag(menupadding)")
for i in 0 2 5 8 12 16; do out2+=("$(printf "<tt>%4s</tt>,%s" "$i" "$ME setvar menu_padding=${i};$PAR fixed")");done
out2+=("^tag(appsin)")
out2+=("^sep()")
out2+=("root,$ME setvar apps_in=root;$PAR fixed")
out2+=("submenu,$ME setvar apps_in=submenu;$PAR fixed")
out2+=("^tag(terminal)")
out2+=("^sep(Select Terminal)")
terminals="$CNF_DIR/inc/terminals.inc"
while read -r term
do
out2+=("$term,mbx setvar terminal=$term;$PAR fixed")
done < "$terminals"
out2+=("^tag(filemanager)")
out2+=("^sep(Select File Manager)")
filemanagers="$CNF_DIR/inc/file_managers.inc"
while read -r fm
do
out2+=("$fm,mbx setvar filemanager=$fm;$PAR fixed")
done < "$filemanagers"
if [[ "$2" == "st" ]]; then
CONFIG_FILE=$(mktemp)
MENU_ITEMS=$(mktemp)
trap "rm -f ${CONFIG_FILE} ${MENU_ITEMS}" EXIT
case "$1" in
lpanel) menu_halign="left";;
rpanel) menu_halign="right";;
about) menu_halign="center";;
esac
2021-10-25 23:14:07 +02:00
fg "$color_menu_bg"
2021-10-24 13:08:30 +02:00
[ "$menu_padding" == "0" ] && item_margin_x=0 item_margin_y=0 item_radius=0
configure
cat <<EOF > ${MENU_ITEMS}
$(printf '%s\n' "${out[@]}")
$(printf '%s\n' "${out2[@]}")
EOF
jgmenu --config-file=${CONFIG_FILE} --csv-file=${MENU_ITEMS} 2>/dev/null
exit 0
else
printf '%s\n' "${out[@]}"
printf '%s\n' "${out2[@]}"
fi
}
case "$1" in
fonts) fonts "$2";;
setvar) setvar "$2";;
2021-10-25 23:14:07 +02:00
pickcolor) pickcolor "$1" "$2";;
2021-10-24 22:13:14 +02:00
appsmenu|lpanel|rpanel|about) main "$1" "$2";;
*) main;;
2021-10-24 13:08:30 +02:00
esac
exit 0