Commit Graph

40 Commits

Author SHA1 Message Date
Lucas Schwiderski 4b30158176
doc(w.l.fixed): Improve documentation for spacing properties
Signed-off-by: Lucas Schwiderski <lucas@lschwiderski.de>
2021-07-14 23:00:29 +02:00
Lucas Schwiderski f2c66b006d
doc(w.l.fixed): Add module description
Signed-off-by: Lucas Schwiderski <lucas@lschwiderski.de>
2021-07-13 22:44:50 +02:00
Lucas Schwiderski 08c893fff9
refactor(w.l.fixed): Fix line length
Signed-off-by: Lucas Schwiderski <lucas@lschwiderski.de>
2021-07-13 22:33:32 +02:00
Lucas Schwiderski a938a1b807
refactor(w.l.fixed): Rename abbreviated variables
Signed-off-by: Lucas Schwiderski <lucas@lschwiderski.de>
2021-07-13 22:30:52 +02:00
Emmanuel Lepage Vallee 83c31f948b fixed: Try to handle zero sized widgets again.
The newly changed code doesn't handle this well:

    local w = wibox.widget {
        {
            --add anything here
            widget = wibox.layout.fixed.horizontal
        },
        widget = wibox.layout.fixed.horizontal,
    }

This will cause the "inner" fixed layout to have the minimum size
it supports. In that case, if the last widget has "no size" because
it supports up to 0x0, then it isn't added to the layout.

This was done "on purpose" because if there is a spacing, then `:fit`
would have returned a size "too small" because the last spacing area
would be (correctly) missing.

But if the zero sized widget isn't added to the layout, then it's size
isn't tracker. So if it emits a layout_changed signal, nothing catches
it.

The "fix" is rather hacky and probably a little incorrect. It rely
on the behavior of `:fit()` to avoid adding the "wrong" widgets to
the layout, which is fragile.

However, I don't have a better idea.
2021-05-31 02:27:36 -07:00
mergify[bot] a4572b9b52
Merge pull request #3238 from ShayAgros/master
Fixed wrong handling of negative spacing in layout.fixed
2021-04-29 06:45:50 +00:00
Aire-One 3969ad8819 doc(@supermodule): Add to wibox.layout modules 2021-04-02 19:24:07 +02:00
Shay Agroskin 62850476d2 layout/fixed: Prevent overloading widgets with negative spacing
For each widget, the layout function checks whether placing it would
make the function exceed the allowed geometry.
If not, the function places both the widget and a spacing widget.
This check ignores the size of the spacing widget itself, this can cause
overloading of widgets on top of each other.

For example, the following scenario with these widgets:
    widgets: widget1 { width = 10, height = 10  }
	     widget2 { width = 10, height = 10  }
	     widget3 { width = 10, height = 10  }
and a call to horizontal layout with the
{ width = 10, height = 10, spacing = -5 } parameters.

The function would layout the widgets the following way:
{
    widget1: { x = 0, y = 0, width = 10, height = 10 }
    spacing: { x = 5, y = 0, width = 5, height = 10  }
    widget2: { x = 5, y = 0, width = 5, height = 10  }
    spacing: { x = 5, y = 0, width = 5, height = 10 }
    widget3: { x = 5, y = 0, width = 5, height = 10  }
}

This behaviour would be the same for any number of widgets for negative
layout.

This patch changes the layout function to check whether the current
widget uses up the whole space.
It also removes 'pos' variable. Its purpose isn't intuitive in the
presence of x and y. This helps to understand where each widget is
placed now that x, y don't hold the end location of the widget in the
previous loop iteration.

The result of the previous example becomes:
{
    widget1: { x = 0, y = 0, width = 10, height = 10 }
}

While this might not be the wanted behaviour exactly, distinguishing
between the scenario where 2 widgets are drawn and a scenario where 3
are drawn might complicate the layout function too much.

This patch also adds unit testing that catches the described behaviour.

Signed-off-by: Shay Agroskin <agrosshay@gmail.com>
2021-03-26 16:11:01 +03:00
Shay Agroskin a18e3508f6 layout/fixed: Fix wrong space calculation in fit
The fit function is called twice in row.

- The first time it gets the maximum available width, and returns how
  much of it it needs (with 0 spacing it would be 477)

- The second time the available width it gets is the same as it returned
  last phase (and probably is expected to return the same result again)

The width fit requests is the total width of all widgets together + the
spacing (e.g. if each tag widget is 53 px and spacing is -10 then the
requested width 53 * 9 - 80).

The function tries to first fit all its widgets (the tag numbers) in the
amount of width it received, and only then adds the spacing to it. This
is problematic because in the second phase the widgets need to fit
themselves in the same width they requested earlier minus the spacing
(in case of negative spacing). This is of course impossible and so some
widgets are just not being drawn correctly.

This patch makes fit function take into account the spacing while
placing the widgets and not afterwards.

Also add unit-testing that test the bug described.

Signed-off-by: Shay Agroskin <agrosshay@gmail.com>
2021-03-26 16:11:01 +03:00
Shay Agroskin 749422100e layout/fixed: Remove code duplication
The function has several expressions of the form
    if self._private.dir == "y" then
This patch stores the result of
    self._private.dir == "y"
to avoid code duplication.

Also remove the 'used_in_dir' and 'in_dir' variables since their values
can be calculated using other variables in the function and updating
them individually is error prone.

This patch doesn't do any functional changes.

Signed-off-by: Shay Agroskin <agrosshay@gmail.com>
2021-03-26 16:11:01 +03:00
Emmanuel Lepage Vallee f21e0ba9dd doc: Upgrade the widget layout documentation. 2019-11-30 01:26:06 -05:00
Emmanuel Lepage Vallee 82db9180b1 widget: Mutualize all set_widget implementation to behave the same
Now always call both check_widget and make_widget_from_value. This
should make it a lot less confusing when randomly trying to create
a widget as all ways to do it slowly converge toward an unified
one.
2019-10-05 22:57:04 -04:00
Emmanuel Lepage Vallee 90a29f92eb doc: Fix all the property, theme and field types. 2019-06-08 18:14:14 -04:00
Emmanuel Lepage Vallee 11d7a614d9 doc: Add a constructor stereotype for everything.
This forces the constructor functions to be at the top of the API
documentation rather than in a random position.
2019-06-08 18:13:42 -04:00
Emmanuel Lepage Vallee 63ca0f0d8f doc: Use an explicit @method stereotype for all methods.
ldoc has a magical `@classmod` module type which tries to detect
what is a method and what is a static function. It fails about as
often as it works. This commit makes everything explicit to remove
such issues.

Fixes #2640
Ref #1373
2019-06-08 18:13:42 -04:00
Emmanuel Lepage Vallee 7b00d76673 doc: Move all layouts to a new section. 2019-06-08 17:49:14 -04:00
Daniel Hahler 3876b18240 doc: Add missing C-object documentation and fix some papercuts.
Ref: https://github.com/awesomeWM/awesome/issues/1373
2018-07-25 18:26:11 -04:00
Emmanuel Lepage Vallee e12c000b97 layout: Add separator widget support to 3 layouts
The ratio, fixed and flex layout can now display a widget between
each layout elements.

The align layout was left out because it doesn't support spacing
2017-11-24 19:13:59 -05:00
Kevin Zander c3461b535c gears: Move awful.util.table to gears.table (#1641)
* Move table functions out of awful.util into new gears.table

* travis: Use v9999 prefix for full requests

Make sure no newly deprecated functions are used

* Move all `awful.util.table.*` calls to `gears.table.*` calls
Move table test functions from awful/util_spec to new gears/table_spec
Change awful.util.subsets call to gears.math.subsets in awful/key.lua
2017-03-08 15:18:33 -05:00
Lego Stax bc728a5f46 doc: Update fixed.lua (#1591) 2017-02-21 22:03:21 -05:00
Uli Schlachter 259c4f716f Remove @release @AWESOME_VERSION@ everywhere (#1157)
It does not provide much value. The version number is already known to
ldoc globally in the "description" variable.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-10-09 22:36:20 +02:00
Emmanuel Lepage Vallee ec923e96fc layout: Add more signals. 2016-08-17 02:31:16 -04:00
Emmanuel Lepage Vallee b89fbcf940 fixed: Enable the property system
And add the missing documentation
2016-05-30 23:10:02 -04:00
Emmanuel Lepage Vallee 150026690c doc: Add a fixed layout default screenshot 2016-05-30 18:00:58 -04:00
Emmanuel Lepage Vallee 533a4bfd8f fixed: Use the shared documentation and fix the doc 2016-05-09 01:37:48 -04:00
Emmanuel Lepage Vallee 78ed3abe1a wibox.widget: Minor enhancements
* Better widget names when using the declarative syntax
 * Add ratio.get_ratio to avoid using the private API
 * Also support `set_widget` when swapping widgets
2016-03-04 04:16:53 -05:00
Uli Schlachter cf3c81fa9e Implement :set_children() sanely everywhere
This makes the code use the existing functions for setting widgets. That way,
all the sanity checks that the existing functions have are applied for this code
as well.

I just spent half an hour tracking down a bug where a boolean ended up as a
"widget" in a fixed layout. The symptom was that while drawing the widget, an
error happened. Via this change, the error would instead be flagged while
constructing the widget.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-02-27 13:55:34 +01:00
Uli Schlachter 15e72fb037 Fix luacheck warnings in lib/wibox
Warnings pointing out actual problems are left.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-02-12 09:15:55 +01:00
Emmanuel Lepage Vallee e36f23171b wibox.widget: Add `set_children` method
Provide a generic method to set the widget content
2016-02-10 01:09:50 -05:00
Emmanuel Lepage Vallee e615173552 layout.fixed: Add methods to manipulate the layout after creation
Until now, this layout was "append only". There was no official
APIs to remove, replace, insert and swap widgets. This is fine
for the usual wibox + sensors widget used by the majority of
users, but lack flexibility necessary to use the layout system
to place dynamic elements such as clients.

The methods introduced by this commit are also recursive. This
allow widgets to be decorated, wrapped and splitted without
having to add boilerplate code everywhere.
2016-02-03 04:01:38 -05:00
Emmanuel Lepage Vallee 330c8d97e1 layout.flex: Base on layout.fixed rather than widget.base
This remove duplicated code and will allow more "collection"
style layouts to be implemented without logic duplication.

This commit also do some small cleanup to remove duplicated
code now present in `awful.util`.

Fixes https://github.com/awesomeWM/awesome/issues/617
2016-02-03 04:00:56 -05: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 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 dcd4db69e6 fixed layout: Test signal emission
Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-09-05 14:51:36 +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 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 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
Uli Schlachter 88b98789a0 Rename the first argument to :draw to "context"
Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-08-12 11:19:28 +02:00
Uli Schlachter d990e7918f Use :weak_connect_signal() for connecting to widget::updated
This way "that other widget" doesn't prevent the current widget from being
garbage collected.

Please note that this in all of these cases the widget under consideration does
have a strong reference to the callback function. This means that the callback
cannot be garbage collected until "this widget" itself is collected. Thanks to
this, this change is safe.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-06-25 06:37:05 +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