diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-04-05 22:53:21 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-05 22:53:21 -0400 |
commit | f63d9417cd4d25121fa1fd309acad14a7562a55c (patch) | |
tree | c46a070652793db69ec5d6c5258d0e6cf86c1231 /sway/tree | |
parent | Merge pull request #1745 from swaywm/swaybar-hotplugging (diff) | |
parent | Handle unmanaged surfaces motion (diff) | |
download | sway-f63d9417cd4d25121fa1fd309acad14a7562a55c.tar.gz sway-f63d9417cd4d25121fa1fd309acad14a7562a55c.tar.zst sway-f63d9417cd4d25121fa1fd309acad14a7562a55c.zip |
Merge pull request #1743 from emersion/subsurface-damage-tracking
Damage tracking for view children
Diffstat (limited to 'sway/tree')
-rw-r--r-- | sway/tree/container.c | 11 | ||||
-rw-r--r-- | sway/tree/view.c | 112 |
2 files changed, 121 insertions, 2 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c index 3e8c1c75..41321dc8 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -514,9 +514,16 @@ static bool find_child_func(struct sway_container *con, void *data) { | |||
514 | 514 | ||
515 | bool container_has_child(struct sway_container *con, | 515 | bool container_has_child(struct sway_container *con, |
516 | struct sway_container *child) { | 516 | struct sway_container *child) { |
517 | if (con == NULL || con->type == C_VIEW || | 517 | if (con == NULL || con->type == C_VIEW || con->children->length == 0) { |
518 | con->children->length == 0) { | ||
519 | return false; | 518 | return false; |
520 | } | 519 | } |
521 | return container_find(con, find_child_func, child); | 520 | return container_find(con, find_child_func, child); |
522 | } | 521 | } |
522 | |||
523 | void container_damage_whole(struct sway_container *con) { | ||
524 | struct sway_container *output = con; | ||
525 | if (output->type != C_OUTPUT) { | ||
526 | output = container_parent(output, C_OUTPUT); | ||
527 | } | ||
528 | output_damage_whole_container(output->sway_output, con); | ||
529 | } | ||
diff --git a/sway/tree/view.c b/sway/tree/view.c index 3927c195..d3e3186c 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c | |||
@@ -11,6 +11,7 @@ void view_init(struct sway_view *view, enum sway_view_type type, | |||
11 | const struct sway_view_impl *impl) { | 11 | const struct sway_view_impl *impl) { |
12 | view->type = type; | 12 | view->type = type; |
13 | view->impl = impl; | 13 | view->impl = impl; |
14 | wl_signal_init(&view->events.unmap); | ||
14 | } | 15 | } |
15 | 16 | ||
16 | void view_destroy(struct sway_view *view) { | 17 | void view_destroy(struct sway_view *view) { |
@@ -123,6 +124,20 @@ static void view_update_outputs(struct sway_view *view, | |||
123 | } | 124 | } |
124 | } | 125 | } |
125 | 126 | ||
127 | static void view_subsurface_create(struct sway_view *view, | ||
128 | struct wlr_subsurface *subsurface); | ||
129 | |||
130 | static void view_init_subsurfaces(struct sway_view *view, | ||
131 | struct wlr_surface *surface); | ||
132 | |||
133 | static void view_handle_surface_new_subsurface(struct wl_listener *listener, | ||
134 | void *data) { | ||
135 | struct sway_view *view = | ||
136 | wl_container_of(listener, view, surface_new_subsurface); | ||
137 | struct wlr_subsurface *subsurface = data; | ||
138 | view_subsurface_create(view, subsurface); | ||
139 | } | ||
140 | |||
126 | void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { | 141 | void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { |
127 | if (!sway_assert(view->surface == NULL, "cannot map mapped view")) { | 142 | if (!sway_assert(view->surface == NULL, "cannot map mapped view")) { |
128 | return; | 143 | return; |
@@ -136,6 +151,11 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { | |||
136 | view->surface = wlr_surface; | 151 | view->surface = wlr_surface; |
137 | view->swayc = cont; | 152 | view->swayc = cont; |
138 | 153 | ||
154 | view_init_subsurfaces(view, wlr_surface); | ||
155 | wl_signal_add(&wlr_surface->events.new_subsurface, | ||
156 | &view->surface_new_subsurface); | ||
157 | view->surface_new_subsurface.notify = view_handle_surface_new_subsurface; | ||
158 | |||
139 | arrange_windows(cont->parent, -1, -1); | 159 | arrange_windows(cont->parent, -1, -1); |
140 | input_manager_set_focus(input_manager, cont); | 160 | input_manager_set_focus(input_manager, cont); |
141 | 161 | ||
@@ -148,10 +168,14 @@ void view_unmap(struct sway_view *view) { | |||
148 | return; | 168 | return; |
149 | } | 169 | } |
150 | 170 | ||
171 | wl_signal_emit(&view->events.unmap, view); | ||
172 | |||
151 | view_damage_whole(view); | 173 | view_damage_whole(view); |
152 | 174 | ||
153 | struct sway_container *parent = container_destroy(view->swayc); | 175 | struct sway_container *parent = container_destroy(view->swayc); |
154 | 176 | ||
177 | wl_list_remove(&view->surface_new_subsurface.link); | ||
178 | |||
155 | view->swayc = NULL; | 179 | view->swayc = NULL; |
156 | view->surface = NULL; | 180 | view->surface = NULL; |
157 | 181 | ||
@@ -185,3 +209,91 @@ void view_update_size(struct sway_view *view, int width, int height) { | |||
185 | view_update_outputs(view, &box); | 209 | view_update_outputs(view, &box); |
186 | view_damage_whole(view); | 210 | view_damage_whole(view); |
187 | } | 211 | } |
212 | |||
213 | |||
214 | static void view_subsurface_create(struct sway_view *view, | ||
215 | struct wlr_subsurface *subsurface) { | ||
216 | struct sway_view_child *child = calloc(1, sizeof(struct sway_view_child)); | ||
217 | if (child == NULL) { | ||
218 | wlr_log(L_ERROR, "Allocation failed"); | ||
219 | return; | ||
220 | } | ||
221 | view_child_init(child, NULL, view, subsurface->surface); | ||
222 | } | ||
223 | |||
224 | static void view_child_handle_surface_commit(struct wl_listener *listener, | ||
225 | void *data) { | ||
226 | struct sway_view_child *child = | ||
227 | wl_container_of(listener, child, surface_commit); | ||
228 | // TODO: only accumulate damage from the child | ||
229 | view_damage_from(child->view); | ||
230 | } | ||
231 | |||
232 | static void view_child_handle_surface_new_subsurface( | ||
233 | struct wl_listener *listener, void *data) { | ||
234 | struct sway_view_child *child = | ||
235 | wl_container_of(listener, child, surface_new_subsurface); | ||
236 | struct wlr_subsurface *subsurface = data; | ||
237 | view_subsurface_create(child->view, subsurface); | ||
238 | } | ||
239 | |||
240 | static void view_child_handle_surface_destroy(struct wl_listener *listener, | ||
241 | void *data) { | ||
242 | struct sway_view_child *child = | ||
243 | wl_container_of(listener, child, surface_destroy); | ||
244 | view_child_destroy(child); | ||
245 | } | ||
246 | |||
247 | static void view_child_handle_view_unmap(struct wl_listener *listener, | ||
248 | void *data) { | ||
249 | struct sway_view_child *child = | ||
250 | wl_container_of(listener, child, view_unmap); | ||
251 | view_child_destroy(child); | ||
252 | } | ||
253 | |||
254 | static void view_init_subsurfaces(struct sway_view *view, | ||
255 | struct wlr_surface *surface) { | ||
256 | struct wlr_subsurface *subsurface; | ||
257 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { | ||
258 | view_subsurface_create(view, subsurface); | ||
259 | } | ||
260 | } | ||
261 | |||
262 | void view_child_init(struct sway_view_child *child, | ||
263 | const struct sway_view_child_impl *impl, struct sway_view *view, | ||
264 | struct wlr_surface *surface) { | ||
265 | child->impl = impl; | ||
266 | child->view = view; | ||
267 | child->surface = surface; | ||
268 | |||
269 | wl_signal_add(&surface->events.commit, &child->surface_commit); | ||
270 | child->surface_commit.notify = view_child_handle_surface_commit; | ||
271 | wl_signal_add(&surface->events.new_subsurface, | ||
272 | &child->surface_new_subsurface); | ||
273 | child->surface_new_subsurface.notify = | ||
274 | view_child_handle_surface_new_subsurface; | ||
275 | wl_signal_add(&surface->events.destroy, &child->surface_destroy); | ||
276 | child->surface_destroy.notify = view_child_handle_surface_destroy; | ||
277 | wl_signal_add(&view->events.unmap, &child->view_unmap); | ||
278 | child->view_unmap.notify = view_child_handle_view_unmap; | ||
279 | |||
280 | view_init_subsurfaces(child->view, surface); | ||
281 | |||
282 | // TODO: only damage the whole child | ||
283 | view_damage_whole(child->view); | ||
284 | } | ||
285 | |||
286 | void view_child_destroy(struct sway_view_child *child) { | ||
287 | // TODO: only damage the whole child | ||
288 | view_damage_whole(child->view); | ||
289 | |||
290 | wl_list_remove(&child->surface_commit.link); | ||
291 | wl_list_remove(&child->surface_destroy.link); | ||
292 | wl_list_remove(&child->view_unmap.link); | ||
293 | |||
294 | if (child->impl && child->impl->destroy) { | ||
295 | child->impl->destroy(child); | ||
296 | } else { | ||
297 | free(child); | ||
298 | } | ||
299 | } | ||