void view_move(struct view *view, int x, int y);
void view_moved(struct view *view);
void view_minimize(struct view *view, bool minimized);
+struct output *view_output(struct view *view);
void view_store_natural_geometry(struct view *view);
/* output is optional, defaults to current nearest output */
-void view_center(struct view *view, struct output *output);
+void view_center(struct view *view, struct output *output,
+ const struct wlr_box *ref);
void view_restore_to(struct view *view, struct wlr_box geometry);
void view_set_untiled(struct view *view);
void view_maximize(struct view *view, bool maximize,
}
/* view_output - return the output that a view is mostly on */
-static struct output *
+struct output *
view_output(struct view *view)
{
assert(view);
static bool
view_compute_centered_position(struct view *view, struct output *output,
- int w, int h, int *x, int *y)
+ const struct wlr_box *ref, int w, int h, int *x, int *y)
{
if (w <= 0 || h <= 0) {
wlr_log(WLR_ERROR, "view has empty geometry, not centering");
struct wlr_box usable = output_usable_area_in_layout_coords(output);
int width = w + margin.left + margin.right;
int height = h + margin.top + margin.bottom;
- *x = usable.x + (usable.width - width) / 2;
- *y = usable.y + (usable.height - height) / 2;
+
+ /* If reference box is NULL then center to usable area */
+ if (!ref) {
+ ref = &usable;
+ }
+ *x = ref->x + (ref->width - width) / 2;
+ *y = ref->y + (ref->height - height) / 2;
/* If view is bigger than usable area, just top/left align it */
if (*x < usable.x) {
*y = usable.y;
}
-#if HAVE_XWAYLAND
- /* TODO: refactor xwayland.c functions to get rid of this */
- if (view->type == LAB_XWAYLAND_VIEW) {
- *x += margin.left;
- *y += margin.top;
- }
-#endif
+ *x += margin.left;
+ *y += margin.top;
return true;
}
{
view->natural_geometry.width = LAB_FALLBACK_WIDTH;
view->natural_geometry.height = LAB_FALLBACK_HEIGHT;
- view_compute_centered_position(view, NULL,
+ view_compute_centered_position(view, NULL, NULL,
view->natural_geometry.width,
view->natural_geometry.height,
&view->natural_geometry.x,
}
void
-view_center(struct view *view, struct output *output)
+view_center(struct view *view, struct output *output, const struct wlr_box *ref)
{
assert(view);
int x, y;
- if (view_compute_centered_position(view, output, view->pending.width,
- view->pending.height, &x, &y)) {
+ if (view_compute_centered_position(view, output, ref,
+ view->pending.width, view->pending.height, &x, &y)) {
view_move(view, x, y);
}
}
} else {
/* reposition if original geometry is offscreen */
struct wlr_box box = view->natural_geometry;
- if (view_compute_centered_position(view, NULL, box.width,
- box.height, &box.x, &box.y)) {
+ if (view_compute_centered_position(view, NULL, NULL,
+ box.width, box.height, &box.x, &box.y)) {
view_move_resize(view, box);
}
}
/* reposition view if it's offscreen */
if (!wlr_output_layout_intersects(view->server->output_layout,
NULL, &view->pending)) {
- view_center(view, NULL);
+ view_center(view, NULL, NULL);
}
}
if (view->toplevel.handle) {
static void
position_xdg_toplevel_view(struct view *view)
{
- struct wlr_xdg_surface *xdg_surface = xdg_surface_from_view(view);
struct wlr_xdg_toplevel *parent_xdg_toplevel =
xdg_toplevel_from_view(view)->parent;
if (!parent_xdg_toplevel) {
- view_center(view, output_from_cursor_coords(view->server));
+ view_center(view, output_from_cursor_coords(view->server),
+ NULL);
} else {
/*
* If child-toplevel-views, we center-align relative to their
struct view *parent = lookup_view_by_xdg_toplevel(
view->server, parent_xdg_toplevel);
assert(parent);
- int center_x = parent->current.x + parent->current.width / 2;
- int center_y = parent->current.y + parent->current.height / 2;
- view->current.x = center_x
- - xdg_surface->current.geometry.width / 2;
- view->current.y = center_y
- - xdg_surface->current.geometry.height / 2;
+ view_center(view, view_output(parent), &parent->pending);
}
-
- struct border margin = ssd_get_margin(view->ssd);
- view->current.x += margin.left;
- view->current.y += margin.top;
}
static const char *