On 22.08.2012 11:57, Daniel wrote:
> Trying to migrate old cairo stuff to lgi.cairo...
>
> cairo = require("lgi").cairo
>
> 1) This is to give mplayer an icon, but it seems to do nothing now
> (but no error):
>
> { rule_any = { class = { "MPlayer" } },
> properties = { icon = cairo.ImageSurface.create_from_png(
> "/tmp/Applications-mplayer.png") }
> },
Hm, I guess this should crash awesome. :-)
Try this instead:
local do_not_ever_touch_this_variable =
cairo.ImageSurface.create_from_png("/tmp/Applications-mplayer.png")
{ rule_any = { class = { "MPlayer" } },
properties = { icon = do_not_ever_touch_this_variable._native }
},
The _native gives a lightuserdata that the C code expects (it's just a pointer
to a cairo_surface_t). The variable is necessary to make sure that lua's garbage
collector doesn't destroy ImageSurface, because it doesn't see that the result
from _native depends on this to stay alive.
> 2) This should grayscale icons. I used to get the icon by just "c.icon" but
> that gives "attempt to index userdata value", so I dug around and found some
> methods, but I can't seem to get it right; methods are nil, etc. I think I got
> atleast the write_to_png and create_from_png right, but seeing as the above 1)
> didn't work, I don't know...
>
> iconbeingset = false
> client.connect_signal("new",
> function(c)
> c:connect_signal("property::icon",
> function()
> if iconbeingset then return end
> icon = c:client_get_icon()
Uhm, shouldn't this cause errors? There is no client_get_icon.
The userdata that c.icon returns should be sent through gears.surface() to turn
it into a cairo surface. I know, this isn't exactly perfectly user-friendly, but
it works well enough:
icon = gears.surface(c.icon)
> if icon then
> icon:write_to_png("/tmp/.awesome-icon-quite.png")
> io.popen("convert -modulate 50,40,100 /tmp/a
> /tmp/b"):read("*all")
> iconbeingset = true
> c:client_set_icon(cairo.ImageSurface.create_from_png("/tmp/b"))
> iconbeingset = false
> end
> end)
> end)
Hope this helps,
Uli
--
"Every once in a while, declare peace. It confuses the hell out of your enemies"
- 79th Rule of Acquisition
--
To unsubscribe, send mail to [email protected].