aboutsummaryrefslogtreecommitdiff
path: root/sway/tree
diff options
context:
space:
mode:
authoremersion <contact@emersion.fr>2018-04-02 10:57:45 -0400
committeremersion <contact@emersion.fr>2018-04-02 10:57:45 -0400
commit61fabede14bb3a8fe9ee5a249352cd405fd1b9bf (patch)
treede0cc1378f2edba5cc194c8dcebe4d5fdaeda647 /sway/tree
parent1d68f9ecca8870f2f2a6823072c77657436b123a (diff)
downloadsway-61fabede14bb3a8fe9ee5a249352cd405fd1b9bf.tar.xz
Address review comments
Diffstat (limited to 'sway/tree')
-rw-r--r--sway/tree/layout.c8
-rw-r--r--sway/tree/output.c1
-rw-r--r--sway/tree/view.c137
3 files changed, 85 insertions, 61 deletions
diff --git a/sway/tree/layout.c b/sway/tree/layout.c
index ce0682dc..3fec02a1 100644
--- a/sway/tree/layout.c
+++ b/sway/tree/layout.c
@@ -261,7 +261,7 @@ void arrange_windows(struct sway_container *container,
{
container->width = width;
container->height = height;
- view_set_size(container->sway_view,
+ view_configure(container->sway_view, container->x, container->y,
container->width, container->height);
wlr_log(L_DEBUG, "Set view to %.f x %.f @ %.f, %.f",
container->width, container->height,
@@ -322,7 +322,8 @@ static void apply_horiz_layout(struct sway_container *container,
wlr_log(L_DEBUG,
"Calculating arrangement for %p:%d (will scale %f by %f)",
child, child->type, width, scale);
- view_set_position(child->sway_view, child_x, y);
+ view_configure(child->sway_view, child_x, y, child->width,
+ child->height);
if (i == end - 1) {
double remaining_width = x + width - child_x;
@@ -373,7 +374,8 @@ void apply_vert_layout(struct sway_container *container,
wlr_log(L_DEBUG,
"Calculating arrangement for %p:%d (will scale %f by %f)",
child, child->type, height, scale);
- view_set_position(child->sway_view, x, child_y);
+ view_configure(child->sway_view, x, child_y, child->width,
+ child->height);
if (i == end - 1) {
double remaining_height = y + height - child_y;
diff --git a/sway/tree/output.c b/sway/tree/output.c
index 7248fd00..80a36ac7 100644
--- a/sway/tree/output.c
+++ b/sway/tree/output.c
@@ -29,6 +29,7 @@ struct sway_container *container_output_destroy(struct sway_container *output) {
wl_list_remove(&output->sway_output->destroy.link);
wl_list_remove(&output->sway_output->mode.link);
wl_list_remove(&output->sway_output->transform.link);
+ wl_list_remove(&output->sway_output->scale.link);
wl_list_remove(&output->sway_output->damage_destroy.link);
wl_list_remove(&output->sway_output->damage_frame.link);
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);
}