implement flip_x

This commit is contained in:
Tony Crisci 2018-03-27 14:49:31 -04:00
parent bbd0e23fa7
commit 8371e2f41d
3 changed files with 115 additions and 97 deletions

View File

@ -296,13 +296,19 @@ struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6_popup_at(
struct wlr_xdg_surface_v6 *surface, double sx, double sy, struct wlr_xdg_surface_v6 *surface, double sx, double sy,
double *popup_sx, double *popup_sy); double *popup_sx, double *popup_sy);
struct wlr_box wlr_xdg_positioner_v6_get_geometry(
struct wlr_xdg_positioner_v6_attributes *positioner);
/** /**
* Get the anchor point for this popup in the root parent's coordinate system. * Get the anchor point for this popup in the root parent's coordinate system.
*/ */
void wlr_xdg_popup_v6_get_anchor_point(struct wlr_xdg_popup_v6 *popup, void wlr_xdg_popup_v6_get_anchor_point(struct wlr_xdg_popup_v6 *popup,
int *root_sx, int *root_sy); int *root_sx, int *root_sy);
void wlr_positioner_v6_invert( void wlr_positioner_v6_invert_x(
struct wlr_xdg_positioner_v6_attributes *positioner);
void wlr_positioner_v6_invert_y(
struct wlr_xdg_positioner_v6_attributes *positioner); struct wlr_xdg_positioner_v6_attributes *positioner);
#endif #endif

View File

@ -38,6 +38,77 @@ static void popup_handle_new_popup(struct wl_listener *listener, void *data) {
popup_create(popup->view_child.view, wlr_popup); popup_create(popup->view_child.view, wlr_popup);
} }
static void popup_get_coords(struct wlr_xdg_popup_v6 *popup,
double *sx, double *sy) {
struct wlr_xdg_surface_v6 *parent = popup->parent;
double popup_sx = popup->geometry.x;
double popup_sy = popup->geometry.y;
while (parent->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) {
popup_sx += parent->popup->geometry.x;
popup_sy += parent->popup->geometry.y;
parent = parent->popup->parent;
}
*sx = popup_sx + parent->geometry.x;
*sy = popup_sy + parent->geometry.y;
}
static void popup_is_constrained(struct roots_xdg_popup_v6 *popup,
bool *x_constrained, bool *y_constrained) {
struct roots_view *view = popup->view_child.view;
struct wlr_output_layout *layout = view->desktop->layout;
struct wlr_xdg_popup_v6 *wlr_popup = popup->wlr_popup;
int popup_width = wlr_popup->geometry.width;
int popup_height = wlr_popup->geometry.height;
int anchor_lx, anchor_ly;
wlr_xdg_popup_v6_get_anchor_point(wlr_popup, &anchor_lx, &anchor_ly);
double popup_lx, popup_ly;
popup_get_coords(wlr_popup, &popup_lx, &popup_ly);
popup_lx += view->x;
popup_ly += view->y;
anchor_lx += popup_lx;
anchor_ly += popup_ly;
double dest_x = 0, dest_y = 0;
wlr_output_layout_closest_point(layout, NULL, anchor_lx, anchor_ly,
&dest_x, &dest_y);
struct wlr_output *output =
wlr_output_layout_output_at(layout, dest_x, dest_y);
// XXX: handle empty output layout
assert(output);
struct wlr_box *output_box = wlr_output_layout_get_box(layout, output);
*x_constrained = popup_lx <= output_box->x ||
popup_lx + popup_width >= output_box->x + output_box->width;
*y_constrained = popup_ly <= output_box->y ||
popup_ly + popup_height >= output_box->y + output_box->height;
}
static void popup_unconstrain_flip(struct roots_xdg_popup_v6 *popup) {
bool x_constrained, y_constrained;
popup_is_constrained(popup, &x_constrained, &y_constrained);
if (x_constrained) {
wlr_positioner_v6_invert_x(&popup->wlr_popup->positioner);
}
if (y_constrained) {
wlr_positioner_v6_invert_y(&popup->wlr_popup->positioner);
}
popup->wlr_popup->geometry =
wlr_xdg_positioner_v6_get_geometry(&popup->wlr_popup->positioner);
}
static void popup_unconstrain(struct roots_xdg_popup_v6 *popup) {
popup_unconstrain_flip(popup);
// TODO popup_unconstrain_slide(popup);
// TODO popup_unconstrain_resize(popup);
}
static struct roots_xdg_popup_v6 *popup_create(struct roots_view *view, static struct roots_xdg_popup_v6 *popup_create(struct roots_view *view,
struct wlr_xdg_popup_v6 *wlr_popup) { struct wlr_xdg_popup_v6 *wlr_popup) {
struct roots_xdg_popup_v6 *popup = struct roots_xdg_popup_v6 *popup =
@ -45,55 +116,6 @@ static struct roots_xdg_popup_v6 *popup_create(struct roots_view *view,
if (popup == NULL) { if (popup == NULL) {
return NULL; return NULL;
} }
struct wlr_xdg_surface_v6 *parent = wlr_popup->parent;
double popup_lx = wlr_popup->geometry.x;
double popup_ly = wlr_popup->geometry.y;
while (parent->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) {
popup_lx += parent->popup->geometry.x;
popup_ly += parent->popup->geometry.y;
parent = parent->popup->parent;
}
popup_lx += view->x + parent->geometry.x;
popup_ly += view->y + parent->geometry.y;
int popup_width = wlr_popup->geometry.width;
int popup_height = wlr_popup->geometry.height;
int anchor_x, anchor_y;
wlr_xdg_popup_v6_get_anchor_point(wlr_popup, &anchor_x, &anchor_y);
anchor_x += popup_lx;
anchor_y += popup_ly;
struct wlr_output_layout *layout = view->desktop->layout;
// get the output that contains (or closest to) the anchor point
struct wlr_output *output =
wlr_output_layout_output_at(layout, anchor_x, anchor_y);
if (output == NULL) {
// TODO find the closest output to the anchor
assert(false);
}
// does the output completely contain the popup?
struct wlr_box *output_box = wlr_output_layout_get_box(layout, output);
bool output_contains_popup_x = popup_lx >= output_box->x &&
popup_lx + popup_width <= output_box->x + output_box->width;
bool output_contains_popup_y = popup_ly >= output_box->y &&
popup_ly + popup_height <= output_box->y + output_box->height;
if (!output_contains_popup_x) {
// TODO flip_x
// TODO slide_x
// TODO resize_x
}
if (!output_contains_popup_y) {
// TODO flip_y
// TODO slide_y
// TODO resize_y
}
popup->wlr_popup = wlr_popup; popup->wlr_popup = wlr_popup;
popup->view_child.destroy = popup_destroy; popup->view_child.destroy = popup_destroy;
view_child_init(&popup->view_child, view, wlr_popup->base->surface); view_child_init(&popup->view_child, view, wlr_popup->base->surface);
@ -101,6 +123,9 @@ static struct roots_xdg_popup_v6 *popup_create(struct roots_view *view,
wl_signal_add(&wlr_popup->base->events.destroy, &popup->destroy); wl_signal_add(&wlr_popup->base->events.destroy, &popup->destroy);
popup->new_popup.notify = popup_handle_new_popup; popup->new_popup.notify = popup_handle_new_popup;
wl_signal_add(&wlr_popup->base->events.new_popup, &popup->new_popup); wl_signal_add(&wlr_popup->base->events.new_popup, &popup->new_popup);
popup_unconstrain(popup);
return popup; return popup;
} }

View File

@ -399,9 +399,7 @@ static void xdg_shell_handle_create_positioner(struct wl_client *wl_client,
positioner, xdg_positioner_destroy); positioner, xdg_positioner_destroy);
} }
static struct wlr_box xdg_positioner_get_geometry( struct wlr_box wlr_xdg_positioner_v6_get_geometry(struct wlr_xdg_positioner_v6_attributes *positioner) {
struct wlr_xdg_positioner_v6_attributes *positioner,
struct wlr_xdg_surface_v6 *surface, struct wlr_xdg_surface_v6 *parent) {
struct wlr_box geometry = { struct wlr_box geometry = {
.x = positioner->offset.x, .x = positioner->offset.x,
.y = positioner->offset.y, .y = positioner->offset.y,
@ -589,7 +587,7 @@ static void xdg_surface_handle_get_popup(struct wl_client *client,
surface->popup->base = surface; surface->popup->base = surface;
surface->popup->parent = parent; surface->popup->parent = parent;
surface->popup->geometry = surface->popup->geometry =
xdg_positioner_get_geometry(positioner->attrs, surface, parent); wlr_xdg_positioner_v6_get_geometry(positioner->attrs);
// positioner properties // positioner properties
memcpy(&surface->popup->positioner, positioner->attrs, memcpy(&surface->popup->positioner, positioner->attrs,
@ -1675,50 +1673,39 @@ void wlr_xdg_popup_v6_get_anchor_point(struct wlr_xdg_popup_v6 *popup,
*/ */
} }
void wlr_positioner_v6_invert( void wlr_positioner_v6_invert_x(struct wlr_xdg_positioner_v6_attributes *positioner) {
if (positioner->anchor & WLR_POSITIONER_V6_ANCHOR_LEFT) {
positioner->anchor &= ~WLR_POSITIONER_V6_ANCHOR_LEFT;
positioner->anchor |= WLR_POSITIONER_V6_ANCHOR_RIGHT;
} else if (positioner->anchor & WLR_POSITIONER_V6_ANCHOR_RIGHT) {
positioner->anchor &= ~WLR_POSITIONER_V6_ANCHOR_RIGHT;
positioner->anchor |= WLR_POSITIONER_V6_ANCHOR_LEFT;
}
if (positioner->gravity & WLR_POSITIONER_V6_GRAVITY_RIGHT) {
positioner->gravity &= ~WLR_POSITIONER_V6_GRAVITY_RIGHT;
positioner->gravity |= WLR_POSITIONER_V6_GRAVITY_LEFT;
} else if (positioner->gravity & WLR_POSITIONER_V6_GRAVITY_LEFT) {
positioner->gravity &= ~WLR_POSITIONER_V6_GRAVITY_LEFT;
positioner->gravity |= WLR_POSITIONER_V6_GRAVITY_RIGHT;
}
}
void wlr_positioner_v6_invert_y(
struct wlr_xdg_positioner_v6_attributes *positioner) { struct wlr_xdg_positioner_v6_attributes *positioner) {
enum wlr_positioner_v6_anchor anchor = positioner->anchor; if (positioner->anchor & WLR_POSITIONER_V6_ANCHOR_TOP) {
positioner->anchor &= ~WLR_POSITIONER_V6_ANCHOR_TOP;
if (anchor == WLR_POSITIONER_V6_ANCHOR_NONE) { positioner->anchor |= WLR_POSITIONER_V6_ANCHOR_BOTTOM;
// already inverted } else if (positioner->anchor & WLR_POSITIONER_V6_ANCHOR_BOTTOM) {
} else if (anchor == WLR_POSITIONER_V6_ANCHOR_TOP) { positioner->anchor &= ~WLR_POSITIONER_V6_ANCHOR_BOTTOM;
positioner->anchor = WLR_POSITIONER_V6_ANCHOR_BOTTOM; positioner->anchor |= WLR_POSITIONER_V6_ANCHOR_TOP;
} else if (anchor == WLR_POSITIONER_V6_ANCHOR_BOTTOM) {
positioner->anchor = WLR_POSITIONER_V6_ANCHOR_TOP;
} else if (anchor == WLR_POSITIONER_V6_ANCHOR_LEFT) {
positioner->anchor = WLR_POSITIONER_V6_ANCHOR_RIGHT;
} else if (anchor == WLR_POSITIONER_V6_ANCHOR_RIGHT) {
positioner->anchor = WLR_POSITIONER_V6_ANCHOR_LEFT;
} else if (anchor == (WLR_POSITIONER_V6_ANCHOR_TOP |
WLR_POSITIONER_V6_ANCHOR_LEFT)) {
positioner->anchor = WLR_POSITIONER_V6_ANCHOR_BOTTOM | WLR_POSITIONER_V6_ANCHOR_RIGHT;
} else if (anchor == (WLR_POSITIONER_V6_ANCHOR_TOP |
WLR_POSITIONER_V6_ANCHOR_RIGHT)) {
positioner->anchor = WLR_POSITIONER_V6_ANCHOR_BOTTOM | WLR_POSITIONER_V6_ANCHOR_LEFT;
} else if (anchor == (WLR_POSITIONER_V6_ANCHOR_BOTTOM |
WLR_POSITIONER_V6_ANCHOR_LEFT)) {
positioner->anchor = WLR_POSITIONER_V6_ANCHOR_TOP | WLR_POSITIONER_V6_ANCHOR_RIGHT;
} else if (anchor == (WLR_POSITIONER_V6_ANCHOR_BOTTOM |
WLR_POSITIONER_V6_ANCHOR_RIGHT)) {
positioner->anchor = WLR_POSITIONER_V6_ANCHOR_TOP | WLR_POSITIONER_V6_ANCHOR_LEFT;
} }
enum wlr_positioner_v6_gravity gravity = positioner->gravity; if (positioner->gravity & WLR_POSITIONER_V6_GRAVITY_TOP) {
switch (gravity) { positioner->gravity &= ~WLR_POSITIONER_V6_GRAVITY_TOP;
case WLR_POSITIONER_V6_GRAVITY_NONE: positioner->gravity |= WLR_POSITIONER_V6_GRAVITY_BOTTOM;
// already inverted } else if (positioner->gravity & WLR_POSITIONER_V6_GRAVITY_BOTTOM) {
break; positioner->gravity &= ~WLR_POSITIONER_V6_GRAVITY_BOTTOM;
case WLR_POSITIONER_V6_GRAVITY_TOP: positioner->gravity |= WLR_POSITIONER_V6_GRAVITY_TOP;
positioner->gravity = WLR_POSITIONER_V6_GRAVITY_BOTTOM;
break;
case WLR_POSITIONER_V6_GRAVITY_BOTTOM:
positioner->gravity = WLR_POSITIONER_V6_GRAVITY_TOP;
break;
case WLR_POSITIONER_V6_GRAVITY_LEFT:
positioner->gravity = WLR_POSITIONER_V6_GRAVITY_RIGHT;
break;
case WLR_POSITIONER_V6_GRAVITY_RIGHT:
positioner->gravity = WLR_POSITIONER_V6_GRAVITY_LEFT;
break;
} }
} }