Commit Graph

67 Commits

Author SHA1 Message Date
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
Uli Schlachter 1924ee9e6e drawin: Only redraw on move with translucent background
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>
2014-03-16 14:58:14 +01:00
Uli Schlachter f86a9c896c gears.wallpaper: Create smaller image surface (FS#1087)
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>
2013-02-12 15:15:16 +01:00
Uli Schlachter fca2f3e58d gears.color: Accept cairo patterns as arguments
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>
2013-02-11 14:26:05 +01:00
Thomas Jost cd5180f60f gears.wallpaper: Add wallpaper.fit
Signed-off-by: Thomas Jost <schnouki@schnouki.net>
Signed-off-by: Uli Schlachter <psychon@znc.in>
2013-01-10 17:38:19 +01:00
uzsolt 23fe017bd4 fix locale problem (decimal separator isn't dot but comma)
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>
2013-01-06 12:08:02 +01:00
Uli Schlachter d13b825c36 Fix warnings from LDoc
Signed-off-by: Uli Schlachter <psychon@znc.in>
2012-11-19 15:35:32 +01:00
Uli Schlachter 96e03cb45d Lots of random documentation fixes
This is mostly about mis-named parameters, but also other small things.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2012-11-19 14:09:10 +01:00
Uli Schlachter 5ea174782d Also make gears.object more object-y
Signed-off-by: Uli Schlachter <psychon@znc.in>
2012-11-19 13:40:37 +01:00
Uli Schlachter 241d582c55 gears.object: Give better error messages
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>
2012-10-14 16:58:54 +02:00
Alexander Yakushev ec66ac876b Fix debug.dump
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>
2012-08-31 15:23:56 +02:00
Uli Schlachter 615aff3369 gears.wallpaper: Import
This is a lua module for managing the wallpaper.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2012-07-29 16:39:03 +02:00
Uli Schlachter 4b049c310d gears.surface: Update required lgi version
Signed-off-by: Uli Schlachter <psychon@znc.in>
2012-06-22 23:22:58 +02:00
Arvydas Sidorenko 65de8a7ab5 Broken lgi version checking
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>
2012-06-22 23:21:14 +02:00
Arvydas Sidorenko 997de2726c Ported lib/gears to lua 5.2
Tested with lua 5.1: all good

Signed-off-by: Arvydas Sidorenko <asido4@gmail.com>
Signed-off-by: Uli Schlachter <psychon@znc.in>
2012-06-16 17:37:30 +02:00
Arvydas Sidorenko e789cfaf66 Ported lib/gears to lua 5.2
Tested with lua 5.1: all good

Signed-off-by: Arvydas Sidorenko <asido4@gmail.com>
2012-06-16 17:37:30 +02:00
Arvydas Sidorenko 9623b8e42f Changed unpack in portable way
Signed-off-by: Arvydas Sidorenko <asido4@gmail.com>
Signed-off-by: Uli Schlachter <psychon@znc.in>
2012-06-16 13:00:13 +02:00