rootston: use box for views position

This commit is contained in:
Louis Taylor 2018-12-05 09:01:25 +00:00
parent d703ae45dd
commit 0f3a061f60
No known key found for this signature in database
GPG Key ID: 8E81A6DAE13E7098
10 changed files with 89 additions and 90 deletions

View File

@ -99,7 +99,7 @@ void view_destroy(struct roots_view *view);
void view_activate(struct roots_view *view, bool activate); void view_activate(struct roots_view *view, bool activate);
void view_apply_damage(struct roots_view *view); void view_apply_damage(struct roots_view *view);
void view_damage_whole(struct roots_view *view); void view_damage_whole(struct roots_view *view);
void view_update_position(struct roots_view *view, double x, double y); void view_update_position(struct roots_view *view, int x, int y);
void view_update_size(struct roots_view *view, int width, int height); void view_update_size(struct roots_view *view, int width, int height);
void view_update_decorated(struct roots_view *view, bool decorated); void view_update_decorated(struct roots_view *view, bool decorated);
void view_initial_focus(struct roots_view *view); void view_initial_focus(struct roots_view *view);

View File

@ -88,8 +88,7 @@ struct roots_view {
struct roots_desktop *desktop; struct roots_desktop *desktop;
struct wl_list link; // roots_desktop::views struct wl_list link; // roots_desktop::views
double x, y; struct wlr_box box;
uint32_t width, height;
float rotation; float rotation;
float alpha; float alpha;

View File

@ -190,8 +190,8 @@ void roots_cursor_update_position(struct roots_cursor *cursor,
if (view != NULL) { if (view != NULL) {
double dx = cursor->cursor->x - cursor->offs_x; double dx = cursor->cursor->x - cursor->offs_x;
double dy = cursor->cursor->y - cursor->offs_y; double dy = cursor->cursor->y - cursor->offs_y;
double x = view->x; double x = view->box.x;
double y = view->y; double y = view->box.y;
int width = cursor->view_width; int width = cursor->view_width;
int height = cursor->view_height; int height = cursor->view_height;
if (cursor->resize_edges & WLR_EDGE_TOP) { if (cursor->resize_edges & WLR_EDGE_TOP) {
@ -220,8 +220,8 @@ void roots_cursor_update_position(struct roots_cursor *cursor,
case ROOTS_CURSOR_ROTATE: case ROOTS_CURSOR_ROTATE:
view = roots_seat_get_focus(seat); view = roots_seat_get_focus(seat);
if (view != NULL) { if (view != NULL) {
int ox = view->x + view->wlr_surface->current.width/2, int ox = view->box.x + view->wlr_surface->current.width/2,
oy = view->y + view->wlr_surface->current.height/2; oy = view->box.y + view->wlr_surface->current.height/2;
int ux = cursor->offs_x - ox, int ux = cursor->offs_x - ox,
uy = cursor->offs_y - oy; uy = cursor->offs_y - oy;
int vx = cursor->cursor->x - ox, int vx = cursor->cursor->x - ox,
@ -322,11 +322,11 @@ void roots_cursor_handle_motion(struct roots_cursor *cursor,
double lx2 = lx1 + dx; double lx2 = lx1 + dx;
double ly2 = ly1 + dy; double ly2 = ly1 + dy;
double sx1 = lx1 - view->x; double sx1 = lx1 - view->box.x;
double sy1 = ly1 - view->y; double sy1 = ly1 - view->box.y;
double sx2 = lx2 - view->x; double sx2 = lx2 - view->box.x;
double sy2 = ly2 - view->y; double sy2 = ly2 - view->box.y;
double sx2_confined, sy2_confined; double sx2_confined, sy2_confined;
if (!wlr_region_confine(&cursor->confine, sx1, sy1, sx2, sy2, if (!wlr_region_confine(&cursor->confine, sx1, sy1, sx2, sy2,
@ -354,7 +354,7 @@ void roots_cursor_handle_motion_absolute(struct roots_cursor *cursor,
if (cursor->active_constraint && if (cursor->active_constraint &&
!pixman_region32_contains_point(&cursor->confine, !pixman_region32_contains_point(&cursor->confine,
floor(lx - view->x), floor(ly - view->y), NULL)) { floor(lx - view->box.x), floor(ly - view->box.y), NULL)) {
return; return;
} }
} }
@ -474,7 +474,7 @@ void roots_cursor_handle_tool_axis(struct roots_cursor *cursor,
if (cursor->active_constraint && if (cursor->active_constraint &&
!pixman_region32_contains_point(&cursor->confine, !pixman_region32_contains_point(&cursor->confine,
floor(lx - view->x), floor(ly - view->y), NULL)) { floor(lx - view->box.x), floor(ly - view->box.y), NULL)) {
return; return;
} }
} }
@ -598,11 +598,11 @@ void roots_cursor_constrain(struct roots_cursor *cursor,
double sx = (boxes[0].x1 + boxes[0].x2) / 2.; double sx = (boxes[0].x1 + boxes[0].x2) / 2.;
double sy = (boxes[0].y1 + boxes[0].y2) / 2.; double sy = (boxes[0].y1 + boxes[0].y2) / 2.;
rotate_child_position(&sx, &sy, 0, 0, view->width, view->height, rotate_child_position(&sx, &sy, 0, 0, view->box.width, view->box.height,
view->rotation); view->rotation);
double lx = view->x + sx; double lx = view->box.x + sx;
double ly = view->y + sy; double ly = view->box.y + sy;
wlr_cursor_warp_closest(cursor->cursor, NULL, lx, ly); wlr_cursor_warp_closest(cursor->cursor, NULL, lx, ly);
} }

View File

@ -48,10 +48,10 @@ struct roots_view *view_create(struct roots_desktop *desktop) {
} }
void view_get_box(const struct roots_view *view, struct wlr_box *box) { void view_get_box(const struct roots_view *view, struct wlr_box *box) {
box->x = view->x; box->x = view->box.x;
box->y = view->y; box->y = view->box.y;
box->width = view->width; box->width = view->box.width;
box->height = view->height; box->height = view->box.height;
} }
void view_get_deco_box(const struct roots_view *view, struct wlr_box *box) { void view_get_deco_box(const struct roots_view *view, struct wlr_box *box) {
@ -131,7 +131,7 @@ static void view_update_output(const struct roots_view *view,
} }
void view_move(struct roots_view *view, double x, double y) { void view_move(struct roots_view *view, double x, double y) {
if (view->x == x && view->y == y) { if (view->box.x == x && view->box.y == y) {
return; return;
} }
@ -162,8 +162,8 @@ void view_resize(struct roots_view *view, uint32_t width, uint32_t height) {
void view_move_resize(struct roots_view *view, double x, double y, void view_move_resize(struct roots_view *view, double x, double y,
uint32_t width, uint32_t height) { uint32_t width, uint32_t height) {
bool update_x = x != view->x; bool update_x = x != view->box.x;
bool update_y = y != view->y; bool update_y = y != view->box.y;
if (!update_x && !update_y) { if (!update_x && !update_y) {
view_resize(view, width, height); view_resize(view, width, height);
return; return;
@ -190,8 +190,8 @@ static struct wlr_output *view_get_output(struct roots_view *view) {
double output_x, output_y; double output_x, output_y;
wlr_output_layout_closest_point(view->desktop->layout, NULL, wlr_output_layout_closest_point(view->desktop->layout, NULL,
view->x + (double)view_box.width/2, view->box.x + (double)view_box.width/2,
view->y + (double)view_box.height/2, view->box.y + (double)view_box.height/2,
&output_x, &output_y); &output_x, &output_y);
return wlr_output_layout_output_at(view->desktop->layout, output_x, return wlr_output_layout_output_at(view->desktop->layout, output_x,
output_y); output_y);
@ -227,11 +227,11 @@ void view_maximize(struct roots_view *view, bool maximized) {
if (!view->maximized && maximized) { if (!view->maximized && maximized) {
view->maximized = true; view->maximized = true;
view->saved.x = view->x; view->saved.x = view->box.x;
view->saved.y = view->y; view->saved.y = view->box.y;
view->saved.rotation = view->rotation; view->saved.rotation = view->rotation;
view->saved.width = view->width; view->saved.width = view->box.width;
view->saved.height = view->height; view->saved.height = view->box.height;
view_arrange_maximized(view); view_arrange_maximized(view);
} }
@ -272,8 +272,8 @@ void view_set_fullscreen(struct roots_view *view, bool fullscreen,
struct wlr_box view_box; struct wlr_box view_box;
view_get_box(view, &view_box); view_get_box(view, &view_box);
view->saved.x = view->x; view->saved.x = view->box.x;
view->saved.y = view->y; view->saved.y = view->box.y;
view->saved.rotation = view->rotation; view->saved.rotation = view->rotation;
view->saved.width = view_box.width; view->saved.width = view_box.width;
view->saved.height = view_box.height; view->saved.height = view_box.height;
@ -500,7 +500,7 @@ void view_unmap(struct roots_view *view) {
} }
view->wlr_surface = NULL; view->wlr_surface = NULL;
view->width = view->height = 0; view->box.width = view->box.height = 0;
} }
void view_initial_focus(struct roots_view *view) { void view_initial_focus(struct roots_view *view) {
@ -536,25 +536,25 @@ void view_damage_whole(struct roots_view *view) {
} }
} }
void view_update_position(struct roots_view *view, double x, double y) { void view_update_position(struct roots_view *view, int x, int y) {
if (view->x == x && view->y == y) { if (view->box.x == x && view->box.y == y) {
return; return;
} }
view_damage_whole(view); view_damage_whole(view);
view->x = x; view->box.x = x;
view->y = y; view->box.y = y;
view_damage_whole(view); view_damage_whole(view);
} }
void view_update_size(struct roots_view *view, int width, int height) { void view_update_size(struct roots_view *view, int width, int height) {
if (view->width == width && view->height == height) { if (view->box.width == width && view->box.height == height) {
return; return;
} }
view_damage_whole(view); view_damage_whole(view);
view->width = width; view->box.width = width;
view->height = height; view->box.height = height;
view_damage_whole(view); view_damage_whole(view);
} }
@ -585,8 +585,8 @@ static bool view_at(struct roots_view *view, double lx, double ly,
return false; return false;
} }
double view_sx = lx - view->x; double view_sx = lx - view->box.x;
double view_sy = ly - view->y; double view_sy = ly - view->box.y;
struct wlr_surface_state *state = &view->wlr_surface->current; struct wlr_surface_state *state = &view->wlr_surface->current;
struct wlr_box box = { struct wlr_box box = {
@ -806,10 +806,10 @@ static void handle_constraint_destroy(struct wl_listener *listener,
double sy = wlr_constraint->current.cursor_hint.y; double sy = wlr_constraint->current.cursor_hint.y;
struct roots_view *view = seat->cursor->pointer_view->view; struct roots_view *view = seat->cursor->pointer_view->view;
rotate_child_position(&sx, &sy, 0, 0, view->width, view->height, rotate_child_position(&sx, &sy, 0, 0, view->box.width, view->box.height,
view->rotation); view->rotation);
double lx = view->x + sx; double lx = view->box.x + sx;
double ly = view->y + sy; double ly = view->box.y + sy;
wlr_cursor_warp(seat->cursor->cursor, NULL, lx, ly); wlr_cursor_warp(seat->cursor->cursor, NULL, lx, ly);
} }

View File

@ -67,8 +67,8 @@ static void surface_for_each_surface(struct wlr_surface *surface,
static void view_for_each_surface(struct roots_view *view, static void view_for_each_surface(struct roots_view *view,
struct layout_data *layout_data, wlr_surface_iterator_func_t iterator, struct layout_data *layout_data, wlr_surface_iterator_func_t iterator,
void *user_data) { void *user_data) {
layout_data->x = view->x; layout_data->x = view->box.x;
layout_data->y = view->y; layout_data->y = view->box.y;
layout_data->width = view->wlr_surface->current.width; layout_data->width = view->wlr_surface->current.width;
layout_data->height = view->wlr_surface->current.height; layout_data->height = view->wlr_surface->current.height;
layout_data->rotation = view->rotation; layout_data->rotation = view->rotation;
@ -304,13 +304,13 @@ static void get_decoration_box(struct roots_view *view,
struct wlr_box deco_box; struct wlr_box deco_box;
view_get_deco_box(view, &deco_box); view_get_deco_box(view, &deco_box);
double sx = deco_box.x - view->x; double sx = deco_box.x - view->box.x;
double sy = deco_box.y - view->y; double sy = deco_box.y - view->box.y;
rotate_child_position(&sx, &sy, deco_box.width, deco_box.height, rotate_child_position(&sx, &sy, deco_box.width, deco_box.height,
view->wlr_surface->current.width, view->wlr_surface->current.width,
view->wlr_surface->current.height, view->rotation); view->wlr_surface->current.height, view->rotation);
double x = sx + view->x; double x = sx + view->box.x;
double y = sy + view->y; double y = sy + view->box.y;
wlr_output_layout_output_coords(output->desktop->layout, wlr_output, &x, &y); wlr_output_layout_output_coords(output->desktop->layout, wlr_output, &x, &y);

View File

@ -1341,8 +1341,8 @@ void roots_seat_begin_move(struct roots_seat *seat, struct roots_view *view) {
cursor->view_x = view->saved.x; cursor->view_x = view->saved.x;
cursor->view_y = view->saved.y; cursor->view_y = view->saved.y;
} else { } else {
cursor->view_x = view->x; cursor->view_x = view->box.x;
cursor->view_y = view->y; cursor->view_y = view->box.y;
} }
view_maximize(view, false); view_maximize(view, false);
wlr_seat_pointer_clear_focus(seat->seat); wlr_seat_pointer_clear_focus(seat->seat);
@ -1363,8 +1363,8 @@ void roots_seat_begin_resize(struct roots_seat *seat, struct roots_view *view,
cursor->view_width = view->saved.width; cursor->view_width = view->saved.width;
cursor->view_height = view->saved.height; cursor->view_height = view->saved.height;
} else { } else {
cursor->view_x = view->x; cursor->view_x = view->box.x;
cursor->view_y = view->y; cursor->view_y = view->box.y;
struct wlr_box box; struct wlr_box box;
view_get_box(view, &box); view_get_box(view, &box);
cursor->view_width = box.width; cursor->view_width = box.width;

View File

@ -162,8 +162,8 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) {
int height = wlr_surface->current.height; int height = wlr_surface->current.height;
view_update_size(view, width, height); view_update_size(view, width, height);
double x = view->x; double x = view->box.x;
double y = view->y; double y = view->box.y;
if (view->pending_move_resize.update_x) { if (view->pending_move_resize.update_x) {
x = view->pending_move_resize.x + view->pending_move_resize.width - x = view->pending_move_resize.x + view->pending_move_resize.width -
width; width;
@ -236,8 +236,8 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
return; return;
} }
view->type = ROOTS_WL_SHELL_VIEW; view->type = ROOTS_WL_SHELL_VIEW;
view->width = surface->surface->current.width; view->box.width = surface->surface->current.width;
view->height = surface->surface->current.height; view->box.height = surface->surface->current.height;
view->wl_shell_surface = surface; view->wl_shell_surface = surface;
view->roots_wl_shell_surface = roots_surface; view->roots_wl_shell_surface = roots_surface;
@ -262,8 +262,8 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
} }
if (found) { if (found) {
view_move(view, view_move(view,
parent->x + surface->transient_state->x, parent->box.x + surface->transient_state->x,
parent->y + surface->transient_state->y); parent->box.y + surface->transient_state->y);
} }
} }
} }

View File

@ -72,8 +72,8 @@ static void popup_unconstrain(struct roots_xdg_popup *popup) {
int popup_lx, popup_ly; int popup_lx, popup_ly;
wlr_xdg_popup_get_toplevel_coords(wlr_popup, wlr_popup->geometry.x, wlr_xdg_popup_get_toplevel_coords(wlr_popup, wlr_popup->geometry.x,
wlr_popup->geometry.y, &popup_lx, &popup_ly); wlr_popup->geometry.y, &popup_lx, &popup_ly);
popup_lx += view->x; popup_lx += view->box.x;
popup_ly += view->y; popup_ly += view->box.y;
anchor_lx += popup_lx; anchor_lx += popup_lx;
anchor_ly += popup_ly; anchor_ly += popup_ly;
@ -95,8 +95,8 @@ static void popup_unconstrain(struct roots_xdg_popup *popup) {
// the output box expressed in the coordinate system of the toplevel parent // the output box expressed in the coordinate system of the toplevel parent
// of the popup // of the popup
struct wlr_box output_toplevel_sx_box = { struct wlr_box output_toplevel_sx_box = {
.x = output->lx - view->x, .x = output->lx - view->box.x,
.y = output->ly - view->y, .y = output->ly - view->box.y,
.width = width, .width = width,
.height = height .height = height
}; };
@ -193,8 +193,8 @@ static void move_resize(struct roots_view *view, double x, double y,
return; return;
} }
bool update_x = x != view->x; bool update_x = x != view->box.x;
bool update_y = y != view->y; bool update_y = y != view->box.y;
uint32_t constrained_width, constrained_height; uint32_t constrained_width, constrained_height;
apply_size_constraints(surface, width, height, &constrained_width, apply_size_constraints(surface, width, height, &constrained_width,
@ -345,8 +345,8 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) {
uint32_t pending_serial = uint32_t pending_serial =
roots_surface->pending_move_resize_configure_serial; roots_surface->pending_move_resize_configure_serial;
if (pending_serial > 0 && pending_serial >= surface->configure_serial) { if (pending_serial > 0 && pending_serial >= surface->configure_serial) {
double x = view->x; double x = view->box.x;
double y = view->y; double y = view->box.y;
if (view->pending_move_resize.update_x) { if (view->pending_move_resize.update_x) {
x = view->pending_move_resize.x + view->pending_move_resize.width - x = view->pending_move_resize.x + view->pending_move_resize.width -
size.width; size.width;
@ -377,8 +377,8 @@ static void handle_map(struct wl_listener *listener, void *data) {
struct wlr_box box; struct wlr_box box;
get_size(view, &box); get_size(view, &box);
view->width = box.width; view->box.width = box.width;
view->height = box.height; view->box.height = box.height;
view_map(view, view->xdg_surface->surface); view_map(view, view->xdg_surface->surface);
view_setup(view); view_setup(view);

View File

@ -73,8 +73,8 @@ static void popup_unconstrain(struct roots_xdg_popup_v6 *popup) {
int popup_lx, popup_ly; int popup_lx, popup_ly;
wlr_xdg_popup_v6_get_toplevel_coords(wlr_popup, wlr_popup->geometry.x, wlr_xdg_popup_v6_get_toplevel_coords(wlr_popup, wlr_popup->geometry.x,
wlr_popup->geometry.y, &popup_lx, &popup_ly); wlr_popup->geometry.y, &popup_lx, &popup_ly);
popup_lx += view->x; popup_lx += view->box.x;
popup_ly += view->y; popup_ly += view->box.y;
anchor_lx += popup_lx; anchor_lx += popup_lx;
anchor_ly += popup_ly; anchor_ly += popup_ly;
@ -96,8 +96,8 @@ static void popup_unconstrain(struct roots_xdg_popup_v6 *popup) {
// the output box expressed in the coordinate system of the toplevel parent // the output box expressed in the coordinate system of the toplevel parent
// of the popup // of the popup
struct wlr_box output_toplevel_sx_box = { struct wlr_box output_toplevel_sx_box = {
.x = output->lx - view->x, .x = output->lx - view->box.x,
.y = output->ly - view->y, .y = output->ly - view->box.y,
.width = width, .width = width,
.height = height .height = height
}; };
@ -193,8 +193,8 @@ static void move_resize(struct roots_view *view, double x, double y,
return; return;
} }
bool update_x = x != view->x; bool update_x = x != view->box.x;
bool update_y = y != view->y; bool update_y = y != view->box.y;
uint32_t constrained_width, constrained_height; uint32_t constrained_width, constrained_height;
apply_size_constraints(surface, width, height, &constrained_width, apply_size_constraints(surface, width, height, &constrained_width,
@ -344,8 +344,8 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) {
uint32_t pending_serial = uint32_t pending_serial =
roots_surface->pending_move_resize_configure_serial; roots_surface->pending_move_resize_configure_serial;
if (pending_serial > 0 && pending_serial >= surface->configure_serial) { if (pending_serial > 0 && pending_serial >= surface->configure_serial) {
double x = view->x; double x = view->box.x;
double y = view->y; double y = view->box.y;
if (view->pending_move_resize.update_x) { if (view->pending_move_resize.update_x) {
x = view->pending_move_resize.x + view->pending_move_resize.width - x = view->pending_move_resize.x + view->pending_move_resize.width -
size.width; size.width;
@ -376,8 +376,8 @@ static void handle_map(struct wl_listener *listener, void *data) {
struct wlr_box box; struct wlr_box box;
get_size(view, &box); get_size(view, &box);
view->width = box.width; view->box.width = box.width;
view->height = box.height; view->box.height = box.height;
view_map(view, view->xdg_surface_v6->surface); view_map(view, view->xdg_surface_v6->surface);
view_setup(view); view_setup(view);

View File

@ -64,8 +64,8 @@ static void move_resize(struct roots_view *view, double x, double y,
assert(view->type == ROOTS_XWAYLAND_VIEW); assert(view->type == ROOTS_XWAYLAND_VIEW);
struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface; struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface;
bool update_x = x != view->x; bool update_x = x != view->box.x;
bool update_y = y != view->y; bool update_y = y != view->box.y;
uint32_t constrained_width, constrained_height; uint32_t constrained_width, constrained_height;
apply_size_constraints(xwayland_surface, width, height, &constrained_width, apply_size_constraints(xwayland_surface, width, height, &constrained_width,
@ -210,8 +210,8 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) {
int height = wlr_surface->current.height; int height = wlr_surface->current.height;
view_update_size(view, width, height); view_update_size(view, width, height);
double x = view->x; double x = view->box.x;
double y = view->y; double y = view->box.y;
if (view->pending_move_resize.update_x) { if (view->pending_move_resize.update_x) {
x = view->pending_move_resize.x + view->pending_move_resize.width - x = view->pending_move_resize.x + view->pending_move_resize.width -
width; width;
@ -231,10 +231,10 @@ static void handle_map(struct wl_listener *listener, void *data) {
struct wlr_xwayland_surface *surface = data; struct wlr_xwayland_surface *surface = data;
struct roots_view *view = roots_surface->view; struct roots_view *view = roots_surface->view;
view->x = surface->x; view->box.x = surface->x;
view->y = surface->y; view->box.y = surface->y;
view->width = surface->surface->current.width; view->box.width = surface->surface->current.width;
view->height = surface->surface->current.height; view->box.height = surface->surface->current.height;
roots_surface->surface_commit.notify = handle_surface_commit; roots_surface->surface_commit.notify = handle_surface_commit;
wl_signal_add(&surface->surface->events.commit, wl_signal_add(&surface->surface->events.commit,
@ -307,8 +307,8 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
return; return;
} }
view->type = ROOTS_XWAYLAND_VIEW; view->type = ROOTS_XWAYLAND_VIEW;
view->x = (double)surface->x; view->box.x = surface->x;
view->y = (double)surface->y; view->box.y = surface->y;
view->xwayland_surface = surface; view->xwayland_surface = surface;
view->roots_xwayland_surface = roots_surface; view->roots_xwayland_surface = roots_surface;