Browse Source

initial commit

master
Daniel Napora 12 months ago
parent
commit
0e917ed605
  1. 16
      Makefile
  2. 328
      bin/mbx
  3. 58
      bin/mbxinit
  4. 26
      share/inc/colors.clr

16
Makefile

@ -0,0 +1,16 @@
NAME=mbxutils
VERSION=0.0.1
DIRS=bin share
INSTALL_DIRS=`find $(DIRS) -type d 2>/dev/null`
INSTALL_FILES=`find $(DIRS) -type f 2>/dev/null`
PREFIX?=/usr
install:
for dir in $(INSTALL_DIRS); do mkdir -p $(PREFIX)/$$dir; done
for file in $(INSTALL_FILES); do cp $$file $(PREFIX)/$$file; done
uninstall:
for file in $(INSTALL_FILES); do rm -f $(PREFIX)/$$file; done
rm -r $(PREFIX)/share/$(NAME)

328
bin/mbx

@ -0,0 +1,328 @@
#!/bin/bash
# mbxutils: handy utilities for your X11 window manager.
#
# Copyright (C) 2021 Daniel Napora <napcok@gmail.com>
# mbx
# TODO Preferences standalone
# TODO Logout Dialog postponed
# TODO Filebrowser standalone postponed
ME=$(basename "$0")
CNF_DIR="$HOME/.config/mbxutils"
CNF_FILE="$CNF_DIR/$ME.conf"
[ ! -d "$CNF_DIR" ] && mkdir -p "$CNF_DIR" && cp -r /usr/share/mbxutils/* "$CNF_DIR"/
if [ ! -f $CNF_FILE ]; then
cat <<EOF > ${CNF_FILE}
menu_padding=5
item_height_factor=200
font="Noto Sans"
font_size=12
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"
### [ "$((r*299+g*587+b*114))" -gt 149000 ] && echo "#111111" || echo "#EEEEEE"
}
###fgcolor=$(fg $bgcolor)
fg "$bgcolor"
#KOLOR FG
### DDEV ONLY
rgb() {
r=$(printf "%d" 0x${1:1:2}) g=$(printf "%d" 0x${1:3:2}) b=$(printf "%d" 0x${1:5:2})
echo "rgb($r, $g, $b)"
}
color=$(rgb $fgcolor)
background=$(rgb $bgcolor)
function luminance()
{
R=$( echo $1 | awk -F, '{print substr($1,5)}' )
G=$( echo $1 | awk -F, '{print $2}' )
B=$( echo $1 | awk -F, '{n=length($3); print substr($3,1,n-1)}' )
echo "scale=4
rsrgb=$R/255
gsrgb=$G/255
bsrgb=$B/255
if ( rsrgb <= 0.03928 ) r = rsrgb/12.92 else r = e( 2.4 * l((rsrgb+0.055)/1.055) )
if ( gsrgb <= 0.03928 ) g = gsrgb/12.92 else g = e( 2.4 * l((gsrgb+0.055)/1.055) )
if ( bsrgb <= 0.03928 ) b = bsrgb/12.92 else b = e( 2.4 * l((bsrgb+0.055)/1.055) )
0.2126 * r + 0.7152 * g + 0.0722 * b" | bc -l
}
lum1=$( luminance $color )
lum2=$( luminance $background )
# compute contrast
function contrast()
{
echo "scale=2
if ( $1 > $2 ) { l1=$1; l2=$2 } else { l1=$2; l2=$1 }
(l1 + 0.05) / (l2 + 0.05)" | bc
}
rel=$( contrast $lum1 $lum2 )
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
# 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 = 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_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
}
mmenu() {
CONFIG_FILE=$(mktemp)
trap "rm -f ${CONFIG_FILE}" EXIT
font_size=${font_size:-12}
echo "${font} ${font_size}px"
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))
#CHujowy HAK
#apps_in_submenu=true
rm -f ~/.config/jgmenu/append.csv
if [[ $apps_in_submenu == true ]]
then
cat <<EOF > $HOME/.config/jgmenu/prepend.csv
@text,,$((menu_padding + 24)),$((menu_padding_top-font_size*item_height_factor/100)),150,20,0,left,top,auto,#000000,<span size="large"></span>
@search,,$((menu_padding + 38)),$((menu_padding + 4)),150,20,2,left,top,auto,#000000 0,<i>type to search</i>
. ~/.config/mbxutils/inc/favorites.csv
$APPS,^checkout(apps),applications-other
. ~/.config/mbxutils/inc/m_after_apps.csv
^sep()
Logout dialog,mb-jgtools mblogout,system-shutdown
Preferences,^pipe($ME preferences mmenu),firefox
^sep(rgb: $rgb)
^sep(rel: $rel)
^tag(apps)
EOF
else
cat <<EOF > $HOME/.config/jgmenu/prepend.csv
@text,,$((menu_padding+20)),$((menu_padding_top-font_size*item_height_factor/100)),150,$((font_size*item_height_factor/100)),0,left,top,auto,#000000,<span size="large"></span>
@search,,$((menu_padding + 38)),$((menu_padding_top-font_size*item_height_factor/100)),150,$((font_size*item_height_factor/100)),2,left,top,auto,#000000,<i>▸<u> type to search </u></i>
. ~/.config/mbxutils/inc/favorites.csv
EOF
cat <<EOF > $HOME/.config/jgmenu/append.csv
. ~/.config/mbxutils/inc/m_after_apps.csv
^sep()
Preferences,^pipe($ME preferences mmenu),firefox
Logout dialog,mb-jgtools mblogout,system-shutdown
^sep(rgb: $rgb)
^sep(rel: $rel)
EOF
fi
configure
jgmenu --config-file=${CONFIG_FILE} --no-append 2>/dev/null
}
lpanel() {
CONFIG_FILE=$(mktemp)
MENU_ITEMS=$(mktemp)
trap "rm -f ${CONFIG_FILE} ${MENU_ITEMS}" EXIT
menu_halign="left"
configure
cat <<EOF > ${MENU_ITEMS}
. ~/.config/mbxutils/inc/ltop.csv
^sep(<b>File browser</b>)
/etc,^pipe(mbxfiles /etc)
~/.config,^pipe(mbxfiles ~/.config)
^sep(<b>mbxutils</b>)
Left panel,,firefox
. ~/.config/mbxutils/inc/lbottom.csv
EOF
jgmenu --config-file=${CONFIG_FILE} --csv-file=${MENU_ITEMS} 2>/dev/null
}
rpanel() {
CONFIG_FILE=$(mktemp)
MENU_ITEMS=$(mktemp)
trap "rm -f ${CONFIG_FILE} ${MENU_ITEMS}" EXIT
menu_halign="right"
icon_size=$((font_size*item_height_factor/100-2))
configure
cat <<EOF > ${MENU_ITEMS}
. ~/.config/mbxutils/inc/rtop.csv
^sep(Right Panel)
Right Panel,,terminal
. ~/.config/mbxutils/inc/rbottom.csv
EOF
jgmenu --config-file=${CONFIG_FILE} --csv-file=${MENU_ITEMS} 2>/dev/null
}
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
}
preferences() {
# if $1 brak then standalone
PAR="${ME} $1"
out+=("^sep(mbxutils Global Settings)")
out+=("^sep(rgb: $rgb)")
out+=("^sep(rel: $rel)")
out+=("^sep(Appearance)")
out+=("<tt>$(printf "%-15s %20s" "Font:" "[<b>$font</b>]")</tt>,^pipe($ME fonts $1)")
out+=("<tt>$(printf "%-15s %20s" "Font size (px):" "[<b>$font_size</b>]")</tt>,^checkout(fontsize)")
out+=("<tt>$(printf "%-15s %20s" "Line height:" "[<b>$item_height_factor%</b>]")</tt>,^checkout(lineheight)")
out+=("<tt>$(printf "%-15s %20s" "BGcolor:" "[<b>$bgcolor</b>]")</tt>,^checkout(bgcolor)")
out+=("^sep(Other)")
out+=("<tt>$(printf "%-15s %20s" "Terminal:" "[<b>$terminal</b>]")</tt>,^checkout(terminal),terminal")
out+=("<tt>$(printf "%-15s %20s" "File Manager:" "[<b>$filemanager</b>]")</tt>,^checkout(filemanager)")
#out+=("<tt>$(printf "%-15s %20s" "Margin (px):" "[<b>$margin_xy</b>]")</tt>,^checkout(margin)")
out+=("^sep()")
out+=("Edit config file,xdg-open $CNF_FILE")
out+=("Open config dir,xdg-open $CNF_DIR")
#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)")
out2+=("Pick color from screen")
colors="$CNF_DIR/inc/colors.clr"
while read -r color
do
fg $color
out2+=("<tt><span bgcolor='$color' fgcolor='$fgcolor'><sub> </sub>$color<sup> $rgb</sup></span></tt>,mbx setvar bgcolor='$color';$PAR fixed")
done < "$colors"
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 [[ -z $1 ]]; then
echo "standalone"
exit 0
else
printf '%s\n' "${out[@]}"
printf '%s\n' "${out2[@]}"
fi
}
fonts(){
PAR="${ME} $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
}
case "$1" in
mmenu) mmenu "$2";;
lpanel) lpanel;;
rpanel) rpanel;;
preferences) preferences "$2";;
fonts) fonts "$2";;
setvar) setvar "$2";;
*);;
esac
exit 0

58
bin/mbxinit

@ -0,0 +1,58 @@
#!/bin/bash
# mbxinit - initialize/update config files needed by mbxutils
CNF_DIR="$HOME/.config/mbxutils"
CNF_FILE="$CNF_DIR/mbx.conf"
[ ! -d "$CNF_DIR" ] && mkdir -p "$CNF_DIR" && cp -r /usr/share/mbxutils/* "$CNF_DIR"/
mkdir -p "$CNF_DIR"/inc
check_fonts() {
search_fonts=(Ubuntu "DejaVu Serif" "Autour One" "Noto Sans" "Noto Sans Light" "JetBrains Mono" "Droid Sans" Roboto Helvetica Cantarell)
while read -r x
do
if ( dlm=$'\x1F' ; IFS="$dlm" ; [[ "$dlm${search_fonts[*]}$dlm" == *"$dlm${x}$dlm"* ]] ) ; then
fonts+=("${x}")
fi
done < <(fc-list| cut -d: -f2|cut -d, -f1,2 |tr , '\n'|sort|uniq)
printf '%s\n' "${fonts[@]}" > "$CNF_DIR"/inc/fonts.inc
}
check_terminals() {
search_terminals=(terminator lxterminal xfce4-terminal alacritty konsole qterminal )
for i in "${search_terminals[@]}"
do
if hash ${i} 2>/dev/null; then
terminals+=("${i}")
fi
done
printf '%s\n' "${terminals[@]}" > "$CNF_DIR"/inc/terminals.inc
}
check_browsers() {
search_browsers=(firefox chromium vivaldi opera midori)
for i in "${search_browsers[@]}"
do
if hash ${i} 2>/dev/null; then
browsers+=("${i}")
fi
done
printf '%s\n' "${browsers[@]}" > "$CNF_DIR"/inc/browsers.inc
}
check_file_managers() {
search_file_managers=(xdg-open pcmanfm thunar caja nautilus dolphin)
for i in "${search_file_managers[@]}"
do
if hash ${i} 2>/dev/null; then
file_managers+=("${i}")
fi
done
printf '%s\n' "${file_managers[@]}" > "$CNF_DIR"/inc/file_managers.inc
}
check_fonts
check_terminals
check_browsers
check_file_managers

26
share/inc/colors.clr

@ -0,0 +1,26 @@
#FFFFFF
#FFF79C
#FED883
#FEBE40
#F8C09D
#F5F6E8
#EF937E
#EEEEEE
#EE8EB4
#EC7523
#EA676C
#DD94C1
#D0E2EE
#D0AD9A
#556B2F
#432355
#3b3b3b
#3A4D5C
#311A12
#252525
#1D5C87
#181818
#143441
#111111
#0F2437
#000000
Loading…
Cancel
Save