#!/bin/bash # mbxutils: handy utilities for your X11 window manager. # Copyright (C) 2021 Daniel Napora # # mbx-preferences appsmenu|lpanel|rpanel|about - pipemenu # mbx-preferences appsmenu|lpanel|rpanel|about st - standalone ME=$(basename "$0") 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 < ${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:-} color_menu_bg = ${bgcolor:-#0F2437} 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 "$x,$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 } me() { # if $1 brak then standalone PAR="mbx ${1:-preferences}" case "$1" in appsmenu) out+=("^sep(Apps Menu)") out+=("$(printf "%-15s %24s" "Show Apps in:" "[$apps_in]"),^checkout(appsin)") out+=("^sep(Custom commands in Apps Menu)") out+=("Favorites,xdg-open ~/.config/mbxutils/inc/favorites.csv") out+=("Commands below Apps,xdg-open ~/.config/mbxutils/inc/m_after_apps.csv") ;; lpanel) out+=("^sep(Custom commands in Left Sidepanel)") out+=("Top,xdg-open ~/.config/mbxutils/inc/ltop.csv") out+=("Bottom,xdg-open ~/.config/mbxutils/inc/lbottom.csv") ;; rpanel) out+=("^sep(Custom commands in Right Sidepanel)") out+=("Top,xdg-open ~/.config/mbxutils/inc/rtop.csv") out+=("Bottom,xdg-open ~/.config/mbxutils/inc/rbottom.csv") ;; all) out+=("^sep(Custom commands ALL)") ;; esac out+=("^sep(Global Settings)") out+=("^sep(Appearance)") out+=("$(printf "%-15s %24s" "Font:" "[$font]"),^pipe($ME fonts $1)") out+=("$(printf "%-15s %24s" "Font size (px):" "[$font_size]"),^checkout(fontsize)") out+=("$(printf "%-15s %24s" "Line height:" "[$item_height_factor%]"),^checkout(lineheight)") out+=("$(printf "%-15s %24s" "Menu BGcolor:" "[$bgcolor]"),^checkout(bgcolor)") out+=("$(printf "%-15s %24s" "Menu Padding:" "[$menu_padding]"),^checkout(menupadding)") out+=("^sep(Other)") out+=("$(printf "%-15s %24s" "Terminal:" "[$terminal]"),^checkout(terminal),terminal") #out+=("$(printf "%-15s %24s" "File Manager:" "[$filemanager]"),^checkout(filemanager)") #out+=("$(printf "%-15s %20s" "Margin (px):" "[$margin_xy]"),^checkout(margin)") out+=("^sep(Config files)") out+=("Edit config file,xdg-open $CNF_FILE") out+=("Open config dir,xdg-open $CNF_DIR") out+=("^sep()") out+=("About mbxutils,mbx") #tags out2+=("^tag(fontsize)") out2+=("^sep(Font size)") for i in 10 11 12 13 14 15 16 18 20; do out2+=("$(printf "%4s,%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 "%4s%%,%s" "$i" "$ME setvar item_height_factor=${i};$PAR fixed")");done out2+=("^tag(bgcolor)") out2+=("^sep(Select BGcolor)") out2+=("Pick color from screen") colors="$CNF_DIR/inc/colors.clr" while read -r color; do fgc $color out2+=(" $color ,mbx setvar bgcolor='$color';$PAR fixed") done < "$colors" out2+=("^tag(menupadding)") for i in 0 2 5 8 12 16; do out2+=("$(printf "%4s,%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 fg "$bgcolor" [ "$menu_padding" == "0" ] && item_margin_x=0 item_margin_y=0 item_radius=0 configure cat < ${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";; appsmenu|lpanel|rpanel|about) me "$1" "$2";; *) me;; esac exit 0