What is "cr" in the usage of the gears.shape.rounded_rect, and how can I use this to alter the shape of naughty.notify?
I am attempting to reshape a naughty.notify notification from a rectangle to a rectangle with rounded corners. Here I'm told that the shape argument takes a gears.shape
argument—so I look here to see how to use gears.shape.rounded_rect
. Every example shows something like this: shape.rounded_rect(cr, 70, 70, 10
, but the only place I can find that gives any information about what cr
is says "cr: A cairo content".
What is a cairo content?
This is the code I'm using:
naughty.notify({ text = "Monitor Test", ontop = true, position = "bottom_left",
shape = gears.shape.rounded_rect(cr, 70, 20, 5),
opacity = .95})
Naturally, I get an error when restarting Awesome, because cr
isn't anything. I've tried everything from a number to cr:fill, but I just don't know what's supposed to go there.
Does anyone?
Solution 1:
Cairo is a 2D graphic library used by Awesome. You might want to have a look here
Solution 2:
I've search for this quite a lot and didn't find an answer that can easily be put to use. ploth's link is a really good read. The easy answer is that anywhere that you can set shape
, you can pass a function and call the shape you want. The function you pass to shape
will receive (cr, width, height)
and you can pass those to the shape you want. For example:
wibox.container.background(widget, "#000", function(cr, width, height)
gears.shape.partially_rounded_rect(cr, width, height, false, true, true, false, 30)
end)
Hope this helps.
Solution 3:
The answer is, define a function like this, which ill have cr
as a placeholder:
example:
local new_shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, 2)
end
Then just use new_shape
as shape. (cr
is defined on the function signature above, line 1, so it is already defined in line 2, and will be filled with the correct value by the callback when new_shape
is called. You don't define it in rc.lua
yourself, just leave it empty.)
use new_shape like this:
local noti = naughty.notify {
position = "top_middle",
height = 20,
width = 70,
timeout = 1,
shape = new_shape, --SEE HERE
bg="#333333",
fg="#ffffff",
text = "TEST",
}