aboutsummaryrefslogtreecommitdiffstats
path: root/sway/desktop
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-07-14 23:14:55 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-07-14 23:14:55 +1000
commit2032f85d94f2f222282b242116b3e827dd458f6c (patch)
treed6ad82f79521cdd948985be22630b803af58afea /sway/desktop
parentMerge pull request #2244 from RyanDwyer/floating-resize (diff)
downloadsway-2032f85d94f2f222282b242116b3e827dd458f6c.tar.gz
sway-2032f85d94f2f222282b242116b3e827dd458f6c.tar.zst
sway-2032f85d94f2f222282b242116b3e827dd458f6c.zip
Simplify transactions by utilising a dirty flag on containers
This PR changes the way we handle transactions to a more simple method. The new method is to mark containers as dirty from low level code (eg. arranging, or container_destroy, and eventually seat_set_focus), then call transaction_commit_dirty which picks up those containers and runs them through a transaction. The old methods of using transactions (arrange_and_commit, or creating one manually) are now no longer possible. The highest-level code (execute_command and view implementation handlers) will call transaction_commit_dirty, so most other code just needs to set containers as dirty. This is done by arranging, but can also be done by calling container_set_dirty.
Diffstat (limited to 'sway/desktop')
-rw-r--r--sway/desktop/layer_shell.c3
-rw-r--r--sway/desktop/output.c14
-rw-r--r--sway/desktop/transaction.c35
-rw-r--r--sway/desktop/xdg_shell.c8
-rw-r--r--sway/desktop/xdg_shell_v6.c8
-rw-r--r--sway/desktop/xwayland.c8
6 files changed, 42 insertions, 34 deletions
diff --git a/sway/desktop/layer_shell.c b/sway/desktop/layer_shell.c
index 16910c7e..91baa6f8 100644
--- a/sway/desktop/layer_shell.c
+++ b/sway/desktop/layer_shell.c
@@ -12,7 +12,6 @@
12#include "sway/layers.h" 12#include "sway/layers.h"
13#include "sway/output.h" 13#include "sway/output.h"
14#include "sway/server.h" 14#include "sway/server.h"
15#include "sway/tree/arrange.h"
16#include "sway/tree/layout.h" 15#include "sway/tree/layout.h"
17#include "log.h" 16#include "log.h"
18 17
@@ -176,7 +175,7 @@ void arrange_layers(struct sway_output *output) {
176 sizeof(struct wlr_box)) != 0) { 175 sizeof(struct wlr_box)) != 0) {
177 wlr_log(WLR_DEBUG, "Usable area changed, rearranging output"); 176 wlr_log(WLR_DEBUG, "Usable area changed, rearranging output");
178 memcpy(&output->usable_area, &usable_area, sizeof(struct wlr_box)); 177 memcpy(&output->usable_area, &usable_area, sizeof(struct wlr_box));
179 arrange_and_commit(output->swayc); 178 container_set_dirty(output->swayc);
180 } 179 }
181 180
182 // Arrange non-exlusive surfaces from top->bottom 181 // Arrange non-exlusive surfaces from top->bottom
diff --git a/sway/desktop/output.c b/sway/desktop/output.c
index a2720885..a9808406 100644
--- a/sway/desktop/output.c
+++ b/sway/desktop/output.c
@@ -492,19 +492,21 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
492 output->wlr_output->data = NULL; 492 output->wlr_output->data = NULL;
493 free(output); 493 free(output);
494 494
495 arrange_and_commit(&root_container); 495 arrange_windows(&root_container);
496} 496}
497 497
498static void handle_mode(struct wl_listener *listener, void *data) { 498static void handle_mode(struct wl_listener *listener, void *data) {
499 struct sway_output *output = wl_container_of(listener, output, mode); 499 struct sway_output *output = wl_container_of(listener, output, mode);
500 arrange_layers(output); 500 arrange_layers(output);
501 arrange_and_commit(output->swayc); 501 arrange_windows(output->swayc);
502 transaction_commit_dirty();
502} 503}
503 504
504static void handle_transform(struct wl_listener *listener, void *data) { 505static void handle_transform(struct wl_listener *listener, void *data) {
505 struct sway_output *output = wl_container_of(listener, output, transform); 506 struct sway_output *output = wl_container_of(listener, output, transform);
506 arrange_layers(output); 507 arrange_layers(output);
507 arrange_and_commit(output->swayc); 508 arrange_windows(output->swayc);
509 transaction_commit_dirty();
508} 510}
509 511
510static void handle_scale_iterator(struct sway_container *view, void *data) { 512static void handle_scale_iterator(struct sway_container *view, void *data) {
@@ -515,7 +517,8 @@ static void handle_scale(struct wl_listener *listener, void *data) {
515 struct sway_output *output = wl_container_of(listener, output, scale); 517 struct sway_output *output = wl_container_of(listener, output, scale);
516 arrange_layers(output); 518 arrange_layers(output);
517 container_descendants(output->swayc, C_VIEW, handle_scale_iterator, NULL); 519 container_descendants(output->swayc, C_VIEW, handle_scale_iterator, NULL);
518 arrange_and_commit(output->swayc); 520 arrange_windows(output->swayc);
521 transaction_commit_dirty();
519} 522}
520 523
521struct sway_output *output_from_wlr_output(struct wlr_output *wlr_output) { 524struct sway_output *output_from_wlr_output(struct wlr_output *wlr_output) {
@@ -584,5 +587,6 @@ void output_enable(struct sway_output *output) {
584 output->damage_destroy.notify = damage_handle_destroy; 587 output->damage_destroy.notify = damage_handle_destroy;
585 588
586 arrange_layers(output); 589 arrange_layers(output);
587 arrange_and_commit(&root_container); 590 arrange_windows(&root_container);
591 transaction_commit_dirty();
588} 592}
diff --git a/sway/desktop/transaction.c b/sway/desktop/transaction.c
index 2b3f87c3..d7ef7130 100644
--- a/sway/desktop/transaction.c
+++ b/sway/desktop/transaction.c
@@ -47,7 +47,7 @@ struct sway_transaction_instruction {
47 bool ready; 47 bool ready;
48}; 48};
49 49
50struct sway_transaction *transaction_create() { 50static struct sway_transaction *transaction_create() {
51 struct sway_transaction *transaction = 51 struct sway_transaction *transaction =
52 calloc(1, sizeof(struct sway_transaction)); 52 calloc(1, sizeof(struct sway_transaction));
53 transaction->instructions = create_list(); 53 transaction->instructions = create_list();
@@ -141,23 +141,8 @@ static void copy_pending_state(struct sway_container *container,
141 } 141 }
142} 142}
143 143
144static bool transaction_has_container(struct sway_transaction *transaction, 144static void transaction_add_container(struct sway_transaction *transaction,
145 struct sway_container *container) { 145 struct sway_container *container) {
146 for (int i = 0; i < transaction->instructions->length; ++i) {
147 struct sway_transaction_instruction *instruction =
148 transaction->instructions->items[i];
149 if (instruction->container == container) {
150 return true;
151 }
152 }
153 return false;
154}
155
156void transaction_add_container(struct sway_transaction *transaction,
157 struct sway_container *container) {
158 if (transaction_has_container(transaction, container)) {
159 return;
160 }
161 struct sway_transaction_instruction *instruction = 146 struct sway_transaction_instruction *instruction =
162 calloc(1, sizeof(struct sway_transaction_instruction)); 147 calloc(1, sizeof(struct sway_transaction_instruction));
163 instruction->transaction = transaction; 148 instruction->transaction = transaction;
@@ -285,7 +270,7 @@ static bool should_configure(struct sway_container *con,
285 return true; 270 return true;
286} 271}
287 272
288void transaction_commit(struct sway_transaction *transaction) { 273static void transaction_commit(struct sway_transaction *transaction) {
289 wlr_log(WLR_DEBUG, "Transaction %p committing with %i instructions", 274 wlr_log(WLR_DEBUG, "Transaction %p committing with %i instructions",
290 transaction, transaction->instructions->length); 275 transaction, transaction->instructions->length);
291 transaction->num_waiting = 0; 276 transaction->num_waiting = 0;
@@ -418,3 +403,17 @@ struct wlr_texture *transaction_get_saved_texture(struct sway_view *view,
418 *height = instruction->saved_buffer_height; 403 *height = instruction->saved_buffer_height;
419 return instruction->saved_buffer->texture; 404 return instruction->saved_buffer->texture;
420} 405}
406
407void transaction_commit_dirty() {
408 if (!server.dirty_containers->length) {
409 return;
410 }
411 struct sway_transaction *transaction = transaction_create();
412 for (int i = 0; i < server.dirty_containers->length; ++i) {
413 struct sway_container *container = server.dirty_containers->items[i];
414 transaction_add_container(transaction, container);
415 container->dirty = false;
416 }
417 server.dirty_containers->length = 0;
418 transaction_commit(transaction);
419}
diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c
index fbeeb2e3..98c16faf 100644
--- a/sway/desktop/xdg_shell.c
+++ b/sway/desktop/xdg_shell.c
@@ -244,7 +244,8 @@ static void handle_request_fullscreen(struct wl_listener *listener, void *data)
244 view_set_fullscreen(view, e->fullscreen); 244 view_set_fullscreen(view, e->fullscreen);
245 245
246 struct sway_container *output = container_parent(view->swayc, C_OUTPUT); 246 struct sway_container *output = container_parent(view->swayc, C_OUTPUT);
247 arrange_and_commit(output); 247 arrange_windows(output);
248 transaction_commit_dirty();
248} 249}
249 250
250static void handle_unmap(struct wl_listener *listener, void *data) { 251static void handle_unmap(struct wl_listener *listener, void *data) {
@@ -281,10 +282,11 @@ static void handle_map(struct wl_listener *listener, void *data) {
281 if (xdg_surface->toplevel->client_pending.fullscreen) { 282 if (xdg_surface->toplevel->client_pending.fullscreen) {
282 view_set_fullscreen(view, true); 283 view_set_fullscreen(view, true);
283 struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE); 284 struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
284 arrange_and_commit(ws); 285 arrange_windows(ws);
285 } else { 286 } else {
286 arrange_and_commit(view->swayc->parent); 287 arrange_windows(view->swayc->parent);
287 } 288 }
289 transaction_commit_dirty();
288 290
289 xdg_shell_view->commit.notify = handle_commit; 291 xdg_shell_view->commit.notify = handle_commit;
290 wl_signal_add(&xdg_surface->surface->events.commit, 292 wl_signal_add(&xdg_surface->surface->events.commit,
diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c
index 88d9bb94..4d76f0a7 100644
--- a/sway/desktop/xdg_shell_v6.c
+++ b/sway/desktop/xdg_shell_v6.c
@@ -239,7 +239,8 @@ static void handle_request_fullscreen(struct wl_listener *listener, void *data)
239 view_set_fullscreen(view, e->fullscreen); 239 view_set_fullscreen(view, e->fullscreen);
240 240
241 struct sway_container *output = container_parent(view->swayc, C_OUTPUT); 241 struct sway_container *output = container_parent(view->swayc, C_OUTPUT);
242 arrange_and_commit(output); 242 arrange_windows(output);
243 transaction_commit_dirty();
243} 244}
244 245
245static void handle_unmap(struct wl_listener *listener, void *data) { 246static void handle_unmap(struct wl_listener *listener, void *data) {
@@ -276,10 +277,11 @@ static void handle_map(struct wl_listener *listener, void *data) {
276 if (xdg_surface->toplevel->client_pending.fullscreen) { 277 if (xdg_surface->toplevel->client_pending.fullscreen) {
277 view_set_fullscreen(view, true); 278 view_set_fullscreen(view, true);
278 struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE); 279 struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
279 arrange_and_commit(ws); 280 arrange_windows(ws);
280 } else { 281 } else {
281 arrange_and_commit(view->swayc->parent); 282 arrange_windows(view->swayc->parent);
282 } 283 }
284 transaction_commit_dirty();
283 285
284 xdg_shell_v6_view->commit.notify = handle_commit; 286 xdg_shell_v6_view->commit.notify = handle_commit;
285 wl_signal_add(&xdg_surface->surface->events.commit, 287 wl_signal_add(&xdg_surface->surface->events.commit,
diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c
index 460d1cc8..11516673 100644
--- a/sway/desktop/xwayland.c
+++ b/sway/desktop/xwayland.c
@@ -333,10 +333,11 @@ static void handle_map(struct wl_listener *listener, void *data) {
333 if (xsurface->fullscreen) { 333 if (xsurface->fullscreen) {
334 view_set_fullscreen(view, true); 334 view_set_fullscreen(view, true);
335 struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE); 335 struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
336 arrange_and_commit(ws); 336 arrange_windows(ws);
337 } else { 337 } else {
338 arrange_and_commit(view->swayc->parent); 338 arrange_windows(view->swayc->parent);
339 } 339 }
340 transaction_commit_dirty();
340} 341}
341 342
342static void handle_destroy(struct wl_listener *listener, void *data) { 343static void handle_destroy(struct wl_listener *listener, void *data) {
@@ -392,7 +393,8 @@ static void handle_request_fullscreen(struct wl_listener *listener, void *data)
392 view_set_fullscreen(view, xsurface->fullscreen); 393 view_set_fullscreen(view, xsurface->fullscreen);
393 394
394 struct sway_container *output = container_parent(view->swayc, C_OUTPUT); 395 struct sway_container *output = container_parent(view->swayc, C_OUTPUT);
395 arrange_and_commit(output); 396 arrange_windows(output);
397 transaction_commit_dirty();
396} 398}
397 399
398static void handle_set_title(struct wl_listener *listener, void *data) { 400static void handle_set_title(struct wl_listener *listener, void *data) {