Commit Graph

83 Commits

Author SHA1 Message Date
Daniel Hahler f1598881a4 Merge pull request #537 from psychon/timer-signals
gears.timer: Add start and stop signals (#348)

Closes https://github.com/awesomeWM/awesome/pull/537.
2015-11-05 23:07:31 +01:00
Uli Schlachter a69d901c64 Add some documentation to gears.timer
It feels weird to document the signals like this, but apparently that is the way
this needs to be done.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-11-01 17:08:20 +01:00
Uli Schlachter 112ce3b419 Set the wallpaper more intelligently
Usually users want a wallpaper on all their screens. With the current code, this
resulted in a loop of upload-wallpaper, {download-wallpaper, add-new-part,
upload-wallpaper}*.

Fix this by being more intelligent: Instead of setting the wallpaper
immediately, this now uses gears.timer.delayed_call() to set the wallpaper. All
following modifications which come in before the delayed call runs will still be
part of the current update. This should mean that during startup, there is just
a single upload of a wallpaper.

(The above is what happens if there is no wallpaper yet. If there is already
one, we use :create_similar() and thus should only upload the part of the
wallpaper that changed, but this doesn't really make a difference.)

As a side-effect, the new code no longer draws to the old wallpaper to modify
it, but always creates a copy of it. This means that:

Fixes https://github.com/awesomeWM/awesome/issues/288.
Closes https://github.com/awesomeWM/awesome/pull/530.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-10-26 23:06:32 +01:00
Uli Schlachter b61026310d gears.timer: Add start and stop signals (#348)
This makes the timer emit signals for when it is started and stopped. This does
not add a signal for :again(), because that function just calls the other two
functions and thus already emits start and stop.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-10-18 15:31:52 +02:00
Daniel Hahler 4bffa7e47e doc: fix unintentional rendering as code due to indent 2015-10-14 00:22:26 +02:00
Daniel Hahler 28ffdb050e Merge pull request #454 from psychon/remove_gears.debug.assert
Remove gears.debug.assert

Closes https://github.com/awesomeWM/awesome/pull/454.

Conflicts:
	lib/gears/matrix.lua
2015-09-21 21:16:36 +02:00
Uli Schlachter b134318f19 Use gears.matrix instead of cairo.Matrix everywhere
This has some positive results on the "benchmark test". Each single number is
the best one out of three runs.

Before:
        create wibox: 0.0826502  sec/iter ( 13 iters, 1.157 sec for benchmark)
    update textclock: 0.0186952  sec/iter ( 57 iters, 2.473 sec for benchmark)
  relayout textclock: 0.0158112  sec/iter ( 64 iters, 1.028 sec for benchmark)
    redraw textclock: 0.0015197  sec/iter (662 iters, 1.861 sec for benchmark)

After:
        create wibox: 0.0825672  sec/iter ( 13 iters, 1.154 sec for benchmark)
    update textclock: 0.00378412 sec/iter (277 iters, 4.216 sec for benchmark)
  relayout textclock: 0.00259056 sec/iter (420 iters, 1.09 sec for benchmark)
    redraw textclock: 0.00105128 sec/iter (958 iters, 1.79 sec for benchmark)

We see no significant change in the creation of wiboxes (99.9% compared to
before). Update (20% of the previous run time), relayout (16%) and redraw (69%)
are all sped up by this change.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-09-19 13:38:05 +02:00
Uli Schlachter 34927b187d gears.matrix: Implement matrices in Lua
Instead of going through LGI to call cairo, this now implements the various
matrix operations directly in Lua. The plan is to avoid the overhead that we hit
due to LGI.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-09-19 13:32:12 +02:00
Uli Schlachter 14be909206 Remove gears.debug.assert
Lua provides an assert() function already, so let's just use that.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-09-16 15:01:26 +02:00
actionless 7ae58b3208 doc(lib: gears: surface): more verbose docstring
Closes https://github.com/awesomeWM/awesome/pull/436.
2015-09-07 20:29:57 +02:00
actionless e023fd0640 fix(lib: gears: color): use surface for recolor 2015-09-04 21:09:46 +02:00
actionless 2f340f05ff feat(themes: xresources): recolor layout icons 2015-09-04 21:08:18 +02:00
Uli Schlachter 564fae8934 Merge branch 'add_gears_matrix' 2015-08-23 15:36:55 +02:00
Uli Schlachter 56c22cde77 Merge branch 'widget_context' 2015-08-23 15:33:43 +02:00
Uli Schlachter d122b825ee gears.timer: Fix the traceback on errors
With the second argument being 2, the traceback will not include the error
handling function, but instead end at the actual place of the error.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-08-12 11:17:48 +02:00
Uli Schlachter 16a1ef0f48 Add gears.matrix for working with cairo matrices
Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-08-12 10:38:22 +02:00
Uli Schlachter 74276b3a11 gears.timer: Add a note about GC'ing timers
Ref: https://github.com/awesomeWM/awesome/issues/216

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-08-12 09:54:58 +02:00
Uli Schlachter 0367af2be9 gears.timer: Add simpler ways to start timers
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>
2015-08-12 09:54:55 +02:00
Daniel Hahler e47773933c Bump required lgi version to 0.7.1
Ref: https://github.com/pavouk/lgi/issues/41
Ref: https://github.com/awesomeWM/awesome/pull/392
2015-08-11 19:08:35 +02:00
Daniel Hahler 09dce08fd4 gears.debug: add support for limited depth
This is useful with big tables and might even be necessary to prevent
infinite recursion.

To prevent the latter, the default is 10.

This adds an indicator when `depth` is reached for tables.

    awesome# return require("gears").debug.dump_return(t4, "", 2)
       string " : table: 0x1580130
      1 : table: 0x16951d0
        1 : wibox.widget.base (table) […]
        2 : wibox.widget.base (table) […]
        3 : 4 (number)
        4 : 5 (number)
        5 : foo (string)
      2 : table: 0x16ac790
        1 : table: 0x16951d0 (table) […]
      3 : table: 0x16cc500
        1 : table: 0x16951d0 (table) […]
        2 : table: 0x16ac790 (table) […]"

    awesome# return require("gears").debug.dump_return(t4, "", 1)
       string " : table: 0x1580130
      1 : table: 0x16951d0 (table) […]
      2 : table: 0x16ac790 (table) […]
      3 : table: 0x16cc500 (table) […]"

Closes https://github.com/awesomeWM/awesome/pull/372.
2015-08-01 11:24:35 +02:00
Daniel Hahler c602eb4ff7 Merge pull request #352 from psychon/gears_cache
Add gears.cache: a generic cache which may loose values at any time
2015-07-27 13:58:35 +02:00
Daniel Hahler 68ad2529a4 wibox.widget.base: add __tostring method to widgets
Fixes https://github.com/awesomeWM/awesome/issues/337.
Closes https://github.com/awesomeWM/awesome/pull/341.
2015-07-26 18:17:01 +02:00
Uli Schlachter a239b2cac7 Use gears.cache to replace some other caches
Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-07-25 15:08:00 +02:00
Uli Schlachter 42c913332f Add a generic cache system as gears.cache
Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-07-25 15:07:47 +02:00
Daniel Hahler dc9295d981 gears.timer: use xpcall with timeout and delayed calls
This provides a traceback in case of errors.

Ref: https://github.com/awesomeWM/awesome/issues/301
2015-07-22 13:52:47 +02:00
Uli Schlachter 089ed0e8dd gears.object: Add :weak_connect_signal()
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>
2015-06-25 06:37:04 +02:00
Julian Wollrath 6cc7be512c Remove the *.in from all files.
Signed-off-b: Julian Wollrath <jwollrath@web.de>
2015-06-19 22:33:32 +02:00
Julian Wollrath ca89f0f311 Use LDoc commands to mark parameters as optional in the docs.
Signed-off-by: Julian Wollrath <jwollrath@web.de>
2015-02-28 23:14:15 +01:00
Julian Wollrath 939dab8ba9 Some more doc fixes all over the place.
Signed-off-by: Julian Wollrath <jwollrath@web.de>
2015-02-28 23:14:13 +01:00
Ignas Anikevicius (gns_ank) 00f558ff92 Docs: General work on gears module.
Signed-off-by: Ignas Anikevicius (gns_ank) <anikevicius@gmail.com>
2015-02-28 23:14:11 +01:00
Ignas Anikevicius (gns_ank) 20eeb66541 Docs: Start gears.color refactoring
Signed-off-by: Ignas Anikevicius (gns_ank) <anikevicius@gmail.com>
2015-02-28 23:14:11 +01:00
Daniel Hahler 47ffb1610c doc: improve meta info / structure for gears.timer 2015-02-15 22:30:05 +01:00
Uli Schlachter 7bc4ab0bf7 gears.object: Assert that arguments have the correct type
Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-01-11 11:19:04 +01:00
Uli Schlachter 6fc15f4afd Add and use gears.timer.delayed_call
This function calls a callback at the end of the current main loop iteration.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-01-11 11:19:04 +01:00
Uli Schlachter a36ddb68e1 gears.timer: Don't assert() that no error occured
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>
2015-01-10 16:53:59 +01:00
Uli Schlachter 94e61ec94b timer: Move from C to lua as gears.timer
No API-change (besides the obvious no-longer-a-global-object) intended.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2014-12-06 16:44:04 +01:00
Uli Schlachter 305f148c4b gears.color: Use proper references in the doc comments
Signed-off-by: Uli Schlachter <psychon@znc.in>
2014-09-13 14:20:59 +02:00
Uli Schlachter 5c387f3bd1 gears.color: Add a way to bypass the pattern cache
Signed-off-by: Uli Schlachter <psychon@znc.in>
2014-09-13 14:16:54 +02:00
Uli Schlachter 0dc6b7f724 gears.wallpaper: Make code more readable
by introducing some extra variables that server as some documentation.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2014-08-24 11:54:12 +02:00
Uli Schlachter 1942986468 Merge branch 'patch-1' of git://github.com/SammysHP/awesome 2014-08-24 11:46:13 +02:00
Uli Schlachter ba50e65b5b Add unit tests
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>
2014-08-23 22:09:06 +02:00
SammysHP b6cdccda96 gears.wallpaper: Center maximized if no offset set
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.
2014-06-08 20:18:09 +02:00
Uli Schlachter 96c49e6c6a gears.surface: Handle the cache more intelligently
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>
2014-04-09 21:55:07 +02:00
Emmanuel Lepage Vallee 7349f3b902 Make sure gears.color.create_png_pattern are being repeated 2014-04-08 22:57:05 +02:00
Emmanuel Lepage Vallee 5fdce4d845 Move 'surface_size' to gears.surface and make it public 2014-04-08 22:51:55 +02:00
Uli Schlachter ed6d5e0246 gears.color: Handle nil arguments correctly again
Signed-off-by: Uli Schlachter <psychon@znc.in>
2014-04-03 20:27:45 +02:00
Uli Schlachter b9361d54c6 gears.color: Add a pattern cache
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>
2014-03-29 22:52:04 +01:00
Uli Schlachter 79ad0d3e6e gears.surface: Cache files from disk
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>
2014-03-29 22:01:01 +01:00
Uli Schlachter 1847b0ae1f gears.color.create_opaque_pattern: Fix for SurfacePatterns (FS#1236)
Sorry!

Signed-off-by: Uli Schlachter <psychon@znc.in>
2014-03-23 21:51:29 +01:00
Uli Schlachter 41bc77d64c Bump minimum lgi dependency to 0.7.0
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>
2014-03-17 17:52:09 +01:00