Commit Graph

44 Commits

Author SHA1 Message Date
Uli Schlachter 225bb8a8c6 Consider icon spacing in systray:draw()
When less space is available than was asked, systray:draw() has to
compute the right base size so that all the icons fit into the available
space. This computation so far ignored the icon spacing, resulting in a
too large base size.

Fixes: https://github.com/awesomeWM/awesome/issues/2981
Signed-off-by: Uli Schlachter <psychon@znc.in>
2020-02-13 12:11:41 -05:00
Uli Schlachter 60033a2113 Start some unit tests for the systray icon
Signed-off-by: Uli Schlachter <psychon@znc.in>
2020-02-13 12:11:41 -05:00
Uli Schlachter c80bf6f46e wibox.layout.flex: Do not leave empty space behind
It is not possible to distribute 100px to three widgets equally. The
current version of wibox.layout.flex tries to do that anyway, by giving
each widget 33px and leaving one pixel outside of any widget. Thus, if
the widgets e.g. have a common background, this leads to a one pixel gap
in the background.

This patch changes the flex layout so that the extra pixel is assigned
to some widget instead. It does so by basically keeping a sum of
space_per_item for the widgets that was assigned so far. This sum is
rounded and when this leads to rounding, the corresponding child widget
gets an extra pixel.

More precisely, this tracks a pos as before. Widgets get their position
still assigned based on rounding pos. However, this now also remembers
this rounded position for the next iteration of the loop. This allows to
assign the size of widgets based on the difference between the current
and last rounded position.

(Possibly) fixes: https://github.com/awesomeWM/awesome/issues/2461
Signed-off-by: Uli Schlachter <psychon@znc.in>
2018-11-05 10:13:18 +01:00
Aire-One c58e7d4fc8 add busted tests for signal "property::value" 2018-04-24 00:24:06 +02:00
Uli Schlachter c8dc563ce1 Add tests for get_children of containers
Fixes: https://github.com/awesomeWM/awesome/issues/1672
Signed-off-by: Uli Schlachter <psychon@znc.in>
2017-06-08 17:00:44 +02:00
Uli Schlachter 72c2f06c01 Add tests for get_children of layouts
Partially-fixes: https://github.com/awesomeWM/awesome/issues/1672
Signed-off-by: Uli Schlachter <psychon@znc.in>
2017-06-08 17:00:44 +02:00
Emmanuel Lepage Vallée 06a7818c09 tests: Test imagebox:set_image(nil) 2017-03-26 17:51:11 +02:00
Uli Schlachter 13dbc558fc wibox.hierarchy: Only count "really visible" widgets
Widgets with width or height zero cannot really be counted as visible,
so do not do so.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2017-03-11 18:44:56 +01:00
Uli Schlachter e1fe1de98f wibox.hierarchy: Add ability to count widgets
This adds new code so that we can count how often a specific widget is
visible inside of all widget hierarchies.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2017-03-11 13:55:57 +01:00
Kevin Zander 3f6df8ddee Fix Luacheck 0.19.0 release Travis breaks 2017-03-03 16:41:12 -06:00
Uli Schlachter 4bb02d1b53 wibox.hierarchy: Fix the matrix_to/from_device
Matrix operations are hard. Apparently I always keep confusing the order
that transformations are applied in the matrix resulting from a matrix
multiplication.

This commit fixes things in wibox.hierarchy that were wrong due to the
wrong order and changes a unit test so that it would now catch the
breakage (and makes sure that it does not happen again).

Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-10-05 20:07:19 +02:00
Uli Schlachter 0857f6f1b5 Lua: Remove calls to add_signal()
The requirement to call add_signal() was added to catch typos. However, this
requirement became increasingly annoying with property::<name> signals and e.g.
gears.object allowing arbitrary properties to be changed.

All of this ended up in a single commit because tests/examples fails if I first
let add_signal() emit a deprecation warning.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-06-04 18:23:48 +02:00
Emmanuel Lepage Vallee 72c437a7c8 test: Fix widget cache 2016-05-30 23:12:39 -04:00
Emmanuel Lepage Vallee adb2f88383 objects: Add a table for private elements
Provide a standardized place for them rather than having each
widgets use their own conventions.
2016-05-30 18:00:59 -04:00
Emmanuel Lepage Vallée 3be5343e83 Merge pull request #709 from psychon/implement-set-children-sanely
Implement set children sanely
2016-03-03 02:06:58 -05:00
Uli Schlachter 923d0b8767 Add some unit tests for errors in :setup()
This adds a test that checks that :setup{ false } filters out the false, just
like it already filters out nil values. Then, this also adds a test that checks
that properties (:setup{ foo = false }) are not filtered out, because the first
version of me check did that accidentally.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-02-28 11:09:21 +01:00
Uli Schlachter 9900cdacd6 Add a unit test that I have laying around
Weird, no idea why this isn't in Git and where it should have been committed...

Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-02-28 10:43:48 +01:00
Uli Schlachter 1dd63b04de check_widget(): Also check .is_widget entry
Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-02-27 14:01:31 +01:00
Uli Schlachter f3091154f6 Make beautiful work directly under unit tests
Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-02-21 17:09:08 +01:00
Uli Schlachter cf1576cdd8 Fix all luacheck warnings in spec/
Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-02-11 21:55:08 +01:00
Uli Schlachter dc0afe9f59 Add some constructor arguments to some layouts
This adds new constructor arguments to align, fixed and flex which allows adding
widgets directly while creating the layout.

Idea originally by actionless:
https://github.com/awesomeWM/awesome/pull/486#issuecomment-143606301

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

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-10-17 14:50:46 +02:00
Uli Schlachter dfcbf20d81 Add and use wibox.hierarchy:update()
This function updates a hierarchy if the layout of some widgets changed. It does
nothing on the parts that did not change. This should be more efficient than
recomputing the whole hierarchy whenever something changes.

Once again, this has some positive results on the "benchmark test":

Before:
        create wibox: 0.083016   sec/iter ( 13 iters, 1.161 sec for benchmark)
    update textclock: 0.00391091 sec/iter (271 iters, 3.219 sec for benchmark)
  relayout textclock: 0.00273234 sec/iter (397 iters, 1.087 sec for benchmark)
    redraw textclock: 0.0010191  sec/iter (989 iters, 1.745 sec for benchmark)

After:
        create wibox: 0.083146   sec/iter ( 13 iters, 1.163 sec for benchmark)
    update textclock: 0.00170519 sec/iter (647 iters, 2.201 sec for benchmark)
  relayout textclock: 0.000581637 sec/iter (1880 iters, 1.094 sec for benchmark)
    redraw textclock: 0.0010167  sec/iter (997 iters, 1.773 sec for benchmark)

So again no difference for creating wiboxes (100.16% compared to before). This
time we also have no real difference for creating wiboxes (99.76%). Update (44%)
and relayout (21%) are improved a lot.

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

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-09-23 20:57:41 +02:00
Daniel Hahler b0d7e6bb6c Merge pull request #458 from psychon/explicit_widget_deps
Explicitly track dependencies between widgets

Closes https://github.com/awesomeWM/awesome/pull/458.
2015-09-21 21:12:39 +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 41a8fabf4c Explicitly track dependencies between widgets
Before this, dependencies between widgets where implicitly discovered by
recursive calls to base.fit_widget() and base.layout_widget(). However, it is
too easy to get this wrong (just call one of these functions from outside of a
widget's :fit() / :layout() function) and the resulting mess would be hard to
debug.

Thus, this commit changes the API so that callers have to identify themselves
and we can explicitly record the dependency between the widgets involved.

This also fixes a bug where no dependencies were tracked for widgets after
:set_visible(false). Whoops...

Sorry for breaking the API for adding this.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-09-17 18:17:05 +02:00
Uli Schlachter c62d323d09 wibox.widget.base: Add caches for :layout and :fit
These caches, well, cache the result of the :layout and :fit callbacks on
widgets.

Clearing caches is done by recording dependencies between a widget. When a call
to base.fit_widget() or base.layout_widget() recursively causes another call to
such a function, this means that the earlier widget depends on the later widget.
This dependency is recorded and when the later widget emits
widget::layout_changed, the caches of all the widgets involved are cleared.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-09-06 18:57:21 +02:00
Uli Schlachter 447492e986 Tests: Have only one place for stubbing widgets
This makes the tests for wibox.hierarchy use test_utils.widget_stub() instead of
having its own implementation of "fake widgets".

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-09-06 18:57:07 +02:00
Uli Schlachter 45323f2801 Remove wibox.hierarchy:get_parent()
It's unused.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-09-06 18:56:58 +02:00
Uli Schlachter 5406ac6fe1 Add some tests for the textbox
Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-09-05 14:51:36 +02:00
Uli Schlachter 958603410c flex layout: Test signal emission
Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-09-05 14:51:36 +02:00
Uli Schlachter dcd4db69e6 fixed layout: Test signal emission
Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-09-05 14:51:36 +02:00
Uli Schlachter 0e7ae1cb25 align layout: Test signal emission
Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-09-05 14:51:36 +02:00
Uli Schlachter a430f6bc4c Remove now-unused stuff from test_utils
Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-09-05 14:28:53 +02:00
Uli Schlachter 3338718b93 Merge wibox.layout.base and wibox.widget.base
Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-09-05 14:28:53 +02:00
Uli Schlachter 496fbde9b4 Convert the flex layout to the new widget system
Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-09-05 14:28:52 +02:00
Uli Schlachter 199b553895 Convert the fixed layout to the new widget system
Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-09-05 14:28:52 +02:00
Uli Schlachter e67e2813e9 Convert the align layout to the new widget system
Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-09-05 14:28:52 +02:00
Uli Schlachter 02f67b61b4 Add a widget hierarchy implementation
A widget hierarchy describes the position of widgets. The hierarchy is a
recursive tree of widget hierarchy instances. This functionality depends on a
:layout function that is not yet implemented on widgets, but will be added
later.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-09-05 14:28:52 +02:00
Uli Schlachter bcc1751fca fit_widget(): Sanitize the result of :fit()
After this change, fit_widget() enforces that a widget cannot ask for more space
than was offered to it. This also fixes a rounding issue in the flex layout
where its fit function would return too small numbers.

Thanks to this, lots of "XXX" comments in spec/ disappear.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-08-23 17:08:44 +02:00
Uli Schlachter 1ebc34b5e9 Widgets: Also add a context argument to :fit()
Together with the context argument to :draw(), this even allows widgets to have
DPI-dependant size.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-08-12 11:19:48 +02:00
Daniel Hahler 68b0fa243f Add "visible" property for widgets
Widgets with `visible = false` will not be drawn.

Closes https://github.com/awesomeWM/awesome/pull/326.
2015-08-10 23:09:07 +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
Daniel Hahler c26a96177d spec: fix "require" statements for busted 2.0.rc6
Busted now only provides the magic modules `assert`, `spy` etc for
the busted context.  The helper module `spec/wibox/test_utils.lua`
therefore needs to explicitly require them.

Ref: https://github.com/awesomeWM/awesome/pull/139
2015-02-19 12:13:53 +01: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