conky icon indicating copy to clipboard operation
conky copied to clipboard

[Bug]: ${image}s are drawn beneath backgrounds drawn with Cairo

Open IfGremlinThen opened this issue 1 year ago • 1 comments

What happened?

Relatively straightforward issue, which may or may not be a coding error on my end.

My conky.config calls a .lua script that uses cairo to draw a transparent background with rounded corners. That works totally fine, except that while any text is drawn over the background, ${image}s are drawn beneath it (a black background with 0.50 alpha shades the image, and at 1.00 alpha the image completely disappears). I can't figure out if it's an ordering issue or what, but it's one of the biggest issues I have with conky right now.

I've experienced with all available versions of conky: 1.12.2 (the Ubuntu repo version) 1.18.3 (the Debian repo version) 1.19.4 (the latest appimage)

Strangely, when I double-click the 1.19.4 appimage, the ${image} appears fullcolor, as though it's drawn above the background. But if I attempt to launch it from the terminal with exec or just it's path, it's loads with the image beneath the background.

My lua script:

--------------------------------------------------------------------------------
-- Change these settings to affect your background.
-- "corner_r" is the radius, in pixels, of the rounded corners. If you don't want rounded corners, use 0.

corner_r=16

--------------------------------------------------------------------------------
-- Set the colour and transparency (alpha) of your background.

bg_colour=0x000000
bg_alpha=0.66

--------------------------------------------------------------------------------
require 'cairo'
function rgb_to_r_g_b(colour,alpha)
	return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
end

function conky_draw_bg()
	if conky_window==nil then return end
	local w=conky_window.width
	local h=conky_window.height
	local cs=cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, w, h)
	cr=cairo_create(cs)

	cairo_move_to(cr,corner_r,0)
	cairo_line_to(cr,w-corner_r,0)
	cairo_curve_to(cr,w,0,w,0,w,corner_r)
	cairo_line_to(cr,w,h-corner_r)
	cairo_curve_to(cr,w,h,w,h,w-corner_r,h)
	cairo_line_to(cr,corner_r,h)
	cairo_curve_to(cr,0,h,0,h,0,h-corner_r)
	cairo_line_to(cr,0,corner_r)
	cairo_curve_to(cr,0,0,0,0,corner_r,0)
	cairo_close_path(cr)

	cairo_set_source_rgba(cr,rgb_to_r_g_b(bg_colour,bg_alpha))
	cairo_fill(cr)
end

Version

1.19.4

Which OS/distro are you seeing the problem on?

Ubuntu

Conky config

conky.config = {
    -- TRANSPARENCY & ROUNDED CORNERS
    lua_load = '~/.config/conky/draw_bg.lua',
    lua_draw_hook_pre = 'draw_bg',
    own_window_argb_value = 255,
    own_window_argb_visual = true,
    own_window_transparent = true,
    own_window_colour = 'black',

    -- CONKY OUTPUT DESTINATION
    extra_newline = false,         -- Put an extra newline at the end when writing to  stdout.
    background = false,            -- Boolean  value, if true, Conky will be forked to background when started.
    out_to_console = false,        -- When set to true, will output to terminal.
    out_to_ncurses = false,
    out_to_stderr = false,
    out_to_x = true,               -- When set to true, will output to X.

    -- WINDOW POSITION
    alignment = 'top_right',
    gap_x = 16,
    gap_y = 44,
    xinerama_head = 0,             -- for multi monitor setups, select monitor to run on: 0,1,2

    -- WINDOW UPDATE RATE
    update_interval = 2,           -- update interval in seconds
    double_buffer = true,          -- use double buffering (reduces flicker, may not work for everyone)
    total_run_times = 0,           -- Total number of times for Conky to update before quitting.  Zero makes Conky run forever.

    -- WINDOW BORDERS
    border_inner_margin = 0,       -- margin between the border and text in pixels
    border_outer_margin = 3,       -- margin between the border and the edge of the window in pixels
    border_width = 5,
    draw_borders = false,
    stippled_borders = 0,

    -- WINDOW PROPERTIES
    minimum_width = 288,           -- conky will add an extra pixel to this
    maximum_width = 0,
    minimum_height = 0,            -- conky will add an extra pixel to this height
    own_window = true,
    own_window_class = 'Conky',
    own_window_type = 'desktop',   -- values: desktop (background), panel (bar)
    own_window_hints = 'undecorated,below,sticky,skip_taskbar,skip_pager',

    -- TEXT SETTINGS
    color1 = 'white',
    default_color = 'white',       -- regular text
    default_outline_color = 'white',
    default_shade_color = 'white',
    draw_outline = false,          -- black outline around text (not good if text is black)
    draw_shades = false,           -- black shadow on text (not good if text is black)
    font = 'UbuntuMono Nerd Font:size=14',
    format_human_readable = true,  -- If  enabled,  values which are in bytes will be printed in human -- readable format (i.e., KiB, MiB, etc).
    short_units = true,
    uppercase = false,
    use_xft = true,                -- Use Xft (anti-aliased font and stuff).
    xftalpha = 0,

    -- GRAPH SETTINGS
    draw_graph_borders = false,    -- borders around the graph, ex. cpu graph, network down speed graph
    show_graph_range = false,
    show_graph_scale = false,

    -- IMAGE SUPPORT
    draw_blended = false,
    imlib_cache_flush_interval = 250,
    imlib_cache_size = 0,

    -- RESOURCE SETTINGS
    cpu_avg_samples = 2,
    net_avg_samples = 2,
    no_buffers = true,             -- Subtract (file system) buffers from used memory.
    use_spacer = 'none',
}

conky.text = [[
# -- HEADER --------------------------------------------------------------------
${font BebasNeue:size=24}$alignc${time %l:%M%P  %A}${voffset -12}
$font${color white}󰃭  DAY: ${color grey}${time %D} $alignr${color white}󰅐  UP: ${color grey}$uptime_short
Show last backup.
# -- SYSTEM --------------------------------------------------------------------
${voffset 6}${color white}${font BebasNeue:size=16}SYSTEM  ${hr 2}${voffset 2}$font
${color white}󰣚  OS:  ${color grey}${execi 600 cat /etc/os-release | grep PRETTY_NAME | cut -d '"' -f 2}
   ${voffset -3}${font UbuntuMono Nerd Font:size=10}${color white}DE: ${color grey}${execi 600 cinnamon_version=$(cinnamon --version 2>/dev/null); echo "${cinnamon_version:-Unknown}"} $alignr${color white}WM: ${color grey}${execi 600 wmctrl -m | grep "Name:" | awk -F 'Name: ' '{print $2}'}
$font${color white}󰌌  KEY: ${color grey}$keyboard_layout
# -- HEALTH --------------------------------------------------------------------
${voffset 6}${color white}${font BebasNeue:size=16}HEALTH  ${hr 2}${voffset 2}$font
$font${color white}  CPU: ${color grey}$cpu% $color${cpubar 7}
${color white}  RAM: ${color grey}$memperc% $color${membar 7}
   ${voffset -3}${font UbuntuMono Nerd Font:size=10}TOP ${alignr}CPU     RAM       PID
    ${color grey}${top name 1} $alignr${top cpu 1}% ${top mem 1}% ${top pid 1}
    ${top name 2} $alignr${top cpu 2}% ${top mem 2}% ${top pid 2}
    ${top name 3} $alignr${top cpu 3}% ${top mem 3}% ${top pid 3}
# -- STORAGE -------------------------------------------------------------------
${voffset 6}$font${color white}${font BebasNeue:size=16}STORAGE  ${hr 2}${voffset 2}$font
${color white}󰆦  DSK: ${color grey}${fs_used_perc /}% $color${fs_bar 7 /}
${color white}󰆧  PKG: ${color grey}${execi 10 dpkg -l | grep -c '^ii'} $alignr${color white}  TRA: ${color grey}${exec du -sh ~/.local/share/Trash | awk '{print $1}'}
${voffset -3}   ${font UbuntuMono Nerd Font:size=10}${color white}DOC: ${color grey}${execi 10 du -sh ~/Documents/Unsorted | awk '{print $1}'}  ${color white}PIC: ${color grey}${execi 10 du -sh ~/Pictures/Unsorted | awk '{print $1}'}  ${color white}MUS: ${color grey}${execi 10 du -sh ~/Music/Unsorted | awk '{print $1}'}  ${color white}VID: ${color grey}${execi 10 du -sh ~/Videos/Unsorted | awk '{print $1}'}
# -- NETWORK -------------------------------------------------------------------
${voffset 6}${color white}${font BebasNeue:size=16}NETWORK  ${hr 2}${voffset 2}$font
${color white}󰖟  NET:  ${color grey}${execi 5 if ip link show | grep -q "state UP"; then echo "Online"; else echo "Offline"; fi}
${color white}󰌗  LAN:  ${alignr}  ${color grey}${downspeed enp5s0}  ${color white}  ${color grey}${upspeed enp5s0}
${color white}󰖩  WIFI: ${color grey}${execi 5 nmcli general status | awk '$4=="enabled" {print "ON"} $4=="disabled" {print "OFF"}'} ${alignr}${color white}  ${color grey}${downspeed wlo1}  ${color white}  ${color grey}${upspeed wlo1}
${color white}  BLUE: ${color grey}${execi 5 if bluetoothctl paired-devices | grep -q "Device"; then echo "ON"; else echo "OFF"; fi} $alignr${execi 5 bluetoothctl info | awk -F 'Name: ' '/Name:/ {print $2}'}
# -- CURRENTLY PLAYING ---------------------------------------------------------
${voffset 6}$font${color white}${font BebasNeue:size=16}CURRENTLY PLAYING  ${hr 2}${voffset 2}$font
${color white}󰜟  SPK: ${color grey}${execi 10 pacmd list-sinks | grep -m 1 -oP 'device.product.name = "\K[^"]+'} $alignr${color white}  VOL: ${color grey}${pa_sink_volume}%
${execi 10 bash ~/.config/conky/playerctl.sh}

$alignc${color white}${execi 10 playerctl -p "$(playerctl -l | head -n 1)" metadata title | cut -c 1-35}
$alignc${color grey}${execi 10 playerctl -p "$(playerctl -l | head -n 1)" metadata artist | cut -c 1-35}

${if_match "${exec playerctl -l | grep -n 'firefox'}" != ""}${image ~/.config/conky/albumartwork.jpg -p 75,565 -s 170x96}${else}${image ~/.config/conky/albumartwork.jpg -p 110,565 -s 96x96}${endif}
]]

Stack trace

No response

Relevant log output

No response

IfGremlinThen avatar Oct 08 '23 18:10 IfGremlinThen

any progress? I use ${hr conky_window_height} to draw background. And {image} still beneath background.

20NE avatar Dec 03 '23 12:12 20NE

I might be seeing something like this but with text below my lua in the pre script but I need to debug more and make a simple test case so for now i'm just adding a comment to follow the issue

simotek avatar Feb 25 '24 11:02 simotek

Cairo draws in order in which draw functions are called, you're correctly using lua_draw_hook_pre to draw the background before images in text option.

Related code is in draw_stuff in conky.cc, as well as cimlib_render in conky-imlib2.cc.

The issue seems to be that cimlib_render is called from draw_stuff before llua_draw_pre_hook.

Caellian avatar Apr 06 '24 12:04 Caellian

Can you test the fix/tweak-render-order branch and let me know whether it gives you expected results?

git clone -b fix/tweak-render-order [email protected]:brndnmtthws/conky.git
mkdir conky/build && cd conky/build
cmake .. && make
src/conky

Caellian avatar Apr 06 '24 12:04 Caellian

Recreated the bug and confirmed that the PR properly fixes the render order.

Caellian avatar Apr 08 '24 12:04 Caellian