0

Some context:

I am writing a font-previewing application, and one of the things I have to do very often is change the size of the text. As you can see in the image, someone drags the "Size" slider, and the application has to change the size of all of those pieces of text.

NOTE: keep in mind I am not using beautiful.load_font and these examples are happening in my own text element I wrote, NOT in "wibox/widget/textbox.lua". So no caching happens from there, and I don't do any caching of fonts myself currently.

Initially, I tried to write something like:

    -- in my "draw" function which would be called every time someone would move
    -- the "Size" slider:
    local tf = self.family .. ' ' ..  self.weight .. ' ' .. self.size
    local new_desc = lgi.Pango.FontDescription.from_string(tf)
    text_layout:set_font_description(new_desc)

    cr:update_layout(self._text_layout)
    cr:show_layout(self._text_layout)

Using this was very slow, down to about 10 - 30 fps as I moved my mouse on the "Size" slider. To try to make this faster, I thought about NOT setting the font description on the text_layout every time, but only set it once when the text element was created, and try to only change the size every time I had to redraw.

So I read the Pango docs, and tried this:

when the text element is created:

    local ctx = lgi.PangoCairo.font_map_get_default():create_context()
    local text_layout = lgi.Pango.Layout.new(ctx)
    local typeface_description = font_family .. " " .. font_weight
    local desc = lgi.Pango.FontDescription.from_string(typeface_description)

    text_layout:set_font_description(desc)

    local pango_attrs = lgi.Pango.AttrList.new()
    local pango_size = lgi.Pango.AttrSize.new(font_size * lgi.Pango.SCALE)

    lgi.Pango.AttrList.insert(pango_attrs, pango_size)
    text_layout:set_attributes(pango_attrs)
    self.pango_attrs = pango_attrs

In my "draw" function:

    local pango_size = lgi.Pango.AttrSize.new(self.size * lgi.Pango.SCALE)
    lgi.Pango.AttrList.change(self.pango_attrs, pango_size)

And when I do this, and use "Xephyr" for testing, The application works well until I start moving the "Size" knob. Then, as I move it, the application still works well for 1-3 seconds. Then, I get a blank screen, and I get this in my terminal:

kill: not enough arguments
kill: not enough arguments
Calling callback function on subscribed signal 'TimeChanged' failed: ./wonderful/bar.lua:148: Pango.Attribute: no `format'
Calling callback function on subscribed signal 'TimeChanged' failed: ./apps/RibbonPanel/LateForLunch/layout.lua:49: Pango.Attribute: no `format'
2022-11-20 09:06:50 E: awesome: signal_fatal:497: signal 11, dumping backtrace
awesome(backtrace_get+0x5f) [0x563e0a3984f2]
awesome(+0x1343e) [0x563e0a38243e]
/usr/lib/libc.so.6(+0x38a00) [0x7fbfdcaa3a00]
/usr/lib/libpango-1.0.so.0(pango_attribute_destroy+0xc) [0x7fbfdb10c36c]
/usr/lib/lua/5.1/lgi/corelgilua51.so(+0x12dc2) [0x7fbfdb386dc2]
/usr/lib/lua/5.1/lgi/corelgilua51.so(+0x132a8) [0x7fbfdb3872a8]
/usr/lib/libluajit-5.1.so.2(+0x9ef6) [0x7fbfdccb9ef6]
/usr/lib/libluajit-5.1.so.2(+0xfcd6) [0x7fbfdccbfcd6]
/usr/lib/libluajit-5.1.so.2(+0x16eac) [0x7fbfdccc6eac]
/usr/lib/libluajit-5.1.so.2(+0x174cd) [0x7fbfdccc74cd]
/usr/lib/libluajit-5.1.so.2(lua_pushstring+0x95) [0x7fbfdccd1955]
awesome(+0x1cc21) [0x563e0a38bc21]
/usr/lib/libluajit-5.1.so.2(+0x9ef6) [0x7fbfdccb9ef6]
/usr/lib/libluajit-5.1.so.2(lua_getfield+0xb1) [0x7fbfdccd7d51]
/usr/lib/lua/5.1/lgi/corelgilua51.so(lgi_marshal_access+0x2c) [0x7fbfdb38585c]
/usr/lib/libluajit-5.1.so.2(+0x9ef6) [0x7fbfdccb9ef6]
/usr/lib/libluajit-5.1.so.2(lua_pcall+0xb3) [0x7fbfdcccc873]
/usr/lib/lua/5.1/lgi/corelgilua51.so(+0x82ee) [0x7fbfdb37c2ee]
/usr/lib/libffi.so.8(+0x70d2) [0x7fbfdc7320d2]
/usr/lib/libffi.so.8(+0x7718) [0x7fbfdc732718]
/usr/lib/libglib-2.0.so.0(+0x560a2) [0x7fbfdd1bd0a2]
/usr/lib/libglib-2.0.so.0(g_main_context_dispatch+0x19b) [0x7fbfdd1bc87b]
/usr/lib/libglib-2.0.so.0(+0xac279) [0x7fbfdd213279]
/usr/lib/libglib-2.0.so.0(g_main_loop_run+0x6f) [0x7fbfdd1bbddf]
awesome(main+0x166c) [0x563e0a383eb0]
/usr/lib/libc.so.6(+0x23290) [0x7fbfdca8e290]
/usr/lib/libc.so.6(__libc_start_main+0x8a) [0x7fbfdca8e34a]
awesome(_start+0x25) [0x563e0a382045]

I decided to ask this because it seems to me like the error has something to do with pango_attribute_destroy. I know awesome is using "lgi", which also includes Pango, so my question is: Am I doing something wrong? Or is this a bug in another library like "lgi"?

  • I don't really know yet what is going on, but this is definitely a bug in either Pango (wrong GI information) or LGI. So, in a sense this answers your question, but I will not post this as an answer since it does not feel helpful. – Uli Schlachter Nov 20 '22 at 07:52

0 Answers0