diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-06-24 23:01:09 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-06-24 23:01:09 +1000 |
commit | 1549fb719ae75a498bf319db45281464e72c759e (patch) | |
tree | e5944487928a65b1af3b7dc9a44f1b14250bc0bf | |
parent | Fix crash when running move <direction> in an empty workspace (diff) | |
download | sway-1549fb719ae75a498bf319db45281464e72c759e.tar.gz sway-1549fb719ae75a498bf319db45281464e72c759e.tar.zst sway-1549fb719ae75a498bf319db45281464e72c759e.zip |
Implement atomic layout updates for xwayland views
-rw-r--r-- | include/sway/desktop/transaction.h | 9 | ||||
-rw-r--r-- | sway/desktop/transaction.c | 44 | ||||
-rw-r--r-- | sway/desktop/xwayland.c | 14 |
3 files changed, 40 insertions, 27 deletions
diff --git a/include/sway/desktop/transaction.h b/include/sway/desktop/transaction.h index d6adc609..b1da86f1 100644 --- a/include/sway/desktop/transaction.h +++ b/include/sway/desktop/transaction.h | |||
@@ -50,6 +50,15 @@ void transaction_commit(struct sway_transaction *transaction); | |||
50 | void transaction_notify_view_ready(struct sway_view *view, uint32_t serial); | 50 | void transaction_notify_view_ready(struct sway_view *view, uint32_t serial); |
51 | 51 | ||
52 | /** | 52 | /** |
53 | * Notify the transaction system that a view is ready for the new layout, but | ||
54 | * identifying the instruction by width and height rather than by serial. | ||
55 | * | ||
56 | * This is used by xwayland views, as they don't have serials. | ||
57 | */ | ||
58 | void transaction_notify_view_ready_by_size(struct sway_view *view, | ||
59 | int width, int height); | ||
60 | |||
61 | /** | ||
53 | * Get the texture that should be rendered for a view. | 62 | * Get the texture that should be rendered for a view. |
54 | * | 63 | * |
55 | * In most cases this will return the normal live texture for a view, but if the | 64 | * In most cases this will return the normal live texture for a view, but if the |
diff --git a/sway/desktop/transaction.c b/sway/desktop/transaction.c index 04142bcc..08678b5b 100644 --- a/sway/desktop/transaction.c +++ b/sway/desktop/transaction.c | |||
@@ -267,9 +267,7 @@ void transaction_commit(struct sway_transaction *transaction) { | |||
267 | instruction->state.view_y, | 267 | instruction->state.view_y, |
268 | instruction->state.view_width, | 268 | instruction->state.view_width, |
269 | instruction->state.view_height); | 269 | instruction->state.view_height); |
270 | if (instruction->serial) { | 270 | ++transaction->num_waiting; |
271 | ++transaction->num_waiting; | ||
272 | } | ||
273 | } | 271 | } |
274 | list_add(con->instructions, instruction); | 272 | list_add(con->instructions, instruction); |
275 | } | 273 | } |
@@ -307,20 +305,8 @@ void transaction_commit(struct sway_transaction *transaction) { | |||
307 | update_debug_tree(); | 305 | update_debug_tree(); |
308 | } | 306 | } |
309 | 307 | ||
310 | void transaction_notify_view_ready(struct sway_view *view, uint32_t serial) { | 308 | static void set_instruction_ready( |
311 | // Find the instruction | 309 | struct sway_transaction_instruction *instruction) { |
312 | struct sway_transaction_instruction *instruction = NULL; | ||
313 | for (int i = 0; i < view->swayc->instructions->length; ++i) { | ||
314 | struct sway_transaction_instruction *tmp_instruction = | ||
315 | view->swayc->instructions->items[i]; | ||
316 | if (tmp_instruction->serial == serial && !tmp_instruction->ready) { | ||
317 | instruction = tmp_instruction; | ||
318 | break; | ||
319 | } | ||
320 | } | ||
321 | if (!instruction) { | ||
322 | return; | ||
323 | } | ||
324 | instruction->ready = true; | 310 | instruction->ready = true; |
325 | 311 | ||
326 | // If all views are ready, apply the transaction. | 312 | // If all views are ready, apply the transaction. |
@@ -335,6 +321,30 @@ void transaction_notify_view_ready(struct sway_view *view, uint32_t serial) { | |||
335 | } | 321 | } |
336 | } | 322 | } |
337 | 323 | ||
324 | void transaction_notify_view_ready(struct sway_view *view, uint32_t serial) { | ||
325 | for (int i = 0; i < view->swayc->instructions->length; ++i) { | ||
326 | struct sway_transaction_instruction *instruction = | ||
327 | view->swayc->instructions->items[i]; | ||
328 | if (instruction->serial == serial && !instruction->ready) { | ||
329 | set_instruction_ready(instruction); | ||
330 | return; | ||
331 | } | ||
332 | } | ||
333 | } | ||
334 | |||
335 | void transaction_notify_view_ready_by_size(struct sway_view *view, | ||
336 | int width, int height) { | ||
337 | for (int i = 0; i < view->swayc->instructions->length; ++i) { | ||
338 | struct sway_transaction_instruction *instruction = | ||
339 | view->swayc->instructions->items[i]; | ||
340 | if (!instruction->ready && instruction->state.view_width == width && | ||
341 | instruction->state.view_height == height) { | ||
342 | set_instruction_ready(instruction); | ||
343 | return; | ||
344 | } | ||
345 | } | ||
346 | } | ||
347 | |||
338 | struct wlr_texture *transaction_get_texture(struct sway_view *view) { | 348 | struct wlr_texture *transaction_get_texture(struct sway_view *view) { |
339 | if (!view->swayc || !view->swayc->instructions->length) { | 349 | if (!view->swayc || !view->swayc->instructions->length) { |
340 | return view->surface->buffer->texture; | 350 | return view->surface->buffer->texture; |
diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index a1837420..7e78ef32 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c | |||
@@ -7,6 +7,7 @@ | |||
7 | #include <wlr/xwayland.h> | 7 | #include <wlr/xwayland.h> |
8 | #include "log.h" | 8 | #include "log.h" |
9 | #include "sway/desktop.h" | 9 | #include "sway/desktop.h" |
10 | #include "sway/desktop/transaction.h" | ||
10 | #include "sway/input/input-manager.h" | 11 | #include "sway/input/input-manager.h" |
11 | #include "sway/input/seat.h" | 12 | #include "sway/input/seat.h" |
12 | #include "sway/output.h" | 13 | #include "sway/output.h" |
@@ -243,16 +244,9 @@ static void handle_commit(struct wl_listener *listener, void *data) { | |||
243 | struct sway_view *view = &xwayland_view->view; | 244 | struct sway_view *view = &xwayland_view->view; |
244 | struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; | 245 | struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; |
245 | 246 | ||
246 | // Don't allow xwayland views to do resize or reposition themselves if | 247 | if (view->swayc->instructions->length) { |
247 | // they're involved in a transaction. Once the transaction has finished | 248 | transaction_notify_view_ready_by_size(view, |
248 | // they'll apply the next time a commit happens. | 249 | xsurface->width, xsurface->height); |
249 | if (view->swayc && view->swayc->instructions->length) { | ||
250 | if (view->swayc && container_is_floating(view->swayc)) { | ||
251 | view_update_size(view, xsurface->width, xsurface->height); | ||
252 | } else { | ||
253 | view_update_size(view, view->swayc->width, view->swayc->height); | ||
254 | } | ||
255 | view_update_position(view, view->x, view->y); | ||
256 | } | 250 | } |
257 | view_damage_from(view); | 251 | view_damage_from(view); |
258 | } | 252 | } |