Conky, LUA Unicode

Add functionality to your desktop
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Post Reply
User avatar
Bleys
Level 4
Level 4
Posts: 431
Joined: Wed Apr 20, 2022 4:17 am
Location: Essen, Germany

Conky, LUA Unicode

Post by Bleys »

Conky and LUA can handle unicode directly, although conky displays less than LUA could.
I have created a loop in LUA that displays all utf8 characters directly in the Conky window. The last character Conky could display was utf8 11858 (decimal).

The LUA code to display a Unicode directly: utf8.char(dezimal_unicode)

I took screenshots of all screens containing characters that Conky could display and saved them in my drive space.
https://drive.google.com/drive/folders/ ... sp=sharing

a section:
Screen Capture_select-area_20240208221316.jpg
test.lua

Code: Select all

--[[
2023 Bleys


]]


require 'cairo'
require "imlib2"
home_path = os.getenv ('HOME')

function rgb_to_rgba(color,alpha)
if color == nil then color=0xFF0000 end
if alpha == nil then alpha=1 end
	return ((color / 0x10000) % 0x100) / 255., ((color / 0x100) % 0x100) / 255., (color % 0x100) / 255., alpha
end
function draw_bg(cr,color,alpha,typ) -- zeichne Hintergrund Conky Fenster / draw Conky Area Background
    local corner_r=0
    local bg_color=color 

    local bg_alpha=alpha
	local w=conky_window.width
	local h=conky_window.height
	cairo_set_source_rgba(cr,rgb_to_rgba(bg_color,bg_alpha))
	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)	
    if typ==1 then
	    cairo_fill(cr)
    else
        cairo_set_line_width(cr, 3)
        cairo_stroke(cr)
    end
end 
function write_text(cr, x, y, text, f)
--write_text(cr, x, y, text, {})
--font attributes (Schriftattribute zuweisen oder default Werte annehmen)
      local font=f.font or "Noto Sans"
      local size=f.size or 10
      local align=f.align or 'l'
      local bold=f.bold or false
      local ital=f.italic or false
      local color=f.color or "0xffffff"
      local slant=CAIRO_FONT_SLANT_NORMAL
      if ital then slant=CAIRO_FONT_SLANT_ITALIC end
      local weight=CAIRO_FONT_WEIGHT_NORMAL
      if bold then weight=CAIRO_FONT_WEIGHT_BOLD end

--Text Size (Textgröße für die Plazierung bestimmen.)
      local x_a=0
      local y_a=0
      local te = cairo_text_extents_t:create()
      tolua.takeownership(te)
      cairo_select_font_face (cr, font, slant, weight)
      cairo_set_font_size (cr, size)
      cairo_text_extents (cr, text, te)

--Text Position
      if align=='c' then
        x_a = -(te.width/2+te.x_bearing)
        y_a = -(te.height/2+te.y_bearing)
      end
      if align=='r' then
        x_a = -(te.width+te.x_bearing)
      end

--Schadow 1 Pixel (Schatten für den Text um 1 Pixel versetzt)
      cairo_set_source_rgba(cr, rgb_to_rgba(0x000000,1))

      cairo_move_to (cr, x+1+x_a, y+1+y_a)
      cairo_show_text (cr, text)
      cairo_stroke(cr)

-- Now Text on Top (nun den Text oben drauf)
      cairo_set_source_rgba(cr, rgb_to_rgba(color,1))
      cairo_move_to (cr, x+x_a, y+y_a)
      cairo_show_text (cr, text)
      cairo_stroke(cr)
end





function conky_main()
	if conky_window==nil then return end
	local cs=cairo_xlib_surface_create(conky_window.display,conky_window.drawable,conky_window.visual, conky_window.width,conky_window.height)	
	local cr=cairo_create(cs)		
	local updates=conky_parse('${updates}')
	update_num=tonumber(updates)

	if update_num>4 then
        color=0x5a5a5a  alpha=0.9   typ=1
        draw_bg(cr,color,alpha,typ) -- Funktion Hintergrund Conky Bereich / Function Backgrounds Conky Area
        local z = 10 
	    local x = 20
	    local y = 20
        for yy = 0,960,40 do
            for  xx = 10,3660,30 do --change 3660 to less then 1920 for FHD Displays!
                z=z+1
                mychar=utf8.char(z)
                write_text(cr, x+xx,y+yy,mychar, {align="l", size=16})
                write_text(cr, x+xx,y+yy+20,z, {align="l", size=8})
            end
        end
	end
   cairo_surface_destroy(cs)
   cairo_destroy(cr)
end
conkyrc

Code: Select all

--[[
unicode Test
]]
conky.config = {
-- — Conky settings

	background = false,
	update_interval = 1,
	total_run_times = 0,
	no_buffers = true,	
	
-- — Window specifications with Shadow

	own_window = true,
    own_window_transparent = true,
	own_window_hints = 'undecorated,sticky,skip_taskbar,skip_pager,below',

--  end 

	double_buffer = true,
	minimum_width = 3720, minimum_height = 1000, --change 3720 to less then 1920 for FHD Displays
	alignment = 'top_middle',
	
	gap_x = 10,
	gap_y = 10,


-- Lua Load
	lua_load = './test.lua',
	lua_draw_hook_post = 'main',		
};
conky.text = [[

]];

Ryzen 5 5600G, 16GB RAM, 2TB M.2 Crucial P3, Asrock Deskmeet X300, Samsung Odyssey 49", Linux Mint 21
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Conky, LUA Unicode

Post by Logansfury »

Holy Crap:

Image

Look at all the symbols my system isn't displaying!! Can anything be done about it?
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Bleys
Level 4
Level 4
Posts: 431
Joined: Wed Apr 20, 2022 4:17 am
Location: Essen, Germany

Re: Conky, LUA Unicode

Post by Bleys »

Bleys wrote: Thu Feb 08, 2024 5:22 pm Conky and LUA can handle unicode directly, although conky displays less than LUA could.
I have to correct myself. Conky can display all unicode characters that the selected font contains.
Symbola set in the LUA Script and start display at Unidoce Decimal 127744. Full Picture in my Drive. A part:
unicode_symbola.png
Ryzen 5 5600G, 16GB RAM, 2TB M.2 Crucial P3, Asrock Deskmeet X300, Samsung Odyssey 49", Linux Mint 21
Post Reply

Return to “Compiz, Conky, Docks & Widgets”