mirror of
https://github.com/labwc/labwc.git
synced 2026-03-17 05:33:47 -04:00
view: factor out view_compute_position_by_policy()
This commit is contained in:
parent
6a9e6dcae1
commit
5238dcaa08
2 changed files with 27 additions and 20 deletions
|
|
@ -514,6 +514,14 @@ int view_effective_height(struct view *view, bool use_pending);
|
||||||
*/
|
*/
|
||||||
void view_center(struct view *view, const struct wlr_box *ref);
|
void view_center(struct view *view, const struct wlr_box *ref);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Like view_place_by_policy() but doesn't actually move the view.
|
||||||
|
* Returns false if position could not be computed (for example, if no
|
||||||
|
* outputs are connected). In that case, @geom is not modified.
|
||||||
|
*/
|
||||||
|
bool view_compute_position_by_policy(struct view *view, struct wlr_box *geom,
|
||||||
|
bool allow_cursor, enum lab_placement_policy policy);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* view_place_by_policy - apply placement strategy to view
|
* view_place_by_policy - apply placement strategy to view
|
||||||
* @view: view to be placed
|
* @view: view to be placed
|
||||||
|
|
|
||||||
39
src/view.c
39
src/view.c
|
|
@ -1067,6 +1067,22 @@ view_compute_cascaded_position(struct view *view, struct wlr_box *geom)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
view_compute_position_by_policy(struct view *view, struct wlr_box *geom,
|
||||||
|
bool allow_cursor, enum lab_placement_policy policy)
|
||||||
|
{
|
||||||
|
if (allow_cursor && policy == LAB_PLACE_CURSOR) {
|
||||||
|
return view_compute_near_cursor_position(view, geom);
|
||||||
|
} else if (policy == LAB_PLACE_AUTOMATIC) {
|
||||||
|
return placement_find_best(view, geom);
|
||||||
|
} else if (policy == LAB_PLACE_CASCADE) {
|
||||||
|
return view_compute_cascaded_position(view, geom);
|
||||||
|
} else {
|
||||||
|
return view_compute_centered_position(view, NULL,
|
||||||
|
geom->width, geom->height, &geom->x, &geom->y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
view_place_by_policy(struct view *view, bool allow_cursor,
|
view_place_by_policy(struct view *view, bool allow_cursor,
|
||||||
enum lab_placement_policy policy)
|
enum lab_placement_policy policy)
|
||||||
|
|
@ -1078,27 +1094,10 @@ view_place_by_policy(struct view *view, bool allow_cursor,
|
||||||
view_move_resize(view, view->natural_geometry);
|
view_move_resize(view, view->natural_geometry);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (allow_cursor && policy == LAB_PLACE_CURSOR) {
|
struct wlr_box geom = view->pending;
|
||||||
struct wlr_box geometry = view->pending;
|
if (view_compute_position_by_policy(view, &geom, allow_cursor, policy)) {
|
||||||
if (view_compute_near_cursor_position(view, &geometry)) {
|
view_move(view, geom.x, geom.y);
|
||||||
view_move(view, geometry.x, geometry.y);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else if (policy == LAB_PLACE_AUTOMATIC) {
|
|
||||||
struct wlr_box geometry = view->pending;
|
|
||||||
if (placement_find_best(view, &geometry)) {
|
|
||||||
view_move(view, geometry.x, geometry.y);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else if (policy == LAB_PLACE_CASCADE) {
|
|
||||||
struct wlr_box geometry = view->pending;
|
|
||||||
if (view_compute_cascaded_position(view, &geometry)) {
|
|
||||||
view_move(view, geometry.x, geometry.y);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
view_center(view, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue