2021-10-20 18:17:15 +02:00
#!/bin/bash
2021-10-21 22:59:27 +02:00
# mbxutils: handy utilities for your X11 window manager.
# Copyright (C) 2021 Daniel Napora <napcok@gmail.com>
#
2021-10-20 18:17:15 +02:00
# TODO Logout Dialog postponed
# TODO Filebrowser standalone postponed
ME=$(basename "$0")
CNF_DIR="$HOME/.config/mbxutils"
CNF_FILE="$CNF_DIR/$ME.conf"
2021-10-20 18:32:27 +02:00
[ ! -d "$HOME/.config/jgmenu" ] && mkdir -p "$HOME/.config/jgmenu"
2021-10-20 18:17:15 +02:00
2021-10-24 22:13:14 +02:00
defaults() {
mbx setvar apps_in=rootmenu
mbx setvar menu_padding=5
mbx setvar item_height_factor=200
mbx setvar "font=\'Noto Sans\'"
mbx setvar font_size=13
2021-10-25 23:14:07 +02:00
mbx setvar color_menu_bg=#252525
2021-10-24 22:13:14 +02:00
mbx ${1}
}
2021-10-20 18:17:15 +02:00
[ ! -d "$CNF_DIR" ] && mkdir -p "$CNF_DIR" && cp -r /usr/share/mbxutils/* "$CNF_DIR"/
if [ ! -f $CNF_FILE ]; then
cat <<EOF > ${CNF_FILE}
2021-10-24 22:13:14 +02:00
apps_in=rootmenu
2021-10-20 18:17:15 +02:00
menu_padding=5
item_height_factor=200
2021-10-24 22:13:14 +02:00
font='Noto Sans'
font_size=13
2021-10-25 23:14:07 +02:00
color_menu_bg=#252525
2021-10-20 18:17:15 +02:00
EOF
fi
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"
2021-10-21 22:59:27 +02:00
[ "$rgb" -gt 200000 ] && color_sel_bg="#222222 8" color_sel_border="#222222 16" color_title_bg="#222222 8"
2021-10-20 18:17:15 +02:00
}
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 item_padding_x=8
2021-10-20 18:17:15 +02:00
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
2021-10-21 18:15:31 +02:00
columns = ${columns:-1}
2021-10-20 18:17:15 +02:00
# 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}
2021-10-24 13:08:30 +02:00
item_padding_x = {item_padding_x:-2}
2021-10-20 18:17:15 +02:00
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-20 18:17:15 +02:00
color_menu_border = #eeeeee 8
color_title_bg = ${color_title_bg:-"$fgcolor 12"}
2021-10-21 01:14:20 +02:00
color_title_border = ${color_title_border:-}
2021-10-20 18:17:15 +02:00
color_sep_fg = ${color_sep_fg:-}
2021-10-25 00:33:00 +02:00
icon_theme = ${icon_theme:-Papirus}
2021-10-25 23:14:07 +02:00
icon_theme_fallback = ${icon_theme_fallback:-hicolor}
2021-10-20 18:17:15 +02:00
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
}
2021-10-24 13:08:30 +02:00
appsmenu() {
2021-10-20 18:17:15 +02:00
CONFIG_FILE=$(mktemp)
trap "rm -f ${CONFIG_FILE}" EXIT
font_size=${font_size:-12}
position_mode=${1:-pointer}
hide_back_items=1
## poniższe defaultowo do configu
menu_padding=${menu_padding:-5}
menu_padding_top=$((font_size*item_height_factor/100+menu_padding))
icon_size=$((font_size*item_height_factor/100-2))
rm -f ~/.config/jgmenu/append.csv
2021-10-24 13:08:30 +02:00
if [[ $apps_in == "submenu" ]]
2021-10-20 18:17:15 +02:00
then
cat <<EOF > $HOME/.config/jgmenu/prepend.csv
2021-10-24 13:08:30 +02:00
@text,,$((menu_padding+10)),$((menu_padding_top-font_size*item_height_factor/100+2)),150,$((font_size*item_height_factor/100)),0,left,top,auto,#000000,🔍
@search,,$((menu_padding+32)),$((menu_padding_top-font_size*item_height_factor/100)),150,$((font_size*item_height_factor/100)),2,left,top,auto,#000000,<i> type to search </i>
2021-10-20 18:17:15 +02:00
. ~/.config/mbxutils/inc/favorites.csv
2021-10-24 13:08:30 +02:00
Applications,^checkout(apps),applications-other
2021-10-20 18:17:15 +02:00
. ~/.config/mbxutils/inc/m_after_apps.csv
^sep()
Logout dialog,mb-jgtools mblogout,system-shutdown
2021-10-24 13:08:30 +02:00
Preferences,^pipe(mbx-preferences appsmenu),settings
Preferences,mbx-preferences appsmenu st,settings
^sep()
About <b>mbxutils</b>,mbx
2021-10-20 18:17:15 +02:00
^tag(apps)
EOF
else
cat <<EOF > $HOME/.config/jgmenu/prepend.csv
2021-10-24 13:08:30 +02:00
@text,,$((menu_padding+10)),$((menu_padding_top-font_size*item_height_factor/100+2)),150,$((font_size*item_height_factor/100)),0,left,top,auto,#000000,🔍
@search,,$((menu_padding+32)),$((menu_padding_top-font_size*item_height_factor/100)),150,$((font_size*item_height_factor/100)),2,left,top,auto,#000000,<i> type to search </i>
2021-10-20 18:17:15 +02:00
. ~/.config/mbxutils/inc/favorites.csv
2021-10-24 13:08:30 +02:00
^sep(Applications)
2021-10-20 18:17:15 +02:00
EOF
cat <<EOF > $HOME/.config/jgmenu/append.csv
. ~/.config/mbxutils/inc/m_after_apps.csv
^sep()
2021-10-24 13:08:30 +02:00
Logout dialog,mb-jgtools mblogout,system-shutdown
Preferences,^pipe(mbx-preferences appsmenu),settings
Preferences,mbx-preferences appsmenu st,settings
2021-10-21 01:14:20 +02:00
^sep()
About <b>mbxutils</b>,mbx
2021-10-24 13:08:30 +02:00
2021-10-20 18:17:15 +02:00
EOF
fi
configure
jgmenu --config-file=${CONFIG_FILE} --no-append 2>/dev/null
}
2021-10-24 22:13:14 +02:00
distrologo() {
case "$distro" in
Manjaro) logo=manjaro;;
2021-10-24 22:17:03 +02:00
Mabox) logo=mabox;;
Lubuntu) logo=lubuntu;;
2021-10-24 22:13:14 +02:00
*) logo=tux;;
esac
}
2021-10-20 18:17:15 +02:00
lpanel() {
2021-10-24 13:08:30 +02:00
OSNAME=$(lsb_release -d | awk '{print $2}') #Mabox
OSVERSION=$(lsb_release -r | awk '{print $2}') #21.10
OSCODE=$(lsb_release -c | awk '{print $2}') # Geralt
2021-10-20 18:17:15 +02:00
CONFIG_FILE=$(mktemp)
MENU_ITEMS=$(mktemp)
trap "rm -f ${CONFIG_FILE} ${MENU_ITEMS}" EXIT
2021-10-24 22:13:14 +02:00
menu_padding_top=$((menu_padding+item_margin_y+48))
2021-10-20 18:17:15 +02:00
menu_halign="left"
2021-10-24 22:13:14 +02:00
distro="${distro:-$OSNAME}"
distrologo
2021-10-20 18:17:15 +02:00
configure
2021-10-24 13:08:30 +02:00
#${HOSTNAME:-$(hostname)}@${USER}
2021-10-20 18:17:15 +02:00
cat <<EOF > ${MENU_ITEMS}
2021-10-24 22:13:14 +02:00
@icon,,$((menu_padding+item_margin_x)),${menu_padding},48,48,0,left,top,,,/usr/share/mbxutils/logos/distributor-logo-${logo}.svg
@text,,$((menu_padding+item_margin_x+50)),${menu_padding},180,32,0,left,top,${fgcolor},#DDDDDD,$distro ${OSVERSION} <sup><i>${OSCODE}</i></sup>
@text,,$((menu_padding+item_margin_x+50)),$((menu_padding+20)),180,32,0,left,top,${fgcolor},#DDDDDD,<i>${XDG_SESSION_DESKTOP^}</i>
2021-10-20 18:17:15 +02:00
. ~/.config/mbxutils/inc/ltop.csv
^sep(<b>File browser</b>)
2021-10-24 13:08:30 +02:00
$HOME,^pipe(mbxfiles ~)
2021-10-20 18:17:15 +02:00
~/.config,^pipe(mbxfiles ~/.config)
2021-10-24 13:08:30 +02:00
/etc,^pipe(mbxfiles /etc)
2021-10-20 18:17:15 +02:00
^sep(<b>mbxutils</b>)
2021-10-24 13:08:30 +02:00
Preferences,^pipe(mbx-preferences lpanel)
Preferences,mbx-preferences lpanel st
2021-10-20 18:17:15 +02:00
. ~/.config/mbxutils/inc/lbottom.csv
EOF
jgmenu --config-file=${CONFIG_FILE} --csv-file=${MENU_ITEMS} 2>/dev/null
}
rpanel() {
2021-10-24 22:13:14 +02:00
OSNAME=$(lsb_release -d | awk '{print $2}') #Mabox
OSVERSION=$(lsb_release -r | awk '{print $2}') #21.10
OSCODE=$(lsb_release -c | awk '{print $2}') # Geralt
2021-10-20 18:17:15 +02:00
CONFIG_FILE=$(mktemp)
MENU_ITEMS=$(mktemp)
trap "rm -f ${CONFIG_FILE} ${MENU_ITEMS}" EXIT
2021-10-24 22:13:14 +02:00
menu_padding_top=$((menu_padding+item_margin_y+48))
2021-10-20 18:17:15 +02:00
menu_halign="right"
icon_size=$((font_size*item_height_factor/100-2))
2021-10-24 22:13:14 +02:00
distro="${distro:-$OSNAME}"
distrologo
2021-10-20 18:17:15 +02:00
configure
cat <<EOF > ${MENU_ITEMS}
2021-10-24 22:13:14 +02:00
@icon,,$((menu_padding+item_margin_x)),${menu_padding},48,48,0,left,top,,,/usr/share/mbxutils/logos/distributor-logo-${logo}.svg
@text,,$((menu_padding+item_margin_x+50)),${menu_padding},180,32,0,left,top,${fgcolor},#DDDDDD,$distro ${OSVERSION} <sup><i>${OSCODE}</i></sup>
@text,,$((menu_padding+item_margin_x+50)),$((menu_padding+20)),180,32,0,left,top,${fgcolor},#DDDDDD,<i>${XDG_SESSION_DESKTOP^}</i>
2021-10-20 18:17:15 +02:00
. ~/.config/mbxutils/inc/rtop.csv
^sep(Right Panel)
2021-10-24 13:08:30 +02:00
Preferences,^pipe(mbx-preferences rpanel)
Preferences,mbx-preferences rpanel st
2021-10-20 18:17:15 +02:00
. ~/.config/mbxutils/inc/rbottom.csv
EOF
jgmenu --config-file=${CONFIG_FILE} --csv-file=${MENU_ITEMS} 2>/dev/null
}
2021-10-21 01:14:20 +02:00
about() {
CONFIG_FILE=$(mktemp)
MENU_ITEMS=$(mktemp)
trap "rm -f ${CONFIG_FILE} ${MENU_ITEMS}" EXIT
eval $(xdotool getdisplaygeometry --shell)
twidth=$((WIDTH/4))
theight=$((HEIGHT/4))
THUMB="$(DISPLAY=:0 scrot -t ${twidth}x${theight} -o $HOME/.config/mbxutils/mbx.png -e 'echo $m')"
2021-10-25 00:33:00 +02:00
2021-10-21 18:15:31 +02:00
columns=2
icon_size=$((font_size*item_height_factor/100-2))
2021-10-21 01:14:20 +02:00
menu_halign=center
2021-10-24 13:08:30 +02:00
#menu_padding=8
2021-10-21 01:14:20 +02:00
menu_width=$((twidth+menu_padding*2))
2021-10-21 18:15:31 +02:00
item_height=$((font_size*item_height_factor/100))
2021-10-24 13:08:30 +02:00
menu_padding_top=$((theight+menu_padding+60))
menu_height_max=$((menu_padding_top+menu_padding+item_height*6+item_margin_y*10))
#menu_height_min=$((menu_padding_top+menu_padding+item_height*6+item_margin_y*10))
2021-10-21 01:14:20 +02:00
configure
cat <<EOF > ${MENU_ITEMS}
@icon,,${menu_padding},${menu_padding},${twidth},${theight},4,left,top,,,$THUMB
2021-10-24 13:08:30 +02:00
@text,,$((menu_padding+6)),$((menu_padding+theight+4)),${twidth},25,4,left,top,${fgcolor},#DDDDDD,<span font="28px"><b>mbxutils</b></span><span font="12px"> v0.2.0 (alpha)</span>
@text,,$((menu_padding+40)),$((menu_padding+theight+26)),${twidth},25,4,left,top,${fgcolor} 60,${fgcolor} 12,<span font="12px"><i>a set of lightweight and handy utilities</i></span>
@text,,$((menu_padding+56)),$((menu_padding+theight+38)),${twidth},25,4,left,top,${fgcolor} 60,${fgcolor} 12,<span font="12px"><i>for your X11 window manager</i></span>
2021-10-21 18:15:31 +02:00
^sep(Utilities)
2021-10-25 23:14:07 +02:00
Apps menu (main),mbx appsmenu,mbx-appsmenu
2021-10-24 13:08:30 +02:00
Left SidePanel,mbx lpanel,mbx-lpanel
Right SidePanel,mbx rpanel,mbx-rpanel
Logout Dialog, mbx
2021-10-21 18:15:31 +02:00
Quick Filebrowser,mbx files,folder
2021-10-24 13:08:30 +02:00
Preferences,mbx-preferences about st
2021-10-21 18:15:31 +02:00
^sep(Manual)
Configure keybindings,xdg-open https://mbxutils.maboxlinux.org,firefox
Roadmap
2021-10-21 01:14:20 +02:00
EOF
jgmenu --config-file=${CONFIG_FILE} --csv-file=${MENU_ITEMS} 2>/dev/null
}
2021-10-24 13:08:30 +02:00
setvar() { # Może tu niepotrzebnie a tylko w mbx-preferences
2021-10-20 18:17:15 +02:00
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
}
case "$1" in
2021-10-24 22:13:14 +02:00
reset) defaults "$2";;
2021-10-24 13:08:30 +02:00
appsmenu) appsmenu "$2";;
2021-10-20 18:17:15 +02:00
lpanel) lpanel;;
rpanel) rpanel;;
setvar) setvar "$2";;
2021-10-20 20:10:12 +02:00
*) about;;
2021-10-20 18:17:15 +02:00
esac
exit 0