feat(w.l.overflow): Implement simple child extends clipping

While it is possible for any widget to clip drawing for its children to
prevent drawing outside the widget's boundaries, the widget system would
still consider the child widget's full size for mouse clicks.

Draw clipping via Cairo supports any arbitrary, complex path. To mirror
that for mouse clicks, we would need to create a temporary Cairo surface
to do the clipping for us, which is rather expensive.

Therefore this patch only adds the very basic, but likely the most
common use case where mouse clicks should be clipped to the widget's own
size.

See https://github.com/awesomeWM/awesome/pull/3309#discussion_r611138512
for the full discussion.

Signed-off-by: Lucas Schwiderski <lucas@lschwiderski.de>
This commit is contained in:
Lucas Schwiderski 2021-12-16 22:47:06 +01:00
parent ea264d4388
commit 23681c1f26
No known key found for this signature in database
GPG Key ID: AA12679AAA6DF4D8
2 changed files with 12 additions and 6 deletions

View File

@ -143,12 +143,14 @@ function hierarchy_update(self, context, widget, width, height, region, matrix_t
-- Calculate the draw extents
local x1, y1, x2, y2 = 0, 0, width, height
for _, h in ipairs(self._children) do
local px, py, pwidth, pheight = matrix.transform_rectangle(h._matrix, h:get_draw_extents())
x1 = math.min(x1, px)
y1 = math.min(y1, py)
x2 = math.max(x2, px + pwidth)
y2 = math.max(y2, py + pheight)
if not widget.clip_child_extends then
for _, h in ipairs(self._children) do
local px, py, pwidth, pheight = matrix.transform_rectangle(h._matrix, h:get_draw_extents())
x1 = math.min(x1, px)
y1 = math.min(y1, py)
x2 = math.max(x2, px + pwidth)
y2 = math.max(y2, py + pheight)
end
end
self._draw_extents = {
x = x1, y = y1,

View File

@ -473,6 +473,10 @@ local function new(dir, ...)
gtable.crush(ret, overflow, true)
ret.widget_name = gobject.modulename(2)
-- Tell the widget system to prevent clicks outside the layout's extends
-- to register with child widgets, even if they actually extend that far.
-- This prevents triggering button presses on hidden/clipped widgets.
ret.clip_child_extends = true
-- Manually set the scroll factor here. We don't know the bounding size yet.
ret._private.scroll_factor = 0