more on conky handling

This commit is contained in:
Daniel Napora 2023-01-07 23:10:48 +01:00
parent 997222b9ab
commit 661a120efb
4 changed files with 276 additions and 46 deletions

View File

@ -34,6 +34,9 @@ case "$LANG" in
NO_CONKY_RUNNING="Brak uruchomionych Conky"
RUN_CONKY_SESSION="Uruchom zapisaną sesję"
MOVEABLEALL="Ustaw wszystkie (<i>przeciągaj</i>)..."
NOT_FULLY_SUPPORTED="Częściowo wspierane..."
UNSUPPORTED="Conky - częściowo wspierane"
UNSUPPORTED_START="kliknij aby uruchomić"
GENERATEFROMWP="Generuj z kolorów tapety"
LIGHTBG="Jasne tło"
DARKBG="Ciemne tło"
@ -74,6 +77,9 @@ case "$LANG" in
NO_CONKY_RUNNING="No Conky running"
RUN_CONKY_SESSION="Run Conky session"
MOVEABLEALL="Make moveable all..."
NOT_FULLY_SUPPORTED="Partially supported"
UNSUPPORTED="partially supported Conkies"
UNSUPPORTED_START="click to start"
GENERATEFROMWP="Generate from wallpaper colors"
LIGHTBG="Light Background"
DARKBG="Dark Background"
@ -102,7 +108,7 @@ case "$LANG" in
RUNNING_CONKIES="Running Conkys"
STOP_ALL="Stop All"
MORECONKIES="More Conkies Available"
CLICKTOSTART="click to start"
CLICKTOSTART="...click to start"
STARTALL="Start all"
RESET="Reset"
RESETALL="Reset all to defaults"
@ -155,8 +161,9 @@ if pgrep -af "conky.*mbcolor" >/dev/null; then
# array with running conkies - only filenames with full path
readarray -t running < <(pgrep -af "conky -c " | cut -d' ' -f4)
#array with all supported conkies
for i in "$CONKYDIR"/*.con* "$CONKYDIR"/**/*.con*; do
#array with all conkies found
#for i in "$CONKYDIR"/*.con* "$CONKYDIR"/**/*.con*; do
for i in "$CONKYDIR"/*.conkyrc "$CONKYDIR"/*.conf "$CONKYDIR"/**/*.conkyrc "$CONKYDIR"/**/*.conf; do
if [[ "$i" == *mbcolor* ]];then
supported+=("$i")
else
@ -170,13 +177,17 @@ if pgrep -af "conky.*mbcolor" >/dev/null; then
notstarted=($(echo ${running[@]} ${supported[@]} ${unsupported[@]} ${unsupported[@]}| tr ' ' '\n' | sort | uniq -u))
notstarted_unsupported=($(echo ${running[@]} ${supported[@]} ${supported[@]} ${unsupported[@]} | tr ' ' '\n' | sort | uniq -u))
RCONKIES="${#running[@]}"
NSCONKIES="${#notstarted[@]}"
ALLSUPP=$(($RCONKIES+$NSCONKIES))
#notify-send.sh "$ALLSUPP" "$RCONKIES $NSCONKIES"
if [[ ${#running[@]} > 0 ]];then
out+=("^sep($RUNNING_CONKIES)")
for c in ${running[@]};do
filename=${c##*/}
name=${filename%%_mb*}
title=${name//_/ }
name2=${name%%.con*}
title=${name2//_/ }
out+=("${title^},^pipe(conkyctl single ${c})")
done
out+=("^sep()")
@ -184,6 +195,7 @@ if pgrep -af "conky.*mbcolor" >/dev/null; then
fi
if [[ ${#notstarted[@]} > 0 ]];then
out+=("^sep($MORECONKIES)")
if [[ "$ALLSUPP" < 15 ]];then
out+=("^sep(<small><i>$CLICKTOSTART</i></small>)")
for c in ${notstarted[@]};do
filename=${c##*/}
@ -195,15 +207,30 @@ if pgrep -af "conky.*mbcolor" >/dev/null; then
out+=("^sep()")
out+=("$STARTALL (${#notstarted[@]}),conkyctl startall;$me")
fi
else # too many conkies - not started go to submenu
out+=("$CLICKTOSTART (${#notstarted[@]}),^checkout(nstarted)")
out2+=("^tag(nstarted)")
for c in ${notstarted[@]};do
filename=${c##*/}
name=${filename%%_mb*}
title=${name//_/ }
out2+=("${title^},conkyctl startone ${c};$me")
done
if [[ ${#notstarted[@]} > 1 ]];then
out2+=("^sep()")
out2+=("$STARTALL (${#notstarted[@]}),conkyctl startall;$me")
fi
fi
fi
if [[ ${#notstarted_unsupported[@]} > 0 ]];then
out+=("^sep()")
out+=("UNSUPPORTED,^checkout(unsup)")
out+=("$NOT_FULLY_SUPPORTED (${#notstarted_unsupported[@]}),^checkout(unsup)")
out2+=("^tag(unsup)")
out2+=("^sep(UNSUPPORTED)")
out2+=("^sep($UNSUPPORTED)")
out2+=("^sep($UNSUPPORTED_START)")
for c in ${notstarted_unsupported[@]};do
filename=${c##*/}
name=${filename%%_mb*}
name=${filename%%.con*}
title=${name//_/ }
out2+=("${title^},conkyctl startone ${c};$me")
done

View File

@ -66,7 +66,7 @@ read MB1 MB2 MBFG<<< "$(grep '^Messages Border ' ${THEMERC})"
out+=("^sep($COLORIZE_PYRADIO)")
#out+=("$START_PYRADIO,terminator --geometry=420x440-20-20 -e pyradio")
out+=("$INFO,notify-send.sh -i music '$INFO_HEAD' '$INFO_TXT' -t 20000")
out+=("$INFO,notify-send.sh -i music '$INFO_HEAD' '$INFO_TXT' -t 20000")
out+=("^sep(<i>$GENERATEFROMWP</i>)")
out+=("$LIGHTBG,w2theme pyradio light;$me")
out+=("$DARKBG,w2theme pyradio dark;$me")
@ -113,13 +113,13 @@ read MB1 MB2 MBFG<<< "$(grep '^Messages Border ' ${THEMERC})"
out+=("^sep($CONFIG_AND_DOCS)")
#out+=("PyRadio README,cat /usr/share/doc/pyradio/README.html| yad --html --no-buttons --no-escape --height=800 --width=600")
out+=(" $README,xdg-open /usr/share/doc/pyradio/README.html")
out+=(" $MANUAL,^term(man pyradio)")
out+=(" $README,xdg-open /usr/share/doc/pyradio/README.html")
out+=(" $MANUAL,^term(man pyradio)")
out+=("^sep()")
out+=(" $EDITCONF,xdg-open ~/.config/pyradio/config")
out+=(" $EDITSTATIONS,xdg-open ~/.config/pyradio/stations.csv")
out+=(" $EDITCONF,xdg-open ~/.config/pyradio/config")
out+=(" $EDITSTATIONS,xdg-open ~/.config/pyradio/stations.csv")
out+=("^sep()")
out+=(" $CONFIGDIR,^pipe(jgbrowser ~/.config/pyradio)")
out+=(" $CONFIGDIR,^pipe(jgbrowser ~/.config/pyradio)")
### RUN

View File

@ -155,28 +155,28 @@ pos () {
### jak po środku to wyzerować gaps
case "$1" in
top_left|top_right|bottom_left|bottom_right)
sd "gap_x .*=.*,$" "gap_x = ${def_x}," ${2}
sd "gap_y .*=.*,$" "gap_y = ${def_y}," ${2}
sd "gap_x .*=.*," "gap_x = ${def_x}," ${2}
sd "gap_y .*=.*," "gap_y = ${def_y}," ${2}
;;
top_middle|bottom_middle)
sd "gap_x .*=.*,$" "gap_x = 0," ${2}
sd "gap_y .*=.*,$" "gap_y = ${def_y}," ${2}
sd "gap_x .*=.*," "gap_x = 0," ${2}
sd "gap_y .*=.*," "gap_y = ${def_y}," ${2}
;;
middle_left|middle_right)
sd "gap_x .*=.*,$" "gap_x = ${def_x}," ${2}
sd "gap_y .*=.*,$" "gap_y = 0," ${2}
sd "gap_x .*=.*," "gap_x = ${def_x}," ${2}
sd "gap_y .*=.*," "gap_y = 0," ${2}
;;
middle_middle)
sd "gap_x .*=.*,$" "gap_x = 0," ${2}
sd "gap_y .*=.*,$" "gap_y = 0," ${2}
sd "gap_x .*=.*," "gap_x = 0," ${2}
sd "gap_y .*=.*," "gap_y = 0," ${2}
;;
esac
}
gap_x () {
sd "gap_x .*=.*,$" "gap_x = ${1}," ${2}
sd "gap_x .*=.*," "gap_x = ${1}," ${2}
}
gap_y () {
sd "gap_y .*=.*,$" "gap_y = ${1}," ${2}
sd "gap_y .*=.*," "gap_y = ${1}," ${2}
}
setpos () {
filename=${1##*/}
@ -310,6 +310,7 @@ saveposall () {
while read -r WIN_ID b c X Y rest
do
conffile=$(xprop -id $WIN_ID |grep WM_COMMAND |cut -d'"' -f6)
if [[ "$conffile" = *"mbcolor"* ]];then
pos top_left ${conffile}
#notify-send.sh -t 10000 "${X} ${Y}" "${conffile}"
# improve conky margin calculation here: gap = border_width + border_inner_margin + border_outer_margin
@ -317,6 +318,7 @@ saveposall () {
((Y=Y+17))
gap_x ${X} ${conffile}
gap_y ${Y} ${conffile}
fi
done < <(wmctrl -lpG | grep '1 0 ')
makedesktoptypeall
}
@ -345,6 +347,10 @@ resetcolorsone () {
languages () {
case "$LANG" in
pl*)
UNSUPPORTED="częściowo wspierane!!!"
OLD_SYNTAX_DETECTED="<b><span bgcolor='yellow'> stara składnia! </span></b> wykryta..."
CONVERT_OLD="Czy spróbować skonwertować?"
CONVERT_OLD_TRY="Tak, spróbuj konwertować"
POSITION="Pozycja"
MAKEMOVEABLE="Ustaw wszystkie (<i>poprzez przeciąganie</i>)..."
MARKNEWPOS="Nowa pozycja (<i>zaznacz na ekranie</i>)..."
@ -401,6 +407,10 @@ languages () {
MOUNTPOINTS="Dyski (punkty montowania)"
;;
es*)
UNSUPPORTED="partially supported!!!"
OLD_SYNTAX_DETECTED="<b><span bgcolor='yellow'> old syntax!!! </span></b> detected..."
CONVERT_OLD="Try to convert to new syntax?"
CONVERT_OLD_TRY="Yes, try to convert"
POSITION="Position"
MAKEMOVEABLE="Make moveable all..."
MARKNEWPOS="New position (<i>mark on the screen</i>)..."
@ -457,6 +467,10 @@ languages () {
MOUNTPOINTS="Discs (mount points)"
;;
*)
UNSUPPORTED="partially supported!!!"
OLD_SYNTAX_DETECTED="<b><span bgcolor='yellow'> old syntax!!! </span></b> detected..."
CONVERT_OLD="Try to convert to new syntax?"
CONVERT_OLD_TRY="Yes, try to convert"
POSITION="Position"
MAKEMOVEABLE="Make moveable all..."
MARKNEWPOS="New position (<i>mark on the screen</i>)..."
@ -516,10 +530,15 @@ languages () {
}
single () {
unset NOT_SUPPORTED OLD_SYNTAX
languages
filename=${1##*/}
name=${filename%%_mb*}
title=${name//_/ }
grep -q "conky.text" "$1" && : || OLD_SYNTAX="true"
# breaks mbclr color picking from contextmenu, leave it as "colorizer-conky -s" for now
if [[ "$2" == "s" ]];then
me="none none"
@ -560,11 +579,18 @@ single () {
if [[ "$filename" == *"mbcolor"* ]];then
out+=("^sep(Conky: [ ${title^} ])")
else
NOT_SUPPORTED="true"
out+=("^sep(Conky: [ ${title^} ]")
out+=("^sep(<span bgcolor='red'> unsupported!!! </span>)")
out+=("^sep(<span bgcolor='red' fgcolor='white'> ${UNSUPPORTED} </span>)")
fi
if [[ "$OLD_SYNTAX" = "true" ]];then
out+=("$OLD_SYNTAX_DETECTED,^checkout(oldsyntax)")
out2+=("^tag(oldsyntax)")
out2+=("^sep($CONVERT_OLD)")
out2+=("\"\"\"$CONVERT_OLD_TRY\"\"\",conkyctl convert_from_old ${1}")
#notify-send.sh "Plik" "${1}"
else
out+=(" $POSITION,^checkout(position)")
if [[ "$1" =~ "etwork_mbcolor" ]]; then
out+=("$NOT_WORKING,conkyctl netdevice")
@ -598,8 +624,11 @@ single () {
for i in 0 10 20 30 40 60 80 100 120 140 160 180 200 220 240 260 280 300 320 340 360; do
out3+=("${i},conkyctl gap_y ${i} ${1};$me")
done
if [[ "$NOT_SUPPORTED" != "true" ]];then
out2+=("^sep()")
out2+=(" $MAKEMOVEABLE,conkyctl makemoveableall")
fi
if [[ "$1" =~ "logo_mbcolor" ]]; then
read LSIZE <<< "$(grep minimum_height ${1} | cut -d'=' -f2 | cut -d"," -f1)"
@ -690,12 +719,16 @@ single () {
fi
out+=("$TRANSPARENT [ <b>$WINTRANS</b> ],^checkout(transsingle)")
if [[ "$WINCLR" != "#" ]];then
if [ "$WINTRANS" == false ];then
out+=("<small><span bgcolor='$WINCLR'> </span><span ${BG} fgcolor='$WINCLR'> AbCd </span></small> $BACKGROUND,^pipe(mbclr '$WINCLR' conkyctl win_bgcolor '${BACKGROUND}' '$me' ${1})")
out+=("^sep()")
else
out+=("<small><span bgcolor='$WINCLR'> transparent </span></small> $BACKGROUND,^pipe(mbclr '$WINCLR' conkyctl win_bgcolor '${BACKGROUND}' '$me' ${1})")
fi
out+=("^sep()")
fi
fi
if [[ "$1" != *"logo_mbcolor"* ]]; then
[[ "$CLR" != "#" ]] && out+=("<small><span bgcolor='$CLR'> </span><span ${BG} fgcolor='$CLR'> <b>AbCd</b> </span></small> $DEFCOLOR,^pipe(mbclr '$CLR' conkyctl default_color '${DEFCOLOR}' '$me' ${1})")
@ -742,7 +775,7 @@ single () {
out2+=("2,conkyctl stippled_borders 2 ${1};$me")
out2+=("3,conkyctl stippled_borders 3 ${1};$me")
out2+=("4,conkyctl stippled_borders 4 ${1};$me")
fi #OLD SYNTAX CHECK
out+=("^sep()")
out+=(" $EDIT ${title^},xdg-open ${1}")
out+=("北 $RELOAD ${title^},conkyctl restartone ${1}")
@ -844,7 +877,7 @@ contextmenu () {
mkconfigfile
if [[ "$OLD_SYNTAX" != "true" ]];then
echo "color_menu_bg_to=${WINCLR} 100" >> ${CONFIG_FILE}
TXTCOLOR=$(pastel textcolor ${WINCLR}|pastel format hex)
#notify-send.sh "TXTCOLOR" "${TXTCOLOR} ${menu_gradient_pos}"
@ -875,7 +908,7 @@ contextmenu () {
echo "color_sep_fg=${CLR} 10" >> ${CONFIG_FILE}
echo "font=${FONT} 10" >> ${CONFIG_FILE}
fi
cat <<EOF > ${MENU_ITEMS}
$(printf '%s\n' "${out[@]}")
$(printf '%s\n' "${out2[@]}")
@ -1186,6 +1219,14 @@ newcolorscheme () {
savecolorscheme "${themename}" "${1}"
fi
}
convert_from_old () {
# try to convert from old syntax to new by convert.lua script
#notify-send.sh "Convert func" "${1}"
kill ${1}
convert.lua ${1}
sleep 1
startone ${1}
}
case "$1" in
transparent_all) transparent_all "$2";;
@ -1232,5 +1273,6 @@ case "$1" in
settheme_all) settheme_all "$2";;
newcolorscheme) newcolorscheme "$2";;
netdevice) netdevice ;;
convert_from_old) convert_from_old "$2";;
*) : ;;
esac

161
bin/convert.lua Executable file
View File

@ -0,0 +1,161 @@
#! /usr/bin/lua
local usage = [[
Usage: convert.lua old_conkyrc [new_conkyrc]
Tries to convert conkyrc from the old v1.x format to the new, lua-based format.
Keep in mind that there is no guarantee that the output will work correctly
with conky, or that it will be able to convert every conkyrc. However, it
should provide a good starting point.
Although you can use this script with only 1 arg and let it overwrite the old
config, it's suggested to use 2 args so that the new config is written in a new
file (so that you have backup if something went wrong).
Optional: Install dos2unix. We will attempt to use this if it is available
because Conky configs downloaded from Internet sometimes are created on DOS/Windows
machines with different line endings than Conky configs created on Unix/Linux.
For more information about the new format, read the wiki page
<https://github.com/brndnmtthws/conky/wiki>
]];
local function quote(s)
if not s:find("[\n'\\]") then
return "'" .. s .. "'";
end;
local q = '';
while s:find(']' .. q .. ']', 1, true) do
q = q .. '=';
end;
return string.format('[%s[\n%s]%s]', q, s, q);
end;
local bool_setting = {
background = true, disable_auto_reload = true, double_buffer = true, draw_borders = true,
draw_graph_borders = true, draw_outline = true, draw_shades = true, extra_newline = true,
format_human_readable = true, no_buffers = true, out_to_console = true,
out_to_wayland = true,
out_to_ncurses = true, out_to_stderr = true, out_to_x = true, override_utf8_locale = true,
own_window = true, own_window_argb_visual = true, own_window_transparent = true,
short_units = true, show_graph_range = true, show_graph_scale = true,
times_in_seconds = true, top_cpu_separate = true, uppercase = true, use_xft = true,
draw_blended = true, forced_redraw = true
};
local num_setting = {
border_inner_margin = true, border_outer_margin = true, border_width = true,
cpu_avg_samples = true, diskio_avg_samples = true, gap_x = true, gap_y = true,
imlib_cache_flush_interval = true, imlib_cache_size = true,
max_port_monitor_connections = true, max_text_width = true, max_user_text = true,
maximum_width = true, mpd_port = true, music_player_interval = true, net_avg_samples = true,
own_window_argb_value = true, pad_percents = true, stippled_borders = true,
text_buffer_size = true, top_name_width = true, total_run_times = true,
update_interval = true, update_interval_on_battery = true, xftalpha = true,
xinerama_head = true,
};
local split_setting = {
default_bar_size = true, default_gauge_size = true, default_graph_size = true,
minimum_size = true
};
local colour_setting = {
color0 = true, color1 = true, color2 = true, color3 = true, color4 = true, color5 = true,
color6 = true, color7 = true, color8 = true, color9 = true, default_color = true,
default_outline_color = true, default_shade_color = true, own_window_colour = true
};
local function alignment_map(value)
local map = { m = 'middle', t = 'top', b = 'bottom', r = 'right', l = 'left' };
if map[value] == nil then
return value;
else
return map[value];
end;
end;
local function handle(setting, value)
setting = setting:lower();
if setting == '' then
return '';
end;
if split_setting[setting] then
local x, y = value:match('^(%S+)%s*(%S*)$');
local ret = setting:gsub('_size', '_width = ') .. x .. ',';
if y ~= '' then
ret = ret .. ' ' .. setting:gsub('_size', '_height = ') .. y .. ',';
end;
return '\t' .. ret;
end;
if bool_setting[setting] then
value = value:lower();
if value == 'yes' or value == 'true' or value == '1' or value == '' then
value = 'true';
else
value = 'false';
end;
elseif not num_setting[setting] then
if setting == 'alignment' and value:len() == 2 then
value = alignment_map(value:sub(1,1)) .. '_' .. alignment_map(value:sub(2,2));
elseif colour_setting[setting] and value:match('^[0-9a-fA-F]+$') then
value = '#' .. value;
elseif setting == 'xftfont' then
setting = 'font';
end;
value = quote(value);
end;
return '\t' .. setting .. ' = ' .. value .. ',';
end;
local function convert(s)
local setting, comment = s:match('^([^#]*)#?(.*)\n$');
if comment ~= '' then
comment = '--' .. comment;
end;
comment = comment .. '\n';
return handle(setting:match('^%s*(%S*)%s*(.-)%s*$')) .. comment;
end;
local input;
local output;
if conky == nil then --> standalone program
-- 1 arg: arg is input and outputfile
-- 2 args: 1st is inputfile, 2nd is outputfile
-- 0, 3 or more args: print usage to STDERR and quit
if #arg == 1 or #arg == 2 then
if os.execute('command -v dos2unix 2>&1 >/dev/null') == 0 then
os.execute('dos2unix ' .. arg[1]);
end
input = io.input(arg[1]);
else
io.stderr:write(usage);
return;
end;
else
-- we are called from conky, the filename is the first argument
input = io.open(..., 'r');
end;
local config = input:read('*a');
input:close();
local settings, text = config:match('^(.-)TEXT\n(.*)$');
local converted = 'conky.config = {\n' .. settings:gsub('.-\n', convert) .. '};\n\nconky.text = ' ..
quote(text) .. ';\n';
if conky == nil then
if #arg == 2 then
output = io.output(arg[2]);
else
output = io.output(arg[1]);
end
output:write(converted);
output:close();
else
return assert(load(converted, 'converted config'));
end;