client, mouse: improve struts a bit

- struts are now additive
- allow multiple docks at the edge of the screen, trigger is approaching workarea from inside

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Maarten Maathuis 2009-03-26 22:13:45 +01:00 committed by Julien Danjou
parent bf0329d8a3
commit 47efde17f5
2 changed files with 27 additions and 25 deletions

View File

@ -72,14 +72,14 @@ end
local function snap_inside(g, sg, snap)
local edgev = 'none'
local edgeh = 'none'
if math.abs(g.x) < snap + sg.x and g.x > sg.x then
if math.abs(g.x) < snap + sg.x and g.x >= sg.x then
edgev = 'left'
g.x = sg.x
elseif math.abs((sg.x + sg.width) - (g.x + g.width)) < snap then
edgev = 'right'
g.x = sg.x + sg.width - g.width
end
if math.abs(g.y) < snap + sg.y and g.y > sg.y then
if math.abs(g.y) < snap + sg.y and g.y >= sg.y then
edgeh = 'top'
g.y = sg.y
elseif math.abs((sg.y + sg.height) - (g.y + g.height)) < snap then
@ -115,18 +115,19 @@ function client.snap(c, snap, x, y, fixed_x, fixed_y)
geom, edge = snap_inside(geom, capi.screen[c.screen].geometry, snap)
geom, edge2 = snap_inside(geom, capi.screen[c.screen].workarea, snap)
-- Allow certain windows to snap to the edge of the screen.
-- Allow certain windows to snap to the edge of the workarea.
-- Only allow docking to workarea for consistency/to avoid problems.
if c.type == "utility" or c.type == "toolbar" or c.type == "dock" then
local struts = c:struts()
struts['left'] = 0
struts['right'] = 0
struts['top'] = 0
struts['bottom'] = 0
if edge ~= "none" and aclient.floating.get(c) then
if edge == "left" or edge == "right" then
struts[edge] = cur_geom.width
elseif edge == "top" or edge == "bottom" then
struts[edge] = cur_geom.height
if edge2 ~= "none" and aclient.floating.get(c) then
if edge2 == "left" or edge2 == "right" then
struts[edge2] = cur_geom.width
elseif edge2 == "top" or edge2 == "bottom" then
struts[edge2] = cur_geom.height
end
end
c:struts(struts)

View File

@ -176,6 +176,7 @@ screen_area_get(int screen, wibox_array_t *wiboxes,
area.height -= padding->top + padding->bottom;
}
/* struts are additive, to allow for multiple clients at the screen edge. */
if(strut)
{
client_t *c;
@ -185,35 +186,35 @@ screen_area_get(int screen, wibox_array_t *wiboxes,
if(c->strut.top_start_x || c->strut.top_end_x)
{
if (c->strut.top)
top = MAX(top, c->strut.top);
top += c->strut.top;
else
top = MAX(top, (c->geometry.y - area.y) + c->geometry.height);
top += c->geometry.height;
}
if(c->strut.bottom_start_x || c->strut.bottom_end_x)
{
if (c->strut.bottom)
bottom = MAX(bottom, c->strut.bottom);
bottom += c->strut.bottom;
else
bottom = MAX(bottom, (area.y + area.height) - c->geometry.y);
bottom += c->geometry.height;
}
if(c->strut.left_start_y || c->strut.left_end_y)
{
if (c->strut.left)
left = MAX(left, c->strut.left);
left += c->strut.left;
else
left = MAX(left, (c->geometry.x - area.x) + c->geometry.width);
left += c->geometry.width;
}
if(c->strut.right_start_y || c->strut.right_end_y)
{
if (c->strut.right)
right = MAX(right, c->strut.right);
right += c->strut.right;
else
right = MAX(right, (area.x + area.width) - c->geometry.x);
right += c->geometry.width;
}
}
}
/* swindow geometry includes borders. */
if(wiboxes)
for(int i = 0; i < wiboxes->len; i++)
{
@ -222,16 +223,16 @@ screen_area_get(int screen, wibox_array_t *wiboxes,
switch(w->position)
{
case Top:
top = MAX(top, (uint16_t) (w->sw.geometry.y - area.y) + w->sw.geometry.height + 2 * w->sw.border.width);
top += w->sw.geometry.height;
break;
case Bottom:
bottom = MAX(bottom, (uint16_t) (area.y + area.height) - w->sw.geometry.y);
bottom += w->sw.geometry.height;
break;
case Left:
left = MAX(left, (uint16_t) (w->sw.geometry.x - area.x) + w->sw.geometry.width + 2 * w->sw.border.width);
left += w->sw.geometry.width;
break;
case Right:
right = MAX(right, (uint16_t) (area.x + area.width) - w->sw.geometry.x);
right += w->sw.geometry.width;
break;
default:
break;