294 lines
10 KiB
Bash
Executable File
294 lines
10 KiB
Bash
Executable File
#!/bin/bash
|
|
# mbxutils: handy utilities for your X11 window manager.
|
|
# Copyright (C) 2021 Daniel Napora <napcok@gmail.com>
|
|
#
|
|
# TODO Logout Dialog postponed
|
|
# TODO Filebrowser standalone postponed
|
|
|
|
|
|
ME=$(basename "$0")
|
|
CNF_DIR="$HOME/.config/mbxutils"
|
|
CNF_FILE="$CNF_DIR/$ME.conf"
|
|
[ ! -d "$HOME/.config/jgmenu" ] && mkdir -p "$HOME/.config/jgmenu"
|
|
|
|
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
|
|
mbx setvar bgcolor=#252525
|
|
mbx ${1}
|
|
}
|
|
|
|
|
|
[ ! -d "$CNF_DIR" ] && mkdir -p "$CNF_DIR" && cp -r /usr/share/mbxutils/* "$CNF_DIR"/
|
|
if [ ! -f $CNF_FILE ]; then
|
|
cat <<EOF > ${CNF_FILE}
|
|
apps_in=rootmenu
|
|
menu_padding=5
|
|
item_height_factor=200
|
|
font='Noto Sans'
|
|
font_size=13
|
|
bgcolor=#252525
|
|
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"
|
|
[ "$rgb" -gt 200000 ] && color_sel_bg="#222222 8" color_sel_border="#222222 16" color_title_bg="#222222 8"
|
|
}
|
|
fg "$bgcolor"
|
|
[ "$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:-}
|
|
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
|
|
}
|
|
|
|
appsmenu() {
|
|
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
|
|
if [[ $apps_in == "submenu" ]]
|
|
then
|
|
cat <<EOF > $HOME/.config/jgmenu/prepend.csv
|
|
@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>
|
|
. ~/.config/mbxutils/inc/favorites.csv
|
|
Applications,^checkout(apps),applications-other
|
|
. ~/.config/mbxutils/inc/m_after_apps.csv
|
|
^sep()
|
|
Logout dialog,mb-jgtools mblogout,system-shutdown
|
|
Preferences,^pipe(mbx-preferences appsmenu),settings
|
|
Preferences,mbx-preferences appsmenu st,settings
|
|
^sep()
|
|
About <b>mbxutils</b>,mbx
|
|
^tag(apps)
|
|
EOF
|
|
else
|
|
cat <<EOF > $HOME/.config/jgmenu/prepend.csv
|
|
@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>
|
|
|
|
. ~/.config/mbxutils/inc/favorites.csv
|
|
^sep(Applications)
|
|
EOF
|
|
cat <<EOF > $HOME/.config/jgmenu/append.csv
|
|
. ~/.config/mbxutils/inc/m_after_apps.csv
|
|
^sep()
|
|
Logout dialog,mb-jgtools mblogout,system-shutdown
|
|
Preferences,^pipe(mbx-preferences appsmenu),settings
|
|
Preferences,mbx-preferences appsmenu st,settings
|
|
^sep()
|
|
About <b>mbxutils</b>,mbx
|
|
|
|
EOF
|
|
fi
|
|
configure
|
|
jgmenu --config-file=${CONFIG_FILE} --no-append 2>/dev/null
|
|
}
|
|
|
|
distrologo() {
|
|
case "$distro" in
|
|
Manjaro) logo=manjaro;;
|
|
Mabox) logo=mabox;;
|
|
Lubuntu) logo=lubuntu;;
|
|
*) logo=tux;;
|
|
esac
|
|
}
|
|
|
|
|
|
|
|
lpanel() {
|
|
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
|
|
|
|
CONFIG_FILE=$(mktemp)
|
|
MENU_ITEMS=$(mktemp)
|
|
trap "rm -f ${CONFIG_FILE} ${MENU_ITEMS}" EXIT
|
|
menu_padding_top=$((menu_padding+item_margin_y+48))
|
|
menu_halign="left"
|
|
distro="${distro:-$OSNAME}"
|
|
distrologo
|
|
configure
|
|
|
|
#${HOSTNAME:-$(hostname)}@${USER}
|
|
cat <<EOF > ${MENU_ITEMS}
|
|
@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>
|
|
. ~/.config/mbxutils/inc/ltop.csv
|
|
^sep(<b>File browser</b>)
|
|
$HOME,^pipe(mbxfiles ~)
|
|
~/.config,^pipe(mbxfiles ~/.config)
|
|
/etc,^pipe(mbxfiles /etc)
|
|
^sep(<b>mbxutils</b>)
|
|
Preferences,^pipe(mbx-preferences lpanel)
|
|
Preferences,mbx-preferences lpanel st
|
|
|
|
. ~/.config/mbxutils/inc/lbottom.csv
|
|
EOF
|
|
jgmenu --config-file=${CONFIG_FILE} --csv-file=${MENU_ITEMS} 2>/dev/null
|
|
}
|
|
|
|
rpanel() {
|
|
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
|
|
CONFIG_FILE=$(mktemp)
|
|
MENU_ITEMS=$(mktemp)
|
|
trap "rm -f ${CONFIG_FILE} ${MENU_ITEMS}" EXIT
|
|
menu_padding_top=$((menu_padding+item_margin_y+48))
|
|
menu_halign="right"
|
|
icon_size=$((font_size*item_height_factor/100-2))
|
|
distro="${distro:-$OSNAME}"
|
|
distrologo
|
|
|
|
configure
|
|
cat <<EOF > ${MENU_ITEMS}
|
|
@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>
|
|
. ~/.config/mbxutils/inc/rtop.csv
|
|
^sep(Right Panel)
|
|
Preferences,^pipe(mbx-preferences rpanel)
|
|
Preferences,mbx-preferences rpanel st
|
|
. ~/.config/mbxutils/inc/rbottom.csv
|
|
EOF
|
|
jgmenu --config-file=${CONFIG_FILE} --csv-file=${MENU_ITEMS} 2>/dev/null
|
|
}
|
|
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')"
|
|
# TODO better menu height calculation
|
|
columns=2
|
|
icon_size=$((font_size*item_height_factor/100-2))
|
|
menu_halign=center
|
|
#menu_padding=8
|
|
menu_width=$((twidth+menu_padding*2))
|
|
item_height=$((font_size*item_height_factor/100))
|
|
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))
|
|
configure
|
|
cat <<EOF > ${MENU_ITEMS}
|
|
@icon,,${menu_padding},${menu_padding},${twidth},${theight},4,left,top,,,$THUMB
|
|
@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>
|
|
^sep(Utilities)
|
|
Apps menu (main),mbx appsmenu,menu
|
|
Left SidePanel,mbx lpanel,mbx-lpanel
|
|
Right SidePanel,mbx rpanel,mbx-rpanel
|
|
Logout Dialog, mbx
|
|
Quick Filebrowser,mbx files,folder
|
|
Preferences,mbx-preferences about st
|
|
^sep(Manual)
|
|
Configure keybindings,xdg-open https://mbxutils.maboxlinux.org,firefox
|
|
Roadmap
|
|
EOF
|
|
|
|
jgmenu --config-file=${CONFIG_FILE} --csv-file=${MENU_ITEMS} 2>/dev/null
|
|
}
|
|
setvar() { # Może tu niepotrzebnie a tylko w mbx-preferences
|
|
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
|
|
reset) defaults "$2";;
|
|
appsmenu) appsmenu "$2";;
|
|
lpanel) lpanel;;
|
|
rpanel) rpanel;;
|
|
setvar) setvar "$2";;
|
|
*) about;;
|
|
esac
|
|
exit 0
|