This adds gears.timer.start(timeout, callback) that creates a timer object and
connects a callback to it, all in one go.
Additionally, this adds gears.timer.weak_start(timeout, callback). The weak
version still allows the callback function to be garbage collected and will then
stop the timer.
This was tested with the following code:
require("gears.timer").start(0.3, function()
print("ping")
if collectgarbage("step", 500) then
print("collection done")
error("err")
end
return true end)
require("gears.timer").weak_start(0.1, function()
io.stdout:write(".")
return true
end)
After a full collection cycle, both timers are stopped. The first one is stopped
because of the error() that it generated. The second one is stopped because the
callback function was garbage collected.
Ref: https://github.com/awesomeWM/awesome/issues/216
Signed-off-by: Uli Schlachter <psychon@znc.in>
Connecting to a signal weakly has the same effect as connecting to it strongly,
but it allows the garbage collector to disconnect the signal in case nothing
else references this function.
Signed-off-by: Uli Schlachter <psychon@znc.in>
The whole point of this pcall() is that we do not have unprotected Lua errors,
because those kill awesome. So instead of assert()ing, let's just print a
message.
Signed-off-by: Uli Schlachter <psychon@znc.in>
This uses busted (http://olivinelabs.com/busted/) to implement unit testing.
This is wired up to "make check" and/or "make test".
This commit also adds tests for the more complicated parts of the gears and
wibox.layout libraries.
Signed-off-by: Uli Schlachter <psychon@znc.in>
maximized() used to align the image with (0,0) so that it is shifted to the right or bottom. Most wallpapers are designed from the center, so this behavior is not desired usually. With this commit the wallpaper is centered when no offset is set. To get the old behavior use {x=0, y=0} for the offset parameter.
It doesn't make sense for surface.load_uncached() to load a file without
inserting into the cache. The next "cached" load will have to load it again.
So move cache insertion into surface.load_uncached() and the only thing that
surface.load() does differently is checking if we have a suitable cache entry
before calling load_uncached().
So load_uncached() does the cache insertion and load() reads from the cache.
Signed-off-by: Uli Schlachter <psychon@znc.in>
This makes gears.color() cache patterns in a weak table and returns that cached
pattern when we get called with the same argument again.
To benchmark this change, the following code was used:
local time = require("socket").gettime
function benchmark(func)
local begin = time()
local iter = 0
while time() - begin < 1 do
func()
iter = iter + 1
end
return iter
end
for _, arg in pairs({
"#00aa00",
"solid:#00aa00",
"radial:50,50,10:55,55,30:0,#ff0000:0.5,#00ff00:1,#0000ff",
"linear:1,2:3,4:0,#000000:1,#ffffff",
"png:/home/psychon/Wallpaper/Bars.png",
{ type = "solid", color = "#00aa00" },
{ type = "radial", from = { 50, 50, 10 }, to = { 55, 55, 30 }, stops = { { 0, "#ff0000" }, { 0.5, "#00ff00" }, { 1, "#0000ff" } } },
{ type = "linear", from = { 1, 2 }, to = { 3, 4 }, stops = { { 0, "#000000" }, { 1, "#ffffff" } } },
{ type = "png", file = "/home/psychon/Wallpaper/Bars.png" },
}) do
collectgarbage("collect")
print(benchmark(function() gears.color.create_pattern(arg) end), arg)
end
Before this change (larger numbers are better, this measures how many times we
can create the given pattern per second):
29525 #00aa00
29344 solid:#00aa00
3446 radial:50,50,10:55,55,30:0,#ff0000:0.5,#00ff00:1,#0000ff
4845 linear:1,2:3,4:0,#000000:1,#ffffff
32855 png:/home/psychon/Wallpaper/Bars.png
29883 table: 0x1bb67e0
3868 table: 0x1bb6830
5339 table: 0x1bb6c60
32772 table: 0x1bb6fe0
After this change:
126188 #00aa00
125962 solid:#00aa00
125125 radial:50,50,10:55,55,30:0,#ff0000:0.5,#00ff00:1,#0000ff
125213 linear:1,2:3,4:0,#000000:1,#ffffff
113659 png:/home/psychon/Wallpaper/Bars.png
125586 table: 0x1232680
125249 table: 0x12326d0
125468 table: 0x1232b00
113711 table: 0x1232e80
As you see, this makes some cases about 35 times faster (although I have to
admit that something like this can be expected from such a synthetic benchmark).
Signed-off-by: Uli Schlachter <psychon@znc.in>
Instead of loading files from disk every time we need them, add a cache to
gears.surface as a weak table that maps strings to cairo surfaces.
If this cache should be avoided, there is a new gears.surface.load_uncached()
function which works just like gears.surface.load() worked before.
Signed-off-by: Uli Schlachter <psychon@znc.in>
Before commit 1b2826 in lgi, the get_rgba() function on cairo SolidPatterns was
specified like this:
get_rgba = { ret = cairo.Status,
{ ti.double, dir = 'out' },
{ ti.double, dir = 'out' },
{ ti.double, dir = 'out' } },
The above commit fixed this (without saying so) and the code became:
get_rgba = { ret = cairo.Status,
{ ti.double, dir = 'out' },
{ ti.double, dir = 'out' },
{ ti.double, dir = 'out' },
{ ti.double, dir = 'out' } },
The prototype for the corresponding cairo function is:
cairo_public cairo_status_t
cairo_pattern_get_rgba (cairo_pattern_t *pattern,
double *red, double *green,
double *blue, double *alpha);
As you see, this functions gets four double* as arguments and it will save its
result via those pointers. Old versions of lgi call this function with too few
arguments and this will cause a segmentation fault when cairo dereferences an
invalid pointer.
Signed-off-by: Uli Schlachter <psychon@znc.in>
If a drawable has an opaque background, we don't need pseudo transparency and
thus its content don't change when it is moved. However, when we need pseudo
transparency, then we have to redraw the drawable to apply the new background.
Previously we just always did the redraw. This commit adds a helper function
gears.color.create_opaque_pattern() that analyzes a cairo pattern for
transparency. We use this new function to only redraw-on-move when there is
actual pseudo transparency in effect. Otherwise, this redraw can be skipped.
Signed-off-by: Uli Schlachter <psychon@znc.in>
When no wallpaper exists yet, instead of creating a black image surface which
covers all the screens, just create a surface for the screen which we need. This
means that way less pixels have to be uploaded to the X11 server, which should
be faster.
Signed-off-by: Uli Schlachter <psychon@znc.in>
This allows to use cairo patterns directly for any kind of "color". This makes
it easier to use things which aren't possible through gears.color.
Signed-off-by: Uli Schlachter <psychon@znc.in>
If user changes locale with os.setlocale to a "dirty"
locale (which use comma as decimal separator (not dot), e.g.
hu_HU) `tonumber` will produce "0,6" instead of "0.6"
which causes bad comparision.
Signed-off-by: uzsolt <udvzsolt@gmail.com>
Signed-off-by: Uli Schlachter <psychon@znc.in>
It helps a lot to know which signal does not exist. That should make it a lot
easier to look for the "guily" code without having to resort to the backtrace.
Signed-off-by: Uli Schlachter <psychon@znc.in>
dump_return is no longer local, so debug prefix must be provided
Signed-off-by: Alexander Yakushev <yakushev.alex@gmail.com>
Signed-off-by: Julien Danjou <julien@danjou.info>
Currently it takes `require('lgi.version')`, converts it blindly to
number and compares with another value.
I am using lgi v0.6.1 and that is not convertable to number value,
thus tonumber() returns nil and crashes Awesome.
The fix is to take major and minor numbers only ignoring the rest.
Signed-off-by: Arvydas Sidorenko <asido4@gmail.com>
Signed-off-by: Uli Schlachter <psychon@znc.in>