From 61fabede14bb3a8fe9ee5a249352cd405fd1b9bf Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 2 Apr 2018 10:57:45 -0400 Subject: Address review comments --- sway/tree/view.c | 137 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 79 insertions(+), 58 deletions(-) (limited to 'sway/tree/view.c') diff --git a/sway/tree/view.c b/sway/tree/view.c index d7a52e19..73e3d445 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -62,55 +62,10 @@ const char *view_get_instance(struct sway_view *view) { return NULL; } -static void view_update_outputs(struct sway_view *view, - const struct wlr_box *before) { - struct wlr_output_layout *output_layout = - root_container.sway_root->output_layout; - struct wlr_box box = { - .x = view->swayc->x, - .y = view->swayc->y, - .width = view->width, - .height = view->height, - }; - struct wlr_output_layout_output *layout_output; - wl_list_for_each(layout_output, &output_layout->outputs, link) { - bool intersected = before != NULL && wlr_output_layout_intersects( - output_layout, layout_output->output, before); - bool intersects = wlr_output_layout_intersects(output_layout, - layout_output->output, &box); - if (intersected && !intersects) { - wlr_surface_send_leave(view->surface, layout_output->output); - } - if (!intersected && intersects) { - wlr_surface_send_enter(view->surface, layout_output->output); - } - } -} - -void view_set_size(struct sway_view *view, int width, int height) { - if (view->impl->set_size) { - struct wlr_box box = { - .x = view->swayc->x, - .y = view->swayc->y, - .width = view->width, - .height = view->height, - }; - view->impl->set_size(view, width, height); - view_update_outputs(view, &box); - } -} - -// TODO make view coordinates in layout coordinates -void view_set_position(struct sway_view *view, double ox, double oy) { - if (view->impl->set_position) { - struct wlr_box box = { - .x = view->swayc->x, - .y = view->swayc->y, - .width = view->width, - .height = view->height, - }; - view->impl->set_position(view, ox, oy); - view_update_outputs(view, &box); +void view_configure(struct sway_view *view, double ox, double oy, int width, + int height) { + if (view->impl->configure) { + view->impl->configure(view, ox, oy, width, height); } } @@ -136,6 +91,56 @@ struct sway_container *container_view_destroy(struct sway_container *view) { return parent; } +void view_damage_whole(struct sway_view *view) { + for (int i = 0; i < root_container.children->length; ++i) { + struct sway_container *cont = root_container.children->items[i]; + if (cont->type == C_OUTPUT) { + output_damage_whole_view(cont->sway_output, view); + } + } +} + +void view_damage_from(struct sway_view *view) { + // TODO + view_damage_whole(view); +} + +static void view_get_layout_box(struct sway_view *view, struct wlr_box *box) { + struct sway_container *cont = container_parent(view->swayc, C_OUTPUT); + + struct wlr_output_layout *output_layout = + root_container.sway_root->output_layout; + struct wlr_box *output_box = wlr_output_layout_get_box(output_layout, + cont->sway_output->wlr_output); + + box->x = output_box->x + view->swayc->x; + box->y = output_box->y + view->swayc->y; + box->width = view->width; + box->height = view->height; +} + +static void view_update_outputs(struct sway_view *view, + const struct wlr_box *before) { + struct wlr_box box; + view_get_layout_box(view, &box); + + struct wlr_output_layout *output_layout = + root_container.sway_root->output_layout; + struct wlr_output_layout_output *layout_output; + wl_list_for_each(layout_output, &output_layout->outputs, link) { + bool intersected = before != NULL && wlr_output_layout_intersects( + output_layout, layout_output->output, before); + bool intersects = wlr_output_layout_intersects(output_layout, + layout_output->output, &box); + if (intersected && !intersects) { + wlr_surface_send_leave(view->surface, layout_output->output); + } + if (!intersected && intersects) { + wlr_surface_send_enter(view->surface, layout_output->output); + } + } +} + void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { if (!sway_assert(view->surface == NULL, "cannot map mapped view")) { return; @@ -153,6 +158,7 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { sway_input_manager_set_focus(input_manager, cont); view_damage_whole(view); + view_update_outputs(view, NULL); } void view_map_unmanaged(struct sway_view *view, @@ -168,6 +174,8 @@ void view_map_unmanaged(struct sway_view *view, &view->unmanaged_view_link); view_damage_whole(view); + // TODO: make this work for unmanaged views + //view_update_outputs(view, NULL); } void view_unmap(struct sway_view *view) { @@ -186,17 +194,30 @@ void view_unmap(struct sway_view *view) { view->surface = NULL; } -void view_damage_whole(struct sway_view *view) { - struct sway_container *cont = NULL; - for (int i = 0; i < root_container.children->length; ++i) { - cont = root_container.children->items[i]; - if (cont->type == C_OUTPUT) { - output_damage_whole_view(cont->sway_output, view); - } +void view_update_position(struct sway_view *view, double ox, double oy) { + if (view->swayc->x == ox && view->swayc->y == oy) { + return; } + + struct wlr_box box; + view_get_layout_box(view, &box); + view_damage_whole(view); + view->swayc->x = ox; + view->swayc->y = oy; + view_update_outputs(view, &box); + view_damage_whole(view); } -void view_damage_from(struct sway_view *view) { - // TODO +void view_update_size(struct sway_view *view, int width, int height) { + if (view->width == width && view->height == height) { + return; + } + + struct wlr_box box; + view_get_layout_box(view, &box); + view_damage_whole(view); + view->width = width; + view->height = height; + view_update_outputs(view, &box); view_damage_whole(view); } -- cgit v1.2.3-54-g00ecf