aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/view.c
diff options
context:
space:
mode:
authorLibravatar emersion <contact@emersion.fr>2018-04-02 10:57:45 -0400
committerLibravatar emersion <contact@emersion.fr>2018-04-02 10:57:45 -0400
commit61fabede14bb3a8fe9ee5a249352cd405fd1b9bf (patch)
treede0cc1378f2edba5cc194c8dcebe4d5fdaeda647 /sway/tree/view.c
parentAdd sway_view_impl (diff)
downloadsway-61fabede14bb3a8fe9ee5a249352cd405fd1b9bf.tar.gz
sway-61fabede14bb3a8fe9ee5a249352cd405fd1b9bf.tar.zst
sway-61fabede14bb3a8fe9ee5a249352cd405fd1b9bf.zip
Address review comments
Diffstat (limited to 'sway/tree/view.c')
-rw-r--r--sway/tree/view.c137
1 files changed, 79 insertions, 58 deletions
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) {
62 return NULL; 62 return NULL;
63} 63}
64 64
65static void view_update_outputs(struct sway_view *view, 65void view_configure(struct sway_view *view, double ox, double oy, int width,
66 const struct wlr_box *before) { 66 int height) {
67 struct wlr_output_layout *output_layout = 67 if (view->impl->configure) {
68 root_container.sway_root->output_layout; 68 view->impl->configure(view, ox, oy, width, height);
69 struct wlr_box box = {
70 .x = view->swayc->x,
71 .y = view->swayc->y,
72 .width = view->width,
73 .height = view->height,
74 };
75 struct wlr_output_layout_output *layout_output;
76 wl_list_for_each(layout_output, &output_layout->outputs, link) {
77 bool intersected = before != NULL && wlr_output_layout_intersects(
78 output_layout, layout_output->output, before);
79 bool intersects = wlr_output_layout_intersects(output_layout,
80 layout_output->output, &box);
81 if (intersected && !intersects) {
82 wlr_surface_send_leave(view->surface, layout_output->output);
83 }
84 if (!intersected && intersects) {
85 wlr_surface_send_enter(view->surface, layout_output->output);
86 }
87 }
88}
89
90void view_set_size(struct sway_view *view, int width, int height) {
91 if (view->impl->set_size) {
92 struct wlr_box box = {
93 .x = view->swayc->x,
94 .y = view->swayc->y,
95 .width = view->width,
96 .height = view->height,
97 };
98 view->impl->set_size(view, width, height);
99 view_update_outputs(view, &box);
100 }
101}
102
103// TODO make view coordinates in layout coordinates
104void view_set_position(struct sway_view *view, double ox, double oy) {
105 if (view->impl->set_position) {
106 struct wlr_box box = {
107 .x = view->swayc->x,
108 .y = view->swayc->y,
109 .width = view->width,
110 .height = view->height,
111 };
112 view->impl->set_position(view, ox, oy);
113 view_update_outputs(view, &box);
114 } 69 }
115} 70}
116 71
@@ -136,6 +91,56 @@ struct sway_container *container_view_destroy(struct sway_container *view) {
136 return parent; 91 return parent;
137} 92}
138 93
94void view_damage_whole(struct sway_view *view) {
95 for (int i = 0; i < root_container.children->length; ++i) {
96 struct sway_container *cont = root_container.children->items[i];
97 if (cont->type == C_OUTPUT) {
98 output_damage_whole_view(cont->sway_output, view);
99 }
100 }
101}
102
103void view_damage_from(struct sway_view *view) {
104 // TODO
105 view_damage_whole(view);
106}
107
108static void view_get_layout_box(struct sway_view *view, struct wlr_box *box) {
109 struct sway_container *cont = container_parent(view->swayc, C_OUTPUT);
110
111 struct wlr_output_layout *output_layout =
112 root_container.sway_root->output_layout;
113 struct wlr_box *output_box = wlr_output_layout_get_box(output_layout,
114 cont->sway_output->wlr_output);
115
116 box->x = output_box->x + view->swayc->x;
117 box->y = output_box->y + view->swayc->y;
118 box->width = view->width;
119 box->height = view->height;
120}
121
122static void view_update_outputs(struct sway_view *view,
123 const struct wlr_box *before) {
124 struct wlr_box box;
125 view_get_layout_box(view, &box);
126
127 struct wlr_output_layout *output_layout =
128 root_container.sway_root->output_layout;
129 struct wlr_output_layout_output *layout_output;
130 wl_list_for_each(layout_output, &output_layout->outputs, link) {
131 bool intersected = before != NULL && wlr_output_layout_intersects(
132 output_layout, layout_output->output, before);
133 bool intersects = wlr_output_layout_intersects(output_layout,
134 layout_output->output, &box);
135 if (intersected && !intersects) {
136 wlr_surface_send_leave(view->surface, layout_output->output);
137 }
138 if (!intersected && intersects) {
139 wlr_surface_send_enter(view->surface, layout_output->output);
140 }
141 }
142}
143
139void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { 144void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) {
140 if (!sway_assert(view->surface == NULL, "cannot map mapped view")) { 145 if (!sway_assert(view->surface == NULL, "cannot map mapped view")) {
141 return; 146 return;
@@ -153,6 +158,7 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) {
153 sway_input_manager_set_focus(input_manager, cont); 158 sway_input_manager_set_focus(input_manager, cont);
154 159
155 view_damage_whole(view); 160 view_damage_whole(view);
161 view_update_outputs(view, NULL);
156} 162}
157 163
158void view_map_unmanaged(struct sway_view *view, 164void view_map_unmanaged(struct sway_view *view,
@@ -168,6 +174,8 @@ void view_map_unmanaged(struct sway_view *view,
168 &view->unmanaged_view_link); 174 &view->unmanaged_view_link);
169 175
170 view_damage_whole(view); 176 view_damage_whole(view);
177 // TODO: make this work for unmanaged views
178 //view_update_outputs(view, NULL);
171} 179}
172 180
173void view_unmap(struct sway_view *view) { 181void view_unmap(struct sway_view *view) {
@@ -186,17 +194,30 @@ void view_unmap(struct sway_view *view) {
186 view->surface = NULL; 194 view->surface = NULL;
187} 195}
188 196
189void view_damage_whole(struct sway_view *view) { 197void view_update_position(struct sway_view *view, double ox, double oy) {
190 struct sway_container *cont = NULL; 198 if (view->swayc->x == ox && view->swayc->y == oy) {
191 for (int i = 0; i < root_container.children->length; ++i) { 199 return;
192 cont = root_container.children->items[i];
193 if (cont->type == C_OUTPUT) {
194 output_damage_whole_view(cont->sway_output, view);
195 }
196 } 200 }
201
202 struct wlr_box box;
203 view_get_layout_box(view, &box);
204 view_damage_whole(view);
205 view->swayc->x = ox;
206 view->swayc->y = oy;
207 view_update_outputs(view, &box);
208 view_damage_whole(view);
197} 209}
198 210
199void view_damage_from(struct sway_view *view) { 211void view_update_size(struct sway_view *view, int width, int height) {
200 // TODO 212 if (view->width == width && view->height == height) {
213 return;
214 }
215
216 struct wlr_box box;
217 view_get_layout_box(view, &box);
218 view_damage_whole(view);
219 view->width = width;
220 view->height = height;
221 view_update_outputs(view, &box);
201 view_damage_whole(view); 222 view_damage_whole(view);
202} 223}