mirror of
https://github.com/labwc/labwc.git
synced 2025-11-30 06:59:52 -05:00
action: allow SnapToEdge to combine two cardinal directions
This patch adds `combine` argument to (Toggle)SnapToEdge actions. This allows to snap a window to e.g. up-left by running two actions: - `<action name="SnapToEdge" direction="left" combine="yes" />` - `<action name="SnapToEdge" direction="up" combine="yes" />` Then running `<action name="SnapToEdge" direction="down" combine="yes" />` snaps it to left again. This behavior is almost the same as KWin, except that snapping a up-right-tiled window to right doesn't move it to the right-adjacent output, but makes it right-tiled first.
This commit is contained in:
parent
af6a0df231
commit
2ac48116e1
5 changed files with 68 additions and 26 deletions
48
src/view.c
48
src/view.c
|
|
@ -2126,7 +2126,7 @@ view_placement_parse(const char *policy)
|
|||
|
||||
void
|
||||
view_snap_to_edge(struct view *view, enum lab_edge edge,
|
||||
bool across_outputs, bool store_natural_geometry)
|
||||
bool across_outputs, bool combine, bool store_natural_geometry)
|
||||
{
|
||||
assert(view);
|
||||
|
||||
|
|
@ -2142,15 +2142,45 @@ view_snap_to_edge(struct view *view, enum lab_edge edge,
|
|||
|
||||
view_set_shade(view, false);
|
||||
|
||||
if (across_outputs && view->tiled == edge && view->maximized == VIEW_AXIS_NONE) {
|
||||
/* We are already tiled for this edge; try to switch outputs */
|
||||
output = output_get_adjacent(view->output, edge, /* wrap */ false);
|
||||
if (!output) {
|
||||
return;
|
||||
}
|
||||
if (lab_edge_is_cardinal(edge) && view->maximized == VIEW_AXIS_NONE) {
|
||||
enum lab_edge invert_edge = lab_edge_invert(edge);
|
||||
/* Represents axis of snapping direction */
|
||||
enum lab_edge parallel_mask = edge | invert_edge;
|
||||
/*
|
||||
* The vector view->tiled is split to components
|
||||
* parallel/orthogonal to snapping direction. For example,
|
||||
* view->tiled=TOP_LEFT is split to parallel_tiled=TOP and
|
||||
* orthogonal_tiled=LEFT when edge=TOP or edge=BOTTOM.
|
||||
*/
|
||||
enum lab_edge parallel_tiled = view->tiled & parallel_mask;
|
||||
enum lab_edge orthogonal_tiled = view->tiled & ~parallel_mask;
|
||||
|
||||
/* When switching outputs, jump to the opposite edge */
|
||||
edge = lab_edge_invert(edge);
|
||||
if (across_outputs && view->tiled == edge) {
|
||||
/*
|
||||
* E.g. when window is tiled to up and being snapped
|
||||
* to up again, move it to the output above and tile
|
||||
* it to down.
|
||||
*/
|
||||
output = output_get_adjacent(view->output, edge,
|
||||
/* wrap */ false);
|
||||
if (!output) {
|
||||
return;
|
||||
}
|
||||
edge = invert_edge;
|
||||
} else if (combine && parallel_tiled == invert_edge
|
||||
&& orthogonal_tiled != LAB_EDGE_NONE) {
|
||||
/*
|
||||
* E.g. when window is tiled to downleft/downright and
|
||||
* being snapped to up, tile it to left/right.
|
||||
*/
|
||||
edge = view->tiled & ~parallel_mask;
|
||||
} else if (combine && parallel_tiled == LAB_EDGE_NONE) {
|
||||
/*
|
||||
* E.g. when window is tiled to left/right and being
|
||||
* snapped to up, tile it to upleft/upright.
|
||||
*/
|
||||
edge = view->tiled | edge;
|
||||
}
|
||||
}
|
||||
|
||||
if (view->maximized != VIEW_AXIS_NONE) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue